Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ let lookup_export (env : env) x_opt name at =
let exports = find_inst env x_opt at in
try NameMap.find name exports with Not_found ->
raise (Eval.Crash (at, "unknown export \"" ^
string_of_name name ^ "\" within module isntance"))
string_of_name name ^ "\" within module instance"))


(* Transitively unsubstitute deftype into list of unrolled recursive types *)
Expand Down
21 changes: 14 additions & 7 deletions interpreter/text/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,8 @@ memoryuse :
memory :
| LPAR MEMORY bindidx_opt memory_fields RPAR
{ fun c -> let x = $3 c anon_memory bind_memory @@ $sloc in
fun () -> $4 c x $sloc }
let mff = $4 c in
fun () -> mff x $sloc }

memory_fields :
| memorytype
Expand All @@ -1122,10 +1123,12 @@ memory_fields :
[], [],
[Import (fst $1, snd $1, ExternMemoryT ($2 c)) @@ loc], [] }
| inline_export memory_fields /* Sugar */
{ fun c x loc -> let mems, data, ims, exs = $2 c x loc in
{ fun c -> let mff = $2 c in
fun x loc -> let mems, data, ims, exs = mff x loc in
mems, data, ims, $1 (MemoryX x) c :: exs }
| addrtype LPAR DATA string_list RPAR /* Sugar */
{ fun c x loc ->
{ fun c -> ignore (anon_data c $sloc);
fun x loc ->
let size = Int64.(div (add (of_int (String.length $4)) 65535L) 65536L) in
let offset = [at_const $1 (0L @@ loc) @@ loc] @@ loc in
[Memory (MemoryT ($1, {min = size; max = Some size})) @@ loc],
Expand Down Expand Up @@ -1185,7 +1188,8 @@ tableuse :
table :
| LPAR TABLE bindidx_opt table_fields RPAR
{ fun c -> let x = $3 c anon_table bind_table @@ $sloc in
fun () -> $4 c x $sloc }
let tff = $4 c in
fun () -> tff x $sloc }

table_fields :
| tabletype constexpr1
Expand All @@ -1198,10 +1202,12 @@ table_fields :
[], [],
[Import (fst $1, snd $1, ExternTableT ($2 c)) @@ loc], [] }
| inline_export table_fields /* Sugar */
{ fun c x loc -> let tabs, elems, ims, exs = $2 c x loc in
{ fun c -> let tff = $2 c in
fun x loc -> let tabs, elems, ims, exs = tff x loc in
tabs, elems, ims, $1 (TableX x) c :: exs }
| addrtype reftype LPAR ELEM elemexpr elemexpr_list RPAR /* Sugar */
{ fun c x loc ->
{ fun c -> ignore (anon_elem c $sloc);
fun x loc ->
let offset = [at_const $1 (0L @@ loc) @@ loc] @@ loc in
let einit = $5 c :: $6 c in
let size = Lib.List64.length einit in
Expand All @@ -1211,7 +1217,8 @@ table_fields :
[Elem (rt, einit, Active (x, offset) @@ loc) @@ loc],
[], [] }
| addrtype reftype LPAR ELEM elemidx_list RPAR /* Sugar */
{ fun c x loc ->
{ fun c -> ignore (anon_elem c $sloc);
fun x loc ->
let (_, ht) as rt = $2 c in
let tinit = [RefNull ht @@ loc] @@ loc in
let offset = [at_const $1 (0L @@ loc) @@ loc] @@ loc in
Expand Down
14 changes: 14 additions & 0 deletions test/core/data.wast
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,17 @@
)
"constant expression required"
)

;; Testing how identifiers interact with data segments specified inline
(module
(memory (data "\AB"))
(data $d "\CD")
(func (export "init")
(memory.init $d (i32.const 0) (i32.const 0) (i32.const 1))
)
(func (export "load") (result i32)
(i32.load8_u (i32.const 0))
)
)
(invoke "init")
(assert_return (invoke "load") (i32.const 0xCD))
16 changes: 16 additions & 0 deletions test/core/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,19 @@

(assert_return (invoke "call_in_table" (i32.const 6)) (i32.const 42))
(assert_trap (invoke "call_in_table" (i32.const 0)) "uninitialized element")

;; Testing how identifiers interact with elem segments specified inline
(module
(func $f (result i32) i32.const 0xAB)
(func $g (result i32) i32.const 0xCD)
(table funcref (elem (ref.func $f)))
(elem $e funcref (ref.func $g))
(func (export "init")
(table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
)
(func (export "run") (result i32)
(call_indirect (result i32) (i32.const 0))
)
)
(invoke "init")
(assert_return (invoke "run") (i32.const 0xCD))
Loading