-
Notifications
You must be signed in to change notification settings - Fork 111
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
WIP feat: new asm
parser
#1064
base: main
Are you sure you want to change the base?
WIP feat: new asm
parser
#1064
Conversation
Let's start with concrete examples of asm-functions we would like to write and then try to develop some grammar for it. As of now, we should start with instruction sequences and comments (let's use the Tact/Fift syntax for comments). |
i.e. no |
definitely not using this syntax :) |
we might allow asm-blocks to avoid introducing high-level constructions into the assembly language, so the user might able to insert those into loops, etc. |
Hmm, then, something like this we've showed earlier (and have in our tests) won't work anymore:
Proceed with removing that? This kinda goes against POLA. UPD: Edited the original post, saying that the full range of Fift+TVM syntax there was highly experimental and subject to change in next releases. Ok, now we can proceed. |
we haven't documented it, so there is no backwards compatibility violation |
and Tact Kitchen posts are about raw immature things, sneak peek |
WIP WIP WIP
82a65b1
to
f1562ff
Compare
e52f1ec
to
40f118b
Compare
]); | ||
|
||
// NOTE: ok, I might need some help here... | ||
export const ppAstAsmExpressionList: Printer<A.AstAsmExpressionList> = |
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.
c.braced(node.exprs.map(ppAstAsmExpression))
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.
Depending on the order PRs get merged, you might not have this problem here at all :)
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.
Thanks, but I've already removed the asm expression lists from the grammar, such that { ... }
are prohibited. At least until we may or may not make sense of them ourselves and without Fift's aid.
Didn't remove it there in pretty printer yet, but will.
// 1. Instructions cannot contain braces | ||
// 2. Cannot be braces themselves | ||
// 3. Cannot contain lowercase letters, except for the very last position | ||
asmInstruction (TVM instruction) = ~(("{" | "}") ~asmWord) asmWord |
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.
Unfortunately all newline characters get parsed as spaces
and are completely erased from AST. There is no way to pretty-print this at all.
I can imagine only one way to make this work without adding ;
or some other explicit way to terminate lines: put this into a separate grammar with its own spaces
rule.
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.
Hmm, I'm thinking of the Prettier's approach with trying to fit as much as allowed in 80, 120 or other column limits, and put all excesses on new lines. Or, to simply put a newline character after each instruction — to keep all prior primitives required for it on the same line.
The second option sounds best from legibility perspective as well:
asm fun showcase(a: Int, b: Int, c: Int): Int {
s0 s1 s2 XCHG3
s1 s2 s0 XCHG3
DROP2
}
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.
Oh, and it would be nice to also check if the instructions are written on the same line with the opening and closing braces { ... }
, i.e. when the start row of the function body equals its end row. Because if that's the case, we should respect the author's intent and inline everything there: add spaces after instructions, not newlines.
This is another attempt at making the
asm
parser — now we're deliberately limiting ourselves to TVM instructions. In the current iteration it's still possible to write code in a very limited subset of Fift, but only if we won't restrict the list of supported TVM instructions ingrammar.ts
, i.e. during semantical actions on the lexed tokens.TODO:
grammar.ohm
ast.ts
grammar.ts
prettyPrinter.ts
→writeFunction.ts
(to actually have asm instructions written)hash.ts
compare.ts
Issue
Closes #837.
Closes #1030 (once the
grammar.ts
is written, there will be a small check for such gotchas).Checklist