mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Fixed code that expands eval'd macros, general cleanup
This commit is contained in:
parent
2c2c5b9da1
commit
32bf682db7
2 changed files with 33 additions and 47 deletions
|
@ -11,7 +11,7 @@
|
|||
;(scheme cyclone libraries) ;; for handling import sets
|
||||
(scheme base)
|
||||
(scheme file)
|
||||
(scheme write)
|
||||
;(scheme write) ;; Only used for debugging
|
||||
(scheme read))
|
||||
(export
|
||||
;environment
|
||||
|
@ -445,68 +445,53 @@
|
|||
|
||||
(define (pre-analyze-application exp a-env)
|
||||
;; Notes:
|
||||
;;
|
||||
;; look up symbol in env, and expand if it is a macro
|
||||
;; Adds some extra overhead into eval, which is not ideal. may need to
|
||||
;; reduce that overhead later...
|
||||
;;(write (list 'JAE-DEBUG 'expanding exp)) ;; DEBUG-only
|
||||
|
||||
;; TODO: need to use common rename/compare functions
|
||||
;; instead of fudging them here. maybe keep common
|
||||
;; functions in the macros module and hook into them???
|
||||
|
||||
;; see macro-expand in that module. believe these are the only
|
||||
;; two places so far that introduce instances of rename/compare?
|
||||
(let* ((op (operator exp))
|
||||
(var (if (symbol? op)
|
||||
(_lookup-variable-value op a-env
|
||||
(lambda () #f)) ; Not found
|
||||
#f))
|
||||
(expand (lambda (macro-op)
|
||||
(newline)
|
||||
(display "/* ")
|
||||
(display (list 'expand macro-op (operands exp)
|
||||
(car exp)
|
||||
(macro? var)
|
||||
(compound-macro? var)
|
||||
(macro? macro-op)
|
||||
(Cyc-get-cvar (cadr var)) ;; this is what is analyzed
|
||||
(compound-macro? op)
|
||||
))
|
||||
(display " */ ")
|
||||
(analyze (apply macro-op
|
||||
(list (cons (car exp) (operands exp))
|
||||
(lambda (sym) sym)
|
||||
(lambda (a b) (eq? a b))))
|
||||
a-env))))
|
||||
(newline)
|
||||
(display "/* ")
|
||||
(display (list 'pre-analyze
|
||||
(macro? var)
|
||||
(compound-macro? var)
|
||||
(compound-macro? op)
|
||||
exp))
|
||||
(display " */ ")
|
||||
;; TODO: need to use common rename/compare functions
|
||||
;; instead of fudging them here. maybe keep common
|
||||
;; functions in the macros module and hook into them???
|
||||
;;
|
||||
;; see macro-expand in that module. believe these are the only
|
||||
;; two places so far that introduce instances of rename/compare?
|
||||
(rename (lambda (sym) sym))
|
||||
(compare? (lambda (a b) (eq? a b)))
|
||||
(expand
|
||||
(lambda (macro-op)
|
||||
(if (macro? macro-op)
|
||||
;; Compiled macro, call directly
|
||||
(analyze (apply macro-op
|
||||
(list (cons (car exp) (operands exp))
|
||||
rename
|
||||
compare?))
|
||||
a-env)
|
||||
;; Interpreted macro, build expression and eval
|
||||
(let ((expr (cons macro-op
|
||||
(list (cons 'quote
|
||||
(list (cons (car exp)
|
||||
(operands exp))))
|
||||
rename
|
||||
compare?))))
|
||||
(analyze
|
||||
(eval expr a-env) ;; Expand macro
|
||||
a-env))))))
|
||||
(cond
|
||||
;; compiled macro
|
||||
((macro? var)
|
||||
(expand var))
|
||||
;; compiled macro in compound form
|
||||
;; compiled or interpreted macro in compound form
|
||||
((compound-macro? var)
|
||||
(newline)
|
||||
(display "/* ")
|
||||
(display (list 'compound-macro var))
|
||||
(display " */ ")
|
||||
|
||||
(let ((macro (Cyc-get-cvar (cadr var))))
|
||||
(if (macro? macro) ;; compiled macro
|
||||
(expand macro)
|
||||
(expand (analyze macro a-env))))) ;; interpreted, make sure macr is expanded first
|
||||
;; TODO: may need to optimize macros by expanding them just once when constructing env
|
||||
(expand macro)))
|
||||
;; standard interpreted macro
|
||||
((compound-macro? op)
|
||||
(expand (cdr op))) ;; ?? correct? need to test this
|
||||
;(expand (analyze (cdr op) a-env))) ;; ?? correct? need to test this
|
||||
(expand (cdr op)))
|
||||
;; normal function
|
||||
(else
|
||||
(analyze-application exp a-env)))))
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
;; tbd how this parameter would be combined with eval's global env,
|
||||
;; because it would need to extend it.
|
||||
;; could eval expose a function to extend the global env (or any env)?
|
||||
(test 1 2 3) ; breaks
|
||||
(test 1 2 3)
|
||||
;(test 1 2 3) ; breaks
|
||||
;(my-or 1 2 3) ; breaks
|
||||
(and ''test ''test2))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue