mirror of
https://github.com/irmen/prog8.git
synced 2025-08-16 05:27:31 +00:00
cleanups
This commit is contained in:
1
.idea/inspectionProfiles/Project_Default.xml
generated
1
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -7,6 +7,7 @@
|
|||||||
<language isEnabled="false" name="Groovy" />
|
<language isEnabled="false" name="Groovy" />
|
||||||
</Languages>
|
</Languages>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="IncompleteDestructuring" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
|
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
|
||||||
<option name="processCode" value="false" />
|
<option name="processCode" value="false" />
|
||||||
|
@@ -1384,14 +1384,15 @@ $label nop""")
|
|||||||
|
|
||||||
private fun translate(jump: Jump) {
|
private fun translate(jump: Jump) {
|
||||||
if(jump.isGosub) {
|
if(jump.isGosub) {
|
||||||
|
jump as GoSub
|
||||||
val tgt = jump.identifier!!.targetSubroutine(program)
|
val tgt = jump.identifier!!.targetSubroutine(program)
|
||||||
if(tgt!=null && tgt.isAsmSubroutine) {
|
if(tgt!=null && tgt.isAsmSubroutine) {
|
||||||
// no need to rescue X , this has been taken care of already
|
// no need to rescue X , this has been taken care of already
|
||||||
out(" jsr ${getJumpTarget(jump)}")
|
out(" jsr ${getJumpTarget(jump)}")
|
||||||
} else {
|
} else {
|
||||||
saveXbeforeCall(jump as GoSub)
|
saveXbeforeCall(jump)
|
||||||
out(" jsr ${getJumpTarget(jump)}")
|
out(" jsr ${getJumpTarget(jump)}")
|
||||||
restoreXafterCall(jump as GoSub)
|
restoreXafterCall(jump)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -144,7 +144,7 @@ internal class AsmAssignSource(val kind: SourceStorageKind,
|
|||||||
return AsmAssignSource(SourceStorageKind.LITERALNUMBER, program, asmgen, cv.type, number = cv)
|
return AsmAssignSource(SourceStorageKind.LITERALNUMBER, program, asmgen, cv.type, number = cv)
|
||||||
|
|
||||||
return when(value) {
|
return when(value) {
|
||||||
is NumericLiteralValue -> AsmAssignSource(SourceStorageKind.LITERALNUMBER, program, asmgen, value.type, number = cv)
|
is NumericLiteralValue -> throw AssemblyError("should have been constant value")
|
||||||
is StringLiteralValue -> throw AssemblyError("string literal value should not occur anymore for asm generation")
|
is StringLiteralValue -> throw AssemblyError("string literal value should not occur anymore for asm generation")
|
||||||
is ArrayLiteralValue -> throw AssemblyError("array literal value should not occur anymore for asm generation")
|
is ArrayLiteralValue -> throw AssemblyError("array literal value should not occur anymore for asm generation")
|
||||||
is IdentifierReference -> {
|
is IdentifierReference -> {
|
||||||
|
@@ -1660,7 +1660,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
asmgen.out(" stz ${target.asmVarname} | stz ${target.asmVarname}+1")
|
asmgen.out(" stz ${target.asmVarname} | stz ${target.asmVarname}+1")
|
||||||
}
|
}
|
||||||
TargetStorageKind.MEMORY -> {
|
TargetStorageKind.MEMORY -> {
|
||||||
throw AssemblyError("no asm gen for assign word $word to memory ${target.memory}")
|
throw AssemblyError("memory is bytes not words")
|
||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
asmgen.loadScaledArrayIndexIntoRegister(target.array!!, DataType.UWORD, CpuRegister.Y)
|
asmgen.loadScaledArrayIndexIntoRegister(target.array!!, DataType.UWORD, CpuRegister.Y)
|
||||||
@@ -1759,7 +1759,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
asmgen.out(" stz ${target.asmVarname} ")
|
asmgen.out(" stz ${target.asmVarname} ")
|
||||||
}
|
}
|
||||||
TargetStorageKind.MEMORY -> {
|
TargetStorageKind.MEMORY -> {
|
||||||
asmgen.out(" lda #${byte.toHex()}")
|
asmgen.out(" lda #0")
|
||||||
storeRegisterAInMemoryAddress(target.memory!!)
|
storeRegisterAInMemoryAddress(target.memory!!)
|
||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
|
@@ -80,8 +80,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
|||||||
// printProgram(program)
|
// printProgram(program)
|
||||||
|
|
||||||
if (args.writeAssembly) {
|
if (args.writeAssembly) {
|
||||||
val result = writeAssembly(program, args.errors, args.outputDir, args.quietAssembler, compilationOptions)
|
when (val result = writeAssembly(program, args.errors, args.outputDir, args.quietAssembler, compilationOptions)) {
|
||||||
when (result) {
|
|
||||||
is WriteAssemblyResult.Ok -> programName = result.filename
|
is WriteAssemblyResult.Ok -> programName = result.filename
|
||||||
is WriteAssemblyResult.Fail -> {
|
is WriteAssemblyResult.Fail -> {
|
||||||
System.err.println(result.error)
|
System.err.println(result.error)
|
||||||
|
@@ -43,10 +43,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
println(logMsg)
|
println(logMsg)
|
||||||
|
|
||||||
val module = importModule(SourceCode.File(srcPath))
|
val module = importModule(SourceCode.File(srcPath))
|
||||||
return if(module==null)
|
return Ok(module)
|
||||||
Err(NoSuchFileException(srcPath.toFile()))
|
|
||||||
else
|
|
||||||
Ok(module)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importLibraryModule(name: String): Module? {
|
fun importLibraryModule(name: String): Module? {
|
||||||
@@ -56,7 +53,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
return executeImportDirective(import, null)
|
return executeImportDirective(import, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun importModule(src: SourceCode) : Module? {
|
private fun importModule(src: SourceCode) : Module {
|
||||||
val moduleAst = Prog8Parser.parseModule(src)
|
val moduleAst = Prog8Parser.parseModule(src)
|
||||||
program.addModule(moduleAst)
|
program.addModule(moduleAst)
|
||||||
|
|
||||||
@@ -150,7 +147,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
locations.forEach {
|
locations.forEach {
|
||||||
try {
|
try {
|
||||||
return Ok(SourceCode.File(it.resolve(fileName)))
|
return Ok(SourceCode.File(it.resolve(fileName)))
|
||||||
} catch (e: NoSuchFileException) {
|
} catch (_: NoSuchFileException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -703,7 +703,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
err("this directive can't be used here")
|
err("this directive can't be used here")
|
||||||
val errormsg = "invalid asmbinary directive, expected arguments: \"filename\" [, offset [, length ] ]"
|
val errormsg = "invalid asmbinary directive, expected arguments: \"filename\" [, offset [, length ] ]"
|
||||||
if(directive.args.isEmpty()) err(errormsg)
|
if(directive.args.isEmpty()) err(errormsg)
|
||||||
else if(directive.args.isNotEmpty() && directive.args[0].str==null) err(errormsg)
|
else if(directive.args[0].str==null) err(errormsg)
|
||||||
else if(directive.args.size>=2 && directive.args[1].int==null) err(errormsg)
|
else if(directive.args.size>=2 && directive.args[1].int==null) err(errormsg)
|
||||||
else if(directive.args.size==3 && directive.args[2].int==null) err(errormsg)
|
else if(directive.args.size==3 && directive.args[2].int==null) err(errormsg)
|
||||||
else if(directive.args.size>3) err(errormsg)
|
else if(directive.args.size>3) err(errormsg)
|
||||||
@@ -1216,7 +1216,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
val arraySpecSize = arrayspec.constIndex()
|
val arraySpecSize = arrayspec.constIndex()
|
||||||
val arraySize = value.value.size
|
val arraySize = value.value.size
|
||||||
if(arraySpecSize!=null && arraySpecSize>0) {
|
if(arraySpecSize!=null && arraySpecSize>0) {
|
||||||
if(arraySpecSize<1 || arraySpecSize>256)
|
if(arraySpecSize>256)
|
||||||
return err("byte array length must be 1-256")
|
return err("byte array length must be 1-256")
|
||||||
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
||||||
if (arraySize != expectedSize)
|
if (arraySize != expectedSize)
|
||||||
@@ -1235,7 +1235,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
val arraySpecSize = arrayspec.constIndex()
|
val arraySpecSize = arrayspec.constIndex()
|
||||||
val arraySize = value.value.size
|
val arraySize = value.value.size
|
||||||
if(arraySpecSize!=null && arraySpecSize>0) {
|
if(arraySpecSize!=null && arraySpecSize>0) {
|
||||||
if(arraySpecSize<1 || arraySpecSize>128)
|
if(arraySpecSize>128)
|
||||||
return err("word array length must be 1-128")
|
return err("word array length must be 1-128")
|
||||||
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
||||||
if (arraySize != expectedSize)
|
if (arraySize != expectedSize)
|
||||||
@@ -1254,7 +1254,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
val arraySize = value.value.size
|
val arraySize = value.value.size
|
||||||
val arraySpecSize = arrayspec.constIndex()
|
val arraySpecSize = arrayspec.constIndex()
|
||||||
if(arraySpecSize!=null && arraySpecSize>0) {
|
if(arraySpecSize!=null && arraySpecSize>0) {
|
||||||
if(arraySpecSize < 1 || arraySpecSize>51)
|
if(arraySpecSize>51)
|
||||||
return err("float array length must be 1-51")
|
return err("float array length must be 1-51")
|
||||||
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
val expectedSize = arrayspec.constIndex() ?: return err("array size specifier must be constant integer value")
|
||||||
if (arraySize != expectedSize)
|
if (arraySize != expectedSize)
|
||||||
|
@@ -11,7 +11,6 @@ import prog8.ast.walk.AstWalker
|
|||||||
import prog8.ast.walk.IAstModification
|
import prog8.ast.walk.IAstModification
|
||||||
import prog8.compiler.BeforeAsmGenerationAstChanger
|
import prog8.compiler.BeforeAsmGenerationAstChanger
|
||||||
import prog8.compilerinterface.CompilationOptions
|
import prog8.compilerinterface.CompilationOptions
|
||||||
import prog8.compilerinterface.ICompilationTarget
|
|
||||||
import prog8.compilerinterface.IErrorReporter
|
import prog8.compilerinterface.IErrorReporter
|
||||||
import prog8.compilerinterface.IStringEncoding
|
import prog8.compilerinterface.IStringEncoding
|
||||||
|
|
||||||
|
@@ -8,7 +8,6 @@ import prog8.ast.walk.AstWalker
|
|||||||
import prog8.ast.walk.IAstModification
|
import prog8.ast.walk.IAstModification
|
||||||
import prog8.compilerinterface.BuiltinFunctions
|
import prog8.compilerinterface.BuiltinFunctions
|
||||||
import prog8.compilerinterface.CompilationOptions
|
import prog8.compilerinterface.CompilationOptions
|
||||||
import prog8.compilerinterface.ICompilationTarget
|
|
||||||
import prog8.compilerinterface.IErrorReporter
|
import prog8.compilerinterface.IErrorReporter
|
||||||
|
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ class TypecastsAdder(val program: Program, val errors: IErrorReporter) : AstWalk
|
|||||||
}
|
}
|
||||||
val cvalue = assignment.value.constValue(program)
|
val cvalue = assignment.value.constValue(program)
|
||||||
if(cvalue!=null) {
|
if(cvalue!=null) {
|
||||||
val number = cvalue.number.toDouble()
|
val number = cvalue.number
|
||||||
// more complex comparisons if the type is different, but the constant value is compatible
|
// more complex comparisons if the type is different, but the constant value is compatible
|
||||||
if (valuetype == DataType.BYTE && targettype == DataType.UBYTE) {
|
if (valuetype == DataType.BYTE && targettype == DataType.UBYTE) {
|
||||||
if(number>0)
|
if(number>0)
|
||||||
|
@@ -173,14 +173,14 @@ class TestModuleImporter: FunSpec({
|
|||||||
val act = { importer.importModule(importing) }
|
val act = { importer.importModule(importing) }
|
||||||
|
|
||||||
repeat(repetitions) { n -> withClue(count[n] + " call") {
|
repeat(repetitions) { n -> withClue(count[n] + " call") {
|
||||||
shouldThrow<ParseError>() { act() }.let {
|
shouldThrow<ParseError> { act() }.let {
|
||||||
it.position.file shouldBe SourceCode.relative(imported).toString()
|
it.position.file shouldBe SourceCode.relative(imported).toString()
|
||||||
withClue("line; should be 1-based") { it.position.line shouldBe 2 }
|
withClue("line; should be 1-based") { it.position.line shouldBe 2 }
|
||||||
withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }
|
withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }
|
||||||
withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }
|
withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
withClue("imported module with error in it should not be present") { program.modules.size shouldBe 1 }
|
withClue("imported module with error in it should not be present") { program.modules.size shouldBe 1 }
|
||||||
program.modules[0].name shouldBe internedStringsModuleName
|
program.modules[0].name shouldBe internedStringsModuleName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,9 +35,6 @@ enum class DataType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun oneOf(vararg types: DataType) = this in types
|
fun oneOf(vararg types: DataType) = this in types
|
||||||
infix fun isAssignableTo(targetTypes: Set<DataType>) = targetTypes.any { this isAssignableTo it }
|
|
||||||
infix fun isNotAssignableTo(targetType: DataType) = !this.isAssignableTo(targetType)
|
|
||||||
infix fun isNotAssignableTo(targetTypes: Set<DataType>) = !this.isAssignableTo(targetTypes)
|
|
||||||
|
|
||||||
infix fun largerThan(other: DataType) =
|
infix fun largerThan(other: DataType) =
|
||||||
when {
|
when {
|
||||||
|
Reference in New Issue
Block a user