adding compilation of if-else statements

This commit is contained in:
cozis
2021-10-31 07:01:15 +00:00
parent 5e8fb7ef6b
commit 9eaa82297f
16 changed files with 269 additions and 25 deletions
+30
View File
@@ -218,6 +218,13 @@ _Bool Object_IsInt(Object *obj)
return obj->type->atomic == ATMTP_INT;
}
_Bool Object_IsBool(Object *obj)
{
assert(obj != NULL);
assert(obj->type != NULL);
return obj->type->atomic == ATMTP_BOOL;
}
_Bool Object_IsFloat(Object *obj)
{
assert(obj != NULL);
@@ -248,6 +255,29 @@ long long int Object_ToInt(Object *obj, Error *err)
return type->to_int(obj, err);
}
_Bool Object_ToBool(Object *obj, Error *err)
{
assert(err);
assert(obj);
if(!Object_IsBool(obj))
{
Error_Report(err, 0, "Object is not a boolean");
return 0;
}
const Type *type = Object_GetType(obj);
assert(type);
if(type->to_bool == NULL)
{
Error_Report(err, "Object %s doesn't implement %s", Object_GetName(obj), __func__);
return 0;
}
return type->to_bool(obj, err);
}
double Object_ToFloat(Object *obj, Error *err)
{
assert(err);