Jibble

Author Topic: Proper forward declarations for AGS  (Read 1176 times)

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Proper forward declarations for AGS
« on: 23 Mar 2015, 19:37 »
I don't have the time or the knowledge to work on this, but I had an idea that could maybe prove useful for implementing proper forward declarations. We already have all of the syntax and keywords that are needed (import and export are sufficient there), the problem AFAICT is that when a user tries to reference an imported item before it has been fully defined the engine isn't linking it properly.

I could be totally off-base here, but it seems like the compiler (which is also acting as the linker, isn't it?) should be able to tell at compile-time whether or not an invocation of an imported item has been appropriately linked to the full definition. Assuming that is correct (and eating my foot if it's not), then the compiler should be able to keep track of imports that aren't linked.

From that point (if I haven't derailed completely yet), it seems that the compiler should be able to just make one more pass through the symbols that have been fully defined, and check for any matching definitions. If it finds a matching definition, then it can link it.

Any thoughts on this? Could it work this way?

Wyz

  • anno 1986
    • I can help with making music
    • I can help with story design
    • I can help with translating
    • I can help with voice acting
    • I can help with web design
    • Wyz worked on one or more games that won an AGS Award!
    •  
    • Wyz worked on one or more games that was nominated for an AGS Award!
Re: Proper forward declarations for AGS
« Reply #1 on: 23 Mar 2015, 20:11 »
Your observations are right. If we compare the compiler with a C/C++ compiler it has two passes: compiling and linking (actually a lot more but let's keep it simple). AGS only has a compiler that links at compile time as you already mentioned. If you want forward declarations you definitely need another pass. You can either choose to have a separate linking stage or have another pass that fills in missing links as you described it; in the end it boils down to the same thing apart from precedence. Speaking of: for C compilers it is on first served base and only missing links cause error. Maybe you want to disallow double links or warn about them; it is a matter of taste I guess. :)
Life is like an adventure without the pixel hunts.