aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Lockwood2021-06-29 19:20:32 -0400
committerAlexis Lockwood2021-06-29 19:20:32 -0400
commit28c925db09ef5f2007854d929db5530e47e769fd (patch)
tree5182931e98a320345b7f2403f9adbc5389ba718c
parent45160a54da8ff82a89dd44eabcd9c90d8b8d96a0 (diff)
OPER should be namespaced too
-rw-r--r--README.md1
-rw-r--r--ls_minify.c30
-rw-r--r--ls_run.c46
-rw-r--r--src/ls_expr.c98
-rw-r--r--src/ls_internal.c2
-rw-r--r--src/ls_kw_impl_GOSUB_RETURN.c6
-rw-r--r--src/ls_kw_impl_GOTO.c4
-rw-r--r--src/ls_lex.c32
-rw-r--r--src/ls_types.h50
-rw-r--r--test/test_internal.c12
10 files changed, 140 insertions, 141 deletions
diff --git a/README.md b/README.md
index 132dc20..cd4d172 100644
--- a/README.md
+++ b/README.md
@@ -107,7 +107,6 @@ The following things use pool entries:
- Hooks
- Label cache
- Fetcher (always execute in RAM)
-- `OPER` should be `LS_OPER`
# THE SCRIPTING LANGUAGE
diff --git a/ls_minify.c b/ls_minify.c
index 8da01fd..4c295cb 100644
--- a/ls_minify.c
+++ b/ls_minify.c
@@ -381,23 +381,23 @@ static void _min_operator(minifier_t * min, ls_token_t tok)
{
// TODO: this could be centralized
static const unsigned char ops[][3] = {
- [OPER_LEQ] = "<=",
- [OPER_GEQ] = ">=",
- [OPER_NEQ] = "<>",
- [OPER_LPAREN] = "(",
- [OPER_RPAREN] = ")",
- [OPER_MOD] = "%",
- [OPER_MUL] = "*",
- [OPER_ADD] = "+",
- [OPER_SUB] = "-",
- [OPER_DIV] = "/",
- [OPER_POW] = "^",
- [OPER_LT] = "<",
- [OPER_EQ] = "=",
- [OPER_GT] = ">",
+ [LS_OP_LEQ] = "<=",
+ [LS_OP_GEQ] = ">=",
+ [LS_OP_NEQ] = "<>",
+ [LS_OP_LPAREN] = "(",
+ [LS_OP_RPAREN] = ")",
+ [LS_OP_MOD] = "%",
+ [LS_OP_MUL] = "*",
+ [LS_OP_ADD] = "+",
+ [LS_OP_SUB] = "-",
+ [LS_OP_DIV] = "/",
+ [LS_OP_POW] = "^",
+ [LS_OP_LT] = "<",
+ [LS_OP_EQ] = "=",
+ [LS_OP_GT] = ">",
};
- assert(tok.body.oper_val <= OPER_GT);
+ assert(tok.body.oper_val <= LS_OP_GT);
if (un_minify)
fprintf(min->f_out, " ");
diff --git a/ls_run.c b/ls_run.c
index 4323bfd..0af59c4 100644
--- a/ls_run.c
+++ b/ls_run.c
@@ -301,29 +301,29 @@ static void _tokenize(ls_t * ls)
printf("OPERAT ");
switch (tok.body.oper_val)
{
- case OPER_ABS: printf("ABS\n"); break;
- case OPER_NOT: printf("NOT\n"); break;
- case OPER_AND: printf("AND\n"); break;
- case OPER_OR : printf("OR\n"); break;
- case OPER_XOR: printf("XOR\n"); break;
- case OPER_EQV: printf("EQV\n"); break;
- case OPER_IMP: printf("IMP\n"); break;
- case OPER_NEQ: printf("<>\n"); break;
- case OPER_LEQ: printf("<=\n"); break;
- case OPER_GEQ: printf(">=\n"); break;
- case OPER_LPAREN: printf("(\n"); break;
- case OPER_RPAREN: printf(")\n"); break;
- case OPER_POW: printf("^\n"); break;
- case OPER_MUL: printf("*\n"); break;
- case OPER_DIV: printf("/\n"); break;
- case OPER_MOD: printf("MOD\n"); break;
- case OPER_NEG: printf("- (neg)\n"); break;
- case OPER_ADD: printf("+\n"); break;
- case OPER_SUB: printf("- (sub)\n"); break;
- case OPER_EQ: printf("=\n"); break;
- case OPER_LT: printf("<\n"); break;
- case OPER_GT: printf(">\n"); break;
- case NO_OPER: printf("--no oper--\n"); break;
+ case LS_OP_ABS: printf("ABS\n"); break;
+ case LS_OP_NOT: printf("NOT\n"); break;
+ case LS_OP_AND: printf("AND\n"); break;
+ case LS_OP_OR : printf("OR\n"); break;
+ case LS_OP_XOR: printf("XOR\n"); break;
+ case LS_OP_EQV: printf("EQV\n"); break;
+ case LS_OP_IMP: printf("IMP\n"); break;
+ case LS_OP_NEQ: printf("<>\n"); break;
+ case LS_OP_LEQ: printf("<=\n"); break;
+ case LS_OP_GEQ: printf(">=\n"); break;
+ case LS_OP_LPAREN: printf("(\n"); break;
+ case LS_OP_RPAREN: printf(")\n"); break;
+ case LS_OP_POW: printf("^\n"); break;
+ case LS_OP_MUL: printf("*\n"); break;
+ case LS_OP_DIV: printf("/\n"); break;
+ case LS_OP_MOD: printf("MOD\n"); break;
+ case LS_OP_NEG: printf("- (neg)\n"); break;
+ case LS_OP_ADD: printf("+\n"); break;
+ case LS_OP_SUB: printf("- (sub)\n"); break;
+ case LS_OP_EQ: printf("=\n"); break;
+ case LS_OP_LT: printf("<\n"); break;
+ case LS_OP_GT: printf(">\n"); break;
+ case LS_NO_OP: printf("--no oper--\n"); break;
default: printf("--invalid %u--\n",
(unsigned) tok.body.oper_val); break;
}
diff --git a/src/ls_expr.c b/src/ls_expr.c
index 805a741..7d9cfd8 100644
--- a/src/ls_expr.c
+++ b/src/ls_expr.c
@@ -31,7 +31,7 @@ typedef struct {
bool right : 1; // associativity
/// Function for two ints, or for one int (ignore lhs, for unary)
ls_int_t (*fun_int_int)(ls_int_t lhs, ls_int_t rhs);
-} ls_operdef_t;
+} ls_opdef_t;
typedef struct __packed{
ls_t * self;
@@ -46,14 +46,14 @@ typedef struct __packed{
// --- PRIVATE CONSTANTS -------------------------------------------------------
// --- PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
-/// Return the top operator on the stack without popping. Returns NO_OPER if
+/// Return the top operator on the stack without popping. Returns LS_NO_OP if
/// empty.
-static ls_oper_t _top(ls_shuntingyard_t * yard);
+static ls_op_t _top(ls_shuntingyard_t * yard);
/// Pop the top operator off the stack and return it. Throws LS_INTERNAL_ERROR
/// if empty.
-static ls_oper_t _pop(ls_shuntingyard_t * yard);
+static ls_op_t _pop(ls_shuntingyard_t * yard);
/// Push an operator to the stack, throwing LS_OUT_OF_MEMORY if it's full.
-static void _push(ls_shuntingyard_t * yard, ls_oper_t oper);
+static void _push(ls_shuntingyard_t * yard, ls_op_t op);
/// Handle a LS_TOK_WORD. If a word is found, it is transformed into a NUMBER
/// and should be passed along to _handle_number(). (If it is not found, an
@@ -107,31 +107,31 @@ static ls_int_t _geq_int_int(ls_int_t lhs, ls_int_t rhs);
// --- PUBLIC VARIABLES --------------------------------------------------------
// --- PRIVATE VARIABLES -------------------------------------------------------
-static const ls_operdef_t _opers[] = {
- [OPER_ABS] = { 13, true, true, &_abs_int },
- [OPER_NOT] = { 13, true, true, &_not_int },
- [OPER_NEG] = { 13, true, true, &_neg_int },
+static const ls_opdef_t _ops[] = {
+ [LS_OP_ABS] = { 13, true, true, &_abs_int },
+ [LS_OP_NOT] = { 13, true, true, &_not_int },
+ [LS_OP_NEG] = { 13, true, true, &_neg_int },
- [OPER_MUL] = { 12, false, false, &_mul_int_int },
- [OPER_DIV] = { 12, false, false, &_div_int_int },
- [OPER_MOD] = { 12, false, false, &_mod_int_int },
+ [LS_OP_MUL] = { 12, false, false, &_mul_int_int },
+ [LS_OP_DIV] = { 12, false, false, &_div_int_int },
+ [LS_OP_MOD] = { 12, false, false, &_mod_int_int },
- [OPER_ADD] = { 11, false, false, &_add_int_int },
- [OPER_SUB] = { 11, false, false, &_sub_int_int },
+ [LS_OP_ADD] = { 11, false, false, &_add_int_int },
+ [LS_OP_SUB] = { 11, false, false, &_sub_int_int },
- [OPER_LT] = { 9, false, false, &_lt_int_int },
- [OPER_GT] = { 9, false, false, &_gt_int_int },
- [OPER_LEQ] = { 9, false, false, &_leq_int_int },
- [OPER_GEQ] = { 9, false, false, &_geq_int_int },
+ [LS_OP_LT] = { 9, false, false, &_lt_int_int },
+ [LS_OP_GT] = { 9, false, false, &_gt_int_int },
+ [LS_OP_LEQ] = { 9, false, false, &_leq_int_int },
+ [LS_OP_GEQ] = { 9, false, false, &_geq_int_int },
- [OPER_EQ] = { 8, false, false, &_eq_int_int },
- [OPER_NEQ] = { 8, false, false, &_neq_int_int },
+ [LS_OP_EQ] = { 8, false, false, &_eq_int_int },
+ [LS_OP_NEQ] = { 8, false, false, &_neq_int_int },
- [OPER_AND] = { 7, false, false, &_and_int_int },
- [OPER_XOR] = { 7, false, false, &_xor_int_int },
- [OPER_OR] = { 7, false, false, &_or_int_int },
- [OPER_EQV] = { 7, false, false, &_eqv_int_int },
- [OPER_IMP] = { 7, false, false, &_imp_int_int },
+ [LS_OP_AND] = { 7, false, false, &_and_int_int },
+ [LS_OP_XOR] = { 7, false, false, &_xor_int_int },
+ [LS_OP_OR] = { 7, false, false, &_or_int_int },
+ [LS_OP_EQV] = { 7, false, false, &_eqv_int_int },
+ [LS_OP_IMP] = { 7, false, false, &_imp_int_int },
};
// --- PUBLIC FUNCTIONS --------------------------------------------------------
@@ -209,23 +209,23 @@ have_token:
// --- PRIVATE FUNCTION DEFINITIONS --------------------------------------------
-static ls_oper_t _top(ls_shuntingyard_t * yard)
+static ls_op_t _top(ls_shuntingyard_t * yard)
{
uint8_t i = yard->opstack_i;
- return i ? yard->opstack[i - 1] : NO_OPER;
+ return i ? yard->opstack[i - 1] : LS_NO_OP;
}
-static ls_oper_t _pop(ls_shuntingyard_t * yard)
+static ls_op_t _pop(ls_shuntingyard_t * yard)
{
if (yard->opstack_i)
return yard->opstack[--yard->opstack_i];
else
ls_throw_err(yard->self, LS_INTERNAL_ERROR);
// unreachable
- return NO_OPER;
+ return LS_NO_OP;
}
-static void _push(ls_shuntingyard_t * yard, ls_oper_t oper)
+static void _push(ls_shuntingyard_t * yard, ls_op_t oper)
{
if (yard->opstack_i >= OPSTACK_N - 1)
ls_throw_err(yard->self, LS_OUT_OF_MEMORY);
@@ -235,10 +235,10 @@ static void _push(ls_shuntingyard_t * yard, ls_oper_t oper)
static void _pop_oper_and_apply(ls_shuntingyard_t * yard)
{
- ls_oper_t const op = _pop(yard);
- ls_operdef_t const * p_op = &_opers[op];
+ ls_op_t const op = _pop(yard);
+ ls_opdef_t const * p_op = &_ops[op];
- if (op == OPER_LPAREN)
+ if (op == LS_OP_LPAREN)
return;
ls_value_t * rhs = yard->outstack;
@@ -294,13 +294,13 @@ static bool _handle_keyword(ls_shuntingyard_t * yard, ls_token_t * tok)
switch (tok->body.keyword_val)
{
- case LS_KW_ABS: tok->body.oper_val = OPER_ABS; break;
- case LS_KW_NOT: tok->body.oper_val = OPER_NOT; break;
- case LS_KW_AND: tok->body.oper_val = OPER_AND; break;
- case LS_KW_XOR: tok->body.oper_val = OPER_XOR; break;
- case LS_KW_OR: tok->body.oper_val = OPER_OR; break;
- case LS_KW_EQV: tok->body.oper_val = OPER_EQV; break;
- case LS_KW_IMP: tok->body.oper_val = OPER_IMP; break;
+ case LS_KW_ABS: tok->body.oper_val = LS_OP_ABS; break;
+ case LS_KW_NOT: tok->body.oper_val = LS_OP_NOT; break;
+ case LS_KW_AND: tok->body.oper_val = LS_OP_AND; break;
+ case LS_KW_XOR: tok->body.oper_val = LS_OP_XOR; break;
+ case LS_KW_OR: tok->body.oper_val = LS_OP_OR; break;
+ case LS_KW_EQV: tok->body.oper_val = LS_OP_EQV; break;
+ case LS_KW_IMP: tok->body.oper_val = LS_OP_IMP; break;
default:
return true;
}
@@ -310,28 +310,28 @@ static bool _handle_keyword(ls_shuntingyard_t * yard, ls_token_t * tok)
static bool _handle_operator(ls_shuntingyard_t * yard, ls_token_t const * tok)
{
- ls_oper_t op = tok->body.oper_val;
+ ls_op_t op = tok->body.oper_val;
if (yard->allow_unary)
{
- if (op == OPER_SUB)
- op = OPER_NEG;
+ if (op == LS_OP_SUB)
+ op = LS_OP_NEG;
}
- if (op == OPER_RPAREN)
+ if (op == LS_OP_RPAREN)
{
// This is likely an enclosing paren for something else
// (e.g. function call syntax in GOSUB).
if (yard->nest == 0)
return true;
- while (_top(yard) != OPER_LPAREN)
+ while (_top(yard) != LS_OP_LPAREN)
_pop_oper_and_apply(yard);
_pop(yard);
--yard->nest;
yard->allow_unary = false;
}
- else if (op == OPER_LPAREN)
+ else if (op == LS_OP_LPAREN)
{
_push(yard, op);
++yard->nest;
@@ -339,12 +339,12 @@ static bool _handle_operator(ls_shuntingyard_t * yard, ls_token_t const * tok)
}
else
{
- ls_operdef_t const * p_op = &_opers[op];
+ ls_opdef_t const * p_op = &_ops[op];
uint8_t const prec = p_op->precedence;
- while (_top(yard) != NO_OPER)
+ while (_top(yard) != LS_NO_OP)
{
- ls_operdef_t const *p_top = &_opers[_top(yard)];
+ ls_opdef_t const *p_top = &_ops[_top(yard)];
uint8_t const tprec = p_top->precedence;
bool apply = p_op->right
diff --git a/src/ls_internal.c b/src/ls_internal.c
index 692b17c..13b3f61 100644
--- a/src/ls_internal.c
+++ b/src/ls_internal.c
@@ -328,7 +328,7 @@ bool ls_exec_line(ls_t * self)
ls_token_t tok_eq;
ls_lex(self, &tok_eq);
if (tok_eq.ty != LS_TOK_OPERATOR
- || tok_eq.body.oper_val != OPER_EQ)
+ || tok_eq.body.oper_val != LS_OP_EQ)
ls_throw_err(self, LS_SYNTAX_ERROR);
ls_value_t val;
diff --git a/src/ls_kw_impl_GOSUB_RETURN.c b/src/ls_kw_impl_GOSUB_RETURN.c
index 8e8d850..2561be4 100644
--- a/src/ls_kw_impl_GOSUB_RETURN.c
+++ b/src/ls_kw_impl_GOSUB_RETURN.c
@@ -52,7 +52,7 @@ void ls_kw_fun_GOSUB(ls_t * self)
self->_callstack->body.sctx_call.pc = self->_pc;
ls_lex(self, &tok);
- if (tok.ty == LS_TOK_OPERATOR && tok.body.oper_val == OPER_LPAREN)
+ if (tok.ty == LS_TOK_OPERATOR && tok.body.oper_val == LS_OP_LPAREN)
{
for (;;)
{
@@ -66,7 +66,7 @@ void ls_kw_fun_GOSUB(ls_t * self)
ls_lex(self, &tok);
if (!(tok.ty == LS_TOK_OPERATOR &&
- tok.body.oper_val == OPER_EQ))
+ tok.body.oper_val == LS_OP_EQ))
ls_throw_err(self, LS_SYNTAX_ERROR);
ls_value_t val;
@@ -78,7 +78,7 @@ void ls_kw_fun_GOSUB(ls_t * self)
else if (tok.ty == LS_TOK_COMMA)
continue;
else if (tok.ty == LS_TOK_OPERATOR
- && tok.body.oper_val == OPER_RPAREN)
+ && tok.body.oper_val == LS_OP_RPAREN)
break;
else
ls_throw_err(self, LS_SYNTAX_ERROR);
diff --git a/src/ls_kw_impl_GOTO.c b/src/ls_kw_impl_GOTO.c
index cbabeb0..ef364ef 100644
--- a/src/ls_kw_impl_GOTO.c
+++ b/src/ls_kw_impl_GOTO.c
@@ -41,9 +41,9 @@ void ls_kw_fun_GOTO(ls_t * self)
ls_goto_ident(self, tok.body.word_val);
break;
case LS_TOK_OPERATOR:
- if (tok.body.oper_val == OPER_SUB)
+ if (tok.body.oper_val == LS_OP_SUB)
backward = true;
- else if (tok.body.oper_val != OPER_ADD)
+ else if (tok.body.oper_val != LS_OP_ADD)
ls_throw_err(self, LS_SYNTAX_ERROR);
ls_lex(self, &tok);
diff --git a/src/ls_lex.c b/src/ls_lex.c
index 34bd39f..4bfc599 100644
--- a/src/ls_lex.c
+++ b/src/ls_lex.c
@@ -224,23 +224,23 @@ static ch_kind_t _ident_ch_kind(unsigned char ch)
static void _lex_oper(ls_t * self, ls_token_t * tok, ls_uchar ch[2])
{
tok->ty = LS_TOK_OPERATOR;
- tok->body.oper_val = NO_OPER;
+ tok->body.oper_val = LS_NO_OP;
static const unsigned char ops[][2] = {
- [OPER_LEQ] = "<=",
- [OPER_GEQ] = ">=",
- [OPER_NEQ] = "<>",
- [OPER_LPAREN] = "(",
- [OPER_RPAREN] = ")",
- [OPER_MOD] = "%",
- [OPER_MUL] = "*",
- [OPER_ADD] = "+",
- [OPER_SUB] = "-",
- [OPER_DIV] = "/",
- [OPER_POW] = "^",
- [OPER_LT] = "<",
- [OPER_EQ] = "=",
- [OPER_GT] = ">",
+ [LS_OP_LEQ] = "<=",
+ [LS_OP_GEQ] = ">=",
+ [LS_OP_NEQ] = "<>",
+ [LS_OP_LPAREN] = "(",
+ [LS_OP_RPAREN] = ")",
+ [LS_OP_MOD] = "%",
+ [LS_OP_MUL] = "*",
+ [LS_OP_ADD] = "+",
+ [LS_OP_SUB] = "-",
+ [LS_OP_DIV] = "/",
+ [LS_OP_POW] = "^",
+ [LS_OP_LT] = "<",
+ [LS_OP_EQ] = "=",
+ [LS_OP_GT] = ">",
};
for (uint8_t i = 0; i < sizeof(ops)/sizeof(ops[0]); i++)
@@ -261,7 +261,7 @@ static void _lex_oper(ls_t * self, ls_token_t * tok, ls_uchar ch[2])
}
}
- if (tok->body.oper_val == NO_OPER)
+ if (tok->body.oper_val == LS_NO_OP)
tok->ty = LS_TOK_INVALID;
}
diff --git a/src/ls_types.h b/src/ls_types.h
index 3353a54..29d389d 100644
--- a/src/ls_types.h
+++ b/src/ls_types.h
@@ -290,41 +290,41 @@ typedef enum {
typedef enum {
// Double char
- OPER_LEQ,
- OPER_GEQ,
- OPER_NEQ,
+ LS_OP_LEQ,
+ LS_OP_GEQ,
+ LS_OP_NEQ,
// Single char
- OPER_LPAREN,
- OPER_RPAREN,
- OPER_MOD,
- OPER_MUL,
- OPER_ADD,
- OPER_SUB,
- OPER_DIV,
- OPER_POW,
- OPER_LT,
- OPER_EQ,
- OPER_GT,
+ LS_OP_LPAREN,
+ LS_OP_RPAREN,
+ LS_OP_MOD,
+ LS_OP_MUL,
+ LS_OP_ADD,
+ LS_OP_SUB,
+ LS_OP_DIV,
+ LS_OP_POW,
+ LS_OP_LT,
+ LS_OP_EQ,
+ LS_OP_GT,
// Any operators that are detected directly in text by ls_lex() should
// be located contiguously above this point, so that these enum values
// may be indices into a non-sparse lookup table.
// Virtual
- OPER_NEG, // OPER_SUB becomes OPER_NEG in context
+ LS_OP_NEG, // LS_OP_SUB becomes LS_OP_NEG in context
// Keyword
- OPER_ABS,
- OPER_NOT,
- OPER_AND,
- OPER_OR,
- OPER_XOR,
- OPER_EQV,
- OPER_IMP,
+ LS_OP_ABS,
+ LS_OP_NOT,
+ LS_OP_AND,
+ LS_OP_OR,
+ LS_OP_XOR,
+ LS_OP_EQV,
+ LS_OP_IMP,
- NO_OPER
-} ls_oper_t;
+ LS_NO_OP
+} ls_op_t;
typedef enum {
/// Integer and floating point values
@@ -378,7 +378,7 @@ typedef struct {
ls_addr_t pc_start;
ls_addr_t pc_end;
} string_val;
- ls_oper_t oper_val;
+ ls_op_t oper_val;
} body;
} ls_token_t;
diff --git a/test/test_internal.c b/test/test_internal.c
index 38c0077..56c0adf 100644
--- a/test/test_internal.c
+++ b/test/test_internal.c
@@ -38,22 +38,22 @@ DECLTEST(_ls_lex)
ls_test_setup(&ls, operstrings[i]);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_LT);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_LT);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_LEQ);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_LEQ);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_EQ);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_EQ);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_NEQ);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_NEQ);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_GEQ);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_GEQ);
ls_lex(&ls, &tok);
dammit_assert_enum(tok.ty, ==, LS_TOK_OPERATOR);
- dammit_assert_enum(tok.body.oper_val, ==, OPER_GT);
+ dammit_assert_enum(tok.body.oper_val, ==, LS_OP_GT);
}
// Numbers are done separately in _ls_parse_num