Package org.jruby.ast

Examples of org.jruby.ast.Node


                    BranchCallback setup = new BranchCallback() {

                                public void branch(BodyCompiler context) {
                                    if (iVisited instanceof Colon2Node) {
                                        final Node leftNode = ((Colon2Node) iVisited).getLeftNode();
                                        compile(leftNode, context);
                                    } else {
                                        context.loadObject();
                                    }
                                }
View Full Code Here


        if (opt > 0) {
            optionalGiven = new ArrayCallback() {

                        public void nextValue(BodyCompiler context, Object object, int index) {
                            Node optArg = ((ListNode) object).get(index);

                            compileAssignment(optArg, context);
                        }
                    };
            optionalNotGiven = new ArrayCallback() {

                        public void nextValue(BodyCompiler context, Object object, int index) {
                            Node optArg = ((ListNode) object).get(index);

                            compile(optArg, context);
                        }
                    };
        }
View Full Code Here

    }

    public void compileModule(Node node, BodyCompiler context) {
        final ModuleNode moduleNode = (ModuleNode) node;

        final Node cpathNode = moduleNode.getCPath();

        CompilerCallback bodyCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        if (moduleNode.getBodyNode() != null) {
                            compile(moduleNode.getBodyNode(), context);
                        }
                        context.loadNil();
                    }
                };

        CompilerCallback pathCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        if (cpathNode instanceof Colon2Node) {
                            Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
                            if (leftNode != null) {
                                compile(leftNode, context);
                            } else {
                                context.loadNil();
                            }
View Full Code Here

        ArrayCallback headAssignCallback = new ArrayCallback() {

                    public void nextValue(BodyCompiler context, Object sourceArray,
                            int index) {
                        ListNode headNode = (ListNode) sourceArray;
                        Node assignNode = headNode.get(index);

                        // perform assignment for the next node
                        compileAssignment(assignNode, context);
                    }
                };

        // head items for which we've run out of assignable elements
        ArrayCallback headNilCallback = new ArrayCallback() {

                    public void nextValue(BodyCompiler context, Object sourceArray,
                            int index) {
                        ListNode headNode = (ListNode) sourceArray;
                        Node assignNode = headNode.get(index);

                        // perform assignment for the next node
                        context.loadNil();
                        compileAssignment(assignNode, context);
                    }
                };

        CompilerCallback argsCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        Node argsNode = multipleAsgnNode.getArgsNode();
                        if (argsNode instanceof StarNode) {
                        // done processing args
                        } else {
                            // assign to appropriate variable
                            compileAssignment(argsNode, context);
View Full Code Here

    public void compileRescueBody(Node node, BodyCompiler context) {
        final RescueBodyNode rescueBodyNode = (RescueBodyNode) node;

        context.loadException();

        Node exceptionList = rescueBodyNode.getExceptionNodes();
        if (exceptionList == null) {
            context.loadClass("StandardError");
            context.createObjectArray(1);
        } else {
            compileArguments(exceptionList, context);
View Full Code Here

    }

    public void compileJavaRescueBody(Node node, BodyCompiler context) {
        final RescueBodyNode rescueBodyNode = (RescueBodyNode) node;

        Node exceptionList = rescueBodyNode.getExceptionNodes();
        if (exceptionList == null) {
            if (rescueBodyNode.getOptRescueNode() != null) {
                compileJavaRescueBody(rescueBodyNode.getOptRescueNode(), context);
            } else {
                context.rethrowException();
View Full Code Here

        context.startScript(rootNode.getStaticScope());

        // create method for toplevel of script
        BodyCompiler methodCompiler = context.startMethod("__file__", "__file__", null, rootNode.getStaticScope(), inspector);

        Node nextNode = rootNode.getBodyNode();
        if (nextNode != null) {
            if (nextNode.nodeId == NodeType.BLOCKNODE) {
                // it's a multiple-statement body, iterate over all elements in turn and chain if it get too long
                BlockNode blockNode = (BlockNode) nextNode;
View Full Code Here

        ArrayNode arrayNode = (ArrayNode) node;

        ArrayCallback callback = new ArrayCallback() {

                    public void nextValue(BodyCompiler context, Object sourceArray, int index) {
                        Node node = (Node) ((Object[]) sourceArray)[index];
                        compile(node, context);
                    }
                };

        context.setLinePosition(arrayNode.getPosition());
View Full Code Here

            }

          // See eval todo about why this is commented out
            //runtime.setPosition(file, line);

            Node node = runtime.parseEval(file, funcBody.toString(), null, 0);
            IRubyObject result = node.interpret(runtime, context, runtime.getTopSelf(), Block.NULL_BLOCK);
            return JavaEmbedUtils.rubyToJava(runtime, result, Object.class);
        } catch (StackOverflowError sfe) {
            throw runtime.newSystemStackError("stack level too deep");
        } finally {
            context.postBsfApply();
View Full Code Here

                }
                break compileLoop;
            case HASHNODE:
                LinkAnchor list = DECL_ANCHOR();
                long size = 0;
                Node lnode = ((HashNode)node).getListNode();
                if(lnode.childNodes().size()>0) {
                    compile_array(list, lnode, false);
                    size = ((Insn)POP_ELEMENT(list)).i.l_op0;
                    ADD_SEQ(ret, list);
                }

                ADD_INSN1(ret, nd_line(node), YARVInstructions.NEWHASH, size);

                if(poped) {
                    ADD_INSN(ret, nd_line(node), YARVInstructions.POP);
                }
                break compileLoop;
            case FIXNUMNODE:
                FixnumNode iVisited = (FixnumNode) node;
                if(!poped) {
                    ADD_INSN1(ret, nd_line(node), YARVInstructions.PUTOBJECT, iVisited.getFixnum(runtime));
                }
                break compileLoop;
            case WHILENODE:
            case UNTILNODE:{
                Label next_label = NEW_LABEL(nd_line(node))/* next  */
                Label redo_label = NEW_LABEL(nd_line(node))/* redo  */
                Label break_label = NEW_LABEL(nd_line(node))/* break */
                Label end_label = NEW_LABEL(nd_line(node));

                ADD_LABEL(ret, redo_label);

                Node body = null;
                if(node instanceof WhileNode) {
                    body = ((WhileNode)node).getBodyNode();
                } else if(node instanceof UntilNode) {
                    body = ((UntilNode)node).getBodyNode();
                }
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.