diff --git a/src/runtime/internals/hashmap/hashmap.c b/src/runtime/internals/hashmap/hashmap.c index 397178a..1b15e36 100644 --- a/src/runtime/internals/hashmap/hashmap.c +++ b/src/runtime/internals/hashmap/hashmap.c @@ -8,6 +8,7 @@ #include "../../../memory.h" #include +#include #include #include #include @@ -27,8 +28,8 @@ struct hashmap_GC *createHashmap_GC() { } static int compare_node_asc(const void *a, const void *b) { - const struct node_GC *na = (const struct node_GC *)a; - const struct node_GC *nb = (const struct node_GC *)b; + const struct node_GC *na = *((const struct node_GC **)a); + const struct node_GC *nb = *((const struct node_GC **)b); // Ascending order (smallest order first) if (na->order < nb->order) @@ -38,34 +39,34 @@ static int compare_node_asc(const void *a, const void *b) { return 0; } -void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC **array, +void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC ***array, size_t *array_length) { size_t array_size = 8; *array_length = 0; - *array = ar_alloc(array_size * sizeof(struct node_GC)); + *array = ar_alloc(array_size * sizeof(struct node_GC *)); for (size_t i = 0; i < t->inline_count; i++) { if (*array_length >= array_size) { array_size *= 2; - *array = ar_realloc(*array, array_size * sizeof(struct node_GC)); + *array = ar_realloc(*array, array_size * sizeof(struct node_GC *)); } - (*array)[(*array_length)++] = t->inline_values[i]; + (*array)[(*array_length)++] = &t->inline_values[i]; } for (size_t i = 0; i < t->size; i++) { if (*array_length >= array_size) { array_size *= 2; - *array = ar_realloc(*array, array_size * sizeof(struct node_GC)); + *array = ar_realloc(*array, array_size * sizeof(struct node_GC *)); } struct node_GC *list = t->list[i]; struct node_GC *temp = list; while (temp) { - (*array)[(*array_length)++] = *t->list[i]; + (*array)[(*array_length)++] = temp; temp = temp->next; } } - qsort(*array, *array_length, sizeof(struct node_GC), compare_node_asc); + qsort(*array, *array_length, sizeof(struct node_GC *), compare_node_asc); } void clear_hashmap_GC(struct hashmap_GC *t) { diff --git a/src/runtime/internals/hashmap/hashmap.h b/src/runtime/internals/hashmap/hashmap.h index a9b8400..1d162d3 100644 --- a/src/runtime/internals/hashmap/hashmap.h +++ b/src/runtime/internals/hashmap/hashmap.h @@ -33,8 +33,8 @@ struct hashmap_GC *createHashmap_GC(); void clear_hashmap_GC(struct hashmap_GC *t); -void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC**array, - size_t *array_length); +void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC ***array, + size_t *array_length); int hashCode_GC(struct hashmap_GC *t, uint64_t hash); diff --git a/src/runtime/objects/dictionary/dictionary.c b/src/runtime/objects/dictionary/dictionary.c index 9e164e2..3b590b2 100644 --- a/src/runtime/objects/dictionary/dictionary.c +++ b/src/runtime/objects/dictionary/dictionary.c @@ -45,7 +45,7 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc, ArgonObject *object = argv[0]; size_t string_length = 0; char *string = NULL; - struct node_GC *keys; + struct node_GC **keys; size_t keys_length; hashmap_GC_to_array(object->value.as_hashmap, &keys, &keys_length); char *string_obj = "{"; @@ -54,9 +54,9 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc, memcpy(string + string_length, string_obj, length); string_length += length; for (size_t i = 0; i < keys_length; i++) { - struct node_GC node = keys[i]; - ArgonObject *key = node.key; - ArgonObject *value = node.val; + struct node_GC* node = keys[i]; + ArgonObject *key = node->key; + ArgonObject *value = node->val; ArgonObject *string_convert_method = get_builtin_field_for_class( get_builtin_field(key, __class__), __repr__, key); diff --git a/src/shell.c b/src/shell.c index 4514050..51c8f90 100644 --- a/src/shell.c +++ b/src/shell.c @@ -91,7 +91,7 @@ void handle_sigint(int sig) { } int execute_code(FILE *stream, char *path, Stack *scope, - RuntimeState *runtime_state) { + ArgonObject * registers[UINT8_MAX], RuntimeState* runtime_state) { if (!stream) { perror("fmemopen"); return 1; @@ -150,7 +150,6 @@ int execute_code(FILE *stream, char *path, Stack *scope, translated.constants.capacity = __translated.constants.capacity; darray_free(&__translated.bytecode, NULL); free(__translated.constants.data); - ArgonObject * registers[UINT8_MAX]; *runtime_state = init_runtime_state(translated, path, registers); runtime(translated, *runtime_state, scope, &err); if (err.exists) { @@ -212,13 +211,14 @@ char *read_all_stdin(size_t *out_len) { int shell() { Stack *main_scope = create_scope(Global_Scope, true); + ArgonObject * registers[UINT8_MAX]; if (!isatty(STDIN_FILENO)) { RuntimeState runtime_state; size_t len; char *data = read_all_stdin(&len); FILE *file = fmemopen(data, len, "r"); - int resp = execute_code(file, "", main_scope, &runtime_state); + int resp = execute_code(file, "", main_scope, registers, &runtime_state); fclose(file); free(data); return resp; @@ -308,12 +308,12 @@ int shell() { totranslate[totranslatelength] = '\0'; RuntimeState runtime_state; FILE *file = fmemopen((void *)totranslate, totranslatelength, "r"); - int resp = execute_code(file, "", main_scope, &runtime_state); + int resp = execute_code(file, "", main_scope, registers, &runtime_state); fclose(file); if (resp) { continue; } - if (runtime_state.registers[0]&&runtime_state.registers[0] != ARGON_NULL) { + if (registers[0]&®isters[0] != ARGON_NULL) { ArErr err = no_err; argon_call(output_object, 1, (ArgonObject *[]){runtime_state.registers[0]}, &err, diff --git a/tests/hashmap_order.ar b/tests/hashmap_order.ar index 7971e77..f17d814 100644 --- a/tests/hashmap_order.ar +++ b/tests/hashmap_order.ar @@ -5,9 +5,19 @@ x.c = 3 x.a = 7 term.log(x) -let y = {'p':1} -y.z = 1 +let y = {} +y.a = 1 y.b = 2 y.c = 3 -y.a = 7 +y.d = 7 +y.e = 2 +y.f = 3 +y.g = 7 +y.h = 1 +y.i = 2 +y.j = 3 +y.k = 7 +y.l = 2 +y.m = 3 +y.n = 7 term.log(y) \ No newline at end of file diff --git a/tests/iteration-test.ar b/tests/iteration-test.ar index 7d2094d..57dcb71 100644 --- a/tests/iteration-test.ar +++ b/tests/iteration-test.ar @@ -1,4 +1,5 @@ -term.log(global) +#term.log(global) let i = 1e7 while (i) do - i=i-1 \ No newline at end of file + i=i-1 + term.log(i) \ No newline at end of file