Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dan): basic template macro (#4358)
Description --- * New engine package to encapsulate the macro logic. In the future we may consider extracting it to a separate project or repo. * The user template code handling is encapsulated into the `ast` module. * Each section of the generated template code is split into different modules: * **definition**: generates a verbatim module of the user code, needed for the template macro to compile properly. * **abi**: generates the ABI section of the contract wasm, needed in the engine to know the contract function signatures. * **dispatcher**: executes a call invocation, by deciding which user-defined code to call and encoding the result. * **dependencies**: helper functions that need to be included into the wasm, as well as the `tari_engine` import signature. * Current limitations: * The function arguments are not yet processed and encoded, so at the moment it only supports user-defined functions with no parameters. But return values are handled. * Struct fields and `self` is not handled yet * Calls to the tari engine import are not being done Motivation and Context --- Template developers need an ergonomic way of writing contract code. This PR aims to provide a new macro `template!` to allow easy development of new _basic_ contracts. And for _basic_ I mean no struct fields, no resource access and no composability, only stateless functions. Those features will be added in future PRs. With this PR, the existing "Hello World" example is rewritten as: ``` use tari_template_macros::template; template! { struct HelloWorld {} impl HelloWorld { pub fn greet() -> String { "Hello World!".to_string() } } } ``` How Has This Been Tested? --- * The unit test for the "Hello World" contract example now is written using the new macro. It compiles and runs in our engine successfully * New unit tests for some complex sections of the macro
- Loading branch information