aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 15:33:47 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 15:33:47 -0400
commite422079fcced744e3a6247aeb12a09a658989072 (patch)
tree393d5e52ba67dcc822ccfa9a812198edda5e735d /typecheck.c
parent259c7efcf8c3808d8151d8e15f1167ad2b6f2ca7 (diff)
Add a Byte datatype
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/typecheck.c b/typecheck.c
index 86c204dc..5f40b078 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -503,6 +503,7 @@ type_t *get_type(env_t *env, ast_t *ast)
auto i = Match(ast, Int);
switch (i->bits) {
case IBITS_UNSPECIFIED: return Type(BigIntType);
+ case IBITS_BYTE: return Type(ByteType);
case IBITS8: return Type(IntType, .bits=TYPE_IBITS8);
case IBITS16: return Type(IntType, .bits=TYPE_IBITS16);
case IBITS32: return Type(IntType, .bits=TYPE_IBITS32);
@@ -1006,7 +1007,8 @@ type_t *get_type(env_t *env, ast_t *ast)
auto rhs_ptr = Match(rhs_t, PointerType);
if (type_eq(lhs_ptr->pointed, rhs_ptr->pointed))
return Type(PointerType, .pointed=lhs_ptr->pointed, .is_readonly=lhs_ptr->is_readonly || rhs_ptr->is_readonly);
- } else if (is_int_type(lhs_t) && is_int_type(rhs_t)) {
+ } else if ((is_int_type(lhs_t) && is_int_type(rhs_t))
+ || (lhs_t->tag == ByteType && rhs_t->tag == ByteType)) {
return get_math_type(env, ast, lhs_t, rhs_t);
}
code_err(ast, "I can't figure out the type of this `and` expression because the left side is a %T, but the right side is a %T",
@@ -1017,7 +1019,8 @@ type_t *get_type(env_t *env, ast_t *ast)
return lhs_t;
} else if (lhs_t->tag == BoolType && (rhs_t->tag == AbortType || rhs_t->tag == ReturnType)) {
return lhs_t;
- } else if (is_int_type(lhs_t) && is_int_type(rhs_t)) {
+ } else if ((is_int_type(lhs_t) && is_int_type(rhs_t))
+ || (lhs_t->tag == ByteType && rhs_t->tag == ByteType)) {
return get_math_type(env, ast, lhs_t, rhs_t);
} else if (lhs_t->tag == OptionalType) {
if (can_promote(rhs_t, lhs_t))
@@ -1038,7 +1041,8 @@ type_t *get_type(env_t *env, ast_t *ast)
case BINOP_XOR: {
if (lhs_t->tag == BoolType && rhs_t->tag == BoolType) {
return lhs_t;
- } else if (is_int_type(lhs_t) && is_int_type(rhs_t)) {
+ } else if ((is_int_type(lhs_t) && is_int_type(rhs_t))
+ || (lhs_t->tag == ByteType && rhs_t->tag == ByteType)) {
return get_math_type(env, ast, lhs_t, rhs_t);
}