From 961a5d9988c5986d563310275adad3fd181b2bb7 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 15 Feb 2024 15:44:34 +0100 Subject: [PATCH] address all remaining compiler warnings --- .clangd | 2 +- src/builtins.h | 2 +- src/compiler.c | 113 ++++++++++++++++++++------------------ src/compiler.h | 4 +- src/gc.c | 2 +- src/lexer.c | 4 +- src/object.c | 1 - src/object.h | 16 +++--- src/opcode.c | 3 +- src/parser.c | 2 - src/pepper.c | 1 + src/sizes.c | 4 +- src/symbol_table.c | 15 ++--- src/util.h | 2 +- src/vm.c | 28 ++++------ tests/compiler_test.c | 64 ++++++++++----------- tests/lexer_test.c | 8 +-- tests/opcode_test.c | 16 +++--- tests/parser_test.c | 57 ++++++++++--------- tests/symbol_table_test.c | 22 ++++---- tests/vm_test.c | 112 ++++++++++++++++++------------------- 21 files changed, 235 insertions(+), 243 deletions(-) diff --git a/.clangd b/.clangd index 95dbdca..1e28b54 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,2 @@ CompileFlags: - Add: [-std=c11, -Wall, -Wextra, -Wpedantic ] + Add: [-std=c11, -Wall, -Wextra, -Wpedantic, -Wmissing-braces ] diff --git a/src/builtins.h b/src/builtins.h index f96244d..954aed7 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -7,4 +7,4 @@ struct object get_builtin(const char *name); struct object get_builtin_by_index(const uint8_t index); -void define_builtins(struct symbol_table *t); \ No newline at end of file +void define_builtins(struct symbol_table *t); diff --git a/src/compiler.c b/src/compiler.c index 31d463a..1ff7a02 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -8,7 +8,6 @@ #include "opcode.h" #include "parser.h" #include "symbol_table.h" -#include "vm.h" #include "builtins.h" enum { @@ -272,74 +271,80 @@ void compiler_change_jump_placeholders(struct compiler* c, uint32_t pos_start, u } } -static int -compile_expression(struct compiler *c, const struct expression *expr) { - int err; - switch (expr->type) { - case EXPR_INFIX: { - err = compile_expression(c, expr->infix.left); - if (err) return err; +static int compile_infix_expression(struct compiler *c, const struct expression *expr) { + int err = compile_expression(c, expr->infix.left); + if (err) return err; - err = compile_expression(c, expr->infix.right); - if (err) return err; + err = compile_expression(c, expr->infix.right); + if (err) return err; - switch (expr->infix.operator) { - case OP_ADD: - compiler_emit(c, OPCODE_ADD); - break; + switch (expr->infix.operator) { + case OP_ADD: + compiler_emit(c, OPCODE_ADD); + break; - case OP_SUBTRACT: - compiler_emit(c, OPCODE_SUBTRACT); - break; + case OP_SUBTRACT: + compiler_emit(c, OPCODE_SUBTRACT); + break; - case OP_MULTIPLY: - compiler_emit(c, OPCODE_MULTIPLY); - break; + case OP_MULTIPLY: + compiler_emit(c, OPCODE_MULTIPLY); + break; - case OP_DIVIDE: - compiler_emit(c, OPCODE_DIVIDE); - break; + case OP_DIVIDE: + compiler_emit(c, OPCODE_DIVIDE); + break; - case OP_MODULO: - compiler_emit(c, OPCODE_MODULO); - break; + case OP_MODULO: + compiler_emit(c, OPCODE_MODULO); + break; - case OP_GTE: - compiler_emit(c, OPCODE_GREATER_THAN_OR_EQUALS); - break; + case OP_GTE: + compiler_emit(c, OPCODE_GREATER_THAN_OR_EQUALS); + break; - case OP_GT: - compiler_emit(c, OPCODE_GREATER_THAN); - break; + case OP_GT: + compiler_emit(c, OPCODE_GREATER_THAN); + break; - case OP_EQ: - compiler_emit(c, OPCODE_EQUAL); - break; + case OP_EQ: + compiler_emit(c, OPCODE_EQUAL); + break; - case OP_NOT_EQ: - compiler_emit(c, OPCODE_NOT_EQUAL); - break; + case OP_NOT_EQ: + compiler_emit(c, OPCODE_NOT_EQUAL); + break; - case OP_LT: - compiler_emit(c, OPCODE_LESS_THAN); - break; + case OP_LT: + compiler_emit(c, OPCODE_LESS_THAN); + break; - case OP_LTE: - compiler_emit(c, OPCODE_LESS_THAN_OR_EQUALS); - break; + case OP_LTE: + compiler_emit(c, OPCODE_LESS_THAN_OR_EQUALS); + break; - case OP_AND: - compiler_emit(c, OPCODE_AND); - break; + case OP_AND: + compiler_emit(c, OPCODE_AND); + break; - case OP_OR: - compiler_emit(c, OPCODE_OR); - break; + case OP_OR: + compiler_emit(c, OPCODE_OR); + break; - default: - return COMPILE_ERR_UNKNOWN_OPERATOR; - break; - } + default: + return COMPILE_ERR_UNKNOWN_OPERATOR; + break; + } + + return 0; +} + +static int +compile_expression(struct compiler *c, const struct expression *expr) { + int err; + switch (expr->type) { + case EXPR_INFIX: { + return compile_infix_expression(c, expr); } break; diff --git a/src/compiler.h b/src/compiler.h index 071c9a7..0b35467 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -22,7 +22,7 @@ struct compiler { struct compiler_scope scopes[64]; }; -struct compiler *compiler_new(); +struct compiler *compiler_new(void); struct compiler *compiler_new_with_state(struct symbol_table *t, struct object_list *constants); void compiler_free(struct compiler *c); int compile_program(struct compiler *compiler, const struct program *program); @@ -32,4 +32,4 @@ const char *compiler_error_str(const int err); uint32_t compiler_emit(struct compiler *c, const enum opcode opcode, ...); void compiler_enter_scope(struct compiler *c); struct instruction *compiler_leave_scope(struct compiler *c); -struct compiler_scope compiler_current_scope(struct compiler *c); \ No newline at end of file +struct compiler_scope compiler_current_scope(struct compiler *c); diff --git a/src/gc.c b/src/gc.c index 5f93eea..339095f 100644 --- a/src/gc.c +++ b/src/gc.c @@ -99,4 +99,4 @@ gc(struct vm* restrict vm) printf("Heap size (after): %d\n", vm->heap->size); printf("GARBAGE COLLECTION DONE\n"); #endif -} \ No newline at end of file +} diff --git a/src/lexer.c b/src/lexer.c index bce8fef..6a7525e 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,8 +1,6 @@ #include "lexer.h" #include #include -#include -#include #include #include @@ -310,4 +308,4 @@ struct lexer new_lexer(const char *input) { .cur_lineno = 1, .cur_linepos = 0, }; -} \ No newline at end of file +} diff --git a/src/object.c b/src/object.c index 52b19a6..65c42c8 100644 --- a/src/object.c +++ b/src/object.c @@ -8,7 +8,6 @@ #include "util.h" #include "opcode.h" #include "object.h" -#include "parser.h" const char *object_type_to_str(enum object_type t) { diff --git a/src/object.h b/src/object.h index b1da8c0..798a288 100644 --- a/src/object.h +++ b/src/object.h @@ -10,14 +10,14 @@ enum object_type { - OBJ_NULL, - OBJ_BOOL, - OBJ_INT, - OBJ_BUILTIN, - OBJ_ERROR, - OBJ_STRING, - OBJ_ARRAY, - OBJ_COMPILED_FUNCTION, + OBJ_NULL, // 0b000 + OBJ_BOOL, // 0b001 + OBJ_INT, // 0b010 + OBJ_BUILTIN, // 0b011 + OBJ_ERROR, // 0b100 + OBJ_STRING, // 0b101 + OBJ_ARRAY, // 0b110 + OBJ_COMPILED_FUNCTION, // 0b111 }; struct function { diff --git a/src/opcode.c b/src/opcode.c index bb8d72f..64bb3ea 100644 --- a/src/opcode.c +++ b/src/opcode.c @@ -4,10 +4,9 @@ #include #include #include -#include "util.h" #include "opcode.h" -const struct definition definitions[] = { +static const struct definition definitions[] = { { "OpConstant", 1, {2} }, { "OpPop", 0, {0} }, { "OpAdd", 0, {0} }, diff --git a/src/parser.c b/src/parser.c index fa9a9b5..e5fee3b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,10 +1,8 @@ #include -#include #include #include #include #include -#include "object.h" #include "parser.h" #include "lexer.h" #include "util.h" diff --git a/src/pepper.c b/src/pepper.c index e6e103d..2258de2 100644 --- a/src/pepper.c +++ b/src/pepper.c @@ -48,6 +48,7 @@ static int repl(void) { print_version(); printf("Press CTRL+c to exit\n\n"); + struct program *program; struct symbol_table *symbol_table = symbol_table_new(); struct object_list *constants = make_object_list(64); diff --git a/src/sizes.c b/src/sizes.c index e1c41e3..de210a9 100644 --- a/src/sizes.c +++ b/src/sizes.c @@ -4,7 +4,7 @@ #include "object.h" -int main() { +int main(void) { printf("sizeof(char): %ld\n", sizeof(char)); printf("sizeof(enum): %ld\n", sizeof(enum { A, B})); printf("sizeof(char*): %ld\n", sizeof(char*)); @@ -31,4 +31,4 @@ int main() { t.value.b = malloc(sizeof(int)); printf("%p\n", t.value.b); printf("%p\n", t.value); -} \ No newline at end of file +} diff --git a/src/symbol_table.c b/src/symbol_table.c index 492f927..10a686a 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -7,17 +7,17 @@ #define hash(v) (v[0] - 'a') -static struct hashmap *hashmap_new(); +static struct hashmap *hashmap_new(void); static void hashmap_insert(struct hashmap *hm, const char *key, void *item); static void *hashmap_get(struct hashmap *hm, const char *key); static void hashmap_free(struct hashmap *hm); static struct hashmap * -hashmap_new() { +hashmap_new(void) { struct hashmap *hm = malloc(sizeof *hm); if (!hm) err(EXIT_FAILURE, "out of memory"); - for (int8_t i=0; i < 26; i++) { + for (unsigned i=0; i < 26u; i++) { hm->table[i] = NULL; } @@ -51,8 +51,9 @@ hashmap_insert(struct hashmap *hm, const char *key, void *item) { static void * hashmap_get(struct hashmap *hm, const char *key) { - const int8_t pos = hash(key); + unsigned pos = hash(key); struct hashmap_node *node = hm->table[pos]; + while (node) { if (strcmp(node->key, key) == 0) { return node->value; @@ -67,7 +68,7 @@ void hashmap_free(struct hashmap *hm) { struct hashmap_node *node; struct hashmap_node *next; - for (int8_t i=0; i < 26; i++) { + for (unsigned i=0; i < 26u; i++) { node = hm->table[i]; while (node) { next = node->next; @@ -80,7 +81,7 @@ void hashmap_free(struct hashmap *hm) { free(hm); } -struct symbol_table *symbol_table_new() { +struct symbol_table *symbol_table_new(void) { struct symbol_table *t = malloc(sizeof *t); if (!t) err(EXIT_FAILURE, "out of memory"); t->size = 0; @@ -146,4 +147,4 @@ struct symbol *symbol_table_resolve(struct symbol_table *t, const char *name) { void symbol_table_free(struct symbol_table *t) { hashmap_free(t->store); free(t); -} \ No newline at end of file +} diff --git a/src/util.h b/src/util.h index c3f49b1..6e5d7bf 100644 --- a/src/util.h +++ b/src/util.h @@ -4,7 +4,7 @@ #include __attribute__((noreturn)) -static inline void err(const int status, const char *format, ...) { +static inline void err(__attribute__((unused)) int status, const char *format, ...) { va_list args; va_start(args, format); vfprintf(stderr, format, args); diff --git a/src/vm.c b/src/vm.c index 1ea2efd..630ba59 100644 --- a/src/vm.c +++ b/src/vm.c @@ -4,7 +4,6 @@ #include #include -#include "parser.h" #include "util.h" #include "object.h" #include "opcode.h" @@ -180,7 +179,7 @@ vm_do_binary_string_operation(struct vm* restrict vm, enum opcode opcode, struct } static void -vm_do_binary_boolean_operation(const struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { +vm_do_binary_boolean_operation(__attribute__((unused)) struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { switch (opcode) { case OPCODE_AND: left->value.boolean = left->value.boolean && right->value.boolean; @@ -217,7 +216,7 @@ vm_do_binary_operation(struct vm* restrict vm, const enum opcode opcode) { } static void -vm_do_integer_comparison(const struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { +vm_do_integer_comparison(__attribute__((unused)) struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { switch (opcode) { case OPCODE_EQUAL: left->value.boolean = left->value.integer == right->value.integer; @@ -252,7 +251,7 @@ vm_do_integer_comparison(const struct vm* restrict vm, const enum opcode opcode, } static void -vm_do_bool_comparison(const struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { +vm_do_bool_comparison(__attribute__((unused)) struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { switch (opcode) { case OPCODE_EQUAL: left->value.boolean = left->value.boolean == right->value.boolean; @@ -269,7 +268,7 @@ vm_do_bool_comparison(const struct vm* restrict vm, const enum opcode opcode, st } static void -vm_do_string_comparison(const struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { +vm_do_string_comparison(__attribute__((unused)) struct vm* restrict vm, const enum opcode opcode, struct object* restrict left, const struct object* restrict right) { left->type = OBJ_BOOL; switch (opcode) { case OPCODE_EQUAL: @@ -720,31 +719,26 @@ vm_run(struct vm* restrict vm) { switch (left.type) { case OBJ_ARRAY: { struct object_list* list = left.value.list; - int32_t i = index.value.integer; - if (i < 0) { - i = list->size + i; - } - if (i < 0 || i >= list->size) { + unsigned idx = (unsigned) (index.value.integer < 0 ? list->size + index.value.integer : index.value.integer); + if (idx >= list->size) { vm_stack_push(vm, make_error_object("Array index out of bounds")); gc_add(vm, vm_stack_cur(vm)); } else { - vm_stack_push(vm, list->values[i]); + vm_stack_push(vm, list->values[idx]); } } break; case OBJ_STRING: { const char *str = left.value.string->value; - int32_t i = index.value.integer; - if (i < 0) { - i = left.value.string->length + i; - } - if (i < 0 || i >= left.value.string->length) { + unsigned idx = (unsigned) (index.value.integer < 0 ? (int) left.value.string->length + index.value.integer : index.value.integer); + if (idx >= left.value.string->length) { vm_stack_push(vm, make_error_object("String index out of bounds")); gc_add(vm, vm_stack_cur(vm)); } else { + /* TODO: Create char object? Bit wasteful here for a single byte */ char buf[2]; - buf[0] = (char) str[i]; + buf[0] = (char) str[idx]; buf[1] = '\0'; struct object obj = make_string_object(buf); vm_stack_push(vm, obj); diff --git a/tests/compiler_test.c b/tests/compiler_test.c index 4f040d0..afda554 100755 --- a/tests/compiler_test.c +++ b/tests/compiler_test.c @@ -25,7 +25,7 @@ static void test_object(struct object expected, struct object actual) { char *expected_str = instruction_to_str(&ef->instructions); char *actual_str = instruction_to_str(&af->instructions); assertf(ef->instructions.size == af->instructions.size, "wrong instructions length: \nexpected\n\"%s\"\ngot\n\"%s\"", expected_str, actual_str); - for (int i=0; i < ef->instructions.size; i++) { + for (unsigned i=0; i < ef->instructions.size; i++) { assertf(ef->instructions.bytes[i] == af->instructions.bytes[i], "byte mismatch at pos %d: expected '%d', got '%d'\n\texpected: \t%s\n\tgot: \t\t%s\n", i, ef->instructions.bytes[i], af->instructions.bytes[i], expected_str, actual_str); } free(expected_str); @@ -52,12 +52,12 @@ static void run_compiler_test(struct compiler_test_case t) { char *bytecode_str = instruction_to_str(bytecode->instructions); assertf(bytecode->instructions->size == concatted->size, "wrong instructions length: \nexpected %d\n\"%s\"\ngot %d\n\"%s\"", concatted->size, concatted_str, bytecode->instructions->size, bytecode_str); - for (int i=0; i < concatted->size; i++) { + for (unsigned i=0; i < concatted->size; i++) { assertf(concatted->bytes[i] == bytecode->instructions->bytes[i], "byte mismatch at pos %d: expected '%d', got '%d'\n\texpected: \t%s\n\tgot: \t\t%s\n", i, concatted->bytes[i], bytecode->instructions->bytes[i], concatted_str, bytecode_str); } assertf(bytecode->constants->size == t.constants_size, "wrong constants size: expected %d, got %d", t.constants_size, bytecode->constants->size); - for (int i=0; i < t.constants_size; i++) { + for (unsigned i=0; i < t.constants_size; i++) { test_object(t.constants[i], bytecode->constants->values[i]); free_object(&t.constants[i]); } @@ -71,12 +71,12 @@ static void run_compiler_test(struct compiler_test_case t) { } static void run_compiler_tests(struct compiler_test_case tests[], uint32_t n) { - for (int t=0; t < n; t++) { + for (unsigned t=0; t < n; t++) { run_compiler_test(tests[t]); } } -static void integer_arithmetic() { +static void integer_arithmetic(void) { struct compiler_test_case tests[] = { { @@ -176,12 +176,12 @@ static void integer_arithmetic() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void boolean_expressions() { +static void boolean_expressions(void) { struct compiler_test_case tests[] = { { .input = "true", - .constants = {}, + .constants = {{0}}, .constants_size = 0, .instructions = { make_instruction(OPCODE_TRUE), @@ -192,7 +192,7 @@ static void boolean_expressions() { }, { "false", - {}, 0, + {{0}}, 0, { make_instruction(OPCODE_FALSE), make_instruction(OPCODE_POP), @@ -258,7 +258,7 @@ static void boolean_expressions() { }, { "true == false", - {}, 0, + {{0}}, 0, { make_instruction(OPCODE_TRUE), make_instruction(OPCODE_FALSE), @@ -269,7 +269,7 @@ static void boolean_expressions() { }, { "true != false", - {}, 0, + {{0}}, 0, { make_instruction(OPCODE_TRUE), make_instruction(OPCODE_FALSE), @@ -280,7 +280,7 @@ static void boolean_expressions() { }, { "!true", - {}, 0, + {{0}}, 0, { make_instruction(OPCODE_TRUE), make_instruction(OPCODE_BANG), @@ -293,7 +293,7 @@ static void boolean_expressions() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void if_expressions() { +static void if_expressions(void) { struct compiler_test_case tests[] = { { @@ -357,7 +357,7 @@ static void if_expressions() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void global_let_statements() { +static void global_let_statements(void) { struct compiler_test_case tests[] = { { .input = "let one = 1; let two = 2;", @@ -424,7 +424,7 @@ static void global_let_statements() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void functions() { +static void functions(void) { { struct instruction *fn_body = flatten_instructions_array((struct instruction *[]) { make_instruction(OPCODE_CONST, 0), @@ -515,7 +515,7 @@ static void functions() { } } -static void compiler_scopes() { +static void compiler_scopes(void) { struct compiler_scope scope; struct compiler *compiler = compiler_new(); assertf(compiler->scope_index == 0, "wrong scope index: expected %d, got %d", 0, compiler->scope_index); @@ -543,7 +543,7 @@ static void compiler_scopes() { compiler_free(compiler); } -static void function_calls() { +static void function_calls(void) { { struct instruction *fn_body = flatten_instructions_array((struct instruction *[]) { make_instruction(OPCODE_CONST, 0), @@ -683,7 +683,7 @@ static void function_calls() { } -static void let_statement_scopes() { +static void let_statement_scopes(void) { { struct instruction *fn_body = flatten_instructions_array((struct instruction *[]) { make_instruction(OPCODE_GET_GLOBAL, 0), @@ -759,7 +759,7 @@ static void let_statement_scopes() { } -static void recursive_functions() { +static void recursive_functions(void) { struct instruction *fn_body = flatten_instructions_array((struct instruction *[]) { make_instruction(OPCODE_GET_GLOBAL, 0), make_instruction(OPCODE_GET_LOCAL, 0), @@ -789,7 +789,7 @@ static void recursive_functions() { free_instruction(fn_body); } -static void string_expressions() { +static void string_expressions(void) { struct compiler_test_case tests[] = { { .input = "\"monkey\"", @@ -822,7 +822,7 @@ static void string_expressions() { } -static void builtin_functions() { +static void builtin_functions(void) { struct compiler_test_case tests[] = { { .input = "len(\"monkey\")", @@ -859,7 +859,7 @@ static void builtin_functions() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void while_expressions() { +static void while_expressions(void) { struct compiler_test_case tests[] = { { .input = "while (true) { 10; } 3333;", @@ -898,7 +898,7 @@ static void while_expressions() { }, { .input = "while (true) { break; };", - .constants = {}, 0, + .constants = {{0}}, 0, .instructions = { make_instruction(OPCODE_NULL), make_instruction(OPCODE_TRUE), @@ -914,7 +914,7 @@ static void while_expressions() { }, { .input = "while (true) { continue; };", - .constants = {}, 0, + .constants = {{0}}, 0, .instructions = { make_instruction(OPCODE_NULL), make_instruction(OPCODE_TRUE), @@ -933,7 +933,7 @@ static void while_expressions() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void for_expressions() { +static void for_expressions(void) { struct compiler_test_case tests[] = { { .input = "for (let i = 0; i < 10; i = i + 1) { 5 }", @@ -1029,11 +1029,11 @@ static void for_expressions() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void array_literals() { +static void array_literals(void) { struct compiler_test_case tests[] = { { .input = "[]", - .constants = {}, 0, + .constants = {{0}}, 0, .instructions = { make_instruction(OPCODE_ARRAY, 0), make_instruction(OPCODE_POP), @@ -1086,7 +1086,7 @@ static void array_literals() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void index_get() { +static void index_get(void) { struct compiler_test_case tests[] = { { .input = "[1, 2][1]", @@ -1110,7 +1110,7 @@ static void index_get() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void var_assignment() { +static void var_assignment(void) { struct compiler_test_case tests[] = { { .input = "let a = 1; a = 2;", @@ -1133,7 +1133,7 @@ static void var_assignment() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void index_set() { +static void index_set(void) { struct compiler_test_case tests[] = { { .input = "let arr = [1]; arr[0] = 2;", @@ -1160,7 +1160,7 @@ static void index_set() { } -static void slices() { +static void slices(void) { struct compiler_test_case tests[] = { { .input = "[0, 1, 2][0:1]", @@ -1188,7 +1188,7 @@ static void slices() { run_compiler_tests(tests, ARRAY_SIZE(tests)); } -static void postfix_expressions() { +static void postfix_expressions(void) { struct compiler_test_case tests[] = { { .input = "let foo = 0; foo--;", @@ -1251,4 +1251,4 @@ int main(int argc, char *argv[]) { TEST(index_set); TEST(postfix_expressions); TEST(slices); -} \ No newline at end of file +} diff --git a/tests/lexer_test.c b/tests/lexer_test.c index 079e767..3f44d5e 100755 --- a/tests/lexer_test.c +++ b/tests/lexer_test.c @@ -2,10 +2,8 @@ #include "test_helpers.h" #include -#include -#include -static void test_lexer() { +static void test_lexer(void) { const char *input = "let five = 5;\n" "let ten = 10;\n" "let add = fn(x, y) {\n" @@ -129,7 +127,7 @@ static void test_lexer() { struct token t; - for (int j = 0; j < sizeof tokens / sizeof tokens[0]; j++) { + for (unsigned j = 0; j < sizeof tokens / sizeof tokens[0]; j++) { gettoken(&l, &t); assertf(t.type == tokens[j].type, "[%d] wrong type: expected \"%s\", got \"%s\"\n", j, token_type_to_str(tokens[j].type), token_type_to_str(t.type)); assertf(strcmp(t.literal, tokens[j].literal) == 0, "[%d] wrong %s literal: expected \"%s\", got \"%s\"\n", j, token_type_to_str(tokens[j].type), tokens[j].literal, t.literal); @@ -139,7 +137,7 @@ static void test_lexer() { } } -static void string_with_256_chars() { +static void string_with_256_chars(void) { char *input = "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\""; struct lexer l = new_lexer(input); struct token t; diff --git a/tests/opcode_test.c b/tests/opcode_test.c index 4f77e27..afc7b7b 100755 --- a/tests/opcode_test.c +++ b/tests/opcode_test.c @@ -5,7 +5,7 @@ #include "../src/opcode.h" #include "test_helpers.h" -static void test_make_instruction() { +static void test_make_instruction(void) { struct { enum opcode opcode; uint32_t operands[MAX_OP_SIZE]; @@ -29,11 +29,11 @@ static void test_make_instruction() { } }; - for (int i=0; i < ARRAY_SIZE(tests); i++) { + for (unsigned i=0; i < ARRAY_SIZE(tests); i++) { struct instruction *ins = make_instruction(tests[i].opcode, tests[i].operands[0]); assertf(ins->size == tests[i].expected_size, "wrong length: expected %d, got %d", tests[i].expected_size, ins->size); - for (int j=0; j < tests[i].expected_size; j++) { + for (unsigned j=0; j < tests[i].expected_size; j++) { assertf(ins->bytes[j] == tests[i].expected[j], "[%d] invalid byte value at index %d: expected %d, got %d", i, j, tests[i].expected[j], ins->bytes[j]); } @@ -41,7 +41,7 @@ static void test_make_instruction() { } } -static void test_instruction_string() { +static void test_instruction_string(void) { struct instruction *instructions[] = { make_instruction(OPCODE_ADD), make_instruction(OPCODE_GET_LOCAL, 1), @@ -57,7 +57,7 @@ static void test_instruction_string() { free(str); } -static void test_read_operands() { +static void test_read_operands(void) { struct { enum opcode opcode; uint32_t operands[MAX_OP_SIZE]; @@ -68,7 +68,7 @@ static void test_read_operands() { {OPCODE_GET_LOCAL, {255}, 1}, }; - for (int t = 0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t = 0; t < ARRAY_SIZE(tests); t++) { struct instruction *ins = make_instruction(tests[t].opcode, tests[t].operands[0]); struct definition def = lookup(tests[t].opcode); uint32_t operands[3] = {0}; @@ -81,7 +81,7 @@ static void test_read_operands() { } } -static void test_read_bytes() { +static void test_read_bytes(void) { uint8_t bytes[] = {100, 20, 255}; uint8_t v1 = read_uint8(bytes); assertf(v1 == 100, "read_bytes(uint8_t) failed: expected %d, got %d", 100, v1); @@ -94,4 +94,4 @@ int main(int argc, char *argv[]) { TEST(test_read_operands); TEST(test_instruction_string); TEST(test_read_bytes); -} \ No newline at end of file +} diff --git a/tests/parser_test.c b/tests/parser_test.c index f7f4ec4..d7cb90e 100755 --- a/tests/parser_test.c +++ b/tests/parser_test.c @@ -1,7 +1,6 @@ #include #include #include -#include #include "../src/parser.h" #include "test_helpers.h" @@ -56,7 +55,7 @@ static void assert_program_size(struct program *p, uint32_t expected_size) { assertf(p->size == expected_size, "wrong program size. expected %d, got %d\n", expected_size, p->size); } -static void let_statements() { +static void let_statements(void) { const char *input = "" "let x = 5;\n" "let y = true;\n" @@ -86,7 +85,7 @@ static void let_statements() { free_program(program); } -static void let_statements_without_assignment() { +static void let_statements_without_assignment(void) { const char *input = "let foo;"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -96,7 +95,7 @@ static void let_statements_without_assignment() { free_program(program); } -static void return_statements() { +static void return_statements(void) { const char *input = "" "return 5;\n" "return true;\n" @@ -124,7 +123,7 @@ static void return_statements() { free_program(program); } -static void program_string() { +static void program_string(void) { struct expression e1 = { .type = EXPR_INT, .token = { @@ -200,7 +199,7 @@ static void program_string() { free(str); } -static void identifier_expression_parsing() { +static void identifier_expression_parsing(void) { const char *input = "foobar;"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -212,7 +211,7 @@ static void identifier_expression_parsing() { free_program(program); } -static void integer_expression_parsing() { +static void integer_expression_parsing(void) { const char *input = "5;"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -224,7 +223,7 @@ static void integer_expression_parsing() { free_program(program); } -static void boolean_expression_parsing() { +static void boolean_expression_parsing(void) { struct test { const char* input; char expected; @@ -243,7 +242,7 @@ static void boolean_expression_parsing() { } } -static void postfix_expressions() { +static void postfix_expressions(void) { struct test{ const char* input; enum operator operator; @@ -254,7 +253,7 @@ static void postfix_expressions() { {"foo++", OP_ADD, "foo"}, }; - for (int i=0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i=0; i < sizeof tests / sizeof tests[0]; i++) { struct program *program = parse_program_str(tests[i].input); assert_program_size(program, 1); struct statement stmt = program->statements[0]; @@ -265,7 +264,7 @@ static void postfix_expressions() { } } -static void infix_expression_parsing() { +static void infix_expression_parsing(void) { struct test{ const char *input; union expression_value left_value; @@ -286,7 +285,7 @@ static void infix_expression_parsing() { {"false == false", {0}, OP_EQ, {0}}, }; - for (int i=0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i=0; i < sizeof tests / sizeof tests[0]; i++) { struct test t = tests[i]; struct program *program = parse_program_str(t.input); assert_program_size(program, 1); @@ -296,7 +295,7 @@ static void infix_expression_parsing() { } } -static void prefix_expression_parsing() { +static void prefix_expression_parsing(void) { typedef struct test { const char *input; enum operator operator; @@ -310,7 +309,7 @@ static void prefix_expression_parsing() { {"!false", OP_NEGATE, { .bool_value = 0 }}, }; test t; - for (int i=0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i=0; i < sizeof tests / sizeof tests[0]; i++) { t = tests[i]; struct program *program = parse_program_str(tests[i].input); @@ -324,7 +323,7 @@ static void prefix_expression_parsing() { } } -static void operator_precedence_parsing() { +static void operator_precedence_parsing(void) { struct test { const char *input; const char *expected; @@ -370,7 +369,7 @@ static void operator_precedence_parsing() { }, }; - for (int i=0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i=0; i < sizeof tests / sizeof tests[0]; i++) { struct program *program = parse_program_str(tests[i].input); char *program_str = program_to_str(program); assertf(strcmp(program_str, tests[i].expected) == 0, "wrong program string: expected %s, got %s\n", tests[i].expected, program_str); @@ -379,7 +378,7 @@ static void operator_precedence_parsing() { } } -static void if_expression_parsing() { +static void if_expression_parsing(void) { const char *input = "if (x < y) { x }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -401,7 +400,7 @@ static void if_expression_parsing() { free_program(program); } -static void if_else_expression_parsing() { +static void if_else_expression_parsing(void) { const char *input = "if (x < y) { x } else { 5 }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -426,7 +425,7 @@ static void if_else_expression_parsing() { free_program(program); } -static void if_elseif() { +static void if_elseif(void) { const char *input = "if (x < y) { x } else if (true) { 5 }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -453,7 +452,7 @@ static void if_elseif() { free_program(program); } -static void function_literal_parsing() { +static void function_literal_parsing(void) { const char *input = "fn(x, y) { x + y; }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -476,7 +475,7 @@ static void function_literal_parsing() { free_program(program); } -static void call_expression_parsing() { +static void call_expression_parsing(void) { const char *input = "add(1, 2 * 3, 4 + 5);"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -518,7 +517,7 @@ static void test_string_literal(struct expression *expr, char *expected) { assertf(strcmp(expr->string, expected) == 0, "wrong expression value: expected \"%s\", got %s", expected, expr->string); } -static void string_expression_parsing() { +static void string_expression_parsing(void) { const char *input = "\"hello world\";"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -529,7 +528,7 @@ static void string_expression_parsing() { free_program(program); } -static void array_literal_parsing() { +static void array_literal_parsing(void) { const char *input = "[ 1, 2 * 2, 3 + 3, \"four\"];"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -546,7 +545,7 @@ static void array_literal_parsing() { free_program(program); } -static void index_expression_parsing() { +static void index_expression_parsing(void) { const char *input = "myArray[1+2];"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -560,7 +559,7 @@ static void index_expression_parsing() { free_program(program); } -static void slice_expression_parsing() { +static void slice_expression_parsing(void) { const char *input = "myArray[1:2+2];"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -574,7 +573,7 @@ static void slice_expression_parsing() { free_program(program); } -static void while_expression_parsing() { +static void while_expression_parsing(void) { const char *input = "while (x < y) { x }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -595,7 +594,7 @@ static void while_expression_parsing() { free_program(program); } -static void for_expressions() { +static void for_expressions(void) { const char *input = "for (let i=0; i < 5; i = i + 1) { x }"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -606,7 +605,7 @@ static void for_expressions() { free_program(program); } -static void function_literal_with_name() { +static void function_literal_with_name(void) { const char *input = "let myFunction = fn() {};"; struct program *program = parse_program_str(input); assert_program_size(program, 1); @@ -618,7 +617,7 @@ static void function_literal_with_name() { free_program(program); } -static void assignment_expressions() { +static void assignment_expressions(void) { const char *input = "let a = 5; a = 10;"; struct program *program = parse_program_str(input); assert_program_size(program, 2); diff --git a/tests/symbol_table_test.c b/tests/symbol_table_test.c index be7195e..5977d33 100755 --- a/tests/symbol_table_test.c +++ b/tests/symbol_table_test.c @@ -1,7 +1,7 @@ #include "test_helpers.h" #include "../src/symbol_table.h" -static void define() { +static void define(void) { struct { char *name; struct symbol expected; @@ -12,7 +12,7 @@ static void define() { struct symbol_table *global = symbol_table_new(); - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct symbol *s = symbol_table_define(global, tests[t].name); assertf(s != NULL, "expected symbol, got NULL"); assertf(strcmp(s->name, tests[t].expected.name) == 0, "wrong name: expected %s, got %s", tests[t].expected.name, s->name); @@ -23,7 +23,7 @@ static void define() { symbol_table_free(global); } -static void resolve_global() { +static void resolve_global(void) { struct symbol_table *global = symbol_table_new(); symbol_table_define(global, "a"); @@ -34,7 +34,7 @@ static void resolve_global() { { .name = "b", .scope = SCOPE_GLOBAL, .index = 1 }, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct symbol *s = symbol_table_resolve(global, tests[t].name); assertf(s != NULL, "expected symbol, got NULL"); assertf(strcmp(s->name, tests[t].name) == 0, "wrong name: expected %s, got %s", tests[t].name, s->name); @@ -46,7 +46,7 @@ static void resolve_global() { } -static void resolve_local() { +static void resolve_local(void) { struct symbol_table *global = symbol_table_new(); symbol_table_define(global, "a"); @@ -63,7 +63,7 @@ static void resolve_local() { { .name = "d", .scope = SCOPE_LOCAL, .index = 1 }, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct symbol *s = symbol_table_resolve(local, tests[t].name); assertf(s != NULL, "expected symbol, got NULL"); assertf(strcmp(s->name, tests[t].name) == 0, "wrong name: expected %s, got %s", tests[t].name, s->name); @@ -75,7 +75,7 @@ static void resolve_local() { symbol_table_free(local); } -static void define_and_resolve_builtins() { +static void define_and_resolve_builtins(void) { struct symbol_table *global = symbol_table_new(); struct symbol_table *local1 = symbol_table_new_enclosed(global); struct symbol_table *local2 = symbol_table_new_enclosed(local1); @@ -85,14 +85,14 @@ static void define_and_resolve_builtins() { { .name = "c", .scope = SCOPE_BUILTIN, .index = 2 }, { .name = "d", .scope = SCOPE_BUILTIN, .index = 3 }, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { symbol_table_define_builtin_function(global, tests[t].index, tests[t].name); } // in all scopes, the declared symbols should resolve to our builtin struct symbol_table *tables[] = {global, local1, local2}; - for (int i=0; i < 2; i++) { - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned i=0; i < 2; i++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct symbol *s = symbol_table_resolve(tables[i], tests[t].name); assertf(s != NULL, "expected symbol, got NULL"); assertf(strcmp(s->name, tests[t].name) == 0, "wrong name: expected %s, got %s", tests[t].name, s->name); @@ -111,4 +111,4 @@ int main(int argc, char *argv[]) { TEST(resolve_global); TEST(resolve_local); TEST(define_and_resolve_builtins); -} \ No newline at end of file +} diff --git a/tests/vm_test.c b/tests/vm_test.c index bd1d5de..3c1a4f1 100755 --- a/tests/vm_test.c +++ b/tests/vm_test.c @@ -82,7 +82,7 @@ static void run_tests(test_case_t* tests, int ntests) { } } -static void integer_arithmetic() { +static void integer_arithmetic(void) { test_case_t tests[] = { {"1", EXPECT_INT(1)}, {"2", EXPECT_INT(2)}, @@ -113,7 +113,7 @@ static void integer_arithmetic() { run_tests(tests, ARRAY_SIZE(tests)); } -static void boolean_expressions() { +static void boolean_expressions(void) { struct { const char *input; bool expected; @@ -150,13 +150,13 @@ static void boolean_expressions() { {"1 % 2 == 0 || true", true}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_BOOL, (object_value) { .boolean = tests[t].expected }); } } -static void if_expressions() { +static void if_expressions(void) { test_case_t tests[] = { {"if (true) { 10 }", EXPECT_INT(10) }, {"if (true) { 10 } else { 20 }", EXPECT_INT(10) }, @@ -184,7 +184,7 @@ static void if_expressions() { } -static void while_expressions() { +static void while_expressions(void) { test_case_t tests[] = { {"while (false) { 10 }; 5", EXPECT_INT(5)}, {"let a = 2; while (1 > 3) { a = a + 1; }; a;", EXPECT_INT(2)}, @@ -199,7 +199,7 @@ static void while_expressions() { run_tests(tests, ARRAY_SIZE(tests)); } -static void nulls() { +static void nulls(void) { struct { const char *input; } tests[] = { @@ -207,13 +207,13 @@ static void nulls() { {"if (false) { 10 }"}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); assertf(obj.type == OBJ_NULL, "expected NULL, got %s", object_type_to_str(obj.type)); } } -static void global_let_statements() { +static void global_let_statements(void) { test_case_t tests[] = { {"let one = 1; one", EXPECT_INT(1)}, {"let one = 1; let two = 2; one + two", EXPECT_INT(3)}, @@ -226,7 +226,7 @@ static void global_let_statements() { run_tests(tests, ARRAY_SIZE(tests)); } -static void function_calls() { +static void function_calls(void) { struct { const char *input; int expected; @@ -238,25 +238,25 @@ static void function_calls() { {"let earlyExit = fn() { return 99; return 100; }; earlyExit();", 99}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[t].expected }); } } -static void functions_without_return_value() { +static void functions_without_return_value(void) { const char *tests[] = { "let noReturn = fn() { }; noReturn();", "let noReturn = fn() { }; let noReturnTwo = fn() { noReturn(); }; noReturn(); noReturnTwo();" }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t]); - test_object(obj, OBJ_NULL, (object_value) {}); + test_object(obj, OBJ_NULL, (object_value) {0}); } } -static void first_class_functions() { +static void first_class_functions(void) { struct { const char *input; @@ -265,13 +265,13 @@ static void first_class_functions() { {"let returnsOne = fn() { 1; }; let returnsOneReturner = fn() { returnsOne; }; returnsOneReturner()();", 1}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[t].expected }); } } -static void function_calls_with_bindings() { +static void function_calls_with_bindings(void) { struct { const char *input; int expected; @@ -283,14 +283,14 @@ static void function_calls_with_bindings() { {"let globalSeed = 50; let minusOne = fn() { let num = 1; globalSeed - num; } let minusTwo = fn() { let num = 2; globalSeed - num; } minusOne() + minusTwo();", 97}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[t].expected }); } } -static void function_calls_with_args_and_bindings() { +static void function_calls_with_args_and_bindings(void) { struct { const char *input; int expected; @@ -314,13 +314,13 @@ static void function_calls_with_args_and_bindings() { {"let a = 5; let add = fn(a, b) { a + b }; add(1, 2);", 3} }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[t].expected }); } } -static void fib() { +static void fib(void) { const char *input = " \ let fibonacci = fn(x) { \ if (x < 2) { \ @@ -333,7 +333,7 @@ static void fib() { test_object(obj, OBJ_INT, (object_value) { .integer = 8 }); } -static void recursive_functions() { +static void recursive_functions(void) { struct { const char *input; int expected; @@ -342,13 +342,13 @@ static void recursive_functions() { {"let countdown = fn(x) { if (x < 0) { return 0; } countdown(x-1) + countdown(x-2); }; countdown(3);", 0}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[t].expected }); } } -static void string_expressions() { +static void string_expressions(void) { struct { const char *input; char *expected; @@ -362,13 +362,13 @@ static void string_expressions() { {"let a = \"foo\"; let b = \"bar\"; let c = a + b; c", "foobar"}, }; - for (int t=0; t < ARRAY_SIZE(tests); t++) { + for (unsigned t=0; t < ARRAY_SIZE(tests); t++) { struct object obj = run_vm_test(tests[t].input); test_object(obj, OBJ_STRING, (object_value) { .string = tests[t].expected }); } } -static void builtin_functions() { +static void builtin_functions(void) { test_case_t tests[] = { {"len(\"\")", EXPECT_INT(0)}, {"let l = len(\"a\"); print(\"Length: \", l);", EXPECT_NULL()}, @@ -385,26 +385,26 @@ static void builtin_functions() { run_tests(tests, ARRAY_SIZE(tests)); } -static void array_literals() { +static void array_literals(void) { struct { const char *input; - int nexpected; + unsigned nexpected; int expected[3]; } tests[] = { - {"[]", 0, {}}, + {"[]", 0, {0}}, {"[1, 2, 3]", 3, {1, 2, 3}}, {"[1 + 2, 3 * 4, 5 + 6]", 3, {3, 12, 11}}, }; - for (int i = 0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i = 0; i < sizeof tests / sizeof tests[0]; i++) { struct object obj = run_vm_test(tests[i].input); assertf(obj.type == OBJ_ARRAY, "invalid obj type: expected \"%s\", got \"%s\"", object_type_to_str(OBJ_ARRAY), object_type_to_str(obj.type)); struct object_list* arr = obj.value.list; assertf(tests[i].nexpected == arr->size, "invalid array size"); - for (int j=0; j < tests[i].nexpected; j++) { + for (unsigned j=0; j < tests[i].nexpected; j++) { assertf(arr->values[j].type == OBJ_INT, "invalid element type"); assertf(arr->values[j].value.integer == tests[i].expected[j], "invalid integer value: expected %d, got %d", tests[i].expected[j], arr->values[j].value.integer); } @@ -413,7 +413,7 @@ static void array_literals() { } -static void mixed_arrays() { +static void mixed_arrays(void) { struct { const char *input; @@ -427,7 +427,7 @@ static void mixed_arrays() { } }; - for (int i = 0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i = 0; i < sizeof tests / sizeof tests[0]; i++) { struct object obj = run_vm_test(tests[i].input); assertf(obj.type == OBJ_ARRAY, "invalid obj type: expected \"%s\", got \"%s\"", object_type_to_str(OBJ_ARRAY), object_type_to_str(obj.type)); @@ -442,7 +442,7 @@ static void mixed_arrays() { } } -static void array_indexing() { +static void array_indexing(void) { test_case_t tests[] = { { "[1, 2, 3][1]", @@ -473,7 +473,7 @@ static void array_indexing() { run_tests(tests, ARRAY_SIZE(tests)); } -static void array_indexing_out_of_bounds() { +static void array_indexing_out_of_bounds(void) { test_case_t tests[] = { { "[0][1]", @@ -492,7 +492,7 @@ static void array_indexing_out_of_bounds() { run_tests(tests, ARRAY_SIZE(tests)); } -static void array_indexing_assignment() { +static void array_indexing_assignment(void) { test_case_t tests[] = { { "let arr = [1]; arr[0] = 2; arr[0]", @@ -515,7 +515,7 @@ static void array_indexing_assignment() { run_tests(tests, ARRAY_SIZE(tests)); } -static void array_pop() { +static void array_pop(void) { test_case_t tests[] = { { "array_pop([])", @@ -538,7 +538,7 @@ static void array_pop() { run_tests(tests, ARRAY_SIZE(tests)); } -static void array_push() { +static void array_push(void) { test_case_t tests[] = { { "array_push([], 1)", @@ -557,7 +557,7 @@ static void array_push() { run_tests(tests, ARRAY_SIZE(tests)); } -static void file_get_contents() { +static void file_get_contents(void) { test_case_t tests[] = { { "file_get_contents(\"tests/file.txt\")", @@ -572,12 +572,12 @@ static void file_get_contents() { run_tests(tests, ARRAY_SIZE(tests)); } -static void str_split() { +static void str_split(void) { struct { const char* input; char* expected[3]; - int nexpected; + unsigned nexpected; } tests[] = { { "str_split(\"a,b,c\", \",\")", @@ -596,12 +596,12 @@ static void str_split() { }, }; - for (int i = 0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i = 0; i < sizeof tests / sizeof tests[0]; i++) { struct object obj = run_vm_test(tests[i].input); assertf(obj.type == OBJ_ARRAY, "invalid obj type: expected \"%s\", got \"%s\"", object_type_to_str(OBJ_ARRAY), object_type_to_str(obj.type)); struct object_list* arr = obj.value.list; assertf(arr->size == tests[i].nexpected, "invalid array size: expected 3, got %d", arr->size); - for (int j=0; j < tests[i].nexpected; j++) { + for (unsigned j=0; j < tests[i].nexpected; j++) { assertf(arr->values[j].type == OBJ_STRING, "invalid type"); assertf(strcmp(arr->values[j].value.string->value, tests[i].expected[j]) == 0, "invalid string value: expected \"%s\", got \"%s\"", tests[i].expected[j], arr->values[j].value.string->value); } @@ -609,7 +609,7 @@ static void str_split() { } } -static void builtin_int() { +static void builtin_int(void) { struct { const char* input; @@ -621,13 +621,13 @@ static void builtin_int() { { "int(false)", 0 }, }; - for (int i = 0; i < sizeof tests / sizeof tests[0]; i++) { + for (unsigned i = 0; i < sizeof tests / sizeof tests[0]; i++) { struct object obj = run_vm_test(tests[i].input); test_object(obj, OBJ_INT, (object_value) { .integer = tests[i].expected } ); } } -static void var_assignment() { +static void var_assignment(void) { test_case_t tests[] = { { "let a = 1; a = 2; a", @@ -642,7 +642,7 @@ static void var_assignment() { run_tests(tests, ARRAY_SIZE(tests)); } -static void for_loops() { +static void for_loops(void) { test_case_t tests[] = { { "for (let i=0; i < 10; i = i + 1) { i }", @@ -681,7 +681,7 @@ static void for_loops() { run_tests(tests, ARRAY_SIZE(tests)); } -static void for_loops_break_statement() { +static void for_loops_break_statement(void) { test_case_t tests[] = { { "for (let i = 0; i < 3; i = i + 1) { break; } i;", @@ -704,7 +704,7 @@ static void for_loops_break_statement() { run_tests(tests, ARRAY_SIZE(tests)); } -static void for_loops_continue_statement() { +static void for_loops_continue_statement(void) { test_case_t tests[] = { { "for (let i = 0; i < 3; i = i + 1) { continue; };", @@ -723,7 +723,7 @@ static void for_loops_continue_statement() { run_tests(tests, ARRAY_SIZE(tests)); } -static void arrays_2d() { +static void arrays_2d(void) { test_case_t tests[] = { { "[[10, 11, 12], [20, 21,22 ]][0][0];", @@ -734,7 +734,7 @@ static void arrays_2d() { run_tests(tests, ARRAY_SIZE(tests)); } -static void string_indexing() { +static void string_indexing(void) { test_case_t tests[] = { { "let s = \"hello\"; s[1]", @@ -761,7 +761,7 @@ static void string_indexing() { run_tests(tests, ARRAY_SIZE(tests)); } -static void string_comparison() { +static void string_comparison(void) { test_case_t tests[] = { { "\"foo\" == \"bar\"", @@ -781,7 +781,7 @@ static void string_comparison() { } -static void postfix_expressions() { +static void postfix_expressions(void) { test_case_t tests[] = { { "let foo = 1; foo--;", EXPECT_INT(1) }, { "let foo = 1; foo--; foo", EXPECT_INT(0) }, @@ -797,7 +797,7 @@ static void postfix_expressions() { run_tests(tests, sizeof(tests) / sizeof(tests[0])); } -static void array_slices() { +static void array_slices(void) { test_case_t tests[] = { { "[0, 1, 2][0:1][0]", EXPECT_INT(0) }, { "[0, 1, 2][1:2][0]", EXPECT_INT(1) }, @@ -811,7 +811,7 @@ static void array_slices() { run_tests(tests, sizeof(tests) / sizeof(tests[0])); } -static void string_slices() { +static void string_slices(void) { test_case_t tests[] = { { "\"foobar\"[3:]", EXPECT_STRING("bar") }, { "\"foobar\"[100:]", EXPECT_STRING("") }, @@ -823,7 +823,7 @@ static void string_slices() { run_tests(tests, sizeof(tests) / sizeof(tests[0])); } -static void builtin_str_contains() { +static void builtin_str_contains(void) { test_case_t tests[] = { { "str_contains(\"foobar\", \"foo\");", EXPECT_BOOL(true) }, { "str_contains(\"foobar\", \"bar\");", EXPECT_BOOL(true) }, @@ -834,7 +834,7 @@ static void builtin_str_contains() { run_tests(tests, sizeof(tests) / sizeof(tests[0])); } -static void copies() { +static void copies(void) { test_case_t tests[] = { { "let a = fn() { 5 }; let b = a; a = 100; b();", EXPECT_INT(5) }, };