mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-08 13:37:33 +02:00
Cleanup
This commit is contained in:
parent
e177410706
commit
0578c4963a
3 changed files with 14 additions and 78 deletions
19
cyclone.scm
19
cyclone.scm
|
@ -101,19 +101,7 @@
|
||||||
;; in final compiled program
|
;; in final compiled program
|
||||||
;(set! input-program (add-libs input-program))
|
;(set! input-program (add-libs input-program))
|
||||||
|
|
||||||
;; JAE DEBUG code, remove (or refactor) once working
|
;; Load macros for expansion phase
|
||||||
;(trace:info "JAE DEBUG - compiled macros")
|
|
||||||
;(trace:info
|
|
||||||
; (filter
|
|
||||||
; (lambda (v)
|
|
||||||
; (cond
|
|
||||||
; ((equal? (car v) 'my-or)
|
|
||||||
; (trace:info (list 'my-or (car v) (cdr v) (macro? (Cyc-get-cvar (cdr v)))))
|
|
||||||
; #t)
|
|
||||||
; (else #f)))
|
|
||||||
; ;(macro? (cdr v)))
|
|
||||||
; (Cyc-global-vars)))
|
|
||||||
; TODO: should be able to use this to find all the compiled macros
|
|
||||||
(let ((macros (filter
|
(let ((macros (filter
|
||||||
(lambda (v)
|
(lambda (v)
|
||||||
(macro? (Cyc-get-cvar (cdr v))))
|
(macro? (Cyc-get-cvar (cdr v))))
|
||||||
|
@ -123,11 +111,8 @@
|
||||||
macros
|
macros
|
||||||
*defined-macros*)))
|
*defined-macros*)))
|
||||||
(macro:load-env! *defined-macros* (create-environment '() '()))
|
(macro:load-env! *defined-macros* (create-environment '() '()))
|
||||||
;TODO: try this again, make sure macro is loaded:
|
|
||||||
;(trace:info (list 'defined-macros *defined-macros*))
|
|
||||||
;(trace:info (list 'macro-env (macro:get-env)))
|
|
||||||
;; END JAE DEBUG
|
|
||||||
|
|
||||||
|
;; Expand macros
|
||||||
(set! input-program (expand input-program (macro:get-env)))
|
(set! input-program (expand input-program (macro:get-env)))
|
||||||
(trace:info "---------------- after macro expansion:")
|
(trace:info "---------------- after macro expansion:")
|
||||||
(trace:info input-program) ;pretty-print
|
(trace:info input-program) ;pretty-print
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
define-syntax?
|
define-syntax?
|
||||||
macro:macro?
|
macro:macro?
|
||||||
macro:expand
|
macro:expand
|
||||||
macro:expand2
|
|
||||||
macro:add!
|
macro:add!
|
||||||
macro:load-env!
|
macro:load-env!
|
||||||
macro:get-env
|
macro:get-env
|
||||||
|
@ -44,52 +43,13 @@
|
||||||
(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
|
|
||||||
;restore this and debug...
|
|
||||||
;
|
|
||||||
; TODO: probably want to look at contents of defined-macros and figure out
|
|
||||||
; exactly how the env needs to represent macros (compiled and eval'd)
|
|
||||||
;
|
|
||||||
(define (macro:expand _ exp mac-env defined-macros)
|
|
||||||
(let* ((macro (assoc (car exp) defined-macros))
|
|
||||||
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
|
|
||||||
(procedure? (cdr macro)))))
|
|
||||||
;(newline)
|
|
||||||
;(display "/* ")
|
|
||||||
;(display (list 'macro:expand exp macro compiled-macro?))
|
|
||||||
;(display "*/ ")
|
|
||||||
;; Invoke ER macro
|
|
||||||
(cond
|
|
||||||
((not macro)
|
|
||||||
(error "macro not found" exp))
|
|
||||||
(compiled-macro?
|
|
||||||
((Cyc-get-cvar (cdr macro))
|
|
||||||
exp
|
|
||||||
(Cyc-er-rename mac-env)
|
|
||||||
Cyc-er-compare?))
|
|
||||||
(else
|
|
||||||
;; Assume evaluated macro
|
|
||||||
(let* ((env-vars (map car defined-macros))
|
|
||||||
(env-vals (map (lambda (v)
|
|
||||||
(list 'macro (cdr v)))
|
|
||||||
defined-macros))
|
|
||||||
;; Pass defined macros so nested macros can be expanded
|
|
||||||
(env (create-environment env-vars env-vals)))
|
|
||||||
(eval
|
|
||||||
(list
|
|
||||||
(Cyc-get-cvar (cdr macro))
|
|
||||||
(list 'quote exp)
|
|
||||||
(Cyc-er-rename mac-env)
|
|
||||||
Cyc-er-compare?)
|
|
||||||
env))))))
|
|
||||||
;mac-env))))))
|
|
||||||
|
|
||||||
(define (macro:expand2 exp macro mac-env)
|
(define (macro:expand exp macro mac-env)
|
||||||
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar (cadr macro)))
|
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar (cadr macro)))
|
||||||
(procedure? (cadr macro)))))
|
(procedure? (cadr macro)))))
|
||||||
;(newline)
|
;(newline)
|
||||||
;(display "/* ")
|
;(display "/* ")
|
||||||
;(display (list 'macro:expand2 exp macro compiled-macro?))
|
;(display (list 'macro:expand exp macro compiled-macro?))
|
||||||
;(display "*/ ")
|
;(display "*/ ")
|
||||||
|
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
|
|
|
@ -788,25 +788,16 @@
|
||||||
;;
|
;;
|
||||||
`(define ,name ,(expand body env))))
|
`(define ,name ,(expand body env))))
|
||||||
|
|
||||||
; Newer macro expansion code, but not ready yet
|
|
||||||
((symbol? (car exp))
|
((symbol? (car exp))
|
||||||
(let ((val (env:lookup (car exp) env #f)))
|
(let ((val (env:lookup (car exp) env #f)))
|
||||||
(if (tagged-list? 'macro val)
|
(if (tagged-list? 'macro val)
|
||||||
(expand ; Could expand into another macro
|
(expand ; Could expand into another macro
|
||||||
;(macro:expand 'val exp env *defined-macros*)
|
(macro:expand exp val env)
|
||||||
(macro:expand2 exp val env)
|
|
||||||
env)
|
env)
|
||||||
(map
|
(map
|
||||||
(lambda (expr) (expand expr env))
|
(lambda (expr) (expand expr env))
|
||||||
exp))))
|
exp))))
|
||||||
|
|
||||||
;; Older *define-macro* code:
|
|
||||||
;((macro:macro? exp *defined-macros*)
|
|
||||||
; ;(trace:info (list 'expanding exp))
|
|
||||||
; (expand ;; Could expand into another macro
|
|
||||||
; (macro:expand 'TODO-val exp env *defined-macros*)
|
|
||||||
; env))
|
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(map
|
(map
|
||||||
(lambda (expr) (expand expr env))
|
(lambda (expr) (expand expr env))
|
||||||
|
|
Loading…
Add table
Reference in a new issue