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
User defined macros #18
Comments
NASM multi-line macro format: %macro prologue 1
push ebp
mov ebp,esp
sub esp,%1
%endmacro |
So you define the macro with Couple follow-up questions: How does invoking the macro look? Something like:
How do nested macros work? What are the scoping rules? Are they file scoped, or globally scoped? What about labels in macros? Something like Rust's macro hygiene or just let them collide? |
Yep, that seems like a good way to invoke a macro. A nested macro would need to have been previously defined and we'll expand it. As we discussed on telegram, the arguments must be constants and the developer will need to prepare the stack to call the macro. |
Also, named arguments. |
final format from @SamWilsn on chat (few changes by me): %def approve_selector()
selector("approve(address,uint256)")
%end
%def transfer_selector(): selector("transfer(address,uint256)")
%macro check_selector($sel, $dest)
dup1
push4 $sel
push2 $dest
jumpi
%end
%check_selector(approve_selector(), .approve)
%check_selector(transfer_selector(), .transfer)
push1 0x00
push1 0x00
revert |
To clarify the example a little bit, we want to introduce two new constructs: MacrosDefinitionSingle- and Multi- LineMacros can be defined in either single-line or multi-line formats. The two formats are distinguished by a colon following the parenthesis closing the argument list. The single-line and multi-line formats are equivalent. Single-Line:
Multi-Line:
ArgumentsTODO BehaviourExpression Macro
Expression macros can take the place of an immediate/label, specifically:
Expression macros cannot take the place of an opcode. An expression macro can accept zero or more arguments, but only:
If a multi-line expression macro has two lines which produce a return value, the assembler should emit an error. A multi-line expression macro with two return values could look like:
Instruction Macro
Instruction macros can take the place of zero or more opcodes, and cannot be used as the argument to push instructions. An instruction macro can accept zero or more arguments, but only:
A single-line style instruction macro can only expand to a single instruction. HygieneLabels defined in a macro (ie.
UsageInstruction macros must be prefixed with a percent sign ( Expression Macro
Instruction Macro
|
I think this is done now! |
Seems that we should come up with a template for macros.
The text was updated successfully, but these errors were encountered: