mirror of
https://github.com/irmen/prog8.git
synced 2025-08-16 05:27:31 +00:00
naming consistency for some expression classes
This commit is contained in:
@@ -956,10 +956,10 @@ class AsmGen(private val program: Program,
|
|||||||
internal fun translateExpression(expression: Expression) =
|
internal fun translateExpression(expression: Expression) =
|
||||||
expressionsAsmGen.translateExpression(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)
|
builtinFunctionsAsmGen.translateFunctioncallExpression(functionCallExpr, signature, resultToStack, resultRegister)
|
||||||
|
|
||||||
internal fun translateFunctionCall(functionCallExpr: FunctionCallExpr, isExpression: Boolean) =
|
internal fun translateFunctionCall(functionCallExpr: FunctionCallExpression, isExpression: Boolean) =
|
||||||
functioncallAsmGen.translateFunctionCall(functionCallExpr, isExpression)
|
functioncallAsmGen.translateFunctionCall(functionCallExpr, isExpression)
|
||||||
|
|
||||||
internal fun saveXbeforeCall(functionCall: IFunctionCall) =
|
internal fun saveXbeforeCall(functionCall: IFunctionCall) =
|
||||||
@@ -1636,7 +1636,7 @@ $label nop""")
|
|||||||
pipe.expressions.drop(1).dropLast(1).forEach {
|
pipe.expressions.drop(1).dropLast(1).forEach {
|
||||||
val callName = it as IdentifierReference
|
val callName = it as IdentifierReference
|
||||||
val args = mutableListOf<Expression>(IdentifierReference(valueVar, it.position))
|
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)
|
call.linkParents(pipe)
|
||||||
valueDt = call.inferType(program).getOrElse { throw AssemblyError("invalid dt") }
|
valueDt = call.inferType(program).getOrElse { throw AssemblyError("invalid dt") }
|
||||||
valueVar = getTempVarName(valueDt)
|
valueVar = getTempVarName(valueDt)
|
||||||
@@ -1880,7 +1880,7 @@ $label nop""")
|
|||||||
}
|
}
|
||||||
if(dt==DataType.UBYTE) {
|
if(dt==DataType.UBYTE) {
|
||||||
assignExpressionToRegister(left, RegisterOrPair.A, false)
|
assignExpressionToRegister(left, RegisterOrPair.A, false)
|
||||||
if (left is FunctionCallExpr && !left.isSimple)
|
if (left is FunctionCallExpression && !left.isSimple)
|
||||||
out(" cmp #0")
|
out(" cmp #0")
|
||||||
} else {
|
} else {
|
||||||
assignExpressionToRegister(left, RegisterOrPair.AY, false)
|
assignExpressionToRegister(left, RegisterOrPair.AY, false)
|
||||||
@@ -1896,7 +1896,7 @@ $label nop""")
|
|||||||
}
|
}
|
||||||
DataType.BYTE -> {
|
DataType.BYTE -> {
|
||||||
assignExpressionToRegister(left, RegisterOrPair.A, true)
|
assignExpressionToRegister(left, RegisterOrPair.A, true)
|
||||||
if (left is FunctionCallExpr && !left.isSimple)
|
if (left is FunctionCallExpression && !left.isSimple)
|
||||||
out(" cmp #0")
|
out(" cmp #0")
|
||||||
when (operator) {
|
when (operator) {
|
||||||
"==" -> out(" bne $jumpIfFalseLabel")
|
"==" -> out(" bne $jumpIfFalseLabel")
|
||||||
|
@@ -44,7 +44,7 @@ internal fun asmsub6502ArgsHaveRegisterClobberRisk(args: List<Expression>,
|
|||||||
it.registerOrPair in listOf(RegisterOrPair.Y, RegisterOrPair.AY, RegisterOrPair.XY)
|
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"))
|
if (expr.target.nameInSource == listOf("lsb") || expr.target.nameInSource == listOf("msb"))
|
||||||
return isClobberRisk(expr.args[0])
|
return isClobberRisk(expr.args[0])
|
||||||
if (expr.target.nameInSource == listOf("mkword"))
|
if (expr.target.nameInSource == listOf("mkword"))
|
||||||
|
@@ -19,7 +19,7 @@ import prog8.compilerinterface.subroutineFloatEvalResultVar2
|
|||||||
|
|
||||||
internal class BuiltinFunctionsAsmGen(private val program: Program, private val asmgen: AsmGen, private val assignAsmGen: AssignmentAsmGen) {
|
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)
|
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?) {
|
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")
|
throw AssemblyError("should not discard result of memory allocation at $fcall")
|
||||||
val nameRef = fcall.args[0] as IdentifierReference
|
val nameRef = fcall.args[0] as IdentifierReference
|
||||||
val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value
|
val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value
|
||||||
|
@@ -36,16 +36,16 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
is DirectMemoryRead -> asmgen.translateDirectMemReadExpressionToRegAorStack(expression, true)
|
is DirectMemoryRead -> asmgen.translateDirectMemReadExpressionToRegAorStack(expression, true)
|
||||||
is NumericLiteralValue -> translateExpression(expression)
|
is NumericLiteralValue -> translateExpression(expression)
|
||||||
is IdentifierReference -> 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 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 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")
|
is CharLiteral -> throw AssemblyError("charliteral should have been replaced by ubyte using certain encoding")
|
||||||
else -> TODO("missing expression asmgen for $expression")
|
else -> TODO("missing expression asmgen for $expression")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun translateFunctionCallResultOntoStack(call: FunctionCallExpr) {
|
private fun translateFunctionCallResultOntoStack(call: FunctionCallExpression) {
|
||||||
// only for use in nested expression evaluation
|
// only for use in nested expression evaluation
|
||||||
|
|
||||||
val sub = call.target.targetStatement(program)
|
val sub = call.target.targetStatement(program)
|
||||||
|
@@ -5,7 +5,7 @@ import prog8.ast.base.ArrayToElementTypes
|
|||||||
import prog8.ast.base.DataType
|
import prog8.ast.base.DataType
|
||||||
import prog8.ast.base.RegisterOrPair
|
import prog8.ast.base.RegisterOrPair
|
||||||
import prog8.ast.expressions.IdentifierReference
|
import prog8.ast.expressions.IdentifierReference
|
||||||
import prog8.ast.expressions.RangeExpr
|
import prog8.ast.expressions.RangeExpression
|
||||||
import prog8.ast.statements.ForLoop
|
import prog8.ast.statements.ForLoop
|
||||||
import prog8.ast.toHex
|
import prog8.ast.toHex
|
||||||
import prog8.codegen.target.AssemblyError
|
import prog8.codegen.target.AssemblyError
|
||||||
@@ -18,10 +18,10 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen:
|
|||||||
if(!iterableDt.isKnown)
|
if(!iterableDt.isKnown)
|
||||||
throw AssemblyError("unknown dt")
|
throw AssemblyError("unknown dt")
|
||||||
when(stmt.iterable) {
|
when(stmt.iterable) {
|
||||||
is RangeExpr -> {
|
is RangeExpression -> {
|
||||||
val range = (stmt.iterable as RangeExpr).toConstantIntegerRange()
|
val range = (stmt.iterable as RangeExpression).toConstantIntegerRange()
|
||||||
if(range==null) {
|
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 {
|
} else {
|
||||||
translateForOverConstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, range)
|
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 loopLabel = asmgen.makeLabel("for_loop")
|
||||||
val endLabel = asmgen.makeLabel("for_end")
|
val endLabel = asmgen.makeLabel("for_end")
|
||||||
val modifiedLabel = asmgen.makeLabel("for_modified")
|
val modifiedLabel = asmgen.makeLabel("for_modified")
|
||||||
@@ -587,7 +587,7 @@ $loopLabel""")
|
|||||||
asmgen.loopEndLabels.pop()
|
asmgen.loopEndLabels.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) =
|
private fun assignLoopvar(stmt: ForLoop, range: RangeExpression) =
|
||||||
asmgen.assignExpressionToVariable(
|
asmgen.assignExpressionToVariable(
|
||||||
range.from,
|
range.from,
|
||||||
asmgen.asmVariableName(stmt.loopVar),
|
asmgen.asmVariableName(stmt.loopVar),
|
||||||
|
@@ -167,7 +167,7 @@ internal class AsmAssignSource(val kind: SourceStorageKind,
|
|||||||
val dt = value.inferType(program).getOrElse { throw AssemblyError("unknown dt") }
|
val dt = value.inferType(program).getOrElse { throw AssemblyError("unknown dt") }
|
||||||
AsmAssignSource(SourceStorageKind.ARRAY, program, asmgen, dt, array = value)
|
AsmAssignSource(SourceStorageKind.ARRAY, program, asmgen, dt, array = value)
|
||||||
}
|
}
|
||||||
is FunctionCallExpr -> {
|
is FunctionCallExpression -> {
|
||||||
when (val sub = value.target.targetStatement(program)) {
|
when (val sub = value.target.targetStatement(program)) {
|
||||||
is Subroutine -> {
|
is Subroutine -> {
|
||||||
val returnType = sub.returntypes.zip(sub.asmReturnvaluesRegisters).firstOrNull { rr -> rr.second.registerOrPair != null || rr.second.statusflag!=null }?.first
|
val returnType = sub.returntypes.zip(sub.asmReturnvaluesRegisters).firstOrNull { rr -> rr.second.registerOrPair != null || rr.second.statusflag!=null }?.first
|
||||||
|
@@ -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 ArrayIndexedExpression -> throw AssemblyError("source kind should have been array")
|
||||||
is DirectMemoryRead -> throw AssemblyError("source kind should have been memory")
|
is DirectMemoryRead -> throw AssemblyError("source kind should have been memory")
|
||||||
is TypecastExpression -> assignTypeCastedValue(assign.target, value.type, value.expression, value)
|
is TypecastExpression -> assignTypeCastedValue(assign.target, value.type, value.expression, value)
|
||||||
is FunctionCallExpr -> {
|
is FunctionCallExpression -> {
|
||||||
when (val sub = value.target.targetStatement(program)) {
|
when (val sub = value.target.targetStatement(program)) {
|
||||||
is Subroutine -> {
|
is Subroutine -> {
|
||||||
asmgen.saveXbeforeCall(value)
|
asmgen.saveXbeforeCall(value)
|
||||||
@@ -300,7 +300,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
|
|
||||||
private fun containmentCheckIntoA(containment: ContainmentCheck) {
|
private fun containmentCheckIntoA(containment: ContainmentCheck) {
|
||||||
val elementDt = containment.element.inferType(program)
|
val elementDt = containment.element.inferType(program)
|
||||||
val range = containment.iterable as? RangeExpr
|
val range = containment.iterable as? RangeExpression
|
||||||
if(range!=null) {
|
if(range!=null) {
|
||||||
val constRange = range.toConstantIntegerRange()
|
val constRange = range.toConstantIntegerRange()
|
||||||
if(constRange!=null)
|
if(constRange!=null)
|
||||||
@@ -596,7 +596,7 @@ $containsLabel lda #1
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) {
|
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)
|
lsb.linkParents(value.parent)
|
||||||
val src = AsmAssignSource(SourceStorageKind.EXPRESSION, program, asmgen, DataType.UBYTE, expression = lsb)
|
val src = AsmAssignSource(SourceStorageKind.EXPRESSION, program, asmgen, DataType.UBYTE, expression = lsb)
|
||||||
val assign = AsmAssignment(src, target, false, program.memsizer, value.position)
|
val assign = AsmAssignment(src, target, false, program.memsizer, value.position)
|
||||||
|
@@ -310,7 +310,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
|
|||||||
return noModifications
|
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.
|
// the args of a fuction are constfolded via recursion already.
|
||||||
val constvalue = functionCallExpr.constValue(program)
|
val constvalue = functionCallExpr.constValue(program)
|
||||||
return if(constvalue!=null)
|
return if(constvalue!=null)
|
||||||
@@ -320,7 +320,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun after(forLoop: ForLoop, parent: Node): Iterable<IAstModification> {
|
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 fromCast = rangeFrom.cast(targetDt)
|
||||||
val toCast = rangeTo.cast(targetDt)
|
val toCast = rangeTo.cast(targetDt)
|
||||||
if(!fromCast.isValid || !toCast.isValid)
|
if(!fromCast.isValid || !toCast.isValid)
|
||||||
@@ -337,11 +337,11 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() {
|
|||||||
range.step
|
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.
|
// 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 rangeFrom = iterableRange.from as? NumericLiteralValue
|
||||||
val rangeTo = iterableRange.to as? NumericLiteralValue
|
val rangeTo = iterableRange.to as? NumericLiteralValue
|
||||||
if(rangeFrom==null || rangeTo==null) return noModifications
|
if(rangeFrom==null || rangeTo==null) return noModifications
|
||||||
|
@@ -40,7 +40,7 @@ class VarConstantValueTypeAdjuster(private val program: Program, private val err
|
|||||||
return noModifications
|
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 from = range.from.constValue(program)?.number
|
||||||
val to = range.to.constValue(program)?.number
|
val to = range.to.constValue(program)?.number
|
||||||
val step = range.step.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 -> {
|
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) {
|
if(rangeExpr!=null) {
|
||||||
// convert the initializer range expression to an actual array
|
// convert the initializer range expression to an actual array
|
||||||
val declArraySize = decl.arraysize?.constIndex()
|
val declArraySize = decl.arraysize?.constIndex()
|
||||||
@@ -193,7 +193,7 @@ internal class ConstantIdentifierReplacer(private val program: Program, private
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType.ARRAY_F -> {
|
DataType.ARRAY_F -> {
|
||||||
val rangeExpr = decl.value as? RangeExpr
|
val rangeExpr = decl.value as? RangeExpression
|
||||||
if(rangeExpr!=null) {
|
if(rangeExpr!=null) {
|
||||||
// convert the initializer range expression to an actual array of floats
|
// convert the initializer range expression to an actual array of floats
|
||||||
val declArraySize = decl.arraysize?.constIndex()
|
val declArraySize = decl.arraysize?.constIndex()
|
||||||
|
@@ -209,7 +209,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
// signedw < 0 --> msb(signedw) & $80
|
// signedw < 0 --> msb(signedw) & $80
|
||||||
return listOf(IAstModification.ReplaceNode(
|
return listOf(IAstModification.ReplaceNode(
|
||||||
expr,
|
expr,
|
||||||
BinaryExpression(FunctionCallExpr(IdentifierReference(listOf("msb"), expr.position),
|
BinaryExpression(FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position),
|
||||||
mutableListOf(expr.left),
|
mutableListOf(expr.left),
|
||||||
expr.position
|
expr.position
|
||||||
), "&", NumericLiteralValue.optimalInteger(0x80, expr.position), 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
|
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")) {
|
if(functionCallExpr.target.nameInSource == listOf("lsb")) {
|
||||||
val arg = functionCallExpr.args[0]
|
val arg = functionCallExpr.args[0]
|
||||||
if(arg is TypecastExpression) {
|
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> {
|
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) {
|
if(range!=null && range.step.constValue(program)?.number==1.0) {
|
||||||
val from = range.from.constValue(program)
|
val from = range.from.constValue(program)
|
||||||
val to = range.to.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()
|
val firstValue = pipe.expressions.first()
|
||||||
if(firstValue.isSimple) {
|
if(firstValue.isSimple) {
|
||||||
val funcname = pipe.expressions[1] as IdentifierReference
|
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)
|
val newExprs = mutableListOf<Expression>(first)
|
||||||
newExprs.addAll(pipe.expressions.drop(2))
|
newExprs.addAll(pipe.expressions.drop(2))
|
||||||
return listOf(IAstModification.ReplaceNode(pipe, Pipe(newExprs, pipe.position), parent))
|
return listOf(IAstModification.ReplaceNode(pipe, Pipe(newExprs, pipe.position), parent))
|
||||||
}
|
}
|
||||||
val singleExpr = pipe.expressions.singleOrNull()
|
val singleExpr = pipe.expressions.singleOrNull()
|
||||||
if(singleExpr!=null) {
|
if(singleExpr!=null) {
|
||||||
val callExpr = singleExpr as FunctionCallExpr
|
val callExpr = singleExpr as FunctionCallExpression
|
||||||
val call = FunctionCallStatement(callExpr.target, callExpr.args, true, callExpr.position)
|
val call = FunctionCallStatement(callExpr.target, callExpr.args, true, callExpr.position)
|
||||||
return listOf(IAstModification.ReplaceNode(pipe, call, parent))
|
return listOf(IAstModification.ReplaceNode(pipe, call, parent))
|
||||||
}
|
}
|
||||||
@@ -490,7 +490,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
}
|
}
|
||||||
0.5 -> {
|
0.5 -> {
|
||||||
// sqrt(left)
|
// 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 -> {
|
1.0 -> {
|
||||||
// left
|
// left
|
||||||
@@ -683,12 +683,12 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
if (amount >= 16) {
|
if (amount >= 16) {
|
||||||
return NumericLiteralValue(targetDt, 0.0, expr.position)
|
return NumericLiteralValue(targetDt, 0.0, expr.position)
|
||||||
} else if (amount >= 8) {
|
} 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) {
|
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)
|
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 -> {
|
else -> {
|
||||||
@@ -725,11 +725,11 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
|||||||
return NumericLiteralValue.optimalInteger(0, expr.position)
|
return NumericLiteralValue.optimalInteger(0, expr.position)
|
||||||
}
|
}
|
||||||
else if (amount >= 8) {
|
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) {
|
if (amount == 8) {
|
||||||
// mkword(0, msb(v))
|
// mkword(0, msb(v))
|
||||||
val zero = NumericLiteralValue(DataType.UBYTE, 0.0, expr.position)
|
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)
|
return TypecastExpression(BinaryExpression(msb, ">>", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position), DataType.UWORD, true, expr.position)
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ class StatementOptimizer(private val program: Program,
|
|||||||
private val compTarget: ICompilationTarget
|
private val compTarget: ICompilationTarget
|
||||||
) : AstWalker() {
|
) : 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,
|
// 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.
|
// 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!=null) {
|
||||||
if (range.size() == 1) {
|
if (range.size() == 1) {
|
||||||
// for loop over a (constant) range of just a single value-- optimize the loop away
|
// for loop over a (constant) range of just a single value-- optimize the loop away
|
||||||
|
@@ -234,7 +234,7 @@ class UnusedCodeRemover(private val program: Program,
|
|||||||
is PrefixExpression,
|
is PrefixExpression,
|
||||||
is BinaryExpression,
|
is BinaryExpression,
|
||||||
is TypecastExpression,
|
is TypecastExpression,
|
||||||
is FunctionCallExpr -> { /* don't remove */ }
|
is FunctionCallExpression -> { /* don't remove */ }
|
||||||
else -> linesToRemove.add(assign1)
|
else -> linesToRemove.add(assign1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,6 @@ import prog8.ast.*
|
|||||||
import prog8.ast.base.*
|
import prog8.ast.base.*
|
||||||
import prog8.ast.expressions.*
|
import prog8.ast.expressions.*
|
||||||
import prog8.ast.statements.*
|
import prog8.ast.statements.*
|
||||||
import prog8.ast.walk.IAstModification
|
|
||||||
import prog8.ast.walk.IAstVisitor
|
import prog8.ast.walk.IAstVisitor
|
||||||
import prog8.compilerinterface.*
|
import prog8.compilerinterface.*
|
||||||
import java.io.CharConversionException
|
import java.io.CharConversionException
|
||||||
@@ -86,7 +85,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
override fun visit(forLoop: ForLoop) {
|
override fun visit(forLoop: ForLoop) {
|
||||||
|
|
||||||
fun checkUnsignedLoopDownto0(range: RangeExpr?) {
|
fun checkUnsignedLoopDownto0(range: RangeExpression?) {
|
||||||
if(range==null)
|
if(range==null)
|
||||||
return
|
return
|
||||||
val step = range.step.constValue(program)?.number ?: 1.0
|
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)
|
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)
|
errors.err("can only loop over an iterable type", forLoop.position)
|
||||||
} else {
|
} else {
|
||||||
val loopvar = forLoop.loopVar.targetVarDecl(program)
|
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)
|
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)
|
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 -> {
|
DataType.UWORD -> {
|
||||||
if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.UWORD && iterableDt != DataType.STR &&
|
if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.UWORD && iterableDt != DataType.STR &&
|
||||||
iterableDt != DataType.ARRAY_UB && iterableDt!= DataType.ARRAY_UW)
|
iterableDt != DataType.ARRAY_UB && iterableDt!= DataType.ARRAY_UW)
|
||||||
errors.err("uword loop variable can only loop over unsigned bytes, words or strings", forLoop.position)
|
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 -> {
|
DataType.BYTE -> {
|
||||||
if(iterableDt!= DataType.BYTE && iterableDt!= DataType.ARRAY_B)
|
if(iterableDt!= DataType.BYTE && iterableDt!= DataType.ARRAY_B)
|
||||||
@@ -138,7 +137,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
if(errors.noErrors()) {
|
if(errors.noErrors()) {
|
||||||
// check loop range values
|
// check loop range values
|
||||||
val range = forLoop.iterable as? RangeExpr
|
val range = forLoop.iterable as? RangeExpression
|
||||||
if(range!=null) {
|
if(range!=null) {
|
||||||
val from = range.from as? NumericLiteralValue
|
val from = range.from as? NumericLiteralValue
|
||||||
val to = range.to as? NumericLiteralValue
|
val to = range.to as? NumericLiteralValue
|
||||||
@@ -501,7 +500,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
} else {
|
} else {
|
||||||
val sourceDatatype = assignment.value.inferType(program)
|
val sourceDatatype = assignment.value.inferType(program)
|
||||||
if (sourceDatatype.isUnknown) {
|
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)
|
errors.err("assignment value is invalid or has no proper datatype", assignment.value.position)
|
||||||
} else {
|
} else {
|
||||||
checkAssignmentCompatible(targetDatatype.getOr(DataType.BYTE),
|
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")
|
err("unsized array declaration cannot use a single literal initialization value")
|
||||||
return
|
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")
|
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 -> {
|
null -> {
|
||||||
// a vardecl without an initial value, don't bother with it
|
// 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 -> {
|
is StringLiteralValue -> {
|
||||||
checkValueTypeAndRangeString(decl.datatype, decl.value as StringLiteralValue)
|
checkValueTypeAndRangeString(decl.datatype, decl.value as StringLiteralValue)
|
||||||
}
|
}
|
||||||
@@ -901,7 +900,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
super.visit(typecast)
|
super.visit(typecast)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(range: RangeExpr) {
|
override fun visit(range: RangeExpression) {
|
||||||
fun err(msg: String) {
|
fun err(msg: String) {
|
||||||
errors.err(msg, range.position)
|
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.
|
// this function call is (part of) an expression, which should be in a statement somewhere.
|
||||||
val stmtOfExpression = findParentNode<Statement>(functionCallExpr)
|
val stmtOfExpression = findParentNode<Statement>(functionCallExpr)
|
||||||
?: throw FatalAstException("cannot determine statement scope of function call expression at ${functionCallExpr.position}")
|
?: 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
|
var ident: IdentifierReference? = null
|
||||||
if(arg.value is IdentifierReference)
|
if(arg.value is IdentifierReference)
|
||||||
ident = arg.value as IdentifierReference
|
ident = arg.value as IdentifierReference
|
||||||
else if(arg.value is FunctionCallExpr) {
|
else if(arg.value is FunctionCallExpression) {
|
||||||
val fcall = arg.value as FunctionCallExpr
|
val fcall = arg.value as FunctionCallExpression
|
||||||
if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb"))
|
if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb"))
|
||||||
ident = fcall.args[0] as? IdentifierReference
|
ident = fcall.args[0] as? IdentifierReference
|
||||||
}
|
}
|
||||||
@@ -1473,7 +1472,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
sourceValue: Expression) : Boolean {
|
sourceValue: Expression) : Boolean {
|
||||||
val position = sourceValue.position
|
val position = sourceValue.position
|
||||||
|
|
||||||
if(sourceValue is RangeExpr)
|
if(sourceValue is RangeExpression)
|
||||||
errors.err("can't assign a range value to something else", position)
|
errors.err("can't assign a range value to something else", position)
|
||||||
|
|
||||||
val result = when(targetDatatype) {
|
val result = when(targetDatatype) {
|
||||||
|
@@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall
|
|||||||
import prog8.ast.Node
|
import prog8.ast.Node
|
||||||
import prog8.ast.Program
|
import prog8.ast.Program
|
||||||
import prog8.ast.base.Position
|
import prog8.ast.base.Position
|
||||||
import prog8.ast.expressions.FunctionCallExpr
|
import prog8.ast.expressions.FunctionCallExpression
|
||||||
import prog8.ast.expressions.StringLiteralValue
|
import prog8.ast.expressions.StringLiteralValue
|
||||||
import prog8.ast.statements.*
|
import prog8.ast.statements.*
|
||||||
import prog8.ast.walk.IAstVisitor
|
import prog8.ast.walk.IAstVisitor
|
||||||
@@ -128,7 +128,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
|||||||
super.visit(string)
|
super.visit(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(functionCallExpr: FunctionCallExpr) = visitFunctionCall(functionCallExpr)
|
override fun visit(functionCallExpr: FunctionCallExpression) = visitFunctionCall(functionCallExpr)
|
||||||
override fun visit(functionCallStatement: FunctionCallStatement) = visitFunctionCall(functionCallStatement)
|
override fun visit(functionCallStatement: FunctionCallStatement) = visitFunctionCall(functionCallStatement)
|
||||||
|
|
||||||
private fun visitFunctionCall(call: IFunctionCall) {
|
private fun visitFunctionCall(call: IFunctionCall) {
|
||||||
|
@@ -12,7 +12,7 @@ import prog8.compilerinterface.IErrorReporter
|
|||||||
|
|
||||||
class AstPreprocessor(val program: Program, val errors: IErrorReporter) : AstWalker() {
|
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
|
// has to be done before the constant folding, otherwise certain checks there will fail on invalid range sizes
|
||||||
val modifications = mutableListOf<IAstModification>()
|
val modifications = mutableListOf<IAstModification>()
|
||||||
if(range.from !is NumericLiteralValue) {
|
if(range.from !is NumericLiteralValue) {
|
||||||
|
@@ -117,7 +117,7 @@ _after:
|
|||||||
override fun before(functionCallStatement: FunctionCallStatement, parent: Node) =
|
override fun before(functionCallStatement: FunctionCallStatement, parent: Node) =
|
||||||
before(functionCallStatement as IFunctionCall, parent, functionCallStatement.position)
|
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)
|
before(functionCallExpr as IFunctionCall, parent, functionCallExpr.position)
|
||||||
|
|
||||||
private fun before(functionCall: IFunctionCall, parent: Node, position: Position): Iterable<IAstModification> {
|
private fun before(functionCall: IFunctionCall, parent: Node, position: Position): Iterable<IAstModification> {
|
||||||
|
@@ -161,7 +161,7 @@ internal class ParentNodeChecker: AstWalker() {
|
|||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun before(range: RangeExpr, parent: Node): Iterable<IAstModification> {
|
override fun before(range: RangeExpression, parent: Node): Iterable<IAstModification> {
|
||||||
if(range.parent!==parent)
|
if(range.parent!==parent)
|
||||||
throw FatalAstException("parent node mismatch at $range")
|
throw FatalAstException("parent node mismatch at $range")
|
||||||
return noModifications
|
return noModifications
|
||||||
@@ -221,7 +221,7 @@ internal class ParentNodeChecker: AstWalker() {
|
|||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
|
override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
|
||||||
if(functionCallExpr.parent!==parent)
|
if(functionCallExpr.parent!==parent)
|
||||||
throw FatalAstException("parent node mismatch at $functionCallExpr")
|
throw FatalAstException("parent node mismatch at $functionCallExpr")
|
||||||
return noModifications
|
return noModifications
|
||||||
|
@@ -135,7 +135,7 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
|
|||||||
return afterFunctionCallArgs(functionCallStatement)
|
return afterFunctionCallArgs(functionCallStatement)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable<IAstModification> {
|
override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable<IAstModification> {
|
||||||
return afterFunctionCallArgs(functionCallExpr)
|
return afterFunctionCallArgs(functionCallExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -182,8 +182,8 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is RangeExpr -> {
|
is RangeExpression -> {
|
||||||
val constValues = (containment.iterable as RangeExpr).toConstantIntegerRange()
|
val constValues = (containment.iterable as RangeExpression).toConstantIntegerRange()
|
||||||
if(constValues!=null) {
|
if(constValues!=null) {
|
||||||
if (constValues.isEmpty())
|
if (constValues.isEmpty())
|
||||||
return replaceWithFalse()
|
return replaceWithFalse()
|
||||||
|
@@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall
|
|||||||
import prog8.ast.Program
|
import prog8.ast.Program
|
||||||
import prog8.ast.base.DataType
|
import prog8.ast.base.DataType
|
||||||
import prog8.ast.expressions.Expression
|
import prog8.ast.expressions.Expression
|
||||||
import prog8.ast.expressions.FunctionCallExpr
|
import prog8.ast.expressions.FunctionCallExpression
|
||||||
import prog8.ast.expressions.TypecastExpression
|
import prog8.ast.expressions.TypecastExpression
|
||||||
import prog8.ast.statements.*
|
import prog8.ast.statements.*
|
||||||
import prog8.ast.walk.IAstVisitor
|
import prog8.ast.walk.IAstVisitor
|
||||||
@@ -13,7 +13,7 @@ import prog8.compilerinterface.InternalCompilerException
|
|||||||
|
|
||||||
internal class VerifyFunctionArgTypes(val program: Program) : IAstVisitor {
|
internal class VerifyFunctionArgTypes(val program: Program) : IAstVisitor {
|
||||||
|
|
||||||
override fun visit(functionCallExpr: FunctionCallExpr) {
|
override fun visit(functionCallExpr: FunctionCallExpression) {
|
||||||
val error = checkTypes(functionCallExpr as IFunctionCall, program)
|
val error = checkTypes(functionCallExpr as IFunctionCall, program)
|
||||||
if(error!=null)
|
if(error!=null)
|
||||||
throw InternalCompilerException(error)
|
throw InternalCompilerException(error)
|
||||||
|
@@ -145,7 +145,7 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
val iterable = startSub
|
val iterable = startSub
|
||||||
.statements.filterIsInstance<ForLoop>()
|
.statements.filterIsInstance<ForLoop>()
|
||||||
.map { it.iterable }[0]
|
.map { it.iterable }[0]
|
||||||
val rangeExpr = iterable as RangeExpr
|
val rangeExpr = iterable as RangeExpression
|
||||||
|
|
||||||
val expectedStart = platform.encodeString("a", true)[0].toInt()
|
val expectedStart = platform.encodeString("a", true)[0].toInt()
|
||||||
val expectedEnd = platform.encodeString("f", false)[0].toInt()
|
val expectedEnd = platform.encodeString("f", false)[0].toInt()
|
||||||
@@ -179,7 +179,7 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
val rangeExpr = startSub
|
val rangeExpr = startSub
|
||||||
.statements.filterIsInstance<ForLoop>()
|
.statements.filterIsInstance<ForLoop>()
|
||||||
.map { it.iterable }
|
.map { it.iterable }
|
||||||
.filterIsInstance<RangeExpr>()[0]
|
.filterIsInstance<RangeExpression>()[0]
|
||||||
|
|
||||||
rangeExpr.size() shouldBe 2
|
rangeExpr.size() shouldBe 2
|
||||||
val intProgression = rangeExpr.toConstantIntegerRange()
|
val intProgression = rangeExpr.toConstantIntegerRange()
|
||||||
@@ -205,7 +205,7 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
val rangeExpr = startSub
|
val rangeExpr = startSub
|
||||||
.statements.filterIsInstance<ForLoop>()
|
.statements.filterIsInstance<ForLoop>()
|
||||||
.map { it.iterable }
|
.map { it.iterable }
|
||||||
.filterIsInstance<RangeExpr>()[0]
|
.filterIsInstance<RangeExpression>()[0]
|
||||||
|
|
||||||
rangeExpr.size() shouldBe 9
|
rangeExpr.size() shouldBe 9
|
||||||
val intProgression = rangeExpr.toConstantIntegerRange()
|
val intProgression = rangeExpr.toConstantIntegerRange()
|
||||||
@@ -253,7 +253,7 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("testRangeExprNumericSize") {
|
test("testRangeExprNumericSize") {
|
||||||
val expr = RangeExpr(
|
val expr = RangeExpression(
|
||||||
NumericLiteralValue.optimalInteger(10, Position.DUMMY),
|
NumericLiteralValue.optimalInteger(10, Position.DUMMY),
|
||||||
NumericLiteralValue.optimalInteger(20, Position.DUMMY),
|
NumericLiteralValue.optimalInteger(20, Position.DUMMY),
|
||||||
NumericLiteralValue.optimalInteger(2, Position.DUMMY),
|
NumericLiteralValue.optimalInteger(2, Position.DUMMY),
|
||||||
@@ -278,8 +278,8 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
array shouldBe instanceOf<ArrayLiteralValue>()
|
array shouldBe instanceOf<ArrayLiteralValue>()
|
||||||
(array as ArrayLiteralValue).value.size shouldBe 26
|
(array as ArrayLiteralValue).value.size shouldBe 26
|
||||||
val forloop = (statements.dropLast(1).last() as ForLoop)
|
val forloop = (statements.dropLast(1).last() as ForLoop)
|
||||||
forloop.iterable shouldBe instanceOf<RangeExpr>()
|
forloop.iterable shouldBe instanceOf<RangeExpression>()
|
||||||
(forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
|
(forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
|
||||||
}
|
}
|
||||||
|
|
||||||
test("range with start/end variables should be ok") {
|
test("range with start/end variables should be ok") {
|
||||||
@@ -296,8 +296,8 @@ class TestCompilerOnRanges: FunSpec({
|
|||||||
""").assertSuccess()
|
""").assertSuccess()
|
||||||
val statements = result.program.entrypoint.statements
|
val statements = result.program.entrypoint.statements
|
||||||
val forloop = (statements.dropLast(1).last() as ForLoop)
|
val forloop = (statements.dropLast(1).last() as ForLoop)
|
||||||
forloop.iterable shouldBe instanceOf<RangeExpr>()
|
forloop.iterable shouldBe instanceOf<RangeExpression>()
|
||||||
(forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
|
(forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import io.kotest.core.spec.style.FunSpec
|
|||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import io.kotest.matchers.string.shouldContain
|
import io.kotest.matchers.string.shouldContain
|
||||||
import io.kotest.matchers.types.instanceOf
|
import io.kotest.matchers.types.instanceOf
|
||||||
import prog8.ast.expressions.FunctionCallExpr
|
import prog8.ast.expressions.FunctionCallExpression
|
||||||
import prog8.ast.expressions.IdentifierReference
|
import prog8.ast.expressions.IdentifierReference
|
||||||
import prog8.ast.statements.Pipe
|
import prog8.ast.statements.Pipe
|
||||||
import prog8.codegen.target.C64Target
|
import prog8.codegen.target.C64Target
|
||||||
@@ -45,12 +45,12 @@ class TestPipes: FunSpec({
|
|||||||
stmts.size shouldBe 3
|
stmts.size shouldBe 3
|
||||||
val pipef = stmts[0] as Pipe
|
val pipef = stmts[0] as Pipe
|
||||||
pipef.expressions.size shouldBe 2
|
pipef.expressions.size shouldBe 2
|
||||||
pipef.expressions[0] shouldBe instanceOf<FunctionCallExpr>()
|
pipef.expressions[0] shouldBe instanceOf<FunctionCallExpression>()
|
||||||
pipef.expressions[1] shouldBe instanceOf<IdentifierReference>()
|
pipef.expressions[1] shouldBe instanceOf<IdentifierReference>()
|
||||||
|
|
||||||
val pipew = stmts[1] as Pipe
|
val pipew = stmts[1] as Pipe
|
||||||
pipew.expressions.size shouldBe 2
|
pipew.expressions.size shouldBe 2
|
||||||
pipew.expressions[0] shouldBe instanceOf<FunctionCallExpr>()
|
pipew.expressions[0] shouldBe instanceOf<FunctionCallExpression>()
|
||||||
pipew.expressions[1] shouldBe instanceOf<IdentifierReference>()
|
pipew.expressions[1] shouldBe instanceOf<IdentifierReference>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -512,22 +512,22 @@ class TestProg8Parser: FunSpec( {
|
|||||||
|
|
||||||
iterables.size shouldBe 5
|
iterables.size shouldBe 5
|
||||||
|
|
||||||
val it0 = iterables[0] as RangeExpr
|
val it0 = iterables[0] as RangeExpression
|
||||||
it0.from shouldBe instanceOf<StringLiteralValue>()
|
it0.from shouldBe instanceOf<StringLiteralValue>()
|
||||||
it0.to shouldBe instanceOf<StringLiteralValue>()
|
it0.to shouldBe instanceOf<StringLiteralValue>()
|
||||||
|
|
||||||
val it1 = iterables[1] as StringLiteralValue
|
val it1 = iterables[1] as StringLiteralValue
|
||||||
it1.value shouldBe "something"
|
it1.value shouldBe "something"
|
||||||
|
|
||||||
val it2 = iterables[2] as RangeExpr
|
val it2 = iterables[2] as RangeExpression
|
||||||
it2.from shouldBe instanceOf<CharLiteral>()
|
it2.from shouldBe instanceOf<CharLiteral>()
|
||||||
it2.to 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.from shouldBe instanceOf<NumericLiteralValue>()
|
||||||
it3.to 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.from shouldBe instanceOf<NumericLiteralValue>()
|
||||||
it4.to shouldBe instanceOf<NumericLiteralValue>()
|
it4.to shouldBe instanceOf<NumericLiteralValue>()
|
||||||
}
|
}
|
||||||
|
@@ -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)
|
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)
|
range.from.accept(this)
|
||||||
output(" to ")
|
output(" to ")
|
||||||
range.to.accept(this)
|
range.to.accept(this)
|
||||||
|
@@ -283,12 +283,12 @@ private fun Prog8ANTLRParser.Functioncall_stmtContext.toAst(): Statement {
|
|||||||
FunctionCallStatement(location, expression_list().toAst().toMutableList(), void, toPosition())
|
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()
|
val location = scoped_identifier().toAst()
|
||||||
return if(expression_list() == null)
|
return if(expression_list() == null)
|
||||||
FunctionCallExpr(location, mutableListOf(), toPosition())
|
FunctionCallExpression(location, mutableListOf(), toPosition())
|
||||||
else
|
else
|
||||||
FunctionCallExpr(location, expression_list().toAst().toMutableList(), toPosition())
|
FunctionCallExpression(location, expression_list().toAst().toMutableList(), toPosition())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Prog8ANTLRParser.InlineasmContext.toAst(): InlineAssembly {
|
private fun Prog8ANTLRParser.InlineasmContext.toAst(): InlineAssembly {
|
||||||
@@ -463,7 +463,7 @@ private fun Prog8ANTLRParser.ExpressionContext.toAst() : Expression {
|
|||||||
if (rangefrom!=null && rangeto!=null) {
|
if (rangefrom!=null && rangeto!=null) {
|
||||||
val defaultstep = if(rto.text == "to") 1 else -1
|
val defaultstep = if(rto.text == "to") 1 else -1
|
||||||
val step = rangestep?.toAst() ?: NumericLiteralValue(DataType.UBYTE, defaultstep.toDouble(), toPosition())
|
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==")")
|
if(childCount==3 && children[0].text=="(" && children[2].text==")")
|
||||||
|
@@ -64,11 +64,11 @@ sealed class Expression: Node {
|
|||||||
is AddressOf -> {
|
is AddressOf -> {
|
||||||
(other is AddressOf && other.identifier.nameInSource == identifier.nameInSource)
|
(other is AddressOf && other.identifier.nameInSource == identifier.nameInSource)
|
||||||
}
|
}
|
||||||
is RangeExpr -> {
|
is RangeExpression -> {
|
||||||
(other is RangeExpr && other.from==from && other.to==to && other.step==step)
|
(other is RangeExpression && other.from==from && other.to==to && other.step==step)
|
||||||
}
|
}
|
||||||
is FunctionCallExpr -> {
|
is FunctionCallExpression -> {
|
||||||
(other is FunctionCallExpr && other.target.nameInSource == target.nameInSource
|
(other is FunctionCallExpression && other.target.nameInSource == target.nameInSource
|
||||||
&& other.args.size == args.size
|
&& other.args.size == args.size
|
||||||
&& other.args.zip(args).all { it.first isSameAs it.second } )
|
&& 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,
|
class RangeExpression(var from: Expression,
|
||||||
var to: Expression,
|
var to: Expression,
|
||||||
var step: Expression,
|
var step: Expression,
|
||||||
override val position: Position) : Expression() {
|
override val position: Position) : Expression() {
|
||||||
override lateinit var parent: Node
|
override lateinit var parent: Node
|
||||||
|
|
||||||
override fun linkParents(parent: Node) {
|
override fun linkParents(parent: Node) {
|
||||||
@@ -773,7 +773,7 @@ class RangeExpr(var from: Expression,
|
|||||||
replacement.parent = this
|
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 constValue(program: Program): NumericLiteralValue? = null
|
||||||
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
|
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
|
||||||
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
|
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,
|
class FunctionCallExpression(override var target: IdentifierReference,
|
||||||
override var args: MutableList<Expression>,
|
override var args: MutableList<Expression>,
|
||||||
override val position: Position) : Expression(), IFunctionCall {
|
override val position: Position) : Expression(), IFunctionCall {
|
||||||
override lateinit var parent: Node
|
override lateinit var parent: Node
|
||||||
|
|
||||||
override fun linkParents(parent: Node) {
|
override fun linkParents(parent: Node) {
|
||||||
@@ -917,7 +917,7 @@ class FunctionCallExpr(override var target: IdentifierReference,
|
|||||||
args.forEach { it.linkParents(this) }
|
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 val isSimple = target.nameInSource.size==1 && (target.nameInSource[0] in arrayOf("msb", "lsb", "peek", "peekw"))
|
||||||
|
|
||||||
override fun replaceChildNode(node: Node, replacement: Node) {
|
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 }
|
val exists = (iterable as ArrayLiteralValue).value.any { it.constValue(program)==elementConst }
|
||||||
return NumericLiteralValue.fromBoolean(exists, position)
|
return NumericLiteralValue.fromBoolean(exists, position)
|
||||||
}
|
}
|
||||||
is RangeExpr -> {
|
is RangeExpression -> {
|
||||||
val intRange = (iterable as RangeExpr).toConstantIntegerRange()
|
val intRange = (iterable as RangeExpression).toConstantIntegerRange()
|
||||||
if(intRange!=null && elementConst.type in IntegerDatatypes) {
|
if(intRange!=null && elementConst.type in IntegerDatatypes) {
|
||||||
val exists = elementConst.number.toInt() in intRange
|
val exists = elementConst.number.toInt() in intRange
|
||||||
return NumericLiteralValue.fromBoolean(exists, position)
|
return NumericLiteralValue.fromBoolean(exists, position)
|
||||||
@@ -1035,8 +1035,8 @@ class ContainmentCheck(var element: Expression,
|
|||||||
if(array.value.isEmpty())
|
if(array.value.isEmpty())
|
||||||
return NumericLiteralValue.fromBoolean(false, position)
|
return NumericLiteralValue.fromBoolean(false, position)
|
||||||
}
|
}
|
||||||
is RangeExpr -> {
|
is RangeExpression -> {
|
||||||
val size = (iterable as RangeExpr).size()
|
val size = (iterable as RangeExpression).size()
|
||||||
if(size!=null && size==0)
|
if(size!=null && size==0)
|
||||||
return NumericLiteralValue.fromBoolean(false, position)
|
return NumericLiteralValue.fromBoolean(false, position)
|
||||||
}
|
}
|
||||||
|
@@ -94,7 +94,7 @@ abstract class AstWalker {
|
|||||||
open fun before(expr: PrefixExpression, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(expr: PrefixExpression, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(forLoop: ForLoop, 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(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(functionCallStatement: FunctionCallStatement, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(identifier: IdentifierReference, 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
|
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(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(postIncrDecr: PostIncrDecr, 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(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(untilLoop: UntilLoop, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(returnStmt: Return, 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
|
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(expr: PrefixExpression, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(forLoop: ForLoop, 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(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(functionCallStatement: FunctionCallStatement, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(identifier: IdentifierReference, 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
|
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(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(postIncrDecr: PostIncrDecr, 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(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(untilLoop: UntilLoop, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(returnStmt: Return, 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
|
open fun after(scope: AnonymousScope, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
@@ -258,7 +258,7 @@ abstract class AstWalker {
|
|||||||
track(after(subroutine, parent), subroutine, parent)
|
track(after(subroutine, parent), subroutine, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(functionCallExpr: FunctionCallExpr, parent: Node) {
|
fun visit(functionCallExpr: FunctionCallExpression, parent: Node) {
|
||||||
track(before(functionCallExpr, parent), functionCallExpr, parent)
|
track(before(functionCallExpr, parent), functionCallExpr, parent)
|
||||||
functionCallExpr.target.accept(this, functionCallExpr)
|
functionCallExpr.target.accept(this, functionCallExpr)
|
||||||
functionCallExpr.args.forEach { it.accept(this, functionCallExpr) }
|
functionCallExpr.args.forEach { it.accept(this, functionCallExpr) }
|
||||||
@@ -304,7 +304,7 @@ abstract class AstWalker {
|
|||||||
track(after(branch, parent), branch, parent)
|
track(after(branch, parent), branch, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(range: RangeExpr, parent: Node) {
|
fun visit(range: RangeExpression, parent: Node) {
|
||||||
track(before(range, parent), range, parent)
|
track(before(range, parent), range, parent)
|
||||||
range.from.accept(this, range)
|
range.from.accept(this, range)
|
||||||
range.to.accept(this, range)
|
range.to.accept(this, range)
|
||||||
|
@@ -44,7 +44,7 @@ interface IAstVisitor {
|
|||||||
subroutine.statements.forEach { it.accept(this) }
|
subroutine.statements.forEach { it.accept(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(functionCallExpr: FunctionCallExpr) {
|
fun visit(functionCallExpr: FunctionCallExpression) {
|
||||||
functionCallExpr.target.accept(this)
|
functionCallExpr.target.accept(this)
|
||||||
functionCallExpr.args.forEach { it.accept(this) }
|
functionCallExpr.args.forEach { it.accept(this) }
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ interface IAstVisitor {
|
|||||||
branch.elsepart.accept(this)
|
branch.elsepart.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(range: RangeExpr) {
|
fun visit(range: RangeExpression) {
|
||||||
range.from.accept(this)
|
range.from.accept(this)
|
||||||
range.to.accept(this)
|
range.to.accept(this)
|
||||||
range.step.accept(this)
|
range.step.accept(this)
|
||||||
|
@@ -57,7 +57,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
|||||||
super.visit(directive)
|
super.visit(directive)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(functionCallExpr: FunctionCallExpr) {
|
override fun visit(functionCallExpr: FunctionCallExpression) {
|
||||||
val otherSub = functionCallExpr.target.targetSubroutine(program)
|
val otherSub = functionCallExpr.target.targetSubroutine(program)
|
||||||
if (otherSub != null) {
|
if (otherSub != null) {
|
||||||
functionCallExpr.definingSubroutine?.let { thisSub ->
|
functionCallExpr.definingSubroutine?.let { thisSub ->
|
||||||
|
@@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
9 + 3
|
times_two(554 as ubyte)
|
||||||
|> add_one |> times_two
|
; txt.print_uw(times_two(add_one(9+3)))
|
||||||
|> txt.print_uw
|
; txt.nl()
|
||||||
|
; 9 + 3
|
||||||
|
; |> add_one |> times_two
|
||||||
|
; |> txt.print_uw
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_one(ubyte input) -> ubyte {
|
sub add_one(ubyte input) -> ubyte {
|
||||||
|
Reference in New Issue
Block a user