add subtract support and string concatenation

This commit is contained in:
William Bell
2025-08-15 05:41:26 +01:00
parent c3c7f1597e
commit 2d577594fc
12 changed files with 156 additions and 21 deletions

View File

@@ -131,4 +131,8 @@ loads a mpq_t number into memory
## OP_LOAD_ADDITION_FUNCTION
loads the addition function into register 1
loads the addition function into register 1
## OP_LOAD_SUBTRACTION_FUNCTION
loads the subtraction function into register 1

View File

@@ -8,18 +8,20 @@
#include <stddef.h>
size_t translate_operation(Translated *translated, ParsedOperation *operation,
ArErr *err) {
ArErr *err) {
set_registers(translated, 1);
uint64_t first;
switch (operation->operation) {
case TOKEN_PLUS:;
first = push_instruction_byte(translated, OP_LOAD_ADDITION_FUNCTION);
break;
default:
*err = create_err(operation->line, operation->column,
operation->length, translated->path, "Syntax Error",
"unknown operation");
return 0;
case TOKEN_PLUS:;
first = push_instruction_byte(translated, OP_LOAD_ADDITION_FUNCTION);
break;
case TOKEN_MINUS:
first = push_instruction_byte(translated, OP_LOAD_SUBTRACTION_FUNCTION);
break;
default:
*err = create_err(operation->line, operation->column, operation->length,
translated->path, "Syntax Error", "unknown operation");
return 0;
}
push_instruction_byte(translated, OP_INIT_CALL);
push_instruction_code(translated, operation->to_operate_on.size);

View File

@@ -135,6 +135,11 @@ size_t translate_parsed(Translated *translated, ParsedValue *parsedValue,
size_t output = push_instruction_byte(translated, OP_LOAD_NULL);
push_instruction_byte(translated, 0);
return output;
case AST_BOOLEAN:
set_registers(translated, 1);
output = push_instruction_byte(translated, OP_LOAD_BOOL);
push_instruction_byte(translated, (bool)parsedValue->data);
return output;
case AST_FUNCTION:
return translate_parsed_function(translated,
(ParsedFunction *)parsedValue->data, err);

View File

@@ -32,7 +32,8 @@ typedef enum {
OP_LOAD_ACCESS_FUNCTION,
OP_LOAD_BOOL,
OP_LOAD_NUMBER,
OP_LOAD_ADDITION_FUNCTION
OP_LOAD_ADDITION_FUNCTION,
OP_LOAD_SUBTRACTION_FUNCTION
} OperationType;
void arena_resize(ConstantArena *arena, size_t new_size);