improve performance massively from 0.9 seconds to 0.38 seconds :)
This commit is contained in:
@@ -7,38 +7,43 @@
|
||||
#include "../../runtime.h"
|
||||
#include "../object.h"
|
||||
#include "../string/string.h"
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ArgonObject *ARGON_FUNCTION_TYPE = NULL;
|
||||
|
||||
ArgonObject *create_argon_native_function(char*name, native_fn native_fn) {
|
||||
ArgonObject *create_argon_native_function(char *name, native_fn native_fn) {
|
||||
ArgonObject *object = new_object();
|
||||
add_field(object, "__class__", ARGON_FUNCTION_TYPE);
|
||||
add_builtin_field(object, __class__, ARGON_FUNCTION_TYPE);
|
||||
object->type = TYPE_NATIVE_FUNCTION;
|
||||
add_field(object, "__name__", new_string_object(name, strlen(name)));
|
||||
add_builtin_field(object, __name__,
|
||||
new_string_object(name, strlen(name), 0, 0));
|
||||
object->value.native_fn = native_fn;
|
||||
return object;
|
||||
}
|
||||
|
||||
void load_argon_function(Translated *translated, RuntimeState *state,
|
||||
struct Stack *stack) {
|
||||
struct Stack *stack) {
|
||||
ArgonObject *object = new_object();
|
||||
add_field(object, "__class__", ARGON_FUNCTION_TYPE);
|
||||
add_builtin_field(object, __class__, ARGON_FUNCTION_TYPE);
|
||||
object->type = TYPE_FUNCTION;
|
||||
uint64_t offset = pop_bytecode(translated, state);
|
||||
uint64_t length = pop_bytecode(translated, state);
|
||||
add_field(object, "__name__", new_string_object(arena_get(&translated->constants, offset), length));
|
||||
add_builtin_field(object, __name__,
|
||||
new_string_object(arena_get(&translated->constants, offset),
|
||||
length, 0, 0));
|
||||
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 * sizeof(struct string_struct));
|
||||
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].data = arena_get(&translated->constants, offset);
|
||||
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);
|
||||
@@ -46,5 +51,5 @@ void load_argon_function(Translated *translated, RuntimeState *state,
|
||||
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;
|
||||
state->registers[0] = object;
|
||||
}
|
||||
Reference in New Issue
Block a user