diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 154ac15fe..784041e65 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -317,10 +317,9 @@ class AsmGen( is PtWhen -> translate(stmt) is PtIncludeBinary -> TODO() is PtBreakpoint -> TODO() - is PtVariable -> { /* do nothing; variables are handled elsewhere */ } - is PtScopeVarsDecls -> { /* do nothing; variables are handled elsewhere */ } // TODO translate PtScopeVarsDecls ? or ignore? + is PtVariable, is PtConstant, is PtMemMapped -> { /* do nothing; variables are handled elsewhere */ } is PtBlock -> throw AssemblyError("block should have been handled elsewhere") - is PtNodeGroup -> TODO() + is PtNodeGroup -> stmt.children.forEach { translate(it) } is PtNop -> {} else -> throw AssemblyError("missing asm translation for $stmt") } diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt index 4e271d9d8..54b8a7804 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt @@ -39,22 +39,22 @@ internal fun PtRange.toConstantIntegerRange(): IntProgression? { fun PtExpression.isSimple(): Boolean { - when(this) { - is PtAddressOf -> TODO() - is PtArray -> TODO() - is PtArrayIndexer -> TODO() - is PtBinaryExpression -> TODO() - is PtBuiltinFunctionCall -> TODO() - is PtContainmentCheck -> TODO() - is PtFunctionCall -> TODO() - is PtIdentifier -> TODO() + return when(this) { + is PtAddressOf -> true + is PtArray -> true + is PtArrayIndexer -> index is PtNumber || index is PtIdentifier + is PtBinaryExpression -> false + is PtBuiltinFunctionCall -> name in arrayOf("msb", "lsb", "peek", "peekw", "mkword", "set_carry", "set_irqd", "clear_carry", "clear_irqd") + is PtContainmentCheck -> false + is PtFunctionCall -> false + is PtIdentifier -> true is PtMachineRegister -> TODO() - is PtMemoryByte -> TODO() - is PtNumber -> TODO() - is PtPrefix -> TODO() - is PtRange -> TODO() - is PtString -> TODO() - is PtTypeCast -> TODO() + is PtMemoryByte -> address is PtNumber || address is PtIdentifier + is PtNumber -> true + is PtPrefix -> value.isSimple() + is PtRange -> true + is PtString -> true + is PtTypeCast -> value.isSimple() } } @@ -78,19 +78,7 @@ internal fun PtProgram.lookup(name: String): PtNode { require(remainder.isEmpty()) return node } - is PtSub -> { - if(remainder.isEmpty()) - return node - if(remainder.size==1) { - // look to see if there is a block of vardecls - val scopevars = node.children.firstOrNull() as? PtScopeVarsDecls - if(scopevars!=null) - return recurse(scopevars) - } - val childName = remainder.removeFirst() - return recurse(node.children.filterIsInstance().single { it.name==childName}) - } - is PtBlock, is PtScopeVarsDecls, is PtNamedNode -> { + is PtBlock, is PtSub, is PtNamedNode -> { if(remainder.isEmpty()) return node val childName = remainder.removeFirst() diff --git a/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt index 6fc313899..4d1fd3924 100644 --- a/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt +++ b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt @@ -10,10 +10,10 @@ import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.code.SymbolTable import prog8.code.ast.* +import prog8.code.core.BuiltinFunctions import prog8.code.core.CompilationOptions import prog8.code.core.DataType import prog8.code.core.SourceCode -import prog8.compiler.BuiltinFunctions import prog8.compiler.builtinFunctionReturnType import java.io.File import kotlin.io.path.Path