mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-22 07:09:17 +02:00
Reverted to a working state
Now need to rework previous changes to cut-over to macro-environments
This commit is contained in:
parent
5441714fbd
commit
dadabcaa80
3 changed files with 36 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue