Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Sep 17, 2015
1 parent a059c39 commit 5ef1a3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
9 changes: 3 additions & 6 deletions ml-proto/src/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ let error = Error.error
type value = Values.value
type func = Ast.func
type import = value list -> value option
type host_params =
{
page_size : Memory.size
}
type host_params = { page_size : Memory.size }

This comment has been minimized.

Copy link
@rossberg

rossberg Sep 17, 2015

Member

Final nit: no spaces around record brackets


module ExportMap = Map.Make(String)
type export_map = func ExportMap.t
Expand Down Expand Up @@ -268,13 +265,13 @@ let init m imports host =
assert (List.length imports = List.length m.it.Ast.imports);
assert (host.page_size > 0);
let {Ast.exports; globals; tables; funcs; memory; _} = m.it in
let memory = init_memory memory in
let mem = init_memory memory in
let func x = List.nth funcs x.it in
let export ex = ExportMap.add ex.it.name (func ex.it.func) in
let exports = List.fold_right export exports ExportMap.empty in
let tables = List.map (fun tab -> List.map func tab.it) tables in
let globals = List.map eval_decl globals in
{funcs; imports; exports; tables; globals; memory; host}
{funcs; imports; exports; tables; globals; memory = mem; host}

let invoke m name vs =
let f = export m (name @@ no_region) in
Expand Down
5 changes: 1 addition & 4 deletions ml-proto/src/spec/eval.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
type instance
type value = Values.value
type import = value list -> value option
type host_params =
{
page_size : Memory.size
}
type host_params = { page_size : Memory.size }

This comment has been minimized.

Copy link
@rossberg

rossberg Sep 17, 2015

Member

same here

This comment has been minimized.

Copy link
@sunfishcode

sunfishcode Sep 17, 2015

Member

While here, it'd be nice to leave a comment mentioning the word "nondeterministic" so that people interested in nondeterminism can easily find the relevant parts of the spec.

This comment has been minimized.

Copy link
@lukewagner

lukewagner Sep 17, 2015

Author Member

Although I think you're technically right (both host_params and import are nondeterministic from a host-agnostic pov), I think saying "these values are nondeterministic" in a comment would confuse people more than the more specific statement that these values are host parameters.


val init : Ast.modul -> import list -> host_params -> instance
val invoke : instance -> string -> value list -> value option
Expand Down
12 changes: 4 additions & 8 deletions ml-proto/src/spec/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ let create n =
ref (create' n)

let init_seg mem seg =
let mem = !mem in
(* There currently is no way to blit from a string. *)
for i = 0 to String.length seg.data - 1 do
(view mem : char_view).{seg.addr + i} <- seg.data.[i]
(view !mem : char_view).{seg.addr + i} <- seg.data.[i]
done

let init mem segs =
try List.iter (init_seg mem) segs with Invalid_argument _ -> raise Bounds


let size mem =
let mem = !mem in
Array1.dim mem
Array1.dim !mem

let resize mem n =
let before = !mem in
Expand All @@ -99,11 +97,10 @@ let int64_of_int32_u i = Int64.logand (Int64.of_int32 i) int32_mask
let buf = create' 8

let load mem a memty ext =
let mem = !mem in
let sz = mem_size memty in
let open Types in
try
Array1.blit (Array1.sub mem a sz) (Array1.sub buf 0 sz);
Array1.blit (Array1.sub !mem a sz) (Array1.sub buf 0 sz);
match memty, ext with
| Int8Mem, SX -> Int32 (Int32.of_int (view buf : sint8_view).{0})
| Int8Mem, ZX -> Int32 (Int32.of_int (view buf : uint8_view).{0})
Expand All @@ -117,7 +114,6 @@ let load mem a memty ext =
with Invalid_argument _ -> raise Bounds

let store mem a memty v =
let mem = !mem in
let sz = mem_size memty in
try
(match memty, v with
Expand All @@ -128,5 +124,5 @@ let store mem a memty v =
| Float32Mem, Float32 x -> (view buf : float32_view).{0} <- Float32.to_bits x
| Float64Mem, Float64 x -> (view buf : float64_view).{0} <- Float64.to_bits x
| _ -> raise Type);
Array1.blit (Array1.sub buf 0 sz) (Array1.sub mem a sz)
Array1.blit (Array1.sub buf 0 sz) (Array1.sub !mem a sz)
with Invalid_argument _ -> raise Bounds

0 comments on commit 5ef1a3a

Please sign in to comment.