Sha256: 8c821d82ade6e42939a5a7629bd27986252bdf96ae811a4390035aa50652bdcf

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

package org.cx4a.rsense.ruby;

import java.util.Stack;

public class Context {
    private Ruby runtime;
    private Stack<Scope> scopes;
    private Frame frame;

    public Context(Ruby runtime) {
        this.runtime = runtime;
        this.scopes = new Stack<Scope>();
    }

    public void pushScope(Scope scope) {
        scopes.push(scope);
    }

    public void popScope() {
        scopes.pop();
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }

    public Frame pushFrame(RubyModule cbase, String name, IRubyObject self, Block block, Visibility visibility) {
        this.frame = new Frame(cbase, name, self, block, visibility, this.frame);
        return this.frame;
    }

    public Frame popFrame() {
        Frame frame = this.frame;
        this.frame = frame.getPrevious();
        return frame;
    }

    public void pushMain() {
        pushScope(new LocalScope(runtime.getObject()));
        pushFrame(runtime.getObject(), "main", runtime.getTopSelf(), null, Visibility.PRIVATE);
    }

    public void popMain() {
        popFrame();
        popScope();
    }

    public Scope getCurrentScope() {
        return scopes.peek();
    }

    public IRubyObject getConstant(String name) {
        return getCurrentScope().getModule().getConstant(name);
    }

    public Frame getCurrentFrame() {
        return frame;
    }

    public IRubyObject getFrameSelf() {
        return getCurrentFrame().getSelf();
    }

    public RubyModule getFrameModule() {
        return getCurrentFrame().getModule();
    }

    public Block getFrameBlock() {
        return getCurrentFrame().getBlock();
    }

    public Visibility getFrameVisibility() {
        return getCurrentFrame().getVisibility();
    }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rsense-core-0.6.6 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.6.5 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.6.4 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.6.2 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.6.1 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.6.0 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.9 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.8 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.6 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.2 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.1 src/org/cx4a/rsense/ruby/Context.java
rsense-core-0.5.0 src/org/cx4a/rsense/ruby/Context.java