From ae398bfe0e2bce19f9604493ca40ac4c98746bfa Mon Sep 17 00:00:00 2001 From: mzp Date: Sun, 13 Sep 2009 14:40:10 +0900 Subject: [PATCH] change headr file name --- swflib/OMakefile | 3 +-- swflib/abc.ml | 2 ++ swflib/gen_inst.ml | 10 +++++++--- swflib/gen_typemap.ml | 36 +++++++++++++++++++++++------------- swflib/highInst.mlp | 13 +++++++++++++ swflib/highInstTest.ml | 11 +++++++++++ 6 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 swflib/abc.ml create mode 100644 swflib/highInstTest.ml diff --git a/swflib/OMakefile b/swflib/OMakefile index 73c967b..1d4741d 100644 --- a/swflib/OMakefile +++ b/swflib/OMakefile @@ -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 index 0000000..c22853f --- /dev/null +++ b/swflib/abc.ml @@ -0,0 +1,2 @@ +module A = Asm.Make(LowInst) +(*module C = Compile.Make(HighInst)*) diff --git a/swflib/gen_inst.ml b/swflib/gen_inst.ml index 9e3aab4..cdc2f38 100644 --- a/swflib/gen_inst.ml +++ b/swflib/gen_inst.ml @@ -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 ] diff --git a/swflib/gen_typemap.ml b/swflib/gen_typemap.ml index 34b51a6..29ec44b 100644 --- a/swflib/gen_typemap.ml +++ b/swflib/gen_typemap.ml @@ -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 diff --git a/swflib/highInst.mlp b/swflib/highInst.mlp index b56174a..7ccc3db 100644 --- a/swflib/highInst.mlp +++ b/swflib/highInst.mlp @@ -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 index 0000000..100462a --- /dev/null +++ b/swflib/highInstTest.ml @@ -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 -- 2.11.0