@@ -42,6 +42,11 @@ let numeric_error at = function
4242 | exn -> raise exn
4343
4444
45+ let value_of_index it x =
46+ match it with
47+ | I64IndexType -> Num (I64 x)
48+ | I32IndexType -> Num (I32 (Int64. to_int32 x))
49+
4550(* Administrative Expressions & Configurations *)
4651
4752type 'a stack = 'a list
@@ -93,13 +98,13 @@ let local (frame : frame) x = lookup "local" frame.locals x
9398
9499let any_ref inst x i at =
95100 try Table. load (table inst x) i with Table. Bounds ->
96- Trap. error at (" undefined element " ^ Int32 . to_string i)
101+ Trap. error at (" undefined element " ^ Int64 . to_string i)
97102
98103let func_ref inst x i at =
99104 match any_ref inst x i at with
100105 | FuncRef f -> f
101- | NullRef _ -> Trap. error at (" uninitialized element " ^ Int32 . to_string i)
102- | _ -> Crash. error at (" type mismatch for element " ^ Int32 . to_string i)
106+ | NullRef _ -> Trap. error at (" uninitialized element " ^ Int64 . to_string i)
107+ | _ -> Crash. error at (" type mismatch for element " ^ Int64 . to_string i)
103108
104109let func_type_of = function
105110 | Func. AstFunc (t , inst , f ) -> t
@@ -140,12 +145,12 @@ let data_oob frame x i n =
140145 (Data. size (data frame.inst x))
141146
142147let table_oob frame x i n =
143- I64. gt_u (I64. add (I64_convert. extend_i32_u i) (I64_convert. extend_i32_u n))
144- (I64_convert. extend_i32_u ( Table. size (table frame.inst x) ))
148+ I64. gt_u (I64. add (Table. index_of_num i) (Table. index_of_num n))
149+ (Table. size (table frame.inst x))
145150
146151let elem_oob frame x i n =
147- I64. gt_u (I64. add (I64_convert. extend_i32_u i) (I64_convert. extend_i32_u n))
148- (I64_convert. extend_i32_u ( Elem. size (elem frame.inst x) ))
152+ I64. gt_u (I64. add (Table. index_of_num i) (Table. index_of_num n))
153+ (Elem. size (elem frame.inst x))
149154
150155let inc_address i at =
151156 match i with
@@ -206,7 +211,8 @@ let rec step (c : config) : config =
206211 | Call x , vs ->
207212 vs, [Invoke (func frame.inst x) @@ e.at]
208213
209- | CallIndirect (x , y ), Num (I32 i ) :: vs ->
214+ | CallIndirect (x , y ), Num n :: vs ->
215+ let i = Table. index_of_num n in
210216 let func = func_ref frame.inst x i e.at in
211217 if type_ frame.inst y <> Func. type_of func then
212218 vs, [Trapping " indirect call type mismatch" @@ e.at]
@@ -241,85 +247,97 @@ let rec step (c : config) : config =
241247 with Global. NotMutable -> Crash. error e.at " write to immutable global"
242248 | Global. Type -> Crash. error e.at " type mismatch at global write" )
243249
244- | TableGet x , Num (I32 i ) :: vs' ->
250+ | TableGet x , Num n :: vs' ->
251+ let i = Table. index_of_num n in
245252 (try Ref (Table. load (table frame.inst x) i) :: vs', []
246253 with exn -> vs', [Trapping (table_error e.at exn ) @@ e.at])
247254
248- | TableSet x , Ref r :: Num (I32 i ) :: vs' ->
255+ | TableSet x , Ref r :: Num n :: vs' ->
256+ let i = Table. index_of_num n in
249257 (try Table. store (table frame.inst x) i r; vs', []
250258 with exn -> vs', [Trapping (table_error e.at exn ) @@ e.at])
251259
252260 | TableSize x , vs ->
253- Num (I32 (Table. size (table frame.inst x))) :: vs, []
261+ let tab = table frame.inst x in
262+ value_of_index (Table. index_of tab) (Table. size (table frame.inst x)) :: vs, []
254263
255- | TableGrow x , Num (I32 delta ) :: Ref r :: vs' ->
264+ | TableGrow x , Num delta :: Ref r :: vs' ->
256265 let tab = table frame.inst x in
266+ let delta_64 = Table. index_of_num delta in
257267 let old_size = Table. size tab in
258268 let result =
259- try Table. grow tab delta r; old_size
260- with Table. SizeOverflow | Table. SizeLimit | Table. OutOfMemory -> - 1l
261- in Num ( I32 result) :: vs', []
269+ try Table. grow tab delta_64 r; old_size
270+ with Table. SizeOverflow | Table. SizeLimit | Table. OutOfMemory -> - 1L
271+ in (value_of_index ( Table. index_of tab) result) :: vs', []
262272
263- | TableFill x , Num (I32 n ) :: Ref r :: Num (I32 i ) :: vs' ->
273+ | TableFill x , Num n :: Ref r :: Num i :: vs' ->
274+ let n_64 = Table. index_of_num n in
264275 if table_oob frame x i n then
265276 vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
266- else if n = 0l then
277+ else if n_64 = 0L then
267278 vs', []
268279 else
269- let _ = assert (I32. lt_u i 0xffff_ffffl ) in
280+ let i_64 = Table. index_of_num i in
281+ let _ = assert (I64. lt_u i_64 0xffff_ffff_ffff_ffffL ) in
270282 vs', List. map (at e.at) [
271- Plain (Const (I32 i @@ e.at));
283+ Plain (Const (I64 i_64 @@ e.at));
272284 Refer r;
273285 Plain (TableSet x);
274- Plain (Const (I32 ( I32 . add i 1l ) @@ e.at));
286+ Plain (Const (I64 ( I64 . add i_64 1L ) @@ e.at));
275287 Refer r;
276- Plain (Const (I32 ( I32 . sub n 1l ) @@ e.at));
288+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
277289 Plain (TableFill x);
278290 ]
279291
280- | TableCopy (x , y ), Num (I32 n ) :: Num (I32 s ) :: Num (I32 d ) :: vs' ->
292+ | TableCopy (x , y ), Num n :: Num s :: Num d :: vs' ->
293+ let n_64 = Table. index_of_num n in
294+ let s_64 = Table. index_of_num s in
295+ let d_64 = Table. index_of_num d in
281296 if table_oob frame x d n || table_oob frame y s n then
282297 vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
283- else if n = 0l then
298+ else if n_64 = 0L then
284299 vs', []
285- else if I32 . le_u d s then
300+ else if I64 . le_u d_64 s_64 then
286301 vs', List. map (at e.at) [
287- Plain (Const (I32 d @@ e.at));
288- Plain (Const (I32 s @@ e.at));
302+ Plain (Const (I64 d_64 @@ e.at));
303+ Plain (Const (I64 s_64 @@ e.at));
289304 Plain (TableGet y);
290305 Plain (TableSet x);
291- Plain (Const (I32 ( I32 . add d 1l ) @@ e.at));
292- Plain (Const (I32 ( I32 . add s 1l ) @@ e.at));
293- Plain (Const (I32 ( I32 . sub n 1l ) @@ e.at));
306+ Plain (Const (I64 ( I64 . add d_64 1L ) @@ e.at));
307+ Plain (Const (I64 ( I64 . add s_64 1L ) @@ e.at));
308+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
294309 Plain (TableCopy (x, y));
295310 ]
296311 else (* d > s *)
297- let n' = I32 . sub n 1l in
312+ let n' = I64 . sub n_64 1L in
298313 vs', List. map (at e.at) [
299- Plain (Const (I32 ( I32 . add d n') @@ e.at));
300- Plain (Const (I32 ( I32 . add s n') @@ e.at));
314+ Plain (Const (I64 ( I64 . add d_64 n') @@ e.at));
315+ Plain (Const (I64 ( I64 . add s_64 n') @@ e.at));
301316 Plain (TableGet y);
302317 Plain (TableSet x);
303- Plain (Const (I32 d @@ e.at));
304- Plain (Const (I32 s @@ e.at));
305- Plain (Const (I32 n' @@ e.at));
318+ Plain (Const (I64 d_64 @@ e.at));
319+ Plain (Const (I64 s_64 @@ e.at));
320+ Plain (Const (I64 n' @@ e.at));
306321 Plain (TableCopy (x, y));
307322 ]
308323
309- | TableInit (x , y ), Num (I32 n ) :: Num (I32 s ) :: Num (I32 d ) :: vs' ->
324+ | TableInit (x , y ), Num n :: Num s :: Num d :: vs' ->
325+ let n_64 = Table. index_of_num n in
310326 if table_oob frame x d n || elem_oob frame y s n then
311327 vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
312- else if n = 0l then
328+ else if n_64 = 0L then
313329 vs', []
314330 else
331+ let d_64 = Table. index_of_num d in
332+ let s_64 = Table. index_of_num s in
315333 let seg = elem frame.inst y in
316334 vs', List. map (at e.at) [
317- Plain (Const (I32 d @@ e.at));
318- Refer (Elem. load seg s );
335+ Plain (Const (I64 d_64 @@ e.at));
336+ Refer (Elem. load seg s_64 );
319337 Plain (TableSet x);
320- Plain (Const (I32 ( I32 . add d 1l ) @@ e.at));
321- Plain (Const (I32 ( I32 . add s 1l ) @@ e.at));
322- Plain (Const (I32 ( I32 . sub n 1l ) @@ e.at));
338+ Plain (Const (I64 ( I64 . add d_64 1L ) @@ e.at));
339+ Plain (Const (I64 ( I64 . add s_64 1L ) @@ e.at));
340+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
323341 Plain (TableInit (x, y));
324342 ]
325343
@@ -411,15 +429,15 @@ let rec step (c : config) : config =
411429 | MemorySize , vs ->
412430 let mem = memory frame.inst (0l @@ e.at) in
413431
414- Memory. value_of_address (Memory. index_of mem) (Memory. size mem) :: vs, []
432+ value_of_index (Memory. index_of mem) (Memory. size mem) :: vs, []
415433
416434 | MemoryGrow , Num delta :: vs' ->
417435 let mem = memory frame.inst (0l @@ e.at) in
418436 let old_size = Memory. size mem in
419437 let result =
420438 try Memory. grow mem (Memory. address_of_num delta); old_size
421439 with Memory. SizeOverflow | Memory. SizeLimit | Memory. OutOfMemory -> - 1L
422- in (Memory. value_of_address (Memory. index_of mem) result) :: vs', []
440+ in (value_of_index (Memory. index_of mem) result) :: vs', []
423441
424442 | MemoryFill , Num n :: Num k :: Num i :: vs' ->
425443 let n_64 = Memory. address_of_num n in
@@ -709,7 +727,7 @@ let create_func (inst : module_inst) (f : func) : func_inst =
709727
710728let create_table (inst : module_inst ) (tab : table ) : table_inst =
711729 let {ttype} = tab.it in
712- let TableType (_lim, t) = ttype in
730+ let TableType (_lim, _it, t) = ttype in
713731 Table. alloc ttype (NullRef t)
714732
715733let create_memory (inst : module_inst ) (mem : memory ) : memory_inst =
0 commit comments