bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Incorrect C translation of extern-function #170

Closed GWRon closed 8 years ago

GWRon commented 8 years ago

I tried (again) to compile maxmod2.mod and it fails this way:

./bmk makemods -r maxmod2
[ 27%] Compiling:blitz_thread.c
[ 55%] Archiving:blitz.release.linux.x86.a
ar: creating /BlitzMaxNG/mod/brl.mod/blitz.mod/blitz.release.linux.x86.a
[ 91%] Processing:maxmod2.bmx
[ 92%] Compiling:maxmod2.bmx.release.linux.x86.c
/BlitzMaxNG/mod/maxmod2.mod/maxmod2.mod/.bmx/maxmod2.bmx.release.linux.x86.c: In function ‘maxmod2_maxmod2_CueMusic’:
/BlitzMaxNG/mod/maxmod2.mod/maxmod2.mod/.bmx/maxmod2.bmx.release.linux.x86.c:1152:146: error: expected expression before ‘)’ token
  bbt_chn->_maxmod2_maxmod2_tmaxmodchannel__channel =(bbt_mus->_maxmod2_maxmod2_tmusic_music )->vtbl->Cue(bbt_mus->_maxmod2_maxmod2_tmusic_music ,);
                                                                                                                                                  ^
Build Error: failed to compile (256) /BlitzMaxNG/mod/maxmod2.mod/maxmod2.mod/.bmx/maxmod2.bmx.release.linux.x86.c

That missing portion is based on this code

Function CueMusic:TChannel(URL:Object,Loop:Int=False)
[...]
    Local chn:TMaxModChannel = New TMaxModChannel
    chn._channel = mus.music.Cue(Null)

all Cue()-methods in maxmod are defined with varying return types but the same params:

    Method Cue:TMaxModChannel( alloced_channel:TChannel )

The special thing is, that "IMaxModMusic" is defined externally...

Extern "C"
[...]
    Type IMaxModMusic
[...]
        Method Cue:IMaxModChannel       (alloced_channel:IMaxModChannel)
    EndType
[...]

And mus.music (the erroneous line) is of type IMaxModMusic so "cue()" will be the extern function. Somehow NG thinks, there is a second parameter.

The corresponding .h-file (generated by NG when compiling the module) contains this line

typedef struct IMaxModMusic IMaxModMusic;
struct IMaxModMusicVtbl {
[...]
    struct IMaxModChannel*(* Cue)(struct IMaxModMusic*,struct IMaxModChannel*);

Maybe NG somehow mixes things up?

Albeit this sounds as if "interfaces" should be used, the error means that something is not compatible to vanilla.

How to get it to compile successfully?

SRSSoftware commented 8 years ago

Are you still having issues with this? The first parameter in the c output is a 'hidden' object instance and the 2nd parameter is actually the first parameter in your 'Max code, ie the Null expression.

This may well have been fixed by now?

GWRon commented 8 years ago

Brucey fixed maxmod a while ago.