aboutsummaryrefslogtreecommitdiffstats
path: root/csc/macros.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-07-30 13:31:05 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-07-30 13:31:19 -0700
commit6ffa3538cfeb5a97e967544bfbbcf907f4aa565f (patch)
tree691d7b73e47c8c07acbf3fef5cee11d76bb34a52 /csc/macros.csc
parent0632650d0e4250e08a76982ab2713a34e3531b33 (diff)
downloadchromatopelma-6ffa3538cfeb5a97e967544bfbbcf907f4aa565f.tar.zst
Add call-builtin syntax.
This syntax allows calling opcodes directly from scheme code. Very powerful technique.
Diffstat (limited to 'csc/macros.csc')
-rw-r--r--csc/macros.csc22
1 files changed, 21 insertions, 1 deletions
diff --git a/csc/macros.csc b/csc/macros.csc
index 288865d..4559991 100644
--- a/csc/macros.csc
+++ b/csc/macros.csc
@@ -32,6 +32,7 @@
library-ref-name
library-ref?
make-call
+ make-call-builtin
make-constant
make-define-syntax
make-lambda
@@ -748,6 +749,24 @@
(_ (raise-syntax-error "unexpected form in builtin-define-syntax" x))))))
+ (define builtin-call-builtin
+ (make-macro-transformer
+ (lambda (x)
+ (syntax-case x
+ ((_ op . args) when (identifier? op)
+ (make-call-builtin (identifier-name op)
+ (let loop ((args args)
+ (expanded-args '()))
+ (syntax-case args
+ ('() (reverse expanded-args))
+ ((head . tail)
+ (loop tail
+ (cons (expand-syntax-object head)
+ expanded-args)))
+ (_ (raise-syntax-error "unexpected form in call-builtin"))))))
+ (_ (raise-syntax-error "unexpected form in call-builtin" x))))))
+
+
(define builtins-environment
(alist->substitutions
(list (cons 'syntax-rules builtin-syntax-rules)
@@ -757,7 +776,8 @@
(cons 'quote builtin-quote)
(cons 'lambda builtin-lambda)
(cons 'builtin-define builtin-define)
- (cons 'define-syntax builtin-define-syntax))))
+ (cons 'define-syntax builtin-define-syntax)
+ (cons 'call-builtin builtin-call-builtin))))
; Expands the body of a library, or top level. expand-body can be thought