Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

feat: clarify default parameters for passes #45

Open
BrayanCaro opened this issue Jan 30, 2022 · 0 comments
Open

feat: clarify default parameters for passes #45

BrayanCaro opened this issue Jan 30, 2022 · 0 comments

Comments

@BrayanCaro
Copy link

I think we can use default values for extra formal parameters in the define-pass form:

(define-pass name : lang-specifier (formal ...) -> lang-specifier (extra-return-val ...)
  definitions-clause
  processor ...
  body-expr)

And the following code works:

(define-language L
  (entry Expr)
  (terminals
   (number (n)))
  (Expr (e)
        n
        (someop e)))
(define-parser parse-L L)

(define-pass as-bin : L (ir global-ctx) -> L ()
  ( as-binary : Expr (ir [ctx global-ctx]) -> Expr ()
              [,n (modulo n 2)]
              [(someop ,[e? 'val-b -> e]) `(someop ,e)]))
; usage:
; (as-bin (parse-L '(someop 4)) 'val-default)
; or
; ((compose (curryr as-bin 'val-default) parse-L) '(someop 4))

But only the processor as-binary can have the default value, and I think It would be cool to be able to also write default values as the define statement does:

;                           ⬐---------here---------⬎
(define-pass as-bin : L (ir [global-ctx 'val-default]) -> L ()
  ( as-binary : Expr (ir [ctx global-ctx]) -> Expr ()
              [,n (modulo n 2)]
              [(someop ,[e? 'val-b -> e]) `(someop ,e)]))

; suggested usage:
; (as-bin (parse-L '(someop 4)))
; or
; ((compose as-bin parse-L) '(someop 4))

Note

The documentation does not say anything about default parameters:

formal is an identifier representing a formal argument.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant