From 6ffa3538cfeb5a97e967544bfbbcf907f4aa565f Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 30 Jul 2022 13:31:05 -0700 Subject: Add call-builtin syntax. This syntax allows calling opcodes directly from scheme code. Very powerful technique. --- csc/macros.csc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'csc/macros.csc') 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 -- cgit v1.3.1