This commit is contained in:
Justin Ethier 2015-09-02 01:06:29 -04:00
parent 6bf6b028d2
commit 1244ea5342
2 changed files with 34 additions and 18 deletions

View file

@ -1,6 +1,6 @@
(define-library (scheme cyclone macros)
(import (scheme base)
;(scheme write) ;; Debug only
(scheme write) ;; Debug only
(scheme eval) ;; TODO: without this line, compilation just
;; silently fails. WTF??
(scheme cyclone util))
@ -54,6 +54,10 @@
(let* ((macro (assoc (car exp) defined-macros))
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
(procedure? (cdr macro)))))
(newline)
(display "/* ")
(display (list 'macro:expand exp macro compiled-macro?))
(display "*/ ")
;; Invoke ER macro
(cond
((not macro)
@ -80,25 +84,34 @@
env))))))
;mac-env))))))
(define (macro:expand2 macro exp mac-env)
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar macro))
(procedure? macro))))
(define (macro:expand2 exp macro mac-env)
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar (cadr macro)))
(procedure? (cadr macro)))))
(newline)
(display "/* ")
(display (list 'macro:expand2 exp macro compiled-macro?))
(display "*/ ")
;; Invoke ER macro
(cond
((not macro)
(error "macro not found" exp))
(compiled-macro?
((Cyc-get-cvar macro)
((Cyc-get-cvar (cadr macro))
exp
(Cyc-er-rename mac-env)
Cyc-er-compare?))
(else
(eval
(list
(Cyc-get-cvar macro)
(Cyc-get-cvar (cadr macro))
(list 'quote exp)
(Cyc-er-rename mac-env)
Cyc-er-compare?)
; TODO: this is broken because mac-env only contains macros, but
; we need global-env to handle functions (like null?, caddr, etc).
; not sure what the answer is yet... might need to base macro-env
; on global-env, and ensure symbol is a macro before expanding
mac-env)))))
; TODO: get macro name, transformer

View file

@ -789,20 +789,23 @@
`(define ,name ,(expand body env))))
; Newer macro expansion code, but not ready yet
; ((symbol? (car exp))
; (let ((val (env:lookup (car exp) env #f)))
; (if val
; (macro:expand val exp env)
; (map
; (lambda (expr) (expand expr env))
; exp))))
((symbol? (car exp))
(let ((val (env:lookup (car exp) env #f)))
(if val
(expand ; Could expand into another macro
(macro:expand 'val exp env *defined-macros*)
;(macro:expand2 exp val env)
env)
(map
(lambda (expr) (expand expr env))
exp))))
;; Older *define-macro* code:
((macro:macro? exp *defined-macros*)
;(trace:info (list 'expanding exp))
(expand ;; Could expand into another macro
(macro:expand 'TODO-val exp env *defined-macros*)
env))
;((macro:macro? exp *defined-macros*)
; ;(trace:info (list 'expanding exp))
; (expand ;; Could expand into another macro
; (macro:expand 'TODO-val exp env *defined-macros*)
; env))
(else
(map