tlang-c/libtlang/src/lessthanequal.c

68 lines
1.9 KiB
C
Raw Normal View History

2023-04-24 18:41:46 +00:00
#include "tlang.h"
extern void __node_two_free(node_t* n);
tobject_t* __lessthanequal_node_exec(node_t* n,scope_t* sc)
{
bool freeleftifzero=true;
node_t* left = n->data.two_node_node.left;
node_t* right = n->data.two_node_node.right;
tobject_t* l=left->execute(left,sc);
tobject_t* r=right->execute(right,sc);
tobject_t* out=NULL;
tobject_type_t ltype=l->type;
tobject_type_t rtype =r->type;
if(ltype == tdict)
{
if(dict_haskey(l->data.dict,"lte"))
{
kvp_t* kvp=dict_getkvp(l->data.dict,"lte");
if(kvp->value->type == texternalmethod || kvp->value->type == tinternalmethod)
{
list_tobject_t ls;
list_create(sc->rt,&ls,0);
list_add(&ls,r);
out=tobject_call(sc->rt->globals,kvp->value,&ls);
out->count++; //ensure i dont get deleted
tobject_freeifzero(l);
out->count--; //set me back bitch
r->count++;
list_free(&ls);
r->count--;
freeleftifzero = false;
}
}
}
if(ltype == tnumber && rtype == tnumber)
{
out = tobject_create(sc->rt);
out->type = tbool;
out->data.boolean = l->data.number <= r->data.number;
}
if(freeleftifzero)
{
tobject_freeifzero(l);
}
tobject_freeifzero(r);
if(out == NULL)
{
return tobject_basic(sc->rt,tnull);
}
return out;
}
node_t* node_lessthanequal_create(node_t* left,node_t* right)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
node->type = lessthanequalnode;
node->data.two_node_node.left = left;
node->data.two_node_node.right = right;
node->execute = __lessthanequal_node_exec;
node->free = __node_two_free;
return node;
}