fix bug where it hashmap output bug

This commit is contained in:
William Bell
2025-11-11 02:00:17 +00:00
parent bfaf8df0d0
commit 434b0ed99e
6 changed files with 37 additions and 25 deletions

View File

@@ -8,6 +8,7 @@
#include "../../../memory.h" #include "../../../memory.h"
#include <gc/gc.h> #include <gc/gc.h>
#include <inttypes.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -27,8 +28,8 @@ struct hashmap_GC *createHashmap_GC() {
} }
static int compare_node_asc(const void *a, const void *b) { 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 *na = *((const struct node_GC **)a);
const struct node_GC *nb = (const struct node_GC *)b; const struct node_GC *nb = *((const struct node_GC **)b);
// Ascending order (smallest order first) // Ascending order (smallest order first)
if (na->order < nb->order) if (na->order < nb->order)
@@ -38,34 +39,34 @@ static int compare_node_asc(const void *a, const void *b) {
return 0; 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_length) {
size_t array_size = 8; size_t array_size = 8;
*array_length = 0; *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++) { for (size_t i = 0; i < t->inline_count; i++) {
if (*array_length >= array_size) { if (*array_length >= array_size) {
array_size *= 2; 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++) { for (size_t i = 0; i < t->size; i++) {
if (*array_length >= array_size) { if (*array_length >= array_size) {
array_size *= 2; 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 *list = t->list[i];
struct node_GC *temp = list; struct node_GC *temp = list;
while (temp) { while (temp) {
(*array)[(*array_length)++] = *t->list[i]; (*array)[(*array_length)++] = temp;
temp = temp->next; 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) { void clear_hashmap_GC(struct hashmap_GC *t) {

View File

@@ -33,7 +33,7 @@ struct hashmap_GC *createHashmap_GC();
void clear_hashmap_GC(struct hashmap_GC *t); void clear_hashmap_GC(struct hashmap_GC *t);
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_length);
int hashCode_GC(struct hashmap_GC *t, uint64_t hash); int hashCode_GC(struct hashmap_GC *t, uint64_t hash);

View File

@@ -45,7 +45,7 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc,
ArgonObject *object = argv[0]; ArgonObject *object = argv[0];
size_t string_length = 0; size_t string_length = 0;
char *string = NULL; char *string = NULL;
struct node_GC *keys; struct node_GC **keys;
size_t keys_length; size_t keys_length;
hashmap_GC_to_array(object->value.as_hashmap, &keys, &keys_length); hashmap_GC_to_array(object->value.as_hashmap, &keys, &keys_length);
char *string_obj = "{"; char *string_obj = "{";
@@ -54,9 +54,9 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc,
memcpy(string + string_length, string_obj, length); memcpy(string + string_length, string_obj, length);
string_length += length; string_length += length;
for (size_t i = 0; i < keys_length; i++) { for (size_t i = 0; i < keys_length; i++) {
struct node_GC node = keys[i]; struct node_GC* node = keys[i];
ArgonObject *key = node.key; ArgonObject *key = node->key;
ArgonObject *value = node.val; ArgonObject *value = node->val;
ArgonObject *string_convert_method = get_builtin_field_for_class( ArgonObject *string_convert_method = get_builtin_field_for_class(
get_builtin_field(key, __class__), __repr__, key); get_builtin_field(key, __class__), __repr__, key);

View File

@@ -91,7 +91,7 @@ void handle_sigint(int sig) {
} }
int execute_code(FILE *stream, char *path, Stack *scope, int execute_code(FILE *stream, char *path, Stack *scope,
RuntimeState *runtime_state) { ArgonObject * registers[UINT8_MAX], RuntimeState* runtime_state) {
if (!stream) { if (!stream) {
perror("fmemopen"); perror("fmemopen");
return 1; return 1;
@@ -150,7 +150,6 @@ int execute_code(FILE *stream, char *path, Stack *scope,
translated.constants.capacity = __translated.constants.capacity; translated.constants.capacity = __translated.constants.capacity;
darray_free(&__translated.bytecode, NULL); darray_free(&__translated.bytecode, NULL);
free(__translated.constants.data); free(__translated.constants.data);
ArgonObject * registers[UINT8_MAX];
*runtime_state = init_runtime_state(translated, path, registers); *runtime_state = init_runtime_state(translated, path, registers);
runtime(translated, *runtime_state, scope, &err); runtime(translated, *runtime_state, scope, &err);
if (err.exists) { if (err.exists) {
@@ -212,13 +211,14 @@ char *read_all_stdin(size_t *out_len) {
int shell() { int shell() {
Stack *main_scope = create_scope(Global_Scope, true); Stack *main_scope = create_scope(Global_Scope, true);
ArgonObject * registers[UINT8_MAX];
if (!isatty(STDIN_FILENO)) { if (!isatty(STDIN_FILENO)) {
RuntimeState runtime_state; RuntimeState runtime_state;
size_t len; size_t len;
char *data = read_all_stdin(&len); char *data = read_all_stdin(&len);
FILE *file = fmemopen(data, len, "r"); FILE *file = fmemopen(data, len, "r");
int resp = execute_code(file, "<stdin>", main_scope, &runtime_state); int resp = execute_code(file, "<stdin>", main_scope, registers, &runtime_state);
fclose(file); fclose(file);
free(data); free(data);
return resp; return resp;
@@ -308,12 +308,12 @@ int shell() {
totranslate[totranslatelength] = '\0'; totranslate[totranslatelength] = '\0';
RuntimeState runtime_state; RuntimeState runtime_state;
FILE *file = fmemopen((void *)totranslate, totranslatelength, "r"); FILE *file = fmemopen((void *)totranslate, totranslatelength, "r");
int resp = execute_code(file, "<shell>", main_scope, &runtime_state); int resp = execute_code(file, "<shell>", main_scope, registers, &runtime_state);
fclose(file); fclose(file);
if (resp) { if (resp) {
continue; continue;
} }
if (runtime_state.registers[0]&&runtime_state.registers[0] != ARGON_NULL) { if (registers[0]&&registers[0] != ARGON_NULL) {
ArErr err = no_err; ArErr err = no_err;
argon_call(output_object, 1, argon_call(output_object, 1,
(ArgonObject *[]){runtime_state.registers[0]}, &err, (ArgonObject *[]){runtime_state.registers[0]}, &err,

View File

@@ -5,9 +5,19 @@ x.c = 3
x.a = 7 x.a = 7
term.log(x) term.log(x)
let y = {'p':1} let y = {}
y.z = 1 y.a = 1
y.b = 2 y.b = 2
y.c = 3 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) term.log(y)

View File

@@ -1,4 +1,5 @@
term.log(global) #term.log(global)
let i = 1e7 let i = 1e7
while (i) do while (i) do
i=i-1 i=i-1
term.log(i)