Added tables to integration tests, tweaked a lot of comments

This commit is contained in:
2024-12-25 11:04:18 +11:00
parent 9e2cbb1f59
commit 9cb138a7d6
21 changed files with 22 additions and 78 deletions

View File

@@ -1,10 +1,14 @@
//TODO: functions don't work yet
//example of the fibonacci sequence
fn fib(n: int) {
if (n < 2) return n;
return fib(n-1) + fib(n-2);
}
//NOTE: type coercion syntax hasn't been decided on yet
//TODO: type coercion syntax hasn't been decided on yet, but it will be needed
for (var i = 1; i <= 10; i++) {
print i .. ":" .. fib(i);
}
//Note to self: yes, the base case in 'fib()' is 'n < 2', stop second guessing yourself!

View File

@@ -1,4 +1,5 @@
//standard example
//standard example, using 'while' instead of 'for', because it's not ready yet
var counter: int = 1;
while (counter <= 100) {

View File

@@ -1,19 +0,0 @@
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

View File

@@ -1,7 +1,8 @@
//TODO: functions don't work yet
//find the leap years
fn isLeapYear(n: int) {
if (n % 400) return true;
if (n % 100) return false;
if (n % 400 == 0) return true;
if (n % 100 == 0) return false;
return n % 4 == 0;
}

View File

@@ -1,13 +0,0 @@
{
//if and while work together
var count = 1;
while (count <= 10) {
if (count % 2 == 0) {
print "even";
}
else {
print "odd";
}
count += 1;
}
}

View File

@@ -1,33 +0,0 @@
//1-D table
var a = ["alpha": 1, "beta": 2, "gamma": 3];
a["beta"] = 6;
print a;
assert a == ["alpha": 1, "beta": 6, "gamma": 3], "1-D tables failed";
//nested
var b = [
"outer": ["inner": true],
"alpha": 1,
"beta": 2,
"gamma": 3
];
print b;
assert b == ["alpha": 1, "beta": 2, "gamma": 3, "outer": ["inner": true]], "nested tables failed";
//test empty tables
var empty = [:];
print empty;
assert empty == [:], "empty tables failed";
//test trailing commas
var trailing = [
"alpha":1,
"beta":2,
"gamma":3,
];
print trailing;
assert trailing == ["alpha": 1, "beta": 2, "gamma": 3], "trailing tables failed";

View File

@@ -1,12 +0,0 @@
//test trailing commas
var a = [1, 2, 3, ];
print a;
//test empty arrays
var b = [];
print b;
//TODO: prevent circular references

View File

@@ -1,5 +0,0 @@
var barr = [
[1, 2, 3],
// [4, 5, 6],
// [7, 8, 9]
];