mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 20:33:39 +00:00
comments
This commit is contained in:
parent
3ada0fdf84
commit
aef4598cec
@ -184,6 +184,7 @@ internal class AsmGen(private val program: Program,
|
|||||||
blockLevelVarInits.getValue(block).forEach { decl ->
|
blockLevelVarInits.getValue(block).forEach { decl ->
|
||||||
val scopedFullName = decl.makeScopedName(decl.name).split('.')
|
val scopedFullName = decl.makeScopedName(decl.name).split('.')
|
||||||
require(scopedFullName.first()==block.name)
|
require(scopedFullName.first()==block.name)
|
||||||
|
// TODO use AsmAssignment
|
||||||
val target = AssignTarget(IdentifierReference(scopedFullName.drop(1), decl.position), null, null, decl.position)
|
val target = AssignTarget(IdentifierReference(scopedFullName.drop(1), decl.position), null, null, decl.position)
|
||||||
val assign = Assignment(target, decl.value!!, decl.position)
|
val assign = Assignment(target, decl.value!!, decl.position)
|
||||||
assign.linkParents(decl.parent)
|
assign.linkParents(decl.parent)
|
||||||
@ -1035,6 +1036,7 @@ $counterVar .byte 0""")
|
|||||||
} else {
|
} else {
|
||||||
val next = (stmt.parent as INameScope).nextSibling(stmt)
|
val next = (stmt.parent as INameScope).nextSibling(stmt)
|
||||||
if (next !is ForLoop || next.loopVar.nameInSource.single() != stmt.name) {
|
if (next !is ForLoop || next.loopVar.nameInSource.single() != stmt.name) {
|
||||||
|
// TODO use AsmAssignment
|
||||||
val target = AssignTarget(IdentifierReference(listOf(stmt.name), stmt.position), null, null, stmt.position)
|
val target = AssignTarget(IdentifierReference(listOf(stmt.name), stmt.position), null, null, stmt.position)
|
||||||
val assign = Assignment(target, stmt.value!!, stmt.position)
|
val assign = Assignment(target, stmt.value!!, stmt.position)
|
||||||
assign.linkParents(stmt.parent)
|
assign.linkParents(stmt.parent)
|
||||||
|
@ -116,6 +116,7 @@ $endLabel inx""")
|
|||||||
stepsize == 1 || stepsize == -1 -> {
|
stepsize == 1 || stepsize == -1 -> {
|
||||||
asmgen.translateExpression(range.to)
|
asmgen.translateExpression(range.to)
|
||||||
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
||||||
|
// TODO use AsmAssignment
|
||||||
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
||||||
assignLoopvar.linkParents(stmt)
|
assignLoopvar.linkParents(stmt)
|
||||||
asmgen.translate(assignLoopvar)
|
asmgen.translate(assignLoopvar)
|
||||||
@ -162,6 +163,7 @@ $modifiedLabel2 cmp #0 ; modified
|
|||||||
sta $modifiedLabel2+1
|
sta $modifiedLabel2+1
|
||||||
""")
|
""")
|
||||||
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
||||||
|
// TODO use AsmAssignment
|
||||||
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
||||||
assignLoopvar.linkParents(stmt)
|
assignLoopvar.linkParents(stmt)
|
||||||
asmgen.translate(assignLoopvar)
|
asmgen.translate(assignLoopvar)
|
||||||
@ -215,6 +217,7 @@ $endLabel inx""")
|
|||||||
sta $modifiedLabel2+1
|
sta $modifiedLabel2+1
|
||||||
""")
|
""")
|
||||||
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
val varname = asmgen.asmIdentifierName(stmt.loopVar)
|
||||||
|
// TODO use AsmAssignment
|
||||||
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
val assignLoopvar = Assignment(AssignTarget(stmt.loopVar, null, null, stmt.loopVar.position), range.from, range.position)
|
||||||
assignLoopvar.linkParents(stmt)
|
assignLoopvar.linkParents(stmt)
|
||||||
asmgen.translate(assignLoopvar)
|
asmgen.translate(assignLoopvar)
|
||||||
|
@ -10,6 +10,7 @@ import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_HI_HEX
|
|||||||
import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_LO_HEX
|
import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_LO_HEX
|
||||||
import prog8.compiler.target.c64.codegen.AsmGen
|
import prog8.compiler.target.c64.codegen.AsmGen
|
||||||
import prog8.compiler.toHex
|
import prog8.compiler.toHex
|
||||||
|
import prog8.functions.BuiltinFunctions
|
||||||
|
|
||||||
|
|
||||||
internal class AssignmentAsmGen(private val program: Program, private val asmgen: AsmGen) {
|
internal class AssignmentAsmGen(private val program: Program, private val asmgen: AsmGen) {
|
||||||
@ -115,13 +116,42 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
}
|
}
|
||||||
SourceStorageKind.EXPRESSION -> {
|
SourceStorageKind.EXPRESSION -> {
|
||||||
val value = assign.source.expression!!
|
val value = assign.source.expression!!
|
||||||
if (value is AddressOf) {
|
when(value) {
|
||||||
assignAddressOf(assign.target, value.identifier)
|
is AddressOf -> assignAddressOf(assign.target, value.identifier)
|
||||||
}
|
is NumericLiteralValue -> throw AssemblyError("source kind should have been literalnumber")
|
||||||
// TODO more special cases to avoid stack eval?
|
is IdentifierReference -> throw AssemblyError("source kind should have been variable")
|
||||||
else {
|
is ArrayIndexedExpression -> throw AssemblyError("source kind should have been array")
|
||||||
asmgen.translateExpression(value)
|
is DirectMemoryRead -> throw AssemblyError("source kind should have been memory")
|
||||||
assignStackValue(assign.target)
|
// is TypecastExpression -> {
|
||||||
|
// if(assign.target.kind == TargetStorageKind.STACK) {
|
||||||
|
// asmgen.translateExpression(value)
|
||||||
|
// assignStackValue(assign.target)
|
||||||
|
// } else {
|
||||||
|
// println("!!!!TYPECAST to ${assign.target.kind} $value")
|
||||||
|
// // TODO maybe we can do the typecast on the target directly instead of on the stack?
|
||||||
|
// asmgen.translateExpression(value)
|
||||||
|
// assignStackValue(assign.target)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// is FunctionCall -> {
|
||||||
|
// if (assign.target.kind == TargetStorageKind.STACK) {
|
||||||
|
// asmgen.translateExpression(value)
|
||||||
|
// assignStackValue(assign.target)
|
||||||
|
// } else {
|
||||||
|
// val functionName = value.target.nameInSource.last()
|
||||||
|
// val builtinFunc = BuiltinFunctions[functionName]
|
||||||
|
// if (builtinFunc != null) {
|
||||||
|
// println("!!!!BUILTIN-FUNCCALL target=${assign.target.kind} $value") // TODO optimize certain functions?
|
||||||
|
// }
|
||||||
|
// asmgen.translateExpression(value)
|
||||||
|
// assignStackValue(assign.target)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
else -> {
|
||||||
|
// everything else just evaluate via the stack.
|
||||||
|
asmgen.translateExpression(value)
|
||||||
|
assignStackValue(assign.target)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SourceStorageKind.REGISTER -> {
|
SourceStorageKind.REGISTER -> {
|
||||||
|
@ -7,6 +7,10 @@ main {
|
|||||||
uword lines = 1
|
uword lines = 1
|
||||||
uword score = $1000
|
uword score = $1000
|
||||||
|
|
||||||
|
ubyte x
|
||||||
|
ubyte y
|
||||||
|
|
||||||
|
lines = mkword(x, y)
|
||||||
c64scr.print_uw(lines)
|
c64scr.print_uw(lines)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
c64scr.print_uw(score)
|
c64scr.print_uw(score)
|
||||||
|
Loading…
Reference in New Issue
Block a user