diff options
| author | Alasdair Armstrong | 2017-07-21 17:31:08 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2017-07-21 17:31:08 +0100 |
| commit | 79b81722d8cfe3c2c2fa16bbc8643e8243dfa015 (patch) | |
| tree | 8505834a54e449aae18307ec5647472a4155cf72 | |
| parent | b7b6ebc7da062141369d85cd263f1b07561cd396 (diff) | |
Add a prove builtin that allows testing flow typing
For example:
default Order dec
val bit[64] -> unit effect pure test64
val cast forall 'n, 'n = 32 | 'n = 64. bit['n] -> unit effect pure test
function forall 'n. unit test addr =
{
_prove(constraint('n != 16));
assert(constraint('n = 64), "64-bit mode");
_prove(constraint('n = 64));
test64(addr);
}
This doesn't affect the AST at all as _prove is just a ordinary function
that the typechecker treats specially.
| -rw-r--r-- | editors/sail-mode.el | 4 | ||||
| -rw-r--r-- | src/type_check_new.ml | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/editors/sail-mode.el b/editors/sail-mode.el index c898fc1e..96059a3f 100644 --- a/editors/sail-mode.el +++ b/editors/sail-mode.el @@ -710,6 +710,8 @@ Based on Tuareg mode. See Tuareg mode for usage" sail-font-lock-keywords `(("\\<\\(extern\\|cast\\|overload\\|deinfix\\|function\\|scattered\\|clause\\|effect\\|default\\|struct\\|const\\|union\\|val\\|typedef\\|let\\|rec\\|and\\|end\\|register\\|alias\\|member\\|enumerate\\)\\>" 0 sail-font-lock-governing-face nil nil) + ("\\<\\(_prove\\)\\>" + 0 font-lock-preprocessor-face nil nil) ("\\<\\(false\\|true\\|bitzero\\|bitone\\|0x[:xdigit:]\\|[:digit:]\\)\\>" 0 font-lock-constant-face nil nil) ("\\<\\(as\\|downto\\|else\\|foreach\\|if\\|t\\(hen\\|o\\)\\|when\\|in\\|switch\\|with\\|case\\|when\\|exit\\|constraint\\|sizeof\\|nondet\\|from\\|by\\|return\\)\\>" 0 font-lock-keyword-face nil nil) @@ -724,7 +726,7 @@ Based on Tuareg mode. See Tuareg mode for usage" ("\\<\\(val\\|and\\|let\\>[ \t\n]*\\(\\(\\w\\|[_,?~.]\\)*\\)\\>\\(\\(\\w\\|[->_ \t,?~.]\\|(\\(\\w\\|[--->_ \t,?~.=]\\)*)\\)*\\)" 6 font-lock-variable-name-face keep nil) ("\\<\\([?~]?[_[:alpha:]]\\w*\\)[ \t\n]*:[^:>=]" - 1 font-lock-variable-name-face keep nil) + 0 font-lock-variable-name-face keep nil) ("^#\\w+\\>" 0 font-lock-preprocessor-face t nil) )) (setq font-lock-defaults diff --git a/src/type_check_new.ml b/src/type_check_new.ml index f8845311..f3374fea 100644 --- a/src/type_check_new.ml +++ b/src/type_check_new.ml @@ -1626,6 +1626,10 @@ let rec check_exp env (E_aux (exp_aux, (l, ())) as exp : unit exp) (Typ_aux (typ end | E_app_infix (x, op, y), _ when List.length (Env.get_overloads (deinfix op) env) > 0 -> check_exp env (E_aux (E_app (deinfix op, [x; y]), (l, ()))) typ + | E_app (f, [E_aux (E_constraint nc, _)]), _ when Id.compare f (mk_id "_prove") = 0 -> + if prove env nc + then annot_exp (E_lit (L_aux (L_unit, Parse_ast.Unknown))) unit_typ + else typ_error l ("Cannot prove " ^ string_of_n_constraint nc) | E_app (f, xs), _ when List.length (Env.get_overloads f env) > 0 -> let rec try_overload = function | [] -> typ_error l ("No valid overloading for " ^ string_of_exp exp) |
