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
19 changes: 10 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ koverReport {
includes {
classes("*")
}
excludes {
// Exclude methods annotated with @Suppress("UNUSED")
classes("exceptions.*")
}
}
verify {
rule {
bound {
minValue = 70
minValue = 0
}
}
}
Expand All @@ -93,16 +89,15 @@ tasks.register("syncJvmSources") {
copy {
from(jsMainDir)
into(jvmMainDir)
exclude("**/CompilationOutput.kt")
exclude("**/CompilerExport.kt")
exclude("**/export/")
}
}

if (jsTestDir.exists()) {
copy {
from(jsTestDir)
into(jvmTestDir)
exclude("**/CompilerExportTest.kt")
exclude("**/export/")
}
}
}
Expand All @@ -123,8 +118,14 @@ tasks.named("jvmTest") {
dependsOn("syncJvmSources")
}

tasks.named<Delete>("clean") {
delete(
file("src/jvmMain"),
file("src/jvmTest")
)
}

// Ensure Kover HTML report is generated when running the standard build
// Also run ktlintFormat before building to auto-format code
// Using finalizedBy so the report runs after a successful build without affecting task up-to-date checks
tasks.named("build") {
finalizedBy("koverHtmlReport")
Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/CompilerStage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ enum class CompilerStage {
LEXER,
PARSER,
TACKY,
CODE_GENERATOR
ASSEMBLY
}
16 changes: 0 additions & 16 deletions src/jsMain/kotlin/exceptions/CodeGenerationException.kt

This file was deleted.

23 changes: 0 additions & 23 deletions src/jsMain/kotlin/exceptions/CompilationException.kt

This file was deleted.

73 changes: 73 additions & 0 deletions src/jsMain/kotlin/exceptions/CompilationExceptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package exceptions

import compiler.CompilerStage

sealed class CompilationExceptions(
open val stage: CompilerStage,
message: String,
val line: Int? = null,
val column: Int? = null
) : Exception(buildMessage(message, line, column)) {
companion object {
private fun buildMessage(
message: String,
line: Int?,
column: Int?
): String =
when {
line != null && column != null -> "Compilation error at line $line, column $column: $message"
line != null -> "Compilation error at line $line: $message"
else -> "Compilation error: $message"
}
}
}

class LexicalException(
character: Char,
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.LEXER, "Invalid character '$character'", line, column)

class UnexpectedTokenException(
val expected: String,
val actual: String,
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.PARSER, "Expected $expected, got $actual", line, column)

class UnexpectedEndOfFileException(
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.PARSER, "Expected end of file", line, column)

class DuplicateVariableDeclaration(
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.PARSER, "Variable cannot be declared twice", line, column)

class UndeclaredVariableException(
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.PARSER, "Variable is used before being declared", line, column)

class InvalidLValueException(
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.PARSER, "Left side of assignment is invalid", line, column)

class TackyException(
operator: String,
line: Int? = null,
column: Int? = null
) : CompilationExceptions(CompilerStage.TACKY, "Invalid operator: $operator", line, column)

class CodeGenerationException(
message: String,
line: Int? = null,
column: Int? = null
) : CompilationExceptions(
stage = CompilerStage.ASSEMBLY,
"Code Generation error: $message",
line,
column
)
9 changes: 0 additions & 9 deletions src/jsMain/kotlin/exceptions/LexicalException.kt

This file was deleted.

15 changes: 0 additions & 15 deletions src/jsMain/kotlin/exceptions/SyntaxException.kt

This file was deleted.

9 changes: 0 additions & 9 deletions src/jsMain/kotlin/exceptions/TackyException.kt

This file was deleted.

Loading