mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +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 cyclone libraries) ;; for handling import sets
|
||||||
(scheme base)
|
(scheme base)
|
||||||
(scheme file)
|
(scheme file)
|
||||||
(scheme write)
|
;(scheme write) ;; Only used for debugging
|
||||||
(scheme read))
|
(scheme read))
|
||||||
(export
|
(export
|
||||||
;environment
|
;environment
|
||||||
|
@ -445,68 +445,53 @@
|
||||||
|
|
||||||
(define (pre-analyze-application exp a-env)
|
(define (pre-analyze-application exp a-env)
|
||||||
;; Notes:
|
;; Notes:
|
||||||
;;
|
|
||||||
;; look up symbol in env, and expand if it is a macro
|
;; 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
|
;; Adds some extra overhead into eval, which is not ideal. may need to
|
||||||
;; reduce that overhead later...
|
;; 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))
|
(let* ((op (operator exp))
|
||||||
(var (if (symbol? op)
|
(var (if (symbol? op)
|
||||||
(_lookup-variable-value op a-env
|
(_lookup-variable-value op a-env
|
||||||
(lambda () #f)) ; Not found
|
(lambda () #f)) ; Not found
|
||||||
#f))
|
#f))
|
||||||
(expand (lambda (macro-op)
|
;; TODO: need to use common rename/compare functions
|
||||||
(newline)
|
;; instead of fudging them here. maybe keep common
|
||||||
(display "/* ")
|
;; functions in the macros module and hook into them???
|
||||||
(display (list 'expand macro-op (operands exp)
|
;;
|
||||||
(car exp)
|
;; see macro-expand in that module. believe these are the only
|
||||||
(macro? var)
|
;; two places so far that introduce instances of rename/compare?
|
||||||
(compound-macro? var)
|
(rename (lambda (sym) sym))
|
||||||
(macro? macro-op)
|
(compare? (lambda (a b) (eq? a b)))
|
||||||
(Cyc-get-cvar (cadr var)) ;; this is what is analyzed
|
(expand
|
||||||
(compound-macro? op)
|
(lambda (macro-op)
|
||||||
))
|
(if (macro? macro-op)
|
||||||
(display " */ ")
|
;; Compiled macro, call directly
|
||||||
(analyze (apply macro-op
|
(analyze (apply macro-op
|
||||||
(list (cons (car exp) (operands exp))
|
(list (cons (car exp) (operands exp))
|
||||||
(lambda (sym) sym)
|
rename
|
||||||
(lambda (a b) (eq? a b))))
|
compare?))
|
||||||
a-env))))
|
a-env)
|
||||||
(newline)
|
;; Interpreted macro, build expression and eval
|
||||||
(display "/* ")
|
(let ((expr (cons macro-op
|
||||||
(display (list 'pre-analyze
|
(list (cons 'quote
|
||||||
(macro? var)
|
(list (cons (car exp)
|
||||||
(compound-macro? var)
|
(operands exp))))
|
||||||
(compound-macro? op)
|
rename
|
||||||
exp))
|
compare?))))
|
||||||
(display " */ ")
|
(analyze
|
||||||
|
(eval expr a-env) ;; Expand macro
|
||||||
|
a-env))))))
|
||||||
(cond
|
(cond
|
||||||
;; compiled macro
|
;; compiled macro
|
||||||
((macro? var)
|
((macro? var)
|
||||||
(expand var))
|
(expand var))
|
||||||
;; compiled macro in compound form
|
;; compiled or interpreted macro in compound form
|
||||||
((compound-macro? var)
|
((compound-macro? var)
|
||||||
(newline)
|
|
||||||
(display "/* ")
|
|
||||||
(display (list 'compound-macro var))
|
|
||||||
(display " */ ")
|
|
||||||
|
|
||||||
(let ((macro (Cyc-get-cvar (cadr var))))
|
(let ((macro (Cyc-get-cvar (cadr var))))
|
||||||
(if (macro? macro) ;; compiled macro
|
(expand 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
|
|
||||||
;; standard interpreted macro
|
;; standard interpreted macro
|
||||||
((compound-macro? op)
|
((compound-macro? op)
|
||||||
(expand (cdr op))) ;; ?? correct? need to test this
|
(expand (cdr op)))
|
||||||
;(expand (analyze (cdr op) a-env))) ;; ?? correct? need to test this
|
|
||||||
;; normal function
|
;; normal function
|
||||||
(else
|
(else
|
||||||
(analyze-application exp a-env)))))
|
(analyze-application exp a-env)))))
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
;; tbd how this parameter would be combined with eval's global env,
|
;; tbd how this parameter would be combined with eval's global env,
|
||||||
;; because it would need to extend it.
|
;; because it would need to extend it.
|
||||||
;; could eval expose a function to extend the global env (or any env)?
|
;; 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
|
;(my-or 1 2 3) ; breaks
|
||||||
(and ''test ''test2))))
|
(and ''test ''test2))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue