Comments (2)
I think there are 3 levels where template substitution can be used:
- Tealish
- Teal
- Bytecode
So far I have been doing it at the bytecode level. For example in Tinyman we have logicsigs per pool. These are generated from a template and the asset ids are inserted by replacing specific bytes of the bytecode. It works this way so that the frontend can generate the final logicsig without needing to compile Teal.
I understand in your case you currently have a single PyTeal file which compiles to a single Teal file but then at assembly time you generate specific Teal files with the values before assembling.
In theory you could also replace the values in the PyTeal/Tealish before compiling to Teal but I assume there is a reason you prefer to do the replacement at the Teal level?
Supporting this would require accepting TMPL_
prefixed names in places that expect int or byes. I'd be tempted to restrict this to const
declarations. E.g. const int APP_ID = TMPL_APP_ID
. Would that work for you? With #49 that would result in the following Teal #define APP_ID TMPL_APP_ID
.
from tealish.
For me at least, constants would be fine as my templates are explicitly for network-specific asset and application IDs.
I also do bytecode manipulation for LSIGs in the backend, but deployed Smart-Contracts doing the same thing would also do it using the template technique as the deployed smart-contract would need to vary from network to network.
Generically, because the templates are like constants in their use - I don't see how your constant eg wouldn't work fine for pretty much all cases.
I do it at the teal level because the pyteal/beaker/tealish/.. -> TEAL compilation step is part of a 'contract build'. The output should be stable (recreating them should always compile to the same teal) and doesn't vary from environment to environment.
The output of that feeds into another repo which has those teal files as part of their build process - with the TEAL being directly compiled into the backend infra - whether for system tests (substituting just created IDs in a sandbox environment for eg) or for production with values pulled from bootstrapped data specific to each deployment.
from tealish.
Related Issues (20)
- Comments inside Switch break parser HOT 1
- Macro support HOT 3
- Need support for alternative format Bytes values HOT 1
- Provide better error message (or more specific to situation) for evaluation order issues. HOT 2
- Add support for include or import HOT 1
- Add bigint type HOT 1
- VS Code extension? HOT 1
- Comments should be allowed anywhere in the code, including after lines.
- Roadmap
- Replacing the value of a field of a structured box can keep parts of the replaced value HOT 1
- Setting the value of a field of a structured box can overflow onto the next field HOT 1
- Docs - Switch HOT 1
- [BUG] Tealish format error HOT 1
- [BUG]
- [BUG] cannot parse expression with `const int` HOT 1
- Document for loop end is exclusive
- [BUG] Multiple struct with same field names cause wrong TEAL (confused) code HOT 1
- Tealish dont't compile don't give any error just making stuck on terminal with reasigned variable and validated as conditional
- ABI support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tealish.