set up so reusing scope when in a loop

This commit is contained in:
William Bell
2025-09-01 23:09:09 +01:00
parent 322716af0c
commit fd5b237dfe
10 changed files with 25 additions and 6 deletions

View File

@@ -21,9 +21,16 @@ struct hashmap_GC *createHashmap_GC() {
t->order = 1;
t->list = (struct node_GC **)ar_alloc(sizeof(struct node_GC *) * size);
memset(t->list, 0, sizeof(struct node_GC *) * size);
t->count = 0;
return t;
}
void clear_hashmap_GC(struct hashmap_GC *t) {
t->order = 1;
t->count = 0;
memset(t->list, 0, sizeof(struct node_GC *) * t->size);
}
void resize_hashmap_GC(struct hashmap_GC *t) {
int old_size = t->size;
int new_size = old_size * 2;

View File

@@ -25,6 +25,8 @@ struct hashmap_GC {
struct hashmap_GC *createHashmap_GC();
void clear_hashmap_GC(struct hashmap_GC *t);
int hashCode_GC(struct hashmap_GC *t, uint64_t hash);
int hashmap_remove_GC(struct hashmap_GC *t, uint64_t hash);

View File

@@ -20,7 +20,7 @@ const char *built_in_field_names[BUILT_IN_FIELDS_COUNT] = {
"__string__", "__subtract__", "__multiply__", "__division__",
"__new__", "__init__", "__boolean__", "__get_attr__",
"__binding__", "__function__", "address", "__call__",
"__number__", "log"};
"__number__", "log", "length"};
uint64_t built_in_field_hashes[BUILT_IN_FIELDS_COUNT];

View File

@@ -30,6 +30,7 @@ typedef enum {
__call__,
__number__,
field_log,
field_length,
BUILT_IN_FIELDS_COUNT
} built_in_fields;

View File

@@ -17,7 +17,7 @@ ArgonObject *new_string_object(char *data, size_t length, uint64_t prehash,
uint64_t hash) {
ArgonObject *object = new_object();
add_builtin_field(object, __class__, ARGON_STRING_TYPE);
add_builtin_field(object, length,
add_builtin_field(object, field_length,
new_number_object_from_num_and_den(length, 1));
object->type = TYPE_STRING;
object->value.as_str.data = ar_alloc_atomic(length);

View File

@@ -683,6 +683,7 @@ static inline void run_instructions(Translated *translated, RuntimeState *state,
[OP_JUMP_IF_FALSE] = &&DO_JUMP_IF_FALSE,
[OP_JUMP] = &&DO_JUMP,
[OP_NEW_SCOPE] = &&DO_NEW_SCOPE,
[OP_EMPTY_SCOPE] = &&DO_EMPTY_SCOPE,
[OP_POP_SCOPE] = &&DO_POP_SCOPE,
[OP_INIT_CALL] = &&DO_INIT_CALL,
[OP_INSERT_ARG] = &&DO_INSERT_ARG,
@@ -745,6 +746,9 @@ DO_JUMP:
DO_NEW_SCOPE:
*stack = create_scope(*stack);
goto START;
DO_EMPTY_SCOPE:
clear_hashmap_GC((*stack)->scope);
goto START;
DO_POP_SCOPE:
*stack = (*stack)->prev;
goto START;