fix compiler crashes: txt.chrout("a"), uword[] a = ["ls", subroutine] without & before subroutine.

This commit is contained in:
Irmen de Jong 2022-07-15 23:17:03 +02:00
parent 7cb9a6ba60
commit 8e1071aa89
5 changed files with 33 additions and 12 deletions

View File

@ -799,8 +799,11 @@ internal class AstChecker(private val program: Program,
fun isPassByReferenceElement(e: Expression): Boolean { fun isPassByReferenceElement(e: Expression): Boolean {
if(e is IdentifierReference) { if(e is IdentifierReference) {
val decl = e.targetVarDecl(program)!! val decl = e.targetVarDecl(program)
return decl.datatype in PassByReferenceDatatypes return if(decl!=null)
decl.datatype in PassByReferenceDatatypes
else
true // is probably a symbol that needs addr-of
} }
return e is StringLiteral return e is StringLiteral
} }

View File

@ -57,8 +57,10 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe
if(mismatch>=0) { if(mismatch>=0) {
val actual = argtypes[mismatch] val actual = argtypes[mismatch]
val expected = consideredParamTypes[mismatch] val expected = consideredParamTypes[mismatch]
if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number !in setOf(0.0, 1.0)) return if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number in setOf(0.0, 1.0))
return Pair("argument ${mismatch + 1} type mismatch, was: $actual expected: $expected", call.args[mismatch].position) null // specifying a 1 or 0 as a BOOL is okay
else
Pair("argument ${mismatch + 1} type mismatch, was: $actual expected: $expected", call.args[mismatch].position)
} }
if(target.isAsmSubroutine) { if(target.isAsmSubroutine) {
if(target.asmReturnvaluesRegisters.size>1) { if(target.asmReturnvaluesRegisters.size>1) {

View File

@ -15,6 +15,25 @@ import prog8tests.helpers.compileText
class TestSubroutines: FunSpec({ class TestSubroutines: FunSpec({
test("string arg for byte param proper errormessage and subroutineptr in array too") {
val text="""
main {
sub func(ubyte bb) {
bb++
}
sub start() {
func("abc")
uword[] commands = ["abc", func]
}
}"""
val errors = ErrorReporterForTests()
compileText(C64Target(), false, text, writeAssembly = true, errors=errors) shouldBe null
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "type mismatch, was: STR expected: UBYTE"
errors.errors[1] shouldContain "initialisation value has incompatible type"
}
test("stringParameter") { test("stringParameter") {
val text = """ val text = """
main { main {

View File

@ -3,7 +3,7 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- txt.chrout("a") -> crash - conv.any2uword doesn't accept uppercase hex letters
- see if we can let for loops skip the loop if end<start, without adding a lot of code size/duplicating the loop condition - see if we can let for loops skip the loop if end<start, without adding a lot of code size/duplicating the loop condition
this is documented behiavor to now loop around but it's too easy to forget about this is documented behiavor to now loop around but it's too easy to forget about

View File

@ -2,14 +2,11 @@
%zeropage basicsafe %zeropage basicsafe
main { main {
sub start() { sub func(ubyte bb) {
ubyte derp=2 bb++
callfar(0, &func, 0)
continue:
txt.print("main again.")
} }
sub func() { sub start() {
txt.print("func.") func("abc")
} }
} }