tlang-c/libtlang/src/if.c

28 lines
822 B
C
Raw Normal View History

2023-04-24 18:41:46 +00:00
#include "tlang.h"
extern bool __loop_bool(node_t* n,scope_t* s);
2023-05-06 04:03:12 +00:00
tobject_t* __if_exec(node_t* n,scope_t* s,retarg_t* retArg)
2023-04-24 18:41:46 +00:00
{
if(__loop_bool(n->data.if_node.condition,s))
{
2023-05-06 04:03:12 +00:00
return n->data.if_node.yes->execute(n->data.if_node.yes,s,retArg);
2023-04-24 18:41:46 +00:00
} else {
2023-05-06 04:03:12 +00:00
return n->data.if_node.no->execute(n->data.if_node.no,s,retArg);
2023-04-24 18:41:46 +00:00
}
}
void __if_free(node_t* n)
{
node_free(n->data.if_node.condition);
node_free(n->data.if_node.yes);
node_free(n->data.if_node.no);
}
node_t* node_if_create(node_t* condition,node_t* y,node_t* n)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
node->type = ifnode;
node->data.if_node.condition = condition;
node->data.if_node.yes = y;
node->data.if_node.no = n;
node->execute = __if_exec;
node->free = __if_free;
return node;
}