OSDN Git Service

implements script link
authormzp <mzpppp@gmail.com>
Wed, 28 Oct 2009 23:52:35 +0000 (08:52 +0900)
committermzp <mzpppp@gmail.com>
Wed, 28 Oct 2009 23:52:35 +0000 (08:52 +0900)
link/link.ml
link/link.mli
link/linkTest.ml
link/main.ml

index 3cd0c6b..39a1ee9 100644 (file)
@@ -133,6 +133,13 @@ let reloc_instance ctx i =
      super_name    = reloc_name ctx i.super_name;
      iinit = i.iinit + ctx#methods }
 
+(* script *)
+let reloc_script ctx s =
+  {
+    init = s.init + ctx#methods;
+    script_traits = reloc_traits ctx s.script_traits
+  }
+
 let link a1 a2 =
   let ctx = {|
       cpool = {|
@@ -146,9 +153,10 @@ let link a1 a2 =
       classes = List.length a1.classes
   |} in
     { a1 with
-       cpool         = link_cpool a1.cpool a2.cpool;
+       cpool         = link_cpool                 a1.cpool         a2.cpool;
        method_info   = link reloc_method_info ctx a1.method_info   a2.method_info;
        method_bodies = link reloc_method      ctx a1.method_bodies a2.method_bodies;
        classes       = link reloc_class       ctx a1.classes       a2.classes;
-       instances     = link reloc_instance    ctx a1.instances     a2.instances
+       instances     = link reloc_instance    ctx a1.instances     a2.instances;
+       scripts       = link reloc_script      ctx a1.scripts       a2.scripts
     }
index be5c740..51f47e4 100644 (file)
@@ -1,2 +1 @@
-
 val link : Swflib.Abc.t -> Swflib.Abc.t -> Swflib.Abc.t
index 51b9c4b..6bbea7c 100644 (file)
@@ -266,7 +266,16 @@ let _ = begin "link.ml" >::: [
        [{ trait_name=1; data=SetterTrait(0,0,[]); trait_metadata=[]}]
        [{ trait_name=2; data=SetterTrait(0,1,[]); trait_metadata=[]}]
        [{ trait_name=1; data=SetterTrait(0,0,[]); trait_metadata=[]}]
-
   end;
+  "script" >:: begin fun () ->
+    lok
+      {abc with
+        method_info=[info;info];
+        scripts=[{init=0;script_traits=[]};
+                 {init=1;script_traits=[]}]}
+      {abc with
+        method_info=[info];
+        scripts=[{init=0;script_traits=[]}]}
+  end
 ] end +> run_test_tt_main
 
index aafb203..bc09a60 100644 (file)
@@ -13,6 +13,16 @@ let input_bytes ch =
     with _ ->
       List.rev !xs
 
+let abc_of_swf _ = undef
+
+let read path =
+  if Filename.check_suffix path ".abc" then
+    open_in_with path (Abc.read $ Swflib.BytesIn.of_channel)
+  else if Filename.check_suffix path ".swf" then
+    abc_of_swf @@ open_in_with path Swf.read
+  else
+    failwithf "unknow suffix: %s" path ()
+
 let _ =
   match CmdOpt.parse_argv () with
       [path], t ->