-
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.
language: prelude and internal functions, and varargs support
- Loading branch information
Showing
24 changed files
with
166 additions
and
104 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// GENERATED CODE FROM PORK AST CODEGEN | ||
package gay.pizza.pork.ast | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("argumentSpec") | ||
class ArgumentSpec(var symbol: Symbol, var multiple: Boolean) |
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
23 changes: 23 additions & 0 deletions
23
evaluator/src/main/kotlin/gay/pizza/pork/evaluator/InternalNativeProvider.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,23 @@ | ||
package gay.pizza.pork.evaluator | ||
|
||
class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider { | ||
private val functions = mutableMapOf( | ||
"println" to CallableFunction(::printLine) | ||
) | ||
|
||
override fun provideNativeFunction(definition: String): CallableFunction { | ||
return functions[definition] ?: throw RuntimeException("Unknown Internal Function: $definition") | ||
} | ||
|
||
private fun printLine(arguments: Arguments): Any { | ||
if (quiet) { | ||
return None | ||
} | ||
when (arguments.values.count()) { | ||
0 -> println() | ||
1 -> println(arguments.values[0]) | ||
else -> println(arguments.values.joinToString(" ")) | ||
} | ||
return None | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../pork/evaluator/NativeFunctionProvider.kt → ...ay/pizza/pork/evaluator/NativeProvider.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package gay.pizza.pork.evaluator | ||
|
||
interface NativeFunctionProvider { | ||
interface NativeProvider { | ||
fun provideNativeFunction(definition: String): CallableFunction | ||
} |
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,17 +1,13 @@ | ||
/* fibonacci sequence */ | ||
func fib(n) { | ||
if n == 0 { | ||
0 | ||
if n < 2 { | ||
n | ||
} else { | ||
if n == 1 { | ||
1 | ||
} else { | ||
fib(n - 1) + fib(n - 2) | ||
} | ||
fib(n - 1) + fib(n - 2) | ||
} | ||
} | ||
|
||
export func main() { | ||
let result = fib(20) | ||
let result = fib(30) | ||
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
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
Oops, something went wrong.