mirror of
https://github.com/irmen/prog8.git
synced 2026-10-22 05:02:58 +00:00
Merge branch 'master' into new-codegens
This commit is contained in:
commit
d144235dc9
9 files changed
+1167
-1079
No files matched your search
@@ -314,30 +314,21 @@ class StatementOptimizer(private val program: Program,
|
||||
|
||||
val rNum = (rExpr.right as? NumericLiteral)?.number
|
||||
if(rNum!=null) {
|
||||
if (op1 == "+" || op1 == "-") {
|
||||
if (op2 == "+") {
|
||||
// A = A +/- B + N ---> A = A +/- B ; A = A + N
|
||||
val expr2 = BinaryExpression(binExpr.left, binExpr.operator, rExpr.left, binExpr.position)
|
||||
val addConstant = Assignment(
|
||||
assignment.target.copy(),
|
||||
BinaryExpression(binExpr.left.copy(), "+", rExpr.right, rExpr.position),
|
||||
AssignmentOrigin.OPTIMIZER, assignment.position
|
||||
)
|
||||
return listOf(
|
||||
AstReplaceNode(binExpr, expr2, binExpr.parent),
|
||||
AstInsert.after(assignment, addConstant, parent as IStatementContainer))
|
||||
} else if (op2 == "-") {
|
||||
// A = A +/- B - N ---> A = A +/- B ; A = A - N
|
||||
val expr2 = BinaryExpression(binExpr.left, binExpr.operator, rExpr.left, binExpr.position)
|
||||
val subConstant = Assignment(
|
||||
assignment.target.copy(),
|
||||
BinaryExpression(binExpr.left.copy(), "-", rExpr.right, rExpr.position),
|
||||
AssignmentOrigin.OPTIMIZER, assignment.position
|
||||
)
|
||||
return listOf(
|
||||
AstReplaceNode(binExpr, expr2, binExpr.parent),
|
||||
AstInsert.after(assignment, subConstant, parent as IStatementContainer))
|
||||
}
|
||||
if ((op1 == "+" || op1 == "-") && (op2 == "+" || op2 == "-")) {
|
||||
// A = A op1 (B op2 N) ---> A = A op1 B ; A = A secondOp N
|
||||
// only valid for additive operators (op2 must be + or -).
|
||||
// secondOp keeps the combined expression equivalent:
|
||||
// A+(B+N)=A+N, A+(B-N)=A-N, A-(B+N)=A-N, A-(B-N)=A+N
|
||||
val secondOp = if (op1 == "+") op2 else if (op2 == "+") "-" else "+"
|
||||
val expr2 = BinaryExpression(binExpr.left, binExpr.operator, rExpr.left, binExpr.position)
|
||||
val opConstant = Assignment(
|
||||
assignment.target.copy(),
|
||||
BinaryExpression(binExpr.left.copy(), secondOp, rExpr.right, binExpr.position),
|
||||
AssignmentOrigin.OPTIMIZER, assignment.position
|
||||
)
|
||||
return listOf(
|
||||
AstReplaceNode(binExpr, expr2, binExpr.parent),
|
||||
AstInsert.after(assignment, opConstant, parent as IStatementContainer))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.types.instanceOf
|
||||
import prog8.code.ast.*
|
||||
import prog8.code.target.Cx16Target
|
||||
import prog8.code.target.VMTarget
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
class TestDefers : FunSpec({
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -12,7 +12,6 @@ import prog8.ast.statements.Return
|
||||
import prog8.ast.statements.VarDecl
|
||||
import prog8.ast.statements.VarDeclType
|
||||
import prog8.code.core.BaseDataType
|
||||
import prog8.code.core.DataType
|
||||
import prog8.code.core.Position
|
||||
import prog8.code.target.C64Target
|
||||
import prog8.code.target.Cx16Target
|
||||
|
||||
@@ -3,10 +3,6 @@ package prog8.ast.walk
|
||||
import prog8.ast.*
|
||||
import prog8.ast.expressions.*
|
||||
import prog8.ast.statements.*
|
||||
import prog8.ast.walk.AstInsert.Companion.after
|
||||
import prog8.ast.walk.AstInsert.Companion.before
|
||||
import prog8.ast.walk.AstInsert.Companion.first
|
||||
import prog8.ast.walk.AstInsert.Companion.last
|
||||
import prog8.code.core.CommutativeOperators
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Note: this problem does NOT affect regular data/address registers because those
|
||||
|
||||
Future Things and Ideas
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
- split up AssignmentAsmGen.kt in codeGenCpu6502 it is by far the largest file 6000+ lines
|
||||
- make enums strongly typed instead of just syntactic sugar for ints (see ideas/enum-strong-type.md for the plan)
|
||||
- add %option private_symbols to make access mode private by default; need (new) 'public' keyword to explicitly mark symbols public.
|
||||
- symboldump: some sort of javadocs generated from the p8 source files (instead of just the function signatures). Use markdown for formatting, not html.
|
||||
|
||||
@@ -2,7 +2,6 @@ package prog8lsp
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
|
||||
class GotoDefTest: FunSpec({
|
||||
lateinit var harness: LspTestHarness
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package prog8.code
|
||||
|
||||
import prog8.code.ast.*
|
||||
import prog8.code.core.*
|
||||
import kotlin.math.absoluteValue
|
||||
import prog8.code.core.AssemblyError
|
||||
import prog8.code.core.CompilationOptions
|
||||
import prog8.code.core.DataType
|
||||
import prog8.code.core.ISubType
|
||||
|
||||
fun prefixSymbols(program: PtProgram, options: CompilationOptions, st: SymbolTable): SymbolTable {
|
||||
val nodesToPrefix = mutableListOf<Pair<PtNode, Int>>()
|
||||
|
||||
Reference in new issue
Block a user