2026-05-17 15:33:44 +01:00
|
|
|
#include "compile-node.h"
|
|
|
|
|
|
|
|
|
|
enum bshell_status int_load(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
struct compile_value *value)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_int_ast_node *i
|
|
|
|
|
= (struct bshell_int_ast_node *)value->v_node;
|
2026-05-24 20:17:35 +01:00
|
|
|
long long v;
|
|
|
|
|
fx_value_get_longlong(&i->n_value->tok_number, &v);
|
2026-05-25 10:33:29 +01:00
|
|
|
bshell_scriptblock_push_instruction(ctx->c_block, BSHELL_OPCODE_LDC_INT, v);
|
2026-05-24 20:17:35 +01:00
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum bshell_status double_load(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
struct compile_value *value)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_double_ast_node *d
|
|
|
|
|
= (struct bshell_double_ast_node *)value->v_node;
|
2026-05-24 20:17:35 +01:00
|
|
|
double v;
|
|
|
|
|
fx_value_get_double(&d->n_value->tok_number, &v);
|
|
|
|
|
unsigned long index = bshell_scriptblock_get_double(ctx->c_block, v);
|
2026-05-25 10:33:29 +01:00
|
|
|
bshell_scriptblock_push_instruction(ctx->c_block, BSHELL_OPCODE_LDC_FP, index);
|
2026-05-17 15:33:44 +01:00
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum bshell_status string_load(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
struct compile_value *value)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_string_ast_node *s
|
|
|
|
|
= (struct bshell_string_ast_node *)value->v_node;
|
2026-05-17 15:33:44 +01:00
|
|
|
unsigned long index = bshell_scriptblock_get_string(
|
|
|
|
|
ctx->c_block,
|
|
|
|
|
s->n_value->tok_str);
|
|
|
|
|
if (index == POOL_INDEX_INVALID) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bshell_scriptblock_push_instruction(
|
|
|
|
|
ctx->c_block,
|
2026-05-25 10:33:29 +01:00
|
|
|
BSHELL_OPCODE_LDC_STR,
|
2026-05-17 15:33:44 +01:00
|
|
|
index);
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum bshell_status word_load(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
struct compile_value *value)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_word_ast_node *s
|
|
|
|
|
= (struct bshell_word_ast_node *)value->v_node;
|
2026-05-17 15:33:44 +01:00
|
|
|
unsigned long index = bshell_scriptblock_get_string(
|
|
|
|
|
ctx->c_block,
|
|
|
|
|
s->n_value->tok_str);
|
|
|
|
|
if (index == POOL_INDEX_INVALID) {
|
|
|
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bshell_scriptblock_push_instruction(
|
|
|
|
|
ctx->c_block,
|
2026-05-25 10:33:29 +01:00
|
|
|
BSHELL_OPCODE_LDC_STR,
|
2026-05-17 15:33:44 +01:00
|
|
|
index);
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct compile_value_type int_type = {
|
|
|
|
|
.v_load = int_load,
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-24 20:17:35 +01:00
|
|
|
static const struct compile_value_type double_type = {
|
|
|
|
|
.v_load = double_load,
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
static const struct compile_value_type string_type = {
|
|
|
|
|
.v_load = string_load,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct compile_value_type word_type = {
|
|
|
|
|
.v_load = word_load,
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-25 10:33:29 +01:00
|
|
|
struct compile_result compile_int(
|
|
|
|
|
struct compile_ctx *ctx,
|
|
|
|
|
struct bshell_ast_node *src)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
|
|
|
|
compile_push_value(ctx, &int_type, src);
|
|
|
|
|
return COMPILE_OK(0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 20:17:35 +01:00
|
|
|
struct compile_result compile_double(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src)
|
2026-05-24 20:17:35 +01:00
|
|
|
{
|
|
|
|
|
compile_push_value(ctx, &double_type, src);
|
|
|
|
|
return COMPILE_OK(0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
struct compile_result compile_string(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
|
|
|
|
compile_push_value(ctx, &string_type, src);
|
|
|
|
|
return COMPILE_OK(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct compile_result compile_word(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
|
|
|
|
compile_push_value(ctx, &word_type, src);
|
|
|
|
|
return COMPILE_OK(0);
|
|
|
|
|
}
|