aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_schasm/macros.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/macros.scm
parent501a434ff5834cba51b9efcff1fe18cd75f87334 (diff)
Refactor, improve
Diffstat (limited to 'atk16_schasm/macros.scm')
-rw-r--r--atk16_schasm/macros.scm27
1 files changed, 19 insertions, 8 deletions
diff --git a/atk16_schasm/macros.scm b/atk16_schasm/macros.scm
index 6b759b3..fb1ed3e 100644
--- a/atk16_schasm/macros.scm
+++ b/atk16_schasm/macros.scm
@@ -4,7 +4,7 @@
(define (next-unique)
(inc! *unique-counter*)
*unique-counter*)
-(define *macro-scratch-reg* R12)
+(define *macro-scratch-reg* R11)
(define (%packed-string s)
;; emit length
@@ -65,7 +65,7 @@
(emit-inverted-test *macro-scratch-reg* op rhs sym-false)
tb
- (ld PC (label sym-end))
+ (ld PC ZR (label sym-end))
(def-label sym-false)
fb
(def-label sym-end)))))
@@ -102,7 +102,7 @@
body body* ...
- (ld PC (label sym-test))
+ (ld PC ZR (label sym-test))
(def-label sym-end)))))
(define *procedures* '())
@@ -127,7 +127,7 @@
((_ pname)
(param 'pname))))
-(define-syntax %def-proc
+(define-syntax %proc
(syntax-rules ()
((_ signature body* ...)
(let* ((name (car `signature))
@@ -141,6 +141,7 @@
(def-label name)
(parameterize ((*proc-scope* bindings))
body* ...)
+ (ld PC SP #f preinc: #t indirect: 1)
))))
(define-syntax %call
@@ -171,12 +172,22 @@
;; move each argument to its designated register
;; first arg to R0, etc.
- (let* ((rn (reg i)))
- (ld rn (list-ref args i)))
+ (let* ((rn (reg i))
+ (argi (list-ref args i))
+ (itype (type-of argi)))
+ (cond
+ ((eq? 'reg itype)
+ (ld rn argi))
+ ((or (eq? 'imm itype)
+ (eq? 'label itype))
+ (ld rn ZR argi))
+ (else (error "invalid argument" argi))))
(loop (+ 1 i))))
- (st SP (label sym-ret) push: #t)
- (ld PC (label `name))
+ (ld *macro-scratch-reg* ZR (label sym-ret))
+ (st *macro-scratch-reg* SP #f postdec: #t)
+
+ (ld PC ZR (label `name))
(def-label sym-ret)
))))