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

Addr literal #61

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Addr literal #61

wants to merge 7 commits into from

Conversation

barnjamin
Copy link
Contributor

@barnjamin barnjamin commented Jan 29, 2023

Similar to hex looking for 0x... in #60, this looks for addr(...) where the contents are valid b32 strings.

const bytes ADMIN_ADDR = addr(RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU)

This also changes the const map to allow Union[ConstValue, Literal] where Literal is the AST Node type, this way we can use the write_teal defined on the Literal itself (important for LiteralAddress to write addr ...)

Note: this also includes the LiteralHex changes, so if that gets merged this will look cleaner

Marked as draft for now until syntax is decided.

@fergalwalsh
Copy link
Collaborator

I'm wondering if this is somewhere where we should depart from Teal. This syntax is a bit odd to me. I feel like it would be more useful to have a addr(LiteralBytes): e.g. const bytes ADMIN_ADDR = addr("RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU")
In this case it would be a Tealish builtin function rather than a language feature. It could still compile to addr RIKLQ5HEV...

What do you think? I don't have strong feelings about this. It's just an observation.

@barnjamin
Copy link
Contributor Author

barnjamin commented Jan 30, 2023

I'm not crazy about it either TBH.

Ideally I think something like the following might be nicer but would need other considerations

const addr admin_acct = RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU

Where addr is a sort of alias for AVMType.bytes (+ extra processing)

This would also be useful in the case of

const bigint large_prime = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab

Where bigint is also an alias for AVMType.bytes (+ mapping fn calls like +/-/* to the bytemath equivalent)

@pbennett
Copy link

An explicit address type also makes it nicer for code legibility when we can do things like:
addr dest_account = Txn.ApplicationArgs[1]
as opposed to using bytes for everything.
It would also be cleaner in structs for eg.

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

Successfully merging this pull request may close these issues.

None yet

3 participants