write runtime object bootstrap

This commit is contained in:
2025-08-03 01:48:41 +01:00
parent a7d7ded803
commit 417d66faf3
15 changed files with 69 additions and 91 deletions

View File

@@ -6,6 +6,7 @@
#include "../../runtime.h"
#include "../object.h"
#include "../string/string.h"
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
@@ -13,34 +14,27 @@
ArgonObject *ARGON_FUNCTION_TYPE = NULL;
void init_function_type() {
ARGON_FUNCTION_TYPE = init_argon_class("Function");
}
void load_argon_function(Translated *translated, RuntimeState *state,
struct Stack *stack) {
ArgonObject *object = init_child_argon_object(ARGON_FUNCTION_TYPE);
ArgonObject *object = new_object();
add_field(object, "__class__", ARGON_FUNCTION_TYPE);
object->type = TYPE_FUNCTION;
uint64_t offset = pop_bytecode(translated, state);
uint64_t length = pop_bytecode(translated, state);
object->name = ar_alloc_atomic(length + 1);
memcpy(object->name, arena_get(&translated->constants, offset), length);
object->name[length] = '\0';
add_field(object, "__class__", new_string_object(arena_get(&translated->constants, offset), length));
object->value.argon_fn.number_of_parameters = pop_bytecode(translated, state);
object->value.argon_fn.parameters =
ar_alloc(object->value.argon_fn.number_of_parameters * sizeof(char *));
ar_alloc(object->value.argon_fn.number_of_parameters * sizeof(struct string_struct));
for (size_t i = 0; i < object->value.argon_fn.number_of_parameters; i++) {
offset = pop_bytecode(translated, state);
length = pop_bytecode(translated, state);
object->value.argon_fn.parameters[i] = ar_alloc_atomic(length + 1);
memcpy(object->value.argon_fn.parameters[i], arena_get(&translated->constants, offset), length);
object->value.argon_fn.parameters[i][length] = '\0';
object->value.argon_fn.parameters[i].data = arena_get(&translated->constants, offset);
object->value.argon_fn.parameters[i].length = length;
}
offset = pop_bytecode(translated, state);
length = pop_bytecode(translated, state);
darray_armem_init(&object->value.argon_fn.bytecode, sizeof(uint64_t));
darray_armem_resize(&object->value.argon_fn.bytecode, length/object->value.argon_fn.bytecode.element_size);
memcpy(object->value.argon_fn.bytecode.data, arena_get(&translated->constants, offset), length);
object->value.argon_fn.bytecode = arena_get(&translated->constants, offset);
object->value.argon_fn.bytecode_length = length;
object->value.argon_fn.stack = *stack;
state->registers[0]=object;
}