The Tealish language for the Algorand Virtual Machine.
Project description
Tealish is a readable language for the Algorand Virtual Machine. It enables developers to write TEAL in a procedural style optimized for readability.
Tealish transpiles to Teal rather than compiling directly to AVM bytecode. The produced Teal is as close to handwritten idiomatic Teal as possible. The original source Tealish (including comments) is included as comments in the generated Teal. The generated Teal is intended to be readable and auditable. The generated Teal should not be surprising - the Tealish writer should be able to easily imagine the generated Teal.
Tealish is not a general purpose programming language. It is designed specifically for writing contracts for the AVM, optimizing for common patterns.
Status
Tealish is has been used to write large production contracts but it is not currently considered Production Ready for general use. It may have unexpected behavior outside of the scenarios it has been used for until now.
Docs
https://tealish.readthedocs.io/
Installation
pip install tealish
Minimal Example
A simple example demonstrating assertions, state, if statements and inner transactions:
#pragma version 6
if Txn.OnCompletion == UpdateApplication:
assert(Txn.Sender == Global.CreatorAddress)
exit(1)
end
assert(Txn.OnCompletion == NoOp)
int counter = app_global_get("counter")
counter = counter + 1
app_global_put("counter", counter)
if counter == 10:
inner_txn:
TypeEnum: Pay
Receiver: Txn.Sender
Amount: 10000000
end
elif counter > 10:
exit(0)
end
exit(1)
Compiling
tealish compile examples/minimal_example/counter_prize.tl
This will produce counter_prize.teal
in the build
subdirectory.
Editor Support
A VS Code extension for syntax highlighting of Tealish & TEAL is available here
Starter Template
#pragma version 7
if Txn.ApplicationID == 0:
# Create app
exit(1)
end
switch Txn.OnCompletion:
NoOp: main
OptIn: opt_in
CloseOut: close_out
UpdateApplication: update_app
DeleteApplication: delete_app
end
block opt_in:
# Disallow Opt In
exit(0)
end
block close_out:
# Disallow Closing Out
exit(0)
end
block update_app:
# Only allow the Creator to update the app
exit(Txn.Sender == Global.CreatorAddress)
end
block delete_app:
# Only allow the Creator to delete the app
exit(Txn.Sender == Global.CreatorAddress)
end
block main:
switch Txn.ApplicationArgs[0]:
"method_a": method_a
"method_b": method_b
"method_c": method_c
end
block method_a:
# some statements here
exit(1)
end
block method_b:
# some statements here
exit(1)
end
block method_c:
# some statements here
exit(1)
end
end
Design Goals
Tealish is designed first and foremost to be a more readable version of Teal. The biggest difference between Teal and Tealish is the stack is made implicit in Tealish instead of being explicit as in Teal.
Readability is achieved by the following:
- Multiple operations on a single line
- Semantic names for scratch slots (variables)
- Aliases for values on stack
- Named constants
- High level language concepts (if/elif/else, loops, switches)
- A simple style convention
Safety Features:
- Readability
- Named scratch slots
- Scoped scratch slots
- Type checking
Any Teal opcode can be used in Tealish in a procedural style. Additionally there is syntactic sugar for some common operations. When explicit stack manipulation is required raw Teal can be used inline within a Tealish program.
Tealish is a procedural language, executed from top to bottom. Statements can exist inside blocks or at the top level.
The first statement of a program is the entry point of the program. The program can exit on any line.
Execution can branch from one block to another using jump
or switch
statements.
Blocks are used to define scopes. Variables, Functions and Blocks are scoped to the block they are defined in and are available to any nested blocks.
Blocks are not functions:
- they do not take arguments
- they do not have independent stack space
- they are not re-entrant
Functions are used to define reusable pieces of functionality. They can take arguments and return values. They can read variables from the scope in which they are defined but they may not assign to variables outside their local scope. Functions may have side effects through the use of state manipulation or inner transactions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tealish-0.0.1a2.tar.gz
.
File metadata
- Download URL: tealish-0.0.1a2.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 843def3245c157956dfd9f8c61bf47a91e556dadf946276709fa5c9392de9111 |
|
MD5 | 91c31566e036b2b5dc91b366870835ba |
|
BLAKE2b-256 | a2c7b9b036f7d212adff58130e29b979a560254bee3cdbd521b9e1fc73a410a4 |
File details
Details for the file tealish-0.0.1a2-py3-none-any.whl
.
File metadata
- Download URL: tealish-0.0.1a2-py3-none-any.whl
- Upload date:
- Size: 36.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc28409a68793b85c93663ca824fed8c933e6bc50bf9d3caad423f8b9f62235c |
|
MD5 | 22f3f8174494ebb858e90dbefa1de069 |
|
BLAKE2b-256 | ab17b54c69f44c708b2d1ad7c32f1136caf446f7dd3371c9ae7919a8237444fd |