etk
etk copied to clipboard
feat: negative to unsigned int conversion
Motivation
Resolves https://github.com/quilt/etk/issues/79
Approach
Added uintN()
, a built-in expression macro to convert negative evaluating expressions to positive values. A new expression type Uint
was added to account for the case when the expression needs to be evaluated with context (e.g. user-defined macro). Any feedback is greatly appreciated!
Example
push1 uint8(-1)
evaluates to 0x60ff
.
Alternatives
It may be a bit cleaner to just add built-in macros for max unsigned integer values (e.g. max_uint256()
). I could also see some benefit to implementing bitwise operators (e.g. 1 << 256
). However, the current approach also allows for representing negative integers in two's-compliment, which could be of value.
todo
Will update docs if changes are deemed appropriate.