Package org.jruby.compiler.ir.operands

Examples of org.jruby.compiler.ir.operands.StringLiteral


        super((IRScope) null, null, sourceName, staticScope);
        dummyClass = new IRClass(this, null, null, "__SCRIPT_ROOT__", staticScope);
    }

    public Operand getFileName() {
        return new StringLiteral(getName());
    }
View Full Code Here


    }

    private Operand buildAttrAssign(final AttrAssignNode attrAssignNode, IRScope s) {
        List<Operand> args = setupCallArgs(attrAssignNode.getArgsNode(), s);
        Operand obj = build(attrAssignNode.getReceiverNode(), s);
        s.addInstr(new AttrAssignInstr(obj, new StringLiteral(attrAssignNode.getName()), args.toArray(new Operand[args.size()])));
        return args.get(args.size()-1);
    }
View Full Code Here

    public Operand buildAttrAssignAssignment(Node node, IRScope s, Operand value) {
        final AttrAssignNode attrAssignNode = (AttrAssignNode) node;
        List<Operand> args = setupCallArgs(attrAssignNode.getArgsNode(), s);
        Operand obj = build(attrAssignNode.getReceiverNode(), s);
        s.addInstr(new AttrAssignInstr(obj, new StringLiteral(attrAssignNode.getName()), args.toArray(new Operand[args.size()]), value));
        return value;
    }
View Full Code Here

        return buildGetDefinitionBase(((DefinedNode) node).getExpressionNode(), m);
    }

    public Operand buildGetArgumentDefinition(final Node node, IRScope m, String type) {
        if (node == null) {
            return new StringLiteral(type);
        } else {
            Label failLabel = m.getNewLabel();
            Label doneLabel = m.getNewLabel();
            Variable rv = m.getNewTemporaryVariable();
            if (node instanceof ArrayNode) {
                for (int i = 0; i < ((ArrayNode) node).size(); i++) {
                    Node iterNode = ((ArrayNode) node).get(i);
                    Operand def = buildGetDefinition(iterNode, m);
                    m.addInstr(new BEQInstr(def, Nil.NIL, failLabel));
                }
            } else {
                Operand def = buildGetDefinition(node, m);
                m.addInstr(new BEQInstr(def, Nil.NIL, failLabel));
            }
            m.addInstr(new CopyInstr(rv, new StringLiteral(type)));
            m.addInstr(new JumpInstr(doneLabel));
            m.addInstr(new LABEL_Instr(failLabel));
            m.addInstr(new CopyInstr(rv, Nil.NIL));
            m.addInstr(new LABEL_Instr(doneLabel));
            return rv;
View Full Code Here

    private void buildDefinitionCheck(IRScope s, Variable tmpVar, String definedReturnValue) {
        Label undefLabel = s.getNewLabel();
        Label defLabel   = s.getNewLabel();
        s.addInstr(new BEQInstr(tmpVar, BooleanLiteral.FALSE, undefLabel));
        s.addInstr(new CopyInstr(tmpVar, new StringLiteral(definedReturnValue)));
        s.addInstr(new JumpInstr(defLabel));
        s.addInstr(new LABEL_Instr(undefLabel));
        s.addInstr(new CopyInstr(tmpVar, Nil.NIL));
        s.addInstr(new LABEL_Instr(defLabel));
    }
View Full Code Here

            case OPASGNNODE:
            case OPASGNANDNODE:
            case OPASGNORNODE:
            case OPELEMENTASGNNODE:
            case INSTASGNNODE: // simple assignment cases
                return new StringLiteral("assignment");
            case DVARNODE: 
                return new StringLiteral("local-variable(in-block)");
            case FALSENODE:
                return new StringLiteral("false");
            case TRUENODE:
                return new StringLiteral("true");
            case LOCALVARNODE:
                return new StringLiteral("local-variable");
            case MATCH2NODE:
            case MATCH3NODE:
                return new StringLiteral("method");
            case NILNODE:
                return new StringLiteral("nil");
            case SELFNODE:
                return new StringLiteral("self");
            case VCALLNODE:
            {
                Variable tmp = s.getNewTemporaryVariable();
                s.addInstr(new JRubyImplCallInstr(tmp, new MethAddr("getMetaClass"), getSelf(s), NO_ARGS));

                Variable tmpVar = s.getNewTemporaryVariable();
                StringLiteral mName = new StringLiteral(((VCallNode) node).getName());
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("isMethodBound"), tmp, new Operand[]{mName, BooleanLiteral.FALSE}));
                buildDefinitionCheck(s, tmpVar, "method");
                return tmpVar;
            }
            case CONSTNODE:
            {
                Variable tmpVar = s.getNewTemporaryVariable();
                StringLiteral mName = new StringLiteral(((ConstNode) node).getName());
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("threadContext_getConstantDefined"), null, new Operand[]{mName}));
                buildDefinitionCheck(s, tmpVar, "constant");
                return tmpVar;
            }
            case GLOBALVARNODE:
            {
                Variable tmpVar = s.getNewTemporaryVariable();
                StringLiteral mName = new StringLiteral(((GlobalVarNode) node).getName());
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("runtime_isGlobalDefined"), null, new Operand[]{mName}));
                buildDefinitionCheck(s, tmpVar, "global-variable");
                return tmpVar;
            }
            case INSTVARNODE:
            {
                Variable tmpVar = s.getNewTemporaryVariable();
                StringLiteral mName = new StringLiteral(((GlobalVarNode) node).getName());
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("self_hasInstanceVariable"), getSelf(s), new Operand[]{mName}));
                buildDefinitionCheck(s, tmpVar, "instance-variable");
                return tmpVar;
            }
            case YIELDNODE:
        {
                Variable tmpVar = s.getNewTemporaryVariable();
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("block_isGiven"), null, NO_ARGS));
                buildDefinitionCheck(s, tmpVar, "yield");
                return tmpVar;
            }
            case FCALLNODE:
            {
                Variable tmpVar = s.getNewTemporaryVariable();
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("getMetaClass"), getSelf(s), NO_ARGS));
                Label undefLabel = s.getNewLabel();
                Label defLabel   = s.getNewLabel();
                StringLiteral mName = new StringLiteral(((FCallNode)node).getName());
                Instr callInstr  = new JRubyImplCallInstr(tmpVar, new MethAddr("isMethodBound"), tmpVar, new Operand[]{mName, BooleanLiteral.FALSE});
                s.addInstr(callInstr);
                s.addInstr(new BEQInstr(tmpVar, BooleanLiteral.FALSE, undefLabel));
                s.addInstr(new CopyInstr(tmpVar, buildGetArgumentDefinition(((FCallNode) node).getArgsNode(), s, "method")));
                s.addInstr(new JumpInstr(defLabel));
                s.addInstr(new LABEL_Instr(undefLabel));
                s.addInstr(new CopyInstr(tmpVar, Nil.NIL));
                s.addInstr(new LABEL_Instr(defLabel));
                return tmpVar;
            }
            case COLON3NODE:
            case COLON2NODE:
            {
                final Colon3Node iVisited = (Colon3Node) node;
                final String name = iVisited.getName();

                // store previous exception for restoration if we rescue something
                Variable errInfo = s.getNewTemporaryVariable();
                s.addInstr(new JRubyImplCallInstr(errInfo, new MethAddr("threadContext_stashErrInfo"), null, NO_ARGS));

                CodeBlock protectedCode = new CodeBlock() {
                    public Object run(Object[] args) {
                        IRScope  m      = (IRScope)args[0];
                        Node     n      = (Node)args[1];
                        String   name   = (String)args[2];
                        Variable tmpVar = m.getNewTemporaryVariable();
                        Operand v;
                        if (n instanceof Colon2Node) {
                            v = build(((Colon2Node) n).getLeftNode(), m);
                        } else {
                            m.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("runtime_getObject"), null, NO_ARGS));
                            v = tmpVar;
                        }
                        m.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("getDefinedConstantOrBoundMethod"), null, new Operand[]{v, new StringLiteral(name)}));
                        return tmpVar;
                    }
                };

                // rescue block
View Full Code Here

        return MetaObject.create(closure);
    }

    public Operand buildLiteral(LiteralNode literalNode, IRScope s) {
        return new StringLiteral(literalNode.getName());
    }
View Full Code Here

        s.addInstr(new JumpInstr((s instanceof IRClosure) ? ((IRClosure)s).startLabel : s.getCurrentLoop().iterStartLabel));
        return Nil.NIL;
    }

    public Operand buildRegexp(RegexpNode reNode, IRScope m) {
        return new Regexp(new StringLiteral(reNode.getValue()), reNode.getOptions());
    }
View Full Code Here

        s.addInstr(new ThreadPollInstr());

        // Jump back to the innermost rescue block
        // We either find it, or we add code to throw a runtime exception
        if (_rescueBlockLabelStack.empty()) {
            StringLiteral exc = new StringLiteral("retry found outside of rescue clause!");
            s.addInstr(new THROW_EXCEPTION_Instr(exc));
        }
        else {
            s.addInstr(new JumpInstr(_rescueBlockLabelStack.peek()));
        }
View Full Code Here

    public Operand buildSplat(SplatNode splatNode, IRScope s) {
        return new Splat(build(splatNode.getValue(), s));
    }

    public Operand buildStr(StrNode strNode, IRScope s) {
        return new StringLiteral(strNode.getValue());
    }
View Full Code Here

TOP

Related Classes of org.jruby.compiler.ir.operands.StringLiteral

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.