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:
2026-04-06 21:50:41 +10:00
parent abae97b6e5
commit 1ae3fcbf73
10 changed files with 12 additions and 219 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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";
}

View File

@@ -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!

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}