Files

55 lines
1.2 KiB
C
Raw Permalink Normal View History

#include "compile-node.h"
enum bshell_status var_load(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_var_ast_node *var
= (struct bshell_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,
BSHELL_OPCODE_LDLOCAL,
index);
return BSHELL_SUCCESS;
}
enum bshell_status var_store(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_var_ast_node *var
= (struct bshell_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,
BSHELL_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 bshell_ast_node *src)
{
compile_push_value(ctx, &var_type, src);
return COMPILE_OK(0);
}