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))
|
(tagged-list? 'define-syntax exp))
|
||||||
|
|
||||||
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
|
(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
|
;TODO: seems to be a problem with below. may want to revert and try and see if that works, then
|
||||||
restore this and debug...
|
;restore this and debug...
|
||||||
(define (macro:expand macro-val exp mac-env)
|
;
|
||||||
(let* ( ;(macro (assoc (car exp) defined-macros))
|
; TODO: probably want to look at contents of defined-macros and figure out
|
||||||
(compiled-macro? (or (macro? (Cyc-get-cvar macro-val))
|
; exactly how the env needs to represent macros (compiled and eval'd)
|
||||||
(procedure? macro-val))))
|
;
|
||||||
|
(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
|
;; Invoke ER macro
|
||||||
(cond
|
(cond
|
||||||
((not macro-val)
|
((not macro)
|
||||||
(error "macro not found" exp))
|
(error "macro not found" exp))
|
||||||
(compiled-macro?
|
(compiled-macro?
|
||||||
((Cyc-get-cvar macro-val)
|
((Cyc-get-cvar (cdr macro))
|
||||||
exp
|
exp
|
||||||
(Cyc-er-rename mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?))
|
Cyc-er-compare?))
|
||||||
(else
|
(else
|
||||||
;; Assume evaluated macro
|
;; Assume evaluated macro
|
||||||
;(let* ((env-vars (map car defined-macros))
|
(let* ((env-vars (map car defined-macros))
|
||||||
; (env-vals (map (lambda (v)
|
(env-vals (map (lambda (v)
|
||||||
; (list 'macro (cdr v)))
|
(list 'macro (cdr v)))
|
||||||
; defined-macros))
|
defined-macros))
|
||||||
; ;; Pass defined macros so nested macros can be expanded
|
;; Pass defined macros so nested macros can be expanded
|
||||||
; (env (create-environment env-vars env-vals)))
|
(env (create-environment env-vars env-vals)))
|
||||||
(eval
|
(eval
|
||||||
(list
|
(list
|
||||||
macro-val
|
(cdr macro)
|
||||||
(list 'quote exp)
|
(list 'quote exp)
|
||||||
(Cyc-er-rename mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?)
|
Cyc-er-compare?)
|
||||||
mac-env)))));)
|
mac-env))))))
|
||||||
|
|
||||||
; TODO: get macro name, transformer
|
; TODO: get macro name, transformer
|
||||||
; TODO: let-syntax forms
|
; TODO: let-syntax forms
|
||||||
|
|
|
@ -788,18 +788,21 @@
|
||||||
;;
|
;;
|
||||||
`(define ,name ,(expand body env))))
|
`(define ,name ,(expand body env))))
|
||||||
|
|
||||||
((symbol? (car exp))
|
; Newer macro expansion code, but not ready yet
|
||||||
(let ((val (env:lookup (car exp) env #f)))
|
; ((symbol? (car exp))
|
||||||
(if val
|
; (let ((val (env:lookup (car exp) env #f)))
|
||||||
(macro:expand val exp env)
|
; (if val
|
||||||
(map
|
; (macro:expand val exp env)
|
||||||
(lambda (expr) (expand expr env))
|
; (map
|
||||||
exp))))
|
; (lambda (expr) (expand expr env))
|
||||||
;((macro:macro? exp *defined-macros*)
|
; exp))))
|
||||||
; ;(trace:info (list 'expanding exp))
|
|
||||||
; (expand ;; Could expand into another macro
|
;; Older *define-macro* code:
|
||||||
; (macro:expand exp *defined-macros*)
|
((macro:macro? exp *defined-macros*)
|
||||||
; env))
|
;(trace:info (list 'expanding exp))
|
||||||
|
(expand ;; Could expand into another macro
|
||||||
|
(macro:expand 'TODO-val exp 'TODO-env *defined-macros*)
|
||||||
|
env))
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(map
|
(map
|
||||||
|
|
|
@ -224,7 +224,7 @@
|
||||||
(define (Cyc-er-rename mac-env)
|
(define (Cyc-er-rename mac-env)
|
||||||
(lambda (sym) sym)) ; TODO: temporary placeholder, see below
|
(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)
|
;(define (Cyc-er-rename mac-env)
|
||||||
; Notes:
|
; Notes:
|
||||||
|
|
Loading…
Add table
Reference in a new issue