diff --git a/ml-proto/given/lib.ml b/ml-proto/given/lib.ml index c13a00666b..5820f3e1ed 100644 --- a/ml-proto/given/lib.ml +++ b/ml-proto/given/lib.ml @@ -19,6 +19,14 @@ struct | n, _::xs' when n > 0 -> drop (n - 1) xs' | _ -> failwith "drop" + let length32 xs = Int32.of_int (List.length xs) + + let rec nth32 xs n = + match n, xs with + | 0l, x::_ -> x + | n, _::xs' when n > 0l -> nth32 xs' (Int32.sub n 1l) + | _ -> failwith "nth32" + let rec last = function | x::[] -> x | _::xs -> last xs diff --git a/ml-proto/given/lib.mli b/ml-proto/given/lib.mli index c0cb6bf16d..ef7c3addc3 100644 --- a/ml-proto/given/lib.mli +++ b/ml-proto/given/lib.mli @@ -7,6 +7,9 @@ sig val take : int -> 'a list -> 'a list (* raise Failure *) val drop : int -> 'a list -> 'a list (* raise Failure *) + val length32 : 'a list -> int32 + val nth32 : 'a list -> int32 -> 'a (* raise Failure *) + val last : 'a list -> 'a (* raise Failure *) val split_last : 'a list -> 'a list * 'a (* raise Failure *) diff --git a/ml-proto/host/arrange.ml b/ml-proto/host/arrange.ml index 6185be79b9..61d518e17f 100644 --- a/ml-proto/host/arrange.ml +++ b/ml-proto/host/arrange.ml @@ -192,7 +192,7 @@ let storeop op = (* Expressions *) -let var x = string_of_int x.it +let var x = Int32.to_string x.it let value v = string_of_value v.it let constop v = value_type (type_of v.it) ^ ".const" diff --git a/ml-proto/host/encode.ml b/ml-proto/host/encode.ml index 7b032984ba..b4113dc5d0 100644 --- a/ml-proto/host/encode.ml +++ b/ml-proto/host/encode.ml @@ -63,14 +63,15 @@ let encode m = let vec f xs = vu (List.length xs); list f xs let vec1 f xo = bool (xo <> None); opt f xo - let gap () = let p = pos s in u32 0l; p - let patch_gap p n = + let gap32 () = let p = pos s in u32 0l; u8 0; p + let patch_gap32 p n = assert (n <= 0x0fff_ffff); (* Strings cannot excess 2G anyway *) let lsb i = Char.chr (i land 0xff) in patch s p (lsb (n lor 0x80)); patch s (p + 1) (lsb ((n lsr 7) lor 0x80)); patch s (p + 2) (lsb ((n lsr 14) lor 0x80)); - patch s (p + 3) (lsb (n lsr 21)) + patch s (p + 3) (lsb ((n lsr 21) lor 0x80)); + patch s (p + 4) (lsb (n lsr 28)) (* Types *) @@ -98,8 +99,7 @@ let encode m = let op n = u8 n let memop {align; offset; _} = vu align; vu64 offset (*TODO: to be resolved*) - let var x = vu x.it - let var32 x = vu32 (Int32.of_int x.it) + let var x = vu32 x.it let rec instr e = match e.it with @@ -113,7 +113,7 @@ let encode m = | Select -> op 0x05 | Br (n, x) -> op 0x06; vu n; var x | BrIf (n, x) -> op 0x07; vu n; var x - | BrTable (n, xs, x) -> op 0x08; vu n; vec var32 xs; var32 x + | BrTable (n, xs, x) -> op 0x08; vu n; vec var xs; var x | Return -> op 0x09 | Nop -> op 0x0a | Drop -> op 0x0b @@ -334,16 +334,16 @@ let encode m = let section id f x needed = if needed then begin - string id; - let g = gap () in + u8 id; + let g = gap32 () in let p = pos s in f x; - patch_gap g (pos s - p) + patch_gap32 g (pos s - p) end (* Type section *) let type_section ts = - section "type" (vec func_type) ts (ts <> []) + section 1 (vec func_type) ts (ts <> []) (* Import section *) let import imp = @@ -351,13 +351,13 @@ let encode m = var itype; string module_name; string func_name let import_section imps = - section "import" (vec import) imps (imps <> []) + section 2 (vec import) imps (imps <> []) (* Function section *) let func f = var f.it.ftype let func_section fs = - section "function" (vec func) fs (fs <> []) + section 3 (vec func) fs (fs <> []) (* Table section *) let limits vu lim = @@ -369,7 +369,7 @@ let encode m = elem_type etype; limits vu32 tlimits let table_section tabo = - section "table" (opt table) tabo (tabo <> None) + section 4 (opt table) tabo (tabo <> None) (* Memory section *) let memory mem = @@ -377,7 +377,7 @@ let encode m = limits vu32 mlimits let memory_section memo = - section "memory" (opt memory) memo (memo <> None) + section 5 (opt memory) memo (memo <> None) (* Global section *) let global g = @@ -385,7 +385,7 @@ let encode m = value_type gtype; const value let global_section gs = - section "global" (vec global) gs (gs <> []) + section 6 (vec global) gs (gs <> []) (* Export section *) let export exp = @@ -398,11 +398,11 @@ let encode m = let export_section exps = (*TODO: pending resolution*) let exps = List.filter (fun exp -> exp.it.kind <> `Memory) exps in - section "export" (vec export) exps (exps <> []) + section 7 (vec export) exps (exps <> []) (* Start section *) let start_section xo = - section "start" (opt var) xo (xo <> None) + section 8 (opt var) xo (xo <> None) (* Code section *) let compress ts = @@ -415,14 +415,15 @@ let encode m = let code f = let {locals; body; _} = f.it in - vec local (compress locals); - let g = gap () in + let g = gap32 () in let p = pos s in + vec local (compress locals); list instr body; - patch_gap g (pos s - p) + u8 0x0f; + patch_gap32 g (pos s - p) let code_section fs = - section "code" (vec code) fs (fs <> []) + section 9 (vec code) fs (fs <> []) (* Element section *) let segment dat seg = @@ -433,14 +434,14 @@ let encode m = segment (vec var) seg let elem_section elems = - section "element" (vec table_segment) elems (elems <> []) + section 10 (vec table_segment) elems (elems <> []) (* Data section *) let memory_segment seg = segment string seg let data_section data = - section "data" (vec memory_segment) data (data <> []) + section 11 (vec memory_segment) data (data <> []) (* Module *) @@ -455,8 +456,8 @@ let encode m = global_section m.it.globals; export_section m.it.exports; start_section m.it.start; - code_section m.it.funcs; elem_section m.it.elems; + code_section m.it.funcs; data_section m.it.data end in E.module_ m; to_string s diff --git a/ml-proto/host/import.ml b/ml-proto/host/import.ml index 0cf09a148e..5489bd7251 100644 --- a/ml-proto/host/import.ml +++ b/ml-proto/host/import.ml @@ -13,7 +13,7 @@ let register name lookup = registry := Registry.add name lookup !registry let lookup m import = let {module_name; func_name; itype} = import.it in - let ty = List.nth m.it.types itype.it in + let ty = Lib.List.nth32 m.it.types itype.it in try Registry.find module_name !registry func_name ty with Not_found -> Unknown.error import.at ("no function \"" ^ module_name ^ "." ^ func_name ^ diff --git a/ml-proto/host/parser.mly b/ml-proto/host/parser.mly index 4f1dae6af0..ed93f96158 100644 --- a/ml-proto/host/parser.mly +++ b/ml-proto/host/parser.mly @@ -35,36 +35,31 @@ let ati i = (* Literals *) let literal f s = - try f s with - | Failure msg -> error s.at ("constant out of range: " ^ msg) - | _ -> error s.at "constant out of range" + try f s with Failure _ -> error s.at ("constant out of range") let int s at = - try int_of_string s with Failure _ -> - error at "int constant out of range" + try int_of_string s with Failure _ -> error at "int constant out of range" let int32 s at = - try I32.of_string s with Failure _ -> - error at "i32 constant out of range" + try I32.of_string s with Failure _ -> error at "i32 constant out of range" let int64 s at = - try I64.of_string s with Failure _ -> - error at "i64 constant out of range" + try I64.of_string s with Failure _ -> error at "i64 constant out of range" (* Symbolic variables *) module VarMap = Map.Make(String) -type space = {mutable map : int VarMap.t; mutable count : int} -let empty () = {map = VarMap.empty; count = 0} +type space = {mutable map : int32 VarMap.t; mutable count : int32} +let empty () = {map = VarMap.empty; count = 0l} -type types = {mutable tmap : int VarMap.t; mutable tlist : Types.func_type list} +type types = {mutable tmap : int32 VarMap.t; mutable tlist : Types.func_type list} let empty_types () = {tmap = VarMap.empty; tlist = []} type context = {types : types; funcs : space; imports : space; - locals : space; globals : space; labels : int VarMap.t} + locals : space; globals : space; labels : int32 VarMap.t} let empty_context () = {types = empty_types (); funcs = empty (); imports = empty (); @@ -93,49 +88,50 @@ let label c x = let bind_type c x ty = if VarMap.mem x.it c.types.tmap then error x.at ("duplicate type " ^ x.it); - c.types.tmap <- VarMap.add x.it (List.length c.types.tlist) c.types.tmap; + c.types.tmap <- + VarMap.add x.it (Lib.List.length32 c.types.tlist) c.types.tmap; c.types.tlist <- c.types.tlist @ [ty] let bind category space x = if VarMap.mem x.it space.map then error x.at ("duplicate " ^ category ^ " " ^ x.it); space.map <- VarMap.add x.it space.count space.map; - space.count <- space.count + 1 + space.count <- Int32.add space.count 1l let bind_func c x = bind "function" c.funcs x let bind_import c x = bind "import" c.imports x let bind_local c x = bind "local" c.locals x let bind_global c x = bind "global" c.globals x let bind_label c x = - {c with labels = VarMap.add x.it 0 (VarMap.map ((+) 1) c.labels)} + {c with labels = VarMap.add x.it 0l (VarMap.map (Int32.add 1l) c.labels)} let anon_type c ty = c.types.tlist <- c.types.tlist @ [ty] -let anon space n = space.count <- space.count + n +let anon space n = space.count <- Int32.add space.count n -let anon_func c = anon c.funcs 1 -let anon_import c = anon c.imports 1 -let anon_locals c ts = anon c.locals (List.length ts) -let anon_global c = anon c.globals 1 -let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels} +let anon_func c = anon c.funcs 1l +let anon_import c = anon c.imports 1l +let anon_locals c ts = anon c.locals (Lib.List.length32 ts) +let anon_global c = anon c.globals 1l +let anon_label c = {c with labels = VarMap.map (Int32.add 1l) c.labels} let empty_type = FuncType ([], []) let explicit_decl c name t at = let x = name c type_ in if - x.it < List.length c.types.tlist && + x.it < Lib.List.length32 c.types.tlist && t <> empty_type && - t <> List.nth c.types.tlist x.it + t <> Lib.List.nth32 c.types.tlist x.it then error at "signature mismatch"; x let implicit_decl c t at = match Lib.List.index_of t c.types.tlist with - | None -> let i = List.length c.types.tlist in anon_type c t; i @@ at - | Some i -> i @@ at + | None -> let i = Lib.List.length32 c.types.tlist in anon_type c t; i @@ at + | Some i -> Int32.of_int i @@ at %} @@ -222,7 +218,7 @@ literal : ; var : - | NAT { let at = at () in fun c lookup -> int $1 at @@ at } + | NAT { let at = at () in fun c lookup -> int32 $1 at @@ at } | VAR { let at = at () in fun c lookup -> lookup c ($1 @@ at) @@ at } ; var_list : @@ -358,7 +354,7 @@ func_body : | instr_list { empty_type, fun c -> let c' = anon_label c in - {ftype = -1 @@ at(); locals = []; body = $1 c'} } + {ftype = -1l @@ at(); locals = []; body = $1 c'} } | LPAR LOCAL value_type_list RPAR func_body { fst $5, fun c -> anon_locals c $3; let f = (snd $5) c in @@ -397,7 +393,8 @@ export_opt : | /* empty */ { fun c -> [] } | TEXT { let at = at () in - fun c -> [{name = $1; kind = `Func (c.funcs.count - 1 @@ at)} @@ at] } + fun c -> + [{name = $1; kind = `Func (Int32.sub c.funcs.count 1l @@ at)} @@ at] } ; diff --git a/ml-proto/host/print.ml b/ml-proto/host/print.ml index 68c29a47fc..bd4b47c6b5 100644 --- a/ml-proto/host/print.ml +++ b/ml-proto/host/print.ml @@ -8,7 +8,7 @@ open Printf open Types let func_type m f = - List.nth m.it.types f.it.ftype.it + Lib.List.nth32 m.it.types f.it.ftype.it let string_of_table_type = function | None -> "()" @@ -25,12 +25,12 @@ let print_export m i ex = let {name; kind} = ex.it in let ascription = match kind with - | `Func x -> string_of_func_type (func_type m (List.nth m.it.funcs x.it)) + | `Func x -> string_of_func_type (func_type m (Lib.List.nth32 m.it.funcs x.it)) | `Memory -> "memory" in printf "export \"%s\" : %s\n" name ascription let print_start start = - Lib.Option.app (fun x -> printf "start = func %d\n" x.it) start + Lib.Option.app (fun x -> printf "start = func %ld\n" x.it) start (* Ast *) diff --git a/ml-proto/spec/ast.ml b/ml-proto/spec/ast.ml index be20bab1b8..0739ef0d09 100644 --- a/ml-proto/spec/ast.ml +++ b/ml-proto/spec/ast.ml @@ -70,7 +70,7 @@ type storeop = Memory.mem_size memop (* Expressions *) -type var = int Source.phrase +type var = int32 Source.phrase type literal = value Source.phrase type instr = instr' Source.phrase diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index a15d3131fb..bf3b46714e 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -36,8 +36,8 @@ type context = } let lookup category list x = - try List.nth list x.it with Failure _ -> - error x.at ("unknown " ^ category ^ " " ^ string_of_int x.it) + try Lib.List.nth32 list x.it with Failure _ -> + error x.at ("unknown " ^ category ^ " " ^ Int32.to_string x.it) let type_ types x = lookup "function type" types x let func c x = lookup "function" c.funcs x diff --git a/ml-proto/spec/decode.ml b/ml-proto/spec/decode.ml index 5243852916..2859e9fa60 100644 --- a/ml-proto/spec/decode.ml +++ b/ml-proto/spec/decode.ml @@ -5,21 +5,18 @@ type stream = name : string; bytes : string; pos : int ref; - len : int } exception EOS -let stream name bs = {name; bytes = bs; pos = ref 0; len = String.length bs} -let substream s end_ = {s with len = end_} +let stream name bs = {name; bytes = bs; pos = ref 0} -let len s = s.len +let len s = String.length s.bytes let pos s = !(s.pos) let eos s = (pos s = len s) let check n s = if pos s + n > len s then raise EOS let skip n s = check n s; s.pos := !(s.pos) + n -let rewind p s = s.pos := p let read s = Char.code (s.bytes.[!(s.pos)]) let peek s = if eos s then None else Some (read s) @@ -80,34 +77,53 @@ let u64 s = let hi = Int64.of_int32 (u32 s) in Int64.(add lo (shift_left hi 32)) -let rec vu64 s = +let rec vuN n s = + require (n > 0) s (pos s) "integer representation too long"; let b = u8 s in + require (n >= 7 || b land 0x7f < 1 lsl n) s (pos s - 1) "integer out of range"; let x = Int64.of_int (b land 0x7f) in - if b land 0x80 = 0 then x - else Int64.(logor x (shift_left (vu64 s) 7)) - (*TODO: check for overflow*) + if b land 0x80 = 0 then x else Int64.(logor x (shift_left (vuN (n - 7) s) 7)) -let rec vs64 s = +let rec vsN n s = + require (n > 0) s (pos s) "integer representation too long"; let b = u8 s in + let mask = (-1 lsl n) land 0x7f in + require (n >= 7 || b land mask = 0 || b land mask = mask) s (pos s - 1) + "integer too large"; let x = Int64.of_int (b land 0x7f) in if b land 0x80 = 0 then (if b land 0x40 = 0 then x else Int64.(logor x (logxor (-1L) 0x7fL))) - else Int64.(logor x (shift_left (vs64 s) 7)) - (*TODO: check for overflow*) - -let vu32 s = Int64.to_int32 (vu64 s) (*TODO:check overflow*) -let vs32 s = Int64.to_int32 (vs64 s) (*TODO:check overflow*) -let vu s = Int64.to_int (vu64 s) (*TODO:check overflow*) + else Int64.(logor x (shift_left (vsN (n - 7) s) 7)) + +let vu1 s = Int64.to_int (vuN 1 s) +let vu7 s = Int64.to_int (vuN 7 s) +let vu32 s = Int64.to_int32 (vuN 32 s) +let vs32 s = Int64.to_int32 (vsN 32 s) +let vu64 s = vuN 64 s +let vs64 s = vsN 64 s let f32 s = F32.of_bits (u32 s) let f64 s = F64.of_bits (u64 s) -let bool s = match get s with 0 | 1 as n -> n <> 0 | _ -> error s (pos s - 1) "invalid boolean" -let string s = let n = vu s in get_string n s +let len32 s = + let pos = pos s in + let n = vu32 s in + if n <= Int32.of_int (len s) then Int32.to_int n else + error s pos "length out of bounds" + +let bool s = (vu1 s = 1) +let string s = let n = len32 s in get_string n s let rec list f n s = if n = 0 then [] else let x = f s in x :: list f (n - 1) s let opt f b s = if b then Some (f s) else None -let vec f s = let n = vu s in list f n s +let vec f s = let n = len32 s in list f n s let vec1 f s = let b = bool s in opt f b s +let sized f s = + let size = len32 s in + let start = pos s in + let x = f s in + require (pos s = start + size) s start "section size mismatch"; + x + (* Types *) @@ -139,16 +155,15 @@ open Ast open Operators let op s = u8 s -let arity s = vu s +let arity s = u8 s let memop s = - let align = vu s in + let align = len32 s in (*TODO: check flag bits*) let offset = vu64 s in align, offset -let var s = vu s -let var32 s = Int32.to_int (vu32 s) +let var s = vu32 s let rec args n stack s pos = args' n stack [] s pos and args' n stack es s pos = @@ -404,7 +419,7 @@ and instr_block' s es = let const s = let c = at instr_block s in - expect 0x0f s "`end` opcode expected"; + expect 0x0f s "END opcode expected"; c @@ -415,30 +430,28 @@ let trace s name = (name ^ " @ " ^ string_of_int (pos s) ^ " = " ^ string_of_byte (read s)) let id s = - match string s with - | "type" -> `TypeSection - | "import" -> `ImportSection - | "function" -> `FuncSection - | "table" -> `TableSection - | "memory" -> `MemorySection - | "global" -> `GlobalSection - | "export" -> `ExportSection - | "start" -> `StartSection - | "code" -> `CodeSection - | "element" -> `ElemSection - | "data" -> `DataSection - | _ -> `UnknownSection + let bo = peek s in + Lib.Option.map + (function + | 0 -> `UserSection + | 1 -> `TypeSection + | 2 -> `ImportSection + | 3 -> `FuncSection + | 4 -> `TableSection + | 5 -> `MemorySection + | 6 -> `GlobalSection + | 7 -> `ExportSection + | 8 -> `StartSection + | 9 -> `CodeSection + | 10 -> `ElemSection + | 11 -> `DataSection + | _ -> error s (pos s) "invalid section id" + ) bo let section tag f default s = - if eos s then default else - let start_pos = pos s in - if id s <> tag then (rewind start_pos s; default) else - let size = vu s in - let content_pos = pos s in - let s' = substream s (content_pos + size) in - let x = f s' in - require (eos s') s' (pos s') "junk at end of section"; - x + match id s with + | Some tag' when tag' = tag -> ignore (get s); sized f s + | _ -> default (* Type section *) @@ -523,18 +536,18 @@ let start_section s = (* Code section *) let local s = - let n = vu s in + let n = len32 s in let t = value_type s in Lib.List.make n t let code s = let locals = List.flatten (vec local s) in - let size = vu s in - let body = instr_block (substream s (pos s + size)) in - {locals; body; ftype = Source.((-1) @@ Source.no_region)} + let body = instr_block s in + expect 0x0f s "END opcode expected"; + {locals; body; ftype = Source.((-1l) @@ Source.no_region)} let code_section s = - section `CodeSection (vec (at code)) [] s + section `CodeSection (vec (at (sized code))) [] s (* Element section *) @@ -560,10 +573,10 @@ let data_section s = section `DataSection (vec (at memory_segment)) [] s -(* Unknown section *) +(* User section *) -let unknown_section s = - section `UnknownSection (fun s -> skip (len s - pos s) s; true) false s +let user_section s = + section `UserSection (fun s -> skip (len s - pos s) s; true) false s (* Modules *) @@ -575,31 +588,29 @@ let module_ s = require (magic = 0x6d736100l) s 0 "magic header not detected"; let version = u32 s in require (version = Encode.version) s 4 "unknown binary version"; - iterate unknown_section s; + iterate user_section s; let types = type_section s in - iterate unknown_section s; + iterate user_section s; let imports = import_section s in - iterate unknown_section s; + iterate user_section s; let func_types = func_section s in - iterate unknown_section s; + iterate user_section s; let table = table_section s in - iterate unknown_section s; + iterate user_section s; let memory = memory_section s in - iterate unknown_section s; + iterate user_section s; let globals = global_section s in - iterate unknown_section s; + iterate user_section s; let exports = export_section s in - iterate unknown_section s; + iterate user_section s; let start = start_section s in - iterate unknown_section s; - let func_bodies = code_section s in - iterate unknown_section s; + iterate user_section s; let elems = elem_section s in - iterate unknown_section s; + iterate user_section s; + let func_bodies = code_section s in + iterate user_section s; let data = data_section s in - iterate unknown_section s; - (*TODO: name section*) - iterate unknown_section s; + iterate user_section s; require (pos s = len s) s (len s) "junk after last section"; require (List.length func_types = List.length func_bodies) s (len s) "function and code section have inconsistent lengths"; diff --git a/ml-proto/spec/eval.ml b/ml-proto/spec/eval.ml index 715d676abe..52c8e47640 100644 --- a/ml-proto/spec/eval.ml +++ b/ml-proto/spec/eval.ml @@ -16,8 +16,8 @@ type 'a map = 'a Map.t type instance = { module_ : module_; - imports : (int * import) list; - exports : int map; + imports : (int32 * import) list; + exports : int32 map; table : Table.t option; memory : Memory.t option; globals : value ref list; @@ -65,8 +65,8 @@ type config = let resource_limit = 1000 let lookup category list x = - try List.nth list x.it with Failure _ -> - Crash.error x.at ("undefined " ^ category ^ " " ^ string_of_int x.it) + try Lib.List.nth32 list x.it with Failure _ -> + Crash.error x.at ("undefined " ^ category ^ " " ^ Int32.to_string x.it) let type_ c x = lookup "type" c.instance.module_.it.types x let func c x = lookup "function" c.instance.module_.it.funcs x @@ -270,11 +270,11 @@ let rec step_instr (c : config) (vs : value stack) (e : instr) | Label (es_cont, vs', []), vs -> vs' @ vs, [] - | Label (es_cont, vs', {it = Br (n, i); _} :: es), vs when i.it = 0 -> + | Label (es_cont, vs', {it = Br (n, i); _} :: es), vs when i.it = 0l -> keep n vs' e.at @ vs, es_cont | Label (es_cont, vs', {it = Br (n, i); at} :: es), vs -> - vs', [Br (n, (i.it - 1) @@ i.at) @@ e.at] + vs', [Br (n, (Int32.sub i.it 1l) @@ i.at) @@ e.at] | Label (es_cont, vs', {it = Return; at} :: es), vs -> vs', [Return @@ at] @@ -289,7 +289,7 @@ let rec step_instr (c : config) (vs : value stack) (e : instr) | Local (n, vs_local, vs', []), vs -> vs' @ vs, [] - | Local (n, vs_local, vs', {it = Br (n', i); at} :: es), vs when i.it = 0 -> + | Local (n, vs_local, vs', {it = Br (n', i); at} :: es), vs when i.it = 0l -> if n <> n' then Crash.error at "inconsistent result arity"; keep n vs' at @ vs, [] diff --git a/ml-proto/spec/kernel.ml b/ml-proto/spec/kernel.ml index d89b12debf..d04f936a9b 100644 --- a/ml-proto/spec/kernel.ml +++ b/ml-proto/spec/kernel.ml @@ -67,7 +67,7 @@ type hostop = (* Expressions *) -type var = int Source.phrase +type var = int32 Source.phrase type literal = value Source.phrase type expr = expr' Source.phrase diff --git a/ml-proto/spec/table.ml b/ml-proto/spec/table.ml index a2b96375a0..9e9e9eda37 100644 --- a/ml-proto/spec/table.ml +++ b/ml-proto/spec/table.ml @@ -4,7 +4,7 @@ open Values type size = int32 type index = int32 -type elem = int option +type elem = int32 option type elem_type = Types.elem_type type table' = elem array diff --git a/ml-proto/spec/table.mli b/ml-proto/spec/table.mli index 579c917545..5cbfa7bb51 100644 --- a/ml-proto/spec/table.mli +++ b/ml-proto/spec/table.mli @@ -4,7 +4,7 @@ type t = table type size = int32 type index = int32 -type elem = int option +type elem = int32 option type elem_type = Types.elem_type exception Bounds diff --git a/ml-proto/test/br.wast b/ml-proto/test/br.wast index da7f1074dd..964aa0cfa2 100644 --- a/ml-proto/test/br.wast +++ b/ml-proto/test/br.wast @@ -429,6 +429,6 @@ "unknown label" ) (assert_invalid - (module (func $large-label (br 0x100000001))) + (module (func $large-label (br 0x10000001))) "unknown label" ) diff --git a/ml-proto/test/br_if.wast b/ml-proto/test/br_if.wast index 957cec4a4b..ed98fa4091 100644 --- a/ml-proto/test/br_if.wast +++ b/ml-proto/test/br_if.wast @@ -319,7 +319,7 @@ "unknown label" ) (assert_invalid - (module (func $large-label (br_if 0x100000001 (i32.const 1)))) + (module (func $large-label (br_if 0x10000001 (i32.const 1)))) "unknown label" ) diff --git a/ml-proto/test/br_table.wast b/ml-proto/test/br_table.wast index ff46c57428..5b834d0735 100644 --- a/ml-proto/test/br_table.wast +++ b/ml-proto/test/br_table.wast @@ -1378,7 +1378,7 @@ ) (assert_invalid (module (func $large-label - (block (br_table 0 0x100000001 0 (i32.const 1))) + (block (br_table 0 0x10000001 0 (i32.const 1))) )) "unknown label" ) @@ -1397,7 +1397,7 @@ ) (assert_invalid (module (func $large-label-default - (block (br_table 0 0 0x100000001 (i32.const 1))) + (block (br_table 0 0 0x10000001 (i32.const 1))) )) "unknown label" ) diff --git a/ml-proto/test/call.wast b/ml-proto/test/call.wast index 056412bca0..67d95c26f5 100644 --- a/ml-proto/test/call.wast +++ b/ml-proto/test/call.wast @@ -236,6 +236,6 @@ "unknown function" ) (assert_invalid - (module (func $large-func (call 10001232130000))) + (module (func $large-func (call 1012321300))) "unknown function" ) diff --git a/ml-proto/test/call_indirect.wast b/ml-proto/test/call_indirect.wast index 2b464d7f1a..6788b1b3c8 100644 --- a/ml-proto/test/call_indirect.wast +++ b/ml-proto/test/call_indirect.wast @@ -371,7 +371,7 @@ (assert_invalid (module (table 0 anyfunc) - (func $large-type (call_indirect 10001232130000 (i32.const 0))) + (func $large-type (call_indirect 1012321300 (i32.const 0))) ) "unknown function type" )