Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ let rec instr s =
(match u32 s with
| 0x00l -> let x = at idx s in struct_new x
| 0x01l -> let x = at idx s in struct_new_default x
| 0x20l -> let x = at idx s in struct_new_desc x
| 0x21l -> let x = at idx s in struct_new_default_desc x
| 0x02l -> let x = at idx s in let i = idx s in struct_get x i
| 0x03l -> let x = at idx s in let i = idx s in struct_get_s x i
| 0x04l -> let x = at idx s in let i = idx s in struct_get_u x i
Expand Down
6 changes: 4 additions & 2 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,10 @@ struct
| I31Get S -> op 0xfb; op 0x1d
| I31Get U -> op 0xfb; op 0x1e

| StructNew (x, Explicit) -> op 0xfb; op 0x00; idx x
| StructNew (x, Implicit) -> op 0xfb; op 0x01; idx x
| StructNew (x, Explicit, NoDesc) -> op 0xfb; op 0x00; idx x
| StructNew (x, Implicit, NoDesc) -> op 0xfb; op 0x01; idx x
| StructNew (x, Explicit, Desc) -> op 0xfb; op 0x20; idx x
| StructNew (x, Implicit, Desc) -> op 0xfb; op 0x21; idx x
| StructGet (x, i, None) -> op 0xfb; op 0x02; idx x; u32 i
| StructGet (x, i, Some S) -> op 0xfb; op 0x03; idx x; u32 i
| StructGet (x, i, Some U) -> op 0xfb; op 0x04; idx x; u32 i
Expand Down
10 changes: 4 additions & 6 deletions interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ let data (inst : moduleinst) x = lookup "data segment" inst.datas x
let elem (inst : moduleinst) x = lookup "element segment" inst.elems x
let local (frame : frame) x = lookup "local" frame.locals x

let desc_type (inst : moduleinst) x = expand_deftype_to_desctype (type_ inst x)
let comp_type (inst : moduleinst) x = expand_deftype (type_ inst x)
let struct_type (inst : moduleinst) x = structtype_of_comptype (comp_type inst x)
let array_type (inst : moduleinst) x = arraytype_of_comptype (comp_type inst x)
Expand Down Expand Up @@ -726,12 +725,11 @@ let rec step (c : config) : config =
| I31Get ext, Ref (I31.I31Ref i) :: vs' ->
Num (I32 (I31.to_i32 ext i)) :: vs', []

| StructNew (x, initop), vs' ->
let DescT (_, dt, _) = desc_type c.frame.inst x in
| StructNew (x, initop, descop), vs' ->
let desc, vs'' =
match dt, vs' with
| Some _, Ref desc :: vs'' -> Some desc, vs''
| None, _ -> None, vs'
match descop, vs' with
| Desc, Ref desc :: vs'' -> Some desc, vs''
| NoDesc, _ -> None, vs'
| _ -> Crash.error e.at "missing descriptor"
in
let fts = struct_type c.frame.inst x in
Expand Down
3 changes: 2 additions & 1 deletion interpreter/syntax/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type vstoreop = (vectype, unit) memop
type vlaneop = (vectype, packsize) memop

type initop = Explicit | Implicit
type descop = Desc | NoDesc
type externop = Internalize | Externalize


Expand Down Expand Up @@ -229,7 +230,7 @@ and instr' =
| RefEq (* reference equality *)
| RefI31 (* scalar reference *)
| I31Get of sx (* read scalar *)
| StructNew of typeidx * initop (* allocate structure *)
| StructNew of typeidx * initop * descop (* allocate structure *)
| StructGet of typeidx * fieldidx * sx option (* read structure field *)
| StructSet of typeidx * fieldidx (* write structure field *)
| ArrayNew of typeidx * initop (* allocate array *)
Expand Down
3 changes: 2 additions & 1 deletion interpreter/syntax/free.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ let rec instr (e : instr) =
| RefNull t -> heaptype t
| RefFunc x -> funcs (idx x)
| RefI31 | I31Get _ -> empty
| StructNew (x, _) | ArrayNew (x, _) | ArrayNewFixed (x, _) -> types (idx x)
| StructNew (x, _, _) | ArrayNew (x, _) | ArrayNewFixed (x, _) ->
types (idx x)
| ArrayNewElem (x, y) -> types (idx x) ++ elems (idx y)
| ArrayNewData (x, y) -> types (idx x) ++ datas (idx y)
| StructGet (x, _, _) | StructSet (x, _) -> types (idx x)
Expand Down
6 changes: 4 additions & 2 deletions interpreter/syntax/mnemonics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ let ref_eq = RefEq
let ref_i31 = RefI31
let i31_get_u = I31Get U
let i31_get_s = I31Get S
let struct_new x = StructNew (x, Explicit)
let struct_new_default x = StructNew (x, Implicit)
let struct_new x = StructNew (x, Explicit, NoDesc)
let struct_new_default x = StructNew (x, Implicit, NoDesc)
let struct_new_desc x = StructNew (x, Explicit, Desc)
let struct_new_default_desc x = StructNew (x, Implicit, Desc)
let struct_get x y = StructGet (x, y, None)
let struct_get_u x y = StructGet (x, y, Some U)
let struct_get_s x y = StructGet (x, y, Some S)
Expand Down
7 changes: 6 additions & 1 deletion interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ let initop = function
| Explicit -> ""
| Implicit -> "_default"

let descop = function
| Desc -> "_desc"
| NoDesc -> ""

let constop v = string_of_numtype (type_of_num v) ^ ".const"
let vconstop v = string_of_vectype (type_of_vec v) ^ ".const i32x4"

Expand Down Expand Up @@ -570,7 +574,8 @@ let rec instr e =
| RefEq -> "ref.eq", []
| RefI31 -> "ref.i31", []
| I31Get sx -> "i31.get" ^ ext sx, []
| StructNew (x, op) -> "struct.new" ^ initop op ^ " " ^ idx x, []
| StructNew (x, init, desc) ->
"struct.new" ^ initop init ^ descop desc ^ " " ^ idx x, []
| StructGet (x, i, sxo) ->
"struct.get" ^ opt_s ext sxo ^ " " ^ idx x ^ " " ^ nat32 i, []
| StructSet (x, i) -> "struct.set " ^ idx x ^ " " ^ nat32 i, []
Expand Down
2 changes: 2 additions & 0 deletions interpreter/text/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ rule token = parse

| "struct.new" -> STRUCT_NEW struct_new
| "struct.new_default" -> STRUCT_NEW struct_new_default
| "struct.new_desc" -> STRUCT_NEW struct_new_desc
| "struct.new_default_desc" -> STRUCT_NEW struct_new_default_desc
| "struct.get" -> STRUCT_GET struct_get
| "struct.get_u" -> STRUCT_GET struct_get_u
| "struct.get_s" -> STRUCT_GET struct_get_s
Expand Down
12 changes: 9 additions & 3 deletions interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
| I31Get ext ->
[RefT (Null, I31HT)] --> [NumT I32T], []

| StructNew (x, initop) ->
| StructNew (x, initop, descop) ->
let fts = struct_type c x in
require
( initop = Explicit || List.for_all (fun ft ->
Expand All @@ -884,8 +884,14 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
let ts = if initop = Implicit then [] else List.map unpacked_fieldtype fts in
let DescT (_, dt, _) = expand_deftype_to_desctype (type_ c x) in
let dt = match dt with
| Some dt -> [RefT (Null, UseHT (Exact, dt))]
| None -> []
| Some dt ->
require (descop = Desc) x.at
"type with descriptor requires descriptor allocation";
[RefT (Null, UseHT (Exact, dt))]
| None ->
require (descop = NoDesc) x.at
"type without descriptor requires non-descriptor allocation";
[]
in
(ts @ dt) --> [RefT (NoNull, UseHT (Exact, Def (type_ c x)))], []

Expand Down
Loading