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:
@@ -6,3 +6,6 @@ print 42;
|
|||||||
print 3.14;
|
print 3.14;
|
||||||
print -69;
|
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) {
|
void writeCompiler(Compiler* compiler, Node* node) {
|
||||||
//grow if the bytecode space is too small
|
//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;
|
int oldCapacity = compiler->capacity;
|
||||||
|
|
||||||
compiler->capacity = GROW_CAPACITY(oldCapacity);
|
compiler->capacity = GROW_CAPACITY(oldCapacity);
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ void dissectBytecode(const char* tb, int size) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LITERAL_STRING: {
|
case LITERAL_STRING: {
|
||||||
const s = printString(tb, &count);
|
const char* s = printString(tb, &count);
|
||||||
printf("(string)");
|
printf("(string)");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -190,7 +190,7 @@ void dissectBytecode(const char* tb, int size) {
|
|||||||
//code
|
//code
|
||||||
printf("--bytecode--\n");
|
printf("--bytecode--\n");
|
||||||
while(tb[count] != OP_EOF) {
|
while(tb[count] != OP_EOF) {
|
||||||
const opcode = printByte(tb, &count);
|
const unsigned char opcode = printByte(tb, &count);
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case OP_PRINT:
|
case OP_PRINT:
|
||||||
|
|||||||
@@ -56,29 +56,29 @@ int findLiteralIndex(LiteralArray* array, Literal literal) {
|
|||||||
if (AS_BOOLEAN(array->literals[i]) == AS_BOOLEAN(literal)) {
|
if (AS_BOOLEAN(array->literals[i]) == AS_BOOLEAN(literal)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
case LITERAL_INTEGER:
|
case LITERAL_INTEGER:
|
||||||
if (AS_INTEGER(array->literals[i]) == AS_INTEGER(literal)) {
|
if (AS_INTEGER(array->literals[i]) == AS_INTEGER(literal)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
case LITERAL_FLOAT:
|
case LITERAL_FLOAT:
|
||||||
if (AS_FLOAT(array->literals[i]) == AS_FLOAT(literal)) {
|
if (AS_FLOAT(array->literals[i]) == AS_FLOAT(literal)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
case LITERAL_STRING:
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
continue;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "[Internal] Unexpected literal type in findLiteralIndex(): %d\n", literal.type);
|
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) {
|
static void unary(Parser* parser, Node** nodeHandle, bool canBeAssigned) {
|
||||||
switch(parser->previous.type) {
|
switch(parser->previous.type) {
|
||||||
case TOKEN_MINUS:
|
case TOKEN_MINUS: {
|
||||||
//temp handle to potentially negate values
|
//temp handle to potentially negate values
|
||||||
Node* tmpNode = NULL;
|
Node* tmpNode = NULL;
|
||||||
parsePrecedence(parser, &tmpNode, PREC_TERNARY);
|
parsePrecedence(parser, &tmpNode, PREC_TERNARY);
|
||||||
@@ -157,7 +157,7 @@ static void unary(Parser* parser, Node** nodeHandle, bool canBeAssigned) {
|
|||||||
emitNodeUnary(nodeHandle, OP_NEGATE);
|
emitNodeUnary(nodeHandle, OP_NEGATE);
|
||||||
parsePrecedence(parser, nodeHandle, PREC_TERNARY);
|
parsePrecedence(parser, nodeHandle, PREC_TERNARY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user