Skip to content
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

Q1ASM encoding redundancy #1072

Open
alecandido opened this issue Oct 15, 2024 · 0 comments
Open

Q1ASM encoding redundancy #1072

alecandido opened this issue Oct 15, 2024 · 0 comments

Comments

@alecandido
Copy link
Member

Since with lark-generated parser, it seems difficult to obtain a satisfactory AST without manually-crafted classes, this generated a bit of redundancy in #868.
Specifically, the Q1ASM instructions are listed twice: in the grammar,

jmp: "jmp" VALUE
jge: "jge" REGISTER "," IMMEDIATE "," VALUE
jlt: "jlt" REGISTER "," IMMEDIATE "," VALUE
loop: "loop" REGISTER "," VALUE

and in the AST classes
class Jmp(Instr):
address: Value
class Jge(Instr):
a: Register
b: Immediate
address: Value
class Jlt(Instr):
a: Register
b: Immediate
address: Value
class Loop(Instr):
a: Register
address: Value

However, the AST classes are more powerful, since they can even host metadata (e.g. storing documentation), that could be useful in runtime usage (e.g. declared clock cycles).

So, at this point, it seems to be worth to resolve the redundancy the other way round: generate the grammar from the classes.

This could be done by loading the string with placeholders, and replacing the placeholders at runtime from the generated classes.
It is only needed during parser creation. So, it's not going to be limiting even when parsing many scripts (if ever), since it will be done once (it could have been done even at "compile time", if Python had a compilation process - but it's not worth to introduce something like a compilation step just for the sake of this, as it would considerably affect the workflow).

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

No branches or pull requests

1 participant