Skip to content
This repository
tag: v996
Fetching contributors…

Cannot retrieve contributors at this time

file 159 lines (133 sloc) 3.555 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)

(**
Some utils for users of Ocaml lang.

@author Mathieu Barbin
@author Esther Baruk
*)

(**
Nary support for applications
*)
module App :
sig
  (**
Gather the arguments of an apply. Returns f * args
*)
  val nary_app : Ocaml.expr -> Ocaml.expr -> Ocaml.expr * Ocaml.expr list

  (**
Reconstruct an apply node from f * args
*)
  val app : Ocaml.expr -> Ocaml.expr list -> Ocaml.expr
end

(**
Operations on arrays
*)
module Array : sig
  (** Avoid an array construction by calling Array.make and filling the array *)
  val relax_make : Ocaml.expr -> Ocaml.expr
end

(** {6 Type alias} *)
(** *)
type filename = string

(** {6 Paths in modules} *)

(**
A ocaml module name.
This name is capitalized, like [String, List]
*)
type module_name = string

module Module :
sig

  (**
The path to a module
*)
  type path = module_name list


  val of_filename : filename -> module_name

  (**
For generating code containing field from records,
when you do not want to have conflicting open,
it is better to prefix the field by their global
module path.

{[
module_path ~full:["A" ; "B" ; "C"] ~pwd:["A"]
]}

returns
{[
["B" ; "C"]
]}

*)
  val module_path : full:path -> pwd:path -> path
end

(** {6 Ident} *)

module Ident :
sig
  (**
like {[asr, or, mod, lsr, +, etc...]}
*)
  val is_operator : string -> bool
end

(** {6 Optimizing Ocaml code} *)

(**
* Tries to optimize the code (without affecting its semantics).
* For now it only does a couple of simplifications of match
* expressions such as:
*
* [1]
* match [EXPR] with
* | [V1] -> [V1] -> [EXPR]
* | ...
* | [Vn] -> [Vn]
*
* [2]
* match [EXPR] with match e with
* | [V] -> [V] -> | [V] as E -> E
* | ... | ...
*
* [3]
* match match [EXPR] with match [EXPR] with
* | A(a1, ..., an) -> B(e_b1, ..., e_bn) | A(a1, ..., an) -> let (b1, ..., bn) = (e_b1, ..., e_bn) in X
* | C(c1, ..., cn) -> D(e_d1, ..., e_dn) -> | C(c1, ..., cn) -> let (c1, ..., cn) = (e_c1, ..., e_cn) in Y
* with
* | B(b1, ..., bn) -> X
* | D(d1, ..., dn) -> Y
*
* All are needed for TRX code generation.
* But in the future more optimizations may be added so it's good
* to apply this functions to your generated code so that it can
* benefit from them as they come.
*)
val optimize : Ocaml.code -> Ocaml.code

(**
Misc
*)
module Misc :
sig
  (**
Utils for passtracker.
Returns the number of node of an expression.
FIXME:
currently, the pattern are not counted.
*)
  val size : Ocaml.expr -> int
end

(**
Simple dependencies computation.
*)
module Deps :
sig
  (**
Fold on every ident.
Used for computing the dependency of an expression.
*)
  val deps : (Ocaml.param_effectif -> 'acc -> 'acc) -> 'acc -> Ocaml.expr -> 'acc
end
Something went wrong with that request. Please try again.