Reverted previous macro migration for now.

Need to stabilize things before macros can relocated to the base library as define-syntax.
This commit is contained in:
Justin Ethier 2015-08-17 22:05:30 -04:00
parent bda12755c1
commit 1444e89d73
2 changed files with 24 additions and 8 deletions

View file

@ -80,14 +80,14 @@
flush-output-port flush-output-port
read-line read-line
features features
and my-and
or my-or
) )
(begin (begin
;; Features implemented by this Scheme ;; Features implemented by this Scheme
(define (features) '(cyclone r7rs exact-closed)) (define (features) '(cyclone r7rs exact-closed))
(define-syntax and (define-syntax my-and
(er-macro-transformer (er-macro-transformer
(lambda (expr rename compare) (lambda (expr rename compare)
(cond ((null? (cdr expr)) #t) (cond ((null? (cdr expr)) #t)
@ -95,7 +95,7 @@
(else (list (rename 'if) (cadr expr) (else (list (rename 'if) (cadr expr)
(cons (rename 'and) (cddr expr)) (cons (rename 'and) (cddr expr))
#f)))))) #f))))))
(define-syntax or (define-syntax my-or
(er-macro-transformer (er-macro-transformer
(lambda (expr rename compare) (lambda (expr rename compare)
(cond ((null? (cdr expr)) #f) (cond ((null? (cdr expr)) #f)

View file

@ -139,6 +139,22 @@
(define (get-macros) *defined-macros*) (define (get-macros) *defined-macros*)
(define *defined-macros* (define *defined-macros*
(list (list
(cons 'and
(lambda (expr rename compare)
(cond ((null? (cdr expr)) #t)
((null? (cddr expr)) (cadr expr))
(else (list (rename 'if) (cadr expr)
(cons (rename 'and) (cddr expr))
#f)))))
(cons 'or
(lambda (expr rename compare)
(cond ((null? (cdr expr)) #f)
((null? (cddr expr)) (cadr expr))
(else
(list (rename 'let) (list (list (rename 'tmp) (cadr expr)))
(list (rename 'if) (rename 'tmp)
(rename 'tmp)
(cons (rename 'or) (cddr expr))))))))
; (cons 'let (lambda (exp rename compare) (let=>lambda exp))) ; (cons 'let (lambda (exp rename compare) (let=>lambda exp)))
(cons 'let (cons 'let
(lambda (expr rename compare) (lambda (expr rename compare)
@ -1028,10 +1044,10 @@
;; ;;
`(define ,name ,(expand body)))) `(define ,name ,(expand body))))
TODO: this is not working (I think) because we get "symbol and" and not "compiled macro and". ;TODO: this is not working (I think) because we get "symbol and" and not "compiled macro and".
would have to look up symbol to see if it is a macro, and then get the macro that way... ;would have to look up symbol to see if it is a macro, and then get the macro that way...
may need to have a *define-macros* equivalent but in the compiled code, similar to globals. ;may need to have a *define-macros* equivalent but in the compiled code, similar to globals.
need to be able to look up var in a list and get the (macro?) instance. ;need to be able to look up var in a list and get the (macro?) instance.
((or (macro? exp) ((or (macro? exp)
(macro:macro? exp *defined-macros*)) (macro:macro? exp *defined-macros*))
(expand ;; Could expand into another macro (expand ;; Could expand into another macro