forked from WebAssembly/spec
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Wonho Shin <[email protected]> Co-authored-by: Andreas Rossberg <[email protected]> Co-authored-by: DJ <[email protected]>
- Loading branch information
1 parent
7de8a3a
commit 056aebe
Showing
25 changed files
with
3,265 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
;; Allocation | ||
|
||
|
||
def $funcs(externval*) : funcaddr* | ||
def $funcs(epsilon) = epsilon | ||
def $funcs((FUNC fa) externval'*) = fa $funcs(externval'*) | ||
def $funcs(externval externval'*) = $funcs(externval'*) | ||
-- otherwise | ||
|
||
def $globals(externval*) : globaladdr* | ||
def $globals(epsilon) = epsilon | ||
def $globals((GLOBAL ga) externval'*) = ga $globals(externval'*) | ||
def $globals(externval externval'*) = $globals(externval'*) | ||
-- otherwise | ||
|
||
def $tables(externval*) : tableaddr* | ||
def $tables(epsilon) = epsilon | ||
def $tables((TABLE ta) externval'*) = ta $tables(externval'*) | ||
def $tables(externval externval'*) = $tables(externval'*) | ||
-- otherwise | ||
|
||
def $mems(externval*) : memaddr* | ||
def $mems(epsilon) = epsilon | ||
def $mems((MEM ma) externval'*) = ma $mems(externval'*) | ||
def $mems(externval externval'*) = $mems(externval'*) | ||
-- otherwise | ||
|
||
|
||
def $instexport(funcaddr*, globaladdr*, tableaddr*, memaddr*, export) : exportinst | ||
def $instexport(fa*, ga*, ta*, ma*, EXPORT name (FUNC x)) = { NAME name, VALUE (FUNC fa*[x]) } | ||
def $instexport(fa*, ga*, ta*, ma*, EXPORT name (GLOBAL x)) = { NAME name, VALUE (GLOBAL ga*[x]) } | ||
def $instexport(fa*, ga*, ta*, ma*, EXPORT name (TABLE x)) = { NAME name, VALUE (TABLE ta*[x]) } | ||
def $instexport(fa*, ga*, ta*, ma*, EXPORT name (MEM x)) = { NAME name, VALUE (MEM ma*[x]) } | ||
|
||
|
||
def $allocfunc(store, moduleinst, func) : (store, funcaddr) | ||
def $allocfunc(s, m, func) = (s[.FUNC =.. fi], |s.FUNC|) | ||
-- if fi = { MODULE m, CODE func } | ||
|
||
def $allocfuncs(store, moduleinst, func*) : (store, funcaddr*) | ||
def $allocfuncs(s, m, epsilon) = (s, epsilon) | ||
def $allocfuncs(s, m, func func'*) = (s_2, fa fa'*) | ||
-- if (s_1, fa) = $allocfunc(s, m, func) | ||
-- if (s_2, fa'*) = $allocfuncs(s_1, m, func'*) | ||
|
||
def $allocglobal(store, globaltype, val) : (store, globaladdr) | ||
def $allocglobal(s, globaltype, val) = (s[.GLOBAL =.. gi], |s.GLOBAL|) | ||
-- if gi = { TYPE globaltype, VALUE val } | ||
|
||
def $allocglobals(store, globaltype*, val*) : (store, globaladdr*) | ||
def $allocglobals(s, epsilon, epsilon) = (s, epsilon) | ||
def $allocglobals(s, globaltype globaltype'*, val val'*) = (s_2, ga ga'*) | ||
-- if (s_1, ga) = $allocglobal(s, globaltype, val) | ||
-- if (s_2, ga'*) = $allocglobals(s_1, globaltype'*, val'*) | ||
|
||
def $alloctable(store, tabletype) : (store, tableaddr) | ||
def $alloctable(s, `[i .. j] rt) = (s[.TABLE =.. ti], |s.TABLE|) | ||
-- if ti = { TYPE (`[i .. j] rt), ELEM (REF.NULL rt)^i } | ||
|
||
def $alloctables(store, tabletype*) : (store, tableaddr*) | ||
def $alloctables(s, epsilon) = (s, epsilon) | ||
def $alloctables(s, tabletype tabletype'*) = (s_2, ta ta'*) | ||
-- if (s_1, ta) = $alloctable(s, tabletype) | ||
-- if (s_2, ta'*) = $alloctables(s_1, tabletype'*) | ||
|
||
def $allocmem(store, memtype) : (store, memaddr) | ||
def $allocmem(s, `[i .. j] I8) = (s[.MEM =.. mi], |s.MEM|) | ||
-- if mi = { TYPE (`[i .. j] I8), DATA 0^(i * 64 * $Ki()) } | ||
|
||
def $allocmems(store, memtype*) : (store, memaddr*) | ||
def $allocmems(s, epsilon) = (s, epsilon) | ||
def $allocmems(s, memtype memtype'*) = (s_2, ma ma'*) | ||
-- if (s_1, ma) = $allocmem(s, memtype) | ||
-- if (s_2, ma'*) = $allocmems(s_1, memtype'*) | ||
|
||
def $allocelem(store, reftype, ref*) : (store, elemaddr) | ||
def $allocelem(s, rt, ref*) = (s[.ELEM =.. ei], |s.ELEM|) | ||
-- if ei = { TYPE rt, ELEM ref* } | ||
|
||
def $allocelems(store, reftype*, (ref*)*) : (store, elemaddr*) | ||
def $allocelems(s, epsilon, epsilon) = (s, epsilon) | ||
def $allocelems(s, rt rt'*, ref* ref'**) = (s_2, ea ea'*) | ||
-- if (s_1, ea) = $allocelem(s, rt, ref*) | ||
-- if (s_2, ea'*) = $allocelems(s_2, rt'*, ref'**) | ||
|
||
def $allocdata(store, byte*) : (store, dataaddr) | ||
def $allocdata(s, byte*) = (s[.DATA =.. di], |s.DATA|) | ||
-- if di = { DATA byte* } | ||
|
||
def $allocdatas(store, byte**) : (store, dataaddr*) | ||
def $allocdatas(s, epsilon) = (s, epsilon) | ||
def $allocdatas(s, byte* byte'**) = (s_2, da da'*) | ||
-- if (s_1, da) = $allocdata(s, byte*) | ||
-- if (s_2, da'*) = $allocdatas(s_1, byte'**) | ||
|
||
|
||
def $allocmodule(store, module, externval*, val*, (ref*)*) : (store, moduleinst) | ||
def $allocmodule(s, module, externval*, val*, (ref*)*) = (s_6, m) | ||
-- if module = | ||
MODULE | ||
import* | ||
func^n_func | ||
(GLOBAL globaltype expr_1)^n_global | ||
(TABLE tabletype)^n_table | ||
(MEMORY memtype)^n_mem | ||
(ELEM rt expr_2* elemmode?)^n_elem | ||
(DATA byte* datamode?)^n_data | ||
start? | ||
export* | ||
-- if fa_ex* = $funcs(externval*) | ||
-- if ga_ex* = $globals(externval*) | ||
-- if ta_ex* = $tables(externval*) | ||
-- if ma_ex* = $mems(externval*) | ||
-- if fa* = $(|s.FUNC|+i_func)^(i_func<n_func) | ||
-- if ga* = $(|s.GLOBAL|+i_global)^(i_global<n_global) | ||
-- if ta* = $(|s.TABLE|+i_table)^(i_table<n_table) | ||
-- if ma* = $(|s.MEM|+i_mem)^(i_mem<n_mem) | ||
-- if ea* = $(|s.ELEM|+i_elem)^(i_elem<n_elem) | ||
-- if da* = $(|s.DATA|+i_data)^(i_data<n_data) | ||
-- if xi* = $instexport(fa_ex* fa*, ga_ex* ga*, ta_ex* ta*, ma_ex* ma*, export)* | ||
-- if m = { | ||
FUNC fa_ex* fa*, | ||
GLOBAL ga_ex* ga*, | ||
TABLE ta_ex* ta*, | ||
MEM ma_ex* ma*, | ||
ELEM ea*, | ||
DATA da*, | ||
EXPORT xi* | ||
} | ||
-- if (s_1, fa*) = $allocfuncs(s, m, func^n_func) | ||
-- if (s_2, ga*) = $allocglobals(s_1, globaltype^n_global, val*) | ||
-- if (s_3, ta*) = $alloctables(s_2, tabletype^n_table) | ||
-- if (s_4, ma*) = $allocmems(s_3, memtype^n_mem) | ||
-- if (s_5, ea*) = $allocelems(s_4, rt^n_elem, (ref*)*) | ||
-- if (s_6, da*) = $allocdatas(s_5, (byte*)^n_data) | ||
|
||
|
||
def $runelem(elem, idx) : instr* | ||
def $runelem(ELEM reftype expr*, i) = epsilon | ||
def $runelem(ELEM reftype expr* (DECLARE), i) = (ELEM.DROP i) | ||
def $runelem(ELEM reftype expr* (TABLE x instr*), i) = | ||
instr* (CONST I32 0) (CONST I32 n) (TABLE.INIT x i) (ELEM.DROP i) | ||
-- if n = |expr*| | ||
|
||
def $rundata(data, idx) : instr* | ||
def $rundata(DATA byte*, i) = epsilon | ||
def $rundata(DATA byte* (MEMORY 0 instr*), i) = | ||
instr* (CONST I32 0) (CONST I32 n) (MEMORY.INIT i) (DATA.DROP i) | ||
-- if n = |byte*| | ||
|
||
|
||
def $concat_instr(instr**) : instr* | ||
def $concat_instr(epsilon) = epsilon | ||
def $concat_instr(instr* instr'**) = instr* $concat_instr(instr'**) | ||
|
||
|
||
def $instantiation(store, module, externval*) : config | ||
def $instantiation(s, module, externval*) = s'; f; instr_elem* instr_data* (CALL x)? | ||
-- if module = MODULE import* func* global* table* mem* elem* data* start? export* | ||
-- if m_init = { | ||
FUNC $funcs(externval*), | ||
GLOBAL $globals(externval*), | ||
TABLE epsilon, | ||
MEM epsilon, | ||
ELEM epsilon, | ||
DATA epsilon, | ||
EXPORT epsilon | ||
} | ||
-- if f_init = { LOCAL epsilon, MODULE m_init } | ||
-- if global* = (GLOBAL globaltype instr_1*)* | ||
-- (Step_read : s; f_init; instr_1* ~> val)* | ||
-- if elem* = (ELEM reftype (instr_2*)* elemmode?)* | ||
-- (Step_read : s; f_init; instr_2* ~> ref)** | ||
-- if (s', m) = $allocmodule(s, module, externval*, val*, (ref*)*) | ||
-- if f = { LOCAL epsilon, MODULE m } | ||
-- if n_elem = |elem*| | ||
-- if instr_elem* = $concat_instr($runelem(elem*[i], i)^(i<n_elem)) | ||
-- if n_data = |data*| | ||
-- if instr_data* = $concat_instr($rundata(data*[j], j)^(j<n_data)) | ||
-- if start? = (START x)? | ||
|
||
|
||
def $invocation(store, funcaddr, val*) : config | ||
def $invocation(s, fa, val^n) = s; f; val^n (CALL_ADDR fa) | ||
-- if m = { | ||
FUNC epsilon, | ||
GLOBAL epsilon, | ||
TABLE epsilon, | ||
MEM epsilon, | ||
ELEM epsilon, | ||
DATA epsilon, | ||
EXPORT epsilon | ||
} | ||
-- if f = { LOCAL epsilon, MODULE m } | ||
-- if $funcinst((s; f))[fa].CODE = FUNC functype valtype* expr | ||
-- if functype = valtype_param^n -> valtype_res^k |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.