Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clear

  • Loading branch information...
commit 9ed4d98d9b21b7db2b0808d2da6ae85921211b02 2 parents 6d31ce5 + a30a483
@bobzhang authored
Showing with 3,604 additions and 36 deletions.
  1. +4 −1 .gitignore
  2. +120 −17 camlp4/explore.tex
  3. +1 −0  code/camlp4/macro/_tags
  4. +21 −0 code/camlp4/macro/testfilename.ml
  5. +1 −0  code/camlp4/type_conv/_tags
  6. +293 −0 code/camlp4/type_conv/myocamlbuild.ml
  7. +23 −0 code/camlp4/type_conv/test.ml
  8. +1 −0  code/constraint/_tags
  9. +293 −0 code/constraint/myocamlbuild.ml
  10. +73 −0 code/constraint/test.ml
  11. +1 −0  code/dynlink/_tags
  12. +27 −0 code/dynlink/main.ml
  13. +293 −0 code/dynlink/myocamlbuild.ml
  14. +21 −0 code/dynlink/reg.ml
  15. +23 −0 code/dynlink/some_module.ml
  16. +1 −0  code/js/_tags
  17. +183 −0 code/js/test.js
  18. +23 −0 code/js/test.ml
  19. +70 −0 code/net/My photo
  20. +1 −0  code/net/_tags
  21. +38 −0 code/net/dns.ml
  22. +2 −0  code/net/file0
  23. +2 −0  code/net/file1
  24. +92 −0 code/net/file2
  25. +32 −0 code/net/killall_screen.ml
  26. +293 −0 code/net/myocamlbuild.ml
  27. +39 −0 code/net/test_ftp.ml
  28. +70 −0 code/net/test_netmime.ml
  29. +1 −0  code/ocaml-maze
  30. +2 −0  code/ocaml-text/_tags
  31. +292 −0 code/ocaml-text/myocamlbuild.ml
  32. +24 −0 code/ocaml-text/patt.ml
  33. +116 −0 code/tie/testtie.ml
  34. +293 −0 code/types/myocamlbuild.ml
  35. +62 −0 code/types/type_equal.ml
  36. +1 −0  code/xstrp4/_tags
  37. +122 −0 code/xstrp4/first.ml
  38. +293 −0 code/xstrp4/myocamlbuild.ml
  39. +4 −0 compiler/dynlink.tex
  40. BIN  compiler/to
  41. +18 −0 compiler/tool.tex
  42. +1 −0  library/netclient.tex
  43. +274 −0 library/ocamlnet.tex
  44. +30 −0 library/text.tex
  45. +3 −0  library/xstrp4.tex
  46. +0 −14 master.tdo
  47. +3 −2 master.tex
  48. +5 −0 toolchain/ocamlfind.tex
  49. +9 −1 unix/#api.tex#
  50. +0 −1  unix/.#api.tex
  51. +5 −0 unix/api.tex
  52. +5 −0 unix/netclient.tex
View
5 .gitignore
@@ -21,4 +21,7 @@ _region_*
*.toc
.#.gitignore
*_build*
-*.pdf
+*.pdf
+master.tdo
+#*
+.#*
View
137 camlp4/explore.tex
@@ -23,16 +23,105 @@ \section{Camlp4 SourceCode Exploration}
`-- unmaintained
\end{bashcode}
+\subsection{Camlp4.Sig}
+For \verb|Camlp4.Sig.ml|, all are signatures. It's convention for
+ocaml programmers to document most signatures in \textit{Sig.ml}.
-\subsection{Camlp4 PreCast}
-\verb|Camlp4.PreCast (Camlp4/PreCast.ml)|
+\subsubsection{Basic Signature}
-As above,Struct directory has module \textit{Loc, Dynloader Functor,
- Camlp4Ast.Make, Token.Make, Lexer.Make, Grammar.Static.Make,
- Quotation.Make}
+\begin{ocamlcode}
+module type Type = sig
+ type t;
+end;
+\end{ocamlcode}
+\captionof{listing}{Signature with a type}
+
+\begin{ocamlcode}
+module type Error = sig
+ type t;
+ exception E of t;
+ value to_string : t -> string;
+ value print : Format.formatter -> t -> unit;
+end;
+\end{ocamlcode}
+\captionof{listing}{Error module type}
+
+Signature for errors modules, an \textit{Error} module can be
+registred with the \textit{ErrorHandler.Register} functor in order to
+be well printed.
+
+\begin{ocamlcode}
+module Warning (Loc : Type) = struct
+ module type S = sig
+ type warning = Loc.t -> string -> unit;
+ value default_warning : warning;
+ value current_warning : ref warning;
+ value print_warning : warning;
+ end;
+end;
+\end{ocamlcode}
+\captionof{listing}{Warning Functor}
+It's interesting here \textit{Warning} is a type level function
+actually. Making it a function so you can use \textit{Warning(Loc).S}
+later.
+
+\subsubsection{Advanced Signatures}
+
+\begin{description}
+\item[Loc] A signature for locations
+\item[Ast] Ast \textit{minimal, abstract} signature
+\item[Camlp4Ast] Ast \textit{concrete} signature
+\item[Camlp4AstToAst]
+ \textit{functor (M:Camp4Ast) : Ast with type .. = ...}. This
+ functor is a restriction functor. You can use it like this
+ \textit{with module Ast = Camlp4.Sig.Camlp4AstToAst Camlp4Ast}
+
+\item[MakeCamlp4Ast] the only concrete definition of camlp4 ast. You
+ can write some generic plugins here.
+\item[AstFilters] Registering and folding of Ast filters, it includes
+ \textit{Camlp4Ast} and some filter functions
+
+\item[DynAst] Asts as one single dynamic type
+
+\item[Quotation] signature for a quoation expander registery
+\item[Token] A signature around tokens.
+\item[Camlp4Token] \textit{Token with type t = camlp4\_token}
+\item[DynLoader]
+\item[Grammar]
+\item[Lexer]
+\item[Parser] Parser is a type lever function, like \textit{Warning}
+\item[Printer] The same as above
+
+\item[Syntax] A syntax module is a sort of constistent bunch of
+ modules and values. In such a module you have a parser, a printer,
+ and also modules for locations, syntax trees, tokens, grammars,
+ quotations, anti-quotations. There is also the main grammar
+ entries.
+\item[Camlp4Syntax] Ast is replaced with Camlp4Ast
+\item[SyntaxExtension] functor signature.
+
+ \begin{ocamlcode}
+module type SyntaxExtension = functor (Syn : Syntax)
+ -> (Syntax with module Loc = Syn.Loc
+ and module Ast = Syn.Ast
+ and module Token = Syn.Token
+ and module Gram = Syn.Gram
+ and module Quotation = Syn.Quotation);
+
+ \end{ocamlcode}
+\end{description}
+We can make use of these signatures to write signature file.
+\textit{Ast} is an
+
+
+\subsection{Camlp4.PreCast}
+As above,\textit{Struct}
+directory has module \textit{Loc, Dynloader
+ Functor, Camlp4Ast.Make, Token.Make, Lexer.Make,
+ Grammar.Static.Make, Quotation.Make}
File \verb|Camlp4.PreCast| Listing \ref{lst:Camlp4 PreCast}
-\textbf{Re-Export} such files
+packed such modules
\begin{bluetext}
Struct.Loc Struct.Camlp4Ast Struct.Token Struct.Grammar.Parser
@@ -48,7 +137,7 @@ \subsection{Camlp4 PreCast}
-\subsection{OCamlInitSyntax}
+\subsection{Camlp4.OCamlInitSyntax}
\verb|OCamlInitSyntax| Listing \ref{lst:OCamlInitSyntax} does not do
too many things, first, it initialize all the entries needed later
@@ -57,30 +146,44 @@ \subsection{OCamlInitSyntax}
initialize two entries \verb|antiquot_expr| and \verb|antiquot_patt|,
very easy.
+Its signature is as follows:
+\begin{ocamlcode}
+module Make (Ast : Sig.Camlp4Ast)
+ (Gram : Sig.Grammar.Static with module Loc = Ast.Loc
+ with type Token.t = Sig.camlp4_token)
+ (Quotation : Sig.Quotation with
+ module Ast = Sig.Camlp4AstToAst Ast)
+: Sig.Camlp4Syntax with module Loc = Ast.Loc
+ and module Ast = Ast
+ and module Token = Gram.Token
+ and module Gram = Gram
+ and module Quotation = Quotation
+\end{ocamlcode}
+
\inputminted[fontsize=\scriptsize,
firstline=55]{ocaml}{code/camlp4/source/precast.ml}
\captionof{listing}{OCamlInitSyntax \label{lst:OCamlInitSyntax}}
-\subsection{Camlp4.Sig}
-For \verb|Camlp4.Sig.ml|, all are signatures, there's even no
-\verb|Camlp4.Sig.mli|.
-
-
-
\subsection{Camlp4.Struct.Camlp4Ast.mlast}
This file use macro\verb|INCLUDE| to include
\verb|Camlp4.Camlp4Ast.parital.ml| for reuse.
-\subsection{AstFilters}
-Notice an interesting module \verb|AstFilters| Listing
+\subsection{Camlp4.Register.AstFilter}
+Notice an interesting module \verb|AstFilter| Listing
\ref{lst:AstFilters}, is defined by \verb|Struct.AstFilters.Make|,
which we see in \verb|Camlp4.PreCast.ml|\ref{lst:Camlp4 PreCast} It's
very simple actually.
+\begin{ocamlcode}
+module AstFilter
+ (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) =
+struct
+ declare_dyn_module Id.name (fun _ -> let module M = Maker AstFilters in ());
+\end{ocamlcode}
\inputminted[fontsize=\scriptsize,]{ocaml}{code/camlp4/source/AstFilters.ml}
\captionof{listing}{AstFilters \label{lst:AstFilters}}
@@ -143,7 +246,7 @@ \subsection{Camlp4.Register}
\end{ocamlcode}
-\subsection{Camlp4Ast}
+\section{Camlp4Ast}
As the code Listing \ref{lst:Camlp4 Ast Definition} demonstrate below,
there are several categories including \textit{ident, ctyp,patt,expr,
@@ -160,7 +263,7 @@ \subsection{Camlp4Ast}
\captionof{listing}{Camlp4 Ast Definition\label{lst:Camlp4 Ast Definition}}
-\subsection{TestFile}
+\section{TestFile}
\label{sec:testfile}
Some test files are pretty useful(in the distribution of camlp4)
like \verb|test/fixtures/macro_test.ml|.
View
1  code/camlp4/macro/_tags
@@ -0,0 +1 @@
+<testfilename.ml> : camlp4of
View
21 code/camlp4/macro/testfilename.ml
@@ -0,0 +1,21 @@
+open Format
+let __MODULE__ = String.capitalize (Filename.chop_extension __FILE__)
+let () = Printf.printf "I am in module %s\n" __MODULE__
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
1  code/camlp4/type_conv/_tags
@@ -0,0 +1 @@
+<test.ml> : camlp4o, use_type_conv
View
293 code/camlp4/type_conv/myocamlbuild.ml
@@ -0,0 +1,293 @@
+open Ocamlbuild_plugin
+open Command
+open Printf
+open Ocamlbuild_pack
+(* #directory "+ocamlbuild";;
+ #load "ocamlbuildlib.cma";;
+ for interactive debugging
+ *)
+
+let (//) = Filename.concat
+let flip f x y = f y x
+let prerr_endlinef fmt = ksprintf prerr_endline fmt
+let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
+let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
+let find_packages () =
+ blank_sep_strings &
+ Lexing.from_string &
+ run_and_read "ocamlfind list | cut -d' ' -f1"
+let compiler_lib_installed =
+ try
+ Sys.(file_exists &
+ (Filename.dirname &
+ run_and_read "ocamlfind ocamlc -where | cut -d' ' -f1" ) // "compiler-lib")
+ with e -> false
+
+(** ocamlfind can only handle these two flags *)
+let find_syntaxes () = ["camlp4o"; "camlp4r"]
+let trim_endline str =
+ let len = String.length (str) in
+ if len = 0 then str
+ else if str.[len-1] = '\n'
+ then String.sub str 0 (len-1)
+ else str
+(** list extensions, but not used here *)
+let extensions () =
+ let pas = List.filter
+ (fun x ->
+ String.contains_string x 0 "pa_" <> None) (find_packages ()) in
+ let tbl = List.map
+ (fun pkg ->
+ let dir =
+ trim_endline (run_and_read ("ocamlfind query " ^ pkg))in
+ (pkg, dir)) pas in
+ tbl
+
+let debug = ref false
+let site_lib () =
+ trim_endline (run_and_read ("ocamlfind printconf destdir"))
+
+let _ =
+ if !debug then begin
+ List.iter (fun (pkg,dir) -> Printf.printf "%s,%s\n" pkg dir)
+ (extensions ());
+ Printf.printf "%s\n" (site_lib())
+ end
+
+
+
+(* Menhir options *)
+let menhir_opts = S
+ [A"--dump";A"--explain"; A"--infer";]
+
+let ocamlfind x = S[A"ocamlfind"; x]
+module Default = struct
+ let before_options () =
+ Options.ocamlc := ocamlfind & S[A"ocamlc"; A"-annot"];
+ Options.ocamlopt := ocamlfind & S[A"ocamlopt";A"-annot"];
+ Options.ocamldep := ocamlfind & A"ocamldep";
+ Options.ocamldoc := ocamlfind & A"ocamldoc";
+ Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+ let after_rules () =
+ (*when one link an ocaml library/binary/package, should use -linkpkg*)
+ flag ["ocaml"; "byte"; "link";"program"] & A"-linkpkg";
+ flag ["ocaml"; "native"; "link";"program"] & A"-linkpkg";
+ List.iter begin fun pkg ->
+ flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["menhir"] menhir_opts; (* add support for menhir*)
+ end (find_packages ());
+ (* Like -package but for extensions syntax. Morover -syntax is
+ * useless when linking. *)
+ List.iter begin fun syntax ->
+ flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ end (find_syntaxes ());
+ (* The default "thread" tag is not compatible with ocamlfind.
+ Indeed, the default rules add the "threads.cma" or
+ "threads.cmxa" options when using this tag. When using the
+ "-linkpkg" option with ocamlfind, this module will then be
+ added twice on the command line.
+ To solve this, one approach is to add the "-thread" option when using
+ the "threads" package using the previous plugin.
+ *)
+ flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+end
+
+
+type actions = (unit -> unit) list ref
+
+let before_options : actions = ref []
+and after_options : actions = ref []
+and before_rules : actions = ref []
+and after_rules : actions = ref []
+
+let (+>) x l =
+ l := x :: !l
+
+
+
+(**
+ configuration syntax extensions
+ the key is used by ocamlfind query to get its path
+*)
+let syntax_lib_file
+ = ["bitstring",[`D "bitstring.cma" ;
+ `D "bitstring_persistent.cma";
+ `D "pa_bitstring.cmo"]
+ ;"ulex", [`D "pa_ulex.cma"]
+ ;"bolt", [`D "bolt_pp.cmo"]
+ ;"xstrp4", [`D "xstrp4.cma"]
+ ;"sexplib", [`P ("type-conv", "Pa_type_conv.cma"); `D "pa_sexp_conv.cma"]
+ ;"mikmatch_pcre", [`D "pa_mikmatch_pcre.cma"]
+ ;"meta_filter", [`D "meta_filter.cma"]
+ ;"text", [`D "text.cma"; `D "text-pcre-syntax.cma"]
+ ;"type_conv", [`D "pa_type_conv.cma"]
+ ]
+
+
+exception Next
+
+let syntax_path syntax_lib_file =
+ flip List.iter syntax_lib_file (fun (package, files) ->
+ try
+ (let package_path =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package )
+ with Failure _ ->
+ prerr_endlinef "package %s does not exist" package;
+ raise Next
+ in
+ if Sys.file_exists package_path
+ then
+ let all_path_files =
+ List.map (fun file ->
+ match file with
+ | `D file ->
+ if Sys.file_exists (package_path//file)
+ then (package_path // file)
+ else
+ (prerr_endlinef "%s does not exist " (package_path//file);
+ raise Next)
+ | `P (package,file) ->
+ let sub_pack =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package)
+ with Failure _ -> begin
+ prerr_endlinef "%s does not exist in subpackage definition" package;
+ raise Next
+ end
+ in
+ if Sys.file_exists (sub_pack//file) then
+ (sub_pack // file)
+ else
+ (prerr_endlinef "%s does not exist " (sub_pack//file);
+ raise Next )
+
+ ) files
+ in begin
+ flag ["ocaml"; "pp"; "use_"^ package]
+ (S(List.map (fun file -> A file)
+ all_path_files));
+ end
+ else begin
+ prerr_endlinef "package %s does not exist" package;
+ end
+ )
+ with Next -> ()
+ )
+
+let apply plugin = begin
+ Default.before_options +> before_options;
+ Default.after_rules +> after_rules;
+
+ (fun _ -> begin
+ syntax_path syntax_lib_file;
+
+ (** demo how to use external libraries
+ ocaml_lib ~extern:true "llvm";
+ ocaml_lib ~extern:true "llvm_analysis";
+ ocaml_lib ~extern:true "llvm_bitwriter"; *)
+
+ dep ["link"; "ocaml"; "use_plus_stubs"] ["plus_stubs.o"];
+ flag["link"; "ocaml"; "byte"] (S[A"-custom"]);
+ (if compiler_lib_installed then begin
+ flag["ocaml"; "byte"; "compile"; "use_compiler_lib"]
+ (S[A"-I"; A"+../compiler-lib"]);
+ flag["ocaml"; "program"; "byte"; "use_compiler_lib"]
+ (S[A"toplevellib.cma"]);
+ end
+ else
+ prerr_endline "compiler_lib not installed"
+ );
+ flag["pp" ; "ocaml"; "use_macro"] (S[A"-parser"; A"macro"]);
+ flag["pp" ; "ocaml"; "use_map"] (S[A"-parser"; A"map"]);
+ flag["pp" ; "ocaml"; "use_lift"] (S[A"-parser"; A"lift"]);
+ flag["pp" ; "ocaml"; "use_fold"] (S[A"-parser"; A"fold"]);
+ flag ["link";"ocaml";"g++";] (S[A"-cc"; A"g++"]);
+ flag ["ocaml"; "doc"; "use_camlp4"] (S[A"-I"; A"+camlp4"]);
+
+ dep ["ocamldep"; "file:test_lift_filter_r.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter_r.pp.ml"] ["test_type_r.ml"];
+ seems does not work, but you can build cmo files first, then build
+ the output files
+ *)
+ dep ["ocamldep"; "file:test_lift_filter.ml"] ["test_type.ml"];
+ dep ["ocamldep"; "file:test_dump.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter.pp.ml"] ["test_type.ml"]; *)
+ (* demo how to use dep *)
+ (* dep ["ocamldep"; "file:test/test_string.ml"] *)
+ (* ["test/test_data/string.txt"; *)
+ (* "test/test_data/char.txt"]; *)
+ flag ["ocaml"; "pp"; "use_gen_printer"] (A"gen_printer.cma");
+ dep ["ocamldep"; "use_gen_printer"] ["gen_printer.cma"];
+ end) +> after_rules;
+ plugin ();
+ dispatch begin function
+ | Before_options -> begin
+ List.iter (fun f -> f () ) !before_options;
+ end
+ | After_rules -> begin
+ List.iter (fun f -> f ()) !after_rules;
+ end
+ | _ -> ()
+ end ;
+end
+
+
+let _ =
+ (** customize your plugin here *)
+ let plugin = (fun _ -> ()) in
+ apply plugin
+
+
+
+(**
+ customized local filter
+*)
+(* let _ = dispatch begin function *)
+(* |After_rules -> begin *)
+(* flag ["ocaml"; "pp"; "use_filter"] (A"pa_filter.cma"); *)
+(* dep ["ocaml"; "ocamldep"; "use_filter"] ["pa_filter.cma"]; *)
+(* end *)
+(* |_ -> () *)
+(* end *)
+(** (** for pa_ulex, you must create the symbol link by yourself*)
+ flag ["ocaml"; "pp"; "use_ulex"] (A"pa_ulex.cma"); (** for bolt
+ logger *) flag ["ocaml"; "pp"; "use_bolt"] (A"bolt_pp.cmo"); (**
+ for bitstring *) flag ["ocaml"; "pp"; "use_bitstring"]
+ (S[A"bitstring.cma"; A"bitstring_persistent.cma";
+ A"pa_bitstring.cmo"]); flag ["ocaml"; "pp"; "use_xstrp4"]
+ (S[A"xstrp4.cma"]); flag ["ocaml"; "pp"; "use_sexp"]
+ (S[A"Pa_type_conv.cma"; A"pa_sexp_conv.cma"]); flag ["ocaml";
+ "pp"; "use_mikmatch"] (S[A"pa_mikmatch_pcre.cma"]); flag ["ocaml";
+ "pp"; "use_meta"] (S[A"lift_filter.cma"]);
+*)
+(**
+let gen_interface ml mli env build = Ocaml_utils.(
+ let ml = env ml and mli = env mli in
+ let tags = tags_of_pathname ml++"ocaml" in
+ Ocaml_compiler.prepare_compile build ml;
+ Cmd(S[!Options.ocamlc; ocaml_ppflags tags; ocaml_include_flags ml;
+ A"-I";
+ A"+camlp4"; (** dirty hacks to include camlp4 path for .i.mli *)
+ A"-i";
+ (if Tags.mem "thread" tags then A"-thread" else N);
+ T(tags++"infer_interface"); P ml; Sh">"; Px mli]))
+(**
+ Usage ocamlbuild xx.i.mli
+ *)
+let _ = begin
+ rule "ocaml: ml & ml.depends & *cmi -> .i.mli"
+ ~prod:"%.i.mli"
+ ~deps:["%.ml"; "%.ml.depends"]
+ (gen_interface "%.ml" "%.i.mli")
+end
+*)
View
23 code/camlp4/type_conv/test.ml
@@ -0,0 +1,23 @@
+open Format
+
+
+type t with sexp
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
1  code/constraint/_tags
@@ -0,0 +1 @@
+true : pkg_facile
View
293 code/constraint/myocamlbuild.ml
@@ -0,0 +1,293 @@
+open Ocamlbuild_plugin
+open Command
+open Printf
+open Ocamlbuild_pack
+(* #directory "+ocamlbuild";;
+ #load "ocamlbuildlib.cma";;
+ for interactive debugging
+ *)
+
+let (//) = Filename.concat
+let flip f x y = f y x
+let prerr_endlinef fmt = ksprintf prerr_endline fmt
+let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
+let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
+let find_packages () =
+ blank_sep_strings &
+ Lexing.from_string &
+ run_and_read "ocamlfind list | cut -d' ' -f1"
+let compiler_lib_installed =
+ try
+ Sys.(file_exists &
+ (Filename.dirname &
+ run_and_read "ocamlfind ocamlc -where | cut -d' ' -f1" ) // "compiler-lib")
+ with e -> false
+
+(** ocamlfind can only handle these two flags *)
+let find_syntaxes () = ["camlp4o"; "camlp4r"]
+let trim_endline str =
+ let len = String.length (str) in
+ if len = 0 then str
+ else if str.[len-1] = '\n'
+ then String.sub str 0 (len-1)
+ else str
+(** list extensions, but not used here *)
+let extensions () =
+ let pas = List.filter
+ (fun x ->
+ String.contains_string x 0 "pa_" <> None) (find_packages ()) in
+ let tbl = List.map
+ (fun pkg ->
+ let dir =
+ trim_endline (run_and_read ("ocamlfind query " ^ pkg))in
+ (pkg, dir)) pas in
+ tbl
+
+let debug = ref false
+let site_lib () =
+ trim_endline (run_and_read ("ocamlfind printconf destdir"))
+
+let _ =
+ if !debug then begin
+ List.iter (fun (pkg,dir) -> Printf.printf "%s,%s\n" pkg dir)
+ (extensions ());
+ Printf.printf "%s\n" (site_lib())
+ end
+
+
+
+(* Menhir options *)
+let menhir_opts = S
+ [A"--dump";A"--explain"; A"--infer";]
+
+let ocamlfind x = S[A"ocamlfind"; x]
+module Default = struct
+ let before_options () =
+ Options.ocamlc := ocamlfind & S[A"ocamlc"; A"-annot"];
+ Options.ocamlopt := ocamlfind & S[A"ocamlopt";A"-annot"];
+ Options.ocamldep := ocamlfind & A"ocamldep";
+ Options.ocamldoc := ocamlfind & A"ocamldoc";
+ Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+ let after_rules () =
+ (*when one link an ocaml library/binary/package, should use -linkpkg*)
+ flag ["ocaml"; "byte"; "link";"program"] & A"-linkpkg";
+ flag ["ocaml"; "native"; "link";"program"] & A"-linkpkg";
+ List.iter begin fun pkg ->
+ flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["menhir"] menhir_opts; (* add support for menhir*)
+ end (find_packages ());
+ (* Like -package but for extensions syntax. Morover -syntax is
+ * useless when linking. *)
+ List.iter begin fun syntax ->
+ flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ end (find_syntaxes ());
+ (* The default "thread" tag is not compatible with ocamlfind.
+ Indeed, the default rules add the "threads.cma" or
+ "threads.cmxa" options when using this tag. When using the
+ "-linkpkg" option with ocamlfind, this module will then be
+ added twice on the command line.
+ To solve this, one approach is to add the "-thread" option when using
+ the "threads" package using the previous plugin.
+ *)
+ flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+end
+
+
+type actions = (unit -> unit) list ref
+
+let before_options : actions = ref []
+and after_options : actions = ref []
+and before_rules : actions = ref []
+and after_rules : actions = ref []
+
+let (+>) x l =
+ l := x :: !l
+
+
+
+(**
+ configuration syntax extensions
+ the key is used by ocamlfind query to get its path
+*)
+let syntax_lib_file
+ = ["bitstring",[`D "bitstring.cma" ;
+ `D "bitstring_persistent.cma";
+ `D "pa_bitstring.cmo"]
+ ;"ulex", [`D "pa_ulex.cma"]
+ ;"bolt", [`D "bolt_pp.cmo"]
+ ;"xstrp4", [`D "xstrp4.cma"]
+ ;"sexplib", [`P ("type-conv", "Pa_type_conv.cma"); `D "pa_sexp_conv.cma"]
+ ;"mikmatch_pcre", [`D "pa_mikmatch_pcre.cma"]
+ ;"meta_filter", [`D "meta_filter.cma"]
+ ;"text", [`D "text.cma"; `D "text-pcre-syntax.cma"]
+ ;"type_conv", [`D "pa_type_conv.cma"]
+ ]
+
+
+exception Next
+
+let syntax_path syntax_lib_file =
+ flip List.iter syntax_lib_file (fun (package, files) ->
+ try
+ (let package_path =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package )
+ with Failure _ ->
+ prerr_endlinef "package %s does not exist" package;
+ raise Next
+ in
+ if Sys.file_exists package_path
+ then
+ let all_path_files =
+ List.map (fun file ->
+ match file with
+ | `D file ->
+ if Sys.file_exists (package_path//file)
+ then (package_path // file)
+ else
+ (prerr_endlinef "%s does not exist " (package_path//file);
+ raise Next)
+ | `P (package,file) ->
+ let sub_pack =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package)
+ with Failure _ -> begin
+ prerr_endlinef "%s does not exist in subpackage definition" package;
+ raise Next
+ end
+ in
+ if Sys.file_exists (sub_pack//file) then
+ (sub_pack // file)
+ else
+ (prerr_endlinef "%s does not exist " (sub_pack//file);
+ raise Next )
+
+ ) files
+ in begin
+ flag ["ocaml"; "pp"; "use_"^ package]
+ (S(List.map (fun file -> A file)
+ all_path_files));
+ end
+ else begin
+ prerr_endlinef "package %s does not exist" package;
+ end
+ )
+ with Next -> ()
+ )
+
+let apply plugin = begin
+ Default.before_options +> before_options;
+ Default.after_rules +> after_rules;
+
+ (fun _ -> begin
+ syntax_path syntax_lib_file;
+
+ (** demo how to use external libraries
+ ocaml_lib ~extern:true "llvm";
+ ocaml_lib ~extern:true "llvm_analysis";
+ ocaml_lib ~extern:true "llvm_bitwriter"; *)
+
+ dep ["link"; "ocaml"; "use_plus_stubs"] ["plus_stubs.o"];
+ flag["link"; "ocaml"; "byte"] (S[A"-custom"]);
+ (if compiler_lib_installed then begin
+ flag["ocaml"; "byte"; "compile"; "use_compiler_lib"]
+ (S[A"-I"; A"+../compiler-lib"]);
+ flag["ocaml"; "program"; "byte"; "use_compiler_lib"]
+ (S[A"toplevellib.cma"]);
+ end
+ else
+ prerr_endline "compiler_lib not installed"
+ );
+ flag["pp" ; "ocaml"; "use_macro"] (S[A"-parser"; A"macro"]);
+ flag["pp" ; "ocaml"; "use_map"] (S[A"-parser"; A"map"]);
+ flag["pp" ; "ocaml"; "use_lift"] (S[A"-parser"; A"lift"]);
+ flag["pp" ; "ocaml"; "use_fold"] (S[A"-parser"; A"fold"]);
+ flag ["link";"ocaml";"g++";] (S[A"-cc"; A"g++"]);
+ flag ["ocaml"; "doc"; "use_camlp4"] (S[A"-I"; A"+camlp4"]);
+
+ dep ["ocamldep"; "file:test_lift_filter_r.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter_r.pp.ml"] ["test_type_r.ml"];
+ seems does not work, but you can build cmo files first, then build
+ the output files
+ *)
+ dep ["ocamldep"; "file:test_lift_filter.ml"] ["test_type.ml"];
+ dep ["ocamldep"; "file:test_dump.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter.pp.ml"] ["test_type.ml"]; *)
+ (* demo how to use dep *)
+ (* dep ["ocamldep"; "file:test/test_string.ml"] *)
+ (* ["test/test_data/string.txt"; *)
+ (* "test/test_data/char.txt"]; *)
+ flag ["ocaml"; "pp"; "use_gen_printer"] (A"gen_printer.cma");
+ dep ["ocamldep"; "use_gen_printer"] ["gen_printer.cma"];
+ end) +> after_rules;
+ plugin ();
+ dispatch begin function
+ | Before_options -> begin
+ List.iter (fun f -> f () ) !before_options;
+ end
+ | After_rules -> begin
+ List.iter (fun f -> f ()) !after_rules;
+ end
+ | _ -> ()
+ end ;
+end
+
+
+let _ =
+ (** customize your plugin here *)
+ let plugin = (fun _ -> ()) in
+ apply plugin
+
+
+
+(**
+ customized local filter
+*)
+(* let _ = dispatch begin function *)
+(* |After_rules -> begin *)
+(* flag ["ocaml"; "pp"; "use_filter"] (A"pa_filter.cma"); *)
+(* dep ["ocaml"; "ocamldep"; "use_filter"] ["pa_filter.cma"]; *)
+(* end *)
+(* |_ -> () *)
+(* end *)
+(** (** for pa_ulex, you must create the symbol link by yourself*)
+ flag ["ocaml"; "pp"; "use_ulex"] (A"pa_ulex.cma"); (** for bolt
+ logger *) flag ["ocaml"; "pp"; "use_bolt"] (A"bolt_pp.cmo"); (**
+ for bitstring *) flag ["ocaml"; "pp"; "use_bitstring"]
+ (S[A"bitstring.cma"; A"bitstring_persistent.cma";
+ A"pa_bitstring.cmo"]); flag ["ocaml"; "pp"; "use_xstrp4"]
+ (S[A"xstrp4.cma"]); flag ["ocaml"; "pp"; "use_sexp"]
+ (S[A"Pa_type_conv.cma"; A"pa_sexp_conv.cma"]); flag ["ocaml";
+ "pp"; "use_mikmatch"] (S[A"pa_mikmatch_pcre.cma"]); flag ["ocaml";
+ "pp"; "use_meta"] (S[A"lift_filter.cma"]);
+*)
+(**
+let gen_interface ml mli env build = Ocaml_utils.(
+ let ml = env ml and mli = env mli in
+ let tags = tags_of_pathname ml++"ocaml" in
+ Ocaml_compiler.prepare_compile build ml;
+ Cmd(S[!Options.ocamlc; ocaml_ppflags tags; ocaml_include_flags ml;
+ A"-I";
+ A"+camlp4"; (** dirty hacks to include camlp4 path for .i.mli *)
+ A"-i";
+ (if Tags.mem "thread" tags then A"-thread" else N);
+ T(tags++"infer_interface"); P ml; Sh">"; Px mli]))
+(**
+ Usage ocamlbuild xx.i.mli
+ *)
+let _ = begin
+ rule "ocaml: ml & ml.depends & *cmi -> .i.mli"
+ ~prod:"%.i.mli"
+ ~deps:["%.ml"; "%.ml.depends"]
+ (gen_interface "%.ml" "%.i.mli")
+end
+*)
View
73 code/constraint/test.ml
@@ -0,0 +1,73 @@
+open Format
+open Facile
+open Easy
+
+(* Print a solution *)
+let print queens =
+ let n = Array.length queens in
+ if n <= 10 then (* Pretty printing *)
+ for i = 0 to n - 1 do
+ let c = Fd.int_value queens.(i) in (* queens.(i) is bound *)
+ for j = 0 to n - 1 do
+ Printf.printf "%c " (if j = c then '*' else '-')
+ done;
+ print_newline ()
+ done
+ else (* Short print *)
+ for i = 0 to n-1 do
+ Printf.printf "line %d : col %a\n" i Fd.fprint queens.(i)
+ done;
+flush stdout;;
+
+
+(* Solve the n-queens problem *)
+let queens n =
+ (* n decision variables in 0..n-1 *)
+ let queens = Fd.array n 0 (n-1) in
+
+ (* 2n auxiliary variables for diagonals *)
+ let shift op = Array.mapi (fun i qi -> Arith.e2fd (op (fd2e qi) (i2e i))) queens in
+ let diag1 = shift (+~) and diag2 = shift (-~) in
+
+ (* Global constraints *)
+ Cstr.post (Alldiff.cstr queens);
+ Cstr.post (Alldiff.cstr diag1);
+ Cstr.post (Alldiff.cstr diag2);
+
+ (* Heuristic Min Size, Min Value *)
+ let h a = (Var.Attr.size a, Var.Attr.min a) in
+ let min_min = Goals.Array.choose_index (fun a1 a2 -> h a1 < h a2) in
+
+ (* Search goal *)
+ let labeling = Goals.Array.forall ~select:min_min Goals.indomain in
+
+ (* Solve *)
+ let bt = ref 0 in
+ if Goals.solve ~control:(fun b -> bt := b) (labeling queens) then begin
+ Printf.printf "%d backtracks\n" !bt;
+ print queens
+ end else
+ prerr_endline "No solution"
+
+let _ =
+ if Array.length Sys.argv <> 2
+ then raise (Failure "Usage: queens <nb of queens>");
+ Gc.set ({(Gc.get ()) with Gc.space_overhead = 500}); (* May help except with an underRAMed system *)
+ queens (int_of_string Sys.argv.(1));;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
1  code/dynlink/_tags
@@ -0,0 +1 @@
+true : pkg_dynlink
View
27 code/dynlink/main.ml
@@ -0,0 +1,27 @@
+open Format
+(* Main program *)
+let filename = "some_module.cmo"
+let funcname = "say_hello"
+let () =
+ Dynlink.init ();
+ (try Dynlink.loadfile filename
+ with Dynlink.Error e -> failwith (Dynlink.error_message e));
+ (Hashtbl.find Reg.registry funcname) ()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
293 code/dynlink/myocamlbuild.ml
@@ -0,0 +1,293 @@
+open Ocamlbuild_plugin
+open Command
+open Printf
+open Ocamlbuild_pack
+(* #directory "+ocamlbuild";;
+ #load "ocamlbuildlib.cma";;
+ for interactive debugging
+ *)
+
+let (//) = Filename.concat
+let flip f x y = f y x
+let prerr_endlinef fmt = ksprintf prerr_endline fmt
+let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
+let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
+let find_packages () =
+ blank_sep_strings &
+ Lexing.from_string &
+ run_and_read "ocamlfind list | cut -d' ' -f1"
+let compiler_lib_installed =
+ try
+ Sys.(file_exists &
+ (Filename.dirname &
+ run_and_read "ocamlfind ocamlc -where | cut -d' ' -f1" ) // "compiler-lib")
+ with e -> false
+
+(** ocamlfind can only handle these two flags *)
+let find_syntaxes () = ["camlp4o"; "camlp4r"]
+let trim_endline str =
+ let len = String.length (str) in
+ if len = 0 then str
+ else if str.[len-1] = '\n'
+ then String.sub str 0 (len-1)
+ else str
+(** list extensions, but not used here *)
+let extensions () =
+ let pas = List.filter
+ (fun x ->
+ String.contains_string x 0 "pa_" <> None) (find_packages ()) in
+ let tbl = List.map
+ (fun pkg ->
+ let dir =
+ trim_endline (run_and_read ("ocamlfind query " ^ pkg))in
+ (pkg, dir)) pas in
+ tbl
+
+let debug = ref false
+let site_lib () =
+ trim_endline (run_and_read ("ocamlfind printconf destdir"))
+
+let _ =
+ if !debug then begin
+ List.iter (fun (pkg,dir) -> Printf.printf "%s,%s\n" pkg dir)
+ (extensions ());
+ Printf.printf "%s\n" (site_lib())
+ end
+
+
+
+(* Menhir options *)
+let menhir_opts = S
+ [A"--dump";A"--explain"; A"--infer";]
+
+let ocamlfind x = S[A"ocamlfind"; x]
+module Default = struct
+ let before_options () =
+ Options.ocamlc := ocamlfind & S[A"ocamlc"; A"-annot"];
+ Options.ocamlopt := ocamlfind & S[A"ocamlopt";A"-annot"];
+ Options.ocamldep := ocamlfind & A"ocamldep";
+ Options.ocamldoc := ocamlfind & A"ocamldoc";
+ Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+ let after_rules () =
+ (*when one link an ocaml library/binary/package, should use -linkpkg*)
+ flag ["ocaml"; "byte"; "link";"program"] & A"-linkpkg";
+ flag ["ocaml"; "native"; "link";"program"] & A"-linkpkg";
+ List.iter begin fun pkg ->
+ flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["menhir"] menhir_opts; (* add support for menhir*)
+ end (find_packages ());
+ (* Like -package but for extensions syntax. Morover -syntax is
+ * useless when linking. *)
+ List.iter begin fun syntax ->
+ flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ end (find_syntaxes ());
+ (* The default "thread" tag is not compatible with ocamlfind.
+ Indeed, the default rules add the "threads.cma" or
+ "threads.cmxa" options when using this tag. When using the
+ "-linkpkg" option with ocamlfind, this module will then be
+ added twice on the command line.
+ To solve this, one approach is to add the "-thread" option when using
+ the "threads" package using the previous plugin.
+ *)
+ flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+end
+
+
+type actions = (unit -> unit) list ref
+
+let before_options : actions = ref []
+and after_options : actions = ref []
+and before_rules : actions = ref []
+and after_rules : actions = ref []
+
+let (+>) x l =
+ l := x :: !l
+
+
+
+(**
+ configuration syntax extensions
+ the key is used by ocamlfind query to get its path
+*)
+let syntax_lib_file
+ = ["bitstring",[`D "bitstring.cma" ;
+ `D "bitstring_persistent.cma";
+ `D "pa_bitstring.cmo"]
+ ;"ulex", [`D "pa_ulex.cma"]
+ ;"bolt", [`D "bolt_pp.cmo"]
+ ;"xstrp4", [`D "xstrp4.cma"]
+ ;"sexplib", [`P ("type-conv", "Pa_type_conv.cma"); `D "pa_sexp_conv.cma"]
+ ;"mikmatch_pcre", [`D "pa_mikmatch_pcre.cma"]
+ ;"meta_filter", [`D "meta_filter.cma"]
+ ;"text", [`D "text.cma"; `D "text-pcre-syntax.cma"]
+ ;"type_conv", [`D "pa_type_conv.cma"]
+ ]
+
+
+exception Next
+
+let syntax_path syntax_lib_file =
+ flip List.iter syntax_lib_file (fun (package, files) ->
+ try
+ (let package_path =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package )
+ with Failure _ ->
+ prerr_endlinef "package %s does not exist" package;
+ raise Next
+ in
+ if Sys.file_exists package_path
+ then
+ let all_path_files =
+ List.map (fun file ->
+ match file with
+ | `D file ->
+ if Sys.file_exists (package_path//file)
+ then (package_path // file)
+ else
+ (prerr_endlinef "%s does not exist " (package_path//file);
+ raise Next)
+ | `P (package,file) ->
+ let sub_pack =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package)
+ with Failure _ -> begin
+ prerr_endlinef "%s does not exist in subpackage definition" package;
+ raise Next
+ end
+ in
+ if Sys.file_exists (sub_pack//file) then
+ (sub_pack // file)
+ else
+ (prerr_endlinef "%s does not exist " (sub_pack//file);
+ raise Next )
+
+ ) files
+ in begin
+ flag ["ocaml"; "pp"; "use_"^ package]
+ (S(List.map (fun file -> A file)
+ all_path_files));
+ end
+ else begin
+ prerr_endlinef "package %s does not exist" package;
+ end
+ )
+ with Next -> ()
+ )
+
+let apply plugin = begin
+ Default.before_options +> before_options;
+ Default.after_rules +> after_rules;
+
+ (fun _ -> begin
+ syntax_path syntax_lib_file;
+
+ (** demo how to use external libraries
+ ocaml_lib ~extern:true "llvm";
+ ocaml_lib ~extern:true "llvm_analysis";
+ ocaml_lib ~extern:true "llvm_bitwriter"; *)
+
+ dep ["link"; "ocaml"; "use_plus_stubs"] ["plus_stubs.o"];
+ flag["link"; "ocaml"; "byte"] (S[A"-custom"]);
+ (if compiler_lib_installed then begin
+ flag["ocaml"; "byte"; "compile"; "use_compiler_lib"]
+ (S[A"-I"; A"+../compiler-lib"]);
+ flag["ocaml"; "program"; "byte"; "use_compiler_lib"]
+ (S[A"toplevellib.cma"]);
+ end
+ else
+ prerr_endline "compiler_lib not installed"
+ );
+ flag["pp" ; "ocaml"; "use_macro"] (S[A"-parser"; A"macro"]);
+ flag["pp" ; "ocaml"; "use_map"] (S[A"-parser"; A"map"]);
+ flag["pp" ; "ocaml"; "use_lift"] (S[A"-parser"; A"lift"]);
+ flag["pp" ; "ocaml"; "use_fold"] (S[A"-parser"; A"fold"]);
+ flag ["link";"ocaml";"g++";] (S[A"-cc"; A"g++"]);
+ flag ["ocaml"; "doc"; "use_camlp4"] (S[A"-I"; A"+camlp4"]);
+
+ dep ["ocamldep"; "file:test_lift_filter_r.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter_r.pp.ml"] ["test_type_r.ml"];
+ seems does not work, but you can build cmo files first, then build
+ the output files
+ *)
+ dep ["ocamldep"; "file:test_lift_filter.ml"] ["test_type.ml"];
+ dep ["ocamldep"; "file:test_dump.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter.pp.ml"] ["test_type.ml"]; *)
+ (* demo how to use dep *)
+ (* dep ["ocamldep"; "file:test/test_string.ml"] *)
+ (* ["test/test_data/string.txt"; *)
+ (* "test/test_data/char.txt"]; *)
+ flag ["ocaml"; "pp"; "use_gen_printer"] (A"gen_printer.cma");
+ dep ["ocamldep"; "use_gen_printer"] ["gen_printer.cma"];
+ end) +> after_rules;
+ plugin ();
+ dispatch begin function
+ | Before_options -> begin
+ List.iter (fun f -> f () ) !before_options;
+ end
+ | After_rules -> begin
+ List.iter (fun f -> f ()) !after_rules;
+ end
+ | _ -> ()
+ end ;
+end
+
+
+let _ =
+ (** customize your plugin here *)
+ let plugin = (fun _ -> ()) in
+ apply plugin
+
+
+
+(**
+ customized local filter
+*)
+(* let _ = dispatch begin function *)
+(* |After_rules -> begin *)
+(* flag ["ocaml"; "pp"; "use_filter"] (A"pa_filter.cma"); *)
+(* dep ["ocaml"; "ocamldep"; "use_filter"] ["pa_filter.cma"]; *)
+(* end *)
+(* |_ -> () *)
+(* end *)
+(** (** for pa_ulex, you must create the symbol link by yourself*)
+ flag ["ocaml"; "pp"; "use_ulex"] (A"pa_ulex.cma"); (** for bolt
+ logger *) flag ["ocaml"; "pp"; "use_bolt"] (A"bolt_pp.cmo"); (**
+ for bitstring *) flag ["ocaml"; "pp"; "use_bitstring"]
+ (S[A"bitstring.cma"; A"bitstring_persistent.cma";
+ A"pa_bitstring.cmo"]); flag ["ocaml"; "pp"; "use_xstrp4"]
+ (S[A"xstrp4.cma"]); flag ["ocaml"; "pp"; "use_sexp"]
+ (S[A"Pa_type_conv.cma"; A"pa_sexp_conv.cma"]); flag ["ocaml";
+ "pp"; "use_mikmatch"] (S[A"pa_mikmatch_pcre.cma"]); flag ["ocaml";
+ "pp"; "use_meta"] (S[A"lift_filter.cma"]);
+*)
+(**
+let gen_interface ml mli env build = Ocaml_utils.(
+ let ml = env ml and mli = env mli in
+ let tags = tags_of_pathname ml++"ocaml" in
+ Ocaml_compiler.prepare_compile build ml;
+ Cmd(S[!Options.ocamlc; ocaml_ppflags tags; ocaml_include_flags ml;
+ A"-I";
+ A"+camlp4"; (** dirty hacks to include camlp4 path for .i.mli *)
+ A"-i";
+ (if Tags.mem "thread" tags then A"-thread" else N);
+ T(tags++"infer_interface"); P ml; Sh">"; Px mli]))
+(**
+ Usage ocamlbuild xx.i.mli
+ *)
+let _ = begin
+ rule "ocaml: ml & ml.depends & *cmi -> .i.mli"
+ ~prod:"%.i.mli"
+ ~deps:["%.ml"; "%.ml.depends"]
+ (gen_interface "%.ml" "%.i.mli")
+end
+*)
View
21 code/dynlink/reg.ml
@@ -0,0 +1,21 @@
+open Format
+
+
+let (registry : (string, unit -> unit) Hashtbl.t) = Hashtbl.create 32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
23 code/dynlink/some_module.ml
@@ -0,0 +1,23 @@
+open Format
+
+(* SomeModule.ml *)
+let say_hello () = print_endline "Hello, world!"
+let () = Hashtbl.replace Reg.registry "say_hello" say_hello
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
1  code/js/_tags
@@ -0,0 +1 @@
+true: pkg_js_of_ocaml
View
183 code/js/test.js
@@ -0,0 +1,183 @@
+// This program was compiled from OCaml by js_of_ocaml 1.0
+function caml_raise_with_arg (tag, arg) { throw [0, tag, arg]; }
+function caml_raise_with_string (tag, msg) {
+ caml_raise_with_arg (tag, new MlWrappedString (msg));
+}
+function caml_invalid_argument (msg) {
+ caml_raise_with_string(caml_global_data[4], msg);
+}
+function caml_array_bound_error () {
+ caml_invalid_argument("index out of bounds");
+}
+function caml_str_repeat(n, s) {
+ if (!n) { return ""; }
+ if (n & 1) { return caml_str_repeat(n - 1, s) + s; }
+ var r = caml_str_repeat(n >> 1, s);
+ return r + r;
+}
+function MlString(param) {
+ if (param != null) {
+ this.bytes = this.fullBytes = param;
+ this.last = this.len = param.length;
+ }
+}
+MlString.prototype = {
+ string:null,
+ bytes:null,
+ fullBytes:null,
+ array:null,
+ len:null,
+ last:0,
+ toJsString:function() {
+ return this.string = decodeURIComponent (escape(this.getFullBytes()));
+ },
+ toBytes:function() {
+ if (this.string != null)
+ var b = unescape (encodeURIComponent (this.string));
+ else {
+ var b = "", a = this.array, l = a.length;
+ for (var i = 0; i < l; i ++) b += String.fromCharCode (a[i]);
+ }
+ this.bytes = this.fullBytes = b;
+ this.last = this.len = b.length;
+ return b;
+ },
+ getBytes:function() {
+ var b = this.bytes;
+ if (b == null) b = this.toBytes();
+ return b;
+ },
+ getFullBytes:function() {
+ var b = this.fullBytes;
+ if (b !== null) return b;
+ b = this.bytes;
+ if (b == null) b = this.toBytes ();
+ if (this.last < this.len) {
+ this.bytes = (b += caml_str_repeat(this.len - this.last, '\0'));
+ this.last = this.len;
+ }
+ this.fullBytes = b;
+ return b;
+ },
+ toArray:function() {
+ var b = this.bytes;
+ if (b == null) b = this.toBytes ();
+ var a = [], l = this.last;
+ for (var i = 0; i < l; i++) a[i] = b.charCodeAt(i);
+ for (l = this.len; i < l; i++) a[i] = 0;
+ this.string = this.bytes = this.fullBytes = null;
+ this.last = this.len;
+ this.array = a;
+ return a;
+ },
+ getArray:function() {
+ var a = this.array;
+ if (!a) a = this.toArray();
+ return a;
+ },
+ getLen:function() {
+ var len = this.len;
+ if (len !== null) return len;
+ this.toBytes();
+ return this.len;
+ },
+ toString:function() { var s = this.string; return s?s:this.toJsString(); },
+ valueOf:function() { var s = this.string; return s?s:this.toJsString(); },
+ blitToArray:function(i1, a2, i2, l) {
+ var a1 = this.array;
+ if (a1)
+ for (var i = 0; i < l; i++) a2 [i2 + i] = a1 [i1 + i];
+ else {
+ var b = this.bytes;
+ if (b == null) b = this.toBytes();
+ var l1 = this.last - i1;
+ if (l <= l1)
+ for (var i = 0; i < l; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
+ else {
+ for (var i = 0; i < l1; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
+ for (; i < l; i++) a2 [i2 + i] = 0;
+ }
+ }
+ },
+ get:function (i) {
+ var a = this.array;
+ if (a) return a[i];
+ var b = this.bytes;
+ if (b == null) b = this.toBytes();
+ return (i<this.last)?b.charCodeAt(i):0;
+ },
+ safeGet:function (i) {
+ if (!this.len) this.toBytes();
+ if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
+ return this.get(i);
+ },
+ set:function (i, c) {
+ var a = this.array;
+ if (!a) {
+ if (this.last == i) {
+ this.bytes += String.fromCharCode (c & 0xff);
+ this.last ++;
+ return 0;
+ }
+ a = this.toArray();
+ } else if (this.bytes != null) {
+ this.bytes = this.fullBytes = this.string = null;
+ }
+ a[i] = c & 0xff;
+ return 0;
+ },
+ safeSet:function (i, c) {
+ if (this.len == null) this.toBytes ();
+ if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
+ this.set(i, c);
+ },
+ fill:function (ofs, len, c) {
+ if (ofs >= this.last && this.last && c == 0) return;
+ var a = this.array;
+ if (!a) a = this.toArray();
+ else if (this.bytes != null) {
+ this.bytes = this.fullBytes = this.string = null;
+ }
+ var l = ofs + len;
+ for (var i = ofs; i < l; i++) a[i] = c;
+ },
+ compare:function (s2) {
+ if (this.string != null && s2.string != null) {
+ if (this.string < s2.string) return -1;
+ if (this.string > s2.string) return 1;
+ return 0;
+ }
+ var b1 = this.getFullBytes ();
+ var b2 = s2.getFullBytes ();
+ if (b1 < b2) return -1;
+ if (b1 > b2) return 1;
+ return 0;
+ },
+ equal:function (s2) {
+ if (this.string != null && s2.string != null)
+ return this.string == s2.string;
+ return this.getFullBytes () == s2.getFullBytes ();
+ },
+ lessThan:function (s2) {
+ if (this.string != null && s2.string != null)
+ return this.string < s2.string;
+ return this.getFullBytes () < s2.getFullBytes ();
+ },
+ lessEqual:function (s2) {
+ if (this.string != null && s2.string != null)
+ return this.string <= s2.string;
+ return this.getFullBytes () <= s2.getFullBytes ();
+ }
+}
+function MlWrappedString (s) { this.string = s; }
+MlWrappedString.prototype = new MlString();
+function MlMakeString (l) { this.bytes = ""; this.len = l; }
+MlMakeString.prototype = new MlString ();
+function caml_ml_out_channels_list () { return 0; }
+var caml_global_data = [0];
+function caml_register_global (n, v) { caml_global_data[n + 1] = v; }
+var caml_named_values = {};
+function caml_register_named_value(nm,v) {
+ caml_named_values[nm] = v; return 0;
+}
+(function(){caml_register_global(5,[0,new MlString("Division_by_zero")]);caml_register_global(3,[0,new MlString("Invalid_argument")]);caml_register_global(2,[0,new MlString("Failure")]);var f=new MlString("Pervasives.do_at_exit");function e(d){var a=caml_ml_out_channels_list(0);for(;;){if(a){var b=a[2];try {}catch(c){}var a=b;continue;}return 0;}}caml_register_named_value(f,e);e(0);return;}());
View
23 code/js/test.ml
@@ -0,0 +1,23 @@
+open Format
+(* let _ = print_endline "hello, js" *)
+let b = 3
+let a = b + 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
70 code/net/My photo
@@ -0,0 +1,70 @@
+open Netmime
+open Netchannels
+let date =
+ Netdate.mk_mail_date ~zone:Netdate.localzone (Unix.time())
+
+let mail_header =
+ new basic_mime_header [ "MIME-version", "1.0";
+ "Subject", "Sample mail";
+ "From", "bobzhang1988@gmail.com";
+ "To", "hongboz@seas.upenn.edu";
+ "Date", date;
+ "Content-type", "multipart/mixed" ]
+let main_text_header =
+ new basic_mime_header [ "Content-type", "text/plain;charset=ISO-8859-1";
+ "Content-transfer-encoding", "quoted-printable";
+ ]
+let main_text_body =
+ new memory_mime_body "Hello world!\nThis is a sample mail.\n"
+let att_header =
+ new basic_mime_header [ "Content-type", "image/jpeg";
+ "Content-transfer-encoding", "base64";
+ "Content-disposition", "inline;description=\"My photo\"";
+ ]
+let att_body =
+ new file_mime_body "test_netmime.ml"
+let tree =
+ (mail_header, `Parts [ (main_text_header, `Body main_text_body);
+ (att_header, `Body att_body) ] )
+
+let n = ref 0
+let ext_storage_style (header:mime_header) =
+ let body = new file_mime_body ("attachments") in
+ let filename =
+ try
+ let disp, disp_params = header#content_disposition () in
+ let s = Mimestring.param_value (List.assoc "description" disp_params) in
+ let () = print_string s in
+ s
+ with Not_found -> ("file" ^ string_of_int !n) in
+ let () = incr n in
+ (body, new Netchannels.output_channel (open_out filename))
+
+let () =
+ let (chan:io_obj_channel) = new pipe () in begin
+ with_out_obj_channel (chan:>out_obj_channel)
+ (fun chan -> write_mime_message chan tree) ;
+ with_in_obj_channel chan (fun chan ->
+ let nstr = new Netstream.input_stream (chan:>in_obj_channel) in
+ let tree = read_mime_message ~storage_style:ext_storage_style nstr in
+ write_mime_message ~wr_body:false (new output_channel stdout) tree);
+ Netsendmail.sendmail ~mailer:"/usr/sbin/sendmail" tree
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
1  code/net/_tags
@@ -0,0 +1 @@
+true : pkg_netstring
View
38 code/net/dns.ml
@@ -0,0 +1,38 @@
+open Format
+open Unix
+
+(** dns
+ gethostbyname : string -> Unix.host_entry
+ *)
+let look name =
+ try
+ let addr = gethostbyname name in
+ addr.h_addr_list |> Array.iter
+ (fun addr ->
+ addr
+ |> string_of_inet_addr
+ |> print_endline)
+ with
+ Not_found -> printf "can not resolve %s\n" name
+
+
+(**
+ gethostbyname
+ gethostbyaddr
+ inet_addr_of_string
+ *)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
2  code/net/file0
@@ -0,0 +1,2 @@
+Hello world!
+This is a sample mail.
View
2  code/net/file1
@@ -0,0 +1,2 @@
+Hello world!
+This is a sample mail.
View
92 code/net/file2
@@ -0,0 +1,92 @@
+open Format
+
+
+let date =
+ Netdate.mk_mail_date ~zone:Netdate.localzone (Unix.time())
+open Netmime
+
+let mail_header =
+ new basic_mime_header [ "MIME-version", "1.0";
+ "Subject", "Sample mail";
+ "To", "hongboz@seas.upenn.edu";
+ "From", "bobzhang1988@gmail.com";
+ "Date", date;
+ "Content-type", "multipart/mixed" ]
+
+let main_text_header =
+ new basic_mime_header [ "Content-type", "text/plain;charset=ISO-8859-1";
+ "Content-transfer-encoding", "quoted-printable";
+ ]
+
+let main_text_body =
+ new memory_mime_body "Hello world!\nThis is a sample mail.\n"
+
+let att_header =
+ new basic_mime_header [ "Content-type", "image/jpeg";
+ "Content-transfer-encoding", "base64";
+ "Content-disposition", "inline;description=\"My photo\"";
+ ]
+let att_body =
+ new file_mime_body "test_netmime.ml"
+
+let tree =
+ (mail_header, `Parts [ (main_text_header, `Body main_text_body);
+ (att_header, `Body att_body) ] )
+
+(** write_mime_message
+ do pretty printing
+ Before invoking this function, ensure the following:
+ - The [Content-type] field of all leaves should be set
+ - The [Content-transfer-encoding] field of all leaves should be set
+ (in doubt use "base64"; if missing, the default is "7bit" -
+ probably not what you want)
+ - The [Content-type] field of multipart nodes should be set (it
+ defaults to "multipart/mixed" if missing)
+ - The [Content-transfer-encoding] fields of multipart nodes should
+ {b not} be set - this is done by the function
+ If the [boundary] parameter is missing, the function will invent one;
+ you don't need to deal with this.
+ *)
+
+
+let test =
+ let buf = Buffer.create 200 in
+ let () = write_mime_message (new Netchannels.output_buffer buf) tree in
+ Buffer.contents buf
+
+let ch = new Netchannels.input_string test
+let nstr = new Netstream.input_stream ch
+let n = ref 1
+
+let ext_storage_style (header:mime_header) =
+ let body = new file_mime_body ("file" ^ string_of_int !n) in
+ let filename =
+ try
+ let disp, disp_params = header#content_disposition () in
+ let s = Mimestring.param_value (List.assoc "filename" disp_params) in
+ let () = print_string s in
+ s
+ with Not_found -> ("file" ^ string_of_int !n) in
+ let () = incr n in
+ (body, new Netchannels.output_channel (open_out filename))
+
+(** while parsing storing *)
+let tree = read_mime_message ~storage_style:ext_storage_style nstr
+let () = nstr#close_in () (* implicityly close ch*)
+let () =
+ write_mime_message (new Netchannels.output_channel stdout) tree;;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
32 code/net/killall_screen.ml
@@ -0,0 +1,32 @@
+
+open Format
+open Unix
+
+(* let () = *)
+(* with_in_obj_channel (new input_command "screen -h") (fun ch -> *)
+(* try *)
+(* while true do *)
+(* let device = ch#input_line () in *)
+(* prerr_endline device; *)
+(* done *)
+(* with End_of_file -> prerr_endline "Finished") *)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
293 code/net/myocamlbuild.ml
@@ -0,0 +1,293 @@
+open Ocamlbuild_plugin
+open Command
+open Printf
+open Ocamlbuild_pack
+(* #directory "+ocamlbuild";;
+ #load "ocamlbuildlib.cma";;
+ for interactive debugging
+ *)
+
+let (//) = Filename.concat
+let flip f x y = f y x
+let prerr_endlinef fmt = ksprintf prerr_endline fmt
+let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
+let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
+let find_packages () =
+ blank_sep_strings &
+ Lexing.from_string &
+ run_and_read "ocamlfind list | cut -d' ' -f1"
+let compiler_lib_installed =
+ try
+ Sys.(file_exists &
+ (Filename.dirname &
+ run_and_read "ocamlfind ocamlc -where | cut -d' ' -f1" ) // "compiler-lib")
+ with e -> false
+
+(** ocamlfind can only handle these two flags *)
+let find_syntaxes () = ["camlp4o"; "camlp4r"]
+let trim_endline str =
+ let len = String.length (str) in
+ if len = 0 then str
+ else if str.[len-1] = '\n'
+ then String.sub str 0 (len-1)
+ else str
+(** list extensions, but not used here *)
+let extensions () =
+ let pas = List.filter
+ (fun x ->
+ String.contains_string x 0 "pa_" <> None) (find_packages ()) in
+ let tbl = List.map
+ (fun pkg ->
+ let dir =
+ trim_endline (run_and_read ("ocamlfind query " ^ pkg))in
+ (pkg, dir)) pas in
+ tbl
+
+let debug = ref false
+let site_lib () =
+ trim_endline (run_and_read ("ocamlfind printconf destdir"))
+
+let _ =
+ if !debug then begin
+ List.iter (fun (pkg,dir) -> Printf.printf "%s,%s\n" pkg dir)
+ (extensions ());
+ Printf.printf "%s\n" (site_lib())
+ end
+
+
+
+(* Menhir options *)
+let menhir_opts = S
+ [A"--dump";A"--explain"; A"--infer";]
+
+let ocamlfind x = S[A"ocamlfind"; x]
+module Default = struct
+ let before_options () =
+ Options.ocamlc := ocamlfind & S[A"ocamlc"; A"-annot"];
+ Options.ocamlopt := ocamlfind & S[A"ocamlopt";A"-annot"];
+ Options.ocamldep := ocamlfind & A"ocamldep";
+ Options.ocamldoc := ocamlfind & A"ocamldoc";
+ Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+ let after_rules () =
+ (*when one link an ocaml library/binary/package, should use -linkpkg*)
+ flag ["ocaml"; "byte"; "link";"program"] & A"-linkpkg";
+ flag ["ocaml"; "native"; "link";"program"] & A"-linkpkg";
+ List.iter begin fun pkg ->
+ flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["menhir"] menhir_opts; (* add support for menhir*)
+ end (find_packages ());
+ (* Like -package but for extensions syntax. Morover -syntax is
+ * useless when linking. *)
+ List.iter begin fun syntax ->
+ flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ end (find_syntaxes ());
+ (* The default "thread" tag is not compatible with ocamlfind.
+ Indeed, the default rules add the "threads.cma" or
+ "threads.cmxa" options when using this tag. When using the
+ "-linkpkg" option with ocamlfind, this module will then be
+ added twice on the command line.
+ To solve this, one approach is to add the "-thread" option when using
+ the "threads" package using the previous plugin.
+ *)
+ flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+end
+
+
+type actions = (unit -> unit) list ref
+
+let before_options : actions = ref []
+and after_options : actions = ref []
+and before_rules : actions = ref []
+and after_rules : actions = ref []
+
+let (+>) x l =
+ l := x :: !l
+
+
+
+(**
+ configuration syntax extensions
+ the key is used by ocamlfind query to get its path
+*)
+let syntax_lib_file
+ = ["bitstring",[`D "bitstring.cma" ;
+ `D "bitstring_persistent.cma";
+ `D "pa_bitstring.cmo"]
+ ;"ulex", [`D "pa_ulex.cma"]
+ ;"bolt", [`D "bolt_pp.cmo"]
+ ;"xstrp4", [`D "xstrp4.cma"]
+ ;"sexplib", [`P ("type-conv", "Pa_type_conv.cma"); `D "pa_sexp_conv.cma"]
+ ;"mikmatch_pcre", [`D "pa_mikmatch_pcre.cma"]
+ ;"meta_filter", [`D "meta_filter.cma"]
+ ;"text", [`D "text.cma"; `D "text-pcre-syntax.cma"]
+ ;"type_conv", [`D "pa_type_conv.cma"]
+ ]
+
+
+exception Next
+
+let syntax_path syntax_lib_file =
+ flip List.iter syntax_lib_file (fun (package, files) ->
+ try
+ (let package_path =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package )
+ with Failure _ ->
+ prerr_endlinef "package %s does not exist" package;
+ raise Next
+ in
+ if Sys.file_exists package_path
+ then
+ let all_path_files =
+ List.map (fun file ->
+ match file with
+ | `D file ->
+ if Sys.file_exists (package_path//file)
+ then (package_path // file)
+ else
+ (prerr_endlinef "%s does not exist " (package_path//file);
+ raise Next)
+ | `P (package,file) ->
+ let sub_pack =
+ try
+ trim_endline & run_and_read ("ocamlfind query " ^ package)
+ with Failure _ -> begin
+ prerr_endlinef "%s does not exist in subpackage definition" package;
+ raise Next
+ end
+ in
+ if Sys.file_exists (sub_pack//file) then
+ (sub_pack // file)
+ else
+ (prerr_endlinef "%s does not exist " (sub_pack//file);
+ raise Next )
+
+ ) files
+ in begin
+ flag ["ocaml"; "pp"; "use_"^ package]
+ (S(List.map (fun file -> A file)
+ all_path_files));
+ end
+ else begin
+ prerr_endlinef "package %s does not exist" package;
+ end
+ )
+ with Next -> ()
+ )
+
+let apply plugin = begin
+ Default.before_options +> before_options;
+ Default.after_rules +> after_rules;
+
+ (fun _ -> begin
+ syntax_path syntax_lib_file;
+
+ (** demo how to use external libraries
+ ocaml_lib ~extern:true "llvm";
+ ocaml_lib ~extern:true "llvm_analysis";
+ ocaml_lib ~extern:true "llvm_bitwriter"; *)
+
+ dep ["link"; "ocaml"; "use_plus_stubs"] ["plus_stubs.o"];
+ flag["link"; "ocaml"; "byte"] (S[A"-custom"]);
+ (if compiler_lib_installed then begin
+ flag["ocaml"; "byte"; "compile"; "use_compiler_lib"]
+ (S[A"-I"; A"+../compiler-lib"]);
+ flag["ocaml"; "program"; "byte"; "use_compiler_lib"]
+ (S[A"toplevellib.cma"]);
+ end
+ else
+ prerr_endline "compiler_lib not installed"
+ );
+ flag["pp" ; "ocaml"; "use_macro"] (S[A"-parser"; A"macro"]);
+ flag["pp" ; "ocaml"; "use_map"] (S[A"-parser"; A"map"]);
+ flag["pp" ; "ocaml"; "use_lift"] (S[A"-parser"; A"lift"]);
+ flag["pp" ; "ocaml"; "use_fold"] (S[A"-parser"; A"fold"]);
+ flag ["link";"ocaml";"g++";] (S[A"-cc"; A"g++"]);
+ flag ["ocaml"; "doc"; "use_camlp4"] (S[A"-I"; A"+camlp4"]);
+
+ dep ["ocamldep"; "file:test_lift_filter_r.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter_r.pp.ml"] ["test_type_r.ml"];
+ seems does not work, but you can build cmo files first, then build
+ the output files
+ *)
+ dep ["ocamldep"; "file:test_lift_filter.ml"] ["test_type.ml"];
+ dep ["ocamldep"; "file:test_dump.ml"] ["test_type_r.ml"];
+ (* dep ["ocamldep"; "file:test_lift_filter.pp.ml"] ["test_type.ml"]; *)
+ (* demo how to use dep *)
+ (* dep ["ocamldep"; "file:test/test_string.ml"] *)
+ (* ["test/test_data/string.txt"; *)
+ (* "test/test_data/char.txt"]; *)
+ flag ["ocaml"; "pp"; "use_gen_printer"] (A"gen_printer.cma");
+ dep ["ocamldep"; "use_gen_printer"] ["gen_printer.cma"];
+ end) +> after_rules;
+ plugin ();
+ dispatch begin function
+ | Before_options -> begin
+ List.iter (fun f -> f () ) !before_options;
+ end
+ | After_rules -> begin
+ List.iter (fun f -> f ()) !after_rules;
+ end
+ | _ -> ()
+ end ;
+end
+
+
+let _ =
+ (** customize your plugin here *)
+ let plugin = (fun _ -> ()) in
+ apply plugin
+
+
+
+(**
+ customized local filter
+*)
+(* let _ = dispatch begin function *)
+(* |After_rules -> begin *)
+(* flag ["ocaml"; "pp"; "use_filter"] (A"pa_filter.cma"); *)
+(* dep ["ocaml"; "ocamldep"; "use_filter"] ["pa_filter.cma"]; *)
+(* end *)
+(* |_ -> () *)
+(* end *)
+(** (** for pa_ulex, you must create the symbol link by yourself*)
+ flag ["ocaml"; "pp"; "use_ulex"] (A"pa_ulex.cma"); (** for bolt
+ logger *) flag ["ocaml"; "pp"; "use_bolt"] (A"bolt_pp.cmo"); (**
+ for bitstring *) flag ["ocaml"; "pp"; "use_bitstring"]
+ (S[A"bitstring.cma"; A"bitstring_persistent.cma";
+ A"pa_bitstring.cmo"]); flag ["ocaml"; "pp"; "use_xstrp4"]
+ (S[A"xstrp4.cma"]); flag ["ocaml"; "pp"; "use_sexp"]
+ (S[A"Pa_type_conv.cma"; A"pa_sexp_conv.cma"]); flag ["ocaml";
+ "pp"; "use_mikmatch"] (S[A"pa_mikmatch_pcre.cma"]); flag ["ocaml";
+ "pp"; "use_meta"] (S[A"lift_filter.cma"]);
+*)
+(**
+let gen_interface ml mli env build = Ocaml_utils.(
+ let ml = env ml and mli = env mli in
+ let tags = tags_of_pathname ml++"ocaml" in
+ Ocaml_compiler.prepare_compile build ml;
+ Cmd(S[!Options.ocamlc; ocaml_ppflags tags; ocaml_include_flags ml;
+ A"-I";
+ A"+camlp4"; (** dirty hacks to include camlp4 path for .i.mli *)
+ A"-i";
+ (if Tags.mem "thread" tags then A"-thread" else N);
+ T(tags++"infer_interface"); P ml; Sh">"; Px mli]))
+(**
+ Usage ocamlbuild xx.i.mli
+ *)
+let _ = begin
+ rule "ocaml: ml & ml.depends & *cmi -> .i.mli"
+ ~prod:"%.i.mli"
+ ~deps:["%.ml"; "%.ml.depends"]
+ (gen_interface "%.ml" "%.i.mli")
+end
+*)
View
39 code/net/test_ftp.ml
@@ -0,0 +1,39 @@
+open Format
+
+#require "netclient";;
+
+open Ftp_client
+
+
+let buffer = Buffer.create 1000
+let ch = new Netchannels.output_buffer buffer
+let client = new ftp_client ()
+
+let () = begin
+ client#exec (connect_method ~host:"127.0.0.1" ());
+ client#exec (login_method ~user:"foo"
+ ~get_password:(fun () -> "password")
+ ~get_account:(fun () -> "foo") ());
+ client#exec (get_method
+ ~file:(`NVFS "/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/build/distfiles/ocaml-3.12.1/bytecomp/lambda.ml") ~representation:`Image
+ ~store:(fun _ -> `File_structure ch)
+ ())
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
70 code/net/test_netmime.ml
@@ -0,0 +1,70 @@
+open Netmime
+open Netchannels
+let date =
+ Netdate.mk_mail_date ~zone:Netdate.localzone (Unix.time())
+
+let mail_header =
+ new basic_mime_header [ "MIME-version", "1.0";
+ "Subject", "Sample mail";
+ "From", "bobzhang1988@gmail.com";
+ "To", "hongboz@seas.upenn.edu";
+ "Date", date;
+ "Content-type", "multipart/mixed" ]
+let main_text_header =
+ new basic_mime_header [ "Content-type", "text/plain;charset=ISO-8859-1";
+ "Content-transfer-encoding", "quoted-printable";
+ ]
+let main_text_body =
+ new memory_mime_body "Hello world!\nThis is a sample mail.\n"
+let att_header =
+ new basic_mime_header [ "Content-type", "image/jpeg";
+ "Content-transfer-encoding", "base64";
+ "Content-disposition", "inline;description=\"My photo\"";
+ ]
+let att_body =
+ new file_mime_body "test_netmime.ml"
+let tree =
+ (mail_header, `Parts [ (main_text_header, `Body main_text_body);
+ (att_header, `Body att_body) ] )
+
+let n = ref 0
+let ext_storage_style (header:mime_header) =
+ let body = new file_mime_body ("attachments") in
+ let filename =
+ try
+ let disp, disp_params = header#content_disposition () in
+ let s = Mimestring.param_value (List.assoc "description" disp_params) in
+ let () = print_string s in
+ s
+ with Not_found -> ("file" ^ string_of_int !n) in
+ let () = incr n in
+ (body, new Netchannels.output_channel (open_out filename))
+
+let () =
+ let (chan:io_obj_channel) = new pipe () in begin
+ with_out_obj_channel (chan:>out_obj_channel)
+ (fun chan -> write_mime_message chan tree) ;
+ with_in_obj_channel chan (fun chan ->
+ let nstr = new Netstream.input_stream (chan:>in_obj_channel) in
+ let tree = read_mime_message ~storage_style:ext_storage_style nstr in
+ write_mime_message ~wr_body:false (new output_channel stdout) tree);
+ Netsendmail.sendmail ~mailer:"/usr/sbin/sendmail" tree
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1  code/ocaml-maze
@@ -0,0 +1 @@
+Subproject commit 011010a5946cea4c25468be86558c8d2ae903717
View
2  code/ocaml-text/_tags
@@ -0,0 +1,2 @@
+<patt.ml> : camlp4o, use_text
+<patt.{cmo}> : pkg_text
View
292 code/ocaml-text/myocamlbuild.ml