Debian Codegraph @

kernel/nativelambda.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Util
12 open Genlambda
13
14 (** This file defines the lambda code generation phase of the native compiler *)
15
16 type lambda = Nativevalues.t Genlambda.lambda
17
18 (*s Constructors *)
19
20 (** Simplification of lambda expression *)
21
22 let is_value lc =
23 match node lc with
24 | Lval _ | Lint _ | Luint _ | Lfloat _ | Lstring _ -> true
25 | _ -> false
26
27 let get_value lc =
28 match node lc with
29 | Lval v -> v
30 | Lint tag -> Nativevalues.mk_int tag
31 | Luint i -> Nativevalues.mk_uint i
32 | Lfloat f -> Nativevalues.mk_float f
33 | Lstring s -> Nativevalues.mk_string s
34 | _ -> raise Not_found
35
36 let as_value tag args =
37 if Array.for_all is_value args then
38 let dummy_val = Obj.magic 0 in
39 let args =
40 (* Don't simplify this to Array.map, cf. the related comment in
41 function eval_to_patch, file kernel/csymtable.ml *)
42 let a = Array.make (Array.length args) dummy_val in
43 Array.iteri (fun i v -> a.(i) <- get_value v) args; a in
44 Some (Nativevalues.mk_block tag args)
45 else None
46
47 module Val =
48 struct
49 type value = Nativevalues.t
50 let as_value = as_value
51 let check_inductive _ _ = ()
52 end
53
54 module Lambda = Genlambda.Make(Val)
55
56 let lambda_of_constr env sigma c =
57 let lam = Lambda.lambda_of_constr env sigma c in
58 optimize lam