irmen / prog8

high level programming language and compiler targeting 6502 machines such as the C-64 and CommanderX16
https://prog8.readthedocs.io/
Other
152 stars 18 forks source link

compiler crash when using call builtin #135

Closed djehuti closed 6 months ago

djehuti commented 7 months ago

The following PR exhibits the issue. When building the target repo with this PR:

* internal error *
Exception in thread "main" kotlin.UninitializedPropertyAccessException: lateinit property parent has not been initialized
        at prog8.code.ast.PtNode.getParent(AstBase.kt:15)
        at prog8.code.ast.PtNode.definingBlock(AstBase.kt:129)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:59)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols$prefixSymbols(AsmGen.kt:93)
        at prog8.codegen.cpu6502.AsmGen6502.prefixSymbols(AsmGen.kt:98)
        at prog8.codegen.cpu6502.AsmGen6502.generate(AsmGen.kt:27)
        at prog8.compiler.CompilerKt.createAssemblyAndAssemble(Compiler.kt:496)
        at prog8.compiler.CompilerKt.compileProgram(Compiler.kt:147)
        at prog8.CompilerMainKt.compileMain(CompilerMain.kt:262)
        at prog8.CompilerMainKt.main(CompilerMain.kt:28)
make: *** [Makefile:30: hworld.prg] Error 1
adiee5 commented 7 months ago

I think I know, what could cause it?

void = call(workFunc)

technically, the correct syntax for ignoring a return value from a single return value function is this:

void call(workFunc)

void = syntax wasn't a thing until multi-return syntax was added recently, and I guess the handling of void = for regular functions wasn't added, so stuff happen.

But that's just my thesis.

djehuti commented 7 months ago

Yup, that fixes it. That's a fine workaround for me! (I'm used to that syntax.)

djehuti commented 7 months ago

I'll let you ( @irmen ) decide whether to keep this open to handle that or just close it.

adiee5 commented 7 months ago

yeah, let desertfish see it, so he can add a proper error message

irmen commented 7 months ago

With -target virtual, it also crashes, but with a different error

Exception in thread "main" java.lang.IllegalArgumentException: node prog8.code.ast.PtFunctionCall@ccd1bc3 name is not scoped: call at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:65) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping$verifyPtNode(IRCodeGen.kt:79) at prog8.codegen.intermediate.IRCodeGen.verifyNameScoping(IRCodeGen.kt:90) at prog8.codegen.intermediate.IRCodeGen.generate(IRCodeGen.kt:26)

irmen commented 6 months ago

Minimal reproduction:

main {
  sub start() {
    void = call($2000)
  }
}

related compiler crash:

main {
  sub start() {
    void = 123
  }
}