diff --git a/make.sh b/make.sh index 0061a75..f273625 100644 --- a/make.sh +++ b/make.sh @@ -5,5 +5,4 @@ gcc `find src/ -name '*.c'` \ submodules/utilitiec/build/lib/liballocator-interface.a \ submodules/utilitiec/build/lib/libStringView.a \ submodules/utilitiec/build/lib/libScratchpad.a \ - -Isubmodules/utilitiec/src \ -lm -ggdb -Wall -Wextra -pedantic -o bin/flup diff --git a/src/builtin-functions.c b/src/builtin-functions.c index adb3f0e..119e75b 100644 --- a/src/builtin-functions.c +++ b/src/builtin-functions.c @@ -23,7 +23,6 @@ #include #include -#include int BuiltinFunction_Equality(CallFrame* top_frame) { @@ -78,39 +77,6 @@ int BuiltinFunction_Plus(CallFrame* top_frame) return CallFrame_StackPush(top_frame, &result); } -int BuiltinFunction_Multiply(CallFrame* top_frame) -{ - Value v1; - Value v2; - - CallFrame_StackPop(top_frame, &v1); - if (CallFrame_StackPop(top_frame, &v2) != EXIT_SUCCESS) { - // TODO: Error message - return EXIT_FAILURE; - } - if (v1.type != v2.type) { - // TODO: Error message - return EXIT_FAILURE; - } - - Value result; - result.type = v1.type; - switch (v1.type) { - case VALUETYPE_INT64: - result.get.i64 = v2.get.i64 * v1.get.i64; - break; - case VALUETYPE_DOUBLE: - result.get.f64 = v2.get.f64 * v1.get.f64; - break; - case VALUETYPE_BOOLEAN: - result.get.boolean = v2.get.boolean * v1.get.boolean; - break; - } - - top_frame->instruction_pointer++; - return CallFrame_StackPush(top_frame, &result); -} - int BuiltinFunction_Minus(CallFrame* top_frame) { Value v1; @@ -155,7 +121,7 @@ int BuiltinFunction_PrintLine(CallFrame* top_frame) switch (v1.type) { case VALUETYPE_INT64: - printf("%" PRIi64 "\n", v1.get.i64); + printf("%i\n", v1.get.i64); break; case VALUETYPE_DOUBLE: printf("%f\n", v1.get.f64); diff --git a/src/builtin-functions.h b/src/builtin-functions.h index fb919a0..cd690a3 100644 --- a/src/builtin-functions.h +++ b/src/builtin-functions.h @@ -26,10 +26,9 @@ int BuiltinFunction_Minus(CallFrame* top_frame); int BuiltinFunction_Plus(CallFrame* top_frame); -int BuiltinFunction_Multiply(CallFrame* top_frame); int BuiltinFunction_Equality(CallFrame* top_frame); int BuiltinFunction_PrintLine(CallFrame* top_frame); int BuiltinFunction_Duplicate(CallFrame* top_frame); -#endif +#endif \ No newline at end of file diff --git a/src/interpreter.c b/src/interpreter.c index d8c9d01..1630364 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -360,11 +360,6 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token) BuiltinFunction_Minus(top_frame); break; } - case TOKENTYPE_MULTIPLY: - { - BuiltinFunction_Multiply(top_frame); - break; - } case TOKENTYPE_BIND: { @@ -483,6 +478,7 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token) case TOKENTYPE_LEFT_BRACE: case TOKENTYPE_RIGHT_BRACE: case TOKENTYPE_AMPERSAND: + case TOKENTYPE_MULTIPLY: case TOKENTYPE_DIVIDE: case TOKENTYPE_ARROW: case TOKENTYPE_COLON: @@ -494,7 +490,7 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token) case TOKENTYPE_COMMA: case TOKENTYPE_LEFT_PAREN: case TOKENTYPE_RIGHT_PAREN: - fprintf(stderr, "Unexpected token with type: %s, continuing with next token...\n", TokenType_ToString(t->type)); + fprintf(stderr, "Unexpected token with type: %s\n, continuing with next token...\n", TokenType_ToString(t->type)); top_frame->instruction_pointer++; break; diff --git a/src/main.c b/src/main.c index 3d83bea..4e9bba1 100644 --- a/src/main.c +++ b/src/main.c @@ -56,10 +56,10 @@ char* load_file_string(StringView path) return NULL; } - if (fseek(stream, 0, SEEK_SET)) { - perror("fseek"); - return NULL; - } + if (fseek(stream, 0, SEEK_SET)) { + perror("fseek"); + return NULL; + } char* buffer = malloc(length + 1); if (buffer == NULL) { @@ -68,8 +68,9 @@ char* load_file_string(StringView path) } size_t objects_read = fread(buffer, 1, length, stream); - if (objects_read != (size_t) length) { + if (objects_read != length) { fprintf(stderr, "Fatal Error: Failed read %li bytes from script file, got only %li\n", length, objects_read); + ; free(buffer); return NULL; } diff --git a/test-inputs/factorial.flup b/test-inputs/factorial.flup deleted file mode 100644 index 1e6e681..0000000 --- a/test-inputs/factorial.flup +++ /dev/null @@ -1,6 +0,0 @@ -factorial: int n -> int - | n 0 == -> 1 - | 1 -> n 1 - factorial n * duplicate println - ; - -25 factorial