attempt to remove redundent memory allocations
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
term.log(a()=10)
|
||||
term.log(b(x)=10)
|
||||
term.log(c(x,y)=10)
|
||||
term.log(d(x,y,z)=10)
|
||||
@@ -4,3 +4,10 @@ x.b = 2
|
||||
x.c = 3
|
||||
x.a = 7
|
||||
term.log(x)
|
||||
|
||||
let y = {'p':1}
|
||||
y.z = 1
|
||||
y.b = 2
|
||||
y.c = 3
|
||||
y.a = 7
|
||||
term.log(y)
|
||||
Reference in New Issue
Block a user