2026-05-17 15:33:44 +01:00
|
|
|
#include "compile-node.h"
|
|
|
|
|
|
|
|
|
|
enum bshell_status compile_push_value(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
const struct compile_value_type *type,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *node)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
|
|
|
|
struct compile_value *item = malloc(sizeof *item);
|
|
|
|
|
if (!item) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(item, 0x0, sizeof *item);
|
|
|
|
|
|
|
|
|
|
item->v_type = type;
|
|
|
|
|
item->v_node = node;
|
|
|
|
|
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 20:17:35 +01:00
|
|
|
enum bshell_status compile_push_value_array(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
const struct compile_value_type *type,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *node,
|
2026-05-24 20:17:35 +01:00
|
|
|
struct compile_value **values,
|
|
|
|
|
size_t nr_values)
|
|
|
|
|
{
|
|
|
|
|
struct compile_value *item = malloc(sizeof *item);
|
|
|
|
|
if (!item) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(item, 0x0, sizeof *item);
|
|
|
|
|
|
|
|
|
|
item->v_type = type;
|
|
|
|
|
item->v_node = node;
|
|
|
|
|
item->v_args = values;
|
|
|
|
|
item->v_nr_args = nr_values;
|
|
|
|
|
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
enum bshell_status compile_push_pool_value(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
const struct compile_value_type *type,
|
|
|
|
|
unsigned long pool_slot)
|
|
|
|
|
{
|
|
|
|
|
struct compile_value *item = malloc(sizeof *item);
|
|
|
|
|
if (!item) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(item, 0x0, sizeof *item);
|
|
|
|
|
|
|
|
|
|
item->v_type = type;
|
|
|
|
|
item->v_pool = pool_slot;
|
|
|
|
|
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum bshell_status compile_push_op(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *node,
|
2026-05-17 15:33:44 +01:00
|
|
|
const struct compile_value_type *type,
|
2026-05-25 10:33:29 +01:00
|
|
|
enum bshell_operator_id op,
|
2026-05-17 15:33:44 +01:00
|
|
|
struct compile_value *left,
|
|
|
|
|
struct compile_value *right)
|
|
|
|
|
{
|
|
|
|
|
struct compile_value *item = malloc(sizeof *item);
|
|
|
|
|
if (!item) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(item, 0x0, sizeof *item);
|
|
|
|
|
|
|
|
|
|
item->v_type = type;
|
2026-05-24 20:17:35 +01:00
|
|
|
item->v_node = node;
|
2026-05-17 15:33:44 +01:00
|
|
|
item->v_op = op;
|
|
|
|
|
item->v_left = left;
|
|
|
|
|
item->v_right = right;
|
|
|
|
|
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct compile_value *compile_pop_value(struct compile_ctx *ctx)
|
|
|
|
|
{
|
|
|
|
|
fx_queue_entry *entry = fx_queue_pop_back(&ctx->c_stack);
|
|
|
|
|
if (!entry) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fx_unbox(struct compile_value, entry, v_entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_value_load(struct compile_ctx *ctx, struct compile_value *item)
|
|
|
|
|
{
|
|
|
|
|
if (item->v_type->v_load) {
|
|
|
|
|
item->v_type->v_load(ctx, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_value_store(struct compile_ctx *ctx, struct compile_value *item)
|
|
|
|
|
{
|
|
|
|
|
if (item->v_type->v_store) {
|
|
|
|
|
item->v_type->v_store(ctx, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_value_destroy(struct compile_value *value)
|
|
|
|
|
{
|
2026-05-24 20:17:35 +01:00
|
|
|
if (value->v_left) {
|
|
|
|
|
compile_value_destroy(value->v_left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value->v_right) {
|
|
|
|
|
compile_value_destroy(value->v_right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < value->v_nr_args; i++) {
|
|
|
|
|
compile_value_destroy(value->v_args[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value->v_args) {
|
|
|
|
|
free(value->v_args);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
free(value);
|
|
|
|
|
}
|