Skip to content

Commit

Permalink
Fixed the lines marked as 'URGENT'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Nov 22, 2024
1 parent 7d4ea48 commit 0b559ec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ repl: source
.PHONY: tests
tests: clean test-cases test-integrations

#.PHONY: test-all
#test-all: clean test-cases test-integrations

.PHONY: test-cases
test-cases:
$(MAKE) -C $(TOY_CASESDIR) -k
Expand Down Expand Up @@ -62,6 +59,10 @@ test-cases-valgrind:
test-integrations-valgrind:
$(MAKE) -C $(TOY_INTEGRATIONSDIR) valgrind -k

#Run all tests
.PHONY: tests-all
tests-all: clean tests tests-gdb tests-valgrind

#TODO: mustfail tests

#util targets
Expand Down
2 changes: 1 addition & 1 deletion scripts/a.toy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

//TODO: mustfails

var a = 0;
var b = a = a + 1, 6;

10 changes: 5 additions & 5 deletions source/toy_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Toy_String* Toy_concatStrings(Toy_Bucket** bucketHandle, Toy_String* left, Toy_S
ret->as.node.left = left;
ret->as.node.right = right;

incrementRefCount(left);//URGENT: improve
incrementRefCount(left);
incrementRefCount(right);

return ret;
Expand Down Expand Up @@ -253,12 +253,12 @@ static int deepCompareUtil(Toy_String* left, Toy_String* right, const char** lef
}

//BUGFIX: if we're not currently iterating through the left leaf (and leftHead is not null), skip out
if (left->type == TOY_STRING_LEAF && (*leftHead) != NULL && (**leftHead) != '\0' && ((*leftHead) < left->as.leaf.data || (*leftHead) > (left->as.leaf.data + strlen(left->as.leaf.data))) ) { //URGENT: replace strlen with the stored lengths
if (left->type == TOY_STRING_LEAF && (*leftHead) != NULL && (**leftHead) != '\0' && ((*leftHead) < left->as.leaf.data || (*leftHead) > (left->as.leaf.data + left->length)) ) {
return result;
}

//BUGFIX: if we're not currently iterating through the right leaf (and rightHead is not null), skip out
if (right->type == TOY_STRING_LEAF && (*rightHead) != NULL && (**rightHead) != '\0' && ((*rightHead) < right->as.leaf.data || (*rightHead) > (right->as.leaf.data + strlen(right->as.leaf.data))) ) {
if (right->type == TOY_STRING_LEAF && (*rightHead) != NULL && (**rightHead) != '\0' && ((*rightHead) < right->as.leaf.data || (*rightHead) > (right->as.leaf.data + right->length)) ) {
return result;
}

Expand Down Expand Up @@ -328,7 +328,7 @@ int Toy_compareStrings(Toy_String* left, Toy_String* right) {
exit(-1);
}

return strcmp(left->as.name.data, right->as.name.data); //URGENT: strncmp
return strncmp(left->as.name.data, right->as.name.data, left->length);
}

//util pointers
Expand All @@ -343,7 +343,7 @@ unsigned int Toy_hashString(Toy_String* str) {
return str->cachedHash;
}
else if (str->type == TOY_STRING_NODE) {
//TODO: I wonder if it would be possible to discretely swap the composite node string with a new leaf string here? Would that speed up other parts of the code by not having to walk the tree in future?
//TODO: I wonder if it would be possible to discretely swap the composite node string with a new leaf string here? Would that speed up other parts of the code by not having to walk the tree in future? - needs to be benchmarked
char* buffer = Toy_getStringRawBuffer(str);
str->cachedHash = hashCString(buffer);
free(buffer);
Expand Down
7 changes: 6 additions & 1 deletion source/toy_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void processArithmetic(Toy_VM* vm, Toy_OpcodeType opcode) {
}

static void processComparison(Toy_VM* vm, Toy_OpcodeType opcode) {
Toy_Value right = Toy_popStack(&vm->stack); //URGENT: These are not freed correctly
Toy_Value right = Toy_popStack(&vm->stack);
Toy_Value left = Toy_popStack(&vm->stack);

//most things can be equal, so handle it separately
Expand All @@ -297,6 +297,8 @@ static void processComparison(Toy_VM* vm, Toy_OpcodeType opcode) {
Toy_pushStack(&vm->stack, TOY_VALUE_FROM_BOOLEAN(!equal) );
}

Toy_freeValue(left);
Toy_freeValue(right);
return;
}

Expand Down Expand Up @@ -330,6 +332,9 @@ static void processComparison(Toy_VM* vm, Toy_OpcodeType opcode) {
else {
Toy_pushStack(&vm->stack, TOY_VALUE_FROM_BOOLEAN(false));
}

Toy_freeValue(left);
Toy_freeValue(right);
}

static void processLogical(Toy_VM* vm, Toy_OpcodeType opcode) {
Expand Down

0 comments on commit 0b559ec

Please sign in to comment.