-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declaration based compilation units.
- Loading branch information
Showing
26 changed files
with
255 additions
and
306 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/* fibonacci sequence */ | ||
fib = { n in | ||
fn fib(n) { | ||
if n == 0 | ||
then 0 | ||
else if n == 1 | ||
then 1 | ||
else fib(n - 1) + fib(n - 2) | ||
} | ||
|
||
result = fib(20) | ||
println(result) | ||
fn main() { | ||
result = fib(20) | ||
println(result) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
three = 3 | ||
two = 2 | ||
|
||
calculateSimple = { in | ||
(50 + three) * two | ||
} | ||
|
||
calculateComplex = { in | ||
three + two + 50 | ||
} | ||
|
||
multiply = { a, b in | ||
a * b | ||
} | ||
|
||
// calculates the result | ||
calculateSimpleResult = calculateSimple() | ||
calculateComplexResult = calculateComplex() | ||
multiplyResult = multiply(50, 50) | ||
|
||
list = [10, 20, 30] | ||
trueValue = true | ||
falseValue = false | ||
|
||
invert = { value in | ||
!value | ||
} | ||
|
||
notEqual = { a, b in | ||
a != b | ||
fn main() { | ||
three = 3 | ||
two = 2 | ||
|
||
calculateSimple = { in | ||
(50 + three) * two | ||
} | ||
|
||
calculateComplex = { in | ||
three + two + 50 | ||
} | ||
|
||
multiply = { a, b in | ||
a * b | ||
} | ||
|
||
// calculates the result | ||
calculateSimpleResult = calculateSimple() | ||
calculateComplexResult = calculateComplex() | ||
multiplyResult = multiply(50, 50) | ||
|
||
list = [10, 20, 30] | ||
trueValue = true | ||
falseValue = false | ||
|
||
invert = { value in | ||
!value | ||
} | ||
|
||
notEqual = { a, b in | ||
a != b | ||
} | ||
|
||
equal = { a, b in | ||
a == b | ||
} | ||
|
||
results = [ | ||
calculateSimpleResult, | ||
calculateComplexResult, | ||
multiplyResult, | ||
list, | ||
trueValue, | ||
falseValue, | ||
invert(true), | ||
invert(false), | ||
equal(5, 5), | ||
equal(5, 6), | ||
notEqual(5, 5), | ||
notEqual(5, 6) | ||
] | ||
|
||
println("results:") | ||
println(results) | ||
} | ||
|
||
equal = { a, b in | ||
a == b | ||
} | ||
|
||
results = [ | ||
calculateSimpleResult, | ||
calculateComplexResult, | ||
multiplyResult, | ||
list, | ||
trueValue, | ||
falseValue, | ||
invert(true), | ||
invert(false), | ||
equal(5, 5), | ||
equal(5, 6), | ||
notEqual(5, 5), | ||
notEqual(5, 6) | ||
] | ||
|
||
println("results:") | ||
println(results) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/gay/pizza/pork/ast/nodes/CompilationUnit.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gay.pizza.pork.ast.nodes | ||
|
||
import gay.pizza.pork.ast.NodeType | ||
import gay.pizza.pork.ast.NodeVisitor | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("compilationUnit") | ||
class CompilationUnit(val declarations: List<Declaration>) : Node() { | ||
override val type: NodeType = NodeType.CompilationUnit | ||
|
||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> = | ||
visitor.visitAll(declarations) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is CompilationUnit) return false | ||
return other.declarations == declarations | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = declarations.hashCode() | ||
result = 31 * result + type.hashCode() | ||
return result | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package gay.pizza.pork.ast.nodes | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
sealed class Declaration : Node() |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/gay/pizza/pork/ast/nodes/FunctionDeclaration.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gay.pizza.pork.ast.nodes | ||
|
||
import gay.pizza.pork.ast.NodeType | ||
import gay.pizza.pork.ast.NodeVisitor | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("functionDeclaration") | ||
class FunctionDeclaration(val symbol: Symbol, val arguments: List<Symbol>, val block: Block) : Declaration() { | ||
override val type: NodeType = NodeType.FunctionDeclaration | ||
|
||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> = | ||
visitor.visitNodes(symbol) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is FunctionDeclaration) return false | ||
return other.symbol == symbol && other.arguments == arguments && other.block == block | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = symbol.hashCode() | ||
result = 31 * result + symbol.hashCode() | ||
result = 31 * result + arguments.hashCode() | ||
result = 31 * result + block.hashCode() | ||
return result | ||
} | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.