Skip to content
This repository
tag: v1154
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 134 lines (113 sloc) 3.28 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
/*
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/>.
*/

/**
* @category compiler interface
* @destination internal use, private
* @author Valentin Gatien-Baron, 2011 (ad hoc serialization)
* @author Mathieu Barbin, 2011 (review)
* @stability stable
*/

/**
* {1 About this module}
*
* {1 Where should I start ?}
*
* {1 What if I need more?}
**/

/**
* {2 Javascript code manipulation}
*
* Server side code used to store and retrieve javascript/css files
**/

/**
* {3 Types}
*/

/**
* BEWARE: the compiler generate this type in qmljs_Serializer
* @opacapi
**/
type Client_code.input =
     {adhoc : list(string); package_ : string}
   / {ast : JsAst.code}

/**
* @opacapi
**/
type Client_code.output =
     {adhoc : string; package_ : string}
   / {ast : JsAst.code}

/**
* {3 Interface}
*/

@server_private
Core_client_code =
{{
  /*
* Private registered stack of client code on server (LIFO)
* Will be served for all client.
*/
  @private
  js_codes = ServerReference.create([]:list(Client_code.output))

  /**
* Register client code on server to be served for all client
* @opacapi
**/
  register_js_code(js_code:Client_code.input) : void =
    code =
      match js_code with
      | ~{adhoc package_} ->
        adhoc = String.concat("",adhoc)
        ~{adhoc package_}
      | {ast=_} as v ->
        v
    ServerReference.update(js_codes,List.cons(code,_))

  /**
* Retrieve client code on server to be served for all client
* Used for building the complete javascript code of the application
**/
  retrieve_js_codes() : list(Client_code.output) =
    l = List.rev(ServerReference.get(js_codes))
    do ServerReference.set(js_codes,[])
    do @assert(l != []) /* making sure this function is called at most once */
    l
}}

/**
* {2 Server code representation}
*
* Server side code used to perform a more clever cleaning of the javascript.
**/

/**
* {3 Types}
*/

/**
* BEWARE: the compiler generates this type in pass_GenerateServerAst
* @opacapi
**/
type ServerCode.t =
     {adhoc : string; package_ : string}

/**
* {3 Interface}
*/

Core_server_code =
{{
  @private server_codes = ServerReference.create([]:list(ServerCode.t))
  register_server_code(code:ServerCode.t) : void =
    ServerReference.update(server_codes, List.cons(code,_))
  retrieve_server_codes() : list(ServerCode.t) =
    l = List.rev(ServerReference.get(server_codes))
    do ServerReference.set(server_codes, [])
    do @assert(l != []) // same assertion as for the js code
    l
}}

@opacapi Client_code_register_js_code = Core_client_code.register_js_code
@opacapi Core_server_code_register_server_code = Core_server_code.register_server_code
Something went wrong with that request. Please try again.