mirror of
https://github.com/irmen/prog8.git
synced 2024-07-10 23:29:02 +00:00
@(...) in an expression is now more efficient, without translateExpression()
This commit is contained in:
parent
e95af7498e
commit
7fa21fbdff
@ -8,6 +8,7 @@
|
||||
|
||||
read_byte_from_address_on_stack .proc
|
||||
; -- read the byte from the memory address on the top of the stack, return in A (stack remains unchanged)
|
||||
; TODO get rid of this by not evaluating the adress onto the stack, but directly into AY or SCRATCH_W2
|
||||
lda P8ESTACK_LO+1,x
|
||||
ldy P8ESTACK_HI+1,x
|
||||
sta P8ZP_SCRATCH_W2
|
||||
|
@ -360,7 +360,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
}
|
||||
|
||||
// todo via func args or registers
|
||||
// todo via func args or regs
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.greater_ub | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
@ -771,7 +771,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
}
|
||||
|
||||
// TODO via func args or regs
|
||||
// todo via func args or regs
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.equal_b | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
@ -1117,7 +1117,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
|
||||
private fun translateExpression(typecast: TypecastExpression) {
|
||||
translateExpression(typecast.expression) // todo avoid stack
|
||||
translateExpression(typecast.expression)
|
||||
when(typecast.expression.inferType(program).typeOrElse(DataType.STRUCT)) {
|
||||
DataType.UBYTE -> {
|
||||
when(typecast.type) {
|
||||
@ -1200,12 +1200,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
asmgen.out(" sta P8ESTACK_LO,x | dex")
|
||||
}
|
||||
else -> {
|
||||
translateExpression(expr.addressExpression) // todo directly into A
|
||||
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack")
|
||||
if(pushResultOnEstack)
|
||||
asmgen.out(" sta P8ESTACK_LO+1,x")
|
||||
else
|
||||
asmgen.out(" php | inx | plp")
|
||||
asmgen.assignExpressionToVariable(expr.addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
if(pushResultOnEstack) {
|
||||
asmgen.out(" dex | ldy #0 | lda (P8ZP_SCRATCH_W2),y | sta P8ESTACK_LO,x")
|
||||
} else {
|
||||
asmgen.out(" ldy #0 | lda (P8ZP_SCRATCH_W2),y")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1533,7 +1533,6 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
|
||||
private fun translateExpression(expr: PrefixExpression) {
|
||||
// todo avoid using stack
|
||||
translateExpression(expr.expression)
|
||||
val itype = expr.inferType(program)
|
||||
if(!itype.isKnown)
|
||||
|
@ -114,8 +114,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
assignMemoryByte(assign.target, null, value.addressExpression as IdentifierReference)
|
||||
}
|
||||
else -> {
|
||||
asmgen.translateExpression(value.addressExpression) // TODO directly into AY
|
||||
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | inx")
|
||||
asmgen.assignExpressionToVariable(value.addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, assign.target.scope)
|
||||
asmgen.out(" ldy #0 | lda (P8ZP_SCRATCH_W2),y")
|
||||
assignRegisterByte(assign.target, CpuRegister.A)
|
||||
}
|
||||
}
|
||||
@ -200,8 +200,9 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// everything else just evaluate via the stack.
|
||||
// TODO byte and word values not via stack but via A / AY registers?
|
||||
// Everything else just evaluate via the stack.
|
||||
// (we can't use the assignment helper functions to do it via registers here,
|
||||
// because the code here is the implementation of exactly that...)
|
||||
asmgen.translateExpression(value)
|
||||
if(assign.target.datatype in WordDatatypes && assign.source.datatype in ByteDatatypes)
|
||||
asmgen.signExtendStackLsb(assign.source.datatype)
|
||||
@ -268,7 +269,6 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
|
||||
// give up, do it via eval stack
|
||||
// TODO byte and word values not via stack but directly via A or AY registers?
|
||||
asmgen.translateExpression(origAssign.source.expression!!)
|
||||
assignStackValue(target)
|
||||
}
|
||||
@ -1242,17 +1242,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
asmgen.storeByteIntoPointer(addressExpr, ldaInstructionArg)
|
||||
}
|
||||
else -> {
|
||||
asmgen.out(" lda $ldaInstructionArg | pha")
|
||||
asmgen.translateExpression(addressExpr) // TODO directly into AY
|
||||
asmgen.out("""
|
||||
inx
|
||||
lda P8ESTACK_LO,x
|
||||
sta P8ZP_SCRATCH_W2
|
||||
lda P8ESTACK_HI,x
|
||||
sta P8ZP_SCRATCH_W2+1
|
||||
ldy #0
|
||||
pla
|
||||
sta (P8ZP_SCRATCH_W2),y""")
|
||||
asmgen.assignExpressionToVariable(addressExpr, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
asmgen.out(" ldy #0 | lda $ldaInstructionArg | sta (P8ZP_SCRATCH_W2),y")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1276,16 +1267,9 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
else -> {
|
||||
asmgen.saveRegister(register, false, memoryAddress.definingSubroutine()!!)
|
||||
asmgen.translateExpression(addressExpr) // TODO directly into AY
|
||||
asmgen.assignExpressionToVariable(addressExpr, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
asmgen.restoreRegister(CpuRegister.A, false)
|
||||
asmgen.out("""
|
||||
inx
|
||||
ldy P8ESTACK_LO,x
|
||||
sty P8ZP_SCRATCH_W2
|
||||
ldy P8ESTACK_HI,x
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
ldy #0
|
||||
sta (P8ZP_SCRATCH_W2),y""")
|
||||
asmgen.out(" ldy #0 | sta (P8ZP_SCRATCH_W2),y")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,11 @@ main {
|
||||
sub start() {
|
||||
|
||||
ubyte ub = 4
|
||||
ubyte ub2 = 8
|
||||
uword uw = 5
|
||||
|
||||
if ding(22)!=0
|
||||
txt.chrout('1')
|
||||
if ding(22)
|
||||
txt.chrout('2')
|
||||
txt.chrout('\n')
|
||||
|
||||
if dingw($1100)!=$0000
|
||||
txt.chrout('1')
|
||||
if dingw($1100)
|
||||
txt.chrout('2')
|
||||
txt.chrout('\n')
|
||||
ub = uw*3 as ubyte
|
||||
txt.print_ub(ub)
|
||||
|
||||
testX()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user