.ocamlinit 1.94 KB
Newer Older
Pietro Abate's avatar
Pietro Abate committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#directory "_build";;
#use "topfind";;
#require "num";;
#load "cduce_boolvar.cma";;
#camlp4o;;
#require "camlp4.extend";;
#require "ulex";;
#require "pcre";;
#require "netstring";;

#load "typesOUnit.cma";;
open TypesOUnit;;
open Types;;

let parse_typ s =
  let st = Stream.of_string s in
  let astpat = Parser.pat st in
  let nodepat = Typer.typ Builtin.env astpat in
  Types.descr nodepat
;;

22 23 24 25
type pp = P of vv * string | N of string * vv
and vv = V of string

let mk_pp = function
26 27
  |P(V alpha,t) -> Tallying.CS.singleton (Tallying.Pos (Var.mk alpha,parse_typ t))
  |N(t,V alpha) -> Tallying.CS.singleton (Tallying.Neg (parse_typ t,Var.mk alpha))
28 29 30

let mk_prod l =
    List.fold_left (fun acc2 c ->
Pietro Abate's avatar
Pietro Abate committed
31
      Tallying.CS.prod Var.Set.empty (mk_pp c) acc2
32 33 34 35 36 37 38 39 40 41
    ) Tallying.CS.sat l

let mk_union l1 l2 =
  Tallying.CS.union (mk_prod l1) (mk_prod l2)

let mk_s ll =
  List.fold_left (fun acc1 l ->
    Tallying.CS.union (mk_prod l) acc1
  ) Tallying.CS.S.empty ll

42 43
module BIN = struct
  open Builtin_defs
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  (* Types *)

  let stringn = Types.cons string
  let namespaces =
    Sequence.star (Types.times stringn stringn)

  let types =
    [
      "Empty",   Types.empty;
      "Any",     any;
      "Int",     int;
      "Char",    Types.char Chars.any;
      "Byte",    char_latin1;
      "Atom",    atom;
      "Pair",    Types.Product.any;
      "Arrow",   Types.Arrow.any;
      "Record",  Types.Record.any;
      "String",  string;
      "Latin1",  string_latin1;
      "Bool",    bool;
      "Float",   float;
      "AnyXml",  any_xml;
      "Namespaces", namespaces;
      "Caml_int", caml_int;
    ]

  let env =
    List.fold_left
      (fun accu (n,t) ->
         let n = (Ns.empty, Ident.U.mk n) in
         Types.Print.register_global "" n t;
         Typer.enter_type (Ident.ident n) t accu
      )
      Typer.empty_env
      types
end

let parse_expr s =
  let astexpr = Parser.expr (Stream.of_string s) in
  let texpr = fst (Typer.type_expr BIN.env astexpr) in
  texpr
;;