diff options
| author | Kathy Gray | 2014-02-06 14:41:59 +0000 |
|---|---|---|
| committer | Kathy Gray | 2014-02-06 14:41:59 +0000 |
| commit | eedfe41a826a0a54fcc69fa32d1ad4286f9c9318 (patch) | |
| tree | 6cf2cf9964078daf9505acf6d63e5b2062767350 /src | |
| parent | e25be25def886bcdf78b75a88a996ef4b94416bb (diff) | |
coercians for bits to bools for literals
Diffstat (limited to 'src')
| -rw-r--r-- | src/type_check.ml | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/type_check.ml b/src/type_check.ml index d77e1d92..c691985b 100644 --- a/src/type_check.ml +++ b/src/type_check.ml @@ -375,8 +375,14 @@ let rec check_exp envs expect_t (E_aux(e,(l,annot)) : tannot exp) : (tannot exp | E_lit (L_aux(lit,l')) -> let t,lit' = (match lit with | L_unit -> unit_t,lit - | L_zero -> bit_t,lit - | L_one -> bit_t,lit + | L_zero -> + (match expect_t.t with + | Tid "bool" -> bool_t,L_false + | _ -> bit_t,lit) + | L_one -> + (match expect_t.t with + | Tid "bool" -> bool_t,L_true + | _ -> bit_t,lit) | L_true -> bool_t,lit | L_false -> bool_t,lit | L_num i -> @@ -385,7 +391,12 @@ let rec check_exp envs expect_t (E_aux(e,(l,annot)) : tannot exp) : (tannot exp if i = 0 then bit_t,L_zero else if i = 1 then bit_t,L_one - else typ_error l "Expected bit,found a number that cannot be used as a bit" + else typ_error l "Expected bit, found a number that cannot be used as a bit" + | Tid "bool" -> + if i = 0 then bool_t, L_false + else + if i = 1 then bool_t,L_true + else typ_error l "Expected bool, found a number that cannot be used as a bit and converted to bool" | _ -> {t = Tapp("enum", [TA_nexp{nexp = Nconst i};TA_nexp{nexp= Nconst 0};])},lit) | L_hex s -> {t = Tapp("vector", |
