tlang-c/libtlang/src/constnode.c

114 lines
2.9 KiB
C
Raw Normal View History

2023-04-24 18:41:46 +00:00
#include "tlang.h"
2023-05-06 04:03:12 +00:00
tobject_t* __const_number_exec(node_t* n,scope_t* sc,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
tobject_t* obj=tobject_create(sc->rt);
obj->data.number = n->data.const_number;
obj->type =tnumber;
return obj;
}
void __const_number_free(node_t* s)
{
}
void __const_string_free(node_t* s)
{
string_free(s->data.const_string);
}
node_t* node_const_number_create(double num)
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->data.const_number = num;
n->type = constnumbernode;
n->execute = __const_number_exec;
n->free = __const_number_free;
return n;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_bool_exec(node_t* n,scope_t* sc,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
tobject_t* obj=tobject_create(sc->rt);
obj->data.boolean = n->data.const_bool;
obj->type =tbool;
return obj;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_string_exec(node_t* n,scope_t* sc,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
tobject_t* obj=tobject_create(sc->rt);
obj->data.string = string_dups(n->data.const_string);
obj->type =tstring;
return obj;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_char_exec(node_t* n,scope_t* sc,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
tobject_t* obj=tobject_create(sc->rt);
obj->data.chr = n->data.const_char;
obj->type =tchar;
return obj;
}
node_t* node_const_string_create(string_t* s)
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->data.const_string = string_dups(s);
n->type = conststringnode;
n->execute = __const_string_exec;
n->free = __const_string_free;
return n;
}
node_t* node_const_char_create(char c)
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->data.const_char = c;
n->type = constcharnode;
n->execute = __const_char_exec;
n->free = __const_number_free;
return n;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_object_exec(node_t* n,scope_t* sc,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
return n->data.const_obj;
}
node_t* node_const_object_create(tobject_t* o)
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->data.const_obj = o;
n->type = constobjectnode;
n->execute = __const_object_exec;
n->free = __const_number_free;
return n;
}
node_t* node_const_bool_create(bool c)
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->data.const_bool = c;
n->type = constboolnode;
n->execute = __const_bool_exec;
n->free = __const_number_free;
return n;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_undef_exec(node_t* n,scope_t* s,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
return tobject_basic(s->rt,tundef);
}
node_t* node_const_undef_create()
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->type = constundefnode;
n->execute = __const_undef_exec;
n->free = __const_number_free;
return n;
}
2023-05-06 04:03:12 +00:00
tobject_t* __const_null_exec(node_t* n,scope_t* s,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
return tobject_basic(s->rt,tnull);
}
node_t* node_const_null_create()
{
node_t* n = (node_t*)malloc(sizeof(node_t));
n->type = constnullnode;
n->execute = __const_null_exec;
n->free = __const_number_free;
return n;
}