mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +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)
|
(define-library (scheme cyclone macros)
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
;(scheme write) ;; Debug only
|
(scheme write) ;; Debug only
|
||||||
(scheme eval) ;; TODO: without this line, compilation just
|
(scheme eval) ;; TODO: without this line, compilation just
|
||||||
;; silently fails. WTF??
|
;; silently fails. WTF??
|
||||||
(scheme cyclone util))
|
(scheme cyclone util))
|
||||||
|
@ -54,6 +54,10 @@
|
||||||
(let* ((macro (assoc (car exp) defined-macros))
|
(let* ((macro (assoc (car exp) defined-macros))
|
||||||
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
|
(compiled-macro? (or (macro? (Cyc-get-cvar (cdr macro)))
|
||||||
(procedure? (cdr macro)))))
|
(procedure? (cdr macro)))))
|
||||||
|
(newline)
|
||||||
|
(display "/* ")
|
||||||
|
(display (list 'macro:expand exp macro compiled-macro?))
|
||||||
|
(display "*/ ")
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
(cond
|
(cond
|
||||||
((not macro)
|
((not macro)
|
||||||
|
@ -80,25 +84,34 @@
|
||||||
env))))))
|
env))))))
|
||||||
;mac-env))))))
|
;mac-env))))))
|
||||||
|
|
||||||
(define (macro:expand2 macro exp mac-env)
|
(define (macro:expand2 exp macro mac-env)
|
||||||
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar macro))
|
(let* ((compiled-macro? (or (macro? (Cyc-get-cvar (cadr macro)))
|
||||||
(procedure? macro))))
|
(procedure? (cadr macro)))))
|
||||||
|
(newline)
|
||||||
|
(display "/* ")
|
||||||
|
(display (list 'macro:expand2 exp macro compiled-macro?))
|
||||||
|
(display "*/ ")
|
||||||
|
|
||||||
;; Invoke ER macro
|
;; Invoke ER macro
|
||||||
(cond
|
(cond
|
||||||
((not macro)
|
((not macro)
|
||||||
(error "macro not found" exp))
|
(error "macro not found" exp))
|
||||||
(compiled-macro?
|
(compiled-macro?
|
||||||
((Cyc-get-cvar macro)
|
((Cyc-get-cvar (cadr macro))
|
||||||
exp
|
exp
|
||||||
(Cyc-er-rename mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?))
|
Cyc-er-compare?))
|
||||||
(else
|
(else
|
||||||
(eval
|
(eval
|
||||||
(list
|
(list
|
||||||
(Cyc-get-cvar macro)
|
(Cyc-get-cvar (cadr macro))
|
||||||
(list 'quote exp)
|
(list 'quote exp)
|
||||||
(Cyc-er-rename mac-env)
|
(Cyc-er-rename mac-env)
|
||||||
Cyc-er-compare?)
|
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)))))
|
mac-env)))))
|
||||||
|
|
||||||
; TODO: get macro name, transformer
|
; TODO: get macro name, transformer
|
||||||
|
|
|
@ -789,20 +789,23 @@
|
||||||
`(define ,name ,(expand body env))))
|
`(define ,name ,(expand body env))))
|
||||||
|
|
||||||
; Newer macro expansion code, but not ready yet
|
; 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 val
|
(if val
|
||||||
; (macro:expand val exp env)
|
(expand ; Could expand into another macro
|
||||||
; (map
|
(macro:expand 'val exp env *defined-macros*)
|
||||||
; (lambda (expr) (expand expr env))
|
;(macro:expand2 exp val env)
|
||||||
; exp))))
|
env)
|
||||||
|
(map
|
||||||
|
(lambda (expr) (expand expr env))
|
||||||
|
exp))))
|
||||||
|
|
||||||
;; Older *define-macro* code:
|
;; Older *define-macro* code:
|
||||||
((macro:macro? exp *defined-macros*)
|
;((macro:macro? exp *defined-macros*)
|
||||||
;(trace:info (list 'expanding exp))
|
; ;(trace:info (list 'expanding exp))
|
||||||
(expand ;; Could expand into another macro
|
; (expand ;; Could expand into another macro
|
||||||
(macro:expand 'TODO-val exp env *defined-macros*)
|
; (macro:expand 'TODO-val exp env *defined-macros*)
|
||||||
env))
|
; env))
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(map
|
(map
|
||||||
|
|
Loading…
Add table
Reference in a new issue