Skip to content

Commit

Permalink
Function calls, toint, tobyte, log
Browse files Browse the repository at this point in the history
  • Loading branch information
runvnc authored and pzbitskiy committed Apr 6, 2022
1 parent 8999815 commit 3ed9c4e
Show file tree
Hide file tree
Showing 7 changed files with 1,714 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ gen/java
gen/go
tealang
.idea
*.teal
examples/*.teal
examples/*.tok
7 changes: 5 additions & 2 deletions TealangLexer.l4
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ ASSETPARAMSFIELDS

BUILTINFUNC
: SHA256
| TOINT
| TOBYTE
| KECCAK256
| SHA512
| ED25519
Expand Down Expand Up @@ -156,7 +158,6 @@ APPS : 'apps' ;
ASSETS : 'assets' ;



MINTXNFEE : 'MinTxnFee' ;
MINBALANCE : 'MinBalance' ;
MAXTXNLIFE : 'MaxTxnLife' ;
Expand Down Expand Up @@ -226,7 +227,6 @@ NUMLOCALBYTESLICES : 'LocalNumByteSlice' ;
EXTRAPROGRAMPAGES : 'ExtraProgramPages';



ASSETTOTAL : 'AssetTotal' ;
ASSETDECIMALS : 'AssetDecimals' ;
ASSETDEFAULTFROZEN : 'AssetDefaultFrozen' ;
Expand All @@ -239,6 +239,8 @@ ASSETRESERVE : 'AssetReserve' ;
ASSETFREEZE : 'AssetFreeze' ;
ASSETCLAWBACK : 'AssetClawback' ;

TOINT : 'toint' ;
TOBYTE : 'tobyte' ;
SHA256 : 'sha256' ;
KECCAK256 : 'keccak256' ;
SHA512 : 'sha512_256' ;
Expand All @@ -249,6 +251,7 @@ BTOI : 'btoi' ;
SUBSTRING : 'substring' ;
CONCAT : 'concat' ;
ASSERT : 'assert' ;
LOG : 'log' ;
GETBIT : 'getbit' ;
GETBYTE : 'getbyte' ;
SETBIT : 'setbit' ;
Expand Down
1 change: 1 addition & 0 deletions TealangParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ termination
| RET expr (NEWLINE|SEMICOLON) # TermReturn
| ASSERT LEFTPARA expr RIGHTPARA # TermAssert
| BREAK (NEWLINE|SEMICOLON) # Break
| LOG LEFTPARA expr RIGHTPARA # DoLog
;

decl
Expand Down
2 changes: 1 addition & 1 deletion compiler/bundle_langspec_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func init() {
}
}
EOM
EOM
4 changes: 3 additions & 1 deletion compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ func (n *funCallNode) Codegen(ostream io.Writer) {
} else if n.name == "substring" {
field = fmt.Sprintf(" %s %s", n.index1, n.index2)
}
fmt.Fprintf(ostream, "%s%s\n", n.name, field)
if n.name != "toint" && n.name != "tobyte" {
fmt.Fprintf(ostream, "%s%s\n", n.name, field)
}
} else {
definitionNode := n.definition

Expand Down
1,682 changes: 1,681 additions & 1 deletion compiler/langspec.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions compiler/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ func (l *treeNodeListener) EnterTermAssert(ctx *gen.TermAssertContext) {
l.node = exprNode
}


func (l *treeNodeListener) EnterDoLog(ctx *gen.DoLogContext) {
fmt.Println("ENTER LOG")
name := ctx.LOG().GetText()

listener := newExprListener(l.ctx, l.parent)
exprNode := listener.funCallEnterImpl(name, []gen.IExprContext{ctx.Expr()})

err := exprNode.checkBuiltinArgs()
if err != nil {
parser := ctx.GetParser()
token := ctx.LOG().GetSymbol()
rule := ctx.GetRuleContext()
reportError(err.Error(), parser, token, rule)
return
}

l.node = exprNode
}

func (l *treeNodeListener) EnterBreak(ctx *gen.BreakContext) {
l.node = newBreakNode(l.ctx, l.parent)
}
Expand Down

0 comments on commit 3ed9c4e

Please sign in to comment.