Package org.jruby

Examples of org.jruby.Ruby


            return result;
        }
       
        public IRubyObject initialize(ThreadContext context, final IRubyObject[] args, Block block) {
            this.block = block;
            final Ruby runtime = context.getRuntime();
            this.result = runtime.getNil();
            this.thread = new Thread() {
                @Override
                public void run() {
                    synchronized (yieldLock) {
                        alive = true;
                        ThreadContext context = runtime.getCurrentContext();
                        context.setFiber(Fiber.this);
                        try {
                            result = Fiber.this.block.yield(runtime.getCurrentContext(), result, null, null, true);
                        } finally {
                            yieldLock.notify();
                        }
                    }
                }
View Full Code Here


        } catch(ThreadKill e) {
            throw e;
        } catch(MainExitException e) {
            throw e;
        } catch(Exception e) {
            Ruby runtime = recv.getRuntime();
            runtime.getJavaSupport().handleNativeException(e);
            return runtime.getNil();
        }       
    }
View Full Code Here

       
        setupMakefileConfig(configModule, mkmfHash);
    }
   
    private static void setupMakefileConfig(RubyModule configModule, RubyHash mkmfHash) {
        Ruby ruby = configModule.getRuntime();
       
        String jflags = " -fno-omit-frame-pointer -fno-strict-aliasing -DNDEBUG ";
        String oflags = " -O2 " + jflags;
        String wflags = " -W -Werror -Wall -Wno-unused -Wno-parentheses ";
        String picflags = true ? "" : " -fPIC -pthread ";
       
        String iflags = " -I\"$(JDK_HOME)/include\" -I\"$(JDK_HOME)/include/$(OS)\" -I\"$(BUILD_DIR)\" ";
       
        String cflags = "";
        String soflags = true ? "" : " -shared -static-libgcc -mimpure-text -Wl,-O1 ";
        String ldflags = soflags;
       
       
        String archflags = " -arch i386 -arch ppc -arch x86_64 ";
       
        cflags += archflags;

        // this set is only for darwin
        cflags += " -isysroot /Developer/SDKs/MacOSX10.4u.sdk -DTARGET_RT_MAC_CFM=0 ";
        cflags += " -arch i386 -arch ppc -arch x86_64 ";
        ldflags += " -arch i386 -arch ppc -arch x86_64 -bundle -framework JavaVM -Wl,-syslibroot,$(SDKROOT) -mmacosx-version-min=10.4 -undefined dynamic_lookup ";
        String libext = "a";
        String objext = "o";
       
        setConfig(mkmfHash, "configure_args", "");
        setConfig(mkmfHash, "CFLAGS", cflags);
        setConfig(mkmfHash, "CPPFLAGS", "");
        setConfig(mkmfHash, "ARCH_FLAG", "");
        setConfig(mkmfHash, "LDFLAGS", ldflags);
        setConfig(mkmfHash, "DLDFLAGS", "");
        setConfig(mkmfHash, "LIBEXT", libext);
        setConfig(mkmfHash, "OBJEXT", objext);
        setConfig(mkmfHash, "LIBRUBYARG_STATIC", "");
        setConfig(mkmfHash, "LIBRUBYARG_SHARED", "");
        setConfig(mkmfHash, "LIBS", "");
        setConfig(mkmfHash, "DLDLIBS", "");
        setConfig(mkmfHash, "ENABLED_SHARED", "");
        setConfig(mkmfHash, "LIBRUBY", "");
        setConfig(mkmfHash, "LIBRUBY_A", "");
        setConfig(mkmfHash, "LIBRUBYARG", "");
        setConfig(mkmfHash, "prefix", "");
        setConfig(mkmfHash, "ruby_install_name", jrubyScript());
        setConfig(mkmfHash, "DLEXT", "bundle");
        setConfig(mkmfHash, "CC", "cc ");
        setConfig(mkmfHash, "LDSHARED", "cc ");
        setConfig(mkmfHash, "OUTFLAG", "-o ");
        setConfig(mkmfHash, "PATH_SEPARATOR", ":");
        setConfig(mkmfHash, "INSTALL", "install -c ");
        setConfig(mkmfHash, "RM", "rm -f");
        setConfig(mkmfHash, "CP", "cp ");
        setConfig(mkmfHash, "MAKEDIRS", "mkdir -p ");
       
        ruby.getObject().defineConstant("CROSS_COMPILING", ruby.getNil());
       
        configModule.defineConstant("MAKEFILE_CONFIG", mkmfHash);
    }
View Full Code Here

       
        configModule.defineConstant("MAKEFILE_CONFIG", mkmfHash);
    }

    private static void setConfig(RubyHash mkmfHash, String key, String value) {
        Ruby runtime = mkmfHash.getRuntime();
        mkmfHash.op_aset(runtime.getCurrentContext(), runtime.newString(key), runtime.newString(value));
    }
View Full Code Here

        } catch(ThreadKill e) {
            throw e;
        } catch(MainExitException e) {
            throw e;
        } catch(Exception e) {
            Ruby runtime = recv.getRuntime();
            runtime.getJavaSupport().handleNativeException(e);
            return runtime.getNil();
        }
    }
View Full Code Here

            String file, int lineNumber) {
        // both of these are ensured by the (very few) callers
        assert !scope.isNil();
        //assert file != null;

        Ruby runtime = src.getRuntime();
        String savedFile = context.getFile();
        int savedLine = context.getLine();

        if (!(scope instanceof RubyBinding)) {
            if (scope instanceof RubyProc) {
                scope = ((RubyProc) scope).binding();
            } else {
                // bomb out, it's not a binding or a proc
                throw runtime.newTypeError("wrong argument type " + scope.getMetaClass() + " (expected Proc/Binding)");
            }
        }

        Binding binding = ((RubyBinding)scope).getBinding();
        DynamicScope evalScope = binding.getDynamicScope().getEvalScope();

        // If no explicit file passed in we will use the bindings location
        if (file == null) file = binding.getFrame().getFile();
        if (lineNumber == -1) lineNumber = binding.getFrame().getLine();
       
        // FIXME:  This determine module is in a strange location and should somehow be in block
        evalScope.getStaticScope().determineModule();

        Frame lastFrame = context.preEvalWithBinding(binding);
        try {
            // Binding provided for scope, use it
            IRubyObject newSelf = binding.getSelf();
            RubyString source = src.convertToString();
            Node node = runtime.parseEval(source.getByteList(), file, evalScope, lineNumber);

            return node.interpret(runtime, context, newSelf, binding.getFrame().getBlock());
        } catch (JumpException.BreakJump bj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
        } catch (JumpException.RedoJump rj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, (IRubyObject)rj.getValue(), "unexpected redo");
        } catch (StackOverflowError sfe) {
            throw runtime.newSystemStackError("stack level too deep");           
        } finally {
            context.postEvalWithBinding(binding, lastFrame);

            // restore position
            context.setFile(savedFile);
View Full Code Here

     */
    public static IRubyObject evalSimple(ThreadContext context, IRubyObject self, RubyString src, String file, int lineNumber) {
        // this is ensured by the callers
        assert file != null;

        Ruby runtime = src.getRuntime();
        String savedFile = context.getFile();
        int savedLine = context.getLine();

        // no binding, just eval in "current" frame (caller's frame)
        RubyString source = src.convertToString();
       
        DynamicScope evalScope = context.getCurrentScope().getEvalScope();
        evalScope.getStaticScope().determineModule();
       
        try {
            Node node = runtime.parseEval(source.getByteList(), file, evalScope, lineNumber);
           
            return node.interpret(runtime, context, self, Block.NULL_BLOCK);
        } catch (JumpException.BreakJump bj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
        } catch (StackOverflowError sfe) {
            throw runtime.newSystemStackError("stack level too deep");
        } finally {
            // restore position
            context.setFile(savedFile);
            context.setLine(savedLine);
        }
View Full Code Here

            stack[++stackTop] = args[i];
        }
        int ip = 0;
        int call_flags = -1;
        int cache_index = -1;
        Ruby runtime = context.getRuntime();
        IRubyObject recv;
        IRubyObject other;

        loop: while (ip < bytecodes.length) {
            int ix = ip;
            int code = bytecodes[ip++];
            /*
                System.err.print(RubiniusInstructions.NAMES[code] + " (" + code + ") ");
                if(RubiniusInstructions.ONE_INT[code]) {
                    System.err.print("[" + getInt(bytecodes, ip) + "] ");
                } else if(RubiniusInstructions.TWO_INT[code]) {
                    System.err.print("[" + getInt(bytecodes, ip) + ", " + getInt(bytecodes, ip+4) + "] ");
                }
                System.err.println("{" + ix + "}");

                for(int i=stackTop; i>=0; i--) {
                    System.err.println(" [" + i + "]=" + stack[i].callMethod(context, "inspect"));
                    }*/
            switch(code) {
            case RubiniusInstructions.NOOP: {
                break;
            }
            case RubiniusInstructions.ADD_METHOD: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                String name = literals[val].toString();
                RubyModule clzz = (RubyModule)stack[stackTop--];
                RubyArray method = (RubyArray)stack[stackTop--];
               
                Visibility visibility = context.getCurrentVisibility();
                if (name == "initialize" || visibility == Visibility.MODULE_FUNCTION) {
                    visibility = Visibility.PRIVATE;
                }
               
                RubiniusCMethod cmethod = new RubiniusCMethod(method);
               
                StaticScope staticScope = new LocalStaticScope(context.getCurrentScope().getStaticScope());
                staticScope.setVariables(new String[cmethod.locals]);
                staticScope.determineModule();

                RubiniusMethod newMethod = new RubiniusMethod(clzz, cmethod, staticScope, visibility);

                clzz.addMethod(name, newMethod);
   
                if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
                    clzz.getSingletonClass().addMethod(
                            name,
                            new WrapperMethod(clzz.getSingletonClass(), newMethod,
                                    Visibility.PUBLIC));
                    clzz.callMethod(context, "singleton_method_added", literals[val]);
                }
   
                if (clzz.isSingleton()) {
                    ((MetaClass) clzz).getAttached().callMethod(
                            context, "singleton_method_added", literals[val]);
                } else {
                    clzz.callMethod(context, "method_added", literals[val]);
                }
                stack[++stackTop] = method;
                break;
            }
            case RubiniusInstructions.META_PUSH_NEG_1: {
                stack[++stackTop] = RubyFixnum.minus_one(runtime);
                break;
            }
            case RubiniusInstructions.CHECK_ARGCOUNT: {
                int min = getInt(bytecodes, ip);
                ip += 4;
                int max = getInt(bytecodes, ip);
                ip += 4;

                if(args.length < min) {
                    throw runtime.newArgumentError("wrong # of arguments(" + args.length + " for " + min + ")");
                } else if(max>0 && args.length>max) {
                    throw runtime.newArgumentError("wrong # of arguments(" + args.length + " for " + max + ")");
                }
                break;
            }
            case RubiniusInstructions.META_PUSH_0: {
                stack[++stackTop] = RubyFixnum.zero(runtime);
                break;
            }
            case RubiniusInstructions.META_PUSH_1: {
                stack[++stackTop] = RubyFixnum.one(runtime);
                break;
            }
            case RubiniusInstructions.META_PUSH_2: {
                stack[++stackTop] = runtime.newFixnum(2);
                break;
            }
            case RubiniusInstructions.SET_LOCAL: {
                int local = getInt(bytecodes, ip);
                ip += 4;
                context.getCurrentScope().setValue(local,stack[stackTop],0);
                break;
            }
            case RubiniusInstructions.PUSH_LOCAL: {
                int local = getInt(bytecodes, ip);
                ip += 4;
                stack[++stackTop] = context.getCurrentScope().getValue(local,0);
                break;
            }
            case RubiniusInstructions.PUSH_NIL: {
                stack[++stackTop] = runtime.getNil();
                break;
            }
            case RubiniusInstructions.PUSH_TRUE: {
                stack[++stackTop] = runtime.getTrue();
                break;
            }
            case RubiniusInstructions.PUSH_FALSE: {
                stack[++stackTop] = runtime.getFalse();
                break;
            }
            case RubiniusInstructions.PUSH_SELF: {
                stack[++stackTop] = self;
                break;
            }
            case RubiniusInstructions.STRING_DUP: {
                stack[stackTop] = ((RubyString)stack[stackTop]).strDup(context.getRuntime());
                break;
            }
            case RubiniusInstructions.PUSH_LITERAL: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                stack[++stackTop] = literals[val];
                break;
            }
            case RubiniusInstructions.META_SEND_OP_LT: {
                IRubyObject t1 = stack[stackTop--];
                IRubyObject t2 = stack[stackTop--];
                if((t1 instanceof RubyFixnum) && (t1 instanceof RubyFixnum)) {
                    stack[++stackTop] = (((RubyFixnum)t1).getLongValue() < ((RubyFixnum)t2).getLongValue()) ? runtime.getTrue() : runtime.getFalse();
                } else {
                    stack[++stackTop] = t1.callMethod(context, MethodIndex.OP_LT, "<", t2);
                }
                break;
            }

            case RubiniusInstructions.META_SEND_OP_GT: {
                IRubyObject t1 = stack[stackTop--];
                IRubyObject t2 = stack[stackTop--];
                if((t1 instanceof RubyFixnum) && (t1 instanceof RubyFixnum)) {
                    stack[++stackTop] = (((RubyFixnum)t1).getLongValue() > ((RubyFixnum)t1).getLongValue()) ? runtime.getTrue() : runtime.getFalse();
                } else {
                    stack[++stackTop] = t1.callMethod(context, MethodIndex.OP_GT, ">", t2);
                }
                break;
            }

            case RubiniusInstructions.META_SEND_OP_PLUS: {
                IRubyObject t1 = stack[stackTop--];
                IRubyObject t2 = stack[stackTop--];
                if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
                    stack[++stackTop] = ((RubyFixnum)t1).op_plus(context, t2);
                } else {
                    stack[++stackTop] = t1.callMethod(context, MethodIndex.OP_PLUS, "+", t2);
                }
                break;
            }
            case RubiniusInstructions.META_SEND_OP_MINUS: {

                IRubyObject t1 = stack[stackTop--];
                IRubyObject t2 = stack[stackTop--];
                if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
                    stack[++stackTop] = ((RubyFixnum)t1).op_minus(context, t2);
                } else {
                    stack[++stackTop] = t1.callMethod(context, MethodIndex.OP_MINUS, "-", t2);
                }
                break;
            }
            case RubiniusInstructions.POP: {
                stackTop--;
                break;
            }
            case RubiniusInstructions.SET_CALL_FLAGS: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                call_flags = val;
                break;
            }
            case RubiniusInstructions.SET_CACHE_INDEX: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                cache_index = val;
                break;
            }
            case RubiniusInstructions.SEND_STACK: {
                int index = getInt(bytecodes, ip);
                ip += 4;
                int num_args = getInt(bytecodes, ip);
                ip += 4;
               
                String name = literals[index].toString();
                int ixi = MethodIndex.getIndex(name);
                recv = stack[stackTop--];
                IRubyObject[] argu = new IRubyObject[num_args];
                for(int i=0;i<num_args;i++) {
                    argu[i] = stack[stackTop--];
                }
                if((call_flags & 0x01) == 0x01) { //Functional
                    stack[++stackTop] = RuntimeHelpers.invoke(context, recv, name, argu, Block.NULL_BLOCK);
                } else {
                    stack[++stackTop] = RuntimeHelpers.invoke(context, recv, name, argu, CallType.NORMAL, Block.NULL_BLOCK);
                }
                break;
            }
            case RubiniusInstructions.GOTO_IF_FALSE: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                if(!stack[stackTop--].isTrue()) {
                    ip = val;
                }
                break;
            }
            case RubiniusInstructions.GOTO_IF_TRUE: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                if(stack[stackTop--].isTrue()) {
                    ip = val;
                }
                break;
            }
            case RubiniusInstructions.SWAP_STACK: {
                IRubyObject swap = stack[stackTop];
                stack[stackTop] = stack[stackTop-1];
                stack[stackTop-1] = swap;
                break;
            }
            case RubiniusInstructions.DUP_TOP: {
                stack[stackTop+1] = stack[stackTop];
                stackTop++;
                break;
            }
            case RubiniusInstructions.GOTO: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                ip = val;
                break;
            }
            case RubiniusInstructions.RET: {
                return stack[stackTop];
            }
            case RubiniusInstructions.PUSH_INT: {
                int val = getInt(bytecodes, ip);
                ip += 4;
                stack[++stackTop] = runtime.newFixnum(val);
                break;
            }
            case RubiniusInstructions.PUSH_CONST: {
                int index = getInt(bytecodes, ip);
                ip += 4;
View Full Code Here

            context.postScopedBody();
        }
    }
   
    public IRubyObject exec(ThreadContext context, IRubyObject self, Instruction[] bytecodes) {
        Ruby runtime = context.getRuntime();
       
        // Where this frames stack begins.
        int stackStart = stackTop;
        int ip = 0;
        IRubyObject other;

        yarvloop: while (ip < bytecodes.length) {
            //System.err.println("Executing: " + YARVInstructions.name(bytecodes[ip].bytecode));
            switch (bytecodes[ip].bytecode) {
            case YARVInstructions.NOP:
                break;
            case YARVInstructions.GETGLOBAL:
                push(runtime.getGlobalVariables().get(bytecodes[ip].s_op0));
                break;
            case YARVInstructions.SETGLOBAL:
                runtime.getGlobalVariables().set(bytecodes[ip].s_op0, pop());
                break;
            case YARVInstructions.GETLOCAL:
                push(context.getCurrentScope().getValue((int) bytecodes[ip].l_op0, 0));
                break;
            case YARVInstructions.SETLOCAL:
                context.getCurrentScope().setValue((int) bytecodes[ip].l_op0, pop(), 0);
                break;
            case YARVInstructions.GETINSTANCEVARIABLE:
                push(self.getInstanceVariables().fastGetInstanceVariable(bytecodes[ip].s_op0));
                break;
            case YARVInstructions.SETINSTANCEVARIABLE:
                self.getInstanceVariables().fastSetInstanceVariable(bytecodes[ip].s_op0, pop());
                break;
            case YARVInstructions.GETCLASSVARIABLE: {
                RubyModule rubyClass = context.getRubyClass();
                String name = bytecodes[ip].s_op0;
   
                if (rubyClass == null) {
                    push(self.getMetaClass().fastGetClassVar(name));
                } else if (!rubyClass.isSingleton()) {
                    push(rubyClass.fastGetClassVar(name));
                } else {
                    RubyModule module = (RubyModule)(((MetaClass)rubyClass).getAttached());

                    if (module != null) {
                        push(module.fastGetClassVar(name));
                    } else {
                        push(runtime.getNil());
                    }
                }
                break;
            }
            case YARVInstructions.SETCLASSVARIABLE: {
                RubyModule rubyClass = context.getCurrentScope().getStaticScope().getModule();
   
                if (rubyClass == null) {
                    rubyClass = self.getMetaClass();
                } else if (rubyClass.isSingleton()) {
                    rubyClass = (RubyModule)(((MetaClass)rubyClass).getAttached());
                }
   
                rubyClass.fastSetClassVar(bytecodes[ip].s_op0, pop());
                break;
            }
            case YARVInstructions.GETCONSTANT:
                push(context.getConstant(bytecodes[ip].s_op0));
                break;
            case YARVInstructions.SETCONSTANT:
                context.setConstantInCurrent(bytecodes[ip].s_op0, pop());
                runtime.incGlobalState();
                break;
            case YARVInstructions.PUTNIL:
                push(context.getRuntime().getNil());
                break;
            case YARVInstructions.PUTSELF:
                push(self);
                break;
            case YARVInstructions.PUTOBJECT:
                //System.out.println("PUTOBJECT: " + bytecodes[ip].o_op0);
                push(bytecodes[ip].o_op0);
                break;
            case YARVInstructions.PUTSTRING:
                push(context.getRuntime().newString(bytecodes[ip].s_op0));
                break;
            case YARVInstructions.CONCATSTRINGS: {
                StringBuilder concatter = new StringBuilder();
               
                for (int i = 0; i < bytecodes[ip].l_op0; i++) {
                    concatter.append(pop().toString());
                }
               
                push(runtime.newString(concatter.toString()));
                break;
            }
            case YARVInstructions.TOSTRING:
                IRubyObject top = peek();
                if (!(top instanceof RubyString)) {
                    set(top.callMethod(context, "to_s"));
                }
                break;
            case YARVInstructions.NEWARRAY:
                push(runtime.newArrayNoCopy(popArray(new IRubyObject[(int) bytecodes[ip].l_op0])));
                break;
            case YARVInstructions.DUPARRAY:
                push(bytecodes[ip].o_op0.dup());
                break;
            case YARVInstructions.NEWHASH:
                int hsize = (int)bytecodes[ip].l_op0;
                RubyHash h = RubyHash.newHash(runtime);
                IRubyObject v,k;
                for(int i = hsize; i>0; i -= 2) {
                    v = pop();
                    k = pop();
                    h.op_aset(context, k, v);
                }
                push(h);
                break;
            case YARVInstructions.PUTNOT:
                push(peek().isTrue() ? runtime.getFalse() : runtime.getTrue());
                break;
            case YARVInstructions.POP:
                pop();
                break;
            case YARVInstructions.DUP:
                push(peek());
                break;
            case YARVInstructions.DUPN:
                dupn((int) bytecodes[ip].l_op0);
                break;
            case YARVInstructions.SWAP:
                swap();
                break;
            case YARVInstructions.TOPN:
                topn((int) bytecodes[ip].l_op0);
                break;
            case YARVInstructions.SETN:
                setn((int) bytecodes[ip].l_op0, peek());
                break;
            case YARVInstructions.EMPTSTACK:
                stackTop = stackStart;
                break;
            case YARVInstructions.DEFINEMETHOD:
                RubyModule containingClass = context.getRubyClass();
   
                if (containingClass == null) {
                    throw runtime.newTypeError("No class to add method.");
                }

                String mname = bytecodes[ip].iseq_op.name;
                if (containingClass == runtime.getObject() && mname == "initialize") {
                    runtime.getWarnings().warn(ID.REDEFINING_DANGEROUS, "redefining Object#initialize may cause infinite loop", "Object#initialize");
                }
   
                Visibility visibility = context.getCurrentVisibility();
                if (mname == "initialize" || visibility == Visibility.MODULE_FUNCTION) {
                    visibility = Visibility.PRIVATE;
                }
               
                if (containingClass.isSingleton()) {
                    IRubyObject attachedObject = ((MetaClass) containingClass).getAttached();
                   
                    if (attachedObject instanceof RubyFixnum || attachedObject instanceof RubySymbol) {
                        throw runtime.newTypeError("can't define singleton method \"" +
                                mname + "\" for " + attachedObject.getType());
                    }
                }

                StaticScope sco = new LocalStaticScope(null);
                sco.setVariables(bytecodes[ip].iseq_op.locals);
                YARVMethod newMethod = new YARVMethod(containingClass, bytecodes[ip].iseq_op, sco, visibility);

                containingClass.addMethod(mname, newMethod);
   
                if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
                    RubyModule singleton = containingClass.getSingletonClass();
                    singleton.addMethod(mname, new WrapperMethod(singleton, newMethod, Visibility.PUBLIC));
                    containingClass.callMethod(context, "singleton_method_added", runtime.fastNewSymbol(mname));
                }
   
                // 'class << state.self' and 'class << obj' uses defn as opposed to defs
                if (containingClass.isSingleton()) {
                    ((MetaClass) containingClass).getAttached().callMethod(context,
                            "singleton_method_added", runtime.fastNewSymbol(mname));
                } else {
                    containingClass.callMethod(context, "method_added", runtime.fastNewSymbol(mname));
                }
                push(runtime.getNil());
                runtime.incGlobalState();
                break;
            case YARVInstructions.SEND: {
                ip = send(runtime, context, self, bytecodes, stackStart, ip);
                break;
            }
            case YARVInstructions.LEAVE:
                break yarvloop;
            case YARVInstructions.JUMP:
                ip = (int) bytecodes[ip].l_op0;
                continue yarvloop;
            case YARVInstructions.BRANCHIF:
                ip = pop().isTrue() ? (int) bytecodes[ip].l_op0 : ip + 1;
                continue yarvloop;
            case YARVInstructions.BRANCHUNLESS: {
                ip = !pop().isTrue() ? (int) bytecodes[ip].l_op0 : ip + 1;
                continue yarvloop;
            }
            case YARVInstructions.GETINLINECACHE:
                if(bytecodes[ip].l_op1 == runtime.getGlobalState()) {
                    push(bytecodes[ip].o_op0);
                    ip = (int) bytecodes[ip].l_op0;
                    continue yarvloop;
                }
                break;
            case YARVInstructions.ONCEINLINECACHE:
                if(bytecodes[ip].l_op1 > 0) {
                    push(bytecodes[ip].o_op0);
                    ip = (int) bytecodes[ip].l_op0;
                    continue yarvloop;
                }
                break;
            case YARVInstructions.SETINLINECACHE:
                int we = (int)bytecodes[ip].l_op0;
                bytecodes[we].o_op0 = peek();
                bytecodes[we].l_op1 = runtime.getGlobalState();
                break;
            case YARVInstructions.OPT_PLUS:
                op_plus(runtime, context, pop(), pop());
                break;
            case YARVInstructions.OPT_MINUS:
                op_minus(runtime, context, pop(), pop());
                break;
            case YARVInstructions.OPT_MULT:
                other = pop();
                push(pop().callMethod(context,MethodIndex.OP_TIMES, "*", other));
                break;
            case YARVInstructions.OPT_DIV:
                other = pop();
                push(pop().callMethod(context, "/", other));
                break;
            case YARVInstructions.OPT_MOD:
                other = pop();
                push(pop().callMethod(context,"%",other));
                break;
            case YARVInstructions.OPT_EQ:
                other = pop();
                push(pop().callMethod(context,MethodIndex.EQUALEQUAL, "==", other));
                break;
            case YARVInstructions.OPT_LT:
                op_lt(runtime, context, pop(), pop());
                break;
            case YARVInstructions.OPT_LE:
                other = pop();
                push(pop().callMethod(context,MethodIndex.OP_LE, "<=", other));
                break;
            case YARVInstructions.OPT_LTLT:
                other = pop();
                push(pop().callMethod(context,MethodIndex.OP_LSHIFT, "<<", other));
                break;
            case YARVInstructions.OPT_AREF:
                other = pop();
                push(pop().callMethod(context,MethodIndex.AREF, "[]",other));
                break;
            case YARVInstructions.OPT_ASET:  {
                //YARV will never emit this, for some reason.
                IRubyObject value = pop();
                other = pop();
                push(RuntimeHelpers.invoke(context, pop(), "[]=", other,value));
                break;
            }
            case YARVInstructions.OPT_LENGTH:
                push(pop().callMethod(context, "length"));
                break;
            case YARVInstructions.OPT_SUCC:
                push(pop().callMethod(context, "succ"));
                break;
            case YARVInstructions.OPT_REGEXPMATCH1:
                push(bytecodes[ip].o_op0.callMethod(context, "=~", peek()));
                break;
            case YARVInstructions.OPT_REGEXPMATCH2:
                other = pop();
                push(pop().callMethod(context, "=~", other));
                break;
            case YARVInstructions.ANSWER:
                push(runtime.newFixnum(42));
                break;
            case YARVInstructions.GETSPECIAL:
            case YARVInstructions.SETSPECIAL:
            case YARVInstructions.GETDYNAMIC:
            case YARVInstructions.SETDYNAMIC:
View Full Code Here

public class IOJavaAddons {
    @JRubyMethod
    public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) {
        RubyIO io = (RubyIO)self;
        Ruby runtime = context.getRuntime();

        try {
            io.getOpenFile().checkReadable(context.getRuntime());
        } catch (PipeException pe) {
            throw runtime.newErrnoEPIPEError();
        } catch (IOException ex) {
            throw runtime.newIOErrorFromException(ex);
        } catch (BadDescriptorException ex) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException e) {
            throw runtime.newErrnoEINVALError();
        }
       
        return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), io.getInStream());
    }
View Full Code Here

TOP

Related Classes of org.jruby.Ruby

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.