diff --git a/src/import.c b/src/import.c index 280f604..fc10a08 100644 --- a/src/import.c +++ b/src/import.c @@ -453,8 +453,7 @@ Stack *ar_import(char *current_directory, char *path_relative, ArErr *err) { return NULL; } clock_t start = clock(), end; - ArgonObject * registers[UINT8_MAX]; - RuntimeState state = init_runtime_state(translated, path, registers); + RuntimeState state = init_runtime_state(translated, path); Stack *main_scope = create_scope(Global_Scope, true); runtime(translated, state, main_scope, err); if (err->exists) { diff --git a/src/runtime/call/call.c b/src/runtime/call/call.c index bb13419..6efcff1 100644 --- a/src/runtime/call/call.c +++ b/src/runtime/call/call.c @@ -134,7 +134,7 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv, 0); } if (CStackFrame) { - ArgonObject * registers[UINT8_MAX]; + ArgonObject * registers[MAX_REGISTERS]; // fixed on the stack for speed purposes StackFrame new_stackFrame = { {object->value.argon_fn->translated.registerCount, object->value.argon_fn->translated.registerAssignment, diff --git a/src/runtime/objects/dictionary/dictionary.c b/src/runtime/objects/dictionary/dictionary.c index 3b590b2..18d28f0 100644 --- a/src/runtime/objects/dictionary/dictionary.c +++ b/src/runtime/objects/dictionary/dictionary.c @@ -55,9 +55,13 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc, string_length += length; for (size_t i = 0; i < keys_length; i++) { struct node_GC* node = keys[i]; + if (!node) { fprintf(stderr, "NULL node at %zu\n", i); continue; } ArgonObject *key = node->key; ArgonObject *value = node->val; + if (!key) { fprintf(stderr, "NULL key at node %zu\n", i); continue; } + if (!value) { fprintf(stderr, "NULL value at node %zu\n", i); continue; } + ArgonObject *string_convert_method = get_builtin_field_for_class( get_builtin_field(key, __class__), __repr__, key); diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 5fb4d68..6b5382f 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -826,9 +826,9 @@ static inline void load_variable(Translated *translated, RuntimeState *state, return; } -RuntimeState init_runtime_state(Translated translated, char *path, ArgonObject * registers[UINT8_MAX]) { +RuntimeState init_runtime_state(Translated translated, char *path) { RuntimeState runtime = { - registers, + ar_alloc(translated.registerCount * sizeof(ArgonObject *)), 0, path, NULL, diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 933cf4a..296cda4 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -15,6 +15,8 @@ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) +#define MAX_REGISTERS 256 + extern ArgonObject *ARGON_METHOD_TYPE; extern Stack *Global_Scope; @@ -85,7 +87,7 @@ static inline uint64_t pop_bytecode(Translated *translated, static inline void run_instruction(Translated *translated, RuntimeState *state, struct Stack **stack, ArErr *err); -RuntimeState init_runtime_state(Translated translated, char *path, ArgonObject * registers[UINT8_MAX]); +RuntimeState init_runtime_state(Translated translated, char *path); Stack *create_scope(Stack *prev, bool force); diff --git a/src/shell.c b/src/shell.c index 51c8f90..34de719 100644 --- a/src/shell.c +++ b/src/shell.c @@ -50,34 +50,37 @@ typedef long ssize_t; #endif ssize_t getline(char **lineptr, size_t *n, FILE *stream) { - if (!lineptr || !n || !stream) return -1; + if (!lineptr || !n || !stream) + return -1; - size_t pos = 0; - int c; + size_t pos = 0; + int c; - if (*lineptr == NULL || *n == 0) { - *n = 128; - *lineptr = malloc(*n); - if (!*lineptr) return -1; - } + if (*lineptr == NULL || *n == 0) { + *n = 128; + *lineptr = malloc(*n); + if (!*lineptr) + return -1; + } - while ((c = fgetc(stream)) != EOF) { - if (pos + 1 >= *n) { - *n *= 2; - char *tmp = realloc(*lineptr, *n); - if (!tmp) return -1; - *lineptr = tmp; - } - (*lineptr)[pos++] = c; - if (c == '\n') - break; - } - - if (pos == 0 && c == EOF) + while ((c = fgetc(stream)) != EOF) { + if (pos + 1 >= *n) { + *n *= 2; + char *tmp = realloc(*lineptr, *n); + if (!tmp) return -1; + *lineptr = tmp; + } + (*lineptr)[pos++] = c; + if (c == '\n') + break; + } - (*lineptr)[pos] = '\0'; - return (ssize_t)pos; + if (pos == 0 && c == EOF) + return -1; + + (*lineptr)[pos] = '\0'; + return (ssize_t)pos; } #else #include "../external/linenoise/linenoise.h" @@ -91,7 +94,7 @@ void handle_sigint(int sig) { } int execute_code(FILE *stream, char *path, Stack *scope, - ArgonObject * registers[UINT8_MAX], RuntimeState* runtime_state) { + RuntimeState *runtime_state) { if (!stream) { perror("fmemopen"); return 1; @@ -150,7 +153,7 @@ int execute_code(FILE *stream, char *path, Stack *scope, translated.constants.capacity = __translated.constants.capacity; darray_free(&__translated.bytecode, NULL); free(__translated.constants.data); - *runtime_state = init_runtime_state(translated, path, registers); + *runtime_state = init_runtime_state(translated, path); runtime(translated, *runtime_state, scope, &err); if (err.exists) { output_err(err); @@ -209,16 +212,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, registers, &runtime_state); + int resp = execute_code(file, "", main_scope, &runtime_state); fclose(file); free(data); return resp; @@ -308,12 +309,13 @@ int shell() { totranslate[totranslatelength] = '\0'; RuntimeState runtime_state; FILE *file = fmemopen((void *)totranslate, totranslatelength, "r"); - int resp = execute_code(file, "", main_scope, registers, &runtime_state); + int resp = execute_code(file, "", main_scope, &runtime_state); fclose(file); if (resp) { continue; } - if (registers[0]&®isters[0] != ARGON_NULL) { + if (runtime_state.registers[0] && + runtime_state.registers[0] != ARGON_NULL) { ArErr err = no_err; argon_call(output_object, 1, (ArgonObject *[]){runtime_state.registers[0]}, &err, diff --git a/tests/iteration-test.ar b/tests/iteration-test.ar index 57dcb71..7a28707 100644 --- a/tests/iteration-test.ar +++ b/tests/iteration-test.ar @@ -1,5 +1,6 @@ #term.log(global) let i = 1e7 -while (i) do - i=i-1 - term.log(i) \ No newline at end of file +while (true) do + term.log(global) + #i=i-1 + #term.log(i) \ No newline at end of file