51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
#include "compile-node.h"
|
|
|
|
enum bshell_status var_load(
|
|
struct compile_ctx *ctx,
|
|
struct compile_value *value)
|
|
{
|
|
struct var_ast_node *var = (struct var_ast_node *)value->v_node;
|
|
unsigned long index = bshell_scriptblock_get_string(
|
|
ctx->c_block,
|
|
var->n_ident->tok_str);
|
|
if (index == POOL_INDEX_INVALID) {
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
}
|
|
|
|
bshell_scriptblock_push_instruction(
|
|
ctx->c_block,
|
|
OPCODE_LDLOCAL,
|
|
index);
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
enum bshell_status var_store(
|
|
struct compile_ctx *ctx,
|
|
struct compile_value *value)
|
|
{
|
|
struct var_ast_node *var = (struct var_ast_node *)value->v_node;
|
|
unsigned long index = bshell_scriptblock_get_string(
|
|
ctx->c_block,
|
|
var->n_ident->tok_str);
|
|
if (index == POOL_INDEX_INVALID) {
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
}
|
|
|
|
bshell_scriptblock_push_instruction(
|
|
ctx->c_block,
|
|
OPCODE_STLOCAL,
|
|
index);
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
static const struct compile_value_type var_type = {
|
|
.v_load = var_load,
|
|
.v_store = var_store,
|
|
};
|
|
|
|
struct compile_result compile_var(struct compile_ctx *ctx, struct ast_node *src)
|
|
{
|
|
compile_push_value(ctx, &var_type, src);
|
|
return COMPILE_OK(0);
|
|
}
|