Skip to content

Instantly share code, notes, and snippets.

@amyinorbit
Last active September 28, 2017 15:41
Show Gist options
  • Save amyinorbit/40ad5e70b7cf7649b10ef0c87bf00a01 to your computer and use it in GitHub Desktop.
Save amyinorbit/40ad5e70b7cf7649b10ef0c87bf00a01 to your computer and use it in GitHub Desktop.
Orbit AST Tests
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))
}
}
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