mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 13:05:05 +02:00
Compiling macros to C
This commit is contained in:
parent
f3473f75e1
commit
233d166e02
2 changed files with 13 additions and 1 deletions
|
@ -24,6 +24,7 @@
|
||||||
*do-code-gen*
|
*do-code-gen*
|
||||||
*trace-level*
|
*trace-level*
|
||||||
*primitives*
|
*primitives*
|
||||||
|
get-macros
|
||||||
built-in-syms
|
built-in-syms
|
||||||
trace
|
trace
|
||||||
trace:error
|
trace:error
|
||||||
|
@ -135,6 +136,7 @@
|
||||||
;; Built-in macros
|
;; Built-in macros
|
||||||
;; TODO: just a stub, real code would read (define-syntax)
|
;; TODO: just a stub, real code would read (define-syntax)
|
||||||
;; from a lib file or such
|
;; from a lib file or such
|
||||||
|
(define (get-macros) *defined-macros*)
|
||||||
(define *defined-macros*
|
(define *defined-macros*
|
||||||
(list
|
(list
|
||||||
(cons 'and
|
(cons 'and
|
||||||
|
@ -1025,7 +1027,11 @@
|
||||||
(trans (caddr exp))
|
(trans (caddr exp))
|
||||||
(body (cadr trans)))
|
(body (cadr trans)))
|
||||||
(set! *defined-macros* (cons (cons name body) *defined-macros*))
|
(set! *defined-macros* (cons (cons name body) *defined-macros*))
|
||||||
#t))
|
;; Keep as a 'define' form so available at runtime
|
||||||
|
;; TODO: may run into issues with expanding now, before some
|
||||||
|
;; of the macros are defined. may need to make a special pass
|
||||||
|
;; to do loading or expansion of macro bodies
|
||||||
|
`(define ,name ,(expand body))))
|
||||||
((macro? exp *defined-macros*)
|
((macro? exp *defined-macros*)
|
||||||
(expand ;; Could expand into another macro
|
(expand ;; Could expand into another macro
|
||||||
(macro-expand exp *defined-macros*)))
|
(macro-expand exp *defined-macros*)))
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
|
(scheme eval)
|
||||||
(scheme write))
|
(scheme write))
|
||||||
|
|
||||||
;(define-syntax test
|
;(define-syntax test
|
||||||
|
@ -42,3 +43,8 @@
|
||||||
(write (or #f 2 3 'or))
|
(write (or #f 2 3 'or))
|
||||||
;(test 'done)
|
;(test 'done)
|
||||||
'done
|
'done
|
||||||
|
|
||||||
|
(define x 1)
|
||||||
|
(write x)
|
||||||
|
(write
|
||||||
|
(eval 'x))
|
||||||
|
|
Loading…
Add table
Reference in a new issue