mirror of https://github.com/irmen/prog8.git
Compare commits
2 Commits
53df0eb707
...
4d37581694
Author | SHA1 | Date |
---|---|---|
Irmen de Jong | 4d37581694 | |
Irmen de Jong | 5d7ddebcad |
|
@ -1804,8 +1804,8 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||
|
||||
when (valueDt) {
|
||||
DataType.BOOL -> {
|
||||
if(targetDt in ByteDatatypes) {
|
||||
// optimization to assign boolean expression to byte target (just assign the 0 or 1 directly, no cast needed)
|
||||
if(targetDt in IntegerDatatypes) {
|
||||
// optimization to assign boolean expression to integer target (just assign the 0 or 1 directly)
|
||||
val assignDirect = AsmAssignment(
|
||||
AsmAssignSource.fromAstSource(value, program, asmgen),
|
||||
target,
|
||||
|
@ -1814,7 +1814,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||
)
|
||||
assignExpression(assignDirect, target.scope)
|
||||
} else {
|
||||
throw AssemblyError("expected bool or byte target type")
|
||||
TODO("assign bool to non-integer type $targetDt")
|
||||
}
|
||||
}
|
||||
in ByteDatatypes -> {
|
||||
|
|
|
@ -11,7 +11,6 @@ import prog8.ast.expressions.*
|
|||
import prog8.ast.printProgram
|
||||
import prog8.ast.statements.Assignment
|
||||
import prog8.ast.statements.IfElse
|
||||
import prog8.ast.statements.VarDecl
|
||||
import prog8.code.ast.PtAsmSub
|
||||
import prog8.code.ast.PtSub
|
||||
import prog8.code.core.DataType
|
||||
|
@ -826,4 +825,18 @@ main {
|
|||
}"""
|
||||
compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("bool to word cast") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
bool @shared flag, flag2
|
||||
cx16.r0L = (flag and flag2) as ubyte
|
||||
cx16.r0 = (flag and flag2) as uword
|
||||
}
|
||||
}"""
|
||||
|
||||
compileText(VMTarget(), false, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(C64Target(), false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
|
|
@ -590,5 +590,27 @@ main {
|
|||
val valT = (st[17] as Assignment).value
|
||||
(valT as IdentifierReference).nameInSource shouldBe listOf("r")
|
||||
}
|
||||
|
||||
test("various multi var decl symbol lookups") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
uword @shared a,b
|
||||
b = a ; works
|
||||
cx16.r1L = lsb(a) ; works
|
||||
funcw(a) ; works
|
||||
funcb(lsb(a)) ; fails :-( TODO FIX
|
||||
}
|
||||
|
||||
sub funcw(uword arg) {
|
||||
arg++
|
||||
}
|
||||
|
||||
sub funcb(ubyte arg) {
|
||||
arg++
|
||||
}
|
||||
}"""
|
||||
compileText(Cx16Target(), false, src) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -82,13 +82,8 @@ interface IStatementContainer {
|
|||
// but adding a memoization cache didn't make much of a practical runtime difference...
|
||||
for (stmt in statements) {
|
||||
when(stmt) {
|
||||
// is INamedStatement -> {
|
||||
// if(stmt.name==name) return stmt
|
||||
// }
|
||||
is VarDecl -> if(stmt.name==name) return stmt
|
||||
is Label -> if(stmt.name==name) return stmt
|
||||
is Subroutine -> if(stmt.name==name) return stmt
|
||||
is Block -> if(stmt.name==name) return stmt
|
||||
is VarDecl -> if(stmt.name==name || stmt.names.contains(name)) return stmt
|
||||
is INamedStatement -> if(stmt.name==name) return stmt
|
||||
is AnonymousScope -> {
|
||||
val found = stmt.searchSymbol(name)
|
||||
if(found!=null)
|
||||
|
|
|
@ -1,49 +1,20 @@
|
|||
%import textio
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
%import textio
|
||||
|
||||
main {
|
||||
ubyte[255] array1
|
||||
ubyte[255] array2
|
||||
uword block1 = memory("b1", 6000 ,0)
|
||||
uword block2 = memory("b2", 6000 ,0)
|
||||
|
||||
sub start() {
|
||||
cbm.SETTIM(0,0,0)
|
||||
uword @shared a,b
|
||||
b = a ; works
|
||||
cx16.r1L = lsb(a) ; works
|
||||
funcw(a) ; works
|
||||
funcb(lsb(a)) ; fails :-(
|
||||
}
|
||||
|
||||
repeat 2000 {
|
||||
sys.memcopy(array1, array2, sizeof(array1))
|
||||
}
|
||||
sub funcw(uword arg) {
|
||||
arg++
|
||||
}
|
||||
|
||||
txt.print_uw(cbm.RDTIM16())
|
||||
txt.nl()
|
||||
|
||||
cbm.SETTIM(0,0,0)
|
||||
|
||||
repeat 2000 {
|
||||
cx16.memory_copy(array1, array2, sizeof(array1))
|
||||
}
|
||||
|
||||
txt.print_uw(cbm.RDTIM16())
|
||||
txt.nl()
|
||||
|
||||
cbm.SETTIM(0,0,0)
|
||||
|
||||
repeat 100 {
|
||||
sys.memcopy(block1, block2, 6000)
|
||||
}
|
||||
|
||||
txt.print_uw(cbm.RDTIM16())
|
||||
txt.nl()
|
||||
|
||||
cbm.SETTIM(0,0,0)
|
||||
|
||||
repeat 100 {
|
||||
cx16.memory_copy(block1, block2, 6000)
|
||||
}
|
||||
|
||||
txt.print_uw(cbm.RDTIM16())
|
||||
txt.nl()
|
||||
sub funcb(ubyte arg) {
|
||||
arg++
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue