diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index a4c58bb1f..810e93d78 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -584,13 +584,15 @@ internal class AstChecker(private val program: Program, } } - if(decl.value !is NumericLiteralValue) { - err("value of memory var decl is not a numeric literal (it is a ${decl.value!!.javaClass.simpleName}).", decl.value?.position) - } else { + if(decl.value is NumericLiteralValue) { val value = decl.value as NumericLiteralValue if (value.type !in IntegerDatatypes || value.number.toInt() < 0 || value.number.toInt() > 65535) { err("memory address must be valid integer 0..\$ffff", decl.value?.position) } + } else if(decl.value is AddressOf) { + // we allow this too: the address of another variable + } else { + err("value of memory var decl is invalid type.", decl.value?.position) } } } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 2ad774a2d..8bbcfa30e 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -355,7 +355,10 @@ internal class AsmGen(private val program: Program, out("\n; memdefs and kernel subroutines") val memvars = statements.filterIsInstance().filter { it.type==VarDeclType.MEMORY || it.type==VarDeclType.CONST } for(m in memvars) { - out(" ${m.name} = ${(m.value as NumericLiteralValue).number.toHex()}") + if(m.value is NumericLiteralValue) + out(" ${m.name} = ${(m.value as NumericLiteralValue).number.toHex()}") + else + out(" ${m.name} = ${asmVariableName((m.value as AddressOf).identifier)}") } val asmSubs = statements.filterIsInstance().filter { it.isAsmSubroutine } for(sub in asmSubs) {