Refactoring

This commit is contained in:
Justin Ethier 2016-04-30 02:16:22 -04:00
parent e2d158bdd6
commit 6ed5d735f6

View file

@ -782,13 +782,8 @@
;; FUTURE: append the empty (unprinted) value ;; FUTURE: append the empty (unprinted) value
;; instead of #f ;; instead of #f
#f))) #f)))
((app? exp) ((define-c? exp) exp)
(cond ((define-syntax? exp)
;; TODO: could check for a define-syntax here and load into memory
;; if found. would then want to continue expanding. may need to
;; return some value such as #t or NULL as a placeholder, since the
;; define-syntax form would not be carried forward in the compiled code
((define-syntax? exp) ;; TODO: not good enough, should do error checking, and make sure list is big enough for cadr
;(trace:info `(define-syntax ,exp)) ;(trace:info `(define-syntax ,exp))
(let* ((name (cadr exp)) (let* ((name (cadr exp))
(trans (caddr exp)) (trans (caddr exp))
@ -816,7 +811,8 @@
;; (alpha, cps, closure, etc). otherwise code has to be interpreted during expansion ;; (alpha, cps, closure, etc). otherwise code has to be interpreted during expansion
;; ;;
`(define ,name ,(expand body env)))))) `(define ,name ,(expand body env))))))
((define-c? exp) exp) ((app? exp)
(cond
((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)
@ -826,7 +822,6 @@
(map (map
(lambda (expr) (expand expr env)) (lambda (expr) (expand expr env))
exp)))) exp))))
(else (else
(map (map
(lambda (expr) (expand expr env)) (lambda (expr) (expand expr env))
@ -885,10 +880,10 @@
((or (const? this-exp) ((or (const? this-exp)
(prim? this-exp) (prim? this-exp)
(ref? this-exp) (ref? this-exp)
(quote? this-exp)) (quote? this-exp)
(define-c? this-exp))
(expand-body (cons this-exp result) (cdr exp) env)) (expand-body (cons this-exp result) (cdr exp) env))
((or (define? this-exp) ((or (define? this-exp)
(define-c? this-exp)
(define-syntax? this-exp) (define-syntax? this-exp)
(lambda? this-exp) (lambda? this-exp)
(set!? this-exp) (set!? this-exp)