new built-in variables for each type
This commit is contained in:
@@ -97,6 +97,11 @@ static _Bool to_bool(Object *obj, Error *err)
|
||||
return obj == &the_true_object;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetBoolType()
|
||||
{
|
||||
return &t_bool;
|
||||
}
|
||||
|
||||
Object *Object_FromBool(_Bool val, Heap *heap, Error *error)
|
||||
{
|
||||
(void) heap;
|
||||
|
||||
@@ -82,6 +82,11 @@ static TypeObject t_buffer_slice = {
|
||||
|
||||
#define THRESHOLD 128
|
||||
|
||||
TypeObject *Object_GetBufferType()
|
||||
{
|
||||
return &t_buffer;
|
||||
}
|
||||
|
||||
_Bool Object_IsBuffer(Object *obj)
|
||||
{
|
||||
return obj->type == &t_buffer_slice || obj->type == &t_buffer;
|
||||
|
||||
@@ -44,6 +44,11 @@ static TypeObject t_dir = {
|
||||
.free = dir_free,
|
||||
};
|
||||
|
||||
TypeObject *Object_GetDirType()
|
||||
{
|
||||
return &t_dir;
|
||||
}
|
||||
|
||||
_Bool Object_IsDir(Object *obj)
|
||||
{
|
||||
return obj->type == &t_dir;
|
||||
|
||||
@@ -44,6 +44,11 @@ static TypeObject t_file = {
|
||||
.free = file_free,
|
||||
};
|
||||
|
||||
TypeObject *Object_GetFileType()
|
||||
{
|
||||
return &t_file;
|
||||
}
|
||||
|
||||
_Bool Object_IsFile(Object *obj)
|
||||
{
|
||||
return obj->type == &t_file;
|
||||
|
||||
@@ -98,6 +98,11 @@ static double to_float(Object *obj, Error *err)
|
||||
return ((FloatObject*) obj)->val;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetFloatType()
|
||||
{
|
||||
return &t_float;
|
||||
}
|
||||
|
||||
Object *Object_FromFloat(double val, Heap *heap, Error *error)
|
||||
{
|
||||
FloatObject *obj = (FloatObject*) Heap_Malloc(heap, &t_float, error);
|
||||
|
||||
@@ -84,6 +84,11 @@ static long long int to_int(Object *obj, Error *err)
|
||||
return ((IntObject*) obj)->val;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetIntType()
|
||||
{
|
||||
return &t_int;
|
||||
}
|
||||
|
||||
Object *Object_FromInt(long long int val, Heap *heap, Error *error)
|
||||
{
|
||||
assert(heap != NULL);
|
||||
|
||||
@@ -99,6 +99,11 @@ static Object *copy(Object *self, Heap *heap, Error *err)
|
||||
return (Object*) ls2;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetListType()
|
||||
{
|
||||
return &t_list;
|
||||
}
|
||||
|
||||
Object *Object_NewList(int capacity, Heap *heap, Error *error)
|
||||
{
|
||||
// Handle default args.
|
||||
|
||||
@@ -108,6 +108,11 @@ static int hash(Object *self)
|
||||
return h;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetMapType()
|
||||
{
|
||||
return &t_map;
|
||||
}
|
||||
|
||||
Object *Object_NewMap(int num, Heap *heap, Error *error)
|
||||
{
|
||||
// Handle default args.
|
||||
|
||||
@@ -52,6 +52,11 @@ static Object the_none_object = {
|
||||
.flags = Object_STATIC,
|
||||
};
|
||||
|
||||
TypeObject *Object_GetNoneType()
|
||||
{
|
||||
return &t_none;
|
||||
}
|
||||
|
||||
_Bool Object_IsNone(Object *obj)
|
||||
{
|
||||
return obj == &the_none_object;
|
||||
|
||||
@@ -134,6 +134,11 @@ static char *to_string(Object *self, int *size, Heap *heap, Error *err)
|
||||
return s->body;
|
||||
}
|
||||
|
||||
TypeObject *Object_GetStringType()
|
||||
{
|
||||
return &t_string;
|
||||
}
|
||||
|
||||
Object *Object_FromString(const char *str, int len, Heap *heap, Error *error)
|
||||
{
|
||||
assert(str != NULL);
|
||||
|
||||
@@ -41,6 +41,11 @@ TypeObject t_type = {
|
||||
.op_eql = op_eql,
|
||||
};
|
||||
|
||||
TypeObject *Object_GetTypeType()
|
||||
{
|
||||
return &t_type;
|
||||
}
|
||||
|
||||
static _Bool op_eql(Object *self, Object *other)
|
||||
{
|
||||
return self == other;
|
||||
|
||||
@@ -149,6 +149,18 @@ Object* Object_FromString(const char *str, int len, Heap *heap, Error *error);
|
||||
Object* Object_FromStream(FILE *fp, Heap *heap, Error *error);
|
||||
Object* Object_FromDIR(DIR *handle, Heap *heap, Error *error);
|
||||
|
||||
TypeObject *Object_GetTypeType();
|
||||
TypeObject *Object_GetNoneType();
|
||||
TypeObject *Object_GetIntType();
|
||||
TypeObject *Object_GetBoolType();
|
||||
TypeObject *Object_GetFloatType();
|
||||
TypeObject *Object_GetStringType();
|
||||
TypeObject *Object_GetListType();
|
||||
TypeObject *Object_GetMapType();
|
||||
TypeObject *Object_GetBufferType();
|
||||
TypeObject *Object_GetFileType();
|
||||
TypeObject *Object_GetDirType();
|
||||
|
||||
_Bool Object_IsNone(Object *obj);
|
||||
_Bool Object_IsInt(Object *obj);
|
||||
_Bool Object_IsBool(Object *obj);
|
||||
|
||||
Reference in New Issue
Block a user