fixed compiler crash: when passing the name of a subroutine instead of an array or string to an UWORD parameter

now allows taking the address of a subroutine &routine
This commit is contained in:
Irmen de Jong 2020-12-08 21:17:31 +01:00
parent 106fc5daa4
commit 8a504f8eee
3 changed files with 14 additions and 17 deletions

View File

@ -455,15 +455,12 @@ internal class AstChecker(private val program: Program,
override fun visit(addressOf: AddressOf) {
val variable=addressOf.identifier.targetVarDecl(program.namespace)
if(variable==null)
errors.err("pointer-of operand must be the name of a heap variable", addressOf.position)
else {
if(variable.datatype !in ArrayDatatypes
&& variable.type!=VarDeclType.MEMORY
&& variable.struct == null
&& variable.datatype != DataType.STR && variable.datatype!=DataType.STRUCT)
if(variable!=null
&& variable.datatype !in ArrayDatatypes
&& variable.type!=VarDeclType.MEMORY
&& variable.struct == null
&& variable.datatype != DataType.STR && variable.datatype!=DataType.STRUCT)
errors.err("invalid pointer-of operand type", addressOf.position)
}
super.visit(addressOf)
}

View File

@ -41,8 +41,9 @@ class VerifyFunctionArgTypes(val program: Program) : IAstVisitor {
fun checkTypes(call: IFunctionCall, scope: INameScope, program: Program): String? {
val argITypes = call.args.map { it.inferType(program) }
if(argITypes.any { !it.isKnown })
throw FatalAstException("unknown dt")
val firstUnknownDt = argITypes.indexOfFirst { it.isUnknown }
if(firstUnknownDt>=0)
return "argument ${firstUnknownDt+1} invalid argument type"
val argtypes = argITypes.map { it.typeOrElse(DataType.STRUCT) }
val target = call.target.targetStatement(scope)
if (target is Subroutine) {

View File

@ -8,12 +8,6 @@
errors {
sub tofix() {
; TODO fix compiler crash: when passing the name of a subroutine instead of an array or string to an UWORD parameter
; TODO allow taking the address of a subroutine &routine
while c64.CHRIN() {
; TODO: the loop condition isn't properly tested because a ldx is in the way before the beq
}
@ -46,7 +40,12 @@ errors {
main {
sub start() {
function(&start)
test_stack.test()
}
sub function(uword param) {
txt.print_uwhex(param, 1)
param++
}
}