OUnitTest(label , label)
OUnitTest(bytesOut , bytesOut label)
OUnitTest(bytesIn , bytesIn)
-OUnitTest(abcIn , abcIn)
+OUnitTest(abcIn , abcIn bytesIn)
OUnitTest(lowInst , lowInst bytesOut bytesIn label)
OUnitTest(highInst , highInst label cpool revList)
OUnitTest(abcOut , abcOut label bytesOut)
module type Inst = sig
type t
- val of_bytes : int Stream.t -> t
+ val of_bytes : BytesIn.t Stream.t -> t
end
-let cMajorVersion = 16
-let cMinorVersion = 46
+let cMajorVersion = 46
+let cMinorVersion = 16
module Make(Inst : Inst) = struct
open AbcType
*)
let cpool stream =
+ let int =
+ List.map (Int32.to_int) @@ carray s32 stream in
+ let uint =
+ List.map (Int32.to_int) @@ carray u32 stream in
+ let double=
+ carray d64 stream in
+ let string =
+ carray string_info stream in
+ let namespace=
+ carray namespace_info stream in
+ let namespace_set =
+ carray ns_set_info stream in
+ let multiname =
+ carray multiname_info stream in
{
- int = List.map (Int32.to_int) @@ carray s32 stream;
- uint = List.map (Int32.to_int) @@ carray u32 stream;
- double = carray d64 stream;
- string = carray string_info stream;
- namespace = carray namespace_info stream;
- namespace_set = carray ns_set_info stream;
- multiname = carray multiname_info stream
+ int; uint; double; string; namespace; namespace_set; multiname;
}
(* method info *)
local_count;
init_scope_depth;
max_scope_depth;
- code = many Inst.of_bytes @@ Stream.of_list code;
+ code = many Inst.of_bytes @@ BytesIn.of_list code;
exceptions;
method_traits = traits
}
(* 4.2 ABC File *)
let abcFile stream =
let _ =
- assert (cMajorVersion = u16 stream) in
- let _ =
assert (cMinorVersion = u16 stream) in
+ let _ =
+ assert (cMajorVersion = u16 stream) in
let cpool =
cpool stream in
let method_info =
module type Inst = sig
type t
- val of_bytes : int Stream.t -> t
+ val of_bytes : BytesIn.t Stream.t -> t
end
val cMajorVersion : int
module Make : functor (S : Inst) -> sig
open AbcType
- val of_bytes : int Stream.t -> S.t AbcType.t
+ val of_bytes : BytesIn.t Stream.t -> S.t AbcType.t
end
open Base
open OUnit
+open AbcType
let ok x y =
OUnit.assert_equal ~printer:Std.dump x y
+module A = AbcIn.Make(struct
+ type t = int
+ let of_bytes _ =
+ raise Stream.Failure
+ end)
+
let example name =
let ch =
- open_in_bin @@ Printf.sprintf "example/%s.abc" name in
- Abc.of_stream @@ Byte.of_channel ch
+ open_in_bin @@ Printf.sprintf "%s.abc" name in
+ A.of_bytes @@ BytesIn.of_channel ch
let abc =
example "hello"
let cpool =
- abc#constant_pool
+ abc.cpool
let _ =
("asm module test" >::: [
- "major/minor version" >::
- (fun () ->
- ok 16 abc#minor_version;
- ok 46 abc#major_version);
"cpool" >::: [
"integer" >::
- (fun () -> ok [] cpool#integer);
+ (fun () -> ok [] cpool.int);
"uinteger" >::
- (fun () -> ok [] cpool#uinteger);
+ (fun () -> ok [] cpool.uint);
"double" >::
- (fun () -> ok [] cpool#double);
+ (fun () -> ok [] cpool.double);
"string" >::
- (fun () -> ok [""; "Hello,world!!";"print"] cpool#string);
- "namespace" >::
+ (fun () -> ok [""; "Hello,world!!";"print"] cpool.string);
+(* TODO *)
+(* "namespace" >::
(fun () ->
- match cpool#namespace with
+ match cpool.namespace with
[ns] ->
ok (`Namespace 1l) ns
| _ ->
- assert_failure "list size is over");
+ assert_failure "list size is over");*)
+
"namespace set" >::
(fun () ->
- ok [] cpool#ns_set);
+ ok [] cpool.namespace_set);
"multiname" >::
(fun () ->
- match cpool#multiname with
- [`QName x;`QName y] ->
- ok 1 (Int32.to_int x#ns);
- ok 1 (Int32.to_int x#name);
- ok 1 (Int32.to_int y#ns);
- ok 3 (Int32.to_int y#name);
- | _ ->
- assert_failure "not qname")
+ assert_equal [QName (1,1);QName (1,3)]
+ cpool.multiname)
];
"method signature" >::
(fun () ->
- match abc#methods with
+ match abc.method_info with
[m] ->
- ok [] m#param_types;
- ok 0l m#return_type;
- ok 1l m#name;
- ok false m#need_activation;
- ok false m#need_arguments;
- ok false m#need_rest;
- ok false m#set_dxns;
- ok None m#options;
- ok None m#param_names
+ ok [] m.params;
+ ok 0 m.return;
+ ok 1 m.method_name;
+ ok 0 m.method_flags;
| _ ->
assert_failure "over size");
"metadata test" >::
(fun () ->
- ok [] abc#metadata);
+ ok [] abc.metadata);
"class and instance size has same size" >::
(fun () ->
- ok (List.length abc#instances) (List.length abc#classes));
+ ok (List.length abc.instances) (List.length abc.classes));
"instance" >::
(fun () ->
- ok [] abc#instances);
+ ok [] abc.instances);
"class" >::
(fun () ->
- ok [] abc#classes);
+ ok [] abc.classes);
"script" >::
(fun () ->
- match abc#script with
+ match abc.scripts with
[s] ->
- ok 0l s#init;
- ok [] s#traits
+ ok 0 s.init;
+ ok [] s.script_traits
| _ ->
assert_failure "error");
"method body" >::
(fun () ->
- match abc#method_body with
+ match abc.method_bodies with
[m] ->
- ok 0l m#methodi;
- ok [] m#exceptions;
- ok 1l m#local_count;
- ok 0l m#init_scope_depth;
- ok 1l m#max_scope_depth;
- ok 2l m#max_stack;
- ok [] m#traits;
- flip ok m#code [
- `GetLocal_0;
- `PushScope;
- `FindPropStrict 2l;
- `PushString 2l;
- `CallPropLex (2l,1l);
- `Pop;
- `ReturnVoid ]
+ ok 0 m.method_sig;
+ ok [] m.exceptions;
+ ok 1 m.local_count;
+ ok 0 m.init_scope_depth;
+ ok 1 m.max_scope_depth;
+ ok 2 m.max_stack;
+ ok [] m.method_traits;
+ flip ok m.code [
+ ]
| _ ->
assert_failure "error");
]) +> run_test_tt_main
open Base
+type t = int
let rec repeat n f stream =
if n <= 0 then
with End_of_file ->
None)
+let of_list xs =
+ Stream.of_list xs
+
let (++) x y =
(x lsl 8) + y
-val u8 : int Stream.t -> int
-val u16 : int Stream.t -> int
-val s24 : int Stream.t -> int
-val u30 : int Stream.t -> int
-val u32 : int Stream.t -> int32
-val s32: int Stream.t -> int32
-val d64: int Stream.t ->float
+type t = private int
+val u8 : t Stream.t -> int
+val u16 : t Stream.t -> int
+val s24 : t Stream.t -> int
+val u30 : t Stream.t -> int
+val u32 : t Stream.t -> int32
+val s32: t Stream.t -> int32
+val d64: t Stream.t ->float
+
+val of_channel : in_channel -> t Stream.t
+val of_list : int list -> t Stream.t