aboutsummaryrefslogtreecommitdiff
path: root/src/types.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/types.c b/src/types.c
index 24458ff..31edc4b 100644
--- a/src/types.c
+++ b/src/types.c
@@ -17,6 +17,17 @@ bool type_equals(Type *a, Type *b)
return a->type == b->type && type_equals(a->ptr, b->ptr);
}
+bool is_convertible(Type *from, Type *to)
+{
+ if (from->type == TYPE_ANY || to->type == TYPE_ANY)
+ return true;
+ // TODO: Should we rause a warning if the target type is narrower
+ // than the source type?
+ if (is_int_type(from) && is_int_type(to))
+ return true;
+ return type_equals(from, to);
+}
+
i64 size_for_type(Type *type)
{
switch (type->type)
@@ -55,6 +66,18 @@ bool is_string_type(Type *type)
&& type->ptr->type == TYPE_CHAR;
}
+bool is_int_type(Type *type)
+{
+ switch (type->type)
+ {
+ case TYPE_INT:
+ case TYPE_CHAR:
+ return true;
+ default:
+ return false;
+ }
+}
+
static char *data_type_to_str(DataType type)
{
switch (type)