Implemented CALL(_STACK) and RET on the assembler
This commit is contained in:
23
asm/lexer.c
23
asm/lexer.c
@@ -92,6 +92,12 @@ const char *token_type_as_cstr(token_type_t type)
|
|||||||
return "JUMP_STACK";
|
return "JUMP_STACK";
|
||||||
case TOKEN_JUMP_IF:
|
case TOKEN_JUMP_IF:
|
||||||
return "JUMP_IF";
|
return "JUMP_IF";
|
||||||
|
case TOKEN_CALL:
|
||||||
|
return "CALL";
|
||||||
|
case TOKEN_CALL_STACK:
|
||||||
|
return "CALL_STACK";
|
||||||
|
case TOKEN_RET:
|
||||||
|
return "RET";
|
||||||
case TOKEN_SYMBOL:
|
case TOKEN_SYMBOL:
|
||||||
return "SYMBOL";
|
return "SYMBOL";
|
||||||
}
|
}
|
||||||
@@ -139,7 +145,7 @@ bool is_valid_hex_char(char c)
|
|||||||
|
|
||||||
token_t tokenise_symbol(buffer_t *buffer, size_t *column)
|
token_t tokenise_symbol(buffer_t *buffer, size_t *column)
|
||||||
{
|
{
|
||||||
static_assert(NUMBER_OF_OPCODES == 95, "tokenise_buffer: Out of date!");
|
static_assert(NUMBER_OF_OPCODES == 98, "tokenise_buffer: Out of date!");
|
||||||
|
|
||||||
size_t sym_size = 0;
|
size_t sym_size = 0;
|
||||||
for (; sym_size < space_left(buffer) &&
|
for (; sym_size < space_left(buffer) &&
|
||||||
@@ -310,6 +316,21 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column)
|
|||||||
offset = 8;
|
offset = 8;
|
||||||
type = TOKEN_JUMP_IF;
|
type = TOKEN_JUMP_IF;
|
||||||
}
|
}
|
||||||
|
else if (sym_size == 10 && strncmp(opcode, "CALL.STACK", 10) == 0)
|
||||||
|
{
|
||||||
|
offset = 10;
|
||||||
|
type = TOKEN_CALL_STACK;
|
||||||
|
}
|
||||||
|
else if (sym_size == 4 && strncmp(opcode, "CALL", 4) == 0)
|
||||||
|
{
|
||||||
|
offset = 4;
|
||||||
|
type = TOKEN_CALL;
|
||||||
|
}
|
||||||
|
else if (sym_size == 3 && strncmp(opcode, "RET", 3) == 0)
|
||||||
|
{
|
||||||
|
offset = 3;
|
||||||
|
type = TOKEN_RET;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
is_opcode = false;
|
is_opcode = false;
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ typedef enum TokenType
|
|||||||
TOKEN_JUMP_ABS,
|
TOKEN_JUMP_ABS,
|
||||||
TOKEN_JUMP_STACK,
|
TOKEN_JUMP_STACK,
|
||||||
TOKEN_JUMP_IF,
|
TOKEN_JUMP_IF,
|
||||||
|
TOKEN_CALL,
|
||||||
|
TOKEN_CALL_STACK,
|
||||||
|
TOKEN_RET,
|
||||||
TOKEN_SYMBOL,
|
TOKEN_SYMBOL,
|
||||||
} token_type_t;
|
} token_type_t;
|
||||||
|
|
||||||
|
|||||||
13
asm/parser.c
13
asm/parser.c
@@ -418,6 +418,19 @@ perr_t parse_next(token_stream_t *stream, presult_t *ret)
|
|||||||
*ret = (presult_t){.instruction = INST_JUMP_IF(BYTE, 0)};
|
*ret = (presult_t){.instruction = INST_JUMP_IF(BYTE, 0)};
|
||||||
return parse_jump_inst_operand(stream, ret);
|
return parse_jump_inst_operand(stream, ret);
|
||||||
}
|
}
|
||||||
|
case TOKEN_CALL:
|
||||||
|
*ret = (presult_t){.instruction = INST_CALL(0)};
|
||||||
|
++stream->used;
|
||||||
|
if (stream->used >= stream->available)
|
||||||
|
return PERR_EXPECTED_OPERAND;
|
||||||
|
return parse_word_label_or_relative(stream, ret);
|
||||||
|
case TOKEN_CALL_STACK:
|
||||||
|
*ret = (presult_t){.instruction = INST_CALL_STACK,
|
||||||
|
.type = PRES_COMPLETE_RESULT};
|
||||||
|
break;
|
||||||
|
case TOKEN_RET:
|
||||||
|
*ret = (presult_t){.instruction = INST_RET, .type = PRES_COMPLETE_RESULT};
|
||||||
|
break;
|
||||||
case TOKEN_SYMBOL: {
|
case TOKEN_SYMBOL: {
|
||||||
size_t label_size = strcspn(token.str, ":");
|
size_t label_size = strcspn(token.str, ":");
|
||||||
if (label_size == strlen(token.str))
|
if (label_size == strlen(token.str))
|
||||||
|
|||||||
Reference in New Issue
Block a user