OSDN Git Service

update reloc module
authormzp <mzpppp@gmail.com>
Sun, 8 Nov 2009 06:30:04 +0000 (15:30 +0900)
committermzp <mzpppp@gmail.com>
Sun, 8 Nov 2009 06:30:04 +0000 (15:30 +0900)
link/OMakefile
link/reloc.ml
link/reloc.mli [new file with mode: 0644]
link/relocTest.ml [new file with mode: 0644]

index 0e7096a..afd4049 100644 (file)
@@ -34,6 +34,7 @@ OCamlProgram($(PROGRAM), main $(FILES))
 # ------------------------------
 OUnitTest(cmdOpt, cmdOpt $(ROOT)/config)
 OUnitTest(link,   link)
+OUnitTest(reloc,   reloc)
 
 # ------------------------------
 # PHONY target
index 30eba91..f019a63 100644 (file)
@@ -127,7 +127,6 @@ let reloc_method_info {multiname} m =
 
 let reloc_method ctx m =
   { m with
-      method_sig = ctx.methods m.method_sig;
       code       = rmap reloc_code ctx m.code;
       method_traits = reloc_traits ctx m.method_traits
   }
diff --git a/link/reloc.mli b/link/reloc.mli
new file mode 100644 (file)
index 0000000..3a6e10e
--- /dev/null
@@ -0,0 +1,14 @@
+type reloc = int -> int
+type t = {
+  int       : reloc;
+  uint      : reloc;
+  double    : reloc;
+  string    : reloc;
+  namespace     : reloc;
+  namespace_set : reloc;
+  multiname : reloc;
+  methods   : reloc;
+  classes   : reloc
+}
+
+val reloc : t -> Swflib.Abc.t -> Swflib.Abc.t
diff --git a/link/relocTest.ml b/link/relocTest.ml
new file mode 100644 (file)
index 0000000..16a7743
--- /dev/null
@@ -0,0 +1,177 @@
+open Base
+open OUnit
+open Swflib.AbcType
+open Reloc
+
+let plus n x = n + x
+let ctx = {
+  int       = plus 1;
+  uint      = plus 2;
+  double    = plus 3;
+  string    = plus 4;
+  namespace     = plus 5;
+  namespace_set = plus 6;
+  multiname = plus 7;
+  methods   = plus 8;
+  classes   = plus 9
+}
+let ok x y = assert_equal x @@ reloc ctx y
+
+let cpool = {
+  Swflib.AbcType.int = [];
+  uint          = [];
+  double        = [];
+  string        = [];
+  namespace     = [];
+  namespace_set = [];
+  multiname     = [];
+}
+
+let abc = {
+  Swflib.AbcType.cpool         = cpool;
+  method_info   = [];
+  metadata      = [];
+  classes       = [];
+  instances     = [];
+  scripts       = [];
+  method_bodies = []
+}
+
+let info = {
+  params       = [];
+  return       = 0;
+  method_name  = 0;
+  method_flags = []
+}
+
+let body = {
+  method_sig       = 0;
+  max_stack        = 0;
+  local_count      = 0;
+  init_scope_depth = 0;
+  max_scope_depth  = 0;
+  code             = [];
+  exceptions       = [];
+  method_traits    = []
+}
+
+let class_ = {
+  cinit=0;
+  class_traits=[];
+}
+
+let instance={
+  instance_name=0;
+  super_name=0;
+  instance_flags=[];
+  interfaces=[];
+  iinit=0;
+  instance_traits=[]
+}
+
+
+let _ = begin "reloc.ml" >::: [
+  "cpool" >:: begin fun () ->
+    ok
+      {abc with cpool = { cpool with
+                           Swflib.AbcType.namespace     = [Namespace 4];
+                           namespace_set = [[6;7]];
+                           multiname     = [QName (6,5)]; }}
+      {abc with cpool = { cpool with
+                           Swflib.AbcType.namespace     = [Namespace 0];
+                           namespace_set = [[1;2]];
+                           multiname     = [QName(1,1)] }}
+  end;
+  "method_info" >:: begin fun () ->
+    ok
+      {abc with method_info = [{info with
+                               method_name = 7
+                              }]}
+      {abc with method_info = [ info ]}
+  end;
+  "method_body" >:: begin fun () ->
+    ok
+      {abc with method_bodies =
+         [{ body with
+              code = [
+                `PushInt 1;
+                `PushUInt 2;
+                `PushDouble 3;
+                `PushString 4;
+                `GetLex 7;
+                `GetProperty 7;
+                `SetProperty 7;
+                `InitProperty 7;
+                `FindPropStrict 7;
+                `CallProperty (7,1);
+                `CallPropLex (7,1);
+                `ConstructProp (7,1);
+                `NewFunction 8;
+                `NewClass 9;
+              ]
+          }]}
+      {abc with method_bodies =
+         [{ body with
+              code = [
+                `PushInt 0;
+                `PushUInt 0;
+                `PushDouble 0;
+                `PushString 0;
+                `GetLex 0;
+                `GetProperty 0;
+                `SetProperty 0;
+                `InitProperty 0;
+                `FindPropStrict 0;
+                `CallProperty (0,1);
+                `CallPropLex (0,1);
+                `ConstructProp (0,1);
+                `NewFunction 0;
+                `NewClass 0;
+              ]
+          }]}
+  end;
+  "class" >:: begin fun () ->
+    ok
+      {abc with Swflib.AbcType.classes = [{class_ with cinit = 8 }]}
+      {abc with Swflib.AbcType.classes = [class_]}
+  end;
+  "instance" >:: begin fun () ->
+    ok
+      {abc with instances = [{instance with iinit=8; super_name=7; instance_name=7} ]}
+      {abc with instances = [instance]}
+  end;
+  "script" >:: begin fun () ->
+    ok
+      {abc with
+        scripts=[{init=8;script_traits=[]}]}
+      {abc with
+        scripts=[{init=0;script_traits=[] }]}
+  end;
+  "trait" >:: begin fun () ->
+    ok
+      {abc with
+        scripts=[{init=8;
+                  script_traits=[
+                    {trait_name=7; trait_metadata=[]; data=SlotTrait  (0,7,0,0)};
+                    {trait_name=7; trait_metadata=[]; data=ConstTrait (0,7,0,0)};
+                    {trait_name=7; trait_metadata=[]; data=ClassTrait (0,9)};
+                    {trait_name=7; trait_metadata=[]; data=MethodTrait (0,8,[])};
+                    {trait_name=7; trait_metadata=[]; data=SetterTrait (0,8,[])};
+                    {trait_name=7; trait_metadata=[]; data=GetterTrait (0,8,[])};
+                    {trait_name=7; trait_metadata=[]; data=FunctionTrait (0,8)};
+                  ]}]}
+      {abc with
+        scripts=[{init=0;
+                  script_traits=[
+                    {trait_name=0; trait_metadata=[]; data=SlotTrait  (0,0,0,0)};
+                    {trait_name=0; trait_metadata=[]; data=ConstTrait (0,0,0,0)};
+                    {trait_name=0; trait_metadata=[]; data=ClassTrait (0,0)};
+                    {trait_name=0; trait_metadata=[]; data=MethodTrait (0,0,[])};
+                    {trait_name=0; trait_metadata=[]; data=SetterTrait (0,0,[])};
+                    {trait_name=0; trait_metadata=[]; data=GetterTrait (0,0,[])};
+                    {trait_name=0; trait_metadata=[]; data=FunctionTrait (0,0)};
+                  ] }]}
+  end
+] end +> run_test_tt_main
+
+