On Fri, Feb 20, 2009 at 5:22 AM, Ben Evans
<[email protected]> wrote:
> Hi,
>
> I'm doing some work with JRuby's ast, and I've run into a few questions
> about how the various classes are wired together.
>
> Any hints on the below would be very helpful - I'm making notes as I go and
> would be very happy to polish them for a wiki page or javadoc comments if
> that would be useful.
>
> Apologies if these are covered somewhere on the wiki and I missed it - a
> pointer to docs and instructions to RTF them would be most welcome.
>
> Scoping
> What's the difference between a LocalStaticScope and a BlockStaticScope ?

Scoping

StaticScope represents lexical scoping rules.  A BlockStaticScope is a
scope for local variables in a block.  A LocalStaticScope is a scope
for local variables not in a block (method body/class body).

So:

def foo(a, c)
  [a].each do |b|
     proc { d = 1; puts b,c }
  end
end

LocalStaticScope(a,c)
   BlockStaticScope(b)
      BlockStaticScope(d)

The difference between the two scopes is pretty straight-forward.  Any
variable resolution in a LocalStaticScope will not check any outer
scopes.  A BlockStaticScope will.  So in the example above If we
happen to be inside the proc and we are resolving variable 'c', we
will walk out to LocalStaticScope which contains c.

>
> What's the correct way to initialise a top-level static scope - is it:
>
> StaticScope scope = new LocalStaticScope(null);
>
> or something else?

Yep.  That is fine.  In general it does not matter for
LocalStaticScopes based on my explanation above as to how variables
resolve for scoping.  LocalStaticScopes act like top-level scopes in
places that have them.

> Are class and method body scopes considered top-level or should a method
> body scope have the class scope as an enclosing scope? Or does this answer
> depend on closures.

LocalStaticScope is top or local variable scope resolution.  We create
these for every scope which is not a block.

> Arguments and Method calls
> How do ArgsNodes work?
>
> What do the special values for restArguments mean (-1 and -2 seem to be
> special somehow) -1 crops up explicitly in a few places and there's a
> boundary test for -2.

-2 was an empty '*' argument.  That should be replaced with StarNode now.
-1 represent no rest args.

> What do static and instance methods ArgsNodes look like? Ie, if I was
> calling the ArgsNodes constructor corresponding to a static or an instance
> method, how would this look?

They should look exactly the same.  The arguments for the methods are
exactly the same.  The only real difference between these two is the
receiver.

>
> Current State
> My current status is that I have a very simple ast (programatically built
> from scratch) which I can feed into the jruby compiler and have it compile
> but the resulting JVM bytecode fails verification - I suspect because I
> don't fully understand ArgsNodes yet, which is causing the verifier's stack
> underflow check to fail.
>
> Btw, is there a way to ask JRuby to just produce an ast from a .rb, output
> it and stop? Or is it just a case of using jdb and a breakpoint?

We have an 'ast' program that will or is shipping with JRuby now:
jruby -S ast source.rb.
This will give you some output.

>
> Thanks,
>
> Ben
>
>
>
>



-- 
Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: [email protected] , [email protected]

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to