-
Notifications
You must be signed in to change notification settings - Fork 0
Exact function imports #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,6 +449,10 @@ functype_result : | |
| | LPAR RESULT valtype_list RPAR functype_result | ||
| { fun c -> snd $3 c @ $5 c } | ||
|
|
||
| heapfunctype : | ||
| | LPAR EXACT functype RPAR { fun c -> Exact, $3 c } | ||
| | functype { fun c -> Inexact, $1 c } | ||
|
|
||
| comptype : | ||
| | LPAR STRUCT structtype RPAR { fun c x -> StructT ($3 c x) } | ||
| | LPAR ARRAY arraytype RPAR { fun c x -> ArrayT ($3 c) } | ||
|
|
@@ -488,6 +492,9 @@ limits : | |
| typeuse : | ||
| | LPAR TYPE idx RPAR { fun c -> $3 c type_ } | ||
|
|
||
| heaptypeuse : | ||
| | LPAR EXACT typeuse RPAR { fun c -> UseHT (Exact, Idx ($3 c).it) } | ||
| | typeuse { fun c -> UseHT (Inexact, Idx ($1 c).it) } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the binary format syntactically allows arbitrary heaptypes, then the text format must, too, to stay equi-expressive. In particular, we should have tests for the invalid cases. |
||
|
|
||
| /* Immediates */ | ||
|
|
||
|
|
@@ -991,16 +998,20 @@ func_fields : | |
| let y = inline_functype c' (fst $1 c') loc in | ||
| let Func (_, ls, es) = snd $1 c' in | ||
| [Func (y, ls, es) @@ loc], [], [] } | ||
| | inline_import typeuse func_fields_import /* Sugar */ | ||
| | inline_import heaptypeuse func_fields_import /* Sugar */ | ||
| { fun c x loc -> | ||
| let y = inline_functype_explicit c ($2 c) ($3 c) in | ||
| let exact, y = match ($2 c) with | ||
| | UseHT (exact, Idx y) -> exact, y | ||
| | _ -> assert false | ||
| in | ||
| let y = inline_functype_explicit c (y @@ loc) ($3 c) in | ||
| [], | ||
| [Import (fst $1, snd $1, ExternFuncT (Idx y.it)) @@ loc ], [] } | ||
| [Import (fst $1, snd $1, ExternFuncT (UseHT (exact, Idx y.it))) @@ loc ], [] } | ||
| | inline_import func_fields_import /* Sugar */ | ||
| { fun c x loc -> | ||
| let y = inline_functype c ($2 c) loc in | ||
| [], | ||
| [Import (fst $1, snd $1, ExternFuncT (Idx y.it)) @@ loc ], [] } | ||
| [Import (fst $1, snd $1, ExternFuncT (UseHT (Inexact, Idx y.it))) @@ loc ], [] } | ||
| | inline_export func_fields /* Sugar */ | ||
| { fun c x loc -> | ||
| let fns, ims, exs = $2 c x loc in fns, ims, $1 (FuncX x) c :: exs } | ||
|
|
@@ -1242,9 +1253,9 @@ table_fields : | |
| /* Imports & Exports */ | ||
|
|
||
| externtype : | ||
| | LPAR FUNC bindidx_opt typeuse RPAR | ||
| | LPAR FUNC bindidx_opt heaptypeuse RPAR | ||
| { fun c -> ignore ($3 c anon_func bind_func); | ||
| fun () -> ExternFuncT (Idx ($4 c).it) } | ||
| fun () -> ExternFuncT ($4 c) } | ||
| | LPAR TAG bindidx_opt typeuse RPAR | ||
| { fun c -> ignore ($3 c anon_tag bind_tag); | ||
| fun () -> ExternTagT (TagT (Idx ($4 c).it)) } | ||
|
|
@@ -1260,9 +1271,12 @@ externtype : | |
| | LPAR TABLE bindidx_opt tabletype RPAR | ||
| { fun c -> ignore ($3 c anon_table bind_table); | ||
| fun () -> ExternTableT ($4 c) } | ||
| | LPAR FUNC bindidx_opt functype RPAR /* Sugar */ | ||
| | LPAR FUNC bindidx_opt heapfunctype RPAR /* Sugar */ | ||
| { fun c -> ignore ($3 c anon_func bind_func); | ||
| fun () -> ExternFuncT (Idx (inline_functype c ($4 c) $loc($4)).it) } | ||
| fun () -> | ||
| let exact, ft = $4 c in | ||
| let y = inline_functype c ft $loc($4) in | ||
| ExternFuncT (UseHT (exact, Idx y.it)) } | ||
|
|
||
| import : | ||
| | LPAR IMPORT name name externtype RPAR | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ type context = | |
| globals : globaltype list; | ||
| memories : memorytype list; | ||
| tables : tabletype list; | ||
| funcs : deftype list; | ||
| funcs : heaptype list; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be that general. If it's limited to |
||
| datas : unit list; | ||
| elems : reftype list; | ||
| locals : localtype list; | ||
|
|
@@ -235,8 +235,13 @@ let check_externtype (c : context) (xt : externtype) at = | |
| check_memorytype c mt at | ||
| | ExternTableT tt -> | ||
| check_tabletype c tt at | ||
| | ExternFuncT ut -> | ||
| | ExternFuncT (UseHT (_exact, ut)) -> | ||
| let _ft = func_type c (idx_of_typeuse ut @@ at) in () | ||
| | ExternFuncT ht -> | ||
| error at | ||
| ("external function type should have defined type, but has " ^ | ||
| string_of_heaptype ht) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Remove extra empty line |
||
|
|
||
|
|
||
| let diff_reftype (nul1, ht1) (nul2, ht2) = | ||
|
|
@@ -586,7 +591,8 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins | |
| c.results -->... [], [] | ||
|
|
||
| | Call x -> | ||
| let (ts1, ts2) = functype_of_comptype (expand_deftype (func c x)) in | ||
| let dt = deftype_of_typeuse (typeuse_of_heaptype (func c x)) in | ||
| let (ts1, ts2) = functype_of_comptype (expand_deftype dt) in | ||
| ts1 --> ts2, [] | ||
|
|
||
| | CallRef x -> | ||
|
|
@@ -602,7 +608,8 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins | |
| (ts1 @ [NumT (numtype_of_addrtype at)]) --> ts2, [] | ||
|
|
||
| | ReturnCall x -> | ||
| let (ts1, ts2) = functype_of_comptype (expand_deftype (func c x)) in | ||
| let dt = deftype_of_typeuse (typeuse_of_heaptype (func c x)) in | ||
| let (ts1, ts2) = functype_of_comptype (expand_deftype dt) in | ||
| require (match_resulttype c.types ts2 c.results) e.at | ||
| ("type mismatch: current function requires result type " ^ | ||
| string_of_resulttype c.results ^ | ||
|
|
@@ -777,10 +784,9 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins | |
| [] --> [RefT (Null, ht)], [] | ||
|
|
||
| | RefFunc x -> | ||
| let dt = func c x in | ||
| let ht = func c x in | ||
| refer_func c x; | ||
| (* TODO: Exact function references *) | ||
| [] --> [RefT (NoNull, UseHT (Inexact, Def dt))], [] | ||
| [] --> [RefT (NoNull, ht)], [] | ||
|
|
||
| | RefIsNull -> | ||
| let (_nul, ht) = peek_ref 0 s e.at in | ||
|
|
@@ -1098,7 +1104,7 @@ let check_local (c : context) (loc : local) : localtype = | |
| let check_func (c : context) (f : func) : context = | ||
| let Func (x, _ls, _es) = f.it in | ||
| let _ft = func_type c x in | ||
| {c with funcs = c.funcs @ [type_ c x]} | ||
| {c with funcs = c.funcs @ [UseHT (Exact, Def (type_ c x))]} | ||
|
|
||
| let check_func_body (c : context) (f : func) = | ||
| let Func (x, ls, es) = f.it in | ||
|
|
@@ -1194,7 +1200,8 @@ let check_type (c : context) (t : type_) : context = | |
|
|
||
| let check_start (c : context) (start : start) = | ||
| let Start x = start.it in | ||
| let ft = functype_of_comptype (expand_deftype (func c x)) in | ||
| let dt = deftype_of_typeuse (typeuse_of_heaptype (func c x)) in | ||
| let ft = functype_of_comptype (expand_deftype dt) in | ||
| require (ft = ([], [])) start.at | ||
| "start function must not have parameters or results" | ||
|
|
||
|
|
@@ -1206,7 +1213,7 @@ let check_import (c : context) (im : import) : context = | |
| | ExternGlobalT gt -> {c with globals = c.globals @ [gt]} | ||
| | ExternMemoryT mt -> {c with memories = c.memories @ [mt]} | ||
| | ExternTableT tt -> {c with tables = c.tables @ [tt]} | ||
| | ExternFuncT ut -> {c with funcs = c.funcs @ [deftype_of_typeuse ut]} | ||
| | ExternFuncT ht -> {c with funcs = c.funcs @ [ht]} | ||
|
|
||
| module NameSet = Set.Make(struct type t = Ast.name let compare = compare end) | ||
|
|
||
|
|
@@ -1218,7 +1225,7 @@ let check_export (c : context) (ex : export) : exporttype = | |
| | GlobalX x -> ExternGlobalT (global c x) | ||
| | MemoryX x -> ExternMemoryT (memory c x) | ||
| | TableX x -> ExternTableT (table c x) | ||
| | FuncX x -> ExternFuncT (Def (func c x)) | ||
| | FuncX x -> ExternFuncT (func c x) | ||
| in ExportT (name, xt) | ||
|
|
||
| let check_list f xs (c : context) : context = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: