Skip to content

Commit ea7237b

Browse files
authored
[interpreter] Update {memory,table}.copy to match spec text (#1666)
Change the interpreter implementation of backward copying in the evaluation of memory.copy and table.copy to match the implementation given in the spec. This does not change any behavior.
1 parent dce0593 commit ea7237b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

interpreter/exec/eval.ml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,16 @@ let rec step (c : config) : config =
286286
Plain (TableCopy (x, y));
287287
]
288288
else (* d > s *)
289+
let n' = I32.sub n 1l in
289290
vs', List.map (at e.at) [
290-
Plain (Const (I32 (I32.add d 1l) @@ e.at));
291-
Plain (Const (I32 (I32.add s 1l) @@ e.at));
292-
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
293-
Plain (TableCopy (x, y));
294-
Plain (Const (I32 d @@ e.at));
295-
Plain (Const (I32 s @@ e.at));
291+
Plain (Const (I32 (I32.add d n') @@ e.at));
292+
Plain (Const (I32 (I32.add s n') @@ e.at));
296293
Plain (TableGet y);
297294
Plain (TableSet x);
295+
Plain (Const (I32 d @@ e.at));
296+
Plain (Const (I32 s @@ e.at));
297+
Plain (Const (I32 n' @@ e.at));
298+
Plain (TableCopy (x, y));
298299
]
299300

300301
| TableInit (x, y), Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->
@@ -447,17 +448,18 @@ let rec step (c : config) : config =
447448
Plain (MemoryCopy);
448449
]
449450
else (* d > s *)
451+
let n' = I32.sub n 1l in
450452
vs', List.map (at e.at) [
451-
Plain (Const (I32 (I32.add d 1l) @@ e.at));
452-
Plain (Const (I32 (I32.add s 1l) @@ e.at));
453-
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
454-
Plain (MemoryCopy);
455-
Plain (Const (I32 d @@ e.at));
456-
Plain (Const (I32 s @@ e.at));
453+
Plain (Const (I32 (I32.add d n') @@ e.at));
454+
Plain (Const (I32 (I32.add s n') @@ e.at));
457455
Plain (Load
458456
{ty = I32Type; align = 0; offset = 0l; pack = Some (Pack8, ZX)});
459457
Plain (Store
460458
{ty = I32Type; align = 0; offset = 0l; pack = Some Pack8});
459+
Plain (Const (I32 d @@ e.at));
460+
Plain (Const (I32 s @@ e.at));
461+
Plain (Const (I32 n' @@ e.at));
462+
Plain (MemoryCopy);
461463
]
462464

463465
| MemoryInit x, Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->

0 commit comments

Comments
 (0)