diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index b2a1aa1e1b..26dc3f55a7 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -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 *) diff --git a/interpreter/text/parser.mly b/interpreter/text/parser.mly index b1a32431f2..7952a3abe5 100644 --- a/interpreter/text/parser.mly +++ b/interpreter/text/parser.mly @@ -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 @@ -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], @@ -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 @@ -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 @@ -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 diff --git a/test/core/data.wast b/test/core/data.wast index 73112b673f..fd05b5e443 100644 --- a/test/core/data.wast +++ b/test/core/data.wast @@ -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)) diff --git a/test/core/elem.wast b/test/core/elem.wast index 1722a30b81..6cf25e65fb 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -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))