Last active
September 28, 2017 15:41
-
-
Save amyinorbit/40ad5e70b7cf7649b10ef0c87bf00a01 to your computer and use it in GitHub Desktop.
Orbit AST Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun fibonacci(n: Number) -> Number { | |
if n < 2 { | |
return 1 | |
} | |
return fibonacci(n-2) + fibonacci(n-1) | |
} | |
fun main() -> Void { | |
print("OrbitVM running on " + System.getOS()) | |
print("Fibonacci demo:") | |
for i in steps(0, 20) { | |
print(i + " -> " + fibonacci(i)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ModuleDecl 'TranslationUnit' | |
`-DeclarationList | |
|-FuncDecl 'fibonacci' | |
| |-VarDecl 'n' | |
| | `-TypeExpr 'Number' | |
| |-TypeExpr 'Number' | |
| `-Block | |
| |-IfStmt | |
| | |-BinaryOperatorExpr '<' | |
| | | |-NameRefExpr 'n' | |
| | | `-ConstantExpr '2' | |
| | |-Block | |
| | | `-ReturnStmt | |
| | | `-ConstantExpr '1' | |
| `-ReturnStmt | |
| `-BinaryOperatorExpr '+' | |
| |-CallExpr | |
| | |-NameRefExpr 'fibonacci' | |
| | `-CallParamList | |
| | `-BinaryOperatorExpr '-' | |
| | |-NameRefExpr 'n' | |
| | `-ConstantExpr '2' | |
| `-CallExpr | |
| |-NameRefExpr 'fibonacci' | |
| `-CallParamList | |
| `-BinaryOperatorExpr '-' | |
| |-NameRefExpr 'n' | |
| `-ConstantExpr '1' | |
`-FuncDecl 'main' | |
|-TypeExpr 'Void' | |
`-Block | |
|-CallExpr | |
| |-NameRefExpr 'print' | |
| `-CallParamList | |
| `-BinaryOperatorExpr '+' | |
| |-ConstantExpr 'OrbitVM running on ' | |
| `-CallExpr | |
| `-BinaryOperatorExpr '.' | |
| |-NameRefExpr 'System' | |
| `-NameRefExpr 'getOS' | |
|-CallExpr | |
| |-NameRefExpr 'print' | |
| `-CallParamList | |
| `-ConstantExpr 'Fibonacci demo:' | |
`-ForInStmt'i' | |
|-CallExpr | |
| |-NameRefExpr 'steps' | |
| `-CallParamList | |
| |-ConstantExpr '0' | |
| `-ConstantExpr '20' | |
`-Block | |
`-CallExpr | |
|-NameRefExpr 'print' | |
`-CallParamList | |
`-BinaryOperatorExpr '+' | |
|-BinaryOperatorExpr '+' | |
| |-NameRefExpr 'i' | |
| `-ConstantExpr ' -> ' | |
`-CallExpr | |
|-NameRefExpr 'fibonacci' | |
`-CallParamList | |
`-NameRefExpr 'i' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment