Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import slang.parser.File2ParseTreeTransformer
import slang.repl.Repl
import slang.runtime.ConcreteState
import slang.runtime.Interpreter
import slang.typeinfer.typeCheck
import java.io.File
import java.nio.file.Paths

class SlangCLI : CliktCommand(name = "slang") {
private val filename by argument(help = "Slang source file to execute").optional()
private val hlir by option("--hlir", help = "Output HLIR representation instead of running").flag()
private val typecheckOnly by option("--typecheck", help = "Run Hindley-Milner type inference and report errors").flag()
private val output by option("-o", help = "Output file for HLIR (default: stdout)")

init {
Expand Down Expand Up @@ -54,6 +56,8 @@ class SlangCLI : CliktCommand(name = "slang") {
onSuccess = { programUnit ->
if (hlir) {
outputHlir(programUnit)
} else if (typecheckOnly) {
runTypeCheck(programUnit)
} else {
runProgram(programUnit)
}
Expand Down Expand Up @@ -84,6 +88,18 @@ class SlangCLI : CliktCommand(name = "slang") {
}
}

private fun runTypeCheck(programUnit: ProgramUnit) {
val errors = typeCheck(programUnit)
if (errors.isEmpty()) {
echo("Type checking passed. No errors found.")
} else {
echo("Type checking failed:", err = true)
for (e in errors) {
echo(" ${e.location} ${e.message}", err = true)
}
}
}
Comment thread
jpksh90 marked this conversation as resolved.

private fun runProgram(programUnit: ProgramUnit) {
try {
val interpreter = Interpreter()
Expand Down
Loading