Proper forward declarations for AGS

Started by monkey0506, Mon 23/03/2015 19:37:38

Previous topic - Next topic

monkey0506

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

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.

SMF spam blocked by CleanTalk