essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

feat: Add support for Arrays in `pint-abi-gen` #761

Closed mitchmindtree closed 2 months ago

mitchmindtree commented 3 months ago

Based on #767.

I thought I'd almost finished this this morning, but after doing some testing I'm realising Array support will require a bit more of an overhaul in abi-gen in order to support them reliably.

The n-dimensional array flattening makes it tricky to provide a nice API that is both aware of the array nesting, while also generating flattened keys for each entry.

I think a proper solution should probably be done as a part of this key construction approach, where we traverse keyed vars while providing context on how the var is nested so that 1. a readable API can be generated (without everything flattened) and 2. the flattened key can still be derived automatically from the nesting.


EDIT: OK, this was a bit of a mind bender but should be good to go!

Includes a new array test in pint-abi-gen-tests that tests ABI generation for various types of multi-dimensional arrays and array/tuple combinations to ensure that the key flattening logic matches the logic in the compiler.

The generated API for arrays isn't yet ideal, but at least makes it possible to set values at arbitrary indices. The main goal of this PR is to land base-level support for arrays, ensure flattened key construction is correct, and lay a foundation for building higher-level APIs on top (e.g. providing whole ranges of values at once).

To-Do