diff --git a/ml-proto/host/parser.mly b/ml-proto/host/parser.mly index c671035a39..c4791e7fd3 100644 --- a/ml-proto/host/parser.mly +++ b/ml-proto/host/parser.mly @@ -329,7 +329,7 @@ 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() } ; @@ -337,8 +337,8 @@ modul : /* 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 diff --git a/ml-proto/host/print.mli b/ml-proto/host/print.mli index 25da6cc0ce..df70541ee0 100644 --- a/ml-proto/host/print.mli +++ b/ml-proto/host/print.mli @@ -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 diff --git a/ml-proto/host/script.ml b/ml-proto/host/script.ml index 8e4e12be67..cbaab6fcbd 100644 --- a/ml-proto/host/script.ml +++ b/ml-proto/host/script.ml @@ -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 diff --git a/ml-proto/host/script.mli b/ml-proto/host/script.mli index dd4e5ab181..3da9d0b915 100644 --- a/ml-proto/host/script.mli +++ b/ml-proto/host/script.mli @@ -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 diff --git a/ml-proto/spec/ast.ml b/ml-proto/spec/ast.ml index 1605f68b9b..f2d9b527cc 100644 --- a/ml-proto/spec/ast.ml +++ b/ml-proto/spec/ast.ml @@ -11,7 +11,7 @@ * v : value * e : expr * f : func - * m : modul + * m : module_ * * t : value_type * s : func_type @@ -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; diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index 1ca52be718..b33eac0d74 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -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 diff --git a/ml-proto/spec/check.mli b/ml-proto/spec/check.mli index 325a0f8a11..09e2a24cb0 100644 --- a/ml-proto/spec/check.mli +++ b/ml-proto/spec/check.mli @@ -2,4 +2,4 @@ * (c) 2015 Andreas Rossberg *) -val check_module : Ast.modul -> unit (* raise Error *) +val check_module : Ast.module_ -> unit (* raise Error *) diff --git a/ml-proto/spec/eval.ml b/ml-proto/spec/eval.ml index 16eab27afa..15aec80f17 100644 --- a/ml-proto/spec/eval.ml +++ b/ml-proto/spec/eval.ml @@ -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 @@ -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 @@ -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)) @@ -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 @@ -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 = @@ -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 diff --git a/ml-proto/spec/eval.mli b/ml-proto/spec/eval.mli index f6f6c70fa4..4c737a0103 100644 --- a/ml-proto/spec/eval.mli +++ b/ml-proto/spec/eval.mli @@ -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 *)