joticajulian / koinos-precompiler-as

generator of main.ts file and ABI
MIT License
0 stars 1 forks source link

suggestion: use `decorators` instead of `comment` to describe the entry points #1

Open roaminro opened 1 year ago

roaminro commented 1 year ago

The AssemblyScript compiler allows for passing a transform script as a parameter to the asc cli (see https://www.assemblyscript.org/compiler.html#transforms). This transform scripts allows you to access the "parsed" AS files to do "whatever" you want. I used this option in the very first version of the AS SDK to allow for describing entry points directly in the A code using decorators (see https://github.com/koinos/koinos-sdk-as/blob/3eabc0453a7650a6a973664c5286f6212c8479e6/tools/koinos-contract-transform.ts), for example:

class Contract {
    @entry_point
    myEntryPoint(...) {
    }
}

I believe it would be a less hacky way to parse the AS code and generate the ABIs than using comments.

Also, decorators can take arguments too, so you could have @entry_point(...args)

What do you think?

joticajulian commented 1 year ago

Very interesting! I didn't know AssemblyScript had this feature. So, it seems a good improvement for the precompiler. Right now I can not work on it because of the amount of changes required. But it's definitely something worth to check and implement.