Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit f4a1f12

Browse files
committed
Fix compilation errors after merge.
This commit fixes the errors introduced by the merge of function-references/main into this tree.
1 parent eb9932a commit f4a1f12

File tree

15 files changed

+265
-180
lines changed

15 files changed

+265
-180
lines changed

interpreter/binary/decode.ml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,8 @@ let sized f s =
144144

145145
open Types
146146

147-
let var s = vu32 s
148147
let zero s = expect 0x00 s "zero byte expected"
149148

150-
let var_type s =
151-
let pos = pos s in
152-
match vs33 s with
153-
| i when i >= 0l -> SynVar i
154-
| _ -> error s pos "malformed type index"
155-
156149
let num_type s =
157150
match s7 s with
158151
| -0x01 -> I32T
@@ -208,12 +201,12 @@ let func_type s =
208201
FuncT (ts1, ts2)
209202

210203
let cont_type s =
211-
ContType (var_type s)
204+
ContT (Stat (var_type s))
212205

213206
let def_type s =
214207
match s7 s with
215208
| -0x20 -> DefFuncT (func_type s)
216-
| -0x21 -> ContDefType (cont_type s)
209+
| -0x21 -> DefContT (cont_type s)
217210
| _ -> error s (pos s - 1) "malformed definition type"
218211

219212

@@ -234,8 +227,8 @@ let memory_type s =
234227

235228
let tag_type s =
236229
zero s;
237-
let x = var_type s in
238-
TagType x
230+
let x = Stat (var_type s) in
231+
TagT x
239232

240233
let mutability s =
241234
match byte s with
@@ -329,7 +322,7 @@ let rec instr s =
329322
let ct = catch_list s in
330323
let ca =
331324
if peek s = Some 0x19 then begin
332-
ignore (u8 s);
325+
ignore (byte s);
333326
Some (instr_block s)
334327
end else
335328
None
@@ -372,13 +365,11 @@ let rec instr s =
372365
| 0x14 -> call_ref (at var s)
373366
| 0x15 -> return_call_ref (at var s)
374367

375-
| 0x16 as b -> illegal s pos b
368+
| (0x16 | 0x17) as b -> illegal s pos b
376369

377370
| 0x18 -> error s pos "misplaced DELEGATE opcode"
378371
| 0x19 -> error s pos "misplaced CATCH_ALL opcode"
379372

380-
| 0x17 | 0x19 as b -> illegal s pos b
381-
382373
| 0x1a -> drop
383374
| 0x1b -> select None
384375
| 0x1c -> select (Some (vec val_type s))
@@ -900,7 +891,7 @@ and instr_block' s es =
900891
instr_block' s (Source.(e' @@ region s pos pos) :: es)
901892
and catch_list s =
902893
if peek s = Some 0x07 then begin
903-
ignore (u8 s);
894+
ignore (byte s);
904895
let tag = at var s in
905896
let instrs = instr_block s in
906897
(tag, instrs) :: catch_list s
@@ -1244,7 +1235,7 @@ let module_ s =
12441235
s (len s) "data count section required";
12451236
let funcs =
12461237
List.map2 (fun t f -> {f.it with ftype = t} @@ f.at) func_types func_bodies
1247-
in {types; tables; memories; globals; funcs; imports; exports; elems; datas; start}
1238+
in {types; tables; memories; tags; globals; funcs; imports; exports; elems; datas; start}
12481239

12491240

12501241
let decode name bs = at module_ (stream name bs)

interpreter/binary/encode.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ struct
130130
| FuncT (ts1, ts2) -> vec val_type ts1; vec val_type ts2
131131

132132
let cont_type = function
133-
| ContType x -> var_type x
133+
| ContT x -> var_type x
134134

135135
let def_type = function
136136
| DefFuncT ft -> s7 (-0x20); func_type ft
137-
| ContDefType ct -> vs7 (-0x21); cont_type ct
137+
| DefContT ct -> s7 (-0x21); cont_type ct (* TODO(dhil): I think the GC proposal claims opcode -0x21 for one of the struct/array types. *)
138138

139139
let limits vu {min; max} =
140140
bool (max <> None); vu min; opt vu max
@@ -152,8 +152,8 @@ struct
152152
let global_type = function
153153
| GlobalT (mut, t) -> val_type t; mutability mut
154154

155-
let tag_type (TagType x) =
156-
vu32 0x00l; var_type x
155+
let tag_type (TagT x) =
156+
u32 0x00l; var_type x
157157

158158
(* Instructions *)
159159

interpreter/exec/eval.ml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ and admin_instr' =
6464
| Plain of instr'
6565
| Refer of ref_
6666
| Invoke of func_inst
67-
| Label of int * instr list * code
68-
| Frame of int * frame * code
69-
| Local of int32 * value list * code
67+
| Label of int32 * instr list * code
68+
| Frame of int32 * frame * code
7069
| Handle of (tag_inst * idx) list option * code
7170
| Trapping of string
7271
| Throwing of tag_inst * value stack
@@ -88,7 +87,7 @@ type ref_ += ContRef of cont option ref
8887
let () =
8988
let type_of_ref' = !Value.type_of_ref' in
9089
Value.type_of_ref' := function
91-
| ContRef _ -> BotHeapType (* TODO *)
90+
| ContRef _ -> BotHT (* TODO *)
9291
| r -> type_of_ref' r
9392

9493
let () =
@@ -199,22 +198,22 @@ let rec step (c : config) : config =
199198
match e.it, vs with
200199
| Plain e', vs ->
201200
(match e', vs with
202-
| Unreachable, vs ->
201+
| Unreachable, vs ->
203202
vs, [Trapping "unreachable executed" @@ e.at]
204203

205204
| Nop, vs ->
206205
vs, []
207206

208207
| Block (bt, es'), vs ->
209208
let InstrT (ts1, ts2, _xs) = block_type c.frame.inst bt e.at in
210-
let n1 = List.length ts1 in
211-
let n2 = List.length ts2 in
209+
let n1 = Lib.List32.length ts1 in
210+
let n2 = Lib.List32.length ts2 in
212211
let args, vs' = take n1 vs e.at, drop n1 vs e.at in
213212
vs', [Label (n2, [], (args, List.map plain es')) @@ e.at]
214213

215214
| Loop (bt, es'), vs ->
216215
let InstrT (ts1, ts2, _xs) = block_type c.frame.inst bt e.at in
217-
let n1 = List.length ts1 in
216+
let n1 = Lib.List32.length ts1 in
218217
let args, vs' = take n1 vs e.at, drop n1 vs e.at in
219218
vs', [Label (n1, [e' @@ e.at], (args, List.map plain es')) @@ e.at]
220219

@@ -227,23 +226,23 @@ let rec step (c : config) : config =
227226
| Throw x, vs ->
228227
let tagt = tag c.frame.inst x in
229228
let TagT x' = Tag.type_of tagt in
230-
let FuncT (ts, _) = as_func_def_type (def_of (as_sem_var x')) in
229+
let FuncT (ts, _) = as_func_def_type (def_of (as_dyn_var x')) in
231230
let vs0, vs' = split (Lib.List32.length ts) vs e.at in
232231
vs', [Throwing (tagt, vs0) @@ e.at]
233232

234233
| Rethrow x, vs ->
235234
vs, [Rethrowing (x.it, fun e -> e) @@ e.at]
236235

237236
| TryCatch (bt, es', cts, ca), vs ->
238-
let FuncType (ts1, ts2) = block_type c.frame.inst bt e.at in
237+
let InstrT (ts1, ts2, _xs) = block_type c.frame.inst bt e.at in
239238
let n1 = Lib.List32.length ts1 in
240239
let n2 = Lib.List32.length ts2 in
241240
let args, vs' = take n1 vs e.at, drop n1 vs e.at in
242241
let cts' = List.map (fun (x, es'') -> ((tag c.frame.inst x), es'')) cts in
243242
vs', [Label (n2, [], ([], [Catch (n2, cts', ca, (args, List.map plain es')) @@ e.at])) @@ e.at]
244243

245244
| TryDelegate (bt, es', x), vs ->
246-
let FuncType (ts1, ts2) = block_type c.frame.inst bt e.at in
245+
let InstrT (ts1, ts2, _xs) = block_type c.frame.inst bt e.at in
247246
let n1 = Lib.List32.length ts1 in
248247
let n2 = Lib.List32.length ts2 in
249248
let args, vs' = take n1 vs e.at, drop n1 vs e.at in
@@ -315,7 +314,7 @@ let rec step (c : config) : config =
315314
vs, [Trapping "null function reference" @@ e.at]
316315

317316
| ContNew x, Ref (FuncRef f) :: vs ->
318-
let FuncType (ts, _) = Func.type_of f in
317+
let FuncT (ts, _) = Func.type_of f in
319318
let ctxt code = compose code ([], [Invoke f @@ e.at]) in
320319
Ref (ContRef (ref (Some (Lib.List32.length ts, ctxt)))) :: vs, []
321320

@@ -326,8 +325,8 @@ let rec step (c : config) : config =
326325
vs, [Trapping "continuation already consumed" @@ e.at]
327326

328327
| ContBind x, Ref (ContRef ({contents = Some (n, ctxt)} as cont)) :: vs ->
329-
let ContType z = cont_type c.frame.inst x in
330-
let FuncType (ts', _) = as_func_def_type (def_of (as_sem_var z)) in
328+
let ContT z = cont_type c.frame.inst x in
329+
let FuncT (ts', _) = as_func_def_type (def_of (as_dyn_var z)) in
331330
let args, vs' =
332331
try split (Int32.sub n (Lib.List32.length ts')) vs e.at
333332
with Failure _ -> Crash.error e.at "type mismatch at continuation bind"
@@ -339,7 +338,7 @@ let rec step (c : config) : config =
339338
| Suspend x, vs ->
340339
let tagt = tag c.frame.inst x in
341340
let TagT x' = Tag.type_of tagt in
342-
let FuncT (ts, _) = as_func_def_type (def_of (as_sem_var x')) in
341+
let FuncT (ts, _) = as_func_def_type (def_of (as_dyn_var x')) in
343342
let args, vs' = split (Lib.List32.length ts) vs e.at in
344343
vs', [Suspending (tagt, args, fun code -> code) @@ e.at]
345344

@@ -364,14 +363,14 @@ let rec step (c : config) : config =
364363
| ResumeThrow x, Ref (ContRef ({contents = Some (n, ctxt)} as cont)) :: vs ->
365364
let tagt = tag c.frame.inst x in
366365
let TagT x' = Tag.type_of tagt in
367-
let FuncType (ts, _) = as_func_def_type (def_of (as_sem_var x')) in
366+
let FuncT (ts, _) = as_func_def_type (def_of (as_dyn_var x')) in
368367
let args, vs' = split (Lib.List32.length ts) vs e.at in
369368
let vs1', es1' = ctxt (args, [Plain (Throw x) @@ e.at]) in
370369
cont := None;
371370
vs1' @ vs', es1'
372371

373372
| Barrier (bt, es'), vs ->
374-
let FuncType (ts1, _) = block_type c.frame.inst bt e.at in
373+
let InstrT (ts1, _, _xs) = block_type c.frame.inst bt e.at in
375374
let args, vs' = split (Lib.List32.length ts1) vs e.at in
376375
vs', [
377376
Handle (None,
@@ -821,6 +820,12 @@ let rec step (c : config) : config =
821820
| Frame (n, frame', (vs', [])), vs ->
822821
vs' @ vs, []
823822

823+
| Frame (n, frame', (vs', {it = Trapping msg; at} :: es')), vs ->
824+
vs, [Trapping msg @@ at]
825+
826+
| Frame (n, frame', (vs', {it = Throwing (a, vs0); at} :: es')), vs ->
827+
vs, [Throwing (a, vs0) @@ at]
828+
824829
| Frame (n, frame', (vs', {it = Suspending (tagt, vs1, ctxt); at} :: es')), vs ->
825830
let ctxt' code = [], [Frame (n, frame', compose (ctxt code) (vs', es')) @@ e.at] in
826831
vs, [Suspending (tagt, vs1, ctxt') @@ at]
@@ -830,7 +835,7 @@ let rec step (c : config) : config =
830835

831836
| Frame (n, frame', (vs', {it = ReturningInvoke (vs0, f); at} :: es')), vs ->
832837
let FuncT (ts1, _ts2) = Func.type_of f in
833-
take (List.length ts1) vs0 e.at @ vs, [Invoke f @@ at]
838+
take (Lib.List32.length ts1) vs0 e.at @ vs, [Invoke f @@ at]
834839

835840
| Frame (n, frame', code'), vs ->
836841
let c' = step {frame = frame'; code = code'; budget = c.budget - 1} in
@@ -895,10 +900,10 @@ let rec step (c : config) : config =
895900

896901
| Invoke f, vs ->
897902
let FuncT (ts1, ts2) = Func.type_of f in
898-
let n1, n2 = List.length ts1, List.length ts2 in
903+
let n1, n2 = Lib.List32.length ts1, Lib.List32.length ts2 in
899904
let args, vs' = split n1 vs e.at in
900905
(match f with
901-
| Func.AstFunc (_, inst', func) ->
906+
| Func.AstFunc (_, inst', func) ->
902907
let {locals; body; _} = func.it in
903908
let m = Lib.Promise.value inst' in
904909
let ts = List.map (fun loc -> Types.dyn_val_type m.types loc.it.ltype) locals in
@@ -921,7 +926,7 @@ let rec step (c : config) : config =
921926
| Handle (Some hs, (vs', {it = Suspending (tagt, vs1, ctxt); at} :: es')), vs
922927
when List.mem_assq tagt hs ->
923928
let TagT x' = Tag.type_of tagt in
924-
let FuncT (_, ts) = as_func_def_type (def_of (as_sem_var x')) in
929+
let FuncT (_, ts) = as_func_def_type (def_of (as_dyn_var x')) in
925930
let ctxt' code = compose (ctxt code) (vs', es') in
926931
[Ref (ContRef (ref (Some (Lib.List32.length ts, ctxt'))))] @ vs1 @ vs,
927932
[Plain (Br (List.assq tagt hs)) @@ e.at]
@@ -1025,7 +1030,7 @@ let create_global (inst : module_inst) (glob : global) : global_inst =
10251030

10261031
let create_tag (inst : module_inst) (tag : tag) : tag_inst =
10271032
let {tagtype} = tag.it in
1028-
Tag.alloc (Types.sem_tag_type inst.types tagtype)
1033+
Tag.alloc (Types.dyn_tag_type inst.types tagtype)
10291034

10301035
let create_export (inst : module_inst) (ex : export) : export_inst =
10311036
let {name; edesc} = ex.it in

interpreter/host/spectest.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ let memory = Memory.alloc (MemoryT {min = 1l; max = Some 2l})
2626
let func f ft = Func.alloc_host (Types.alloc (DefFuncT ft)) (f ft)
2727

2828
let tag =
29-
let p = Types.alloc (FuncDefType (FuncType ([NumType I32Type], [NumType I32Type]))) in
30-
Tag.alloc (TagType (SemVar p))
29+
let p = Types.alloc (DefFuncT (FuncT ([NumT I32T], [NumT I32T]))) in
30+
Tag.alloc (TagT (Dyn p))
3131
let except =
32-
let p = Types.alloc (FuncDefType (FuncType ([NumType I32Type], []))) in
33-
Tag.alloc (TagType (SemVar p))
32+
let p = Types.alloc (DefFuncT (FuncT ([NumT I32T], []))) in
33+
Tag.alloc (TagT (Dyn p))
3434

3535
let print_value v =
3636
Printf.printf "%s : %s\n"

interpreter/runtime/instance.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let extern_type_of c = function
6666
| ExternTable tab -> ExternTableT (Table.type_of tab)
6767
| ExternMemory mem -> ExternMemoryT (Memory.type_of mem)
6868
| ExternGlobal glob -> ExternGlobalT (Global.type_of glob)
69-
| ExternTag tag -> ExternTagType (Tag.type_of tag)
69+
| ExternTag tag -> ExternTagT (Tag.type_of tag)
7070

7171
let export inst name =
7272
try Some (List.assoc name inst.exports) with Not_found -> None

interpreter/script/js.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ let null_heap_type_of = function
288288
| Types.DefHT (Dyn a) ->
289289
match Types.def_of a with
290290
| Types.DefFuncT _ -> FuncHT
291+
| Types.DefContT _ -> assert false
291292

292293
let value v =
293294
match v.it with

interpreter/syntax/free.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ let val_type = function
9090
| BotT -> empty
9191

9292
let func_type (FuncT (ins, out)) = list val_type ins ++ list val_type out
93-
let cont_type (ContType x) = var_type x
93+
let cont_type (ContT x) = var_type x
9494
let global_type (GlobalT (_mut, t)) = val_type t
9595
let table_type (TableT (_lim, t)) = ref_type t
9696
let memory_type (MemoryT (_lim)) = empty
97-
let tag_type (TagType x) = var_type x
97+
let tag_type (TagT x) = var_type x
9898

9999
let def_type = function
100100
| DefFuncT ft -> func_type ft

0 commit comments

Comments
 (0)