mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
If-then-else is working, untested
This commit is contained in:
@@ -1,10 +1,44 @@
|
|||||||
|
|
||||||
|
//literals
|
||||||
if (true) {
|
if (true) {
|
||||||
print "Success";
|
print "Success";
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
print "Failed";
|
print "Failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//false literals
|
||||||
|
if (false) {
|
||||||
|
print "Failed";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "Success";
|
||||||
|
}
|
||||||
|
|
||||||
|
//conditionals
|
||||||
|
if (1 < 2) {
|
||||||
|
print "Success";
|
||||||
|
}
|
||||||
|
if (1 > 2) {
|
||||||
|
print "Failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//variables
|
||||||
|
var a = 42;
|
||||||
|
|
||||||
|
if (a) {
|
||||||
|
print "Success";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "Failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (a == 42) {
|
||||||
|
print "Success";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "Failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
19
scripts/gdb_init
Normal file
19
scripts/gdb_init
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
set breakpoint pending on
|
||||||
|
|
||||||
|
break toy_vm.c:547
|
||||||
|
|
||||||
|
command 1
|
||||||
|
print opcode
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
break toy_vm.c:373
|
||||||
|
|
||||||
|
command 2
|
||||||
|
printf "JUMP %d %d %d\n", type, cond, param
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
break toy_vm.c:375
|
||||||
|
|
||||||
|
|
||||||
@@ -332,18 +332,18 @@ static unsigned int writeInstructionIfThenElse(Toy_Routine** rt, Toy_AstIfThenEl
|
|||||||
unsigned int elseEndAddr = SKIP_INT(rt, code); //parameter to be written later
|
unsigned int elseEndAddr = SKIP_INT(rt, code); //parameter to be written later
|
||||||
|
|
||||||
//specify the starting position for the else branch
|
//specify the starting position for the else branch
|
||||||
OVERWRITE_INT(rt, code, thenEndAddr, CURRENT_ADDRESS(rt, code) - thenEndAddr);
|
OVERWRITE_INT(rt, code, thenEndAddr, CURRENT_ADDRESS(rt, code) - (thenEndAddr + 4));
|
||||||
|
|
||||||
//emit the else branch
|
//emit the else branch
|
||||||
writeRoutineCode(rt, ast.elseBranch);
|
writeRoutineCode(rt, ast.elseBranch);
|
||||||
|
|
||||||
//specify the ending position for the else branch
|
//specify the ending position for the else branch
|
||||||
OVERWRITE_INT(rt, code, elseEndAddr, CURRENT_ADDRESS(rt, code) - elseEndAddr);
|
OVERWRITE_INT(rt, code, elseEndAddr, CURRENT_ADDRESS(rt, code) - (elseEndAddr + 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
//without an else branch, set the jump destination and move on
|
//without an else branch, set the jump destination and move on
|
||||||
OVERWRITE_INT(rt, code, thenEndAddr, CURRENT_ADDRESS(rt, code) - thenEndAddr);
|
OVERWRITE_INT(rt, code, thenEndAddr, CURRENT_ADDRESS(rt, code) - (thenEndAddr + 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user