Skip to content

Commit d636e17

Browse files
return_call extension (#60)
* support tail call in grammar & extract function calling logics * when tail call, we can share a continuation for returning * tweak * ignore grammar/.antlr/ * should use `return_call`
1 parent 657fec5 commit d636e17

File tree

10 files changed

+2685
-2538
lines changed

10 files changed

+2685
-2538
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ project/.bloop/bloop.settings.json
2323
conc_gen/*
2424
ccbse_gen/*
2525
headers/gensym/external.hpp
26+
grammar/.antlr/

benchmarks/wasm/sum.wat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(module
2+
(type (;0;) (func (param i32)))
3+
(import "console" "log" (func (type 0)))
4+
(func (param i32 i32) (result i32)
5+
local.get 0
6+
i32.eqz
7+
if (result i32)
8+
local.get 1
9+
else
10+
local.get 0
11+
i32.const 1
12+
i32.sub
13+
local.get 1
14+
local.get 0
15+
i32.add
16+
(return_call 1)
17+
end
18+
)
19+
(func (result i32)
20+
i32.const 10
21+
i32.const 0
22+
(return_call 1))
23+
(export "sum10" (func 2))
24+
)

grammar/WatLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ ELSE: 'else' ;
6868
SELECT: '.select' ;
6969
CALL: 'call' ;
7070
CALL_INDIRECT: 'call_indirect' ;
71+
RETURN_CALL: 'return_call' ;
72+
RETURN_CALL_INDIRECT: 'return_call_indirect' ;
7173

7274
LOCAL_GET: 'local.get' ;
7375
LOCAL_SET: 'local.set' ;

grammar/WatParser.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ plainInstr
133133
| BR_TABLE idx+
134134
| RETURN
135135
| CALL idx
136+
| RETURN_CALL idx
136137
| LOCAL_GET idx
137138
| LOCAL_SET idx
138139
| LOCAL_TEE idx
@@ -177,6 +178,7 @@ selectInstr
177178
callIndirectInstr
178179
/* : CALL_INDIRECT typeUse? callInstrParams */
179180
: CALL_INDIRECT idx? typeUse
181+
| RETURN_CALL_INDIRECT idx? typeUse
180182
;
181183

182184
callInstrParams
@@ -220,6 +222,7 @@ foldedInstr
220222
expr
221223
: plainInstr expr*
222224
| CALL_INDIRECT callExprType
225+
| RETURN_CALL_INDIRECT callExprType
223226
| BLOCK bindVar? block
224227
| LOOP bindVar? block
225228
// | IF bindVar? ifBlock

src/main/java/wasm/WatLexer.java

Lines changed: 1294 additions & 1271 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)