tiny tweak of typecasting str to uword

This commit is contained in:
Irmen de Jong 2020-11-26 19:21:07 +01:00
parent 2b43353eb4
commit e876008427
3 changed files with 25 additions and 16 deletions

View File

@ -170,6 +170,12 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, val errors: E
AddressOf(typecast.expression as IdentifierReference, typecast.position),
parent
))
} else if(typecast.expression is IFunctionCall) {
return listOf(IAstModification.ReplaceNode(
typecast,
typecast.expression,
parent
))
}
} else {
errors.err("cannot cast pass-by-reference value to type ${typecast.type} (only to UWORD)", typecast.position)

View File

@ -274,22 +274,23 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
when (valueDt) {
in ByteDatatypes -> {
assignExpressionToRegister(value, RegisterOrPair.A)
return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.A, valueDt)
assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.A, valueDt)
}
in WordDatatypes -> {
assignExpressionToRegister(value, RegisterOrPair.AY)
return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt)
assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt)
}
DataType.FLOAT -> {
assignExpressionToRegister(value, RegisterOrPair.FAC1)
return assignTypecastedFloatFAC1(target.asmVarname, targetDt)
assignTypecastedFloatFAC1(target.asmVarname, targetDt)
}
in PassByReferenceDatatypes -> {
// str/array value cast (most likely to UWORD, take address-of)
return assignExpressionToVariable(value, target.asmVarname, targetDt, null) // TODO test this cast
assignExpressionToVariable(value, target.asmVarname, targetDt, null)
}
else -> throw AssemblyError("strange dt in typecast assign to var: $valueDt --> $targetDt")
}
return
}
// give up, do it via eval stack

View File

@ -12,26 +12,28 @@ main {
uword uw
byte bb
ubyte ub
str string1 = "irmen"
uword[] array = [1111,2222,3333]
fl = 9997.999
ww = (fl+1.1) as word
uw = (fl+1.1) as uword
fl = 97.999
bb = (fl+1.1) as byte
ub = (fl+1.1) as ubyte
txt.print_w(ww)
uw = string1 as uword
txt.print_uwhex(uw,1)
txt.chrout('\n')
txt.print_uw(uw)
uw = array as uword
txt.print_uwhex(uw,1)
txt.chrout('\n')
txt.print_b(bb)
uw = name() as uword
txt.print_uwhex(uw,1)
txt.chrout('\n')
txt.print_ub(ub)
uw = name()
txt.print_uwhex(uw,1)
txt.chrout('\n')
test_stack.test()
}
sub name() -> str {
return "irmen"
}
}