Giter Site home page Giter Site logo

vuvoth / tealang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pzbitskiy/tealang

0.0 0.0 0.0 801 KB

Tealang - high level language for Algorand ASC1 and TEAL

License: GNU Affero General Public License v3.0

ANTLR 3.86% Go 93.77% Makefile 1.06% Shell 1.31%

tealang's Introduction

Tealang

High-level language for Algorand Smart Contracts at Layer-1 and its low-level TEAL v6 language. The goal is to abstract the stack-based Algorand Virtual Machine and provide imperative Go/JS/Python-like syntax.

Language Features

  • Integer and bytes types

  • Variables and constants

let var1 = 1
let var2 = 0x123
const myaddr = addr"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ"
  • All binary and unary operations from TEAL
let a = (1 + 2) / 3
let b = ~a
  • Functions
inline function sample1(a) {
    return a - 1
}

function sample2(a) {
    return a + 1
}

function noop() void {
    return
}

function logic() {
    return sample1(2) + sample2(3)
}
  • Condition statements and expressions
function condition(a) {
    let b = if a == 1 { 10 } else { 0 }

    if b == 0 {
        return a
    }
    return 1
}
  • Loops
let y= 2;
for y>0 { y=y-1 }
  • Type checking
function get_string() {
    return "\x32\x33\x34"
}

function logic() {
    let a = 1
    a = get_string()  // <- type check error
    return a
}
  • Accounts state access
function approval() {
    let x = accounts[1].Balance
    return 1
}
  • Globals and txn data access
function logic() {
    let s = global.GroupSize
    let idx = 1
    let a = gtxn[s-1].ApplicationArgs[idx+2];
    return a != "\x01"
}
  • Modules
import stdlib.const

Language guide

Check the language documentation!

Usage

  • Tealang to bytecode

    tealang mycontract.tl -o mycontract.tok
  • Tealang to TEAL

    tealang -c mycontract.tl -o mycontract.teal
  • Tealang logic one-liner to bytecode

    tealang -l '(txn.Sender == "abc") && global.MinTxnFee > 2000' -o mycontract.tok
  • stdin to stdout

    cat mycontract.tl | tealang -s -r - > mycontract.tok
  • Dryrun / trace

    tealang -s -c -d '' examples/basic.tl

Build from sources

Prerequisites

  1. Set up ANTLR4
    make antlr-install
    Refer to the documentation in case of problems.
  2. Install runtime for Go
    go get -u github.com/antlr/antlr4/runtime/Go/antlr
  3. Install and setup go-algorand
    make algorand-install
    Check the Algorand README for detailed build instructions if encounter any issues.

Build and test

make && make test

Optionally build and run Java AST visualizer

make java-gui ARGS=examples/basic.tl

Roadmap

  1. Constant folding.
  2. Improve errors reporting.
  3. Code gen: do not use temp scratch in "assign and use" case.
  4. Code gen: keep track scratch slots and mark as available after freeing with load.

tealang's People

Contributors

algorandskiy avatar pzbitskiy avatar runvnc avatar algoidurovic avatar shiqizng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.