allow address-of to be used as a value for a memory pointer variable

This commit is contained in:
Irmen de Jong 2020-09-18 22:10:20 +02:00
parent 9b66a597bb
commit def06dbc0b
2 changed files with 9 additions and 4 deletions

View File

@ -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)
}
}
}

View File

@ -355,7 +355,10 @@ internal class AsmGen(private val program: Program,
out("\n; memdefs and kernel subroutines")
val memvars = statements.filterIsInstance<VarDecl>().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<Subroutine>().filter { it.isAsmSubroutine }
for(sub in asmSubs) {