mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +02:00
WIP
This commit is contained in:
parent
32a2a72ab5
commit
3e71e94ae8
1 changed files with 24 additions and 2 deletions
|
@ -367,6 +367,10 @@
|
||||||
;; - env => Environment used to expand macros
|
;; - env => Environment used to expand macros
|
||||||
;;
|
;;
|
||||||
(define (analyze exp env)
|
(define (analyze exp env)
|
||||||
|
;(newline)
|
||||||
|
;(display "/* ")
|
||||||
|
;(display (list 'analyze exp))
|
||||||
|
;(display " */")
|
||||||
(cond ((self-evaluating? exp)
|
(cond ((self-evaluating? exp)
|
||||||
(analyze-self-evaluating exp))
|
(analyze-self-evaluating exp))
|
||||||
((quoted? exp) (analyze-quoted exp))
|
((quoted? exp) (analyze-quoted exp))
|
||||||
|
@ -440,6 +444,10 @@
|
||||||
(loop (car procs) (cdr procs))))
|
(loop (car procs) (cdr procs))))
|
||||||
|
|
||||||
(define (pre-analyze-application exp a-env)
|
(define (pre-analyze-application exp a-env)
|
||||||
|
(newline)
|
||||||
|
(display "/* ")
|
||||||
|
(display (list 'pre-analyze exp))
|
||||||
|
(display " */ ")
|
||||||
;; 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
|
||||||
|
@ -459,6 +467,10 @@
|
||||||
(lambda () #f)) ; Not found
|
(lambda () #f)) ; Not found
|
||||||
#f))
|
#f))
|
||||||
(expand (lambda (macro-op)
|
(expand (lambda (macro-op)
|
||||||
|
(newline)
|
||||||
|
(display "/* ")
|
||||||
|
(display (list 'expand macro-op (operands exp)))
|
||||||
|
(display " */ ")
|
||||||
(analyze (apply macro-op
|
(analyze (apply macro-op
|
||||||
(list (cons macro-op (operands exp))
|
(list (cons macro-op (operands exp))
|
||||||
(lambda (sym) sym)
|
(lambda (sym) sym)
|
||||||
|
@ -470,10 +482,20 @@
|
||||||
(expand var))
|
(expand var))
|
||||||
;; compiled macro in compound form
|
;; compiled macro in compound form
|
||||||
((compound-macro? var)
|
((compound-macro? var)
|
||||||
(expand (Cyc-get-cvar (cadr 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
|
||||||
;; standard interpreted macro
|
;; standard interpreted macro
|
||||||
((compound-macro? op)
|
((compound-macro? op)
|
||||||
(expand (cdr op)))
|
(expand (cdr op))) ;; ?? correct? need to test this
|
||||||
|
;(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)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue