Package: tealish
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.StatusTealish 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.Docshttps://tealish.readthedocs.io/Installationpip install tealishMinimal ExampleA simple example demonstrating assertions, state, if statements and inner transactions:#pragma version 6ifTxn.OnCompletion==UpdateApplication:assert(Txn.Sender==Global.CreatorAddress)exit(1)endassert(Txn.OnCompletion==NoOp)intcounter=app_global_get("counter")counter=counter+1app_global_put("counter",counter)ifcounter==10:inner_txn:TypeEnum:PayReceiver:Txn.SenderAmount:10000000endelifcounter>10:exit(0)endexit(1)Compilingtealish compile examples/minimal_example/counter_prize.tlThis will producecounter_prize.tealin thebuildsubdirectory.Editor SupportA VS Code extension for syntax highlighting of Tealish & TEAL is availablehereStarter Template#pragma version 7ifTxn.ApplicationID==0:# Create appexit(1)endswitchTxn.OnCompletion:NoOp:mainOptIn:opt_inCloseOut:close_outUpdateApplication:update_appDeleteApplication:delete_appendblockopt_in:# Disallow Opt Inexit(0)endblockclose_out:# Disallow Closing Outexit(0)endblockupdate_app:# Only allow the Creator to update the appexit(Txn.Sender==Global.CreatorAddress)endblockdelete_app:# Only allow the Creator to delete the appexit(Txn.Sender==Global.CreatorAddress)endblockmain:switchTxn.ApplicationArgs[0]:"method_a":method_a"method_b":method_b"method_c":method_cendblockmethod_a:# some statements hereexit(1)endblockmethod_b:# some statements hereexit(1)endblockmethod_c:# some statements hereexit(1)endendDesign GoalsTealish 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 lineSemantic names for scratch slots (variables)Aliases for values on stackNamed constantsHigh level language concepts (if/elif/else, loops, switches)A simple style conventionSafety Features:ReadabilityNamed scratch slotsScoped scratch slotsType checkingAny 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 usingjumporswitchstatements.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 argumentsthey do not have independent stack spacethey are not re-entrantFunctions 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.