c3d / xl

A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites
GNU General Public License v3.0
270 stars 15 forks source link

Implement nested scopes #8

Open c3d opened 4 years ago

c3d commented 4 years ago

The documentation now describes scoping rules which are currently, for the most part, not implemented.

The Tao3D compiler was notoriously bad at scoping, sometimes leaking definitions in the enclosing scope in order to workaround limitations with the LLVM code generation used at the time. Nesting should now be possible, although some special care must be taken with respect to how variables from the enclosing context are accessed by the inner context. I believe that LLVM should be supporting that since the dialect of C / C++ that GNU support does support nested functions, but I have not studied yet how this is represented at the LLVM IR level yet.

Symbol lookup is presently relatively well scoped, but additional testing is needed. Nested scope might even be working correctly in the interpreter.

fnune commented 4 years ago

I'm trying to make some progress with the problem of implementing nested scopes in my own programming language as a learning project. If you're interested in joining the discussion, here it is: https://github.com/fnune/vampa/issues/1