mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
reduce number of similar errors for type problem in assignment
This commit is contained in:
parent
c3144a20db
commit
fbcd9a0c1d
@ -81,7 +81,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
val results = mutableListOf<CompilationResult>()
|
val results = mutableListOf<CompilationResult>()
|
||||||
for(filepathRaw in moduleFiles) {
|
for(filepathRaw in moduleFiles) {
|
||||||
val filepath = pathFrom(filepathRaw).normalize()
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val args = CompilerArguments(
|
val compilerArgs = CompilerArguments(
|
||||||
filepath,
|
filepath,
|
||||||
dontOptimize != true,
|
dontOptimize != true,
|
||||||
optimizeFloatExpressions == true,
|
optimizeFloatExpressions == true,
|
||||||
@ -92,7 +92,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
srcdirs,
|
srcdirs,
|
||||||
outputPath
|
outputPath
|
||||||
)
|
)
|
||||||
val compilationResult = compileProgram(args)
|
val compilationResult = compileProgram(compilerArgs)
|
||||||
results.add(compilationResult)
|
results.add(compilationResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
val filepath = pathFrom(filepathRaw).normalize()
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val compilationResult: CompilationResult
|
val compilationResult: CompilationResult
|
||||||
try {
|
try {
|
||||||
val args = CompilerArguments(
|
val compilerArgs = CompilerArguments(
|
||||||
filepath,
|
filepath,
|
||||||
dontOptimize != true,
|
dontOptimize != true,
|
||||||
optimizeFloatExpressions == true,
|
optimizeFloatExpressions == true,
|
||||||
@ -140,7 +140,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
|||||||
srcdirs,
|
srcdirs,
|
||||||
outputPath
|
outputPath
|
||||||
)
|
)
|
||||||
compilationResult = compileProgram(args)
|
compilationResult = compileProgram(compilerArgs)
|
||||||
if (!compilationResult.success)
|
if (!compilationResult.success)
|
||||||
return false
|
return false
|
||||||
} catch (x: AstException) {
|
} catch (x: AstException) {
|
||||||
|
@ -11,7 +11,6 @@ import prog8.ast.walk.IAstVisitor
|
|||||||
import prog8.compilerinterface.*
|
import prog8.compilerinterface.*
|
||||||
import java.io.CharConversionException
|
import java.io.CharConversionException
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
|
|
||||||
internal class AstChecker(private val program: Program,
|
internal class AstChecker(private val program: Program,
|
||||||
@ -414,18 +413,6 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(assignment: Assignment) {
|
override fun visit(assignment: Assignment) {
|
||||||
if(assignment.value is FunctionCall) {
|
|
||||||
val stmt = (assignment.value as FunctionCall).target.targetStatement(program)
|
|
||||||
if (stmt is Subroutine) {
|
|
||||||
val idt = assignment.target.inferType(program)
|
|
||||||
if(!idt.isKnown)
|
|
||||||
throw FatalAstException("assignment target invalid dt")
|
|
||||||
if(stmt.returntypes.isEmpty() || (stmt.returntypes.size == 1 && stmt.returntypes.single() isNotAssignableTo idt.getOr(DataType.BYTE))) {
|
|
||||||
errors.err("return type mismatch: ${stmt.returntypes.single()} expected $idt", assignment.value.position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val targetDt = assignment.target.inferType(program)
|
val targetDt = assignment.target.inferType(program)
|
||||||
val valueDt = assignment.value.inferType(program)
|
val valueDt = assignment.value.inferType(program)
|
||||||
if(valueDt.isKnown && !(valueDt isAssignableTo targetDt)) {
|
if(valueDt.isKnown && !(valueDt isAssignableTo targetDt)) {
|
||||||
@ -500,7 +487,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
errors.err("assignment value is invalid or has no proper datatype", assignment.value.position)
|
errors.err("assignment value is invalid or has no proper datatype", assignment.value.position)
|
||||||
} else {
|
} else {
|
||||||
checkAssignmentCompatible(targetDatatype.getOr(DataType.BYTE),
|
checkAssignmentCompatible(targetDatatype.getOr(DataType.BYTE),
|
||||||
sourceDatatype.getOr(DataType.BYTE), assignment.value, assignment.position)
|
sourceDatatype.getOr(DataType.BYTE), assignment.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1371,8 +1358,8 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
private fun checkAssignmentCompatible(targetDatatype: DataType,
|
private fun checkAssignmentCompatible(targetDatatype: DataType,
|
||||||
sourceDatatype: DataType,
|
sourceDatatype: DataType,
|
||||||
sourceValue: Expression,
|
sourceValue: Expression) : Boolean {
|
||||||
position: Position) : Boolean {
|
val position = sourceValue.position
|
||||||
|
|
||||||
if(sourceValue is RangeExpr)
|
if(sourceValue is RangeExpr)
|
||||||
errors.err("can't assign a range value to something else", position)
|
errors.err("can't assign a range value to something else", position)
|
||||||
@ -1400,15 +1387,9 @@ internal class AstChecker(private val program: Program,
|
|||||||
errors.err("cannot assign float to ${targetDatatype.name.lowercase()}; possible loss of precision. Suggestion: round the value or revert to integer arithmetic", position)
|
errors.err("cannot assign float to ${targetDatatype.name.lowercase()}; possible loss of precision. Suggestion: round the value or revert to integer arithmetic", position)
|
||||||
else {
|
else {
|
||||||
if(targetDatatype!=DataType.UWORD && sourceDatatype !in PassByReferenceDatatypes)
|
if(targetDatatype!=DataType.UWORD && sourceDatatype !in PassByReferenceDatatypes)
|
||||||
errors.err(
|
errors.err("type of value $sourceDatatype doesn't match target $targetDatatype", position)
|
||||||
"cannot assign ${sourceDatatype.name.lowercase()} to ${
|
|
||||||
targetDatatype.name.lowercase(
|
|
||||||
Locale.getDefault()
|
|
||||||
)
|
|
||||||
}", position)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.io.File
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.channels.Channels
|
import java.nio.channels.Channels
|
||||||
import java.nio.charset.CodingErrorAction
|
import java.nio.charset.CodingErrorAction
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
@ -132,7 +131,7 @@ sealed class SourceCode {
|
|||||||
val inpStr = object {}.javaClass.getResourceAsStream(normalized)!!
|
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
|
// CharStreams.fromStream() doesn't allow us to set the stream name properly, so we use a lower level api
|
||||||
val channel = Channels.newChannel(inpStr)
|
val channel = Channels.newChannel(inpStr)
|
||||||
return CharStreams.fromChannel(channel, StandardCharsets.UTF_8, 4096, CodingErrorAction.REPLACE, origin, -1)
|
return CharStreams.fromChannel(channel, Charsets.UTF_8, 4096, CodingErrorAction.REPLACE, origin, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun readText(): String {
|
override fun readText(): String {
|
||||||
|
@ -7,41 +7,14 @@ main {
|
|||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
string.copy()
|
uword[10] ptrs
|
||||||
|
ubyte @shared xx
|
||||||
ubyte @shared dummy
|
xx = compare("zzz", ptrs[2])
|
||||||
word b1 = 1111
|
|
||||||
byte b2 = 22
|
|
||||||
word b3 = 3333
|
|
||||||
dummy++
|
|
||||||
labelz()
|
|
||||||
labelz(1)
|
|
||||||
printz(1)
|
|
||||||
printz(1,2,3,4,5,6)
|
|
||||||
func(-b1,-b2,-b3 , 3, 4, 5)
|
|
||||||
|
|
||||||
labelz:
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub printz(word a1, byte a2, word a3) {
|
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
|
||||||
txt.print_w(a1)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(a2)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_w(a3)
|
|
||||||
txt.nl()
|
|
||||||
}
|
|
||||||
asmsub func(word a1 @XY, byte a2 @A, word a3 @R0) {
|
|
||||||
%asm {{
|
%asm {{
|
||||||
stx printz.a1
|
rts
|
||||||
sty printz.a1+1
|
|
||||||
sta printz.a2
|
|
||||||
lda cx16.r0
|
|
||||||
sta printz.a3
|
|
||||||
lda cx16.r0+1
|
|
||||||
sta printz.a3+1
|
|
||||||
jmp printz
|
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user