turn access into a function to be ran at runtime
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "../../memory.h"
|
||||
#include "type/type.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -16,6 +17,7 @@ ArgonObject *BASE_CLASS = NULL;
|
||||
|
||||
ArgonObject *new_object() {
|
||||
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
|
||||
object->type = TYPE_OBJECT;
|
||||
object->dict = createHashmap_GC();
|
||||
add_field(object, "__class__", ARGON_TYPE_TYPE);
|
||||
return object;
|
||||
@@ -40,38 +42,48 @@ ArgonObject *bind_object_to_function(ArgonObject *object,
|
||||
return bound_method_wrapper;
|
||||
}
|
||||
|
||||
ArgonObject *get_field_for_class(ArgonObject *target, char *name,
|
||||
ArgonObject *binding_object) {
|
||||
ArgonObject *get_field_for_class_l(ArgonObject *target, char *name,
|
||||
size_t length, ArgonObject *binding_object) {
|
||||
char *field = "__base__";
|
||||
size_t field_size = strlen(field);
|
||||
while (target) {
|
||||
uint64_t hash = siphash64_bytes(name, strlen(name), siphash_key);
|
||||
ArgonObject *object = hashmap_lookup_GC(target->dict, hash);
|
||||
|
||||
ArgonObject *object = get_field_l(target, name, length, false, false);
|
||||
if (object) {
|
||||
if ((object->type == TYPE_FUNCTION ||
|
||||
object->type == TYPE_NATIVE_FUNCTION) && binding_object) {
|
||||
object->type == TYPE_NATIVE_FUNCTION) &&
|
||||
binding_object) {
|
||||
object = bind_object_to_function(binding_object, object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
hash = siphash64_bytes(field, strlen(field), siphash_key);
|
||||
target = hashmap_lookup_GC(target->dict, hash);
|
||||
target = get_field_l(target, field, field_size, false, false);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ArgonObject *get_field(ArgonObject *target, char *name, bool recursive,
|
||||
bool disable_method_wrapper) {
|
||||
ArgonObject *get_field_l(ArgonObject *target, char *name, size_t length,
|
||||
bool recursive, bool disable_method_wrapper) {
|
||||
char *field = "__class__";
|
||||
size_t field_size = strlen(field);
|
||||
ArgonObject *object = hashmap_lookup_GC(
|
||||
target->dict, siphash64_bytes(name, strlen(name), siphash_key));
|
||||
target->dict, siphash64_bytes(name, length, siphash_key));
|
||||
if (!recursive || object)
|
||||
return object;
|
||||
ArgonObject *binding = target;
|
||||
if (disable_method_wrapper)
|
||||
binding = NULL;
|
||||
return get_field_for_class(
|
||||
return get_field_for_class_l(
|
||||
hashmap_lookup_GC(target->dict,
|
||||
siphash64_bytes(field, strlen(field), siphash_key)),
|
||||
name, binding);
|
||||
siphash64_bytes(field, field_size, siphash_key)),
|
||||
name, length, binding);
|
||||
}
|
||||
|
||||
ArgonObject *get_field(ArgonObject *target, char *name, bool recursive,
|
||||
bool disable_method_wrapper) {
|
||||
return get_field_l(target, name, strlen(name), recursive,
|
||||
disable_method_wrapper);
|
||||
}
|
||||
ArgonObject *get_field_for_class(ArgonObject *target, char *name,
|
||||
ArgonObject *binding_object) {
|
||||
return get_field_for_class_l(target, name, strlen(name), binding_object);
|
||||
}
|
||||
Reference in New Issue
Block a user