| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Pp |
| 12 |
|
| 13 |
type error = |
| 14 |
| TooLargeInductive of Names.Id.t |
| 15 |
| TooLargeCode |
| 16 |
|
| 17 |
|
| 18 |
exception CompileError of error |
| 19 |
|
| 20 |
let too_large_code () = raise (CompileError TooLargeCode) |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
let max_nb_const = 0x1000000 |
| 26 |
let max_nb_block = 0x1000000 + Obj.last_non_constant_constructor_tag - 1 |
| 27 |
|
| 28 |
let str_max_constructors = |
| 29 |
Format.sprintf |
| 30 |
" which has more than %i constant constructors or more than %i non-constant constructors" max_nb_const max_nb_block |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
let check_compilable_ind ~name ~mind_nb_args ~mind_nb_constant = |
| 36 |
if not (mind_nb_args <= max_nb_block && mind_nb_constant <= max_nb_const) then |
| 37 |
raise (CompileError (TooLargeInductive name)) |
| 38 |
|
| 39 |
let pr_error = function |
| 40 |
| TooLargeCode -> str "Cannot compile code for virtual machine as it exceeds string size limits." |
| 41 |
| TooLargeInductive name -> |
| 42 |
str "Cannot compile code for virtual machine as it uses inductive " ++ |
| 43 |
Names.Id.print name ++ str str_max_constructors |
| 44 |
|
| 45 |
let () = CErrors.register_handler (function |
| 46 |
| CompileError e -> Some (pr_error e) |
| 47 |
| _ -> None) |