mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Tweaked error messages
This commit is contained in:
@@ -53,7 +53,7 @@ static int writeNodeCompoundToCache(Compiler* compiler, Node* node) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "[Internal] Unrecognized key node type in writeNodeCompoundToCache()");
|
fprintf(stderr, ERROR "[internal] Unrecognized key node type in writeNodeCompoundToCache()" RESET);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ static int writeNodeCompoundToCache(Compiler* compiler, Node* node) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "[Internal] Unrecognized value node type in writeNodeCompoundToCache()");
|
fprintf(stderr, ERROR "[internal] Unrecognized value node type in writeNodeCompoundToCache()" RESET);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ static int writeNodeCompoundToCache(Compiler* compiler, Node* node) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "[Internal] Unrecognized node type in writeNodeCompoundToCache()");
|
fprintf(stderr, ERROR "[internal] Unrecognized node type in writeNodeCompoundToCache()" RESET);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ static int writeNodeCompoundToCache(Compiler* compiler, Node* node) {
|
|||||||
index = pushLiteralArray(&compiler->literalCache, TO_ARRAY_LITERAL(store));
|
index = pushLiteralArray(&compiler->literalCache, TO_ARRAY_LITERAL(store));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "[Internal] Unrecognized compound type in writeNodeCompoundToCache()");
|
fprintf(stderr, ERROR "[Internal] Unrecognized compound type in writeNodeCompoundToCache()" RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
@@ -444,7 +444,7 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd
|
|||||||
|
|
||||||
case NODE_PATH_BREAK: {
|
case NODE_PATH_BREAK: {
|
||||||
if (!breakAddressesPtr) {
|
if (!breakAddressesPtr) {
|
||||||
fprintf(stderr, "Can't place a break statement here\n");
|
fprintf(stderr, ERROR "ERROR: Can't place a break statement here\n" RESET);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd
|
|||||||
|
|
||||||
case NODE_PATH_CONTINUE: {
|
case NODE_PATH_CONTINUE: {
|
||||||
if (!continueAddressesPtr) {
|
if (!continueAddressesPtr) {
|
||||||
fprintf(stderr, "Can't place a continue statement here\n");
|
fprintf(stderr, ERROR "ERROR: Can't place a continue statement here\n" RESET);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +730,7 @@ unsigned char* collateCompiler(Compiler* compiler, int* size) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "[Internal] Unknown literal type encountered within literal cache: %d\n", compiler->literalCache.literals[i].type);
|
fprintf(stderr, ERROR "[internal] Unknown literal type encountered within literal cache: %d\n" RESET, compiler->literalCache.literals[i].type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void stdoutWrapper(const char* output) {
|
static void stdoutWrapper(const char* output) {
|
||||||
fprintf(stdout, "%s", output);
|
printf("%s", output);
|
||||||
fprintf(stdout, "\n"); //default new line
|
printf("\n"); //default new line
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stderrWrapper(const char* output) {
|
static void stderrWrapper(const char* output) {
|
||||||
fprintf(stderr, "Assertion failure: ");
|
fprintf(stderr, ERROR "Assertion failure: ");
|
||||||
fprintf(stderr, "%s", output);
|
fprintf(stderr, "%s", output);
|
||||||
fprintf(stderr, "\n"); //default new line
|
fprintf(stderr, "\n" RESET); //default new line
|
||||||
}
|
}
|
||||||
|
|
||||||
void initInterpreter(Interpreter* interpreter) {
|
void initInterpreter(Interpreter* interpreter) {
|
||||||
@@ -114,9 +114,9 @@ static bool parseIdentifierToValue(Interpreter* interpreter, Literal* literalPtr
|
|||||||
//this converts identifiers to values
|
//this converts identifiers to values
|
||||||
if (IS_IDENTIFIER(*literalPtr)) {
|
if (IS_IDENTIFIER(*literalPtr)) {
|
||||||
if (!getScopeVariable(interpreter->scope, *literalPtr, literalPtr)) {
|
if (!getScopeVariable(interpreter->scope, *literalPtr, literalPtr)) {
|
||||||
printf("Undeclared variable \"");;
|
printf(ERROR "Error: Undeclared variable \"");;
|
||||||
printLiteral(*literalPtr);
|
printLiteral(*literalPtr);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,9 +131,9 @@ static bool execAssert(Interpreter* interpreter) {
|
|||||||
parseIdentifierToValue(interpreter, &lhs);
|
parseIdentifierToValue(interpreter, &lhs);
|
||||||
|
|
||||||
if (!IS_STRING(rhs)) {
|
if (!IS_STRING(rhs)) {
|
||||||
printf("The assert keyword needs a string as the second argument, received: ");
|
printf(ERROR "ERROR: The assert keyword needs a string as the second argument, received: ");
|
||||||
printLiteral(rhs);
|
printLiteral(rhs);
|
||||||
printf("\n");
|
printf("\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +203,9 @@ static bool execNegate(Interpreter* interpreter) {
|
|||||||
lit = TO_FLOAT_LITERAL(-AS_FLOAT(lit));
|
lit = TO_FLOAT_LITERAL(-AS_FLOAT(lit));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("[internal] The interpreter can't negate that literal: ");
|
printf(ERROR "[internal] The interpreter can't negate that literal: ");
|
||||||
printLiteral(lit);
|
printLiteral(lit);
|
||||||
printf("\n");
|
printf("\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,9 +225,9 @@ static bool execInvert(Interpreter* interpreter) {
|
|||||||
lit = TO_BOOLEAN_LITERAL(!AS_BOOLEAN(lit));
|
lit = TO_BOOLEAN_LITERAL(!AS_BOOLEAN(lit));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("[internal] The interpreter can't invert that literal: ");
|
printf(ERROR "[internal] The interpreter can't invert that literal: ");
|
||||||
printLiteral(lit);
|
printLiteral(lit);
|
||||||
printf("\n");
|
printf("\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ static bool execArithmetic(Interpreter* interpreter, Opcode opcode) {
|
|||||||
if (IS_STRING(lhs) && IS_STRING(rhs)) {
|
if (IS_STRING(lhs) && IS_STRING(rhs)) {
|
||||||
//check for overflow
|
//check for overflow
|
||||||
if (STRLEN(lhs) + STRLEN(rhs) > MAX_STRING_LENGTH) {
|
if (STRLEN(lhs) + STRLEN(rhs) > MAX_STRING_LENGTH) {
|
||||||
printf("Can't concatenate these strings (result is too long)\n");
|
printf(ERROR "ERROR: Can't concatenate these strings (result is too long)\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ static bool execArithmetic(Interpreter* interpreter, Opcode opcode) {
|
|||||||
|
|
||||||
case OP_DIVISION:
|
case OP_DIVISION:
|
||||||
if (AS_INTEGER(rhs) == 0) {
|
if (AS_INTEGER(rhs) == 0) {
|
||||||
printf("Can't divide by zero (error found in interpreter)");
|
printf(ERROR "ERROR: Can't divide by zero (error found in interpreter)" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pushLiteralArray(&interpreter->stack, TO_INTEGER_LITERAL( AS_INTEGER(lhs) / AS_INTEGER(rhs) ));
|
pushLiteralArray(&interpreter->stack, TO_INTEGER_LITERAL( AS_INTEGER(lhs) / AS_INTEGER(rhs) ));
|
||||||
@@ -292,7 +292,7 @@ static bool execArithmetic(Interpreter* interpreter, Opcode opcode) {
|
|||||||
|
|
||||||
case OP_MODULO:
|
case OP_MODULO:
|
||||||
if (AS_INTEGER(rhs) == 0) {
|
if (AS_INTEGER(rhs) == 0) {
|
||||||
printf("Can't modulo by zero (error found in interpreter)");
|
printf(ERROR "ERROR: Can't modulo by zero (error found in interpreter)" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pushLiteralArray(&interpreter->stack, TO_INTEGER_LITERAL( AS_INTEGER(lhs) % AS_INTEGER(rhs) ));
|
pushLiteralArray(&interpreter->stack, TO_INTEGER_LITERAL( AS_INTEGER(lhs) % AS_INTEGER(rhs) ));
|
||||||
@@ -306,7 +306,7 @@ static bool execArithmetic(Interpreter* interpreter, Opcode opcode) {
|
|||||||
|
|
||||||
//catch bad modulo
|
//catch bad modulo
|
||||||
if (opcode == OP_MODULO) {
|
if (opcode == OP_MODULO) {
|
||||||
printf("Bad arithmetic argument (modulo on floats not allowed)\n");
|
printf(ERROR "ERROR: Bad arithmetic argument (modulo on floats not allowed)\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,24 +326,24 @@ static bool execArithmetic(Interpreter* interpreter, Opcode opcode) {
|
|||||||
|
|
||||||
case OP_DIVISION:
|
case OP_DIVISION:
|
||||||
if (AS_FLOAT(rhs) == 0) {
|
if (AS_FLOAT(rhs) == 0) {
|
||||||
printf("Can't divide by zero (error found in interpreter)");
|
printf(ERROR "ERROR: Can't divide by zero (error found in interpreter)" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pushLiteralArray(&interpreter->stack, TO_FLOAT_LITERAL( AS_FLOAT(lhs) / AS_FLOAT(rhs) ));
|
pushLiteralArray(&interpreter->stack, TO_FLOAT_LITERAL( AS_FLOAT(lhs) / AS_FLOAT(rhs) ));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("[internal] bad opcode argument passed to execArithmetic()");
|
printf(ERROR "[internal] bad opcode argument passed to execArithmetic()" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//wrong types
|
//wrong types
|
||||||
printf("Bad arithmetic argument ");
|
printf(ERROR "ERROR: Bad arithmetic argument ");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf(" and ");
|
printf(" and ");
|
||||||
printLiteral(rhs);
|
printLiteral(rhs);
|
||||||
printf("\n");
|
printf("\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,9 +367,9 @@ static bool execVarDecl(Interpreter* interpreter, bool lng) {
|
|||||||
parseIdentifierToValue(interpreter, &type);
|
parseIdentifierToValue(interpreter, &type);
|
||||||
|
|
||||||
if (!declareScopeVariable(interpreter->scope, identifier, type)) {
|
if (!declareScopeVariable(interpreter->scope, identifier, type)) {
|
||||||
printf("Can't redefine the variable \"");
|
printf(ERROR "ERROR: Can't redefine the variable \"");
|
||||||
printLiteral(identifier);
|
printLiteral(identifier);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,9 +377,9 @@ static bool execVarDecl(Interpreter* interpreter, bool lng) {
|
|||||||
parseIdentifierToValue(interpreter, &val);
|
parseIdentifierToValue(interpreter, &val);
|
||||||
|
|
||||||
if (!IS_NULL(val) && !setScopeVariable(interpreter->scope, identifier, val, false)) {
|
if (!IS_NULL(val) && !setScopeVariable(interpreter->scope, identifier, val, false)) {
|
||||||
printf("Incorrect type assigned to variable \"");
|
printf(ERROR "ERROR: Incorrect type assigned to variable \"");
|
||||||
printLiteral(identifier);
|
printLiteral(identifier);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,23 +393,23 @@ static bool execVarAssign(Interpreter* interpreter) {
|
|||||||
parseIdentifierToValue(interpreter, &rhs);
|
parseIdentifierToValue(interpreter, &rhs);
|
||||||
|
|
||||||
if (!IS_IDENTIFIER(lhs)) {
|
if (!IS_IDENTIFIER(lhs)) {
|
||||||
printf("Can't assign to a non-variable \"");
|
printf(ERROR "ERROR: Can't assign to a non-variable \"");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDelcaredScopeVariable(interpreter->scope, lhs)) {
|
if (!isDelcaredScopeVariable(interpreter->scope, lhs)) {
|
||||||
printf("Undeclared variable \"");
|
printf(ERROR "ERROR: Undeclared variable \"");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!setScopeVariable(interpreter->scope, lhs, rhs, true)) {
|
if (!setScopeVariable(interpreter->scope, lhs, rhs, true)) {
|
||||||
printf("Incorrect type assigned to variable \"");
|
printf(ERROR "ERROR Incorrect type assigned to variable \"");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ static bool execValCast(Interpreter* interpreter) {
|
|||||||
Literal result = TO_NULL_LITERAL;
|
Literal result = TO_NULL_LITERAL;
|
||||||
|
|
||||||
if (IS_NULL(value)) {
|
if (IS_NULL(value)) {
|
||||||
printf("Can't cast a null value\n");
|
printf(ERROR "ERROR: Can't cast a null value\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,7 +488,7 @@ static bool execValCast(Interpreter* interpreter) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("Unknown cast type found %d, terminating\n", AS_TYPE(type).typeOf);
|
printf(ERROR"ERROR: Unknown cast type found %d, terminating\n" RESET, AS_TYPE(type).typeOf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,16 +524,16 @@ static bool execCompareLess(Interpreter* interpreter, bool invert) {
|
|||||||
|
|
||||||
//not a number, return falure
|
//not a number, return falure
|
||||||
if (!(IS_INTEGER(lhs) || IS_FLOAT(lhs))) {
|
if (!(IS_INTEGER(lhs) || IS_FLOAT(lhs))) {
|
||||||
printf("Incorrect type in comparison, value \"");
|
printf(ERROR "ERROR: Incorrect type in comparison, value \"");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(IS_INTEGER(rhs) || IS_FLOAT(rhs))) {
|
if (!(IS_INTEGER(rhs) || IS_FLOAT(rhs))) {
|
||||||
printf("Incorrect type in comparison, value \"");
|
printf(ERROR "ERROR: Incorrect type in comparison, value \"");
|
||||||
printLiteral(rhs);
|
printLiteral(rhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,16 +569,16 @@ static bool execCompareLessEqual(Interpreter* interpreter, bool invert) {
|
|||||||
|
|
||||||
//not a number, return falure
|
//not a number, return falure
|
||||||
if (!(IS_INTEGER(lhs) || IS_FLOAT(lhs))) {
|
if (!(IS_INTEGER(lhs) || IS_FLOAT(lhs))) {
|
||||||
printf("Incorrect type in comparison, value \"");
|
printf(ERROR "ERROR: Incorrect type in comparison, value \"");
|
||||||
printLiteral(lhs);
|
printLiteral(lhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(IS_INTEGER(rhs) || IS_FLOAT(rhs))) {
|
if (!(IS_INTEGER(rhs) || IS_FLOAT(rhs))) {
|
||||||
printf("Incorrect type in comparison, value \"");
|
printf(ERROR "ERROR: Incorrect type in comparison, value \"");
|
||||||
printLiteral(rhs);
|
printLiteral(rhs);
|
||||||
printf("\"\n");
|
printf("\"\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +609,7 @@ static bool execJump(Interpreter* interpreter) {
|
|||||||
int target = (int)readShort(interpreter->bytecode, &interpreter->count);
|
int target = (int)readShort(interpreter->bytecode, &interpreter->count);
|
||||||
|
|
||||||
if (target + interpreter->codeStart > interpreter->length) {
|
if (target + interpreter->codeStart > interpreter->length) {
|
||||||
printf("Jump out of range\n");
|
printf(ERROR "[internal] Jump out of range\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,7 +623,7 @@ static bool execFalseJump(Interpreter* interpreter) {
|
|||||||
int target = (int)readShort(interpreter->bytecode, &interpreter->count);
|
int target = (int)readShort(interpreter->bytecode, &interpreter->count);
|
||||||
|
|
||||||
if (target + interpreter->codeStart > interpreter->length) {
|
if (target + interpreter->codeStart > interpreter->length) {
|
||||||
printf("Jump out of range (false jump)\n");
|
printf(ERROR "[internal] Jump out of range (false jump)\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,7 +635,7 @@ static bool execFalseJump(Interpreter* interpreter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (IS_NULL(lit)) {
|
if (IS_NULL(lit)) {
|
||||||
printf("Null detected in comparison\n");
|
printf(ERROR "Error: Null detected in comparison\n" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,7 +785,7 @@ static void execInterpreter(Interpreter* interpreter) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("Unknown opcode found %d, terminating\n", opcode);
|
printf(ERROR "Error: Unknown opcode found %d, terminating\n" RESET, opcode);
|
||||||
printLiteralArray(&interpreter->stack, "\n");
|
printLiteralArray(&interpreter->stack, "\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "literal_array.h"
|
#include "literal_array.h"
|
||||||
#include "literal_dictionary.h"
|
#include "literal_dictionary.h"
|
||||||
|
|
||||||
|
#include "console_colors.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -265,7 +267,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
//should never be seen
|
//should never be seen
|
||||||
fprintf(stderr, "[Internal] Unrecognized literal type in print type: %d\n", AS_TYPE(literal).typeOf);
|
fprintf(stderr, ERROR "[internal] Unrecognized literal type in print type: %d\n" RESET, AS_TYPE(literal).typeOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
//const (printed last)
|
//const (printed last)
|
||||||
@@ -293,7 +295,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
//should never bee seen
|
//should never bee seen
|
||||||
fprintf(stderr, "[Internal] Unrecognized literal type in print: %d\n", literal.type);
|
fprintf(stderr, ERROR "[internal] Unrecognized literal type in print: %d\n" RESET, literal.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +329,7 @@ void freeLiteral(Literal literal) {
|
|||||||
|
|
||||||
bool _isTruthy(Literal x) {
|
bool _isTruthy(Literal x) {
|
||||||
if (IS_NULL(x)) {
|
if (IS_NULL(x)) {
|
||||||
fprintf(stderr, "Null is neither true nor false");
|
fprintf(stderr, ERROR "ERROR: Null is neither true nor false" RESET);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +478,7 @@ bool literalsAreEqual(Literal lhs, Literal rhs) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
//should never bee seen
|
//should never bee seen
|
||||||
fprintf(stderr, "[Internal] Unrecognized literal type in equality: %d\n", lhs.type);
|
fprintf(stderr, ERROR "[internal] Unrecognized literal type in equality: %d\n" RESET, lhs.type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,7 +533,7 @@ int hashLiteral(Literal lit) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
//should never bee seen
|
//should never bee seen
|
||||||
fprintf(stderr, "[Internal] Unrecognized literal type in hash: %d\n", lit.type);
|
fprintf(stderr, ERROR "[internal] Unrecognized literal type in hash: %d\n" RESET, lit.type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#include "console_colors.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
//util functions
|
//util functions
|
||||||
@@ -173,7 +175,7 @@ void freeLiteralDictionary(LiteralDictionary* dictionary) {
|
|||||||
|
|
||||||
void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal value) {
|
void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal value) {
|
||||||
if (IS_NULL(key)) {
|
if (IS_NULL(key)) {
|
||||||
fprintf(stderr, "[Internal] Dictionaries can't have null keys\n");
|
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys\n" RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +188,7 @@ void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal va
|
|||||||
|
|
||||||
Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
|
Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
|
||||||
if (IS_NULL(key)) {
|
if (IS_NULL(key)) {
|
||||||
fprintf(stderr, "[Internal] Dictionaries can't have null keys\n");
|
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys\n" RESET);
|
||||||
return TO_NULL_LITERAL;
|
return TO_NULL_LITERAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +204,7 @@ Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
|
|||||||
|
|
||||||
void removeLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
|
void removeLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
|
||||||
if (IS_NULL(key)) {
|
if (IS_NULL(key)) {
|
||||||
fprintf(stderr, "[Internal] Dictionaries can't have null keys\n");
|
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys\n" RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#include "console_colors.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -13,7 +15,7 @@ void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
|
|||||||
void* mem = realloc(pointer, newSize);
|
void* mem = realloc(pointer, newSize);
|
||||||
|
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
fprintf(stderr, "[Internal]Memory allocation error (requested %d for %d, replacing %d)\n", (int)newSize, (int)pointer, (int)oldSize);
|
fprintf(stderr, ERROR "[internal]Memory allocation error (requested %d for %d, replacing %d)\n" ERROR, (int)newSize, (int)pointer, (int)oldSize);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ static void error(Parser* parser, Token token, const char* message) {
|
|||||||
//keep going while panicing
|
//keep going while panicing
|
||||||
if (parser->panic) return;
|
if (parser->panic) return;
|
||||||
|
|
||||||
fprintf(stderr, "[Line %d] Error", token.line);
|
fprintf(stderr, ERROR "[Line %d] Error", token.line);
|
||||||
|
|
||||||
//check type
|
//check type
|
||||||
if (token.type == TOKEN_EOF) {
|
if (token.type == TOKEN_EOF) {
|
||||||
@@ -27,7 +27,7 @@ static void error(Parser* parser, Token token, const char* message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//finally
|
//finally
|
||||||
fprintf(stderr, ": %s\n", message);
|
fprintf(stderr, ": %s\n" RESET, message);
|
||||||
parser->error = true;
|
parser->error = true;
|
||||||
parser->panic = true;
|
parser->panic = true;
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ static void consume(Parser* parser, TokenType tokenType, const char* msg) {
|
|||||||
|
|
||||||
static void synchronize(Parser* parser) {
|
static void synchronize(Parser* parser) {
|
||||||
if (command.verbose) {
|
if (command.verbose) {
|
||||||
printf(ERROR "synchronizing\n" RESET);
|
fprintf(stderr, ERROR "synchronizing\n" RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (parser->current.type != TOKEN_EOF) {
|
while (parser->current.type != TOKEN_EOF) {
|
||||||
@@ -244,7 +244,7 @@ static Opcode string(Parser* parser, Node** nodeHandle) {
|
|||||||
if (length > MAX_STRING_LENGTH) {
|
if (length > MAX_STRING_LENGTH) {
|
||||||
length = MAX_STRING_LENGTH;
|
length = MAX_STRING_LENGTH;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
snprintf(buffer, 256, "Strings can only be a maximum of %d characters long", MAX_STRING_LENGTH);
|
snprintf(buffer, 256, ERROR "Strings can only be a maximum of %d characters long" RESET, MAX_STRING_LENGTH);
|
||||||
error(parser, parser->previous, buffer);
|
error(parser, parser->previous, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,14 +781,14 @@ static bool calcStaticBinaryArithmetic(Parser* parser, Node** nodeHandle) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("[internal] bad opcode argument passed to calcStaticBinaryArithmetic()");
|
error(parser, parser->previous, "[internal] bad opcode argument passed to calcStaticBinaryArithmetic()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//catch bad modulo
|
//catch bad modulo
|
||||||
if ((IS_FLOAT(lhs) || IS_FLOAT(rhs)) && (*nodeHandle)->binary.opcode == OP_MODULO) {
|
if ((IS_FLOAT(lhs) || IS_FLOAT(rhs)) && (*nodeHandle)->binary.opcode == OP_MODULO) {
|
||||||
printf("Bad arithmetic argument (modulo on floats not allowed)");
|
error(parser, parser->previous, "Bad arithmetic argument (modulo on floats not allowed)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,7 +839,7 @@ static bool calcStaticBinaryArithmetic(Parser* parser, Node** nodeHandle) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("[internal] bad opcode argument passed to calcStaticBinaryArithmetic()");
|
error(parser, parser->previous, "[internal] bad opcode argument passed to calcStaticBinaryArithmetic()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ char* readFile(char* path, size_t* fileSize) {
|
|||||||
FILE* file = fopen(path, "rb");
|
FILE* file = fopen(path, "rb");
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
fprintf(stderr, "Could not open file \"%s\"\n", path);
|
fprintf(stderr, ERROR "Could not open file \"%s\"\n" RESET, path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ char* readFile(char* path, size_t* fileSize) {
|
|||||||
char* buffer = (char*)malloc(*fileSize + 1);
|
char* buffer = (char*)malloc(*fileSize + 1);
|
||||||
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
fprintf(stderr, "Not enough memory to read \"%s\"\n", path);
|
fprintf(stderr, ERROR "Not enough memory to read \"%s\"\n" RESET, path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ char* readFile(char* path, size_t* fileSize) {
|
|||||||
buffer[*fileSize] = '\0'; //NOTE: fread doesn't append this
|
buffer[*fileSize] = '\0'; //NOTE: fread doesn't append this
|
||||||
|
|
||||||
if (bytesRead < *fileSize) {
|
if (bytesRead < *fileSize) {
|
||||||
fprintf(stderr, "Could not read file \"%s\"\n", path);
|
fprintf(stderr, ERROR "Could not read file \"%s\"\n" RESET, path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,14 +49,14 @@ void writeFile(char* path, unsigned char* bytes, size_t size) {
|
|||||||
FILE* file = fopen(path, "wb");
|
FILE* file = fopen(path, "wb");
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
fprintf(stderr, "Could not open file \"%s\"\n", path);
|
fprintf(stderr, ERROR "Could not open file \"%s\"\n" RESET, path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int written = fwrite(bytes, size, 1, file);
|
int written = fwrite(bytes, size, 1, file);
|
||||||
|
|
||||||
if (written != 1) {
|
if (written != 1) {
|
||||||
fprintf(stderr, "Could not write file \"%s\"\n", path);
|
fprintf(stderr, ERROR "Could not write file \"%s\"\n" RESET, path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user