@@ -93,13 +93,13 @@ let local (frame : frame) x = lookup "local" frame.locals x
93
93
94
94
let any_ref inst x i at =
95
95
try Table. load (table inst x) i with Table. Bounds ->
96
- Trap. error at (" undefined element " ^ Int32 . to_string i)
96
+ Trap. error at (" undefined element " ^ Int64 . to_string i)
97
97
98
98
let func_ref inst x i at =
99
99
match any_ref inst x i at with
100
100
| 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)
101
+ | NullRef _ -> Trap. error at (" uninitialized element " ^ Int64 . to_string i)
102
+ | _ -> Crash. error at (" type mismatch for element " ^ Int64 . to_string i)
103
103
104
104
let func_type_of = function
105
105
| Func. AstFunc (t , inst , f ) -> t
@@ -140,12 +140,12 @@ let data_oob frame x i n =
140
140
(Data. size (data frame.inst x))
141
141
142
142
let 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) ))
143
+ I64. gt_u (I64. add (Table. index_of_num i) (Table. index_of_num n))
144
+ (Table. size (table frame.inst x))
145
145
146
146
let 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) ))
147
+ I64. gt_u (I64. add (Table. index_of_num i) (Table. index_of_num n))
148
+ (Elem. size (elem frame.inst x))
149
149
150
150
let inc_address i at =
151
151
match i with
@@ -206,7 +206,8 @@ let rec step (c : config) : config =
206
206
| Call x , vs ->
207
207
vs, [Invoke (func frame.inst x) @@ e.at]
208
208
209
- | CallIndirect (x , y ), Num (I32 i ) :: vs ->
209
+ | CallIndirect (x , y ), Num n :: vs ->
210
+ let i = Table. index_of_num n in
210
211
let func = func_ref frame.inst x i e.at in
211
212
if type_ frame.inst y <> Func. type_of func then
212
213
vs, [Trapping " indirect call type mismatch" @@ e.at]
@@ -241,85 +242,96 @@ let rec step (c : config) : config =
241
242
with Global. NotMutable -> Crash. error e.at " write to immutable global"
242
243
| Global. Type -> Crash. error e.at " type mismatch at global write" )
243
244
244
- | TableGet x , Num (I32 i ) :: vs' ->
245
+ | TableGet x , Num n :: vs' ->
246
+ let i = Table. index_of_num n in
245
247
(try Ref (Table. load (table frame.inst x) i) :: vs', []
246
248
with exn -> vs', [Trapping (table_error e.at exn ) @@ e.at])
247
249
248
- | TableSet x , Ref r :: Num (I32 i ) :: vs' ->
250
+ | TableSet x , Ref r :: Num n :: vs' ->
251
+ let i = Table. index_of_num n in
249
252
(try Table. store (table frame.inst x) i r; vs', []
250
253
with exn -> vs', [Trapping (table_error e.at exn ) @@ e.at])
251
254
252
255
| TableSize x , vs ->
253
- Num (I32 (Table. size (table frame.inst x))) :: vs, []
256
+ let tab = table frame.inst x in
257
+ value_of_index (Table. index_type_of tab) (Table. size (table frame.inst x)) :: vs, []
254
258
255
- | TableGrow x , Num (I32 delta ) :: Ref r :: vs' ->
259
+ | TableGrow x , Num delta :: Ref r :: vs' ->
256
260
let tab = table frame.inst x in
257
261
let old_size = Table. size tab in
258
262
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', []
263
+ try Table. grow tab ( Table. index_of_num delta) r; old_size
264
+ with Table. SizeOverflow | Table. SizeLimit | Table. OutOfMemory -> - 1L
265
+ in (value_of_index ( Table. index_type_of tab) result) :: vs', []
262
266
263
- | TableFill x , Num (I32 n ) :: Ref r :: Num (I32 i ) :: vs' ->
267
+ | TableFill x , Num n :: Ref r :: Num i :: vs' ->
268
+ let n_64 = Table. index_of_num n in
264
269
if table_oob frame x i n then
265
270
vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
266
- else if n = 0l then
271
+ else if n_64 = 0L then
267
272
vs', []
268
273
else
269
- let _ = assert (I32. lt_u i 0xffff_ffffl ) in
274
+ let i_64 = Table. index_of_num i in
275
+ let _ = assert (I64. lt_u i_64 0xffff_ffff_ffff_ffffL ) in
270
276
vs', List. map (at e.at) [
271
- Plain (Const (I32 i @@ e.at));
277
+ Plain (Const (I64 i_64 @@ e.at));
272
278
Refer r;
273
279
Plain (TableSet x);
274
- Plain (Const (I32 ( I32 . add i 1l ) @@ e.at));
280
+ Plain (Const (I64 ( I64 . add i_64 1L ) @@ e.at));
275
281
Refer r;
276
- Plain (Const (I32 ( I32 . sub n 1l ) @@ e.at));
282
+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
277
283
Plain (TableFill x);
278
284
]
279
285
280
- | TableCopy (x , y ), Num (I32 n ) :: Num (I32 s ) :: Num (I32 d ) :: vs' ->
286
+ | TableCopy (x , y ), Num n :: Num s :: Num d :: vs' ->
287
+ let n_64 = Table. index_of_num n in
288
+ let s_64 = Table. index_of_num s in
289
+ let d_64 = Table. index_of_num d in
281
290
if table_oob frame x d n || table_oob frame y s n then
282
291
vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
283
- else if n = 0l then
292
+ else if n_64 = 0L then
284
293
vs', []
285
- else if I32 . le_u d s then
294
+ else if I64 . le_u d_64 s_64 then
286
295
vs', List. map (at e.at) [
287
- Plain (Const (I32 d @@ e.at));
288
- Plain (Const (I32 s @@ e.at));
296
+ Plain (Const (I64 d_64 @@ e.at));
297
+ Plain (Const (I64 s_64 @@ e.at));
289
298
Plain (TableGet y);
290
299
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));
300
+ Plain (Const (I64 ( I64 . add d_64 1L ) @@ e.at));
301
+ Plain (Const (I64 ( I64 . add s_64 1L ) @@ e.at));
302
+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
294
303
Plain (TableCopy (x, y));
295
304
]
296
305
else (* d > s *)
297
- let n' = I32 . sub n 1l in
306
+ let n' = I64 . sub n_64 1L in
298
307
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));
308
+ Plain (Const (I64 ( I64 . add d_64 n') @@ e.at));
309
+ Plain (Const (I64 ( I64 . add s_64 n') @@ e.at));
301
310
Plain (TableGet y);
302
311
Plain (TableSet x);
303
- Plain (Const (I32 d @@ e.at));
304
- Plain (Const (I32 s @@ e.at));
305
- Plain (Const (I32 n' @@ e.at));
312
+ Plain (Const (I64 d_64 @@ e.at));
313
+ Plain (Const (I64 s_64 @@ e.at));
314
+ Plain (Const (I64 n' @@ e.at));
306
315
Plain (TableCopy (x, y));
307
316
]
308
317
309
- | TableInit (x , y ), Num (I32 n ) :: Num (I32 s ) :: Num (I32 d ) :: vs' ->
318
+ | TableInit (x , y ), Num n :: Num s :: Num d :: vs' ->
319
+ let n_64 = Table. index_of_num n in
310
320
if table_oob frame x d n || elem_oob frame y s n then
311
321
vs', [Trapping (table_error e.at Table. Bounds ) @@ e.at]
312
- else if n = 0l then
322
+ else if n_64 = 0L then
313
323
vs', []
314
324
else
325
+ let d_64 = Table. index_of_num d in
326
+ let s_64 = Table. index_of_num s in
315
327
let seg = elem frame.inst y in
316
328
vs', List. map (at e.at) [
317
- Plain (Const (I32 d @@ e.at));
318
- Refer (Elem. load seg s );
329
+ Plain (Const (I64 d_64 @@ e.at));
330
+ Refer (Elem. load seg s_64 );
319
331
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));
332
+ Plain (Const (I64 ( I64 . add d_64 1L ) @@ e.at));
333
+ Plain (Const (I64 ( I64 . add s_64 1L ) @@ e.at));
334
+ Plain (Const (I64 ( I64 . sub n_64 1L ) @@ e.at));
323
335
Plain (TableInit (x, y));
324
336
]
325
337
@@ -411,15 +423,15 @@ let rec step (c : config) : config =
411
423
| MemorySize , vs ->
412
424
let mem = memory frame.inst (0l @@ e.at) in
413
425
414
- Memory. value_of_address (Memory. index_of mem) (Memory. size mem) :: vs, []
426
+ value_of_index (Memory. index_type_of mem) (Memory. size mem) :: vs, []
415
427
416
428
| MemoryGrow , Num delta :: vs' ->
417
429
let mem = memory frame.inst (0l @@ e.at) in
418
430
let old_size = Memory. size mem in
419
431
let result =
420
432
try Memory. grow mem (Memory. address_of_num delta); old_size
421
433
with Memory. SizeOverflow | Memory. SizeLimit | Memory. OutOfMemory -> - 1L
422
- in (Memory. value_of_address (Memory. index_of mem) result) :: vs', []
434
+ in (value_of_index (Memory. index_type_of mem) result) :: vs', []
423
435
424
436
| MemoryFill , Num n :: Num k :: Num i :: vs' ->
425
437
let n_64 = Memory. address_of_num n in
@@ -709,7 +721,7 @@ let create_func (inst : module_inst) (f : func) : func_inst =
709
721
710
722
let create_table (inst : module_inst ) (tab : table ) : table_inst =
711
723
let {ttype} = tab.it in
712
- let TableType (_lim, t) = ttype in
724
+ let TableType (_lim, _it, t) = ttype in
713
725
Table. alloc ttype (NullRef t)
714
726
715
727
let create_memory (inst : module_inst ) (mem : memory ) : memory_inst =
0 commit comments