aboutsummaryrefslogtreecommitdiff
path: root/src/ls_goto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ls_goto.c')
-rw-r--r--src/ls_goto.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/ls_goto.c b/src/ls_goto.c
index 1c198c3..3572be6 100644
--- a/src/ls_goto.c
+++ b/src/ls_goto.c
@@ -21,26 +21,26 @@
// --- PRIVATE CONSTANTS -------------------------------------------------------
// --- PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
-static bool _rewind_line(ls_context_t * ctx);
+static bool _rewind_line(ls_t * self);
// --- PUBLIC VARIABLES --------------------------------------------------------
// --- PRIVATE VARIABLES -------------------------------------------------------
// --- PUBLIC FUNCTIONS --------------------------------------------------------
-void ls_goto_num(ls_context_t * ctx, bool backward, uint16_t num)
+void ls_goto_num(ls_t * self, bool backward, uint16_t num)
{
ls_addr_t target = LS_ADDR_NULL;
for (size_t i = 0; i < LS_LABEL_CACHE_SIZE; i++)
{
- if (ctx->label_cache[i].pc == LS_ADDR_NULL)
+ if (self->label_cache[i].pc == LS_ADDR_NULL)
continue;
- if (ctx->label_cache[i].num == num)
+ if (self->label_cache[i].num == num)
{
- if ((ctx->label_cache[i].pc > ctx->pc && !backward) ||
- (ctx->label_cache[i].pc <= ctx->pc && backward))
+ if ((self->label_cache[i].pc > self->pc && !backward) ||
+ (self->label_cache[i].pc <= self->pc && backward))
{
- target = ctx->label_cache[i].pc;
+ target = self->label_cache[i].pc;
break;
}
}
@@ -48,7 +48,7 @@ void ls_goto_num(ls_context_t * ctx, bool backward, uint16_t num)
// In case we can't find the label, save pc to "unwind" for a
// more helpful error later
- ls_addr_t pc = ctx->pc;
+ ls_addr_t pc = self->pc;
if (target == LS_ADDR_NULL && !backward)
{
@@ -56,13 +56,13 @@ void ls_goto_num(ls_context_t * ctx, bool backward, uint16_t num)
for (;;)
{
ls_token_t tok;
- ls_lex(ctx, &tok);
+ ls_lex(self, &tok);
if (tok.ty == LS_TOK_NUM_LABEL)
{
if (tok.body.number_val == num)
{
- target = ctx->pc;
+ target = self->pc;
break;
}
}
@@ -77,43 +77,43 @@ void ls_goto_num(ls_context_t * ctx, bool backward, uint16_t num)
{
ls_token_t tok;
- if (!_rewind_line(ctx))
+ if (!_rewind_line(self))
goto throw;
// Quickly saving and restoring our location avoids
// a costly second rewind to undo the ls_lex().
- ls_addr_t bw_pc = ctx->pc++;
- ls_lex(ctx, &tok);
+ ls_addr_t bw_pc = self->pc++;
+ ls_lex(self, &tok);
if (tok.ty == LS_TOK_NUM_LABEL)
{
if (tok.body.number_val == num)
{
- target = ctx->pc;
+ target = self->pc;
break;
}
}
- ctx->pc = bw_pc;
+ self->pc = bw_pc;
}
}
if (target == LS_ADDR_NULL)
{
throw:
- ctx->pc = pc;
- ls_throw_err(ctx, LS_UNDEFINED_LABEL);
+ self->pc = pc;
+ ls_throw_err(self, LS_UNDEFINED_LABEL);
}
else
{
- ctx->pc = target;
+ self->pc = target;
}
}
-void ls_goto_ident(ls_context_t * ctx, char const * ident)
+void ls_goto_ident(ls_t * self, char const * ident)
{
ls_value_t * label = NULL;
- for (ls_value_t * i = ctx->labels; i; i = i->next)
+ for (ls_value_t * i = self->labels; i; i = i->next)
{
if (!strncmp(i->body.label.ident, ident, LS_IDENT_LEN))
{
@@ -127,17 +127,17 @@ void ls_goto_ident(ls_context_t * ctx, char const * ident)
for (;;)
{
ls_token_t tok;
- ls_lex(ctx, &tok);
+ ls_lex(self, &tok);
if (tok.ty == LS_TOK_STR_LABEL)
{
// New labels are always put at the head,
// so test there. Don't just read the token
// in case some processing was done.
- if (!strncmp(ctx->labels->body.label.ident,
+ if (!strncmp(self->labels->body.label.ident,
ident, LS_IDENT_LEN))
{
- label = ctx->labels;
+ label = self->labels;
break;
}
}
@@ -149,27 +149,27 @@ void ls_goto_ident(ls_context_t * ctx, char const * ident)
}
if (!label)
- ls_throw_err(ctx, LS_UNDEFINED_LABEL);
+ ls_throw_err(self, LS_UNDEFINED_LABEL);
- ctx->pc = label->body.label.pc;
+ self->pc = label->body.label.pc;
}
// --- PRIVATE FUNCTION DEFINITIONS --------------------------------------------
-static bool _rewind_line(ls_context_t * ctx)
+static bool _rewind_line(ls_t * self)
{
- if (ctx->pc == 0)
+ if (self->pc == 0)
return false;
- ls_addr_t pc = (ls_addr_t)(ctx->pc - 1);
+ ls_addr_t pc = (ls_addr_t)(self->pc - 1);
for (;;)
{
- unsigned char ch = ls_fetch(ctx, pc);
+ unsigned char ch = ls_fetch(self, pc);
if (ch == '\n')
{
- ctx->pc = pc;
+ self->pc = pc;
return true;
}