Package org.jruby.compiler.ir.instructions

Examples of org.jruby.compiler.ir.instructions.CopyInstr


    }

    public Operand buildMultipleAsgn(MultipleAsgnNode multipleAsgnNode, IRScope s) {
        Operand  values = build(multipleAsgnNode.getValueNode(), s);
        Variable ret = s.getNewTemporaryVariable();
        s.addInstr(new CopyInstr(ret, values));
        buildMultipleAsgnAssignment(multipleAsgnNode, s, ret);
        return ret;
    }
View Full Code Here


        s.addInstr(new CallInstr(elt, new MethAddr("[]"), array, new Operand[] { index }, null));
        s.addInstr(new IsTrueInstr(flag, elt));
        s.addInstr(new BEQInstr(flag, BooleanLiteral.TRUE, l));
        Operand value = build(opElementAsgnNode.getValueNode(), s);
        s.addInstr(new CallInstr(elt, new MethAddr("[]="), array, new Operand[] { index, value }, null));
        s.addInstr(new CopyInstr(elt, value));
        s.addInstr(new LABEL_Instr(l));
        return elt;
    }
View Full Code Here

        s.addInstr(new CallInstr(elt, new MethAddr("[]"), array, new Operand[] { index }, null));
        s.addInstr(new IsTrueInstr(flag, elt));
        s.addInstr(new BEQInstr(flag, BooleanLiteral.FALSE, l));
        Operand value = build(opElementAsgnNode.getValueNode(), s);
        s.addInstr(new CallInstr(elt, new MethAddr("[]="), array, new Operand[] { index, value }, null));
        s.addInstr(new CopyInstr(elt, value));
        s.addInstr(new LABEL_Instr(l));
        return elt;
    }
View Full Code Here

            return build(orNode.getSecondNode(), m);
        } else {
            Variable ret = m.getNewTemporaryVariable();
            Label    l   = m.getNewLabel();
            Operand  v1  = build(orNode.getFirstNode(), m);
            m.addInstr(new CopyInstr(ret, v1));
            m.addInstr(new BEQInstr(v1, BooleanLiteral.TRUE, l));
            Operand  v2  = build(orNode.getSecondNode(), m);
            m.addInstr(new CopyInstr(ret, v2));
            m.addInstr(new LABEL_Instr(l));
            return ret;
        }
    }
View Full Code Here

            m.addInstr(new LABEL_Instr(elseLabel));
            tmp = build(rescueNode.getElseNode(), m);
        }

        if (tmp != U_NIL) {
            m.addInstr(new CopyInstr(rv, tmp));

            // No explicit return from the protected body
            // - If we dont have any ensure blocks, simply jump to the end of the rescue block
            // - If we do, get the innermost ensure block, set up the return address to the end of the ensure block, and go execute the ensure code.
            if (noEnsure) {
View Full Code Here

        // Caught exception case -- build rescue body
        Node realBody = skipOverNewlines(m, rescueBodyNode.getBodyNode());
        Operand x = build(realBody, m);
        if (x != U_NIL) { // can be U_NIL if the rescue block has an explicit return
            m.addInstr(new CopyInstr(rv, x));
            // Jump to end of rescue block since we've caught and processed the exception
            if (!_ensureBlockStack.empty()) {
                EnsureBlockInfo ebi = _ensureBlockStack.peek();
                m.addInstr(new SET_RETADDR_Instr(ebi.returnAddr, endLabel));
                m.addInstr(new JumpInstr(ebi.start));
View Full Code Here

            // So, capture the result of the body so that it can be returned.
            Variable whileResult = s.getNewTemporaryVariable();
            if (bodyNode != null) {
                Operand v = build(bodyNode, s);
                if (v != U_NIL) {
                    s.addInstr(new CopyInstr((Variable)whileResult, v));
                }
                else {
                    // If the body of the while had an explicit return, the value in 'whileResult' will never be used.
                    // So, we dont need to set it to anything.  We can leave it undefined!
                }
View Full Code Here

                recordSimplification(res, val, valueMap, simplificationMap);

                if (val instanceof BreakResult) {
                    BreakResult br = (BreakResult)val;
                    i.markDead();
                    instrs.add(new CopyInstr(res, br._result));
                    instrs.add(new JumpInstr(br._jumpTarget));
                }
            }
            // Optimize some core class method calls for constant values
            else if (iop.isCall()) {
                val = null;
                CallInstr call = (CallInstr) i;
                Operand    r    = call.getReceiver();
                // SSS FIXME: r can be null for ruby/jruby internal call instructions!
                // Cannot optimize them as of now.
                if (r != null) {
                    // If 'r' is not a constant, it could actually be a compound value!
                    // Look in our value map to see if we have a simplified value for the receiver.
                    if (!r.isConstant()) {
                        Operand v = valueMap.get(r);
                        if (v != null)
                            r = v;
                    }

                    // Check if we can optimize this call based on the receiving method and receiver type
                    // Use the simplified receiver!
                    IRMethod rm = call.getTargetMethodWithReceiver(r);
                    if (rm != null) {
                        IRModule rc = rm.getDefiningIRModule();
                        if (rc != null) { // TODO: I am fairly sure I am wallpapering
                            if (rc.isCoreClass("Fixnum")) {
                                Operand[] args = call.getOperands();
                                if (args[2].isConstant()) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Fixnum) r).computeValue(rm.getName(), (Constant) args[2]);
                                }
                            } else if (rc.isCoreClass("Float")) {
                                Operand[] args = call.getOperands();
                                if (args[2].isConstant()) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Float) r).computeValue(rm.getName(), (Constant) args[2]);
                                }
                            } else if (rc.isCoreClass("Array")) {
                                Operand[] args = call.getOperands();
                                if (args[2] instanceof Fixnum && (rm.getName() == "[]")) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Array) r).fetchCompileTimeArrayElement(((Fixnum) args[2]).value.intValue(), false);
                                }
                            }
                        }

                        // If we got a simplified value, mark the call dead and insert a copy in its place!
                        if (val != null) {
                            i.markDead();
                            instrs.add(new CopyInstr(res, val));
                            recordSimplification(res, val, valueMap, simplificationMap);
                        }
                    }
                }
            }
View Full Code Here

        for (ListIterator<Instr> it = ((ArrayList<Instr>)_instrs).listIterator(); it.hasNext(); ) {
            Instr i = it.next();
            if (i instanceof ClosureReturnInstr) {
                // Replace the closure return receive with a simple copy
                it.set(new CopyInstr(yieldResult, ((ClosureReturnInstr)i).getArg()));
            }
            else if (i instanceof ReceiveClosureArgInstr) {
                Operand closureArg;
                ReceiveClosureArgInstr rcai = (ReceiveClosureArgInstr)i;
                int argIndex = rcai.argIndex;
                boolean restOfArgs = rcai.restOfArgArray;
                if (argIndex < yieldArgs.length) {
                    closureArg = yieldArgs[argIndex].cloneForInlining(ii);
                }
                else if (argIndex >= yieldArgs.length) {
                    closureArg = new Array();
                }
                else {
                    Operand[] tmp = new Operand[yieldArgs.length - argIndex];
                    for (int j = argIndex; j < yieldArgs.length; j++)
                        tmp[j-argIndex] = yieldArgs[j].cloneForInlining(ii);

                    closureArg = new Array(tmp);
                }

                // Replace the arg receive with a simple copy
                it.set(new CopyInstr(rcai.result, closureArg));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jruby.compiler.ir.instructions.CopyInstr

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.