Skip to content

Commit ef9c157

Browse files
tlivelyrossberg
authored andcommitted
[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 e5435b2 commit ef9c157

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
@@ -351,15 +351,16 @@ let rec step (c : config) : config =
351351
Plain (TableCopy (x, y));
352352
]
353353
else (* d > s *)
354+
let n' = I32.sub n 1l in
354355
vs', List.map (Lib.Fun.flip (@@) e.at) [
355-
Plain (Const (I32 (I32.add d 1l) @@ e.at));
356-
Plain (Const (I32 (I32.add s 1l) @@ e.at));
357-
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
358-
Plain (TableCopy (x, y));
359-
Plain (Const (I32 d @@ e.at));
360-
Plain (Const (I32 s @@ e.at));
356+
Plain (Const (I32 (I32.add d n') @@ e.at));
357+
Plain (Const (I32 (I32.add s n') @@ e.at));
361358
Plain (TableGet y);
362359
Plain (TableSet x);
360+
Plain (Const (I32 d @@ e.at));
361+
Plain (Const (I32 s @@ e.at));
362+
Plain (Const (I32 n' @@ e.at));
363+
Plain (TableCopy (x, y));
363364
]
364365

365366
| TableInit (x, y), Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->
@@ -513,17 +514,18 @@ let rec step (c : config) : config =
513514
Plain (MemoryCopy);
514515
]
515516
else (* d > s *)
517+
let n' = I32.sub n 1l in
516518
vs', List.map (Lib.Fun.flip (@@) e.at) [
517-
Plain (Const (I32 (I32.add d 1l) @@ e.at));
518-
Plain (Const (I32 (I32.add s 1l) @@ e.at));
519-
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
520-
Plain (MemoryCopy);
521-
Plain (Const (I32 d @@ e.at));
522-
Plain (Const (I32 s @@ e.at));
519+
Plain (Const (I32 (I32.add d n') @@ e.at));
520+
Plain (Const (I32 (I32.add s n') @@ e.at));
523521
Plain (Load
524522
{ty = Types.I32T; align = 0; offset = 0l; pack = Some (Pack8, ZX)});
525523
Plain (Store
526524
{ty = Types.I32T; align = 0; offset = 0l; pack = Some Pack8});
525+
Plain (Const (I32 d @@ e.at));
526+
Plain (Const (I32 s @@ e.at));
527+
Plain (Const (I32 n' @@ e.at));
528+
Plain (MemoryCopy);
527529
]
528530

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

0 commit comments

Comments
 (0)