aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
Diffstat (limited to 'asm')
-rw-r--r--asm/lexer.c21
-rw-r--r--asm/lexer.h3
-rw-r--r--asm/parser.c24
3 files changed, 25 insertions, 23 deletions
diff --git a/asm/lexer.c b/asm/lexer.c
index 836dd08..73859c3 100644
--- a/asm/lexer.c
+++ b/asm/lexer.c
@@ -86,8 +86,10 @@ const char *token_type_as_cstr(token_type_t type)
return "MULT";
case TOKEN_PRINT:
return "PRINT";
- case TOKEN_JUMP:
- return "JUMP";
+ case TOKEN_JUMP_ABS:
+ return "JUMP_ABS";
+ case TOKEN_JUMP_STACK:
+ return "JUMP_STACK";
case TOKEN_JUMP_IF:
return "JUMP_IF";
case TOKEN_SYMBOL:
@@ -293,16 +295,21 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column)
offset = 5;
type = TOKEN_PRINT;
}
+ else if (sym_size >= 8 && strncmp(opcode, "JUMP.ABS", 8) == 0)
+ {
+ offset = 8;
+ type = TOKEN_JUMP_ABS;
+ }
+ else if (sym_size >= 10 && strncmp(opcode, "JUMP.STACK", 10) == 0)
+ {
+ offset = 10;
+ type = TOKEN_JUMP_STACK;
+ }
else if (sym_size >= 7 && strncmp(opcode, "JUMP.IF", 7) == 0)
{
offset = 7;
type = TOKEN_JUMP_IF;
}
- else if (sym_size >= 4 && strncmp(opcode, "JUMP", 4) == 0)
- {
- offset = 4;
- type = TOKEN_JUMP;
- }
else
is_opcode = false;
diff --git a/asm/lexer.h b/asm/lexer.h
index 2d747bc..687e1a6 100644
--- a/asm/lexer.h
+++ b/asm/lexer.h
@@ -48,7 +48,8 @@ typedef enum TokenType
TOKEN_SUB,
TOKEN_MULT,
TOKEN_PRINT,
- TOKEN_JUMP,
+ TOKEN_JUMP_ABS,
+ TOKEN_JUMP_STACK,
TOKEN_JUMP_IF,
TOKEN_SYMBOL,
} token_type_t;
diff --git a/asm/parser.c b/asm/parser.c
index da0c93c..44c09b4 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -404,22 +404,16 @@ perr_t parse_next(token_stream_t *stream, presult_t *ret)
.type = PRES_COMPLETE_RESULT};
perr = parse_type_inst(stream, &ret->instruction);
break;
- case TOKEN_JUMP: {
- if (token.str_size == 4 && strncmp(token.str, ".ABS", 4) == 0)
- {
- *ret = (presult_t){.instruction = INST_JUMP_ABS(0)};
- ++stream->used;
- if (stream->used >= stream->available)
- return PERR_EXPECTED_OPERAND;
- return parse_word_label_or_relative(stream, ret);
- }
- else if (token.str_size == 6 && strncmp(token.str, ".STACK", 6) == 0)
- *ret = (presult_t){.instruction = INST_JUMP_STACK,
- .type = PRES_COMPLETE_RESULT};
- else
- return PERR_UNKNOWN_OPERATOR;
+ case TOKEN_JUMP_ABS:
+ *ret = (presult_t){.instruction = INST_JUMP_ABS(0)};
+ ++stream->used;
+ if (stream->used >= stream->available)
+ return PERR_EXPECTED_OPERAND;
+ return parse_word_label_or_relative(stream, ret);
+ case TOKEN_JUMP_STACK:
+ *ret = (presult_t){.instruction = INST_JUMP_STACK,
+ .type = PRES_COMPLETE_RESULT};
break;
- }
case TOKEN_JUMP_IF: {
*ret = (presult_t){.instruction = INST_JUMP_IF(BYTE, 0)};
return parse_jump_inst_operand(stream, ret);