Package org.jruby.RubyClass

Examples of org.jruby.RubyClass.VariableAccessor


        IRubyObject object = (IRubyObject) getSource().retrieve(interp);

        RubyClass clazz = object.getMetaClass().getRealClass();

        // FIXME: Should add this as a field for instruction
        VariableAccessor accessor = clazz.getVariableAccessorForRead(getName());
      Object v = (accessor == null) ? null : accessor.get(object);
        getResult().store(interp, v == null ? interp.getRuntime().getNil() : v);
        return null;
    }
View Full Code Here


        }
        return bigint;
    }

    public final IRubyObject getVariable(Ruby runtime, int index, String name, IRubyObject object) {
        VariableAccessor variableAccessor = variableReaders[index];
        RubyClass cls = object.getMetaClass().getRealClass();
        if (variableAccessor.getClassId() != cls.hashCode()) {
            variableReaders[index] = variableAccessor = cls.getVariableAccessorForRead(name);
        }
        IRubyObject value = (IRubyObject) variableAccessor.get(object);
        if (value != null) {
            return value;
        }
        if (runtime.isVerbose()) {
            warnAboutUninitializedIvar(runtime, name);
View Full Code Here

    private void warnAboutUninitializedIvar(Ruby runtime, String name) {
        runtime.getWarnings().warning(ID.IVAR_NOT_INITIALIZED, "instance variable " + name + " not initialized");
    }

    public final IRubyObject setVariable(Ruby runtime, int index, String name, IRubyObject object, IRubyObject value) {
        VariableAccessor variableAccessor = variableWriters[index];
        RubyClass cls = object.getMetaClass().getRealClass();
        if (variableAccessor.getClassId() != cls.hashCode()) {
            variableWriters[index] = variableAccessor = cls.getVariableAccessorForWrite(name);
        }
        variableAccessor.set(object, value);
        return value;
    }
View Full Code Here

    }
   
    @Override
    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        RubyClass cls = self.getMetaClass().getRealClass();
        VariableAccessor localAccessor = accessor;
        IRubyObject value;
        if (localAccessor.getClassId() != cls.hashCode()) {
            localAccessor = cls.getVariableAccessorForRead(name);
            if (localAccessor == null) return runtime.getNil();
            value = (IRubyObject)localAccessor.get(self);
            accessor = localAccessor;
        } else {
            value = (IRubyObject)localAccessor.get(self);
        }
        if (value != null) return value;
        if (runtime.isVerbose()) warnAboutUninitializedIvar(runtime);
        return runtime.getNil();       
    }
View Full Code Here

        verifyAccessor(cls).set(self, value);               
        return runtime.getNil();
    }

    private VariableAccessor verifyAccessor(RubyClass cls) {
        VariableAccessor localAccessor = accessor;
        if (localAccessor.getClassId() != cls.hashCode()) {
            localAccessor = cls.getVariableAccessorForWrite(name);
            accessor = localAccessor;
        }
        return localAccessor;
    }
View Full Code Here

    public final IRubyObject getVariableDefined(ThreadContext context, int index, String name, IRubyObject object) {
        return getValue(context, index, name, object) == null ? null : context.runtime.getDefinedMessage(DefinedMessage.INSTANCE_VARIABLE);
    }

    private final IRubyObject getValue(ThreadContext context, int index, String name, IRubyObject object) {
        VariableAccessor variableAccessor = variableReaders[index];
        RubyClass cls = object.getMetaClass().getRealClass();
        if (variableAccessor.getClassId() != cls.hashCode()) {
            variableReaders[index] = variableAccessor = cls.getVariableAccessorForRead(name);
        }
        return (IRubyObject)variableAccessor.get(object);
    }
View Full Code Here

    private void warnAboutUninitializedIvar(Ruby runtime, String name) {
        runtime.getWarnings().warning(ID.IVAR_NOT_INITIALIZED, "instance variable " + name + " not initialized");
    }

    public final IRubyObject setVariable(int index, String name, IRubyObject object, IRubyObject value) {
        VariableAccessor variableAccessor = variableWriters[index];
        RubyClass cls = object.getMetaClass().getRealClass();
        if (variableAccessor.getClassId() != cls.hashCode()) {
            variableWriters[index] = variableAccessor = cls.getVariableAccessorForWrite(name);
        }
        variableAccessor.set(object, value);
        return value;
    }
View Full Code Here

        return runtime.getNil();
    }

    private IRubyObject getValue(Ruby runtime, IRubyObject self) {
        RubyClass cls = self.getMetaClass().getRealClass();
        VariableAccessor localAccessor = accessor;
        IRubyObject value;
        if (localAccessor.getClassId() != cls.hashCode()) {
            localAccessor = cls.getVariableAccessorForRead(name);
            if (localAccessor == null) return runtime.getNil();
            value = (IRubyObject)localAccessor.get(self);
            accessor = localAccessor;
        } else {
            value = (IRubyObject)localAccessor.get(self);
        }
        return value;
    }
View Full Code Here

    public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
        Ruby runtime = context.runtime;
        IRubyObject object = (IRubyObject) getSource().retrieve(context, self, currDynScope, temp);

        RubyClass cls = object.getMetaClass().getRealClass();
        VariableAccessor localAccessor = accessor;
        IRubyObject value;
        if (localAccessor.getClassId() != cls.hashCode()) {
            localAccessor = cls.getVariableAccessorForRead(getRef());
            if (localAccessor == null) return runtime.getNil();
            value = (IRubyObject)localAccessor.get(object);
            accessor = localAccessor;
        } else {
            value = (IRubyObject)localAccessor.get(object);
        }
        return value == null ? runtime.getNil() : value;
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyClass.VariableAccessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.