xform-define{-syntax} return errors now

This commit is contained in:
ESL 2024-07-24 16:39:15 -04:00
parent 76e0454141
commit 702a8983fc
2 changed files with 10 additions and 24 deletions

View file

@ -632,28 +632,19 @@
(location-set-val! (xenv-lookup env (car ids) 'set!) (xform #t (car inits) env))
(loop (cdr ids) (cdr inits) (cdr nids) sets lids)])))
; FIXME: make sure that (begin (begin) x (begin)) == x !! (tail-rec includes hack)
(define (xform-begin tail env appos?) ; non-internal
(if (list? tail) ; FIXME: make sure that (begin (begin) x (begin)) == x !! (for include)
(if (list? tail)
(if (list1? tail)
(xform appos? (car tail) env) ; (begin x) == x
(cons 'begin (map (lambda (sexp) (xform #f sexp env)) tail)))
(x-error "improper begin form" (cons 'begin tail))))
(define (xform-define tail env) ; non-internal
(cond [(and (list2? tail) (null? (car tail))) ; idless
(xform #f (cadr tail) env)]
[(and (list2? tail) (id? (car tail)))
(list 'define (id->sym (car tail))
(xform #f (cadr tail) env))]
[(and (list2+? tail) (pair? (car tail)) (id? (caar tail)) (idslist? (cdar tail)))
(list 'define (id->sym (caar tail))
(xform-lambda (cons (cdar tail) (cdr tail)) env))]
[else (x-error "improper define form" (cons 'define tail))]))
(define (xform-define tail env) ; actual code is spread all over
(x-error "definition used as expression" (cons 'define tail)))
(define (xform-define-syntax tail env) ; non-internal
(if (and (list2? tail) (id? (car tail)))
(list 'define-syntax (id->sym (car tail)) (xform #t (cadr tail) env))
(x-error "improper define-syntax form" (cons 'define-syntax tail))))
(define (xform-define-syntax tail env) ; actual code is spread all over
(x-error "syntax definition used as expression" (cons 'define-syntax tail)))
(define (xform-syntax-quote tail env)
(if (list1? tail)

13
t.c
View file

@ -402,17 +402,12 @@ char *t_code[] = {
"c,'(s19:improper begin form),@(y7:x-error)[32",
"P", "xform-define",
"%2${.2,@(y6:list2?)[01}?{.0au}{f}?{.1,.1da,f,@(y5:xform)[23}${.2,@(y6:"
"list2?)[01}?{${.2a,@(y3:id?)[01}}{f}?{${.3,.3da,f,@(y5:xform)[03},${.3"
"a,@(y7:id->sym)[01},'(y6:define),l3]2}${.2,@(y7:list2+?)[01}?{.0ap?{${"
".2aa,@(y3:id?)[01}?{${.2ad,@(y8:idslist?)[01}}{f}}{f}}{f}?{${.3,.3d,.4"
"adc,@(y12:xform-lambda)[02},${.3aa,@(y7:id->sym)[01},'(y6:define),l3]2"
"}.0,'(y6:define)c,'(s20:improper define form),@(y7:x-error)[22",
"%2.0,'(y6:define)c,'(s29:definition used as expression),@(y7:x-error)["
"22",
"P", "xform-define-syntax",
"%2${.2,@(y6:list2?)[01}?{${.2a,@(y3:id?)[01}}{f}?{${.3,.3da,t,@(y5:xfo"
"rm)[03},${.3a,@(y7:id->sym)[01},'(y13:define-syntax),l3]2}.0,'(y13:def"
"ine-syntax)c,'(s27:improper define-syntax form),@(y7:x-error)[22",
"%2.0,'(y13:define-syntax)c,'(s36:syntax definition used as expression)"
",@(y7:x-error)[22",
"P", "xform-syntax-quote",
"%2${.2,@(y6:list1?)[01}?{.0a]2}.0,'(y12:syntax-quote)c,'(s26:improper "