This commit is contained in:
Justin Ethier 2015-08-21 23:18:28 -04:00
parent 6cf2a6a4af
commit d929acb220
2 changed files with 35 additions and 29 deletions

1
TODO
View file

@ -31,6 +31,7 @@ Working TODO list. should start creating issues for these to get them out of her
- eval'd macro within compiled macro - ?? - eval'd macro within compiled macro - ??
- compiled macro within eval'd macro - works fine - compiled macro within eval'd macro - works fine
- eval'd macro within eval'd macro - does not work yet, see test2.scm. would need to be able to add macros to an eval env so they can be seen by subsequent macros that use them - eval'd macro within eval'd macro - does not work yet, see test2.scm. would need to be able to add macros to an eval env so they can be seen by subsequent macros that use them
- *defined-macros* is redundant now with the list in the macros module, except for appending macros from meta files. should pick one list (probably module one) and consolidate
* thought: if we go with meta files, the compiler can revert back * thought: if we go with meta files, the compiler can revert back
to using compiled macros if we do not install the meta files. to using compiled macros if we do not install the meta files.

View file

@ -1,6 +1,7 @@
(define-library (scheme cyclone macros) (define-library (scheme cyclone macros)
(import (scheme base) (import (scheme base)
;(scheme write) (scheme eval) ;; TODO: without this line, compilation just
;; silently fails. WTF??
(scheme cyclone util)) (scheme cyclone util))
; TODO: really need export-all for these cyclone libs!! ; TODO: really need export-all for these cyclone libs!!
(export (export
@ -28,42 +29,46 @@
(define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros)) (define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros))
(define (macro:expand exp defined-macros) (define (macro:expand exp defined-macros)
;(display "/* ") (let* (
;(newline) ;; TODO: not good enough, need to actually rename,
;(display "entered macro:expand exp") ;; and keep same results if
;(display " */") ;; the same symbol is renamed more than once
(let ((rename (lambda (sym) ;; TODO: not good enough, need to actually rename, and keep same results if (rename (lambda (sym)
sym)) ;; the same symbol is renamed more than once sym))
(compare? (lambda (sym-a sym-b) ;; TODO: the compare function from exrename. ;; TODO: the compare function from exrename.
(eq? sym-a sym-b))) ;; this may need to be more sophisticated ;; this may need to be more sophisticated
) (compare? (lambda (sym-a sym-b)
(let ((macro (assoc (car exp) defined-macros))) (eq? sym-a sym-b)))
(macro (assoc (car exp) defined-macros))
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
(procedure? (cdr macro)))))
;TODO: restructure this to use eval if the macro is not a proc. ;TODO: restructure this to use eval if the macro is not a proc.
; then can try passing in an environment with create-environment. ; then can try passing in an environment with create-environment.
; once eval is extended to work with macros, this could allow it to ; once eval is extended to work with macros, this could allow it to
; expand a macro contained within another ; expand a macro contained within another
;(display "/* ")
;(newline)
;(display (list macro (car exp)
; (Cyc-get-cvar (cdr macro))
; (macro? (Cyc-get-cvar (cdr macro)))))
;(display " */")
;; Invoke ER macro ;; Invoke ER macro
(if macro (cond
((not macro)
(error "macro not found" exp))
(compiled-macro?
((Cyc-get-cvar (cdr macro)) ((Cyc-get-cvar (cdr macro))
;; Pass expression differently depending upon if this is a
;; compiled macro or a cons one that will be called via eval.
;;
;; If a raw lambda (IE, exec using eval), try quoting it
(if (or (macro? (Cyc-get-cvar (cdr macro)))
(procedure? (cdr macro)))
exp exp
(list 'quote exp)) rename
compare?))
(else
;; Assume evaluated macro
(eval
(list
(cdr macro)
(list 'quote exp)
rename rename
compare?) compare?)
exp)))) ;; TODO: error instead?? ;; TODO: environment (would need to create a new macro
;; type in eval though, and then format defined-macros
;; to create an env of macros
)))))
; TODO: get macro name, transformer ; TODO: get macro name, transformer
; TODO: base off of syntactic closures instead of ER macros?? ; TODO: base off of syntactic closures instead of ER macros??