z00m128 / sjasmplus

Command-line cross-compiler of assembly language for Z80 CPU.
http://z00m128.github.io/sjasmplus/
BSD 3-Clause "New" or "Revised" License
382 stars 54 forks source link

Support for Object-oriented programming #94

Closed sdsnatcher closed 4 years ago

sdsnatcher commented 4 years ago

Nowadays we have STRUCTs, but it's somewhat clumsy to handle OOP with them. It would be nice to have a CLASS keyword and the rest of the syntax framework to allow some easier OOP support.

ped7g commented 4 years ago

I have very difficult time to see what is cumbersome about STRUCT vs OOP, after all class in C++ is just C struct with hidden vtable implementation, i.e. just add the virtual functions pointers as regular WORD fields in STRUCT, and call them ... voila, OOP reached.

I'm actually doing that, for example here: https://github.com/ped7g/ZXSpectrumNextMisc/blob/master/nexload2/nexload2.asm see line 213 with definition of structure "SCREEN_BLOCK_DEF" and fields DRAW_PIX_STRIP and INIT_CODE, then while instancing the structs at line 618 I just init those fields with addresses of particular function to handle the particular "instance type", and call it in later in code...

Also note how the DRAW_PIX_STRIP is manually optimized to work only with low byte of function address, because I designed the whole NEXLOAD2 to work like that, having all the draw pixel routines in single aligned 256B memory block. - you can't do tricks like this easily with some generic OOP system, so I would probably end using my own STRUCTs any way, because I often squeeze some extra feature from the actual layout/size of the structure, which I wouldn't even think of in C++.

Anyway, for the limited "OOP-like" way of programming how I'm used to do it in Assembly, the current structures work well for me and cover all my needs, I'm failing to see what is missing for you.

So some well thought and refined prototype, with examples how it should work, is a must in this case, to show me how the current state can be improved and what kind of problems is currently difficult to solve and why.

alfishe commented 4 years ago

Please.. just don't do that with Z80 assembler...

ped7g commented 4 years ago

Closing because even after months I fail to see any problem here (and what is clumsy about OOP and current STRUCT).

As far as I can tell sjasmplus does support OOP very well and all the use-cases I can think of are covered enough (and nobody else commented with interesting insight or examples).

Feel free to reopen if you can show some problematic case and propose how it could be improved (compared to current sjasmplus possibilities).