diff options
Diffstat (limited to 'src/ls_expr.c')
-rw-r--r-- | src/ls_expr.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/ls_expr.c b/src/ls_expr.c index 29a49f6..95a6e38 100644 --- a/src/ls_expr.c +++ b/src/ls_expr.c @@ -34,7 +34,7 @@ typedef struct { } ls_operdef_t; typedef struct __packed{ - ls_context_t * ctx; + ls_t * self; uint8_t opstack[OPSTACK_N]; uint8_t opstack_i; ls_value_t * outstack; @@ -136,10 +136,10 @@ static const ls_operdef_t _opers[] = { // --- PUBLIC FUNCTIONS -------------------------------------------------------- -void ls_eval_expr(ls_context_t * ctx, ls_value_t * val, ls_token_t * firsttok) +void ls_eval_expr(ls_t * self, ls_value_t * val, ls_token_t * firsttok) { ls_shuntingyard_t yard = { - .ctx = ctx, + .self = self, .opstack_i = 0, .outstack = NULL, .nest = 0, @@ -157,9 +157,9 @@ void ls_eval_expr(ls_context_t * ctx, ls_value_t * val, ls_token_t * firsttok) while (!done) { - ls_addr_t pc_save = ctx->pc; + ls_addr_t pc_save = self->pc; - ls_lex(ctx, &tok); + ls_lex(self, &tok); have_token: switch (tok.ty) { @@ -189,7 +189,7 @@ have_token: if (done) { // Don't eat the token that ended the line - ctx->pc = pc_save; + self->pc = pc_save; } } @@ -197,14 +197,14 @@ have_token: _pop_oper_and_apply(&yard); if (!yard.outstack) - ls_throw_err(ctx, LS_SYNTAX_ERROR); + ls_throw_err(self, LS_SYNTAX_ERROR); *val = *yard.outstack; if (yard.outstack->next) - ls_throw_err(ctx, LS_SYNTAX_ERROR); + ls_throw_err(self, LS_SYNTAX_ERROR); - ls_free(ctx, yard.outstack); + ls_free(self, yard.outstack); } // --- PRIVATE FUNCTION DEFINITIONS -------------------------------------------- @@ -220,7 +220,7 @@ static ls_oper_t _pop(ls_shuntingyard_t * yard) if (yard->opstack_i) return yard->opstack[--yard->opstack_i]; else - ls_throw_err(yard->ctx, LS_INTERNAL_ERROR); + ls_throw_err(yard->self, LS_INTERNAL_ERROR); // unreachable return NO_OPER; } @@ -228,7 +228,7 @@ static ls_oper_t _pop(ls_shuntingyard_t * yard) static void _push(ls_shuntingyard_t * yard, ls_oper_t oper) { if (yard->opstack_i >= OPSTACK_N - 1) - ls_throw_err(yard->ctx, LS_OUT_OF_MEMORY); + ls_throw_err(yard->self, LS_OUT_OF_MEMORY); else yard->opstack[yard->opstack_i++] = oper; } @@ -243,13 +243,13 @@ static void _pop_oper_and_apply(ls_shuntingyard_t * yard) ls_value_t * rhs = yard->outstack; if (!rhs) - ls_throw_err(yard->ctx, LS_SYNTAX_ERROR); + ls_throw_err(yard->self, LS_SYNTAX_ERROR); ls_value_t * lhs = rhs->next; if (!p_op->unary) { if (!lhs) - ls_throw_err(yard->ctx, LS_SYNTAX_ERROR); + ls_throw_err(yard->self, LS_SYNTAX_ERROR); yard->outstack = rhs; rhs->next = lhs->next; } @@ -261,12 +261,12 @@ static void _pop_oper_and_apply(ls_shuntingyard_t * yard) ); if (!p_op->unary) - ls_free(yard->ctx, lhs); + ls_free(yard->self, lhs); } static void _handle_number(ls_shuntingyard_t * yard, ls_token_t const * tok) { - ls_value_t * v = ls_alloc(yard->ctx); + ls_value_t * v = ls_alloc(yard->self); v->ty = LS_TY_INT; v->body.integer.value = tok->body.number_val; v->prev = NULL; @@ -277,14 +277,14 @@ static void _handle_number(ls_shuntingyard_t * yard, ls_token_t const * tok) static void _handle_word(ls_shuntingyard_t * yard, ls_token_t * tok) { - ls_value_t * var = ls_find_var(yard->ctx, tok->body.word_val); + ls_value_t * var = ls_find_var(yard->self, tok->body.word_val); if (!var) - ls_throw_err(yard->ctx, LS_UNDEFINED_VARIABLE); + ls_throw_err(yard->self, LS_UNDEFINED_VARIABLE); // TODO: types tok->ty = LS_TOK_NUMBER; - tok->body.number_val = ls_read_int_var(yard->ctx, var); + tok->body.number_val = ls_read_int_var(yard->self, var); } static bool _handle_keyword(ls_shuntingyard_t * yard, ls_token_t * tok) @@ -377,13 +377,13 @@ static bool _handle_other(ls_shuntingyard_t * yard, ls_token_t const * tok) case LS_TOK_STATEMENT_SEP: case LS_TOK_NONE: if (yard->nest) - ls_throw_err(yard->ctx, LS_SYNTAX_ERROR); + ls_throw_err(yard->self, LS_SYNTAX_ERROR); else return true; break; default: - ls_throw_err(yard->ctx, LS_SYNTAX_ERROR); + ls_throw_err(yard->self, LS_SYNTAX_ERROR); } return false; |