diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt index 37f553bc7..1b6b84195 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt @@ -94,13 +94,13 @@ class AssemblyProgram( internal fun loadAsmIncludeFile(filename: String, source: SourceCode): Result { return if (filename.startsWith(SourceCode.libraryFilePrefix)) { return com.github.michaelbull.result.runCatching { - SourceCode.Resource("/prog8lib/${filename.substring(SourceCode.libraryFilePrefix.length)}").readText() + SourceCode.Resource("/prog8lib/${filename.substring(SourceCode.libraryFilePrefix.length)}").text }.mapError { NoSuchFileException(File(filename)) } } else { val sib = Path(source.origin).resolveSibling(filename) if (sib.isRegularFile()) - Ok(SourceCode.File(sib).readText()) + Ok(SourceCode.File(sib).text) else - Ok(SourceCode.File(Path(filename)).readText()) + Ok(SourceCode.File(Path(filename)).text) } } diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt index 6d5da5126..33946d83e 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt @@ -11,11 +11,6 @@ import prog8.ast.statements.FunctionCallStatement import prog8.ast.statements.Subroutine import prog8.ast.toHex import prog8.codegen.cpu6502.assignment.* -import prog8.codegen.cpu6502.assignment.AsmAssignSource -import prog8.codegen.cpu6502.assignment.AsmAssignTarget -import prog8.codegen.cpu6502.assignment.AsmAssignment -import prog8.codegen.cpu6502.assignment.AssignmentAsmGen -import prog8.codegen.cpu6502.assignment.SourceStorageKind import prog8.compilerinterface.AssemblyError import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.CpuType diff --git a/codeGenTargets/src/prog8/codegen/target/C128Target.kt b/codeGenTargets/src/prog8/codegen/target/C128Target.kt index 379475814..f2047827c 100644 --- a/codeGenTargets/src/prog8/codegen/target/C128Target.kt +++ b/codeGenTargets/src/prog8/codegen/target/C128Target.kt @@ -7,9 +7,9 @@ import prog8.ast.base.WordDatatypes import prog8.ast.expressions.Expression import prog8.ast.statements.RegisterOrStatusflag import prog8.ast.statements.Subroutine +import prog8.codegen.target.c128.C128MachineDefinition import prog8.codegen.target.cbm.asmsub6502ArgsEvalOrder import prog8.codegen.target.cbm.asmsub6502ArgsHaveRegisterClobberRisk -import prog8.codegen.target.c128.C128MachineDefinition import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IStringEncoding diff --git a/codeGenTargets/src/prog8/codegen/target/C64Target.kt b/codeGenTargets/src/prog8/codegen/target/C64Target.kt index f49efb0b8..9c49c361b 100644 --- a/codeGenTargets/src/prog8/codegen/target/C64Target.kt +++ b/codeGenTargets/src/prog8/codegen/target/C64Target.kt @@ -7,9 +7,9 @@ import prog8.ast.base.WordDatatypes import prog8.ast.expressions.Expression import prog8.ast.statements.RegisterOrStatusflag import prog8.ast.statements.Subroutine +import prog8.codegen.target.c64.C64MachineDefinition import prog8.codegen.target.cbm.asmsub6502ArgsEvalOrder import prog8.codegen.target.cbm.asmsub6502ArgsHaveRegisterClobberRisk -import prog8.codegen.target.c64.C64MachineDefinition import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IStringEncoding diff --git a/codeGenTargets/src/prog8/codegen/target/cbm/AsmsubHelpers.kt b/codeGenTargets/src/prog8/codegen/target/cbm/AsmsubHelpers.kt index f4ce9510e..f00d4ff56 100644 --- a/codeGenTargets/src/prog8/codegen/target/cbm/AsmsubHelpers.kt +++ b/codeGenTargets/src/prog8/codegen/target/cbm/AsmsubHelpers.kt @@ -2,7 +2,9 @@ package prog8.codegen.target.cbm import prog8.ast.base.Cx16VirtualRegisters import prog8.ast.base.RegisterOrPair -import prog8.ast.expressions.* +import prog8.ast.expressions.ArrayIndexedExpression +import prog8.ast.expressions.Expression +import prog8.ast.expressions.FunctionCallExpression import prog8.ast.statements.RegisterOrStatusflag import prog8.ast.statements.Subroutine diff --git a/codeGenTargets/src/prog8/codegen/target/cbm/IsoEncoding.kt b/codeGenTargets/src/prog8/codegen/target/cbm/IsoEncoding.kt index 854076924..ba2b8d686 100644 --- a/codeGenTargets/src/prog8/codegen/target/cbm/IsoEncoding.kt +++ b/codeGenTargets/src/prog8/codegen/target/cbm/IsoEncoding.kt @@ -1,8 +1,8 @@ package prog8.codegen.target.cbm -import com.github.michaelbull.result.Result -import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Err +import com.github.michaelbull.result.Ok +import com.github.michaelbull.result.Result import java.io.CharConversionException import java.nio.charset.Charset diff --git a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt index f4e15e2d8..98ded5a3c 100644 --- a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt +++ b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt @@ -5,10 +5,10 @@ import prog8.ast.Node import prog8.ast.Program import prog8.ast.base.DataType import prog8.ast.base.FatalAstException +import prog8.ast.expressions.AugmentAssignmentOperators import prog8.ast.expressions.BinaryExpression import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.TypecastExpression -import prog8.ast.expressions.AugmentAssignmentOperators import prog8.ast.statements.AssignTarget import prog8.ast.statements.Assignment import prog8.ast.statements.AssignmentOrigin diff --git a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt index ed233db13..575d0ac68 100644 --- a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt @@ -1,7 +1,10 @@ package prog8.optimizer import prog8.ast.* -import prog8.ast.base.* +import prog8.ast.base.ArrayDatatypes +import prog8.ast.base.DataType +import prog8.ast.base.IntegerDatatypes +import prog8.ast.base.VarDeclType import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.AstWalker diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index 19bc82873..977469148 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -3,11 +3,11 @@ package prog8 import kotlinx.cli.* import prog8.ast.base.AstException import prog8.codegen.target.C128Target +import prog8.codegen.target.C64Target +import prog8.codegen.target.Cx16Target import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram -import prog8.codegen.target.C64Target -import prog8.codegen.target.Cx16Target import java.io.File import java.nio.file.FileSystems import java.nio.file.Path diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 583771236..36da2cfe0 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -1,6 +1,6 @@ package prog8.compiler -import com.github.michaelbull.result.* +import com.github.michaelbull.result.onFailure import prog8.ast.AstToSourceTextConverter import prog8.ast.IBuiltinFunctions import prog8.ast.Program @@ -11,9 +11,9 @@ import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.Directive import prog8.codegen.cpu6502.AsmGen import prog8.codegen.target.C128Target -import prog8.compiler.astprocessing.* import prog8.codegen.target.C64Target import prog8.codegen.target.Cx16Target +import prog8.compiler.astprocessing.* import prog8.compilerinterface.* import prog8.optimizer.* import prog8.parser.ParseError diff --git a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt index aaa08f4f2..7da635464 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt @@ -2,7 +2,9 @@ package prog8.compiler.astprocessing import prog8.ast.Node import prog8.ast.Program -import prog8.ast.base.* +import prog8.ast.base.NumericDatatypes +import prog8.ast.base.SyntaxError +import prog8.ast.base.VarDeclType import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.AstWalker diff --git a/compiler/src/prog8/compiler/astprocessing/AstVariousTransforms.kt b/compiler/src/prog8/compiler/astprocessing/AstVariousTransforms.kt index caa61e2d3..f1d737cbb 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstVariousTransforms.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstVariousTransforms.kt @@ -7,7 +7,10 @@ import prog8.ast.expressions.ArrayIndexedExpression import prog8.ast.expressions.BinaryExpression import prog8.ast.expressions.DirectMemoryRead import prog8.ast.expressions.StringLiteralValue -import prog8.ast.statements.* +import prog8.ast.statements.AssignTarget +import prog8.ast.statements.DirectMemoryWrite +import prog8.ast.statements.Subroutine +import prog8.ast.statements.VarDecl import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification diff --git a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt index da27a9d8a..778fb7ea2 100644 --- a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt +++ b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt @@ -6,11 +6,14 @@ import prog8.ast.Node import prog8.ast.Program import prog8.ast.base.ParentSentinel import prog8.ast.base.Position -import prog8.ast.expressions.* +import prog8.ast.expressions.DirectMemoryRead +import prog8.ast.expressions.FunctionCallExpression +import prog8.ast.expressions.IdentifierReference +import prog8.ast.expressions.PrefixExpression import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification -import prog8.compilerinterface.* +import prog8.compilerinterface.IErrorReporter internal class CodeDesugarer(val program: Program, private val errors: IErrorReporter) : AstWalker() { diff --git a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt index 94f3d9bd1..55b662d30 100644 --- a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt +++ b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt @@ -8,7 +8,9 @@ import prog8.ast.base.ArrayDatatypes import prog8.ast.base.DataType import prog8.ast.base.FatalAstException import prog8.ast.expressions.* -import prog8.ast.statements.* +import prog8.ast.statements.AnonymousScope +import prog8.ast.statements.Assignment +import prog8.ast.statements.FunctionCallStatement import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification import prog8.compilerinterface.CompilationOptions diff --git a/compiler/test/ModuleImporterTests.kt b/compiler/test/ModuleImporterTests.kt index 8a1dfcd46..55bfa8b31 100644 --- a/compiler/test/ModuleImporterTests.kt +++ b/compiler/test/ModuleImporterTests.kt @@ -2,13 +2,6 @@ package prog8tests import com.github.michaelbull.result.getErrorOrElse import com.github.michaelbull.result.getOrElse -import prog8.ast.Program -import prog8.ast.internedStringsModuleName -import prog8.compiler.ModuleImporter -import prog8.compilerinterface.IErrorReporter -import prog8.parser.ParseError -import prog8.parser.SourceCode -import kotlin.io.path.* import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.withClue @@ -16,11 +9,14 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain +import prog8.ast.Program +import prog8.ast.internedStringsModuleName +import prog8.compiler.ModuleImporter +import prog8.compilerinterface.IErrorReporter +import prog8.parser.ParseError +import prog8.parser.SourceCode import prog8tests.helpers.* -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer -import prog8tests.helpers.DummyStringEncoder -import prog8tests.helpers.ErrorReporterForTests +import kotlin.io.path.* class TestModuleImporter: FunSpec({ @@ -71,7 +67,7 @@ class TestModuleImporter: FunSpec({ val searchIn = Path(".", "$srcPathRel").invariantSeparatorsPathString val importer = makeImporter(null, searchIn) - shouldThrow { importer.importModule(srcPathRel) } + shouldThrow { importer.importModule(srcPathRel) } .let { withClue(".file should be normalized") { "${it.file}" shouldBe "${it.file.normalize()}" @@ -82,7 +78,7 @@ class TestModuleImporter: FunSpec({ } program.modules.size shouldBe 1 - shouldThrow { importer.importModule(srcPathAbs) } + shouldThrow { importer.importModule(srcPathAbs) } .let { withClue(".file should be normalized") { "${it.file}" shouldBe "${it.file.normalize()}" diff --git a/compiler/test/ProjectConfig.kt b/compiler/test/ProjectConfig.kt index 1ff8e9209..5e368549f 100644 --- a/compiler/test/ProjectConfig.kt +++ b/compiler/test/ProjectConfig.kt @@ -1,14 +1,6 @@ package prog8tests import io.kotest.core.config.AbstractProjectConfig -import io.kotest.core.listeners.Listener -import io.kotest.core.listeners.TestListener -import io.kotest.core.spec.Spec -import io.kotest.extensions.system.NoSystemErrListener -import io.kotest.extensions.system.NoSystemOutListener -import java.io.ByteArrayOutputStream -import java.io.PrintStream -import kotlin.math.max object ProjectConfig : AbstractProjectConfig() { override val parallelism = 2 // max(2, Runtime.getRuntime().availableProcessors() / 2) diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 680b87f9a..cb4adeef3 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -1,14 +1,13 @@ package prog8tests import io.kotest.core.spec.style.FunSpec +import prog8.codegen.target.C64Target +import prog8.codegen.target.Cx16Target import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram -import prog8.codegen.target.C64Target -import prog8.codegen.target.Cx16Target import prog8.compilerinterface.ICompilationTarget import prog8tests.helpers.* -import prog8tests.helpers.assertSuccess import java.nio.file.Path import kotlin.io.path.absolute import kotlin.io.path.exists diff --git a/compiler/test/TestCompilerOnRanges.kt b/compiler/test/TestCompilerOnRanges.kt index 089b37bc3..b5ebe713c 100644 --- a/compiler/test/TestCompilerOnRanges.kt +++ b/compiler/test/TestCompilerOnRanges.kt @@ -7,17 +7,16 @@ import io.kotest.matchers.string.shouldContain import io.kotest.matchers.types.instanceOf import prog8.ast.base.DataType import prog8.ast.base.Position -import prog8.ast.expressions.* +import prog8.ast.expressions.ArrayLiteralValue +import prog8.ast.expressions.IdentifierReference +import prog8.ast.expressions.NumericLiteralValue +import prog8.ast.expressions.RangeExpression import prog8.ast.statements.ForLoop import prog8.ast.statements.VarDecl import prog8.codegen.target.C64Target import prog8.codegen.target.Cx16Target import prog8.compilerinterface.Encoding import prog8tests.helpers.* -import prog8tests.helpers.ErrorReporterForTests -import prog8tests.helpers.assertFailure -import prog8tests.helpers.assertSuccess -import prog8tests.helpers.compileText /** diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index d11d29575..67c529ab5 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -1,12 +1,11 @@ package prog8tests import io.kotest.core.spec.style.FunSpec +import prog8.codegen.target.Cx16Target import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram -import prog8.codegen.target.Cx16Target import prog8tests.helpers.* -import prog8tests.helpers.assertSuccess import java.nio.file.Path import kotlin.io.path.absolute import kotlin.io.path.createTempFile diff --git a/compiler/test/TestImportedModulesOrderAndOptions.kt b/compiler/test/TestImportedModulesOrderAndOptions.kt index 369d03977..e468c6828 100644 --- a/compiler/test/TestImportedModulesOrderAndOptions.kt +++ b/compiler/test/TestImportedModulesOrderAndOptions.kt @@ -5,9 +5,9 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldStartWith import prog8.ast.internedStringsModuleName +import prog8.codegen.target.C64Target import prog8.compiler.determineCompilationOptions import prog8.compiler.parseImports -import prog8.codegen.target.C64Target import prog8.compilerinterface.ZeropageType import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.assertSuccess diff --git a/compiler/test/TestMemory.kt b/compiler/test/TestMemory.kt index 87a253768..4253bbaa9 100644 --- a/compiler/test/TestMemory.kt +++ b/compiler/test/TestMemory.kt @@ -12,15 +12,11 @@ import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.NumericLiteralValue import prog8.ast.expressions.PrefixExpression import prog8.ast.statements.* -import prog8.compiler.printProgram import prog8.codegen.target.C64Target +import prog8.compiler.printProgram import prog8.compilerinterface.isIOAddress import prog8.parser.SourceCode import prog8tests.helpers.* -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer -import prog8tests.helpers.DummyStringEncoder -import prog8tests.helpers.compileText class TestMemory: FunSpec({ diff --git a/compiler/test/TestSubroutines.kt b/compiler/test/TestSubroutines.kt index 9622760bb..86071384d 100644 --- a/compiler/test/TestSubroutines.kt +++ b/compiler/test/TestSubroutines.kt @@ -7,7 +7,10 @@ import io.kotest.matchers.shouldNotBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.types.instanceOf import prog8.ast.base.DataType -import prog8.ast.expressions.* +import prog8.ast.expressions.BinaryExpression +import prog8.ast.expressions.DirectMemoryRead +import prog8.ast.expressions.IdentifierReference +import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.* import prog8.codegen.target.C64Target import prog8tests.helpers.ErrorReporterForTests diff --git a/compiler/test/ZeropageTests.kt b/compiler/test/ZeropageTests.kt index 18498cc59..0d75eb9a8 100644 --- a/compiler/test/ZeropageTests.kt +++ b/compiler/test/ZeropageTests.kt @@ -20,7 +20,6 @@ import prog8.codegen.target.cx16.CX16Zeropage import prog8.compilerinterface.* import prog8tests.helpers.DummyCompilationTarget import prog8tests.helpers.ErrorReporterForTests -import java.lang.IllegalArgumentException class TestAbstractZeropage: FunSpec({ diff --git a/compiler/test/ast/TestProg8Parser.kt b/compiler/test/ast/TestProg8Parser.kt index 5e55115fb..90e765082 100644 --- a/compiler/test/ast/TestProg8Parser.kt +++ b/compiler/test/ast/TestProg8Parser.kt @@ -26,7 +26,6 @@ import prog8.parser.ParseError import prog8.parser.Prog8Parser.parseModule import prog8.parser.SourceCode import prog8tests.helpers.* -import prog8tests.helpers.DummyFunctions import kotlin.io.path.Path import kotlin.io.path.isRegularFile import kotlin.io.path.name diff --git a/compiler/test/ast/TestSourceCode.kt b/compiler/test/ast/TestSourceCode.kt index f34b8e0ab..903a6efa9 100644 --- a/compiler/test/ast/TestSourceCode.kt +++ b/compiler/test/ast/TestSourceCode.kt @@ -21,10 +21,9 @@ class TestSourceCode: AnnotationSpec() { main { } """ val src = SourceCode.Text(text) - val actualText = src.getCharStream().toString() src.origin shouldContain Regex("^$") - actualText shouldBe text + src.text shouldBe text src.isFromResources shouldBe false src.isFromFilesystem shouldBe false src.toString().startsWith("prog8.parser.SourceCode") shouldBe true @@ -46,7 +45,7 @@ class TestSourceCode: AnnotationSpec() { @Test fun testFromPathWithDirectory() { - shouldThrow { SourceCode.File(fixturesDir) } + shouldThrow { SourceCode.File(fixturesDir) } } @Test @@ -56,7 +55,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.File(path) val expectedOrigin = SourceCode.relative(path).toString() src.origin shouldBe expectedOrigin - src.readText() shouldBe path.toFile().readText() + src.text shouldBe path.toFile().readText() src.isFromResources shouldBe false src.isFromFilesystem shouldBe true } @@ -69,7 +68,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.File(path) val expectedOrigin = SourceCode.relative(path).toString() src.origin shouldBe expectedOrigin - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() } @Test @@ -79,7 +78,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.Resource(pathString) src.origin shouldBe "$libraryFilePrefix/$pathString" - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() src.isFromResources shouldBe true src.isFromFilesystem shouldBe false } @@ -91,7 +90,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.Resource(pathString) src.origin shouldBe "$libraryFilePrefix$pathString" - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() } @Test @@ -101,7 +100,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.Resource(pathString) src.origin shouldBe "$libraryFilePrefix/$pathString" - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() src.isFromResources shouldBe true } @@ -112,7 +111,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.Resource(pathString) src.origin shouldBe "$libraryFilePrefix$pathString" - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() } @Test @@ -122,7 +121,7 @@ class TestSourceCode: AnnotationSpec() { val src = SourceCode.Resource(pathString) src.origin shouldBe "$libraryFilePrefix/prog8lib/math.p8" - src.readText() shouldBe srcFile.readText() + src.text shouldBe srcFile.readText() src.isFromResources shouldBe true } diff --git a/compiler/test/codegeneration/TestAsmGenSymbols.kt b/compiler/test/codegeneration/TestAsmGenSymbols.kt index 2853772aa..1cdb35b5f 100644 --- a/compiler/test/codegeneration/TestAsmGenSymbols.kt +++ b/compiler/test/codegeneration/TestAsmGenSymbols.kt @@ -4,7 +4,10 @@ import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import prog8.ast.Module import prog8.ast.Program -import prog8.ast.base.* +import prog8.ast.base.DataType +import prog8.ast.base.Position +import prog8.ast.base.RegisterOrPair +import prog8.ast.base.VarDeclType import prog8.ast.expressions.AddressOf import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.NumericLiteralValue @@ -12,7 +15,10 @@ import prog8.ast.statements.* import prog8.codegen.cpu6502.AsmGen import prog8.codegen.target.C64Target import prog8.codegen.target.c64.C64Zeropage -import prog8.compilerinterface.* +import prog8.compilerinterface.CompilationOptions +import prog8.compilerinterface.LauncherType +import prog8.compilerinterface.OutputType +import prog8.compilerinterface.ZeropageType import prog8.parser.SourceCode import prog8tests.helpers.DummyFunctions import prog8tests.helpers.DummyMemsizer diff --git a/compiler/test/codegeneration/TestVariables.kt b/compiler/test/codegeneration/TestVariables.kt index b81667e88..3fd2681db 100644 --- a/compiler/test/codegeneration/TestVariables.kt +++ b/compiler/test/codegeneration/TestVariables.kt @@ -1,10 +1,7 @@ package prog8tests.codegeneration import io.kotest.core.spec.style.FunSpec -import io.kotest.matchers.shouldBe -import io.kotest.matchers.string.shouldContain import prog8.codegen.target.C64Target -import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.assertSuccess import prog8tests.helpers.compileText diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index 8010730ef..b6f451d8e 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -4,11 +4,11 @@ import io.kotest.assertions.withClue import io.kotest.matchers.shouldBe import prog8.ast.Program import prog8.codegen.cpu6502.AsmGen +import prog8.codegen.target.C64Target +import prog8.codegen.target.c64.C64Zeropage import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram -import prog8.codegen.target.C64Target -import prog8.codegen.target.c64.C64Zeropage import prog8.compilerinterface.* import java.nio.file.Path import kotlin.io.path.name diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index 02d6607b3..697f0b081 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -1,6 +1,9 @@ package prog8.ast -import prog8.ast.base.* +import prog8.ast.base.FatalAstException +import prog8.ast.base.ParentSentinel +import prog8.ast.base.Position +import prog8.ast.base.findParentNode import prog8.ast.expressions.Expression import prog8.ast.expressions.IdentifierReference import prog8.ast.statements.* diff --git a/compilerAst/src/prog8/ast/Program.kt b/compilerAst/src/prog8/ast/Program.kt index 133b5e702..830dc4f81 100644 --- a/compilerAst/src/prog8/ast/Program.kt +++ b/compilerAst/src/prog8/ast/Program.kt @@ -4,7 +4,6 @@ import prog8.ast.base.DataType import prog8.ast.base.FatalAstException import prog8.ast.base.Position import prog8.ast.base.VarDeclType -import prog8.ast.expressions.ContainmentCheck import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.* import prog8.compilerinterface.Encoding diff --git a/compilerAst/src/prog8/ast/antlr/EscapeChars.kt b/compilerAst/src/prog8/ast/antlr/EscapeChars.kt index dd800d696..04c5e1a66 100644 --- a/compilerAst/src/prog8/ast/antlr/EscapeChars.kt +++ b/compilerAst/src/prog8/ast/antlr/EscapeChars.kt @@ -2,7 +2,6 @@ package prog8.ast.antlr import prog8.ast.base.Position import prog8.ast.base.SyntaxError -import kotlin.NumberFormatException fun escape(str: String): String { val es = str.map { diff --git a/compilerAst/src/prog8/parser/Prog8Parser.kt b/compilerAst/src/prog8/parser/Prog8Parser.kt index b417730d6..3b04c49ca 100644 --- a/compilerAst/src/prog8/parser/Prog8Parser.kt +++ b/compilerAst/src/prog8/parser/Prog8Parser.kt @@ -14,7 +14,7 @@ object Prog8Parser { fun parseModule(src: SourceCode): Module { val antlrErrorListener = AntlrErrorListener(src) - val lexer = Prog8ANTLRLexer(src.getCharStream()) + val lexer = Prog8ANTLRLexer(CharStreams.fromString(src.text, src.origin)) lexer.removeErrorListeners() lexer.addErrorListener(antlrErrorListener) val tokens = CommonTokenStream(lexer) diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index 0382e27b3..b74d6f7d0 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -1,26 +1,16 @@ package prog8.parser -import org.antlr.v4.runtime.CharStream -import org.antlr.v4.runtime.CharStreams import java.io.File import java.io.IOException -import java.nio.channels.Channels -import java.nio.charset.CodingErrorAction import java.nio.file.Path -import kotlin.io.path.* +import kotlin.io.path.Path +import kotlin.io.path.readText /** - * Encapsulates - and ties together - actual source code (=text) - * and its [origin]. + * Encapsulates - and ties together - actual source code (=text) and its [origin]. */ sealed class SourceCode { - /** - * To be used *only* by the parser (as input to a TokenStream). - * DO NOT mess around with! - */ - internal abstract fun getCharStream(): CharStream - /** * Whether this [SourceCode] instance was created as a [Resource] */ @@ -43,11 +33,10 @@ sealed class SourceCode { /** * The source code as plain string. */ - abstract fun readText(): String + abstract val text: String /** - * Deliberately does NOT return the actual text. - * For this - if at all - use [getCharStream]. + * Printable representation, deliberately does NOT return the actual text. */ final override fun toString() = "${this.javaClass.name}[${this.origin}]" @@ -68,43 +57,37 @@ sealed class SourceCode { * Turn a plain String into a [SourceCode] object. * [origin] will be something like `$stringSourcePrefix44c56085>`. */ - class Text(val text: String): SourceCode() { + class Text(override val text: String): SourceCode() { override val isFromResources = false override val isFromFilesystem = false override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>" - public override fun getCharStream(): CharStream = CharStreams.fromString(text, origin) - override fun readText() = text } /** * Get [SourceCode] from the file represented by the specified Path. - * This does not actually *access* the file, but it does check - * whether it - * * exists - * * is a regular file (ie: not a directory) - * * and is actually readable + * This immediately reads the file fully into memory. * * [origin] will be the given path in absolute and normalized form. * @throws NoSuchFileException if the file does not exist - * @throws AccessDeniedException if the given path points to a directory or the file is non-readable for some other reason + * @throws FileSystemException if the file cannot be read */ class File(path: Path): SourceCode() { - private val normalized = path.normalize() - init { - val file = normalized.toFile() - if (!path.exists()) - throw NoSuchFileException(file) - if (path.isDirectory()) - throw AccessDeniedException(file, reason = "Not a file but a directory") - if (!path.isReadable()) - throw AccessDeniedException(file, reason = "Is not readable") - } - + override val text: String + override val origin: String override val isFromResources = false override val isFromFilesystem = true - override val origin = relative(normalized).toString() - override fun getCharStream(): CharStream = CharStreams.fromPath(normalized) - override fun readText() = normalized.readText() + + init { + val normalized = path.normalize() + origin = relative(normalized).toString() + try { + text = normalized.readText() + } catch (nfx: java.nio.file.NoSuchFileException) { + throw NoSuchFileException(normalized.toFile()).also { it.initCause(nfx) } + } catch (iox: IOException) { + throw FileSystemException(normalized.toFile()).also { it.initCause(iox) } + } + } } /** @@ -113,6 +96,11 @@ sealed class SourceCode { class Resource(pathString: String): SourceCode() { private val normalized = "/" + Path.of(pathString).normalize().toMutableList().joinToString("/") + override val isFromResources = true + override val isFromFilesystem = false + override val origin = "$libraryFilePrefix$normalized" + override val text: String + init { val rscURL = object {}.javaClass.getResource(normalized) if (rscURL == null) { @@ -122,21 +110,8 @@ sealed class SourceCode { reason = "looked in resources rooted at $rscRoot" ) } - } - - override val isFromResources = true - override val isFromFilesystem = false - override val origin = "$libraryFilePrefix$normalized" - public override fun getCharStream(): CharStream { - val inpStr = object {}.javaClass.getResourceAsStream(normalized)!! - // CharStreams.fromStream() doesn't allow us to set the stream name properly, so we use a lower level api - val channel = Channels.newChannel(inpStr) - return CharStreams.fromChannel(channel, Charsets.UTF_8, 4096, CodingErrorAction.REPLACE, origin, -1) - } - - override fun readText(): String { val stream = object {}.javaClass.getResourceAsStream(normalized) - return stream!!.bufferedReader().use { r -> r.readText() } + text = stream!!.reader().use { it.readText() } } } @@ -144,10 +119,9 @@ sealed class SourceCode { * SourceCode for internally generated nodes (usually Modules) */ class Generated(name: String) : SourceCode() { - override fun getCharStream(): CharStream = throw IOException("generated code nodes doesn't have a stream to read") override val isFromResources: Boolean = false override val isFromFilesystem: Boolean = false override val origin: String = name - override fun readText() = throw IOException("generated code nodes don't have a text representation") + override val text: String = "" } } diff --git a/compilerInterfaces/src/prog8/compilerinterface/IMachineDefinition.kt b/compilerInterfaces/src/prog8/compilerinterface/IMachineDefinition.kt index 294a3437e..ab0473daf 100644 --- a/compilerInterfaces/src/prog8/compilerinterface/IMachineDefinition.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/IMachineDefinition.kt @@ -1,6 +1,5 @@ package prog8.compilerinterface -import prog8.ast.base.DataType import java.nio.file.Path diff --git a/examples/test.p8 b/examples/test.p8 index b71fdee54..37a209a35 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,7 +4,7 @@ main { sub start() { word w1 = -10 byte bb = 2 - w1 -= bb-1 + w1 -= bb-1 - - - txt.print_w(w1) txt.nl() diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index 167c45ebf..3b5b9e434 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -4,17 +4,17 @@ import org.takes.Request import org.takes.Response import org.takes.Take import org.takes.facets.fork.FkMethods -import org.takes.http.Exit -import org.takes.http.FtBasic import org.takes.facets.fork.FkRegex import org.takes.facets.fork.TkFork +import org.takes.http.Exit +import org.takes.http.FtBasic import org.takes.rq.form.RqFormBase import org.takes.rs.RsJson import org.takes.tk.TkSlf4j import prog8.compiler.CompilerArguments -import javax.json.Json import prog8.compiler.compileProgram import java.nio.file.Path +import javax.json.Json class Jsonding: RsJson.Source {