OSDN Git Service

Use cpp's #include instead of OCaml's include
authorMIZUNO Hiroki <mzpppp@gmail.com>
Wed, 28 May 2008 15:04:16 +0000 (00:04 +0900)
committerMIZUNO Hiroki <mzpppp@gmail.com>
Wed, 28 May 2008 15:04:16 +0000 (00:04 +0900)
- Previously,I use OCaml's include to use auto-generated code. But there are some problem around lexical-context.
  Because of ignorant of context,cpp doesn't have these problem.

.gitignore
Makefile
src/_tags
src/asm.ml
src/asm.mli
src/match.ml [deleted file]
util/instruction.ml
util/instruction.txt

index c120c03..158017d 100644 (file)
@@ -1,5 +1,5 @@
 *.bytes
-src/match_core.ml
+src/match.ml
 src/opcode.ml
 src/opcode.mli
 _build
index 4b0e30b..ac8035b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,23 +4,20 @@ byte: generate
        $(OCAMLBUILD) main.byte
 
 test: generate camlp4/TestCaseCollector.cmo
-       rm -f _build/src/match.cm[oi]
+       rm -f _build/src/asm.cm[oi]
        $(OCAMLBUILD) runner.byte --
 
-generate: src/match_core.ml src/opcode.ml src/opcode.mli
+generate: src/match.ml src/opcode.ml
 
-src/match_core.ml : util/instruction.txt
+src/match.ml : util/instruction.txt
        $(OCAMLBUILD) -quiet util/instruction.byte -- -m < util/instruction.txt > $@
 
-src/opcode.mli : util/instruction.txt
-       $(OCAMLBUILD) -quiet util/instruction.byte -- -i < util/instruction.txt > $@
-
 src/opcode.ml : util/instruction.txt
        $(OCAMLBUILD) -quiet util/instruction.byte -- -t < util/instruction.txt > $@
 
 clean:
        ocamlbuild -clean
-       rm -f  *~ */*~ *.abc *.cm[io] */*.cm[io] src/match_core.ml src/opcode.{ml,mli}
+       rm -f  *~ */*~ *.abc *.cm[io] */*.cm[io] src/match.ml src/opcode.{ml,mli}
 
 %.cmo:
        $(OCAMLBUILD) $@
index 89d57d1..b1e7a2f 100644 (file)
--- a/src/_tags
+++ b/src/_tags
@@ -1,3 +1,3 @@
-"match.ml": pp(cpp -I../src)
+<asm.*>: pp(cpp -I../src)
 <*.ml> and not "debug.ml":pp(camlp4o -parser OCaml -filter Camlp4ExceptionTracer -printer Auto),pkg_extlib
 <*.byte>:pkg_extlib
index cae243b..fa05e72 100644 (file)
@@ -1,8 +1,44 @@
 open Base
 open Cpool
+open Bytes
 
-include Opcode.B
-include Match
+type instruction =
+#include "opcode.ml"
+ and meth = {
+  name: string;
+  params: int list;
+  return: int;
+  flags:int;
+  instructions:instruction list;
+  traits: int list;
+  exceptions: int list;
+} 
+
+type mmap = meth Pool.map
+type config = {
+  op:     int;
+  args:   Cpool.cmap * mmap -> Bytes.t list;
+  prefix: Cpool.cmap * mmap -> Bytes.t list;
+  const:  Cpool.t;
+  meth:   meth option;
+  stack:  int;
+  scope:  int;
+  count:  int;
+}
+
+let const x _ = x
+let default = {
+  op=0;
+  args=const [];
+  prefix=const [];
+  const= Cpool.empty;
+  meth = None;
+  stack=0;
+  scope=0;
+  count=0;
+}
+
+#include "match.ml"
 
 (* convert instruction *)
 let add (max,current) n = 
index 28c8dfd..7993a9a 100644 (file)
@@ -1,4 +1,15 @@
-include Opcode.S
+
+type instruction =
+#include "opcode.ml"
+ and meth = {
+  name: string;
+  params: int list;
+  return: int;
+  flags:int;
+  instructions:instruction list;
+  traits: int list;
+  exceptions: int list;
+}
 
 val assemble : meth -> Abc.cpool * Abc.method_info list * Abc.method_body list
 
diff --git a/src/match.ml b/src/match.ml
deleted file mode 100644 (file)
index a03e1a3..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-open Opcode.B
-open Cpool
-open Bytes
-
-type mmap = meth Pool.map
-type config = {
-  op:     int;
-  args:   Cpool.cmap * mmap -> Bytes.t list;
-  prefix: Cpool.cmap * mmap -> Bytes.t list;
-  const:  Cpool.t;
-  meth:   meth option;
-  stack:  int;
-  scope:  int;
-  count:  int;
-}
-
-let const x _ = x
-let default = {
-  op=0;
-  args=const [];
-  prefix=const [];
-  const= Cpool.empty;
-  meth = None;
-  stack=0;
-  scope=0;
-  count=0;
-}
-
-#include <match_core.ml>
index 54398ef..8a7dcce 100644 (file)
@@ -42,30 +42,7 @@ let clause_of_decl {name=name;args=args;body=body} =
     Printf.sprintf "| %s %s -> {default with %s}" name args' body
 
 let output_types decls =
-  let inst = 
-    Printf.sprintf "type instruction =\n%s and meth = {
-  name: string;
-  params: int list;
-  return: int;
-  flags:int;
-  instructions:instruction list;
-  traits: int list;
-  exceptions: int list;
-}" (String.concat "\n" (List.map type_of_decl decls)) in
-    Printf.printf "module type S = sig\n %s \nend\n\n module B = struct\n %s \nend\n" inst inst
-
-let output_inf decls =
-  let inst = 
-    Printf.sprintf "type instruction =\n%s and meth = {
-  name: string;
-  params: int list;
-  return: int;
-  flags:int;
-  instructions:instruction list;
-  traits: int list;
-  exceptions: int list;
-}" (String.concat "\n" (List.map type_of_decl decls)) in
-    Printf.printf "module type S = sig\n %s \nend\n\nmodule B : S\n" inst
+  print_endline (String.concat "\n" (List.map type_of_decl decls))
 
 let output_match decls =
   let func = 
@@ -86,11 +63,9 @@ let f _ =
       done
     with End_of_file ->
       let decls' =
-       List.sort (fun {name=a} {name=b} -> compare a b) !decls in
+       !decls in
        if Sys.argv.(1) = "-t" then
          output_types decls'
-       else if Sys.argv.(1) = "-i" then
-         output_inf decls'
        else 
          output_match decls'
 
index f8a1ca2..2540759 100644 (file)
@@ -42,18 +42,18 @@ GetLocal_0: op=0xD0; stack=1;count=1
 GetLocal_1: op=0xD1; stack=1;count=2
 GetLocal_2: op=0xD2; stack=1;count=3
 GetLocal_3: op=0xD3; stack=1;count=4
-GetLocal of int: op=0x62; stack=1; args=const [u30 arg0];count=(arg0+1)
+GetLocal of int: op=0x62; stack=1; args=const [Bytes.u30 arg0];count=(arg0+1)
 SetLocal_0: op=0xD4; stack=1
 SetLocal_1: op=0xD5; stack=1
 SetLocal_2: op=0xD6; stack=1
 SetLocal_3: op=0xD7; stack=1
-SetLocal of int: op=0x63; stack=1; args=const [u30 arg0]
+SetLocal of int: op=0x63; stack=1; args=const [Bytes.u30 arg0]
 GetGlobalScope:op=0x64; stack=1
-GetScopeObject of int:op=0x65; stack=1; args=const[u8 arg0]
-GetSlot of int:op=0x6c; args=const [u30 arg0]
-SetSlot of int:op=0x6d; stack= ~-2; args=const [u30 arg0]
-GetGlobalSlot of int:op=0x6e; stack=1; args=const [u30 arg0]
-SetGlobalSlot of int:op=0x6f; stack= ~-1; args=const [u30 arg0]
+GetScopeObject of int:op=0x65; stack=1; args=const[Bytes.u8 arg0]
+GetSlot of int:op=0x6c; args=const [Bytes.u30 arg0]
+SetSlot of int:op=0x6d; stack= ~-2; args=const [Bytes.u30 arg0]
+GetGlobalSlot of int:op=0x6e; stack=1; args=const [Bytes.u30 arg0]
+SetGlobalSlot of int:op=0x6f; stack= ~-1; args=const [Bytes.u30 arg0]
 
 GetProperty of Cpool.multiname: op=0x66; const=multiname arg0; args=fun (cmap,_) ->[multiname_get arg0 cmap]
 
@@ -67,6 +67,6 @@ Pop: op=0x29; stack= ~-1
 Swap:op=0x2b
 PopScope:op=0x1d; scope= ~-1
 
-NewObject of int:op=0x55; args=const [u30 arg0]
-NewArray of int:op=0x56; args=const [u30 arg0]
+NewObject of int:op=0x55; args=const [Bytes.u30 arg0]
+NewArray of int:op=0x56; args=const [Bytes.u30 arg0]
 NewFunction of meth: op=0x40; stack=1; meth=Some arg0; args=fun (_,mmap)->[Bytes.u30 (Pool.get arg0 mmap)]