mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed a string comparison bug
This commit is contained in:
@@ -5,4 +5,7 @@ print false;
|
||||
print 42;
|
||||
print 3.14;
|
||||
print -69;
|
||||
print -4.20;
|
||||
print -4.20;
|
||||
print "hello world";
|
||||
print "hello world";
|
||||
print "hello world";
|
||||
|
||||
@@ -20,7 +20,7 @@ void initCompiler(Compiler* compiler) {
|
||||
|
||||
void writeCompiler(Compiler* compiler, Node* node) {
|
||||
//grow if the bytecode space is too small
|
||||
if (compiler->capacity < compiler->count + 8) { //assume 8 is the maximum space needed by each instruction (can change later)
|
||||
if (compiler->capacity < compiler->count + 1) {
|
||||
int oldCapacity = compiler->capacity;
|
||||
|
||||
compiler->capacity = GROW_CAPACITY(oldCapacity);
|
||||
|
||||
@@ -176,7 +176,7 @@ void dissectBytecode(const char* tb, int size) {
|
||||
break;
|
||||
|
||||
case LITERAL_STRING: {
|
||||
const s = printString(tb, &count);
|
||||
const char* s = printString(tb, &count);
|
||||
printf("(string)");
|
||||
}
|
||||
break;
|
||||
@@ -190,7 +190,7 @@ void dissectBytecode(const char* tb, int size) {
|
||||
//code
|
||||
printf("--bytecode--\n");
|
||||
while(tb[count] != OP_EOF) {
|
||||
const opcode = printByte(tb, &count);
|
||||
const unsigned char opcode = printByte(tb, &count);
|
||||
|
||||
switch (opcode) {
|
||||
case OP_PRINT:
|
||||
|
||||
@@ -56,29 +56,29 @@ int findLiteralIndex(LiteralArray* array, Literal literal) {
|
||||
if (AS_BOOLEAN(array->literals[i]) == AS_BOOLEAN(literal)) {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
|
||||
case LITERAL_INTEGER:
|
||||
if (AS_INTEGER(array->literals[i]) == AS_INTEGER(literal)) {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
|
||||
case LITERAL_FLOAT:
|
||||
if (AS_FLOAT(array->literals[i]) == AS_FLOAT(literal)) {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
|
||||
case LITERAL_STRING:
|
||||
if (strcmp(AS_STRING(array->literals[i]), AS_STRING(literal)) == 0) {
|
||||
if (strncmp(AS_STRING(array->literals[i]), AS_STRING(literal), STRLEN(literal)) == 0) {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
|
||||
continue;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "[Internal] Unexpected literal type in findLiteralIndex(): %d\n", literal.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ static void binary(Parser* parser, Node** nodeHandle, bool canBeAssigned) {
|
||||
|
||||
static void unary(Parser* parser, Node** nodeHandle, bool canBeAssigned) {
|
||||
switch(parser->previous.type) {
|
||||
case TOKEN_MINUS:
|
||||
case TOKEN_MINUS: {
|
||||
//temp handle to potentially negate values
|
||||
Node* tmpNode = NULL;
|
||||
parsePrecedence(parser, &tmpNode, PREC_TERNARY);
|
||||
@@ -157,7 +157,7 @@ static void unary(Parser* parser, Node** nodeHandle, bool canBeAssigned) {
|
||||
emitNodeUnary(nodeHandle, OP_NEGATE);
|
||||
parsePrecedence(parser, nodeHandle, PREC_TERNARY);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user