mirror of
https://github.com/irmen/prog8.git
synced 2025-03-13 05:31:01 +00:00
fix type errors in Range containment check
This commit is contained in:
parent
069143092d
commit
cd2cc89e6a
2
.idea/kotlinc.xml
generated
2
.idea/kotlinc.xml
generated
@ -14,6 +14,6 @@
|
||||
<option name="additionalArguments" value="-Xwhen-guards" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="2.1.0" />
|
||||
<option name="version" value="2.1.10" />
|
||||
</component>
|
||||
</project>
|
@ -440,12 +440,8 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
|
||||
parent: Node
|
||||
): List<IAstModification> {
|
||||
|
||||
if(!varDt.isUndefined) {
|
||||
if(fromDt==varDt && toDt==varDt) {
|
||||
return noModifications
|
||||
} else if(fromDt==toDt && fromDt.isAssignableTo(varDt)) {
|
||||
return noModifications
|
||||
}
|
||||
if(!varDt.isUndefined && fromDt==varDt && toDt==varDt) {
|
||||
return noModifications
|
||||
}
|
||||
|
||||
if(fromConst!=null) {
|
||||
@ -488,6 +484,45 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
|
||||
}
|
||||
|
||||
val modifications = mutableListOf<IAstModification>()
|
||||
|
||||
if(!varDt.isUndefined) {
|
||||
// adjust from value
|
||||
if (fromDt!=varDt) {
|
||||
if (!fromDt.isUndefined && !fromDt.isAssignableTo(varDt)) {
|
||||
if(fromConst!=null) {
|
||||
val cast = fromConst.cast(varDt.base, true)
|
||||
if(cast.isValid)
|
||||
modifications += IAstModification.ReplaceNode(range.to, cast.valueOrZero(), range)
|
||||
else
|
||||
errors.err("incompatible range value type", range.from.position)
|
||||
} else {
|
||||
errors.err("incompatible range value type", range.from.position)
|
||||
}
|
||||
} else if(fromConst!=null) {
|
||||
modifications += IAstModification.ReplaceNode(range.from, NumericLiteral(varDt.base, fromConst.number, fromConst.position), range)
|
||||
}
|
||||
}
|
||||
|
||||
// adjust to value
|
||||
if (toDt!=varDt) {
|
||||
if (!toDt.isUndefined && !toDt.isAssignableTo(varDt)) {
|
||||
if(toConst!=null) {
|
||||
val cast = toConst.cast(varDt.base, true)
|
||||
if(cast.isValid)
|
||||
modifications += IAstModification.ReplaceNode(range.to, cast.valueOrZero(), range)
|
||||
else
|
||||
errors.err("incompatible range value type", range.to.position)
|
||||
} else {
|
||||
errors.err("incompatible range value type", range.to.position)
|
||||
}
|
||||
} else if(toConst!=null) {
|
||||
modifications += IAstModification.ReplaceNode(range.to, NumericLiteral(varDt.base, toConst.number, toConst.position), range)
|
||||
}
|
||||
}
|
||||
if(modifications.isNotEmpty())
|
||||
return modifications
|
||||
}
|
||||
|
||||
val (commonDt, toChange) = BinaryExpression.commonDatatype(fromDt, toDt, range.from, range.to)
|
||||
if(toChange!=null)
|
||||
addTypecastOrCastedValueModification(modifications, toChange, commonDt.base, range)
|
||||
|
@ -435,4 +435,19 @@ main{
|
||||
"""
|
||||
compileText(Cx16Target(), true, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("range types changed from byte to words if needed by outer containment check") {
|
||||
val src= """
|
||||
main {
|
||||
sub start() {
|
||||
bool @shared z1 = cx16.r0 in 1 to 135
|
||||
bool @shared z2 = cx16.r0 in $0001 to 135
|
||||
bool @shared z4 = cx16.r0s in 1 to 135
|
||||
bool @shared z6 = cx16.r0s in 1 to (135 as word)
|
||||
bool @shared z3 = cx16.r0 in 1 to (135 as word)
|
||||
bool @shared z5 = cx16.r0s in $0001 to 135
|
||||
}
|
||||
}"""
|
||||
compileText(Cx16Target(), true, src) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,15 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix string concatenation error
|
||||
uword totalseconds = 3636
|
||||
uword minutes
|
||||
uword seconds
|
||||
divmod(totalseconds, 60 as uword, minutes, seconds)
|
||||
str minString = conv.str_uw(minutes)
|
||||
str secString = conv.str_uw(seconds)
|
||||
txt.print(minString + ":" + secString)
|
||||
|
||||
- Make neo and atari targets external via configs? They are very bare bones atm so easier to contribute to if they're configurable externally? What about the pet32 target
|
||||
|
||||
- add paypal donation button as well?
|
||||
@ -12,6 +21,7 @@ TODO
|
||||
Future Things and Ideas
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Look at github PR for improved romability
|
||||
- Kotlin: can we use inline value classes in certain spots?
|
||||
- add float support to the configurable compiler targets
|
||||
- improve support for romable code (see github issue 149)
|
||||
|
Loading…
x
Reference in New Issue
Block a user