mirror of
https://github.com/irmen/prog8.git
synced 2024-08-18 23:29:32 +00:00
DirectMemoryWrite is not an expression
This commit is contained in:
parent
3c563d281a
commit
c970d899fa
@ -299,24 +299,6 @@ class DirectMemoryRead(var addressExpression: IExpression, override val position
|
||||
}
|
||||
}
|
||||
|
||||
class DirectMemoryWrite(var addressExpression: IExpression, override val position: Position) : IExpression {
|
||||
override lateinit var parent: Node
|
||||
|
||||
override fun linkParents(parent: Node) {
|
||||
this.parent = parent
|
||||
this.addressExpression.linkParents(this)
|
||||
}
|
||||
|
||||
override fun process(processor: IAstProcessor) = processor.process(this)
|
||||
override fun referencesIdentifier(name: String) = false
|
||||
override fun inferType(program: Program): DataType? = DataType.UBYTE
|
||||
override fun constValue(program: Program): LiteralValue? = null
|
||||
|
||||
override fun toString(): String {
|
||||
return "DirectMemoryWrite($addressExpression)"
|
||||
}
|
||||
}
|
||||
|
||||
open class LiteralValue(val type: DataType,
|
||||
val bytevalue: Short? = null,
|
||||
val wordvalue: Int? = null,
|
||||
|
@ -162,7 +162,7 @@ interface IAstProcessor {
|
||||
fun process(assignTarget: AssignTarget): AssignTarget {
|
||||
assignTarget.arrayindexed?.process(this)
|
||||
assignTarget.identifier?.process(this)
|
||||
assignTarget.memoryAddress?.process(this)
|
||||
assignTarget.memoryAddress?.let { process(it) }
|
||||
return assignTarget
|
||||
}
|
||||
|
||||
@ -181,9 +181,8 @@ interface IAstProcessor {
|
||||
return memread
|
||||
}
|
||||
|
||||
fun process(memwrite: DirectMemoryWrite): IExpression {
|
||||
fun process(memwrite: DirectMemoryWrite) {
|
||||
memwrite.addressExpression = memwrite.addressExpression.process(this)
|
||||
return memwrite
|
||||
}
|
||||
|
||||
fun process(addressOf: AddressOf): IExpression {
|
||||
|
@ -260,7 +260,6 @@ data class AssignTarget(val register: Register?,
|
||||
is IdentifierReference -> AssignTarget(null, expr, null, null, expr.position)
|
||||
is ArrayIndexedExpression -> AssignTarget(null, null, expr, null, expr.position)
|
||||
is DirectMemoryRead -> AssignTarget(null, null, null, DirectMemoryWrite(expr.addressExpression, expr.position), expr.position)
|
||||
is DirectMemoryWrite -> AssignTarget(null, null, null, expr, expr.position)
|
||||
else -> throw FatalAstException("invalid expression object $expr")
|
||||
}
|
||||
}
|
||||
@ -637,3 +636,16 @@ class RepeatLoop(var body: AnonymousScope,
|
||||
|
||||
override fun process(processor: IAstProcessor): IStatement = processor.process(this)
|
||||
}
|
||||
|
||||
class DirectMemoryWrite(var addressExpression: IExpression, override val position: Position) : Node {
|
||||
override lateinit var parent: Node
|
||||
|
||||
override fun linkParents(parent: Node) {
|
||||
this.parent = parent
|
||||
this.addressExpression.linkParents(this)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "DirectMemoryWrite($addressExpression)"
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,6 @@ internal class Compiler(private val program: Program): IAstProcessor {
|
||||
is RangeExpr -> throw CompilerException("it's not possible to just have a range expression that has to be translated")
|
||||
is TypecastExpression -> translate(expr)
|
||||
is DirectMemoryRead -> translate(expr)
|
||||
is DirectMemoryWrite -> translate(expr)
|
||||
is AddressOf -> translate(expr)
|
||||
else -> {
|
||||
val lv = expr.constValue(program) ?: throw CompilerException("constant expression required, not $expr")
|
||||
@ -2061,6 +2060,7 @@ internal class Compiler(private val program: Program): IAstProcessor {
|
||||
|
||||
private fun translate(memwrite: DirectMemoryWrite) {
|
||||
// for now, only a single memory location (ubyte) is written at a time.
|
||||
// TODO inline this function (it's only used once)
|
||||
val address = memwrite.addressExpression.constValue(program)?.asIntegerValue
|
||||
if(address!=null) {
|
||||
prog.instr(Opcode.POP_MEM_BYTE, arg = RuntimeValue(DataType.UWORD, address))
|
||||
|
@ -240,14 +240,6 @@ class ConstantFolding(private val program: Program) : IAstProcessor {
|
||||
return super.process(memread)
|
||||
}
|
||||
|
||||
override fun process(memwrite: DirectMemoryWrite): IExpression {
|
||||
// @( &thing ) --> thing
|
||||
val addrOf = memwrite.addressExpression as? AddressOf
|
||||
if(addrOf!=null)
|
||||
return super.process(addrOf.identifier)
|
||||
return super.process(memwrite)
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to process a unary prefix expression.
|
||||
* Compile-time constant sub expressions will be evaluated on the spot.
|
||||
|
@ -35,14 +35,6 @@ internal class SimplifyExpressions(private val program: Program) : IAstProcessor
|
||||
return super.process(memread)
|
||||
}
|
||||
|
||||
override fun process(memwrite: DirectMemoryWrite): IExpression {
|
||||
// @( &thing ) --> thing
|
||||
val addrOf = memwrite.addressExpression as? AddressOf
|
||||
if(addrOf!=null)
|
||||
return super.process(addrOf.identifier)
|
||||
return super.process(memwrite)
|
||||
}
|
||||
|
||||
override fun process(typecast: TypecastExpression): IExpression {
|
||||
// remove redundant typecasts
|
||||
var tc = typecast
|
||||
|
@ -88,9 +88,6 @@ fun evaluate(expr: IExpression, ctx: EvalContext): RuntimeValue {
|
||||
val address = evaluate(expr.addressExpression, ctx).wordval!!
|
||||
return RuntimeValue(DataType.UBYTE, ctx.mem.getUByte(address))
|
||||
}
|
||||
is DirectMemoryWrite -> {
|
||||
TODO("memorywrite $expr")
|
||||
}
|
||||
is RegisterExpr -> return ctx.runtimeVars.get(ctx.program.namespace, expr.register.name)
|
||||
is IdentifierReference -> {
|
||||
val scope = expr.definingScope()
|
||||
|
@ -1,69 +1,21 @@
|
||||
%import c64utils
|
||||
%zeropage basicsafe
|
||||
%import c64flt
|
||||
|
||||
~ main {
|
||||
|
||||
uword ww = 33 ; @todo error? or should it be 33?
|
||||
uword w2 = foo() ; @todo same issue
|
||||
|
||||
|
||||
sub start() {
|
||||
|
||||
uword xw = 33 ; @todo error? or should it be 33?
|
||||
uword x2 = foo() ; @todo same issue
|
||||
uword xw = 33
|
||||
|
||||
c64scr.print_uw(ww)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_uw(w2)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_uw(xw)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_uw(x2)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
@($d020) = 34
|
||||
xw = $d020 ; @todo gets removed in assembly!?!??!?!?
|
||||
@(xw) = 1 ; @todo should turn border white
|
||||
@(xw) = 1 ; @todo should turn border white
|
||||
|
||||
; Y=12 ; @todo gets removed in assembly???!!!
|
||||
; A=Y
|
||||
; A=99
|
||||
; @($d021)=A
|
||||
; @(xw) = A
|
||||
}
|
||||
|
||||
sub foo() -> uword {
|
||||
A=4
|
||||
return rndw()+A
|
||||
}
|
||||
|
||||
; for ubyte y in 0 to 3 {
|
||||
; for ubyte x in 0 to 10 {
|
||||
; ubyte product = x*y
|
||||
; c64scr.setcc(x, y, 160, product)
|
||||
; }
|
||||
; }
|
||||
; c64.CHROUT('\n')
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; for ubyte y in 12 to 15 {
|
||||
; for ubyte x in 0 to 10 {
|
||||
; ubyte sumv = x+y
|
||||
; c64scr.setcc(x, y, 160, sumv)
|
||||
; }
|
||||
; }
|
||||
|
||||
;ubyte bb = len(xcoor)
|
||||
|
||||
; storage for rotated coordinates
|
||||
; ubyte[len(xcoor)] xx = 2
|
||||
; float[len(xcoor)] rotatedx=0.0
|
||||
;
|
||||
; ubyte[4] x = 23
|
||||
; float[4] yy = 4.4
|
||||
|
||||
; c64flt.print_f(xcoor[1])
|
||||
; c64.CHROUT(',')
|
||||
; c64flt.print_f(xcoor[2])
|
||||
; c64.CHROUT('\n')
|
||||
; swap(xcoor[1], xcoor[2])
|
||||
; c64flt.print_f(xcoor[1])
|
||||
; c64.CHROUT(',')
|
||||
; c64flt.print_f(xcoor[2])
|
||||
; c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user