mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
remove bool to ubyte typecasts
This commit is contained in:
parent
5b6534bb28
commit
2f5bed36b3
@ -149,6 +149,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
|
||||
val value = if(program.memsizer.memorySize(origValue.type) > program.memsizer.memorySize(target.datatype)) {
|
||||
val typecast = PtTypeCast(target.datatype, origValue.position)
|
||||
typecast.add(origValue)
|
||||
require(typecast.type!=origValue.type)
|
||||
typecast
|
||||
}
|
||||
else {
|
||||
@ -1783,6 +1784,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
|
||||
val castDt = if (outerCastDt largerThan innerCastDt) innerCastDt else outerCastDt
|
||||
val resultingCast = PtTypeCast(castDt, position)
|
||||
resultingCast.add((cast.value as PtTypeCast).value)
|
||||
require(castDt!=resultingCast.value.type)
|
||||
inplaceCast(target, resultingCast, position)
|
||||
}
|
||||
}
|
||||
|
@ -464,6 +464,7 @@ class IntermediateAstMaker(private val program: Program, private val symbolTable
|
||||
private fun transform(srcCast: TypecastExpression): PtTypeCast {
|
||||
val cast = PtTypeCast(srcCast.type, srcCast.position)
|
||||
cast.add(transformExpression(srcCast.expression))
|
||||
require(cast.type!=cast.value.type)
|
||||
return cast
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
||||
}
|
||||
|
||||
val sourceDt = typecast.expression.inferType(program)
|
||||
if(sourceDt istype typecast.type)
|
||||
if(sourceDt istype typecast.type || (sourceDt istype DataType.BOOL && typecast.type==DataType.UBYTE))
|
||||
return listOf(IAstModification.ReplaceNode(typecast, typecast.expression, parent))
|
||||
|
||||
if(parent is Assignment) {
|
||||
|
@ -11,7 +11,8 @@ class TestVarious: FunSpec({
|
||||
main {
|
||||
sub start() {
|
||||
ubyte[3] values
|
||||
func(33 + (22 in values))
|
||||
func(22 in values)
|
||||
ubyte @shared qq = 22 in values
|
||||
}
|
||||
sub func(ubyte arg) {
|
||||
arg++
|
||||
|
@ -14,7 +14,7 @@ object InferredTypes {
|
||||
fun getOr(default: DataType) = if(isUnknown || isVoid) default else datatype!!
|
||||
fun getOrElse(transform: (InferredType) -> DataType): DataType =
|
||||
if(isUnknown || isVoid) transform(this) else datatype!!
|
||||
infix fun istype(type: DataType): Boolean = if(isUnknown || isVoid) false else this.datatype==type
|
||||
infix fun istype(type: DataType): Boolean = if(isUnknown || isVoid) false else this.datatype==type // strict equality if known
|
||||
infix fun isnot(type: DataType): Boolean = if(isUnknown || isVoid) true else this.datatype!=type
|
||||
fun oneOf(vararg types: DataType) = if(isUnknown || isVoid) false else this.datatype in types
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user