mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP
This commit is contained in:
parent
6bf6b028d2
commit
1244ea5342
2 changed files with 34 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
(define-library (scheme cyclone macros)
|
||||
(import (scheme base)
|
||||
;(scheme write) ;; Debug only
|
||||
(scheme write) ;; Debug only
|
||||
(scheme eval) ;; TODO: without this line, compilation just
|
||||
;; silently fails. WTF??
|
||||
(scheme cyclone util))
|
||||
|
@ -54,6 +54,10 @@
|
|||
(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)
|
||||
|
@ -80,25 +84,34 @@
|
|||
env))))))
|
||||
;mac-env))))))
|
||||
|
||||
(define (macro:expand2 macro exp mac-env)
|
||||
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar macro))
|
||||
(procedure? macro))))
|
||||
(define (macro:expand2 exp macro mac-env)
|
||||
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar (cadr macro)))
|
||||
(procedure? (cadr macro)))))
|
||||
(newline)
|
||||
(display "/* ")
|
||||
(display (list 'macro:expand2 exp macro compiled-macro?))
|
||||
(display "*/ ")
|
||||
|
||||
;; Invoke ER macro
|
||||
(cond
|
||||
((not macro)
|
||||
(error "macro not found" exp))
|
||||
(compiled-macro?
|
||||
((Cyc-get-cvar macro)
|
||||
((Cyc-get-cvar (cadr macro))
|
||||
exp
|
||||
(Cyc-er-rename mac-env)
|
||||
Cyc-er-compare?))
|
||||
(else
|
||||
(eval
|
||||
(list
|
||||
(Cyc-get-cvar macro)
|
||||
(Cyc-get-cvar (cadr macro))
|
||||
(list 'quote exp)
|
||||
(Cyc-er-rename mac-env)
|
||||
Cyc-er-compare?)
|
||||
; TODO: this is broken because mac-env only contains macros, but
|
||||
; we need global-env to handle functions (like null?, caddr, etc).
|
||||
; not sure what the answer is yet... might need to base macro-env
|
||||
; on global-env, and ensure symbol is a macro before expanding
|
||||
mac-env)))))
|
||||
|
||||
; TODO: get macro name, transformer
|
||||
|
|
|
@ -789,20 +789,23 @@
|
|||
`(define ,name ,(expand body env))))
|
||||
|
||||
; Newer macro expansion code, but not ready yet
|
||||
; ((symbol? (car exp))
|
||||
; (let ((val (env:lookup (car exp) env #f)))
|
||||
; (if val
|
||||
; (macro:expand val exp env)
|
||||
; (map
|
||||
; (lambda (expr) (expand expr env))
|
||||
; exp))))
|
||||
((symbol? (car exp))
|
||||
(let ((val (env:lookup (car exp) env #f)))
|
||||
(if val
|
||||
(expand ; Could expand into another macro
|
||||
(macro:expand 'val exp env *defined-macros*)
|
||||
;(macro:expand2 exp val env)
|
||||
env)
|
||||
(map
|
||||
(lambda (expr) (expand expr env))
|
||||
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))
|
||||
;((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
|
||||
(map
|
||||
|
|
Loading…
Add table
Reference in a new issue