On Sat, Jun 2, 2012 at 2:33 PM, Mike Austin <
mike.aus...@gmail.com> wrote:
> What about using forward declarations like other languages?
Hmm, that would work, but it feels hackish to me. My understanding was
that C only has explicit forward declarations because compilers at the
time didn't have enough memory to do anything more user-friendly.
> This would add a 'null' binding for Bar, and would be replaced when Bar is
> actually defined. You could later go through the AST and ensure there are
> no 'null' bindings.
Having to deal with that redundancy feels a bit hairy to me. This is
one of the things I was hoping to move away from by having top-level
definitions appear "simultaneous". The compiler right now does
something similar to what you suggest when it compiles method calls.
If it sees a call to a method it doesn't know (yet), it implicitly
defines it and then hopes that later the real method will come along
to fill that definition.
In other words, a method call is implicitly treated like a forward
declaration for that method. But that seems kind of nasty to me. I'd
rather do the simpler solution of:
1. Walk through all of the definitions and declare them.
2. Then compile their bodies.
I can do that in two passes if definitions aren't considered
expressions and occur "simultaneously".
> I imagine I'd do something similar in Ruby or Python.
They (like the current Magpie interpreter in Java) handle this by
basically late binding everything I think.
- bob