mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
WIP: Scopes weren't tracking their content sizes
'print' no longer segfaults from a long chain of indirect memory frees. It still doesn't work though, which is odd.
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
//TODO: Not yet functional
|
||||
|
||||
//advent of code thingy
|
||||
var arr = [
|
||||
3, 4,
|
||||
4, 3,
|
||||
2, 5,
|
||||
1, 3,
|
||||
3, 9,
|
||||
3, 3,
|
||||
];
|
||||
|
||||
var total = 0;
|
||||
var counter = 0;
|
||||
|
||||
while (counter < arr.length) {
|
||||
var difference = arr[counter] - arr[counter+1];
|
||||
|
||||
if (difference < 0) {
|
||||
difference = -difference;
|
||||
}
|
||||
|
||||
total += difference;
|
||||
|
||||
counter += 2;
|
||||
}
|
||||
|
||||
print difference;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
//calculate the nth fibonacci number, and print it
|
||||
|
||||
var counter: int = 0;
|
||||
|
||||
var first: int = 1;
|
||||
var second: int = 0;
|
||||
|
||||
//This causes integer overflow, but that's fine for now
|
||||
while (counter < 100_000) {
|
||||
var third: int = first + second;
|
||||
first = second;
|
||||
second = third;
|
||||
|
||||
print third;
|
||||
|
||||
++counter;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
//make sure it works with multiple repititions
|
||||
|
||||
//-------------------------
|
||||
|
||||
//test break
|
||||
while (true) {
|
||||
break;
|
||||
assert false, "break failed";
|
||||
}
|
||||
|
||||
//test continue
|
||||
var flag1: bool = true;
|
||||
while (flag1) {
|
||||
flag1 = false;
|
||||
continue;
|
||||
assert false, "continue failed";
|
||||
}
|
||||
|
||||
print "done";
|
||||
|
||||
//-------------------------
|
||||
|
||||
//test break
|
||||
while (true) {
|
||||
break;
|
||||
assert false, "break failed";
|
||||
}
|
||||
|
||||
//test continue
|
||||
var flag2: bool = true;
|
||||
while (flag2) {
|
||||
flag2 = false;
|
||||
continue;
|
||||
assert false, "continue failed";
|
||||
}
|
||||
|
||||
print "done";
|
||||
|
||||
//-------------------------
|
||||
|
||||
//test break
|
||||
while (true) {
|
||||
break;
|
||||
assert false, "break failed";
|
||||
}
|
||||
|
||||
//test continue
|
||||
var flag3: bool = true;
|
||||
while (flag3) {
|
||||
flag3 = false;
|
||||
continue;
|
||||
assert false, "continue failed";
|
||||
}
|
||||
|
||||
print "done";
|
||||
|
||||
//-------------------------
|
||||
|
||||
{
|
||||
//test break
|
||||
while (true) {
|
||||
break;
|
||||
assert false, "break failed";
|
||||
}
|
||||
|
||||
//test continue
|
||||
var flag4: bool = true;
|
||||
while (flag4) {
|
||||
flag4 = false;
|
||||
continue;
|
||||
assert false, "continue failed";
|
||||
}
|
||||
|
||||
print "done";
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
|
||||
{
|
||||
//test break
|
||||
while (true) {
|
||||
{
|
||||
break;
|
||||
}
|
||||
assert false, "break failed";
|
||||
}
|
||||
|
||||
//test continue
|
||||
var flag5: bool = true;
|
||||
while (flag5) {
|
||||
flag5 = false;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
assert false, "continue failed";
|
||||
}
|
||||
|
||||
print "done";
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
//TODO: Not yet functional
|
||||
|
||||
//example of the fibonacci sequence
|
||||
fn fib(n: int) {
|
||||
if (n < 2) return n;
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
//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 my future self: yes, the base case in 'fib()' is 'n < 2', stop second guessing yourself!
|
||||
//Note to my past self: don't tell me what to do!
|
||||
@@ -1,24 +0,0 @@
|
||||
//standard example, using 'while' instead of 'for', because it's not ready yet
|
||||
|
||||
var counter: int = 0;
|
||||
|
||||
while (++counter <= 100) {
|
||||
var result: string = "";
|
||||
|
||||
if (counter % 3 == 0) {
|
||||
result = result .. "fizz";
|
||||
}
|
||||
|
||||
if (counter % 5 == 0) {
|
||||
result = result .. "buzz";
|
||||
}
|
||||
|
||||
//finally
|
||||
if (result != "") {
|
||||
print result;
|
||||
}
|
||||
else {
|
||||
print counter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//TODO: functions are untested
|
||||
fn makeCounter() {
|
||||
var counter: int = 0;
|
||||
|
||||
fn increment() {
|
||||
return ++counter;
|
||||
}
|
||||
|
||||
return increment;
|
||||
}
|
||||
|
||||
var tally = makeCounter();
|
||||
|
||||
while (true) {
|
||||
var result = tally();
|
||||
|
||||
if (result >= 10_000_000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
//TODO: Not yet functional
|
||||
|
||||
//find the leap years
|
||||
fn isLeapYear(n: int) {
|
||||
if (n % 400 == 0) return true;
|
||||
if (n % 100 == 0) return false;
|
||||
return n % 4 == 0;
|
||||
}
|
||||
Reference in New Issue
Block a user