naming consistency for some expression classes

This commit is contained in:
Irmen de Jong 2022-01-07 21:02:37 +01:00
parent 8f3df3039a
commit 749ad700d8
30 changed files with 119 additions and 117 deletions

View File

@ -956,10 +956,10 @@ class AsmGen(private val program: Program,
internal fun translateExpression(expression: Expression) =
expressionsAsmGen.translateExpression(expression)
internal fun translateBuiltinFunctionCallExpression(functionCallExpr: FunctionCallExpr, signature: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) =
internal fun translateBuiltinFunctionCallExpression(functionCallExpr: FunctionCallExpression, signature: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) =
builtinFunctionsAsmGen.translateFunctioncallExpression(functionCallExpr, signature, resultToStack, resultRegister)
internal fun translateFunctionCall(functionCallExpr: FunctionCallExpr, isExpression: Boolean) =
internal fun translateFunctionCall(functionCallExpr: FunctionCallExpression, isExpression: Boolean) =
functioncallAsmGen.translateFunctionCall(functionCallExpr, isExpression)
internal fun saveXbeforeCall(functionCall: IFunctionCall) =
@ -1636,7 +1636,7 @@ $label nop""")
pipe.expressions.drop(1).dropLast(1).forEach {
val callName = it as IdentifierReference
val args = mutableListOf<Expression>(IdentifierReference(valueVar, it.position))
val call = FunctionCallExpr(callName, args,it.position)
val call = FunctionCallExpression(callName, args,it.position)
call.linkParents(pipe)
valueDt = call.inferType(program).getOrElse { throw AssemblyError("invalid dt") }
valueVar = getTempVarName(valueDt)
@ -1880,7 +1880,7 @@ $label nop""")
}
if(dt==DataType.UBYTE) {
assignExpressionToRegister(left, RegisterOrPair.A, false)
if (left is FunctionCallExpr && !left.isSimple)
if (left is FunctionCallExpression && !left.isSimple)
out(" cmp #0")
} else {
assignExpressionToRegister(left, RegisterOrPair.AY, false)
@ -1896,7 +1896,7 @@ $label nop""")
}
DataType.BYTE -> {
assignExpressionToRegister(left, RegisterOrPair.A, true)
if (left is FunctionCallExpr && !left.isSimple)
if (left is FunctionCallExpression && !left.isSimple)
out(" cmp #0")
when (operator) {
"==" -> out(" bne $jumpIfFalseLabel")

View File

@ -44,7 +44,7 @@ internal fun asmsub6502ArgsHaveRegisterClobberRisk(args: List<Expression>,
it.registerOrPair in listOf(RegisterOrPair.Y, RegisterOrPair.AY, RegisterOrPair.XY)
}
}
is FunctionCallExpr -> {
is FunctionCallExpression -> {
if (expr.target.nameInSource == listOf("lsb") || expr.target.nameInSource == listOf("msb"))
return isClobberRisk(expr.args[0])
if (expr.target.nameInSource == listOf("mkword"))

View File

@ -19,7 +19,7 @@ import prog8.compilerinterface.subroutineFloatEvalResultVar2
internal class BuiltinFunctionsAsmGen(private val program: Program, private val asmgen: AsmGen, private val assignAsmGen: AssignmentAsmGen) {
internal fun translateFunctioncallExpression(fcall: FunctionCallExpr, func: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) {
internal fun translateFunctioncallExpression(fcall: FunctionCallExpression, func: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) {
translateFunctioncall(fcall, func, discardResult = false, resultToStack = resultToStack, resultRegister = resultRegister)
}
@ -414,7 +414,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
}
private fun funcMemory(fcall: IFunctionCall, discardResult: Boolean, resultToStack: Boolean, resultRegister: RegisterOrPair?) {
if(discardResult || fcall !is FunctionCallExpr)
if(discardResult || fcall !is FunctionCallExpression)
throw AssemblyError("should not discard result of memory allocation at $fcall")
val nameRef = fcall.args[0] as IdentifierReference
val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value

View File

@ -36,16 +36,16 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
is DirectMemoryRead -> asmgen.translateDirectMemReadExpressionToRegAorStack(expression, true)
is NumericLiteralValue -> translateExpression(expression)
is IdentifierReference -> translateExpression(expression)
is FunctionCallExpr -> translateFunctionCallResultOntoStack(expression)
is FunctionCallExpression -> translateFunctionCallResultOntoStack(expression)
is ContainmentCheck -> throw AssemblyError("containment check as complex expression value is not supported")
is ArrayLiteralValue, is StringLiteralValue -> throw AssemblyError("no asm gen for string/array literal value assignment - should have been replaced by a variable")
is RangeExpr -> throw AssemblyError("range expression should have been changed into array values")
is RangeExpression -> throw AssemblyError("range expression should have been changed into array values")
is CharLiteral -> throw AssemblyError("charliteral should have been replaced by ubyte using certain encoding")
else -> TODO("missing expression asmgen for $expression")
}
}
private fun translateFunctionCallResultOntoStack(call: FunctionCallExpr) {
private fun translateFunctionCallResultOntoStack(call: FunctionCallExpression) {
// only for use in nested expression evaluation
val sub = call.target.targetStatement(program)

View File

@ -5,7 +5,7 @@ import prog8.ast.base.ArrayToElementTypes
import prog8.ast.base.DataType
import prog8.ast.base.RegisterOrPair
import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.RangeExpr
import prog8.ast.expressions.RangeExpression
import prog8.ast.statements.ForLoop
import prog8.ast.toHex
import prog8.codegen.target.AssemblyError
@ -18,10 +18,10 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen:
if(!iterableDt.isKnown)
throw AssemblyError("unknown dt")
when(stmt.iterable) {
is RangeExpr -> {
val range = (stmt.iterable as RangeExpr).toConstantIntegerRange()
is RangeExpression -> {
val range = (stmt.iterable as RangeExpression).toConstantIntegerRange()
if(range==null) {
translateForOverNonconstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, stmt.iterable as RangeExpr)
translateForOverNonconstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, stmt.iterable as RangeExpression)
} else {
translateForOverConstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, range)
}
@ -33,7 +33,7 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen:
}
}
private fun translateForOverNonconstRange(stmt: ForLoop, iterableDt: DataType, range: RangeExpr) {
private fun translateForOverNonconstRange(stmt: ForLoop, iterableDt: DataType, range: RangeExpression) {
val loopLabel = asmgen.makeLabel("for_loop")
val endLabel = asmgen.makeLabel("for_end")
val modifiedLabel = asmgen.makeLabel("for_modified")
@ -587,7 +587,7 @@ $loopLabel""")
asmgen.loopEndLabels.pop()
}
private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) =
private fun assignLoopvar(stmt: ForLoop, range: RangeExpression) =
asmgen.assignExpressionToVariable(
range.from,
asmgen.asmVariableName(stmt.loopVar),

View File

@ -167,7 +167,7 @@ internal class AsmAssignSource(val kind: SourceStorageKind,
val dt = value.inferType(program).getOrElse { throw AssemblyError("unknown dt") }
AsmAssignSource(SourceStorageKind.ARRAY, program, asmgen, dt, array = value)
}
is FunctionCallExpr -> {
is FunctionCallExpression -> {
when (val sub = value.target.targetStatement(program)) {
is Subroutine -> {
val returnType = sub.returntypes.zip(sub.asmReturnvaluesRegisters).firstOrNull { rr -> rr.second.registerOrPair != null || rr.second.statusflag!=null }?.first

View File

@ -159,7 +159,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
is ArrayIndexedExpression -> throw AssemblyError("source kind should have been array")
is DirectMemoryRead -> throw AssemblyError("source kind should have been memory")
is TypecastExpression -> assignTypeCastedValue(assign.target, value.type, value.expression, value)
is FunctionCallExpr -> {
is FunctionCallExpression -> {
when (val sub = value.target.targetStatement(program)) {
is Subroutine -> {
asmgen.saveXbeforeCall(value)
@ -300,7 +300,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
private fun containmentCheckIntoA(containment: ContainmentCheck) {
val elementDt = containment.element.inferType(program)
val range = containment.iterable as? RangeExpr
val range = containment.iterable as? RangeExpression
if(range!=null) {
val constRange = range.toConstantIntegerRange()
if(constRange!=null)
@ -596,7 +596,7 @@ $containsLabel lda #1
}
private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) {
val lsb = FunctionCallExpr(IdentifierReference(listOf("lsb"), value.position), mutableListOf(value), value.position)
val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), value.position), mutableListOf(value), value.position)
lsb.linkParents(value.parent)
val src = AsmAssignSource(SourceStorageKind.EXPRESSION, program, asmgen, DataType.UBYTE, expression = lsb)
val assign = AsmAssignment(src, target, false, program.memsizer, value.position)

View File

@ -310,7 +310,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
return noModifications
}
override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
// the args of a fuction are constfolded via recursion already.
val constvalue = functionCallExpr.constValue(program)
return if(constvalue!=null)
@ -320,7 +320,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
}
override fun after(forLoop: ForLoop, parent: Node): Iterable<IAstModification> {
fun adjustRangeDt(rangeFrom: NumericLiteralValue, targetDt: DataType, rangeTo: NumericLiteralValue, stepLiteral: NumericLiteralValue?, range: RangeExpr): RangeExpr? {
fun adjustRangeDt(rangeFrom: NumericLiteralValue, targetDt: DataType, rangeTo: NumericLiteralValue, stepLiteral: NumericLiteralValue?, range: RangeExpression): RangeExpression? {
val fromCast = rangeFrom.cast(targetDt)
val toCast = rangeTo.cast(targetDt)
if(!fromCast.isValid || !toCast.isValid)
@ -337,11 +337,11 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
range.step
}
return RangeExpr(fromCast.valueOrZero(), toCast.valueOrZero(), newStep, range.position)
return RangeExpression(fromCast.valueOrZero(), toCast.valueOrZero(), newStep, range.position)
}
// adjust the datatype of a range expression in for loops to the loop variable.
val iterableRange = forLoop.iterable as? RangeExpr ?: return noModifications
val iterableRange = forLoop.iterable as? RangeExpression ?: return noModifications
val rangeFrom = iterableRange.from as? NumericLiteralValue
val rangeTo = iterableRange.to as? NumericLiteralValue
if(rangeFrom==null || rangeTo==null) return noModifications

View File

@ -40,7 +40,7 @@ class VarConstantValueTypeAdjuster(private val program: Program, private val err
return noModifications
}
override fun after(range: RangeExpr, parent: Node): Iterable<IAstModification> {
override fun after(range: RangeExpression, parent: Node): Iterable<IAstModification> {
val from = range.from.constValue(program)?.number
val to = range.to.constValue(program)?.number
val step = range.step.constValue(program)?.number
@ -139,7 +139,7 @@ internal class ConstantIdentifierReplacer(private val program: Program, private
}
}
DataType.ARRAY_UB, DataType.ARRAY_B, DataType.ARRAY_UW, DataType.ARRAY_W -> {
val rangeExpr = decl.value as? RangeExpr
val rangeExpr = decl.value as? RangeExpression
if(rangeExpr!=null) {
// convert the initializer range expression to an actual array
val declArraySize = decl.arraysize?.constIndex()
@ -193,7 +193,7 @@ internal class ConstantIdentifierReplacer(private val program: Program, private
}
}
DataType.ARRAY_F -> {
val rangeExpr = decl.value as? RangeExpr
val rangeExpr = decl.value as? RangeExpression
if(rangeExpr!=null) {
// convert the initializer range expression to an actual array of floats
val declArraySize = decl.arraysize?.constIndex()

View File

@ -209,7 +209,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
// signedw < 0 --> msb(signedw) & $80
return listOf(IAstModification.ReplaceNode(
expr,
BinaryExpression(FunctionCallExpr(IdentifierReference(listOf("msb"), expr.position),
BinaryExpression(FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position),
mutableListOf(expr.left),
expr.position
), "&", NumericLiteralValue.optimalInteger(0x80, expr.position), expr.position),
@ -299,7 +299,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
return noModifications
}
override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
if(functionCallExpr.target.nameInSource == listOf("lsb")) {
val arg = functionCallExpr.args[0]
if(arg is TypecastExpression) {
@ -343,7 +343,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
}
override fun after(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> {
val range = containment.iterable as? RangeExpr
val range = containment.iterable as? RangeExpression
if(range!=null && range.step.constValue(program)?.number==1.0) {
val from = range.from.constValue(program)
val to = range.to.constValue(program)
@ -365,14 +365,14 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
val firstValue = pipe.expressions.first()
if(firstValue.isSimple) {
val funcname = pipe.expressions[1] as IdentifierReference
val first = FunctionCallExpr(funcname.copy(), mutableListOf(firstValue), firstValue.position)
val first = FunctionCallExpression(funcname.copy(), mutableListOf(firstValue), firstValue.position)
val newExprs = mutableListOf<Expression>(first)
newExprs.addAll(pipe.expressions.drop(2))
return listOf(IAstModification.ReplaceNode(pipe, Pipe(newExprs, pipe.position), parent))
}
val singleExpr = pipe.expressions.singleOrNull()
if(singleExpr!=null) {
val callExpr = singleExpr as FunctionCallExpr
val callExpr = singleExpr as FunctionCallExpression
val call = FunctionCallStatement(callExpr.target, callExpr.args, true, callExpr.position)
return listOf(IAstModification.ReplaceNode(pipe, call, parent))
}
@ -490,7 +490,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
}
0.5 -> {
// sqrt(left)
return FunctionCallExpr(IdentifierReference(listOf("sqrt"), expr.position), mutableListOf(expr.left), expr.position)
return FunctionCallExpression(IdentifierReference(listOf("sqrt"), expr.position), mutableListOf(expr.left), expr.position)
}
1.0 -> {
// left
@ -683,12 +683,12 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
if (amount >= 16) {
return NumericLiteralValue(targetDt, 0.0, expr.position)
} else if (amount >= 8) {
val lsb = FunctionCallExpr(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position)
val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position)
if (amount == 8) {
return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
}
val shifted = BinaryExpression(lsb, "<<", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position)
return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
}
}
else -> {
@ -725,11 +725,11 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
return NumericLiteralValue.optimalInteger(0, expr.position)
}
else if (amount >= 8) {
val msb = FunctionCallExpr(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position)
val msb = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position)
if (amount == 8) {
// mkword(0, msb(v))
val zero = NumericLiteralValue(DataType.UBYTE, 0.0, expr.position)
return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(zero, msb), expr.position)
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(zero, msb), expr.position)
}
return TypecastExpression(BinaryExpression(msb, ">>", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position), DataType.UWORD, true, expr.position)
}

View File

@ -17,7 +17,7 @@ class StatementOptimizer(private val program: Program,
private val compTarget: ICompilationTarget
) : AstWalker() {
override fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
// if the first instruction in the called subroutine is a return statement with a simple value,
// remove the jump altogeter and inline the returnvalue directly.
@ -177,7 +177,7 @@ class StatementOptimizer(private val program: Program,
}
}
val range = forLoop.iterable as? RangeExpr
val range = forLoop.iterable as? RangeExpression
if(range!=null) {
if (range.size() == 1) {
// for loop over a (constant) range of just a single value-- optimize the loop away

View File

@ -234,7 +234,7 @@ class UnusedCodeRemover(private val program: Program,
is PrefixExpression,
is BinaryExpression,
is TypecastExpression,
is FunctionCallExpr -> { /* don't remove */ }
is FunctionCallExpression -> { /* don't remove */ }
else -> linesToRemove.add(assign1)
}
}

View File

@ -4,7 +4,6 @@ import prog8.ast.*
import prog8.ast.base.*
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.ast.walk.IAstModification
import prog8.ast.walk.IAstVisitor
import prog8.compilerinterface.*
import java.io.CharConversionException
@ -86,7 +85,7 @@ internal class AstChecker(private val program: Program,
override fun visit(forLoop: ForLoop) {
fun checkUnsignedLoopDownto0(range: RangeExpr?) {
fun checkUnsignedLoopDownto0(range: RangeExpression?) {
if(range==null)
return
val step = range.step.constValue(program)?.number ?: 1.0
@ -98,7 +97,7 @@ internal class AstChecker(private val program: Program,
}
val iterableDt = forLoop.iterable.inferType(program).getOr(DataType.BYTE)
if(iterableDt !in IterableDatatypes && forLoop.iterable !is RangeExpr) {
if(iterableDt !in IterableDatatypes && forLoop.iterable !is RangeExpression) {
errors.err("can only loop over an iterable type", forLoop.position)
} else {
val loopvar = forLoop.loopVar.targetVarDecl(program)
@ -110,14 +109,14 @@ internal class AstChecker(private val program: Program,
if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.ARRAY_UB && iterableDt != DataType.STR)
errors.err("ubyte loop variable can only loop over unsigned bytes or strings", forLoop.position)
checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpr)
checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpression)
}
DataType.UWORD -> {
if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.UWORD && iterableDt != DataType.STR &&
iterableDt != DataType.ARRAY_UB && iterableDt!= DataType.ARRAY_UW)
errors.err("uword loop variable can only loop over unsigned bytes, words or strings", forLoop.position)
checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpr)
checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpression)
}
DataType.BYTE -> {
if(iterableDt!= DataType.BYTE && iterableDt!= DataType.ARRAY_B)
@ -138,7 +137,7 @@ internal class AstChecker(private val program: Program,
}
if(errors.noErrors()) {
// check loop range values
val range = forLoop.iterable as? RangeExpr
val range = forLoop.iterable as? RangeExpression
if(range!=null) {
val from = range.from as? NumericLiteralValue
val to = range.to as? NumericLiteralValue
@ -501,7 +500,7 @@ internal class AstChecker(private val program: Program,
} else {
val sourceDatatype = assignment.value.inferType(program)
if (sourceDatatype.isUnknown) {
if (assignment.value !is FunctionCallExpr)
if (assignment.value !is FunctionCallExpression)
errors.err("assignment value is invalid or has no proper datatype", assignment.value.position)
} else {
checkAssignmentCompatible(targetDatatype.getOr(DataType.BYTE),
@ -556,7 +555,7 @@ internal class AstChecker(private val program: Program,
err("unsized array declaration cannot use a single literal initialization value")
return
}
if(decl.value is RangeExpr)
if(decl.value is RangeExpression)
throw FatalAstException("range expressions in vardecls should have been converted into array values during constFolding $decl")
}
@ -566,7 +565,7 @@ internal class AstChecker(private val program: Program,
null -> {
// a vardecl without an initial value, don't bother with it
}
is RangeExpr -> throw FatalAstException("range expression should have been converted to a true array value")
is RangeExpression -> throw FatalAstException("range expression should have been converted to a true array value")
is StringLiteralValue -> {
checkValueTypeAndRangeString(decl.datatype, decl.value as StringLiteralValue)
}
@ -901,7 +900,7 @@ internal class AstChecker(private val program: Program,
super.visit(typecast)
}
override fun visit(range: RangeExpr) {
override fun visit(range: RangeExpression) {
fun err(msg: String) {
errors.err(msg, range.position)
}
@ -934,7 +933,7 @@ internal class AstChecker(private val program: Program,
}
}
override fun visit(functionCallExpr: FunctionCallExpr) {
override fun visit(functionCallExpr: FunctionCallExpression) {
// this function call is (part of) an expression, which should be in a statement somewhere.
val stmtOfExpression = findParentNode<Statement>(functionCallExpr)
?: throw FatalAstException("cannot determine statement scope of function call expression at ${functionCallExpr.position}")
@ -1079,8 +1078,8 @@ internal class AstChecker(private val program: Program,
var ident: IdentifierReference? = null
if(arg.value is IdentifierReference)
ident = arg.value as IdentifierReference
else if(arg.value is FunctionCallExpr) {
val fcall = arg.value as FunctionCallExpr
else if(arg.value is FunctionCallExpression) {
val fcall = arg.value as FunctionCallExpression
if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb"))
ident = fcall.args[0] as? IdentifierReference
}
@ -1473,7 +1472,7 @@ internal class AstChecker(private val program: Program,
sourceValue: Expression) : Boolean {
val position = sourceValue.position
if(sourceValue is RangeExpr)
if(sourceValue is RangeExpression)
errors.err("can't assign a range value to something else", position)
val result = when(targetDatatype) {

View File

@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall
import prog8.ast.Node
import prog8.ast.Program
import prog8.ast.base.Position
import prog8.ast.expressions.FunctionCallExpr
import prog8.ast.expressions.FunctionCallExpression
import prog8.ast.expressions.StringLiteralValue
import prog8.ast.statements.*
import prog8.ast.walk.IAstVisitor
@ -128,7 +128,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
super.visit(string)
}
override fun visit(functionCallExpr: FunctionCallExpr) = visitFunctionCall(functionCallExpr)
override fun visit(functionCallExpr: FunctionCallExpression) = visitFunctionCall(functionCallExpr)
override fun visit(functionCallStatement: FunctionCallStatement) = visitFunctionCall(functionCallStatement)
private fun visitFunctionCall(call: IFunctionCall) {

View File

@ -12,7 +12,7 @@ import prog8.compilerinterface.IErrorReporter
class AstPreprocessor(val program: Program, val errors: IErrorReporter) : AstWalker() {
override fun after(range: RangeExpr, parent: Node): Iterable<IAstModification> {
override fun after(range: RangeExpression, parent: Node): Iterable<IAstModification> {
// has to be done before the constant folding, otherwise certain checks there will fail on invalid range sizes
val modifications = mutableListOf<IAstModification>()
if(range.from !is NumericLiteralValue) {

View File

@ -117,7 +117,7 @@ _after:
override fun before(functionCallStatement: FunctionCallStatement, parent: Node) =
before(functionCallStatement as IFunctionCall, parent, functionCallStatement.position)
override fun before(functionCallExpr: FunctionCallExpr, parent: Node) =
override fun before(functionCallExpr: FunctionCallExpression, parent: Node) =
before(functionCallExpr as IFunctionCall, parent, functionCallExpr.position)
private fun before(functionCall: IFunctionCall, parent: Node, position: Position): Iterable<IAstModification> {

View File

@ -161,7 +161,7 @@ internal class ParentNodeChecker: AstWalker() {
return noModifications
}
override fun before(range: RangeExpr, parent: Node): Iterable<IAstModification> {
override fun before(range: RangeExpression, parent: Node): Iterable<IAstModification> {
if(range.parent!==parent)
throw FatalAstException("parent node mismatch at $range")
return noModifications
@ -221,7 +221,7 @@ internal class ParentNodeChecker: AstWalker() {
return noModifications
}
override fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
if(functionCallExpr.parent!==parent)
throw FatalAstException("parent node mismatch at $functionCallExpr")
return noModifications

View File

@ -135,7 +135,7 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
return afterFunctionCallArgs(functionCallStatement)
}
override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
return afterFunctionCallArgs(functionCallExpr)
}

View File

@ -182,8 +182,8 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
else -> {}
}
}
is RangeExpr -> {
val constValues = (containment.iterable as RangeExpr).toConstantIntegerRange()
is RangeExpression -> {
val constValues = (containment.iterable as RangeExpression).toConstantIntegerRange()
if(constValues!=null) {
if (constValues.isEmpty())
return replaceWithFalse()

View File

@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall
import prog8.ast.Program
import prog8.ast.base.DataType
import prog8.ast.expressions.Expression
import prog8.ast.expressions.FunctionCallExpr
import prog8.ast.expressions.FunctionCallExpression
import prog8.ast.expressions.TypecastExpression
import prog8.ast.statements.*
import prog8.ast.walk.IAstVisitor
@ -13,7 +13,7 @@ import prog8.compilerinterface.InternalCompilerException
internal class VerifyFunctionArgTypes(val program: Program) : IAstVisitor {
override fun visit(functionCallExpr: FunctionCallExpr) {
override fun visit(functionCallExpr: FunctionCallExpression) {
val error = checkTypes(functionCallExpr as IFunctionCall, program)
if(error!=null)
throw InternalCompilerException(error)

View File

@ -145,7 +145,7 @@ class TestCompilerOnRanges: FunSpec({
val iterable = startSub
.statements.filterIsInstance<ForLoop>()
.map { it.iterable }[0]
val rangeExpr = iterable as RangeExpr
val rangeExpr = iterable as RangeExpression
val expectedStart = platform.encodeString("a", true)[0].toInt()
val expectedEnd = platform.encodeString("f", false)[0].toInt()
@ -179,7 +179,7 @@ class TestCompilerOnRanges: FunSpec({
val rangeExpr = startSub
.statements.filterIsInstance<ForLoop>()
.map { it.iterable }
.filterIsInstance<RangeExpr>()[0]
.filterIsInstance<RangeExpression>()[0]
rangeExpr.size() shouldBe 2
val intProgression = rangeExpr.toConstantIntegerRange()
@ -205,7 +205,7 @@ class TestCompilerOnRanges: FunSpec({
val rangeExpr = startSub
.statements.filterIsInstance<ForLoop>()
.map { it.iterable }
.filterIsInstance<RangeExpr>()[0]
.filterIsInstance<RangeExpression>()[0]
rangeExpr.size() shouldBe 9
val intProgression = rangeExpr.toConstantIntegerRange()
@ -253,7 +253,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testRangeExprNumericSize") {
val expr = RangeExpr(
val expr = RangeExpression(
NumericLiteralValue.optimalInteger(10, Position.DUMMY),
NumericLiteralValue.optimalInteger(20, Position.DUMMY),
NumericLiteralValue.optimalInteger(2, Position.DUMMY),
@ -278,8 +278,8 @@ class TestCompilerOnRanges: FunSpec({
array shouldBe instanceOf<ArrayLiteralValue>()
(array as ArrayLiteralValue).value.size shouldBe 26
val forloop = (statements.dropLast(1).last() as ForLoop)
forloop.iterable shouldBe instanceOf<RangeExpr>()
(forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
forloop.iterable shouldBe instanceOf<RangeExpression>()
(forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
}
test("range with start/end variables should be ok") {
@ -296,8 +296,8 @@ class TestCompilerOnRanges: FunSpec({
""").assertSuccess()
val statements = result.program.entrypoint.statements
val forloop = (statements.dropLast(1).last() as ForLoop)
forloop.iterable shouldBe instanceOf<RangeExpr>()
(forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
forloop.iterable shouldBe instanceOf<RangeExpression>()
(forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
}

View File

@ -4,7 +4,7 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.types.instanceOf
import prog8.ast.expressions.FunctionCallExpr
import prog8.ast.expressions.FunctionCallExpression
import prog8.ast.expressions.IdentifierReference
import prog8.ast.statements.Pipe
import prog8.codegen.target.C64Target
@ -45,12 +45,12 @@ class TestPipes: FunSpec({
stmts.size shouldBe 3
val pipef = stmts[0] as Pipe
pipef.expressions.size shouldBe 2
pipef.expressions[0] shouldBe instanceOf<FunctionCallExpr>()
pipef.expressions[0] shouldBe instanceOf<FunctionCallExpression>()
pipef.expressions[1] shouldBe instanceOf<IdentifierReference>()
val pipew = stmts[1] as Pipe
pipew.expressions.size shouldBe 2
pipew.expressions[0] shouldBe instanceOf<FunctionCallExpr>()
pipew.expressions[0] shouldBe instanceOf<FunctionCallExpression>()
pipew.expressions[1] shouldBe instanceOf<IdentifierReference>()
}

View File

@ -512,22 +512,22 @@ class TestProg8Parser: FunSpec( {
iterables.size shouldBe 5
val it0 = iterables[0] as RangeExpr
val it0 = iterables[0] as RangeExpression
it0.from shouldBe instanceOf<StringLiteralValue>()
it0.to shouldBe instanceOf<StringLiteralValue>()
val it1 = iterables[1] as StringLiteralValue
it1.value shouldBe "something"
val it2 = iterables[2] as RangeExpr
val it2 = iterables[2] as RangeExpression
it2.from shouldBe instanceOf<CharLiteral>()
it2.to shouldBe instanceOf<CharLiteral>()
val it3 = iterables[3] as RangeExpr
val it3 = iterables[3] as RangeExpression
it3.from shouldBe instanceOf<NumericLiteralValue>()
it3.to shouldBe instanceOf<NumericLiteralValue>()
val it4 = iterables[4] as RangeExpr
val it4 = iterables[4] as RangeExpression
it4.from shouldBe instanceOf<NumericLiteralValue>()
it4.to shouldBe instanceOf<NumericLiteralValue>()
}

View File

@ -201,7 +201,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
}
}
override fun visit(functionCallExpr: FunctionCallExpr) {
override fun visit(functionCallExpr: FunctionCallExpression) {
printout(functionCallExpr as IFunctionCall)
}
@ -262,7 +262,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
}
}
override fun visit(range: RangeExpr) {
override fun visit(range: RangeExpression) {
range.from.accept(this)
output(" to ")
range.to.accept(this)

View File

@ -283,12 +283,12 @@ private fun Prog8ANTLRParser.Functioncall_stmtContext.toAst(): Statement {
FunctionCallStatement(location, expression_list().toAst().toMutableList(), void, toPosition())
}
private fun Prog8ANTLRParser.FunctioncallContext.toAst(): FunctionCallExpr {
private fun Prog8ANTLRParser.FunctioncallContext.toAst(): FunctionCallExpression {
val location = scoped_identifier().toAst()
return if(expression_list() == null)
FunctionCallExpr(location, mutableListOf(), toPosition())
FunctionCallExpression(location, mutableListOf(), toPosition())
else
FunctionCallExpr(location, expression_list().toAst().toMutableList(), toPosition())
FunctionCallExpression(location, expression_list().toAst().toMutableList(), toPosition())
}
private fun Prog8ANTLRParser.InlineasmContext.toAst(): InlineAssembly {
@ -463,7 +463,7 @@ private fun Prog8ANTLRParser.ExpressionContext.toAst() : Expression {
if (rangefrom!=null && rangeto!=null) {
val defaultstep = if(rto.text == "to") 1 else -1
val step = rangestep?.toAst() ?: NumericLiteralValue(DataType.UBYTE, defaultstep.toDouble(), toPosition())
return RangeExpr(rangefrom.toAst(), rangeto.toAst(), step, toPosition())
return RangeExpression(rangefrom.toAst(), rangeto.toAst(), step, toPosition())
}
if(childCount==3 && children[0].text=="(" && children[2].text==")")

View File

@ -64,11 +64,11 @@ sealed class Expression: Node {
is AddressOf -> {
(other is AddressOf && other.identifier.nameInSource == identifier.nameInSource)
}
is RangeExpr -> {
(other is RangeExpr && other.from==from && other.to==to && other.step==step)
is RangeExpression -> {
(other is RangeExpression && other.from==from && other.to==to && other.step==step)
}
is FunctionCallExpr -> {
(other is FunctionCallExpr && other.target.nameInSource == target.nameInSource
is FunctionCallExpression -> {
(other is FunctionCallExpression && other.target.nameInSource == target.nameInSource
&& other.args.size == args.size
&& other.args.zip(args).all { it.first isSameAs it.second } )
}
@ -747,10 +747,10 @@ class ArrayLiteralValue(val type: InferredTypes.InferredType, // inferred be
}
}
class RangeExpr(var from: Expression,
var to: Expression,
var step: Expression,
override val position: Position) : Expression() {
class RangeExpression(var from: Expression,
var to: Expression,
var step: Expression,
override val position: Position) : Expression() {
override lateinit var parent: Node
override fun linkParents(parent: Node) {
@ -773,7 +773,7 @@ class RangeExpr(var from: Expression,
replacement.parent = this
}
override fun copy() = RangeExpr(from.copy(), to.copy(), step.copy(), position)
override fun copy() = RangeExpression(from.copy(), to.copy(), step.copy(), position)
override fun constValue(program: Program): NumericLiteralValue? = null
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
@ -906,9 +906,9 @@ data class IdentifierReference(val nameInSource: List<String>, override val posi
}
}
class FunctionCallExpr(override var target: IdentifierReference,
override var args: MutableList<Expression>,
override val position: Position) : Expression(), IFunctionCall {
class FunctionCallExpression(override var target: IdentifierReference,
override var args: MutableList<Expression>,
override val position: Position) : Expression(), IFunctionCall {
override lateinit var parent: Node
override fun linkParents(parent: Node) {
@ -917,7 +917,7 @@ class FunctionCallExpr(override var target: IdentifierReference,
args.forEach { it.linkParents(this) }
}
override fun copy() = FunctionCallExpr(target.copy(), args.map { it.copy() }.toMutableList(), position)
override fun copy() = FunctionCallExpression(target.copy(), args.map { it.copy() }.toMutableList(), position)
override val isSimple = target.nameInSource.size==1 && (target.nameInSource[0] in arrayOf("msb", "lsb", "peek", "peekw"))
override fun replaceChildNode(node: Node, replacement: Node) {
@ -1011,8 +1011,8 @@ class ContainmentCheck(var element: Expression,
val exists = (iterable as ArrayLiteralValue).value.any { it.constValue(program)==elementConst }
return NumericLiteralValue.fromBoolean(exists, position)
}
is RangeExpr -> {
val intRange = (iterable as RangeExpr).toConstantIntegerRange()
is RangeExpression -> {
val intRange = (iterable as RangeExpression).toConstantIntegerRange()
if(intRange!=null && elementConst.type in IntegerDatatypes) {
val exists = elementConst.number.toInt() in intRange
return NumericLiteralValue.fromBoolean(exists, position)
@ -1035,8 +1035,8 @@ class ContainmentCheck(var element: Expression,
if(array.value.isEmpty())
return NumericLiteralValue.fromBoolean(false, position)
}
is RangeExpr -> {
val size = (iterable as RangeExpr).size()
is RangeExpression -> {
val size = (iterable as RangeExpression).size()
if(size!=null && size==0)
return NumericLiteralValue.fromBoolean(false, position)
}

View File

@ -94,7 +94,7 @@ abstract class AstWalker {
open fun before(expr: PrefixExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun before(forLoop: ForLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun before(repeatLoop: RepeatLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> = noModifications
open fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun before(functionCallStatement: FunctionCallStatement, parent: Node): Iterable<IAstModification> = noModifications
open fun before(identifier: IdentifierReference, parent: Node): Iterable<IAstModification> = noModifications
open fun before(ifElse: IfElse, parent: Node): Iterable<IAstModification> = noModifications
@ -109,7 +109,7 @@ abstract class AstWalker {
open fun before(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
open fun before(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
open fun before(program: Program): Iterable<IAstModification> = noModifications
open fun before(range: RangeExpr, parent: Node): Iterable<IAstModification> = noModifications
open fun before(range: RangeExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun before(untilLoop: UntilLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun before(returnStmt: Return, parent: Node): Iterable<IAstModification> = noModifications
open fun before(scope: AnonymousScope, parent: Node): Iterable<IAstModification> = noModifications
@ -138,7 +138,7 @@ abstract class AstWalker {
open fun after(expr: PrefixExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun after(forLoop: ForLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun after(repeatLoop: RepeatLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> = noModifications
open fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun after(functionCallStatement: FunctionCallStatement, parent: Node): Iterable<IAstModification> = noModifications
open fun after(identifier: IdentifierReference, parent: Node): Iterable<IAstModification> = noModifications
open fun after(ifElse: IfElse, parent: Node): Iterable<IAstModification> = noModifications
@ -153,7 +153,7 @@ abstract class AstWalker {
open fun after(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
open fun after(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
open fun after(program: Program): Iterable<IAstModification> = noModifications
open fun after(range: RangeExpr, parent: Node): Iterable<IAstModification> = noModifications
open fun after(range: RangeExpression, parent: Node): Iterable<IAstModification> = noModifications
open fun after(untilLoop: UntilLoop, parent: Node): Iterable<IAstModification> = noModifications
open fun after(returnStmt: Return, parent: Node): Iterable<IAstModification> = noModifications
open fun after(scope: AnonymousScope, parent: Node): Iterable<IAstModification> = noModifications
@ -258,7 +258,7 @@ abstract class AstWalker {
track(after(subroutine, parent), subroutine, parent)
}
fun visit(functionCallExpr: FunctionCallExpr, parent: Node) {
fun visit(functionCallExpr: FunctionCallExpression, parent: Node) {
track(before(functionCallExpr, parent), functionCallExpr, parent)
functionCallExpr.target.accept(this, functionCallExpr)
functionCallExpr.args.forEach { it.accept(this, functionCallExpr) }
@ -304,7 +304,7 @@ abstract class AstWalker {
track(after(branch, parent), branch, parent)
}
fun visit(range: RangeExpr, parent: Node) {
fun visit(range: RangeExpression, parent: Node) {
track(before(range, parent), range, parent)
range.from.accept(this, range)
range.to.accept(this, range)

View File

@ -44,7 +44,7 @@ interface IAstVisitor {
subroutine.statements.forEach { it.accept(this) }
}
fun visit(functionCallExpr: FunctionCallExpr) {
fun visit(functionCallExpr: FunctionCallExpression) {
functionCallExpr.target.accept(this)
functionCallExpr.args.forEach { it.accept(this) }
}
@ -76,7 +76,7 @@ interface IAstVisitor {
branch.elsepart.accept(this)
}
fun visit(range: RangeExpr) {
fun visit(range: RangeExpression) {
range.from.accept(this)
range.to.accept(this)
range.step.accept(this)

View File

@ -57,7 +57,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
super.visit(directive)
}
override fun visit(functionCallExpr: FunctionCallExpr) {
override fun visit(functionCallExpr: FunctionCallExpression) {
val otherSub = functionCallExpr.target.targetSubroutine(program)
if (otherSub != null) {
functionCallExpr.definingSubroutine?.let { thisSub ->

View File

@ -3,9 +3,12 @@
main {
sub start() {
9 + 3
|> add_one |> times_two
|> txt.print_uw
times_two(554 as ubyte)
; txt.print_uw(times_two(add_one(9+3)))
; txt.nl()
; 9 + 3
; |> add_one |> times_two
; |> txt.print_uw
}
sub add_one(ubyte input) -> ubyte {