For language developers on the Rubinius platform, the APIs to the Rubinius generator and other compiler parts are generally very smooth and easy to use. An exception to this is when trying to generate a function/closure. Messing with the low-level APIs turns out to be unwieldy, as they tend to expose quite a lot of detail about Ruby-specific semantics.
The goal of this proposal is to provide a higher-level API optimized for a more general use case.
The file ast.rb
contains the user code, and the file new_api.rb
contains the support code to make it work (what would end up being implemented in some rubinius gem).
One thing that could be confusing about this is
for_block
. A "block" is a somewhat odd name for the thing that Ruby creates. It's usually called a closure. Further, while a "block" in Ruby tends to be used to reference a lexical closure that isn't mobile, we know that a method can take that, turn it into a Proc, and pass it anywhere. So we have this really weird "block", "lambda", "Proc", and sometimes "closure" nomenclature.Ideally, we wouldn't propagate this confusion. :)
In the AST there is already the concept of "scope" and all executable contexts are uniformly CompiledCode instances. I think combining the scope and code into an object may be a useful API. It reduces to asking, "What kind of scope am I in, open or closed?" and "What is the code (ie actual set of instructions) that will execute in this scope?"
Thoughts?