Package org.jruby.ast

Examples of org.jruby.ast.Node


        ArrayNode arrayNode = (ArrayNode) node;
       
        if (expr) {
            ArrayCallback callback = new ArrayCallback() {
                public void nextValue(BodyCompiler context, Object sourceArray, int index) {
                    Node node = (Node) ((Object[]) sourceArray)[index];
                    compile(node, context, true);
                }
            };

            List<Node> childNodes = arrayNode.childNodes();

            if (isListAllLiterals(arrayNode)) {
                context.createNewLiteralArray(childNodes.toArray(), callback, arrayNode.isLightweight());
            } else {
                context.createNewArray(childNodes.toArray(), callback, arrayNode.isLightweight());
            }
        } else {
            if (isListAllLiterals(arrayNode)) {
                // do nothing, no observable effect
            } else {
                for (Iterator<Node> iter = arrayNode.childNodes().iterator(); iter.hasNext();) {
                    Node nextNode = iter.next();
                    compile(nextNode, context, false);
                }
            }
        }
    }
View Full Code Here


    public void compileBlock(Node node, BodyCompiler context, boolean expr) {
        BlockNode blockNode = (BlockNode) node;

        for (Iterator<Node> iter = blockNode.childNodes().iterator(); iter.hasNext();) {
            Node n = iter.next();

            compile(n, context, iter.hasNext() ? false : expr);
        }
    }
View Full Code Here

                }
            }
        }

        if (argsCallback != null && argsCallback.getArity() == 1) {
            Node argument = callNode.getArgsNode().childNodes().get(0);
            if (MethodIndex.hasFastOps(name)) {
                if (argument instanceof FixnumNode) {
                    context.getInvocationCompiler().invokeBinaryFixnumRHS(name, receiverCallback, ((FixnumNode)argument).getValue());
                    if (!expr) context.consumeCurrentValue();
                    return;
View Full Code Here

        }
        return false;
    }

    private boolean compileTrivialCall(String name, DynamicMethod method, int generation, BodyCompiler context, boolean expr) {
        Node simpleBody = null;
        if (method instanceof InterpretedMethod) {
            InterpretedMethod target = (InterpretedMethod)method;
            simpleBody = target.getBodyNode();
            while (simpleBody instanceof NewlineNode) simpleBody = ((NewlineNode)simpleBody).getNextNode();
        }

        if (method instanceof DefaultMethod) {
            DefaultMethod target = (DefaultMethod)method;
            simpleBody = target.getBodyNode();
            while (simpleBody instanceof NewlineNode) simpleBody = ((NewlineNode)simpleBody).getNextNode();
        }

        if (method instanceof JittedMethod) {
            DefaultMethod target = (DefaultMethod)((JittedMethod)method).getRealMethod();
            simpleBody = target.getBodyNode();
            while (simpleBody instanceof NewlineNode) simpleBody = ((NewlineNode)simpleBody).getNextNode();
        }

        if (simpleBody != null) {
            switch (simpleBody.getNodeType()) {
            case SELFNODE:
            case INSTVARNODE:
            case NILNODE:
            case FIXNUMNODE:
            case FLOATNODE:
            case STRNODE:
            case BIGNUMNODE:
            case FALSENODE:
            case TRUENODE:
            case SYMBOLNODE:
            case XSTRNODE:
                final Node simpleBodyFinal = simpleBody;
                context.getInvocationCompiler().invokeTrivial(name, generation, new CompilerCallback() {
                    public void call(BodyCompiler context) {
                        compile(simpleBodyFinal, context, true);
                    }
                });
View Full Code Here

        RubyClass implClass = (RubyClass)method.getImplementationClass();
        Map<Class, Map<String, String>> typeIntrinsics = Intrinsics.get(implClass.getReifiedClass());
        if (typeIntrinsics != null) {
            if (argsCallback != null && argsCallback.getArity() == 1) {
                Node argument = callNode.getArgsNode().childNodes().get(0);
                if (argument instanceof FixnumNode) {
                    Map<String, String> typeLongIntrinsics = typeIntrinsics.get(FixnumNode.class);
                    if (typeLongIntrinsics != null && typeLongIntrinsics.containsKey(name)) {
                        context.getInvocationCompiler().invokeFixnumLong(name, generation, receiverCallback, typeLongIntrinsics.get(name), ((FixnumNode)argument).getValue());
                        return true;
View Full Code Here

        // aggregate when nodes into a list, unfortunately, this is no
        List<Node> cases = caseNode.getCases().childNodes();

        // last node, either !instanceof WhenNode or null, is the else
        Node elseNode = caseNode.getElseNode();

        compileWhen(caseNode.getCaseNode(), cases, elseNode, context, expr, hasCase);
    }
View Full Code Here

    }

    public void compileClass(Node node, BodyCompiler context, boolean expr) {
        final ClassNode classNode = (ClassNode) node;

        final Node superNode = classNode.getSuperNode();

        final Node cpathNode = classNode.getCPath();

        CompilerCallback superCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        compile(superNode, context, true);
                    }
                };
        if (superNode == null) {
            superCallback = null;
        }

        CompilerCallback bodyCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        boolean oldIsAtRoot = isAtRoot;
                        isAtRoot = false;
                        if (classNode.getBodyNode() != null) {
                            compile(classNode.getBodyNode(), context, true);
                        } else {
                            context.loadNil();
                        }
                        isAtRoot = oldIsAtRoot;
                    }
                };

        CompilerCallback pathCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        if (cpathNode instanceof Colon2Node) {
                            Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
                            if (leftNode != null) {
                                if (leftNode instanceof NilNode) {
                                    context.raiseTypeError("No outer class");
                                } else {
                                    compile(leftNode, context, true);
View Full Code Here

    }

    public void compileConstDecl(Node node, BodyCompiler context, boolean expr) {
        // TODO: callback for value would be more efficient, but unlikely to be a big cost (constants are rarely assigned)
        ConstDeclNode constDeclNode = (ConstDeclNode) node;
        Node constNode = constDeclNode.getConstNode();

        if (constNode == null) {
            compile(constDeclNode.getValueNode(), context,true);

            context.assignConstantInCurrent(constDeclNode.getName());
        } else if (constNode.getNodeType() == NodeType.COLON2NODE) {
            compile(((Colon2Node) constNode).getLeftNode(), context,true);
            compile(constDeclNode.getValueNode(), context,true);

            context.assignConstantInModule(constDeclNode.getName());
        } else {// colon3, assign in Object
View Full Code Here

    }

    public void compileConstDeclAssignment(Node node, BodyCompiler context, boolean expr) {
        // TODO: callback for value would be more efficient, but unlikely to be a big cost (constants are rarely assigned)
        ConstDeclNode constDeclNode = (ConstDeclNode) node;
        Node constNode = constDeclNode.getConstNode();

        if (constNode == null) {
            context.assignConstantInCurrent(constDeclNode.getName());
        } else if (constNode.getNodeType() == NodeType.COLON2NODE) {
            compile(((Colon2Node) constNode).getLeftNode(), context,true);
            context.swapValues();
            context.assignConstantInModule(constDeclNode.getName());
        } else {// colon3, assign in Object
            context.assignConstantInObject(constDeclNode.getName());
View Full Code Here

     * processing the RubyArray into a proper form (only to then not do anythign with it).  A
     * secondary benefit is that a simple boolean seems to optimize by hotspot much faster
     * than the zero arg assigner.
     */
    private void assignerFor(IterNode iter) {
        Node varNode = iter.getVarNode();
        Node block = iter.getBlockVarNode();
        boolean hasBlock = block != null;

        if (varNode == null || varNode instanceof ZeroArgNode) { // No argument blocks
            noargblock = !hasBlock;
            assigner = hasBlock ? new Pre0Rest0Post0BlockAssigner(block) :
                new Pre0Rest0Post0Assigner();
        } else if (varNode instanceof MultipleAsgnNode) {
            MultipleAsgnNode masgn = (MultipleAsgnNode) varNode;
            int preCount = masgn.getPreCount();
            boolean isRest = masgn.getRest() != null;
            Node rest = masgn.getRest();
            ListNode pre = masgn.getPre();
            noargblock = false;

            switch(preCount) {
                case 0// Not sure if this is actually possible, but better safe than sorry
View Full Code Here

TOP

Related Classes of org.jruby.ast.Node

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.