WIP - migrating first macros to libraries

This commit is contained in:
Justin Ethier 2015-08-13 22:53:51 -04:00
parent 82e908d670
commit 9b96d13857
3 changed files with 44 additions and 16 deletions

7
TODO
View file

@ -11,6 +11,13 @@ Working TODO list. should start creating issues for these to get them out of her
if necessary, write makefile directive to automate rebuilding cyclone for macro development
- macros
- tried moving 'and macro from base to trans, and recompiled/reinstalled modules and exec's.
seemed to work OK with meta file installed.
but without meta file, it seems and is not expanded and cyclone tries to call it
directly during execution, which of course segfaults.
need to understand why it is not expanded. also double-check but it must have worked
fine when meta file was installed, because did not see segfaults at that time.
* thought: if we go with meta files, the compiler can revert back
to using compiled macros if we do not install the meta files.
just an idea, may be a hack or not feasible. not an awful idea to

View file

@ -80,11 +80,32 @@
flush-output-port
read-line
features
and
or
)
(begin
;; Features implemented by this Scheme
(define (features) '(cyclone r7rs exact-closed))
(define-syntax and
(er-macro-transformer
(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))))))
(define-syntax or
(er-macro-transformer
(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)))))))))
;; TODO: The whitespace characters are space, tab, line feed, form feed (not in parser yet), and carriage return.
(define call-with-current-continuation call/cc)
;; TODO: this is from r7rs, but is not really good enough by itself

View file

@ -139,22 +139,22 @@
(define (get-macros) *defined-macros*)
(define *defined-macros*
(list
(cons 'and
(lambda (expr rename compare)
(cond ((null? (cdr expr))) ;; TODO (?): #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 'and
; (lambda (expr rename compare)
; (cond ((null? (cdr expr))) ;; TODO (?): #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 (expr rename compare)