Skip to content

Commit

Permalink
[interpreter] Update {memory,table}.copy to match spec text (#1666)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tlively authored Sep 25, 2023
1 parent dce0593 commit ea7237b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ let rec step (c : config) : config =
Plain (TableCopy (x, y));
]
else (* d > s *)
let n' = I32.sub n 1l in
vs', List.map (at e.at) [
Plain (Const (I32 (I32.add d 1l) @@ e.at));
Plain (Const (I32 (I32.add s 1l) @@ e.at));
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
Plain (TableCopy (x, y));
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 (I32.add d n') @@ e.at));
Plain (Const (I32 (I32.add s n') @@ e.at));
Plain (TableGet y);
Plain (TableSet x);
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 n' @@ e.at));
Plain (TableCopy (x, y));
]

| TableInit (x, y), Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->
Expand Down Expand Up @@ -447,17 +448,18 @@ let rec step (c : config) : config =
Plain (MemoryCopy);
]
else (* d > s *)
let n' = I32.sub n 1l in
vs', List.map (at e.at) [
Plain (Const (I32 (I32.add d 1l) @@ e.at));
Plain (Const (I32 (I32.add s 1l) @@ e.at));
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
Plain (MemoryCopy);
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 (I32.add d n') @@ e.at));
Plain (Const (I32 (I32.add s n') @@ e.at));
Plain (Load
{ty = I32Type; align = 0; offset = 0l; pack = Some (Pack8, ZX)});
Plain (Store
{ty = I32Type; align = 0; offset = 0l; pack = Some Pack8});
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 n' @@ e.at));
Plain (MemoryCopy);
]

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

0 comments on commit ea7237b

Please sign in to comment.