aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_schasm/structs_idea.scm
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-03-08 00:48:20 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-03-08 00:48:20 +0200
commit7f83828988c2efab56f37c1711cbf6118be8234f (patch)
treed0990b1a9c3e607d4bac3c44f884455dba7c49e6 /atk16_schasm/structs_idea.scm
parent501a434ff5834cba51b9efcff1fe18cd75f87334 (diff)
Refactor, improve
Diffstat (limited to 'atk16_schasm/structs_idea.scm')
-rw-r--r--atk16_schasm/structs_idea.scm28
1 files changed, 28 insertions, 0 deletions
diff --git a/atk16_schasm/structs_idea.scm b/atk16_schasm/structs_idea.scm
new file mode 100644
index 0000000..d2fcc86
--- /dev/null
+++ b/atk16_schasm/structs_idea.scm
@@ -0,0 +1,28 @@
+# This buffer is for notes you don’t want to save, and for Chicken Scheme code.
+
+;; define structs
+(%def-struct point
+ (x u16)
+ (y u16))
+
+;; static struct instances
+(%static global-point
+ point (u16 10) (u16 20))
+
+;; use static address as load offset
+(ld R0 ZR (global-point:x))
+
+;; stack allocated instances
+(%def-proc (main)
+ ;; alloc some space on the stack
+ (%svar my-point (point:size))
+ ;; use stack offset as load offset
+ (ld R0 SP (my-point:x)))
+
+;; a vector of static instances
+(let loop ((i 0))
+ (when (< i 10)
+ (%static (string->symbol (format "global-points/~A" i))
+ point (u16 i) (u16 i))))
+
+(ld R0 ZR (global-points/0:x))