diff --git a/scheme/cyclone/macros.sld b/scheme/cyclone/macros.sld index d4371cde..8d792cf7 100644 --- a/scheme/cyclone/macros.sld +++ b/scheme/cyclone/macros.sld @@ -41,36 +41,40 @@ (tagged-list? 'define-syntax exp)) (define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros)) -TODO: seems to be a problem with below. may want to revert and try and see if that works, then -restore this and debug... - (define (macro:expand macro-val exp mac-env) - (let* ( ;(macro (assoc (car exp) defined-macros)) - (compiled-macro? (or (macro? (Cyc-get-cvar macro-val)) - (procedure? macro-val)))) +;TODO: seems to be a problem with below. may want to revert and try and see if that works, then +;restore this and debug... +; +; TODO: probably want to look at contents of defined-macros and figure out +; exactly how the env needs to represent macros (compiled and eval'd) +; + (define (macro:expand _macro-val exp mac-env defined-macros) + (let* ((macro (assoc (car exp) defined-macros)) + (compiled-macro? (or (macro? (Cyc-get-cvar macro)) + (procedure? macro)))) ;; Invoke ER macro (cond - ((not macro-val) + ((not macro) (error "macro not found" exp)) (compiled-macro? - ((Cyc-get-cvar macro-val) + ((Cyc-get-cvar (cdr macro)) exp (Cyc-er-rename mac-env) Cyc-er-compare?)) (else ;; Assume evaluated macro - ;(let* ((env-vars (map car defined-macros)) - ; (env-vals (map (lambda (v) - ; (list 'macro (cdr v))) - ; defined-macros)) - ; ;; Pass defined macros so nested macros can be expanded - ; (env (create-environment env-vars env-vals))) + (let* ((env-vars (map car defined-macros)) + (env-vals (map (lambda (v) + (list 'macro (cdr v))) + defined-macros)) + ;; Pass defined macros so nested macros can be expanded + (env (create-environment env-vars env-vals))) (eval (list - macro-val + (cdr macro) (list 'quote exp) (Cyc-er-rename mac-env) Cyc-er-compare?) - mac-env)))));) + mac-env)))))) ; TODO: get macro name, transformer ; TODO: let-syntax forms diff --git a/scheme/cyclone/transforms.sld b/scheme/cyclone/transforms.sld index 6646cbaf..a26fd4d6 100644 --- a/scheme/cyclone/transforms.sld +++ b/scheme/cyclone/transforms.sld @@ -788,18 +788,21 @@ ;; `(define ,name ,(expand body env)))) - ((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)))) -;((macro:macro? exp *defined-macros*) -; ;(trace:info (list 'expanding exp)) -; (expand ;; Could expand into another macro -; (macro:expand exp *defined-macros*) -; 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)))) + +;; 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 'TODO-env *defined-macros*) + env)) (else (map diff --git a/scheme/cyclone/util.sld b/scheme/cyclone/util.sld index 00aac29d..67288e02 100644 --- a/scheme/cyclone/util.sld +++ b/scheme/cyclone/util.sld @@ -224,7 +224,7 @@ (define (Cyc-er-rename mac-env) (lambda (sym) sym)) ; TODO: temporary placeholder, see below -TODO: I think we're ready to cut back over to this now? +;TODO: I think we're ready to cut back over to this now? ;(define (Cyc-er-rename mac-env) ; Notes: