-
Notifications
You must be signed in to change notification settings - Fork 0
[interpreter] Custom descriptor syntax #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add descriptor and describes clauses to the syntax of types. Update the various operations on types accordingly, including text and binary parsing and writing.
let dt = match dt with | ||
| DescribesT (_, dt) -> dt | ||
| NoDescribesT dt -> dt in | ||
let ct = match dt with | ||
| DescriptorT (_, ct) -> ct | ||
| NoDescriptorT ct -> ct in | ||
ct) subtypes in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern comes up a lot. Do you have a recommendation for a name and location for a helper function for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See suggestion for flattening the type.
described_type : | ||
| str_type { fun c x -> NoDescriptorT ($1 c x) } | ||
| LPAR DESCRIPTOR var str_type RPAR | ||
{ fun c x -> DescriptorT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these lines are over 80 char long, but I'm not familiar with the formatting conventions. Is there a good automatic formatter I can run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, formatting of the parser has become a real mess. I don't think there is a tool for auto-formatting mly files. Just follow some of the surrounding code and don't worry about it too much. I'll clean it up eventually. :)
and described_type = | ||
| DescriptorT of heap_type * str_type | ||
| NoDescriptorT of str_type | ||
|
||
and describing_type = | ||
| DescribesT of heap_type * described_type | ||
| NoDescribesT of described_type | ||
|
||
and sub_type = SubT of final * heap_type list * describing_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a more direct syntax, which simplifies pattern matching a lot:
and described_type = | |
| DescriptorT of heap_type * str_type | |
| NoDescriptorT of str_type | |
and describing_type = | |
| DescribesT of heap_type * described_type | |
| NoDescribesT of described_type | |
and sub_type = SubT of final * heap_type list * describing_type | |
and desc_type = DescT of heap_type option * heap_type option * str_type | |
and sub_type = SubT of final * heap_type list * desc_type |
(We could turn the tuple into a record to avoid confusing the two clauses, but I suspect that will be tedious to use.)
@@ -298,9 +316,13 @@ let unroll_def_type (dt : def_type) : sub_type = | |||
Lib.List32.nth sts i | |||
|
|||
let expand_def_type (dt : def_type) : str_type = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that this has to return desc_type now, since the clauses affect a type's structure and become relevant in some operations. With the flat type representation suggested above, they can just be pattern-matched away where not needed.
(FWIW, I should rename str_type to comp_type here, to sync with the spec.)
described_type : | ||
| str_type { fun c x -> NoDescriptorT ($1 c x) } | ||
| LPAR DESCRIPTOR var str_type RPAR | ||
{ fun c x -> DescriptorT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, formatting of the parser has become a real mess. I don't think there is a tool for auto-formatting mly files. Just follow some of the surrounding code and don't worry about it too much. I'll clean it up eventually. :)
described_type : | ||
| str_type { fun c x -> NoDescriptorT ($1 c x) } | ||
| LPAR DESCRIPTOR var str_type RPAR | ||
{ fun c x -> DescriptorT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ fun c x -> DescriptorT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } | |
{ fun c x -> DescriptorT (VarHT (StatX ($3 c type_).it), $4 c x) } |
describing_type : | ||
| described_type { fun c x -> NoDescribesT ($1 c x) } | ||
| LPAR DESCRIBES var described_type RPAR | ||
{ fun c x -> DescribesT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ fun c x -> DescribesT ((fun y -> VarHT (StatX y.it)) ($3 c type_), ($4 c x)) } | |
{ fun c x -> DescribesT (VarHT (StatX ($3 c type_).it), $4 c x) } |
let dt = match dt with | ||
| DescribesT (_, dt) -> dt | ||
| NoDescribesT dt -> dt in | ||
let ct = match dt with | ||
| DescriptorT (_, ct) -> ct | ||
| NoDescriptorT ct -> ct in | ||
ct) subtypes in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See suggestion for flattening the type.
@@ -466,12 +466,22 @@ str_type : | |||
| LPAR ARRAY array_type RPAR { fun c x -> DefArrayT ($3 c) } | |||
| LPAR FUNC func_type RPAR { fun c x -> DefFuncT ($3 c) } | |||
|
|||
described_type : | |||
| str_type { fun c x -> NoDescriptorT ($1 c x) } | |||
| LPAR DESCRIPTOR var str_type RPAR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected this, i.e., treating the clauses more like extra fields:
| LPAR DESCRIPTOR var str_type RPAR | |
| LPAR DESCRIPTOR var RPAR str_type |
|
||
describing_type : | ||
| described_type { fun c x -> NoDescribesT ($1 c x) } | ||
| LPAR DESCRIBES var described_type RPAR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| LPAR DESCRIBES var described_type RPAR | |
| LPAR DESCRIBES var RPAR described_type |
Add descriptor and describes clauses to the syntax of types. Update the
various operations on types accordingly, including text and binary
parsing and writing.