Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ml-proto/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,16 @@ module_fields :
| Some _ -> Error.error $1.at "more than one memory section"
| None -> {m with memory = Some $1} }
;
modul :
module_ :
| LPAR MODULE module_fields RPAR { $3 (c0 ()) @@ at() }
;


/* Scripts */

cmd :
| modul { Define $1 @@ at() }
| LPAR ASSERTINVALID modul TEXT RPAR { AssertInvalid ($3, $4) @@ at() }
| module_ { Define $1 @@ at() }
| LPAR ASSERTINVALID module_ TEXT RPAR { AssertInvalid ($3, $4) @@ at() }
| LPAR INVOKE TEXT expr_list RPAR
{ Invoke ($3, $4 (c0 ())) @@ at() }
| LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr RPAR
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/host/print.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* (c) 2015 Andreas Rossberg
*)

val print_module : Ast.modul -> unit
val print_module_sig : Ast.modul -> unit
val print_module : Ast.module_ -> unit
val print_module_sig : Ast.module_ -> unit
val print_value : Values.value option -> unit

4 changes: 2 additions & 2 deletions ml-proto/host/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ open Source

type command = command' phrase
and command' =
| Define of Ast.modul
| AssertInvalid of Ast.modul * string
| Define of Ast.module_
| AssertInvalid of Ast.module_ * string
| Invoke of string * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr
| AssertTrap of string * Ast.expr list * string
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/host/script.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

type command = command' Source.phrase
and command' =
| Define of Ast.modul
| AssertInvalid of Ast.modul * string
| Define of Ast.module_
| AssertInvalid of Ast.module_ * string
| Invoke of string * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr
| AssertTrap of string * Ast.expr list * string
Expand Down
6 changes: 3 additions & 3 deletions ml-proto/spec/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* v : value
* e : expr
* f : func
* m : modul
* m : module_
*
* t : value_type
* s : func_type
Expand Down Expand Up @@ -143,8 +143,8 @@ and import' =

type table = var list Source.phrase

type modul = modul' Source.phrase
and modul' =
type module_ = module_' Source.phrase
and module_' =
{
memory : memory option;
funcs : func list;
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ and check_mem_type ty sz at =

(*
* check_func : context -> func -> unit
* check_module : context -> modul -> unit
* check_module : context -> module_ -> unit
*
* Conventions:
* c : context
* m : modul
* m : module_
* f : func
* e : expr
* v : value
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/spec/check.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* (c) 2015 Andreas Rossberg
*)

val check_module : Ast.modul -> unit (* raise Error *)
val check_module : Ast.module_ -> unit (* raise Error *)
28 changes: 14 additions & 14 deletions ml-proto/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ type label = value option -> exn

type config =
{
modul : instance;
module_ : instance;
locals : value ref list;
labels : label list;
return : label
}

let page_size c =
I32.of_int32 (Int32.of_int c.modul.host.page_size)
I32.of_int32 (Int32.of_int c.module_.host.page_size)

let lookup category list x =
try List.nth list x.it with Failure _ ->
error x.at ("runtime: undefined " ^ category ^ " " ^ string_of_int x.it)

let func c x = lookup "function" c.modul.funcs x
let import c x = lookup "import" c.modul.imports x
let table c x y = lookup "entry" (lookup "table" c.modul.tables x) y
let func c x = lookup "function" c.module_.funcs x
let import c x = lookup "import" c.module_.imports x
let table c x y = lookup "entry" (lookup "table" c.module_.tables x) y
let local c x = lookup "local" c.locals x
let label c x = lookup "label" c.labels x

Expand Down Expand Up @@ -145,7 +145,7 @@ let rec eval_expr (c : config) (e : expr) =

| Call (x, es) ->
let vs = List.map (fun vo -> some (eval_expr c vo) vo.at) es in
eval_func c.modul (func c x) vs
eval_func c.module_ (func c x) vs

| CallImport (x, es) ->
let vs = List.map (fun ev -> some (eval_expr c ev) ev.at) es in
Expand All @@ -155,7 +155,7 @@ let rec eval_expr (c : config) (e : expr) =
let i = int32 (eval_expr c e1) e1.at in
let vs = List.map (fun vo -> some (eval_expr c vo) vo.at) es in
(* TODO: The conversion to int could overflow. *)
eval_func c.modul (table c x (Int32.to_int i @@ e1.at)) vs
eval_func c.module_ (table c x (Int32.to_int i @@ e1.at)) vs

| Return eo ->
raise (c.return (eval_expr_option c eo))
Expand All @@ -171,28 +171,28 @@ let rec eval_expr (c : config) (e : expr) =
| Load ({ty; align = _}, e1) ->
let v1 = some (eval_expr c e1) e1.at in
let a = Memory.address_of_value v1 in
(try Some (Memory.load c.modul.memory a ty)
(try Some (Memory.load c.module_.memory a ty)
with exn -> memory_error e.at exn)

| Store ({ty = _; align = _}, e1, e2) ->
let v1 = some (eval_expr c e1) e1.at in
let v2 = some (eval_expr c e2) e2.at in
let a = Memory.address_of_value v1 in
(try Memory.store c.modul.memory a v2
(try Memory.store c.module_.memory a v2
with exn -> memory_error e.at exn);
None

| LoadExtend ({memop = {ty; align = _}; sz; ext}, e1) ->
let v1 = some (eval_expr c e1) e1.at in
let a = Memory.address_of_value v1 in
(try Some (Memory.load_extend c.modul.memory a sz ext ty)
(try Some (Memory.load_extend c.module_.memory a sz ext ty)
with exn -> memory_error e.at exn)

| StoreTrunc ({memop = {ty; align = _}; sz}, e1, e2) ->
let v1 = some (eval_expr c e1) e1.at in
let v2 = some (eval_expr c e2) e2.at in
let a = Memory.address_of_value v1 in
(try Memory.store_trunc c.modul.memory a sz v2
(try Memory.store_trunc c.module_.memory a sz v2
with exn -> memory_error e.at exn);
None

Expand Down Expand Up @@ -235,14 +235,14 @@ let rec eval_expr (c : config) (e : expr) =
Some (Int32 (page_size c))

| MemorySize ->
Some (Int32 (I32.of_int32 (Int32.of_int (Memory.size c.modul.memory))))
Some (Int32 (I32.of_int32 (Int32.of_int (Memory.size c.module_.memory))))

| ResizeMemory e ->
let i = int32 (eval_expr c e) e.at in
if (I32.rem_u i (page_size c)) <> I32.zero then
error e.at "runtime: resize_memory operand not multiple of page_size";
(* TODO: The conversion to int could overflow. *)
Memory.resize c.modul.memory (Int32.to_int i);
Memory.resize c.module_.memory (Int32.to_int i);
None

and eval_expr_option c eo =
Expand All @@ -265,7 +265,7 @@ and eval_func (m : instance) (f : func) (evs : value list) =
let args = List.map ref evs in
let vars = List.map (fun t -> ref (default_value t.it)) f.it.locals in
let locals = args @ vars in
let c = {modul = m; locals; labels = []; return = Return.label} in
let c = {module_ = m; locals; labels = []; return = Return.label} in
try eval_expr c f.it.body
with Return.Label vo -> vo

Expand Down
2 changes: 1 addition & 1 deletion ml-proto/spec/eval.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type value = Values.value
type import = value list -> value option
type host_params = {page_size : Memory.size}

val init : Ast.modul -> import list -> host_params -> instance
val init : Ast.module_ -> import list -> host_params -> instance
val invoke : instance -> string -> value list -> value option
(* raise Error.Error *)
val eval : Ast.expr -> value option (* raise Error.Error *)