From d4f2fd4ab758805e450021a6b6b235c816a6412d Mon Sep 17 00:00:00 2001 From: mzp Date: Sun, 13 Sep 2009 14:07:35 +0900 Subject: [PATCH] add pa_field --- camlp4/OMakefile | 1 + camlp4/pa_field.ml | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ swflib/OMakefile | 2 +- swflib/asm.ml | 10 ++++---- 4 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 camlp4/pa_field.ml diff --git a/camlp4/OMakefile b/camlp4/OMakefile index 054f267..b091256 100644 --- a/camlp4/OMakefile +++ b/camlp4/OMakefile @@ -16,3 +16,4 @@ OCAMLDEPFLAGS += $(OCAMLPPFLAGS) OCamlProgram(pa_oo,pa_oo) OCamlProgram(pa_monad,pa_monad) OCamlProgram(pa_openin,pa_openin) +OCamlProgram(pa_field,pa_field) diff --git a/camlp4/pa_field.ml b/camlp4/pa_field.ml new file mode 100644 index 0000000..db8f204 --- /dev/null +++ b/camlp4/pa_field.ml @@ -0,0 +1,69 @@ +(* + pa_field.ml + + To compile: + ocamlc -pp camlp4oof -g -I . -I +camlp4 -c pa_field.ml + + To use: + ocamlc -pp 'camlp4o pa_field.cmo' example.ml + or + ocaml dynlink.cma camlp4o.cma pa_field.cmo + + + {x; y} == {x=x; y=y} + + Example: + # type pt = {x:int};; + type pt = { x : int; } + # let x = 42 in {x};; + - : pt = {x = 42} + # let f {x} = x;; + val f : pt -> int = +*) + +open Camlp4.PreCast + +module Id = struct + let name = "pa_field" + let version = "$Id:$" +end + +module Field ( Syntax : Camlp4.Sig.Camlp4Syntax) = struct + include Syntax + + let stream_peek_nth n strm = + let toks = Stream.npeek n strm in + try + Some (fst (List.nth toks (pred n))) + with Failure _ -> + None + + let test_no_with = + let rec test lev strm = + match stream_peek_nth lev strm with + | Some (KEYWORD "(" | KEYWORD "with" | KEYWORD "=") -> + raise Stream.Failure + | Some (UIDENT _ | LIDENT _ | KEYWORD ".") -> + test (succ lev) strm + | _ -> () in + Gram.Entry.of_parser "test_no_with" (test 1) + + EXTEND Gram + expr: LEVEL "simple" [ + [ "{"; test_no_with; lel = label_expr_list; "}" -> + Ast.ExRec (_loc, lel, Ast.ExNil _loc) ] + ]; + + label_expr: [ + [ id = label_longident -> + Ast.RbEq (_loc, id,Ast.ExId (_loc, id)) ] + ]; + + label_patt: [ + [ id = label_longident -> + Ast.PaEq (_loc, id, Ast.PaId (_loc, id)) ] + ]; + END +end + +module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Field) diff --git a/swflib/OMakefile b/swflib/OMakefile index 67afcfd..00f92df 100644 --- a/swflib/OMakefile +++ b/swflib/OMakefile @@ -16,7 +16,7 @@ FILES[] = compile -UseCamlp4(pa_openin pa_oo) +UseCamlp4(pa_openin pa_oo pa_field) PROGRAM=../swflib OCAMLINCLUDES += $(ROOT)/base diff --git a/swflib/asm.ml b/swflib/asm.ml index dd3e139..f691015 100644 --- a/swflib/asm.ml +++ b/swflib/asm.ml @@ -156,12 +156,12 @@ module Make(Inst : Inst) = struct [u30 init]; array of_trait traits] - let to_bytes { cpool=cpool; + let to_bytes { cpool; method_info=info; - metadata=metadata; - classes=classes; - instances=instances; - scripts=scripts; + metadata; + classes; + instances; + scripts; method_bodies=bodies; } = List.concat [ [ u16 16; u16 46; ]; -- 2.11.0