Hack codegen: static closures, ordering of inline functions and classes
[hiphop-php.git] / hphp / hack / src / hhbc / hhas_program.ml
blobda07a66d34827d4a5a56fa7aada36ccc310636f8
1 (**
2 * Copyright (c) 2017, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 *)
11 type t = {
12 hhas_adata : Hhas_adata.t list;
13 hhas_fun : Hhas_function.t list;
14 hhas_classes : Hhas_class.t list;
15 hhas_typedefs: Hhas_typedef.t list;
16 hhas_main : Hhas_body.t;
19 let make hhas_adata hhas_fun hhas_classes hhas_typedefs hhas_main =
20 { hhas_adata; hhas_fun; hhas_classes; hhas_typedefs; hhas_main }
22 let functions hhas_prog =
23 hhas_prog.hhas_fun
25 let classes hhas_prog =
26 hhas_prog.hhas_classes
28 let typedefs hhas_prog =
29 hhas_prog.hhas_typedefs
31 let main hhas_prog =
32 hhas_prog.hhas_main
34 let adata hhas_prog =
35 hhas_prog.hhas_adata
37 open Instruction_sequence
39 let emit_main defs =
40 let body, _is_generator, _is_pair_generator =
41 Emit_body.emit_body
42 ~namespace:Namespace_env.empty_with_default_popt
43 ~is_closure_body:false
44 ~is_memoize:false
45 ~skipawaitable:false
46 ~is_return_by_ref:false
47 ~scope:Ast_scope.Scope.toplevel
48 ~return_value:(instr_int 1)
49 ~default_dropthrough:None
50 [] None defs
52 body
54 open Closure_convert
56 let from_ast ast =
57 let closed_ast = convert_toplevel_prog ast in
58 try
59 let compiled_defs = emit_main closed_ast in
60 let compiled_funs = Emit_function.emit_functions_from_program closed_ast in
61 let compiled_classes = Emit_class.emit_classes_from_program closed_ast in
62 let compiled_typedefs = Emit_typedef.emit_typedefs_from_program closed_ast in
63 let adata = Emit_adata.get_adata () in
64 make adata compiled_funs compiled_classes compiled_typedefs compiled_defs
65 with Emit_fatal.IncludeTimeFatalException (op, message) ->
66 let body = Emit_body.make_body (Emit_fatal.emit_fatal op message)
67 [] (* decl_vars *)
68 false (*is_memoize_wrapper*)
69 [] (* params *)
70 None (* return_type_info *)
72 make [] [] [] [] body