... form built-in

This commit is contained in:
ESL 2023-04-14 11:34:47 -04:00
parent 2c9383768e
commit fbd24ee7e7
4 changed files with 850 additions and 832 deletions

1562
k.c

File diff suppressed because it is too large Load diff

View file

@ -302,6 +302,7 @@
[(syntax-rules) (xform-syntax-rules tail env)] [(syntax-rules) (xform-syntax-rules tail env)]
[(syntax-length) (xform-syntax-length tail env)] [(syntax-length) (xform-syntax-length tail env)]
[(syntax-error) (xform-syntax-error tail env)] [(syntax-error) (xform-syntax-error tail env)]
[(...) (xform-... tail env)]
[else (if (integrable? hval) [else (if (integrable? hval)
(xform-integrable hval tail env) (xform-integrable hval tail env)
(if (procedure? hval) (if (procedure? hval)
@ -378,7 +379,7 @@
[(#\p) (>= n 0)] [(#\m) (>= n 1)] [(#\c) (>= n 2)] [(#\x) (>= n 1)] [(#\p) (>= n 0)] [(#\m) (>= n 1)] [(#\c) (>= n 2)] [(#\x) (>= n 1)]
[(#\u) (<= 0 n 1)] [(#\b) (<= 1 n 2)] [(#\t) (<= 2 n 3)] [(#\u) (<= 0 n 1)] [(#\b) (<= 1 n 2)] [(#\t) (<= 2 n 3)]
[(#\#) (>= n 0)] [(#\@) #f] [(#\#) (>= n 0)] [(#\@) #f]
[else #f])) [else #f]))
(define (xform-integrable ig tail env) (define (xform-integrable ig tail env)
(if (integrable-argc-match? (integrable-type ig) (length tail)) (if (integrable-argc-match? (integrable-type ig) (length tail))
@ -542,11 +543,8 @@
(apply x-error args) (apply x-error args)
(x-error "improper syntax-error form" (cons 'syntax-error tail))))) (x-error "improper syntax-error form" (cons 'syntax-error tail)))))
(define (xform-... tail env)
; ellipsis denotation is used for comparisons only (x-error "improper use of ... in syntax form" (cons '... tail)))
(define denotation-of-default-ellipsis
(make-binding '... (lambda (sexp env) (x-error "improper use of ..." sexp))))
(define *transformers* (define *transformers*
(list (list
@ -567,7 +565,7 @@
(make-binding 'begin 'begin) (make-binding 'begin 'begin)
(make-binding 'if 'if) (make-binding 'if 'if)
(make-binding 'body 'body) (make-binding 'body 'body)
denotation-of-default-ellipsis)) (make-binding '... '...)))
(define (top-transformer-env id) (define (top-transformer-env id)
(let ([bnd (find-top-binding id *transformers*)]) (let ([bnd (find-top-binding id *transformers*)])
@ -594,14 +592,17 @@
; make transformer procedure from the rules ; make transformer procedure from the rules
(define (syntax-rules* mac-env ellipsis pat-literals rules) (define (syntax-rules* mac-env ellipsis pat-literals rules)
(define (pat-literal? id) (memq id pat-literals)) (define (pat-literal? id) (memq id pat-literals))
(define (not-pat-literal? id) (not (pat-literal? id))) (define (not-pat-literal? id) (not (pat-literal? id)))
(define (ellipsis-pair? x) (define (ellipsis-pair? x)
(and (pair? x) (ellipsis? (car x)))) (and (pair? x) (ellipsis? (car x))))
(define (ellipsis-denotation? den)
(and (binding? den) (eq? (binding-val den) '...)))
(define (ellipsis? x) (define (ellipsis? x)
(if ellipsis (if ellipsis
(eq? x ellipsis) (eq? x ellipsis)
(and (id? x) (eq? (mac-env x) denotation-of-default-ellipsis)))) (and (id? x) (ellipsis-denotation? (mac-env x)))))
; List-ids returns a list of the non-ellipsis ids in a ; List-ids returns a list of the non-ellipsis ids in a
; pattern or template for which (pred? id) is true. If ; pattern or template for which (pred? id) is true. If

View file

@ -266,6 +266,7 @@
[(syntax-rules) (xform-syntax-rules tail env)] [(syntax-rules) (xform-syntax-rules tail env)]
[(syntax-length) (xform-syntax-length tail env)] [(syntax-length) (xform-syntax-length tail env)]
[(syntax-error) (xform-syntax-error tail env)] [(syntax-error) (xform-syntax-error tail env)]
[(...) (xform-... tail env)]
[else (if (integrable? hval) [else (if (integrable? hval)
(xform-integrable hval tail env) (xform-integrable hval tail env)
(if (procedure? hval) (if (procedure? hval)
@ -342,7 +343,7 @@
[(#\p) (>= n 0)] [(#\m) (>= n 1)] [(#\c) (>= n 2)] [(#\x) (>= n 1)] [(#\p) (>= n 0)] [(#\m) (>= n 1)] [(#\c) (>= n 2)] [(#\x) (>= n 1)]
[(#\u) (<= 0 n 1)] [(#\b) (<= 1 n 2)] [(#\t) (<= 2 n 3)] [(#\u) (<= 0 n 1)] [(#\b) (<= 1 n 2)] [(#\t) (<= 2 n 3)]
[(#\#) (>= n 0)] [(#\@) #f] [(#\#) (>= n 0)] [(#\@) #f]
[else #f])) [else #f]))
(define (xform-integrable ig tail env) (define (xform-integrable ig tail env)
(if (integrable-argc-match? (integrable-type ig) (length tail)) (if (integrable-argc-match? (integrable-type ig) (length tail))
@ -506,11 +507,8 @@
(apply x-error args) (apply x-error args)
(x-error "improper syntax-error form" (cons 'syntax-error tail))))) (x-error "improper syntax-error form" (cons 'syntax-error tail)))))
(define (xform-... tail env)
; ellipsis denotation is used for comparisons only (x-error "improper use of ... in syntax form" (cons '... tail)))
(define denotation-of-default-ellipsis
(make-binding '... (lambda (sexp env) (x-error "improper use of ..." sexp))))
(define *transformers* (define *transformers*
(list (list
@ -531,7 +529,7 @@
(make-binding 'begin 'begin) (make-binding 'begin 'begin)
(make-binding 'if 'if) (make-binding 'if 'if)
(make-binding 'body 'body) (make-binding 'body 'body)
denotation-of-default-ellipsis)) (make-binding '... '...)))
(define (top-transformer-env id) (define (top-transformer-env id)
(let ([bnd (find-top-binding id *transformers*)]) (let ([bnd (find-top-binding id *transformers*)])
@ -562,14 +560,17 @@
; make transformer procedure from the rules ; make transformer procedure from the rules
(define (syntax-rules* mac-env ellipsis pat-literals rules) (define (syntax-rules* mac-env ellipsis pat-literals rules)
(define (pat-literal? id) (memq id pat-literals)) (define (pat-literal? id) (memq id pat-literals))
(define (not-pat-literal? id) (not (pat-literal? id))) (define (not-pat-literal? id) (not (pat-literal? id)))
(define (ellipsis-pair? x) (define (ellipsis-pair? x)
(and (pair? x) (ellipsis? (car x)))) (and (pair? x) (ellipsis? (car x))))
(define (ellipsis-denotation? den)
(and (binding? den) (eq? (binding-val den) '...)))
(define (ellipsis? x) (define (ellipsis? x)
(if ellipsis (if ellipsis
(eq? x ellipsis) (eq? x ellipsis)
(and (id? x) (eq? (mac-env x) denotation-of-default-ellipsis)))) (and (id? x) (ellipsis-denotation? (mac-env x)))))
; List-ids returns a list of the non-ellipsis ids in a ; List-ids returns a list of the non-ellipsis ids in a
; pattern or template for which (pred? id) is true. If ; pattern or template for which (pred? id) is true. If

86
t.c
View file

@ -147,9 +147,9 @@ char *t_code[] = {
")[72}'(y13:syntax-lambda),.1v?{.6,.3,@(y19:xform-syntax-lambda)[72}'(y" ")[72}'(y13:syntax-lambda),.1v?{.6,.3,@(y19:xform-syntax-lambda)[72}'(y"
"12:syntax-rules),.1v?{.6,.3,@(y18:xform-syntax-rules)[72}'(y13:syntax-" "12:syntax-rules),.1v?{.6,.3,@(y18:xform-syntax-rules)[72}'(y13:syntax-"
"length),.1v?{.6,.3,@(y19:xform-syntax-length)[72}'(y12:syntax-error),." "length),.1v?{.6,.3,@(y19:xform-syntax-length)[72}'(y12:syntax-error),."
"1v?{.6,.3,@(y18:xform-syntax-error)[72}.1U0?{.6,.3,.3,@(y16:xform-inte" "1v?{.6,.3,@(y18:xform-syntax-error)[72}'(y3:...),.1v?{.6,.3,@(y9:xform"
"grable)[73}.1K0?{.6,${.9,.9,.6[02},.6,@(y5:xform)[73}.6,.3,.3,@(y10:xf" "-...)[72}.1U0?{.6,.3,.3,@(y16:xform-integrable)[73}.1K0?{.6,${.9,.9,.6"
"orm-call)[73", "[02},.6,@(y5:xform)[73}.6,.3,.3,@(y10:xform-call)[73",
"P", "xform-sexp->datum", "P", "xform-sexp->datum",
"%1.0,,#0.0,&1{%1${.2,@(y3:id?)[01}?{.0,@(y7:id->sym)[11}.0p?{${.2d,:0^" "%1.0,,#0.0,&1{%1${.2,@(y3:id?)[01}?{.0,@(y7:id->sym)[11}.0p?{${.2d,:0^"
@ -301,20 +301,19 @@ char *t_code[] = {
"1}?{.0aS0}{f}?{.0,@(y7:x-error),@(y13:apply-to-list)[32}.1,'(y12:synta" "1}?{.0aS0}{f}?{.0,@(y7:x-error),@(y13:apply-to-list)[32}.1,'(y12:synta"
"x-error)c,'(s26:improper syntax-error form),@(y7:x-error)[32", "x-error)c,'(s26:improper syntax-error form),@(y7:x-error)[32",
"C", 0, "P", "xform-...",
"&0{%2.0,'(s19:improper use of ...),@(y7:x-error)[22},'(y3:...)c@!(y30:" "%2.0,'(y3:...)c,'(s34:improper use of ... in syntax form),@(y7:x-error"
"denotation-of-default-ellipsis)", ")[22",
"C", 0, "C", 0,
"@(y30:denotation-of-default-ellipsis),'(y4:body),'(y4:body)c,'(y2:if)," "'(y3:...),'(y3:...)c,'(y4:body),'(y4:body)c,'(y2:if),'(y2:if)c,'(y5:be"
"'(y2:if)c,'(y5:begin),'(y5:begin)c,'(y6:withcc),'(y6:withcc)c,'(y5:let" "gin),'(y5:begin)c,'(y6:withcc),'(y6:withcc)c,'(y5:letcc),'(y5:letcc)c,"
"cc),'(y5:letcc)c,'(y12:syntax-error),'(y12:syntax-error)c,'(y13:syntax" "'(y12:syntax-error),'(y12:syntax-error)c,'(y13:syntax-length),'(y13:sy"
"-length),'(y13:syntax-length)c,'(y12:syntax-rules),'(y12:syntax-rules)" "ntax-length)c,'(y12:syntax-rules),'(y12:syntax-rules)c,'(y13:syntax-la"
"c,'(y13:syntax-lambda),'(y13:syntax-lambda)c,'(y7:lambda*),'(y7:lambda" "mbda),'(y13:syntax-lambda)c,'(y7:lambda*),'(y7:lambda*)c,'(y6:lambda),"
"*)c,'(y6:lambda),'(y6:lambda)c,'(y4:set&),'(y4:set&)c,'(y4:set!),'(y4:" "'(y6:lambda)c,'(y4:set&),'(y4:set&)c,'(y4:set!),'(y4:set!)c,'(y5:quote"
"set!)c,'(y5:quote),'(y5:quote)c,'(y13:define-syntax),'(y13:define-synt" "),'(y5:quote)c,'(y13:define-syntax),'(y13:define-syntax)c,'(y6:define)"
"ax)c,'(y6:define),'(y6:define)c,'(y6:syntax),'(y6:syntax)c,l(i18)@!(y1" ",'(y6:define)c,'(y6:syntax),'(y6:syntax)c,l(i18)@!(y14:*transformers*)",
"4:*transformers*)",
"P", "top-transformer-env", "P", "top-transformer-env",
"%1@(y14:*transformers*),.1A3,.0p?{.0d,.0p?{'(y12:syntax-rules),.1aq}{f" "%1@(y14:*transformers*),.1A3,.0p?{.0d,.0p?{'(y12:syntax-rules),.1aq}{f"
@ -333,34 +332,35 @@ char *t_code[] = {
"%!2.0u?{@(y19:top-transformer-env)}{.0a},.3,.3,@(y5:xform)[33", "%!2.0u?{@(y19:top-transformer-env)}{.0a},.3,.3,@(y5:xform)[33",
"P", "syntax-rules*", "P", "syntax-rules*",
"%4,,,,,,,#0#1#2#3#4#5#6.9,&1{%1:0,.1A0]1}.!0.0,&1{%1${.2,:0^[01}~]1}.!" "%4,,,,,,,,#0#1#2#3#4#5#6#7.(i10),&1{%1:0,.1A0]1}.!0.0,&1{%1${.2,:0^[01"
"1.3,&1{%1.0p?{.0a,:0^[11}f]1}.!2.7,.9,&2{%1:0?{:0,.1q]1}${.2,@(y3:id?)" "}~]1}.!1.4,&1{%1.0p?{.0a,:0^[11}f]1}.!2&0{%1.0p?{'(y3:...),.1dq]1}f]1}"
"[01}?{@(y30:denotation-of-default-ellipsis),${.3,:1[01}q]1}f]1}.!3.2,&" ".!3.3,.9,.(i11),&3{%1:0?{:0,.1q]1}${.2,@(y3:id?)[01}?{${.2,:1[01},:2^["
"1{%3n,.2,.2,,#0:0,.1,.8,&3{%3${.2,@(y3:id?)[01}?{.1?{${.2,:0[01}}{f}?{" "11}f]1}.!4.2,&1{%3n,.2,.2,,#0:0,.1,.8,&3{%3${.2,@(y3:id?)[01}?{.1?{${."
".2,.1c]3}.2]3}.0V0?{.2,.2,.2X0,:1^[33}.0p?{${.2d,:2^[01}?{${.4,.4,.4dd" "2,:0[01}}{f}?{.2,.1c]3}.2]3}.0V0?{.2,.2,.2X0,:1^[33}.0p?{${.2d,:2^[01}"
",:1^[03},t,.2a,:1^[33}${.4,.4,.4d,:1^[03},.2,.2a,:1^[33}.2]3}.!0.0^_1[" "?{${.4,.4,.4dd,:1^[03},t,.2a,:1^[33}${.4,.4,.4d,:1^[03},.2,.2a,:1^[33}"
"33}.!4.4,.2,.4,.3,.(i11),&5{%3k3,.0,,#0.1,&1{%0f,:0[01}.!0n,.5,.5,,#0." ".2]3}.!0.0^_1[33}.!5.5,.2,.4,.3,.(i12),&5{%3k3,.0,,#0.1,&1{%0f,:0[01}."
"4,.1,:4,:3,:2,:1,:0,.(i16),&8{%3,#0:7,.4,&2{%1.0?{:0]1}:1^[10}.!0${.3," "!0n,.5,.5,,#0.4,.1,:4,:3,:2,:1,:0,.(i16),&8{%3,#0:7,.4,&2{%1.0?{:0]1}:"
"@(y3:id?)[01}?{${.3,:2^[01}?{${.4,@(y3:id?)[01}?{${.3,:1[01},${.5,:0[0" "1^[10}.!0${.3,@(y3:id?)[01}?{${.3,:2^[01}?{${.4,@(y3:id?)[01}?{${.3,:1"
"1}q}{f},.1^[41}.3,.3,.3cc]4}.1V0?{.2V0,.0?{.0}{${:7^[00}}_1.3,.3X0,.3X" "[01},${.5,:0[01}q}{f},.1^[41}.3,.3,.3cc]4}.1V0?{.2V0,.0?{.0}{${:7^[00}"
"0,:6^[43}.1p~?{.2,.2e,.1^[41}${.3d,:3^[01}?{.1ddg,.3L0?{.3g}{${:7^[00}" "}_1.3,.3X0,.3X0,:6^[43}.1p~?{.2,.2e,.1^[41}${.3d,:3^[01}?{.1ddg,.3L0?{"
"},.1,.1I-,.0<0?{${:7^[00}}.0,.6A6,.3,.7A8A6A8,${:4^,t,.(i10)a,:5^[03}," ".3g}{${:7^[00}},.1,.1I-,.0<0?{${:7^[00}}.0,.6A6,.3,.7A8A6A8,${:4^,t,.("
",#0:6,.9,&2{%1${n,.3,:0a,:1^[03},@(y3:cdr),@(y5:%25map1)[12}.!0${.(i12" "i10)a,:5^[03},,#0:6,.9,&2{%1${n,.3,:0a,:1^[03},@(y3:cdr),@(y5:%25map1)"
"),.6,.(i12)dd,:6^[03},${${.7,.6^,@(y5:%25map1)[02},.5c,@(y4:list)c,@(y" "[12}.!0${.(i12),.6,.(i12)dd,:6^[03},${${.7,.6^,@(y5:%25map1)[02},.5c,@"
"4:%25map),@(y13:apply-to-list)[02}L6](i11)}.2p?{${.5,.5d,.5d,:6^[03},." "(y4:list)c,@(y4:%25map),@(y13:apply-to-list)[02}L6](i11)}.2p?{${.5,.5d"
"3a,.3a,:6^[43}:7^[40}.!0.0^_1[63}.!5.7,.2,.6,.5,&4{%3,,,#0#1#2${${.9,&" ",.5d,:6^[03},.3a,.3a,:6^[43}:7^[40}.!0.0^_1[63}.!6.8,.2,.7,.5,&4{%3,,,"
"1{%1:0,.1A3~]1},t,.(i10),:1^[03},:3,&1{%1${${.4,:0[01},@(y6:new-id)[01" "#0#1#2${${.9,&1{%1:0,.1A3~]1},t,.(i10),:1^[03},:3,&1{%1${${.4,:0[01},@"
"},.1c]1},@(y5:%25map1)[02}.!0${:2^,f,.7,:1^[03}.!1.1,:1,&2{%1:1,&1{%1:" "(y6:new-id)[01},.1c]1},@(y5:%25map1)[02}.!0${:2^,f,.7,:1^[03}.!1.1,:1,"
"0^,.1A0]1},t,.2,:0^[13}.!2.5,.5,,#0.8,.4,:0,.8,.4,&5{%2.0,,#0.0,.4,:0," "&2{%1:1,&1{%1:0^,.1A0]1},t,.2,:0^[13}.!2.5,.5,,#0.8,.4,:0,.8,.4,&5{%2."
":1,:2,:3,:4,&7{%1${.2,@(y3:id?)[01}?{:5,.1A3,.0?{.0}{:0,.2A3,.0?{.0}{:" "0,,#0.0,.4,:0,:1,:2,:3,:4,&7{%1${.2,@(y3:id?)[01}?{:5,.1A3,.0?{.0}{:0,"
"1^,.3A3}_1}_1d]1}.0V0?{${.2X0,:6^[01}X1]1}.0p?{${.2d,:2^[01}}{f}?{${.2" ".2A3,.0?{.0}{:1^,.3A3}_1}_1d]1}.0V0?{${.2X0,:6^[01}X1]1}.0p?{${.2d,:2^"
"a,:3^[01},,,#0#1:5,&1{%1:0,.1A3d]1}.!0.2,.4,:4,&3{%!0${.2,:2,@(y4:cons" "[01}}{f}?{${.2a,:3^[01},,,#0#1:5,&1{%1:0,.1A3d]1}.!0.2,.4,:4,&3{%!0${."
"),@(y5:%25map2)[03},:1a,:0^[12}.!1.2u?{${.5dd,:6^[01},${.6a,:6^[01}c]4" "2,:2,@(y4:cons),@(y5:%25map2)[03},:1a,:0^[12}.!1.2u?{${.5dd,:6^[01},${"
"}${.4,.3^,@(y5:%25map1)[02},${.6dd,:6^[01},${.3,.6^c,@(y4:%25map),@(y1" ".6a,:6^[01}c]4}${.4,.3^,@(y5:%25map1)[02},${.6dd,:6^[01},${.3,.6^c,@(y"
"3:apply-to-list)[02}L6]5}.0p?{${.2d,:6^[01},${.3a,:6^[01}c]1}.0]1}.!0." "4:%25map),@(y13:apply-to-list)[02}L6]5}.0p?{${.2d,:6^[01},${.3a,:6^[01"
"0^_1[21}.!0.0^_1[62}.!6.(i10),.7,.7,&3{%2:2,,#0:0,.3,.5,:1,.4,&5{%1.0u" "}c]1}.0]1}.!0.0^_1[21}.!0.0^_1[62}.!7.(i11),.8,.8,&3{%2:2,,#0:0,.3,.5,"
"?{${:3,'(s14:invalid syntax),@(y7:x-error)[02}}.0a,.0a,.1da,${:2,:3,.5" ":1,.4,&5{%1.0u?{${:3,'(s14:invalid syntax),@(y7:x-error)[02}}.0a,.0a,."
",:4^[03},.0?{.0,.0,.3,.5,:1^[63}.4d,:0^[51}.!0.0^_1[21}](i11)", "1da,${:2,:3,.5,:4^[03},.0?{.0,.0,.3,.5,:1^[63}.4d,:0^[51}.!0.0^_1[21}]"
"(i12)",
"S", "install-sr-transformer!", "S", "install-sr-transformer!",
"l4:y12:syntax-rules;l2:y5:quote;y12:syntax-rules;;l2:l3:y1:_;l2:y5:quo" "l4:y12:syntax-rules;l2:y5:quote;y12:syntax-rules;;l2:l3:y1:_;l2:y5:quo"