remove bool to ubyte typecasts

This commit is contained in:
Irmen de Jong 2023-01-31 01:14:13 +01:00
parent 5b6534bb28
commit 2f5bed36b3
5 changed files with 7 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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) {

View File

@ -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++

View File

@ -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