OSDN Git Service

change headr file name
authormzp <mzpppp@gmail.com>
Sun, 13 Sep 2009 05:40:10 +0000 (14:40 +0900)
committermzp <mzpppp@gmail.com>
Sun, 13 Sep 2009 05:40:10 +0000 (14:40 +0900)
swflib/OMakefile
swflib/abc.ml [new file with mode: 0644]
swflib/gen_inst.ml
swflib/gen_typemap.ml
swflib/highInst.mlp
swflib/highInstTest.ml [new file with mode: 0644]

index 73c967b..1d4741d 100644 (file)
@@ -35,12 +35,11 @@ OCamlProgram(gen_typemap,gen_typemap)
 OUnitTest(label   , label)
 OUnitTest(bytes   , bytes label)
 OUnitTest(lowInst , lowInst bytes)
+OUnitTest(highInst , highInst label)
 OUnitTest(asm     , asm label bytes)
 OUnitTest(compile , compile cpool bytes label revList)
 OUnitTest(revList , revList)
 OUnitTest(cpool   , cpool revList)
-OUnitTest(gTree,gTree)
-#OUnitTest(asm     , bytes asm cpool revList)
 
 # phony
 .PHONY: clean
diff --git a/swflib/abc.ml b/swflib/abc.ml
new file mode 100644 (file)
index 0000000..c22853f
--- /dev/null
@@ -0,0 +1,2 @@
+module A = Asm.Make(LowInst)
+(*module C = Compile.Make(HighInst)*)
index 9e3aab4..cdc2f38 100644 (file)
@@ -97,6 +97,9 @@ let make_pat name args =
           sprintf "(%s)" @@
             concat_mapi "," (fun _ i -> sprintf "arg%d" i) args)
 
+let call_args prefix args =
+    concat_mapi ";" (sprintf "%s_%s arg%d" prefix) args
+
 let cmds = [
   begin "-type",fun {name=name; args=args}->
      if args = [] then
@@ -111,14 +114,15 @@ let cmds = [
      let record =
        sprintf "[u8 0x%x; %s]"
         opcode
-        (concat_mapi ";" (sprintf "write_%s arg%d") args) in
+        (call_args "write" args) in
        sprintf "| %s -> %s" pat record
   end;
 
-  begin "-class",fun {name=name; args=args} ->
+  begin "-const",fun {name=name; args=args} ->
     let pat =
       make_pat name args in
-      sprintf "| %s -> %s" pat ""
+      sprintf "| %s -> some_only [%s]" pat @@
+       call_args "c" args
   end
 ]
 
index 34b51a6..29ec44b 100644 (file)
@@ -10,11 +10,18 @@ let write name ~ocaml ~byte =
 let u30 name =
   write name ~ocaml:"int" ~byte:"u30"
 
-let high name ~ocaml =
-  printf "type %s = %s\n" name ocaml
+let base name ~cpool=
+  printf "let c_%s _x = %s\n" name cpool
 
-let same name =
-  high name ~ocaml:name
+let high name ~ocaml ~cpool =
+  printf "type %s = %s\n" name ocaml;
+  base name ~cpool
+
+let lit name ~ocaml =
+  high name ~ocaml ~cpool:"None"
+
+let cpool name ~ocaml ~entry =
+  high name ~ocaml ~cpool:(sprintf "Some (`%s _x)" entry)
 
 let _ =
   match Sys.argv.(1) with
@@ -35,14 +42,17 @@ let _ =
                    Left  label   -> label_ref label
                  | Right address -> s24 address"
     | "-high" ->
-       high "c_int" ~ocaml:"int";
-       high "c_uint" ~ocaml:"int";
-       high "c_string" ~ocaml:"string";
-       high "c_float" ~ocaml:"float";
-       high"namespace" ~ocaml:"Cpool.namespace";
-       high"multiname" ~ocaml:"Cpool.multiname";
-       high "label" ~ocaml:"Label.t";
-       high "u30" ~ocaml:"int";
-       high "u8" ~ocaml:"int"
+       cpool "c_int" ~ocaml:"int" ~entry:"Int";
+       cpool "c_uint" ~ocaml:"int" ~entry:"Int";
+       cpool "c_string" ~ocaml:"string" ~entry:"String";
+       cpool "c_float" ~ocaml:"float" ~entry:"Double";
+       cpool "namespace" ~ocaml:"Cpool.namespace" ~entry:"Namespace";
+       cpool "multiname" ~ocaml:"Cpool.multiname" ~entry:"Multiname";
+       lit "label" ~ocaml:"Label.t";
+       lit "u30" ~ocaml:"int";
+       lit "u8" ~ocaml:"int";
+       base "label" ~cpool:"None";
+       base "method_" ~cpool:"None";
+       base "class_" ~cpool:"None";
     | _ ->
        exit 1
index b56174a..7ccc3db 100644 (file)
@@ -10,3 +10,16 @@ and method_ = s MethodType.method_
 and class_  = s MethodType.class_
 
 type t = LowInst.t
+
+let rec some_only =
+  function
+      [] ->
+       []
+    | None::xs ->
+       some_only xs
+    | Some x::xs ->
+       x::some_only xs
+
+let const =
+function
+#include "const.inst.h"
diff --git a/swflib/highInstTest.ml b/swflib/highInstTest.ml
new file mode 100644 (file)
index 0000000..100462a
--- /dev/null
@@ -0,0 +1,11 @@
+open Base
+open OUnit
+open HighInst
+
+let _ =
+  ("highInst.ml" >::: [
+     "const" >::
+       (fun () ->
+         assert_equal [`Int 42] (HighInst.const (`PushInt 42));
+         assert_equal [`String "foo"] (HighInst.const (`PushString "foo")))
+   ]) +> run_test_tt_main