totalspectrum / spin2cpp

Tool to convert Parallax Propeller Spin code to PASM, C++ or C
Other
46 stars 17 forks source link

Project with child obj containing obj pointer and array of its own child objects FTBFS #411

Closed avsa242 closed 1 year ago

avsa242 commented 1 year ago

Stumped with this one...can't tell if I'm just not seeing something dumb I'm doing or if this is a genuine bug...

' top.spin
obj

    child: "child"
    child2: "child2"

pub main()

    child.main(@child2)
' child.spin:
obj

    sibling=    "child2"
    child[2]: "grandchild"

pub main(ptr): r

    child[0].main()
    r := sibling[ptr].main(4)
'child2.spin:
pub main(a): c | b

    b := 16
    c := b*a
'grandchild.spin:
var

    byte _var

pub main()

    _var := 1

top.spin fails to build with:

Version 6.3.0 Compiled on: Aug 15 2023
top.spin
|-child.spin
|-|-child2.spin
|-|-grandchild.spin
|-child2.spin
/home/avsa242/prop/github/bugs/obj-arrays-compile-err/child.spin:4: error: Not an identifier
/home/avsa242/prop/github/bugs/obj-arrays-compile-err/child.spin:4: error: Not an identifier
/home/avsa242/prop/github/bugs/obj-arrays-compile-err/child.spin:4: error: Expected identifier
/home/avsa242/prop/github/bugs/obj-arrays-compile-err/child.spin:8: error: request for member main in something not an object
/home/avsa242/prop/github/bugs/obj-arrays-compile-err/child.spin:8: error: main is not a member
Program size:      88 bytes
Variable size:      8 bytes
Stack/Free:     32656 bytes

I went way back to FlexSpins of mid-2021 vintage and they had the same issue, so it's nothing that was changed recently... If you remove either the call r := sibling[ptr].main(4) from child.spin or the declaration of child[2]: "grandchild" (and the call to its method), the build succeeds, but both can't be present. Any ideas?

totalspectrum commented 1 year ago

This seems only to be an issue with the P1 bytecode backend (-1bc). I'll look into it, I suspect it's related to the tangled attempt to derive types in the memory access code.

totalspectrum commented 1 year ago

I fixed it so it compiles now; I'm not sure if the generated code is correct though, that still needs more investigation.

avsa242 commented 1 year ago

This only expands (or hopefully makes a bit clearer) the original contrived example I attached, but attached is an updated archive that tests the fix. It does indeed seem to work, at least in this case. I suppose top.spin could be made more dynamic - maybe a loop that fills x number of grandchildren with some known values, and then reads them back to compare them, but this at least tests the basic functionality.

obj-arrays-compile-err-fixed1.zip

totalspectrum commented 1 year ago

Thanks! Sounds like this bug is resolved then.