Skip to content

Commit

Permalink
WIP: Fixed print bug, tests incomplete, read more
Browse files Browse the repository at this point in the history
I was sidetracked by a strange display bug - turns out it was caused by
pointers - this commit fixes it.

The tests for if-then-else still aren't finished, but I'm knocking off
as it's past my time limit. I've marked 'TODO' and 'URGENT' using
comments, so finding the issues should be easy.
  • Loading branch information
Ratstail91 committed Nov 22, 2024
1 parent b29a878 commit 7d4ea48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions source/toy_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void processRead(Toy_VM* vm) {
int len = (int)READ_BYTE(vm);

//grab the jump as an integer
unsigned int jump = vm->module[ vm->jumpsAddr + READ_INT(vm) ];
unsigned int jump = *((int*)(vm->module + vm->jumpsAddr + READ_INT(vm)));

//jumps are relative to the data address
char* cstring = (char*)(vm->module + vm->dataAddr + jump);
Expand Down 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);
Toy_Value right = Toy_popStack(&vm->stack); //URGENT: These are not freed correctly
Toy_Value left = Toy_popStack(&vm->stack);

//most things can be equal, so handle it separately
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/test_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ int test_string_equality() {
Toy_Bucket* bucket = Toy_allocateBucket(1024);
Toy_String* helloWorldOne = Toy_createNameStringLength(&bucket, "Hello world", strlen("Hello world"), TOY_VALUE_UNKNOWN, false);
Toy_String* helloWorldTwo = Toy_createNameStringLength(&bucket, "Hello world", strlen("Hello world"), TOY_VALUE_UNKNOWN, false);
Toy_String* helloEveryone = Toy_createNameStringLength(&bucket, "Hello everyone", strlen("Hello everyone"), TOY_VALUE_UNKNOWN, false); //TODO: compare types?
Toy_String* helloEveryone = Toy_createNameStringLength(&bucket, "Hello everyone", strlen("Hello everyone"), TOY_VALUE_UNKNOWN, false);

int result = 0; //for print the errors

Expand Down
34 changes: 17 additions & 17 deletions tests/integrations/test_keyword_if_then_else.toy
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@

//literals
if (true) {
print "Success";
print "Success 1";
}
else {
print "Failure";
print "Failure 1";
}

//false literals
if (false) {
print "Failure";
print "Failure 2";
}
else {
print "Success";
print "Success 2";
}

//conditionals
if (1 < 2) {
print "Success";
print "Success 3";
}
if (1 > 2) {
print "Failure";
print "Failure 3";
}


//variables
var a = 42;

if (a) {
print "Success";
print "Success 4";
}
else {
print "Failure";
print "Failure 4";
}


if (a == 42) {
print "Success";
print "Success 5";
}
else {
print "Failure";
print "Failure 5";
}

//concatenated strings
if ("foo" .. "bar" == "foobar") {
print "Success";
print "Success 6";
}
else {
print "Failure";
print "Failure 6";
}


if ("foobar" == "foo" .. "bar") {
print "Success";
print "Success 7";
}
else {
print "Failure";
print "Failure 7";
}

if ("fizz" .. "le" == "fi" .. "zzle") {
print "Success";
print "Success 8";
}
else {
print "Failure";
}
print "Failure 8";
}

0 comments on commit 7d4ea48

Please sign in to comment.