2023-12-11 17:01:22 +00:00
|
|
|
#include "prepass.h"
|
|
|
|
|
|
|
|
void prepass_init(prepass_t* prepass, err_t* err)
|
|
|
|
{
|
|
|
|
assert(prepass);
|
|
|
|
assert(err);
|
|
|
|
|
|
|
|
prepass->err = err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void prepass_free(prepass_t* prepass)
|
|
|
|
{
|
|
|
|
assert(prepass);
|
|
|
|
}
|
|
|
|
|
|
|
|
void prepass_run(prepass_t* prepass, node_t* node)
|
|
|
|
{
|
|
|
|
assert(prepass);
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
switch (node->type)
|
|
|
|
{
|
|
|
|
case NODE_MOD:
|
|
|
|
case NODE_NUM:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_BOOL:
|
2023-12-15 18:30:20 +00:00
|
|
|
case NODE_ASSERT:
|
|
|
|
case NODE_EQ:
|
2023-12-15 20:32:17 +00:00
|
|
|
case NODE_NE:
|
|
|
|
case NODE_LT:
|
|
|
|
case NODE_LE:
|
|
|
|
case NODE_GT:
|
2023-12-15 21:31:01 +00:00
|
|
|
case NODE_GE:
|
|
|
|
|
|
|
|
case NODE_ADD:
|
|
|
|
case NODE_SUB:
|
|
|
|
case NODE_MUL:
|
|
|
|
case NODE_DIV:
|
|
|
|
case NODE_MODULO:
|
|
|
|
case NODE_POW:{
|
2023-12-11 17:01:22 +00:00
|
|
|
for (size_t i=0; i<node->children.size; i++)
|
|
|
|
{
|
|
|
|
prepass_run(prepass, (node_t*) node->children.data[i]);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
fprintf(stderr, "Cannot prepass unknown node '%s'.\n",
|
|
|
|
NodeTypeStr[node->type]);
|
|
|
|
abort();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|