Skip to content
This repository
tag: v1379
Fetching contributors…

Cannot retrieve contributors at this time

file 131 lines (106 sloc) 4.11 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/>.
*)
(**
Serializer for JsAst
@author Mathieu Barbin
@author Rudy Sicard
*)

(**
During the compilation, we generate some opa-structures from the JsAst optained by compiling the client code.
These opa-structures are manipulated by opa code present in the stdlib.
It is a way for passing informations (the js ast) from compile time to runtime
*)

module JsIdent :
sig
  (**
Retreive the name of the js expression from the [name] of OPA
expression. Used for resolve [\@js_ident]. If the given string
doesn't corresponding to an ident in OPA raise [Not_found].

The function return a fresh ident refering to a toplevel declaration
generated in an internal reference.
If you call 2 time this function with the same name, you'll get 2 time
the same ident.

Example:

*)
  val resolve : Ident.t -> Ident.t

  (**
Get all the toplevel declaration corresponding to all previous call to
[resolve_js_ident], and flush the internal reference. (clear it)

Should be concatenated with the code.
The code has no dependencies, and can be inserted anywhere before any utilisation.
*)
  val get_toplevel_declarations : unit -> QmlAst.code

  (**
As we need to perform some check about unbound values before that we reintroduce
the memorized toplevel values generated by call to [resolve], and retrieve with
[get_toplevel_declarations], we need a function to know, given an identifier
if it will be defined in the returned [QmlAst.code].
*)
  val is_toplevel_declaration : Ident.t -> bool
end


(**
Binding with the module JsAst of the stdlib.
This structure is used for generating at compile time some runtime JsAst,
without caring about runtime representation (serialization of the structure)
*)
module JsSerializer :
sig

  type jsast_ident = string

  type jsast_mini_expr =
    | Verbatim of string
    | Ident of jsast_ident
    | Expr of QmlAst.expr
    | SetDistant of jsast_ident list
    | TypeUse of string
    | TypeDef of string
    | RpcUse of string
    | RpcDef of string

  type jsast_key_ident =
    | KI_key of string
    | KI_ident of jsast_ident
    | KI_key_ident of string * jsast_ident

  type jsast_code_elt = {
    ident : jsast_key_ident ;
    definition : [ `Rpc of string | `Type of string | `Nothing ];
    root : bool ;
    content : jsast_mini_expr list ;
  }

  type jsast_code = jsast_code_elt list

  (**
A function for serializing the compile time JsAst. (from jslang).
This function uses internally the Js Partial Printer defined in [JsPrinter].

The [register_call] map is used for tagging register call, so that we know
at runtime that they are not random side effects.
*)
  val serialize :
    client_roots:IdentSet.t ->
    ?key:string ->
    JsAst.code_elt -> jsast_code_elt

end

(**
Serializing the compile time structure to the runtime ast.
The resulting expressions are meant to be part of the generated code.
*)
module QmlSerializer :
sig

  (**
Build a qml expression of type [JsAst.code].
Returns a code of needed generated toplevel intermediate values,
and an expression of type [JsAst.code], ready to be registered.

<!> This module is hard-linked with the representation implemented
in the packages [stdlib.js], in the module [JsAst].
Keep it synchronized.
*)
  val insert_code : kind:[`ast|`adhoc] -> JsSerializer.jsast_code -> QmlAst.code -> QmlAst.code
end
Something went wrong with that request. Please try again.