add multiplication and division

This commit is contained in:
William Bell
2025-08-19 02:36:09 +01:00
parent a96023ced1
commit c856e7d654
8 changed files with 178 additions and 48 deletions

View File

@@ -10,19 +10,22 @@ size_t translate_access(Translated *translated, ParsedAccess *access,
set_registers(translated, 1);
uint64_t first = push_instruction_byte(translated, OP_LOAD_ACCESS_FUNCTION);
push_instruction_byte(translated, OP_INIT_CALL);
push_instruction_code(translated, 3);
push_instruction_code(translated, access->access.size + 2);
translate_parsed(translated, &access->to_access, err);
push_instruction_byte(translated, OP_INSERT_ARG);
push_instruction_code(translated, 0);
translate_parsed(translated, darray_get(&access->access, 0), err);
push_instruction_byte(translated, OP_INSERT_ARG);
push_instruction_code(translated, 1);
push_instruction_byte(translated, OP_LOAD_BOOL);
push_instruction_byte(translated, access->access_fields);
push_instruction_byte(translated, OP_INSERT_ARG);
push_instruction_code(translated, 2);
push_instruction_code(translated, 1);
for (size_t i = 0; i < access->access.size; i++) {
translate_parsed(translated, darray_get(&access->access, i), err);
push_instruction_byte(translated, OP_INSERT_ARG);
push_instruction_code(translated, 2+i);
}
push_instruction_byte(translated, OP_SOURCE_LOCATION);
push_instruction_code(translated, access->line);
push_instruction_code(translated, access->column);

View File

@@ -135,4 +135,12 @@ loads the addition function into register 1
## OP_LOAD_SUBTRACTION_FUNCTION
loads the subtraction function into register 1
loads the subtraction function into register 1
## OP_LOAD_MULTIPLY_FUNCTION
loads the multiply function into register 1
## OP_LOAD_DIVISION_FUNCTION
loads the division function into register 1

View File

@@ -18,6 +18,12 @@ size_t translate_operation(Translated *translated, ParsedOperation *operation,
case TOKEN_MINUS:
first = push_instruction_byte(translated, OP_LOAD_SUBTRACTION_FUNCTION);
break;
case TOKEN_STAR:
first = push_instruction_byte(translated, OP_LOAD_MULTIPLY_FUNCTION);
break;
case TOKEN_SLASH:
first = push_instruction_byte(translated, OP_LOAD_DIVISION_FUNCTION);
break;
default:
*err = create_err(operation->line, operation->column, operation->length,
translated->path, "Syntax Error", "unknown operation");

View File

@@ -33,7 +33,9 @@ typedef enum {
OP_LOAD_BOOL,
OP_LOAD_NUMBER,
OP_LOAD_ADDITION_FUNCTION,
OP_LOAD_SUBTRACTION_FUNCTION
OP_LOAD_SUBTRACTION_FUNCTION,
OP_LOAD_MULTIPLY_FUNCTION,
OP_LOAD_DIVISION_FUNCTION
} OperationType;
void arena_resize(ConstantArena *arena, size_t new_size);