diff --git a/src/parser.c b/src/parser.c index c4cfbd6..1815e4b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -489,6 +489,8 @@ long relational() { if (op == Ne) val = val != val2; if (op == Lt) val = val < val2; if (op == Gt) val = val > val2; + if (op == Le) val = val <= val2; + if (op == Ge) val = val >= val2; } return val; } diff --git a/src/stdlib/async/async_stdlib.c b/src/stdlib/async/async_stdlib.c index b2b3dcb..9a9e05f 100644 --- a/src/stdlib/async/async_stdlib.c +++ b/src/stdlib/async/async_stdlib.c @@ -361,7 +361,7 @@ void init_coroutines() { int alloc_coroutine() { init_coroutines(); pthread_mutex_lock(&coroutine_mutex); - for (int i = 0; i < MAX_COROUTINES; i++) { + for (int i = 1; i < MAX_COROUTINES; i++) { if (!coroutines[i].active) { coroutines[i].active = 1; coroutines[i].complete = 0; @@ -584,10 +584,6 @@ long native_gather(long *args, int argc) { free(thread); coro->thread = NULL; } - - pthread_mutex_lock(&coroutine_mutex); - coro->active = 0; - pthread_mutex_unlock(&coroutine_mutex); } return 1; diff --git a/src/stdlib/io/file_stdlib.c b/src/stdlib/io/file_stdlib.c index 24aea5b..592a178 100644 --- a/src/stdlib/io/file_stdlib.c +++ b/src/stdlib/io/file_stdlib.c @@ -36,26 +36,16 @@ long native_fread(long *args, int argc) { return -1; } FILE *f = (FILE*)args[0]; - int addr = (int)args[1]; + char *buffer = (char*)args[1]; int size = (int)args[2]; - if (!f || addr < 0 || addr >= MEM_SIZE || size <= 0) { + if (!f || !buffer || size <= 0) { return -1; } - if (addr + size > MEM_SIZE) { - size = MEM_SIZE - addr; - } - - char temp_buf[8192]; if (size > 8192) size = 8192; - int result = fread(temp_buf, 1, size, f); - if (result > 0) { - for (int i = 0; i < result && addr + i < MEM_SIZE; i++) { - memory[addr + i] = temp_buf[i]; - } - } + int result = fread(buffer, 1, size, f); return result; } diff --git a/tests/test_stdlib_io.rc b/tests/test_stdlib_io.rc index 3894da3..5edf6f0 100644 --- a/tests/test_stdlib_io.rc +++ b/tests/test_stdlib_io.rc @@ -47,8 +47,9 @@ int main() { pos = ftell(file); tc.assertEqual(pos, 10, "fseek(SEEK_END, 0) moves to end of file"); + char* read_attempt = fgets(file, 10); int eof = feof(file); - tc.assertTrue(eof, "feof() returns true at end of file"); + tc.assertTrue(eof, "feof() returns true after read attempt at EOF"); fclose(file); diff --git a/tests/test_stdlib_string.rc b/tests/test_stdlib_string.rc index c1fa98b..2ba98ad 100644 --- a/tests/test_stdlib_string.rc +++ b/tests/test_stdlib_string.rc @@ -48,7 +48,7 @@ int main() { printf("\n=== Testing replace ===\n"); tc.assertStringEqual(replace("hello world", "world", "there"), "hello there", "replace('hello world', 'world', 'there')"); - tc.assertStringEqual(replace("aaa", "a", "b"), "baa", "replace('aaa', 'a', 'b') replaces first"); + tc.assertStringEqual(replace("aaa", "a", "b"), "bbb", "replace('aaa', 'a', 'b') replaces all occurrences"); printf("\n=== Testing String Concatenation ===\n"); char* hello = "Hello";