Note: these examples work in the latest version of the language. Later major versions are permitted to break any code.
Basic Hello World
func main print("Hello World")
Recursive Fibonacci
func fib(n : int32) : int64
if (n <= 1) {
ret n;
} else {
return fib(n - 1) + fib(n - 2)
}
Iterative Factorial
func factorial(n : int32) : int64 {
let x = 1;
while(n > 1){
x *= n, n -= 1
}
ret x
}
Current features:
if
with or withoutelse
- function calls
- printable syntax tree
-fsyntax-tree
in the command line
- printable intermediate representation "IR"
Future:
- Full type checking
for
Loops- Multi-file programs
Phases used in compilation:
- Tokenize input
- Generate syntax tree
- Typecheck tree
- Generate IR by walking syntax tree
- Optimize IR
- Output bytecode from IR