add if statement and declaration

This commit is contained in:
2025-07-13 03:34:31 +01:00
parent 744e3c281d
commit f7ff3393f0
36 changed files with 587 additions and 165 deletions

View File

@@ -0,0 +1,18 @@
#include "declaration.h"
ArErr runtime_declaration(Translated *translated, RuntimeState *state,
struct Stack *stack) {
int64_t length = pop_bytecode(translated, state);
int64_t offset = pop_bytecode(translated, state);
int64_t prehash = pop_bytecode(translated, state);
int64_t from_register = pop_byte(translated, state);
int64_t source_location_index = pop_bytecode(translated, state);
uint64_t hash = runtime_hash(arena_get(&translated->constants, offset), length, prehash);
ArgonObject * exists = hashmap_lookup_GC(stack->scope, hash);
if (exists) {
SourceLocation *source_location = darray_get(&translated->source_locations, source_location_index);
return create_err(source_location->line, source_location->column, source_location->length, state->path, "Runtime Error", "Identifier '%.*s' has already been declared in the current scope", length, arena_get(&translated->constants, offset));
}
hashmap_insert_GC(stack->scope, hash, arena_get(&translated->constants, offset), state->registers[from_register], 0);
return no_err;
}