Can't using unquote-splicing in define-pass
Yoxem opened this issue · 2 comments
Yoxem commented
When make a pass that output a L0 type to type-checking, it can't use unquote-splicing but shows "unsaved editor:44:11: unquote-splicing: invalid pattern or template in: (unquote-splicing t*)
#(675 4)". (in DrRacket ver. 6.11). The code is shown below:
#lang racket
(require nanopass/base)
(define (variable? x)
(symbol? x))
(define (constant? x)
(or
(flonum? x)
(integer? x)
(boolean? x)))
(define (datatype? x)
(memq x '(int flo bool void)))
(define-language L0
(terminals
(variable (x))
(datatype (dt))
(constant (c)))
(Expr (e body)
x
c
(lambda ([t* x*] ... ) e))
(Type (t)
dt
(-> t* ... t)
)
)
(define-pass type-inference : L0 (ast) -> (L0 Type) ()
(type-infer : Expr (e) -> Type ()
; constant
[,c (cond
[(flonum? e) 'flo]
[(integer? e) 'int]
[(boolean? e) 'bool])]
[,x 'int]
[(lambda ([,t* ,x*] ... ) ,body)
`(-> ,@t* int) ;FIXIT: unquote-splicing: invalid pattern or template in: (unquote-splicing t*)
]
)
(type-infer ast)
)
(type-inference l0)
However, when set the output to a general s-expression (L0 Type) -> * ()
, and Type () -> * ()
, the error will not be shown.
akeep commented
I’m not as sure about the racket version of the nanopass framework, since I
handed maintenance of this off, but in the Chez Scheme version, the syntax
you are looking for is `(-> ,t* … int) — essentially exactly the syntax you
provided when you defined the language.
This is because there i not really any splicing happening here, instead
when you defined the form (-> t* … t) in the nanopass language, it created
a record with two fields one to hold t*, which is expected to be a list of
type and one to hold t. The syntax looks like you are constructing lists,
but the underlying representation is actually racket structs.
…-andy:)
On February 25, 2021 at 3:43:03 PM, Chen, Chien-ting ( notifications@github.com) wrote:
When make a pass that output a L0 type to type-checking, it can't use
unquote-splicing but shows "unsaved editor:44:11: unquote-splicing: invalid
pattern or template in: (unquote-splicing t*)
#(675 4)". (in DrRacket ver. 6.11).
`#lang racket
(require nanopass/base)
(define (variable? x)
(symbol? x))
(define (constant? x)
(or
(flonum? x)
(integer? x)
(boolean? x)))
(define (datatype? x)
(memq x '(int flo bool void)))
(define-language L0
(terminals
(variable (x))
(datatype (dt))
(constant (c)))
(Expr (e body)
x
c
(lambda ([t* x*] ... ) e))
(Type (t)
dt
(-> t* ... t)
)
)
(define-pass type-inference : L0 (ast) -> (L0 Type) ()
(type-infer : Expr (e) -> Type ()
; constant
[,c (cond
[(flonum? e) 'flo]
[(integer? e) 'int]
[(boolean? e) 'bool])]
[,x 'int]
[(lambda ([,t* ,x*] ... ) ,body)
`(-> ,@t* int) ;FIXIT: unquote-splicing: invalid pattern or template
in: (unquote-splicing t*)
]
)
(type-infer ast)
)
(type-inference l0)However, when set the output to a general s-expression(L0
Type) -> * (), and Type () -> * () `, the error will not be shown.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#34>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA3TL462QRYW6VT624PFILTA3N7RANCNFSM4YHNYMLQ>
.
Yoxem commented
I was also told by a Racket user (@dannypsnl) that the syntax (that @akeep mentioned above) ,t* … instead of ,@t*
is that I want and I've found that it is true. I think that the issue can be closed. Thank you very much.