mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
rename PointerOf to AddressOf
This commit is contained in:
parent
4434d31a3b
commit
8bec4eaa87
@ -289,8 +289,8 @@ interface IAstProcessor {
|
||||
return memwrite
|
||||
}
|
||||
|
||||
fun process(pointerOf: PointerOf): IExpression {
|
||||
return pointerOf
|
||||
fun process(addressOf: AddressOf): IExpression {
|
||||
return addressOf
|
||||
}
|
||||
}
|
||||
|
||||
@ -1010,7 +1010,7 @@ class TypecastExpression(var expression: IExpression, var type: DataType, overri
|
||||
}
|
||||
|
||||
|
||||
data class PointerOf(val identifier: IdentifierReference, override val position: Position) : IExpression {
|
||||
data class AddressOf(val identifier: IdentifierReference, override val position: Position) : IExpression {
|
||||
override lateinit var parent: Node
|
||||
|
||||
override fun linkParents(parent: Node) {
|
||||
@ -1407,6 +1407,7 @@ class RegisterExpr(val register: Register, override val position: Position) : IE
|
||||
data class IdentifierReference(val nameInSource: List<String>, override val position: Position) : IExpression {
|
||||
override lateinit var parent: Node
|
||||
|
||||
// TODO make a shortcut for idref.targetStatement(namespace) as VarDecl
|
||||
fun targetStatement(namespace: INameScope) =
|
||||
if(nameInSource.size==1 && nameInSource[0] in BuiltinFunctions)
|
||||
BuiltinFunctionStatementPlaceholder(nameInSource[0], position)
|
||||
@ -2213,8 +2214,8 @@ private fun prog8Parser.ExpressionContext.toAst() : IExpression {
|
||||
if(directmemory()!=null)
|
||||
return DirectMemoryRead(directmemory().expression().toAst(), toPosition())
|
||||
|
||||
if(pointerof()!=null)
|
||||
return PointerOf(pointerof().scoped_identifier().toAst(), toPosition())
|
||||
if(addressof()!=null)
|
||||
return AddressOf(addressof().scoped_identifier().toAst(), toPosition())
|
||||
|
||||
throw FatalAstException(text)
|
||||
}
|
||||
|
@ -455,15 +455,15 @@ private class AstChecker(private val namespace: INameScope,
|
||||
return assignment
|
||||
}
|
||||
|
||||
override fun process(pointerOf: PointerOf): IExpression {
|
||||
val variable=pointerOf.identifier.targetStatement(namespace) as? VarDecl
|
||||
override fun process(addressOf: AddressOf): IExpression {
|
||||
val variable=addressOf.identifier.targetStatement(namespace) as? VarDecl
|
||||
if(variable==null)
|
||||
checkResult.add(ExpressionError("pointer-of operand must be the name of a heap variable", pointerOf.position))
|
||||
checkResult.add(ExpressionError("pointer-of operand must be the name of a heap variable", addressOf.position))
|
||||
else {
|
||||
if(variable.datatype !in ArrayDatatypes && variable.datatype !in StringDatatypes)
|
||||
checkResult.add(ExpressionError("pointer-of operand must be the name of a string or array heap variable", pointerOf.position))
|
||||
checkResult.add(ExpressionError("pointer-of operand must be the name of a string or array heap variable", addressOf.position))
|
||||
}
|
||||
return pointerOf
|
||||
return addressOf
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1095,7 +1095,7 @@ private class AstChecker(private val namespace: INameScope,
|
||||
correct=array.array!=null && array.array.all { it.integer!=null && it.integer in -128..127 }
|
||||
}
|
||||
DataType.ARRAY_UW -> {
|
||||
correct=array.array!=null && array.array.all { (it.integer!=null && it.integer in 0..65535) || it.pointerOf!=null}
|
||||
correct=array.array!=null && array.array.all { (it.integer!=null && it.integer in 0..65535) || it.addressOf!=null}
|
||||
}
|
||||
DataType.ARRAY_W -> {
|
||||
correct=array.array!=null && array.array.all { it.integer!=null && it.integer in -32768..32767 }
|
||||
|
@ -3,7 +3,7 @@ package prog8.ast
|
||||
import prog8.compiler.HeapValues
|
||||
|
||||
fun Module.reorderStatements(namespace: INameScope, heap: HeapValues) {
|
||||
val initvalueCreator = VarInitValueAndPointerOfCreator(namespace)
|
||||
val initvalueCreator = VarInitValueAndAddressOfCreator(namespace)
|
||||
this.process(initvalueCreator)
|
||||
|
||||
val checker = StatementReorderer(namespace, heap)
|
||||
@ -203,7 +203,7 @@ private class StatementReorderer(private val namespace: INameScope, private val
|
||||
}
|
||||
|
||||
|
||||
private class VarInitValueAndPointerOfCreator(private val namespace: INameScope): IAstProcessor {
|
||||
private class VarInitValueAndAddressOfCreator(private val namespace: INameScope): IAstProcessor {
|
||||
// Replace the var decl with an assignment and add a new vardecl with the default constant value.
|
||||
// This makes sure the variables get reset to the intended value on a next run of the program.
|
||||
// Variable decls without a value don't get this treatment, which means they retain the last
|
||||
@ -211,7 +211,7 @@ private class VarInitValueAndPointerOfCreator(private val namespace: INameScope)
|
||||
// This is done in a separate step because it interferes with the namespace lookup of symbols
|
||||
// in other ast processors.
|
||||
|
||||
// Also takes care to insert PointerOf (&) expression where required (string params to a UWORD function param etc).
|
||||
// Also takes care to insert AddressOf (&) expression where required (string params to a UWORD function param etc).
|
||||
|
||||
|
||||
private val vardeclsToAdd = mutableMapOf<INameScope, MutableList<VarDecl>>()
|
||||
@ -258,28 +258,46 @@ private class VarInitValueAndPointerOfCreator(private val namespace: INameScope)
|
||||
override fun process(functionCall: FunctionCall): IExpression {
|
||||
val targetStatement = functionCall.target.targetStatement(namespace) as? Subroutine
|
||||
if(targetStatement!=null)
|
||||
addPointerToIfNeeded(targetStatement, functionCall.arglist, functionCall)
|
||||
addAddressOfExprIfNeeded(targetStatement, functionCall.arglist, functionCall)
|
||||
return functionCall
|
||||
}
|
||||
|
||||
override fun process(functionCallStatement: FunctionCallStatement): IStatement {
|
||||
val targetStatement = functionCallStatement.target.targetStatement(namespace) as? Subroutine
|
||||
if(targetStatement!=null)
|
||||
addPointerToIfNeeded(targetStatement, functionCallStatement.arglist, functionCallStatement)
|
||||
addAddressOfExprIfNeeded(targetStatement, functionCallStatement.arglist, functionCallStatement)
|
||||
return functionCallStatement
|
||||
}
|
||||
|
||||
private fun addPointerToIfNeeded(subroutine: Subroutine, arglist: MutableList<IExpression>, parent: Node) {
|
||||
// functions that accept UWORD and are given an array type, or string, will receive the Pointer (memory location) of that value instead.
|
||||
// TODO move this to StatementReorderer instead?
|
||||
private fun addAddressOfExprIfNeeded(subroutine: Subroutine, arglist: MutableList<IExpression>, parent: Node) {
|
||||
// functions that accept UWORD and are given an array type, or string, will receive the AddressOf (memory location) of that value instead.
|
||||
for(argparam in subroutine.parameters.withIndex().zip(arglist)) {
|
||||
if(argparam.first.value.type==DataType.UWORD || argparam.first.value.type in StringDatatypes) {
|
||||
if(argparam.second is AddressOf)
|
||||
continue
|
||||
val idref = argparam.second as? IdentifierReference
|
||||
val strvalue = argparam.second as? LiteralValue
|
||||
if(strvalue!=null && strvalue.isString) {
|
||||
val idref = IdentifierReference(listOf("$autoHeapValuePrefix${strvalue.heapId}"), strvalue.position) // TODO why does this result later in "pointer-of operand must be the name of a heap variable"
|
||||
val pointerExpr = PointerOf(idref, strvalue.position)
|
||||
pointerExpr.linkParents(arglist[argparam.first.index].parent)
|
||||
arglist[argparam.first.index] = pointerExpr
|
||||
if(idref!=null) {
|
||||
val variable = idref.targetStatement(namespace) as? VarDecl
|
||||
if(variable!=null && (variable.datatype in StringDatatypes || variable.datatype in ArrayDatatypes)) {
|
||||
val pointerExpr = AddressOf(idref, idref.position)
|
||||
pointerExpr.linkParents(arglist[argparam.first.index].parent)
|
||||
arglist[argparam.first.index] = pointerExpr
|
||||
}
|
||||
}
|
||||
else if(strvalue!=null) {
|
||||
if(strvalue.isString) {
|
||||
println("WANTING TO INSERT & for $strvalue") // TODO
|
||||
// TODO why does this result later in "pointer-of operand must be the name of a heap variable"
|
||||
// --> because the AstChecker runs before AstIdentifiersChecker which inserts the actual VarDecl?
|
||||
val autoHeapvarRef = IdentifierReference(listOf("$autoHeapValuePrefix${strvalue.heapId}"), strvalue.position)
|
||||
val pointerExpr = AddressOf(autoHeapvarRef, strvalue.position)
|
||||
pointerExpr.linkParents(arglist[argparam.first.index].parent)
|
||||
arglist[argparam.first.index] = pointerExpr
|
||||
}
|
||||
}
|
||||
else throw FatalAstException("expected either an identifier or a literal as argument to $subroutine")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ fun Number.toHex(): String {
|
||||
}
|
||||
|
||||
|
||||
data class IntegerOrPointerOf(val integer: Int?, val pointerOf: PointerOf?)
|
||||
data class IntegerOrAddressOf(val integer: Int?, val addressOf: AddressOf?)
|
||||
|
||||
|
||||
class HeapValues {
|
||||
data class HeapValue(val type: DataType, val str: String?, val array: Array<IntegerOrPointerOf>?, val doubleArray: DoubleArray?) {
|
||||
data class HeapValue(val type: DataType, val str: String?, val array: Array<IntegerOrAddressOf>?, val doubleArray: DoubleArray?) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
@ -79,7 +79,7 @@ class HeapValues {
|
||||
return newId
|
||||
}
|
||||
|
||||
fun addIntegerArray(type: DataType, array: Array<IntegerOrPointerOf>): Int {
|
||||
fun addIntegerArray(type: DataType, array: Array<IntegerOrAddressOf>): Int {
|
||||
// arrays are never shared, don't check for existing
|
||||
val newId = heapId++
|
||||
heap[newId] = HeapValue(type, null, array, null)
|
||||
@ -656,7 +656,7 @@ internal class Compiler(private val rootModule: Module,
|
||||
is TypecastExpression -> translate(expr)
|
||||
is DirectMemoryRead -> translate(expr)
|
||||
is DirectMemoryWrite -> translate(expr)
|
||||
is PointerOf -> translate(expr)
|
||||
is AddressOf -> translate(expr)
|
||||
else -> {
|
||||
val lv = expr.constValue(namespace, heap) ?: throw CompilerException("constant expression required, not $expr")
|
||||
when(lv.type) {
|
||||
@ -2134,7 +2134,7 @@ internal class Compiler(private val rootModule: Module,
|
||||
}
|
||||
}
|
||||
|
||||
private fun translate(ptrof: PointerOf) {
|
||||
private fun translate(ptrof: AddressOf) {
|
||||
val target = ptrof.identifier.targetStatement(namespace) as VarDecl
|
||||
if(target.datatype in ArrayDatatypes || target.datatype in StringDatatypes|| target.datatype==DataType.FLOAT) {
|
||||
pushHeapVarAddress(ptrof.identifier, false)
|
||||
|
@ -468,7 +468,7 @@ class IntermediateProgram(val name: String, var loadAddress: Int, val heap: Heap
|
||||
val arrayvalues = it.value.array!!.map { av ->
|
||||
when {
|
||||
av.integer!=null -> av.integer.toString()
|
||||
av.pointerOf!=null -> "&${av.pointerOf.identifier}"
|
||||
av.addressOf!=null -> "&${av.addressOf.identifier}"
|
||||
else -> throw CompilerException("weird array value")
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
if(it.integer!=null)
|
||||
"$"+it.integer.toString(16).padStart(2, '0')
|
||||
else
|
||||
TODO("deal with pointerto")
|
||||
TODO("deal with addressOf")
|
||||
}
|
||||
else -> throw AssemblyError("invalid arrayspec type")
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package prog8.optimizing
|
||||
import prog8.ast.*
|
||||
import prog8.compiler.CompilerException
|
||||
import prog8.compiler.HeapValues
|
||||
import prog8.compiler.IntegerOrPointerOf
|
||||
import prog8.compiler.IntegerOrAddressOf
|
||||
import prog8.compiler.target.c64.FLOAT_MAX_NEGATIVE
|
||||
import prog8.compiler.target.c64.FLOAT_MAX_POSITIVE
|
||||
import kotlin.math.floor
|
||||
@ -70,7 +70,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
val heapId = heap.addIntegerArray(decl.datatype, Array(size) { IntegerOrPointerOf(fillvalue, null) })
|
||||
val heapId = heap.addIntegerArray(decl.datatype, Array(size) { IntegerOrAddressOf(fillvalue, null) })
|
||||
decl.value = LiteralValue(decl.datatype, heapId = heapId, position = litval?.position ?: decl.position)
|
||||
}
|
||||
}
|
||||
@ -546,15 +546,15 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
||||
|
||||
private fun moveArrayToHeap(arraylit: LiteralValue): LiteralValue {
|
||||
val array: Array<IExpression> = arraylit.arrayvalue!!.map { it.process(this) }.toTypedArray()
|
||||
val allElementsAreConstantOrPointerOf = array.fold(true) { c, expr-> c and (expr is LiteralValue || expr is PointerOf)}
|
||||
if(!allElementsAreConstantOrPointerOf) {
|
||||
val allElementsAreConstantOrAddressOf = array.fold(true) { c, expr-> c and (expr is LiteralValue || expr is AddressOf)}
|
||||
if(!allElementsAreConstantOrAddressOf) {
|
||||
addError(ExpressionError("array literal can only consist of constant primitive numerical values or memory pointers", arraylit.position))
|
||||
return arraylit
|
||||
} else if(array.any {it is PointerOf}) {
|
||||
} else if(array.any {it is AddressOf}) {
|
||||
val arrayDt = DataType.UWORD
|
||||
val intArrayWithPointers = mutableListOf<IntegerOrPointerOf>()
|
||||
val intArrayWithAddressOfs = mutableListOf<IntegerOrAddressOf>()
|
||||
// TODO FILL THIS ARRAY
|
||||
val heapId = heap.addIntegerArray(DataType.UWORD, intArrayWithPointers.toTypedArray())
|
||||
val heapId = heap.addIntegerArray(DataType.UWORD, intArrayWithAddressOfs.toTypedArray())
|
||||
return LiteralValue(arrayDt, heapId = heapId, position = arraylit.position)
|
||||
} else {
|
||||
// array is only constant numerical values
|
||||
@ -593,7 +593,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
||||
DataType.ARRAY_UB,
|
||||
DataType.ARRAY_B,
|
||||
DataType.ARRAY_UW,
|
||||
DataType.ARRAY_W -> heap.addIntegerArray(arrayDt, integerArray.map { IntegerOrPointerOf(it, null) }.toTypedArray())
|
||||
DataType.ARRAY_W -> heap.addIntegerArray(arrayDt, integerArray.map { IntegerOrAddressOf(it, null) }.toTypedArray())
|
||||
DataType.ARRAY_F -> heap.addDoublesArray(arrayDt, doubleArray)
|
||||
else -> throw CompilerException("invalid arrayspec type")
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package prog8.stackvm
|
||||
|
||||
import prog8.ast.*
|
||||
import prog8.compiler.HeapValues
|
||||
import prog8.compiler.IntegerOrPointerOf
|
||||
import prog8.compiler.IntegerOrAddressOf
|
||||
import prog8.compiler.intermediate.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
@ -92,7 +92,7 @@ class Program (val name: String,
|
||||
DataType.ARRAY_UB, DataType.ARRAY_B,
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||
val numbers = it.third.substring(1, it.third.length-1).split(',')
|
||||
val intarray = numbers.map{number->IntegerOrPointerOf(number.trim().toInt(), null)}.toTypedArray()
|
||||
val intarray = numbers.map{number->IntegerOrAddressOf(number.trim().toInt(), null)}.toTypedArray()
|
||||
heap.addIntegerArray(it.second, intarray)
|
||||
}
|
||||
DataType.ARRAY_F -> {
|
||||
|
@ -2,7 +2,7 @@ package prog8.stackvm
|
||||
|
||||
import prog8.ast.*
|
||||
import prog8.compiler.HeapValues
|
||||
import prog8.compiler.IntegerOrPointerOf
|
||||
import prog8.compiler.IntegerOrAddressOf
|
||||
import prog8.compiler.intermediate.Instruction
|
||||
import prog8.compiler.intermediate.Opcode
|
||||
import prog8.compiler.intermediate.Value
|
||||
@ -1662,7 +1662,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
if(value.integer!=null)
|
||||
Value(DataType.UWORD, value.integer)
|
||||
else
|
||||
TODO("deal with pointerTo $value")
|
||||
TODO("deal with addressOf $value")
|
||||
}
|
||||
DataType.ARRAY_W -> Value(DataType.WORD, array.array!![index].integer!!)
|
||||
else -> throw VmExecutionException("not a proper arrayspec var with word elements")
|
||||
@ -1730,8 +1730,8 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
// set indexed byte element in the arrayspec
|
||||
val array = heap.get(variable.heapId)
|
||||
when (array.type) {
|
||||
DataType.ARRAY_UB -> array.array!![index] = IntegerOrPointerOf(value.integerValue(), null)
|
||||
DataType.ARRAY_B -> array.array!![index] = IntegerOrPointerOf(value.integerValue(), null)
|
||||
DataType.ARRAY_UB -> array.array!![index] = IntegerOrAddressOf(value.integerValue(), null)
|
||||
DataType.ARRAY_B -> array.array!![index] = IntegerOrAddressOf(value.integerValue(), null)
|
||||
DataType.STR, DataType.STR_S -> {
|
||||
val chars = array.str!!.toCharArray()
|
||||
val ps = Petscii.decodePetscii(listOf(value.integerValue().toShort()), true)[0]
|
||||
@ -1778,8 +1778,8 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
// set indexed word element in the arrayspec
|
||||
val array = heap.get(variable.heapId)
|
||||
when (array.type) {
|
||||
DataType.ARRAY_UW -> array.array!![index] = IntegerOrPointerOf(value.integerValue(), null)
|
||||
DataType.ARRAY_W -> array.array!![index] = IntegerOrPointerOf(value.integerValue(), null)
|
||||
DataType.ARRAY_UW -> array.array!![index] = IntegerOrAddressOf(value.integerValue(), null)
|
||||
DataType.ARRAY_W -> array.array!![index] = IntegerOrAddressOf(value.integerValue(), null)
|
||||
else -> throw VmExecutionException("not a proper arrayspec var with word elements")
|
||||
}
|
||||
}
|
||||
@ -2099,7 +2099,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
val value = heap.get(heapVarId)
|
||||
if(length!=value.array!!.size)
|
||||
throw VmExecutionException("iterable length mismatch")
|
||||
if(value.array.any {it.pointerOf!=null})
|
||||
if(value.array.any {it.addressOf!=null})
|
||||
throw VmExecutionException("stackvm cannot process raw memory pointers")
|
||||
evalstack.push(Value(DataType.UWORD, value.array.map{it.integer!!}.max() ?: 0))
|
||||
}
|
||||
@ -2141,7 +2141,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
val value = heap.get(heapVarId)
|
||||
if(length!=value.array!!.size)
|
||||
throw VmExecutionException("iterable length mismatch")
|
||||
if(value.array.any {it.pointerOf!=null})
|
||||
if(value.array.any {it.addressOf!=null})
|
||||
throw VmExecutionException("stackvm cannot process raw memory pointers")
|
||||
evalstack.push(Value(DataType.UWORD, value.array.map{it.integer!!}.min() ?: 0))
|
||||
}
|
||||
@ -2175,7 +2175,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
val value = heap.get(heapVarId)
|
||||
if(length!=value.array!!.size)
|
||||
throw VmExecutionException("iterable length mismatch")
|
||||
if(value.array.any {it.pointerOf!=null})
|
||||
if(value.array.any {it.addressOf!=null})
|
||||
throw VmExecutionException("stackvm cannot process raw memory pointers")
|
||||
evalstack.push(Value(DataType.UWORD, value.array.map{it.integer!!}.sum()))
|
||||
}
|
||||
|
@ -7,89 +7,6 @@
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
aggregates()
|
||||
;pointers()
|
||||
}
|
||||
|
||||
sub aggregates() {
|
||||
|
||||
; @todo test this in StackVM as well!!
|
||||
|
||||
byte[3] ba = [-5, 0, 20]
|
||||
ubyte[3] uba = [100, 0, 20]
|
||||
word[3] wa = [-5000, 0, 2000]
|
||||
uword[3] uwa = [10000, 0, 2000]
|
||||
float[4] fa = [5.5, 0.0, 20.22,-4.44]
|
||||
|
||||
c64scr.print_ub(any(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(any(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(any(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(any(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(any(fa))
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print_ub(all(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(all(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(all(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(all(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(all(fa))
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print_b(min(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(min(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_w(min(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_uw(min(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(min(fa)) ; @todo fix min(floatarray) (vm is ok)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print_b(max(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_ub(max(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_w(max(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_uw(max(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(max(fa)) ; @todo fix max(floatarray) (vm is ok)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print_uw(sum(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_uw(sum(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_w(sum(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64scr.print_uw(sum(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(sum(fa))
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64flt.print_f(avg(ba))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(avg(uba))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(avg(wa))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(avg(uwa))
|
||||
c64.CHROUT(' ')
|
||||
c64flt.print_f(avg(fa))
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
sub pointers() {
|
||||
|
||||
ubyte[3] array1
|
||||
ubyte[3] array2
|
||||
@ -110,9 +27,11 @@
|
||||
;ptrsubasm("moet werken") ; @todo rewrite ast into pointer-of expression (and remove special cases from Compiler)
|
||||
;pointersub("moet werken") ; @todo rewrite ast into pointer-of expression (and remove special cases from Compiler)
|
||||
|
||||
;myprintasm("moet werken3")
|
||||
;myprintasm("moet werken3")
|
||||
;myprintasm("moet werken4")
|
||||
myprintasm(string1)
|
||||
myprintasm(string2)
|
||||
myprintasm("moet werken3")
|
||||
myprintasm("moet werken3")
|
||||
myprintasm("moet werken4")
|
||||
|
||||
c64.CHROUT('\n')
|
||||
|
||||
|
@ -154,7 +154,7 @@ expression :
|
||||
| scoped_identifier
|
||||
| arrayindexed
|
||||
| directmemory
|
||||
| pointerof
|
||||
| addressof
|
||||
| expression typecast
|
||||
| '(' expression ')'
|
||||
;
|
||||
@ -167,7 +167,7 @@ arrayindexed : scoped_identifier arrayspec ;
|
||||
|
||||
directmemory : '@' '(' expression ')';
|
||||
|
||||
pointerof : <assoc=right> '&' scoped_identifier ;
|
||||
addressof : <assoc=right> '&' scoped_identifier ;
|
||||
|
||||
|
||||
functioncall : scoped_identifier '(' expression_list? ')' ;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from prog8.g4 by ANTLR 4.7.2
|
||||
// Generated from /home/irmen/Projects/prog8/parser/antlr/prog8.g4 by ANTLR 4.7.2
|
||||
|
||||
package prog8.parser;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from prog8.g4 by ANTLR 4.7.2
|
||||
// Generated from /home/irmen/Projects/prog8/parser/antlr/prog8.g4 by ANTLR 4.7.2
|
||||
|
||||
package prog8.parser;
|
||||
|
||||
@ -44,7 +44,7 @@ public class prog8Parser extends Parser {
|
||||
RULE_datatype = 12, RULE_arrayspec = 13, RULE_assignment = 14, RULE_assign_targets = 15,
|
||||
RULE_augassignment = 16, RULE_assign_target = 17, RULE_postincrdecr = 18,
|
||||
RULE_expression = 19, RULE_typecast = 20, RULE_arrayindexed = 21, RULE_directmemory = 22,
|
||||
RULE_pointerof = 23, RULE_functioncall = 24, RULE_functioncall_stmt = 25,
|
||||
RULE_addressof = 23, RULE_functioncall = 24, RULE_functioncall_stmt = 25,
|
||||
RULE_expression_list = 26, RULE_returnstmt = 27, RULE_breakstmt = 28,
|
||||
RULE_continuestmt = 29, RULE_identifier = 30, RULE_scoped_identifier = 31,
|
||||
RULE_register = 32, RULE_registerorpair = 33, RULE_statusregister = 34,
|
||||
@ -62,7 +62,7 @@ public class prog8Parser extends Parser {
|
||||
"directive", "directivearg", "vardecl", "varinitializer", "constdecl",
|
||||
"memoryvardecl", "datatype", "arrayspec", "assignment", "assign_targets",
|
||||
"augassignment", "assign_target", "postincrdecr", "expression", "typecast",
|
||||
"arrayindexed", "directmemory", "pointerof", "functioncall", "functioncall_stmt",
|
||||
"arrayindexed", "directmemory", "addressof", "functioncall", "functioncall_stmt",
|
||||
"expression_list", "returnstmt", "breakstmt", "continuestmt", "identifier",
|
||||
"scoped_identifier", "register", "registerorpair", "statusregister",
|
||||
"integerliteral", "wordsuffix", "booleanliteral", "arrayliteral", "stringliteral",
|
||||
@ -1352,8 +1352,8 @@ public class prog8Parser extends Parser {
|
||||
public DirectmemoryContext directmemory() {
|
||||
return getRuleContext(DirectmemoryContext.class,0);
|
||||
}
|
||||
public PointerofContext pointerof() {
|
||||
return getRuleContext(PointerofContext.class,0);
|
||||
public AddressofContext addressof() {
|
||||
return getRuleContext(AddressofContext.class,0);
|
||||
}
|
||||
public List<TerminalNode> EOL() { return getTokens(prog8Parser.EOL); }
|
||||
public TerminalNode EOL(int i) {
|
||||
@ -1451,7 +1451,7 @@ public class prog8Parser extends Parser {
|
||||
case 9:
|
||||
{
|
||||
setState(259);
|
||||
pointerof();
|
||||
addressof();
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
@ -2092,19 +2092,19 @@ public class prog8Parser extends Parser {
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class PointerofContext extends ParserRuleContext {
|
||||
public static class AddressofContext extends ParserRuleContext {
|
||||
public Scoped_identifierContext scoped_identifier() {
|
||||
return getRuleContext(Scoped_identifierContext.class,0);
|
||||
}
|
||||
public PointerofContext(ParserRuleContext parent, int invokingState) {
|
||||
public AddressofContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_pointerof; }
|
||||
@Override public int getRuleIndex() { return RULE_addressof; }
|
||||
}
|
||||
|
||||
public final PointerofContext pointerof() throws RecognitionException {
|
||||
PointerofContext _localctx = new PointerofContext(_ctx, getState());
|
||||
enterRule(_localctx, 46, RULE_pointerof);
|
||||
public final AddressofContext addressof() throws RecognitionException {
|
||||
AddressofContext _localctx = new AddressofContext(_ctx, getState());
|
||||
enterRule(_localctx, 46, RULE_addressof);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user