| 1 |
open Util |
| 2 |
open Declarations |
| 3 |
open Genlambda |
| 4 |
open Vmvalues |
| 5 |
|
| 6 |
type lval = int * structured_values |
| 7 |
type lambda = lval Genlambda.lambda |
| 8 |
|
| 9 |
let get_lval (_, v) = v |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
let is_value lc = |
| 18 |
match node lc with |
| 19 |
| Lval _ | Lint _ | Luint _ | Lfloat _ | Lstring _ -> true |
| 20 |
| _ -> false |
| 21 |
|
| 22 |
let get_value lc = |
| 23 |
match node lc with |
| 24 |
| Luint i -> val_of_uint i |
| 25 |
| Lval (_, v) -> v |
| 26 |
| Lint i -> val_of_int i |
| 27 |
| Lfloat f -> val_of_float f |
| 28 |
| Lstring s -> val_of_string s |
| 29 |
| _ -> assert false |
| 30 |
|
| 31 |
let hash_block tag args = |
| 32 |
let open Hashset.Combine in |
| 33 |
let fold accu v = |
| 34 |
let h = match node v with |
| 35 |
| Luint i -> Uint63.hash i |
| 36 |
| Lint i -> Hashtbl.hash (i : int) |
| 37 |
| Lfloat f -> Float64.hash f |
| 38 |
| Lstring s -> Pstring.hash s |
| 39 |
| Lval (h, _) -> h |
| 40 |
| _ -> assert false |
| 41 |
in |
| 42 |
combine accu h |
| 43 |
in |
| 44 |
combine tag (Array.fold_left fold 0 args) |
| 45 |
|
| 46 |
module HashBlock = |
| 47 |
struct |
| 48 |
type t = int * structured_values array * structured_values |
| 49 |
let eq (tag1, args1, _) (tag2, args2, _) = |
| 50 |
Int.equal tag1 tag2 && CArray.equal (==) args1 args2 |
| 51 |
end |
| 52 |
|
| 53 |
module HashsetBlock = Hashset.Make(HashBlock) |
| 54 |
|
| 55 |
let block_table = HashsetBlock.create 97 |
| 56 |
|
| 57 |
let as_value tag args = |
| 58 |
if Array.for_all is_value args then |
| 59 |
let h = hash_block tag args in |
| 60 |
|
| 61 |
let args = |
| 62 |
let dummy_val = Obj.magic 0 in |
| 63 |
let ans = Array.make (Array.length args) dummy_val in |
| 64 |
let () = Array.iteri (fun i v -> ans.(i) <- get_value v) args in |
| 65 |
ans |
| 66 |
in |
| 67 |
if tag < Obj.last_non_constant_constructor_tag then |
| 68 |
let block = val_of_block tag args in |
| 69 |
let (_, _, block) = HashsetBlock.repr h (tag, args, block) block_table in |
| 70 |
Some (h, block) |
| 71 |
else |
| 72 |
let args = Array.append [| val_of_int (tag - Obj.last_non_constant_constructor_tag) |] args in |
| 73 |
let block = val_of_block Obj.last_non_constant_constructor_tag args in |
| 74 |
let (_, _, block) = HashsetBlock.repr h (tag, args, block) block_table in |
| 75 |
Some (h, block) |
| 76 |
else None |
| 77 |
|
| 78 |
module Val = |
| 79 |
struct |
| 80 |
type value = int * structured_values |
| 81 |
let as_value = as_value |
| 82 |
let check_inductive (_, i) mb = |
| 83 |
let { mind_typename=name; mind_nb_args; mind_nb_constant; _ } = mb.mind_packets.(i) in |
| 84 |
Vmerrors.check_compilable_ind ~name ~mind_nb_args ~mind_nb_constant |
| 85 |
end |
| 86 |
|
| 87 |
module Lambda = Genlambda.Make(Val) |
| 88 |
|
| 89 |
|
| 90 |
let dump_lambda_flag, dump_lambda = CDebug.create_full ~name:"vmlambda" () |
| 91 |
|
| 92 |
let lambda_of_constr env sigma c = |
| 93 |
let lam = Lambda.lambda_of_constr env sigma c in |
| 94 |
let lam = optimize lam in |
| 95 |
dump_lambda (fun () -> pp_lam lam); |
| 96 |
lam |