Skip to content
This repository
tag: v811
Fetching contributors…

Cannot retrieve contributors at this time

file 131 lines (104 sloc) 3.616 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
(*
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/>.
*)

(**
Module for macro generating bsl types coercions and definitions.

@author Mathieu Barbin
*)

(**
This module implements the traduction of bsl-types into the back-end languages.
It has also a module dedicated to Opa syntax for bsl-preprocessing (cf [iformats]).

TODO:
Currently, we output code only as concrete syntax (Ocaml, Js).
It is really usefull to have dedicated printers for BslTypes,
because we can make some specific control for external primitives
printing and error messages,
but for code generation, it would be better to pass through an
AST generation.
Some (sunny) day we will add an implemention for AST production.

+ when OcamlAst will be more stable.
+ when JsAst will be more stable.
+ when we will decide what we do with LLVM, and have a AST for extern C bindings.

*)

(** *)
type 'a pprinter = 'a LangPrint.pprinter
type ('env, 'a, 'ast) generator = 'env -> 'a -> 'env * 'ast

module Opa :
sig
  (**
Printer for [t] with the opa syntax
*)
  val pp : BslTypes.t pprinter

  (**
Used for declarating a new external type
{[
type toto('a, 'b) = external
]}
Assert: This function is called with an [External] type, with [TypeVar] for all parameters
@error if [t] is not a candidate for definition (outside of this case)
*)
  val pp_definition : BslTypes.t pprinter
end

module Ocaml :
sig
  (** TODO: add link for ocaml path manager *)

  (**
Printer for [t] with the ocaml syntax.

This function is the kernel of the type checking done
on the [MLRuntime], because it produces types coercions
from the types read in the register directives.

cf: BslServerLib.S

The scope of type variables is fresh for every call to pp.
*)
  val pp : BslTypes.t pprinter

  (**
For External types, the implementation is hidden, it is a ocaml row code.
{[
##extern-type ('a, 'b) toto = Ka of 'a | Kb of 'b
]}
will produce
+ in the ml:
{[
type ('a, 'b) toto = Ka of 'a | Kb of 'b
]}
+ in the mli:
{[
type ('a, 'b) toto
]}
+ in opa:
{[
type toto('a, 'b) = external
]}

Assert: This function is called with an exteranl types, with only [TypeVars] for parameters

@error if [t] is not a candidate for definition (outside of this case)
*)
  val pp_definition : BslTypes.t pprinter
end

module C :
sig
  (**
At some we did some tests for targetting llvm.
This is currently unused, and unmaintain, and this is
probably no more corresponding to anything we will keep.

This is partially not implemented and not supported by
any back-end.

@deprecated Wait for LLVM backend.
*)

  (**
Printer for [t] with the C syntax.

<!> It outputs type name and macro which are define in
the pervasives of the C (["opabsl/cbsl"]). You cannot use
it without the C init library.
*)
  val pp : BslTypes.t pprinter

end
Something went wrong with that request. Please try again.