diff --git a/src/import.c b/src/import.c index a455e8b..280f604 100644 --- a/src/import.c +++ b/src/import.c @@ -400,7 +400,7 @@ Translated load_argon_file(char *path, ArErr *err) { Translated gc_translated = { translated.registerCount, translated.registerAssignment, NULL, {}, {}, translated.path}; - gc_translated.bytecode.data = ar_alloc_atomic(translated.bytecode.capacity); + gc_translated.bytecode.data = ar_alloc_atomic(translated.bytecode.capacity+translated.constants.capacity); memcpy(gc_translated.bytecode.data, translated.bytecode.data, translated.bytecode.capacity); gc_translated.bytecode.element_size = translated.bytecode.element_size; @@ -408,7 +408,7 @@ Translated load_argon_file(char *path, ArErr *err) { gc_translated.bytecode.resizable = false; gc_translated.bytecode.capacity = translated.bytecode.size * translated.bytecode.element_size; - gc_translated.constants.data = ar_alloc_atomic(translated.constants.capacity); + gc_translated.constants.data = gc_translated.bytecode.data+translated.bytecode.capacity; memcpy(gc_translated.constants.data, translated.constants.data, translated.constants.capacity); gc_translated.constants.size = translated.constants.size; @@ -453,7 +453,8 @@ Stack *ar_import(char *current_directory, char *path_relative, ArErr *err) { return NULL; } clock_t start = clock(), end; - RuntimeState state = init_runtime_state(translated, path); + ArgonObject * registers[UINT8_MAX]; + RuntimeState state = init_runtime_state(translated, path, registers); Stack *main_scope = create_scope(Global_Scope, true); runtime(translated, state, main_scope, err); if (err->exists) { diff --git a/src/runtime/call/call.c b/src/runtime/call/call.c index 3e28f7a..bb13419 100644 --- a/src/runtime/call/call.c +++ b/src/runtime/call/call.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,7 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv, 0); } if (CStackFrame) { + ArgonObject * registers[UINT8_MAX]; StackFrame new_stackFrame = { {object->value.argon_fn->translated.registerCount, object->value.argon_fn->translated.registerAssignment, @@ -142,8 +144,7 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv, object->value.argon_fn->bytecode_length, false}, object->value.argon_fn->translated.constants, object->value.argon_fn->translated.path}, - {ar_alloc(object->value.argon_fn->translated.registerCount * - sizeof(ArgonObject *)), + {registers, 0, object->value.argon_fn->translated.path, NULL, @@ -160,7 +161,8 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv, new_stackFrame.stack, err); state->registers[0] = new_stackFrame.state.registers[0]; } else { - StackFrame *currentStackFrame = ar_alloc(sizeof(StackFrame)); + StackFrame *currentStackFrame = ar_alloc(sizeof(StackFrame)+object->value.argon_fn->translated.registerCount * + sizeof(ArgonObject *)); *currentStackFrame = (StackFrame){ {object->value.argon_fn->translated.registerCount, object->value.argon_fn->translated.registerAssignment, @@ -170,8 +172,7 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv, object->value.argon_fn->bytecode_length, false}, object->value.argon_fn->translated.constants, object->value.argon_fn->translated.path}, - {ar_alloc(object->value.argon_fn->translated.registerCount * - sizeof(ArgonObject *)), + {(ArgonObject **)((char*)currentStackFrame+sizeof(StackFrame)), 0, object->value.argon_fn->translated.path, NULL, diff --git a/src/runtime/objects/functions/functions.c b/src/runtime/objects/functions/functions.c index eff8b94..68f69f9 100644 --- a/src/runtime/objects/functions/functions.c +++ b/src/runtime/objects/functions/functions.c @@ -32,12 +32,12 @@ void load_argon_function(Translated *translated, RuntimeState *state, add_builtin_field(object, __name__, new_string_object(arena_get(&translated->constants, offset), length, 0, 0)); - object->value.argon_fn = ar_alloc(sizeof(struct argon_function_struct)); - object->value.argon_fn->translated = *translated; - 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 * + uint64_t number_of_parameters = pop_bytecode(translated, state); + object->value.argon_fn = ar_alloc(sizeof(struct argon_function_struct)+number_of_parameters * sizeof(struct string_struct)); + object->value.argon_fn->parameters = (struct string_struct*)((char*)object->value.argon_fn+sizeof(struct argon_function_struct)); + object->value.argon_fn->translated = *translated; + object->value.argon_fn->number_of_parameters = number_of_parameters; for (size_t i = 0; i < object->value.argon_fn->number_of_parameters; i++) { offset = pop_bytecode(translated, state); length = pop_bytecode(translated, state); diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 6b5382f..5fb4d68 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -826,9 +826,9 @@ static inline void load_variable(Translated *translated, RuntimeState *state, return; } -RuntimeState init_runtime_state(Translated translated, char *path) { +RuntimeState init_runtime_state(Translated translated, char *path, ArgonObject * registers[UINT8_MAX]) { RuntimeState runtime = { - ar_alloc(translated.registerCount * sizeof(ArgonObject *)), + registers, 0, path, NULL, diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 6f91226..933cf4a 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -85,7 +85,7 @@ static inline uint64_t pop_bytecode(Translated *translated, static inline void run_instruction(Translated *translated, RuntimeState *state, struct Stack **stack, ArErr *err); -RuntimeState init_runtime_state(Translated translated, char *path); +RuntimeState init_runtime_state(Translated translated, char *path, ArgonObject * registers[UINT8_MAX]); Stack *create_scope(Stack *prev, bool force); diff --git a/src/shell.c b/src/shell.c index 095c499..4514050 100644 --- a/src/shell.c +++ b/src/shell.c @@ -150,7 +150,8 @@ int execute_code(FILE *stream, char *path, Stack *scope, translated.constants.capacity = __translated.constants.capacity; darray_free(&__translated.bytecode, NULL); free(__translated.constants.data); - *runtime_state = init_runtime_state(translated, path); + ArgonObject * registers[UINT8_MAX]; + *runtime_state = init_runtime_state(translated, path, registers); runtime(translated, *runtime_state, scope, &err); if (err.exists) { output_err(err); diff --git a/tests/anonymous_function.ar b/tests/anonymous_function.ar index 9ddfe45..8cb0ada 100644 --- a/tests/anonymous_function.ar +++ b/tests/anonymous_function.ar @@ -1,4 +1,9 @@ +term.log("hello world") term.log(()=10) term.log((x)=10) term.log((x,y)=10) -term.log((x,y,z)=10) \ No newline at end of file +term.log((x,y,z)=10) +term.log(a()=10) +term.log(b(x)=10) +term.log(c(x,y)=10) +term.log(d(x,y,z)=10) \ No newline at end of file diff --git a/tests/hashmap_order.ar b/tests/hashmap_order.ar index 65f57e7..7971e77 100644 --- a/tests/hashmap_order.ar +++ b/tests/hashmap_order.ar @@ -3,4 +3,11 @@ x.z = 1 x.b = 2 x.c = 3 x.a = 7 -term.log(x) \ No newline at end of file +term.log(x) + +let y = {'p':1} +y.z = 1 +y.b = 2 +y.c = 3 +y.a = 7 +term.log(y) \ No newline at end of file