mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Script tests re-added, all tests can run under gdb
Also fixed a minor bug with printing, and removed the ability to configure the parser. Added and updated QUICKSTART.md as a quick way to get people started. There's some broken scripts under 'scripts/' that require functions to work properly.
This commit is contained in:
17
scripts/benchpress.toy
Normal file
17
scripts/benchpress.toy
Normal file
@@ -0,0 +1,17 @@
|
||||
//calculate the nth fibonacci number, and print it
|
||||
|
||||
var counter: int = 0;
|
||||
|
||||
var first: int = 1;
|
||||
var second: int = 0;
|
||||
|
||||
//BUG: This causes a stack overflow
|
||||
while (counter < 100_000) {
|
||||
var third: int = first + second;
|
||||
first = second;
|
||||
second = third;
|
||||
|
||||
print third;
|
||||
|
||||
++counter;
|
||||
}
|
||||
16
scripts/fib.toy
Normal file
16
scripts/fib.toy
Normal file
@@ -0,0 +1,16 @@
|
||||
//BUG: 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!
|
||||
//Note to both of you: keep it down you young whipper snappers!
|
||||
24
scripts/fizzbuzz.toy
Normal file
24
scripts/fizzbuzz.toy
Normal file
@@ -0,0 +1,24 @@
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
20
scripts/funky.toy
Normal file
20
scripts/funky.toy
Normal file
@@ -0,0 +1,20 @@
|
||||
//BUG: functions aren't working yet
|
||||
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;
|
||||
}
|
||||
}
|
||||
8
scripts/leapyear.toy
Normal file
8
scripts/leapyear.toy
Normal file
@@ -0,0 +1,8 @@
|
||||
//BUG: 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