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

Add "builtin" macros to the assembly #4

Closed
1 of 2 tasks
SamWilsn opened this issue Feb 9, 2021 · 4 comments
Closed
1 of 2 tasks

Add "builtin" macros to the assembly #4

SamWilsn opened this issue Feb 9, 2021 · 4 comments
Labels
A-assembler Area: assembler C-enhance Category: a request for an improvement

Comments

@SamWilsn
Copy link
Contributor

SamWilsn commented Feb 9, 2021

Add a couple constant functions to the assembly to make it easier to write. For example (signatures to be bike-shedded):

  • selector(...)
  • include(...)

selector(...)

Description

selector(...) is replaced by the function selector of the given solidity function signature.

Example

push4 selector("updatePool(address)")    ; actually pushes 0x7b46c54f
eq
push :label 
jumpi

include(...)

include(...) is replaced by the opcodes (and constants, etc) from the given path. Only valid outside of an opcode.

Example

main.evm

push :hello
include("other.evm")

other.evm

jumpdest :hello
stop

Output

push :hello
jumpdest :hello
stop
@SamWilsn SamWilsn changed the title Add "builtin" methods to the assembly Add "builtin" macros to the assembly Feb 9, 2021
@SamWilsn
Copy link
Contributor Author

Should we differentiate between functions, like selector() that compute a value, and include() which copies opcodes?

@lightclient lightclient added the C-enhance Category: a request for an improvement label Mar 10, 2021
@lightclient
Copy link
Contributor

We could use %include "..." instead?

@lightclient
Copy link
Contributor

lightclient commented Mar 10, 2021

There's also two possible use cases here:

  1. Separating code logic - in which case, the code should not have been processed yet
  2. Writing a contract deploy wrapper - here, the code should have been processed so the label values are filled in.

I'm inclined for include(...) to do the first, but not certain how to handle the second. assemble(...) maybe? include_assembled(...)?

@SamWilsn
Copy link
Contributor Author

I think there are actually three cases:

  1. Unassembled instructions, for organization/reuse.
  2. Assembled instructions, for initcode.
  3. Copy bytes, for including the output of other tools, special data/constants, etc.

I like include(...) for (1), and maybe include_bytes(...) or include_hex(...) for (3).

As for (2)... I think I'm partial to include_asm or include_assembled.


I think we want user-defined macros that generate instructions to look the same as the include macros. I don't know if that means using a % or something else. I guess as long as we're consistent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assembler Area: assembler C-enhance Category: a request for an improvement
Projects
None yet
Development

No branches or pull requests

2 participants