mirror of
https://github.com/irmen/prog8.git
synced 2024-09-27 11:56:10 +00:00
switched to more featureful Result library
This commit is contained in:
parent
36bec62c9a
commit
f891fc698c
8
.idea/codeInsightSettings.xml
Normal file
8
.idea/codeInsightSettings.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaProjectCodeInsightSettings">
|
||||||
|
<excluded-names>
|
||||||
|
<name>kotlin.Result</name>
|
||||||
|
</excluded-names>
|
||||||
|
</component>
|
||||||
|
</project>
|
15
.idea/libraries/michael_bull_kotlin_result_jvm.xml
Normal file
15
.idea/libraries/michael_bull_kotlin_result_jvm.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="michael.bull.kotlin.result.jvm" type="repository">
|
||||||
|
<properties maven-id="com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/1.1.12/kotlin-result-jvm-1.1.12.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.5.10/kotlin-stdlib-jdk8-1.5.10.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.5.10/kotlin-stdlib-1.5.10.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.5.10/kotlin-stdlib-jdk7-1.5.10.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.5.10/kotlin-stdlib-common-1.5.10.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -22,6 +22,7 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3'
|
||||||
|
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12"
|
||||||
|
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
|
||||||
|
@ -21,5 +21,6 @@
|
|||||||
<orderEntry type="library" name="hamcrest" level="project" />
|
<orderEntry type="library" name="hamcrest" level="project" />
|
||||||
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />
|
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />
|
||||||
<orderEntry type="library" name="junit.jupiter" level="project" />
|
<orderEntry type="library" name="junit.jupiter" level="project" />
|
||||||
|
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,5 +1,6 @@
|
|||||||
package prog8.compiler
|
package prog8.compiler
|
||||||
|
|
||||||
|
import com.github.michaelbull.result.*
|
||||||
import prog8.ast.AstToSourceCode
|
import prog8.ast.AstToSourceCode
|
||||||
import prog8.ast.IBuiltinFunctions
|
import prog8.ast.IBuiltinFunctions
|
||||||
import prog8.ast.IMemSizer
|
import prog8.ast.IMemSizer
|
||||||
@ -357,20 +358,19 @@ fun printAst(programAst: Program) {
|
|||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun loadAsmIncludeFile(filename: String, sourcePath: Path): Result<String> {
|
internal fun loadAsmIncludeFile(filename: String, sourcePath: Path): Result<String, NoSuchFileException> {
|
||||||
return if (filename.startsWith(libraryFilePrefix)) {
|
return if (filename.startsWith(libraryFilePrefix)) {
|
||||||
runCatching {
|
return runCatching {
|
||||||
val stream = object {}.javaClass.getResourceAsStream("/prog8lib/${filename.substring(libraryFilePrefix.length)}") // TODO handle via SourceCode
|
val stream = object {}.javaClass.getResourceAsStream("/prog8lib/${filename.substring(libraryFilePrefix.length)}") // TODO handle via SourceCode
|
||||||
stream ?: throw NoSuchFileException(File(filename))
|
stream!!.bufferedReader().use { r -> r.readText() }
|
||||||
}.mapCatching {
|
}.mapError { NoSuchFileException(File(filename)) }
|
||||||
it.bufferedReader().use { r -> r.readText() }
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// first try in the isSameAs folder as where the containing file was imported from
|
// first try in the isSameAs folder as where the containing file was imported from
|
||||||
val sib = sourcePath.resolveSibling(filename)
|
val sib = sourcePath.resolveSibling(filename)
|
||||||
|
|
||||||
if (sib.toFile().isFile)
|
if (sib.toFile().isFile)
|
||||||
Result.success(sib.toFile().readText())
|
Ok(sib.toFile().readText())
|
||||||
else
|
else
|
||||||
Result.success(File(filename).readText())
|
Ok(File(filename).readText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package prog8.compiler.target.cpu6502.codegen
|
package prog8.compiler.target.cpu6502.codegen
|
||||||
|
|
||||||
|
import com.github.michaelbull.result.*
|
||||||
import prog8.ast.*
|
import prog8.ast.*
|
||||||
import prog8.ast.antlr.escape
|
import prog8.ast.antlr.escape
|
||||||
import prog8.ast.base.*
|
import prog8.ast.base.*
|
||||||
@ -1322,8 +1323,8 @@ $repeatLabel lda $counterVar
|
|||||||
val includedName = stmt.args[0].str!!
|
val includedName = stmt.args[0].str!!
|
||||||
val sourcePath = Path(stmt.definingModule.source!!.pathString()) // FIXME: %asminclude inside non-library, non-filesystem module
|
val sourcePath = Path(stmt.definingModule.source!!.pathString()) // FIXME: %asminclude inside non-library, non-filesystem module
|
||||||
loadAsmIncludeFile(includedName, sourcePath).fold(
|
loadAsmIncludeFile(includedName, sourcePath).fold(
|
||||||
onSuccess = { assemblyLines.add(it.trimEnd().trimStart('\n')) },
|
success = { assemblyLines.add(it.trimEnd().trimStart('\n')) },
|
||||||
onFailure = { errors.err(it.toString(), stmt.position) }
|
failure = { errors.err(it.toString(), stmt.position) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
"%asmbinary" -> {
|
"%asmbinary" -> {
|
||||||
|
@ -13,6 +13,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.antlr:antlr4-runtime:4.9.2'
|
implementation 'org.antlr:antlr4-runtime:4.9.2'
|
||||||
|
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12"
|
||||||
implementation project(':parser')
|
implementation project(':parser')
|
||||||
|
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||||
|
@ -15,5 +15,6 @@
|
|||||||
<orderEntry type="library" name="antlr.antlr4" level="project" />
|
<orderEntry type="library" name="antlr.antlr4" level="project" />
|
||||||
<orderEntry type="library" name="hamcrest" level="project" />
|
<orderEntry type="library" name="hamcrest" level="project" />
|
||||||
<orderEntry type="library" name="junit.jupiter" level="project" />
|
<orderEntry type="library" name="junit.jupiter" level="project" />
|
||||||
|
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,4 +1,4 @@
|
|||||||
%import textio2
|
%import textio
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user