Examples of ListNode


Examples of org.jruby.ast.ListNode

            return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1, arg2}, block);
        }
    }

    private int assignOptArgs(IRubyObject[] args, Ruby runtime, ThreadContext context, IRubyObject self, int givenArgsCount) {
        ListNode optArgs = argsNode.getOptArgs();

        // assign given optional arguments to their variables
        int j = 0;
        for (int i = requiredArgsCount; i < args.length && j < optArgs.size(); i++, j++) {
            // in-frame EvalState should already have receiver set as self, continue to use it
            optArgs.get(j).assign(runtime, context, self, args[i], Block.NULL_BLOCK, true);
            givenArgsCount++;
        }

        // assign the default values, adding to the end of allArgs
        for (int i = 0; j < optArgs.size(); i++, j++) {
            optArgs.get(j).interpret(runtime, context, self, Block.NULL_BLOCK);
        }
        return givenArgsCount;
    }
View Full Code Here

Examples of org.jruby.ast.ListNode

        // normal items at the front or back of the masgn
        ArrayCallback prePostAssignCallback = new ArrayCallback() {

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

                        // perform assignment for the next node
                        compileAssignment(assignNode, context, false);
                    }
                };
View Full Code Here

Examples of org.jruby.ast.ListNode

        case DREGEXPNODE:
        case DSTRNODE:
        case DSYMBOLNODE:
        case DXSTRNODE:
        case LISTNODE:
            ListNode listNode = (ListNode)node;
            for (int i = 0; i < listNode.size(); i++) {
                inspect(listNode.get(i));
            }
            break;
        case ARGSNODE:
            ArgsNode argsNode = (ArgsNode)node;
            if (argsNode.getBlock() != null) setFlag(node, BLOCK_ARG);
View Full Code Here

Examples of org.jruby.ast.ListNode

        } 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
                    if (isRest) {
                        assigner = hasBlock ? new Pre0Rest1Post0BlockAssigner(rest, block) :
                            new Pre0Rest1Post0Assigner(rest);
                    } else if (hasBlock) {
                        assigner = new Pre0Rest0Post0BlockAssigner(block);
                    } else {
                        noargblock = true;
                        assigner = new Pre0Rest0Post0Assigner();
                    }
                    break;
                case 1:
                    if (isRest) {
                        assigner = hasBlock ? new Pre1Rest1Post0BlockAssigner(pre.get(0), rest, block) :
                            new Pre1Rest1Post0Assigner(pre.get(0), rest);
                    } else if (hasBlock) {
                        assigner = new Pre1Rest0Post0BlockAssigner(pre.get(0), block);
                    } else {
                        assigner = new Pre1Rest0Post0Assigner(pre.get(0));
                    }
                    break;
                case 2:
                    if (isRest) {
                        assigner = hasBlock ? new Pre2Rest1Post0BlockAssigner(pre.get(0), pre.get(1), rest, block) :
                            new Pre2Rest1Post0Assigner(pre.get(0), pre.get(1), rest);
                    } else if (hasBlock) {
                        assigner = new Pre2Rest0Post0BlockAssigner(pre.get(0), pre.get(1), block);
                    } else {
                        assigner = new Pre2Rest0Post0Assigner(pre.get(0), pre.get(1));
                    }
                    break;
                case 3:
                    if (isRest) {
                        assigner = hasBlock ? new Pre3Rest1Post0BlockAssigner(pre.get(0), pre.get(1), pre.get(2), rest, block) :
                            new Pre3Rest1Post0Assigner(pre.get(0), pre.get(1), pre.get(2), rest);
                    } else if (hasBlock) {
                        assigner = new Pre3Rest0Post0BlockAssigner(pre.get(0), pre.get(1), pre.get(2), block);
                    } else {
                        assigner = new Pre3Rest0Post0Assigner(pre.get(0), pre.get(1), pre.get(2));
                    }
                    break;
                default:
                    if (isRest) {
                        assigner = hasBlock ? new PreManyRest1Post0BlockAssigner(pre, preCount, rest, block) :
View Full Code Here

Examples of org.jruby.ast.ListNode

            }

            ArrayCallback hashCallback = new ArrayCallback() {
                public void nextValue(BodyCompiler context, Object sourceArray,
                        int index) {
                    ListNode listNode = (ListNode) sourceArray;
                    int keyIndex = index * 2;
                    compile(listNode.get(keyIndex), context, true);
                    compile(listNode.get(keyIndex + 1), context, true);
                }
            };

            if (isListAllLiterals(hashNode.getListNode())) {
                context.createNewLiteralHash(hashNode.getListNode(), hashCallback, hashNode.getListNode().size() / 2);
View Full Code Here

Examples of org.jruby.ast.ListNode

        // normal items at the "head" of the masgn
        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, false);
                    }
                };
View Full Code Here

Examples of org.jruby.ast.ListNode

            // Other args begin at index 0
        int argIndex = 0;

            // Both for fixed arity and variable arity methods
        ListNode preArgs  = argsNode.getPre();
        for (int i = 0; i < required; i++, argIndex++) {
            ArgumentNode a = (ArgumentNode)preArgs.get(i);
            // FIXME: Charlie added this to test something?
            if (a instanceof TypedArgumentNode) {
                TypedArgumentNode t = (TypedArgumentNode)a;
                s.addInstr(new DECLARE_LOCAL_TYPE_Instr(argIndex, buildType(t.getTypeNode())));
            }
            s.addInstr(new ReceiveArgumentInstruction(s.getLocalVariable(a.getName()), argIndex));
        }

            // IMPORTANT: Receive the block argument before the opt and splat args
            // This is so that the *arg can be encoded as 'rest of the array'.  This
            // won't work if the block argument hasn't been received yet!
        if (argsNode.getBlock() != null)
            s.addInstr(new ReceiveClosureInstr(s.getLocalVariable(argsNode.getBlock().getName())));

            // Now for the rest
        if (opt > 0) {
            ListNode optArgs = argsNode.getOptArgs();
            for (int j = 0; j < opt; j++, argIndex++) {
                    // Jump to 'l' if this arg is not null.  If null, fall through and build the default value!
                Label l = s.getNewLabel();
                LocalAsgnNode n = (LocalAsgnNode)optArgs.get(j);
                Variable av = s.getLocalVariable(n.getName());
                s.addInstr(new ReceiveOptionalArgumentInstr(av, argIndex));
                s.addInstr(new BNEInstr(av, Nil.NIL, l)); // if 'av' is not null, go to default
                build(n, s);
                s.addInstr(new LABEL_Instr(l));
View Full Code Here

Examples of org.jruby.ast.ListNode

        buildMultipleAsgnAssignment(multipleAsgnNode, s, ret);
        return ret;
    }

    public void buildMultipleAsgnAssignment(final MultipleAsgnNode multipleAsgnNode, IRScope s, Operand values) {
        final ListNode sourceArray = multipleAsgnNode.getHeadNode();

        // First, build assignments for specific named arguments
        int i = 0;
        if (sourceArray != null) {
            ListNode headNode = (ListNode) sourceArray;
            for (Node an: headNode.childNodes()) {
                if (values == null) {
                    buildBlockArgsAssignment(an, s, i, false); // SSS FIXME: Changed this from i+1 to i// Add 1 since 0 is self for argument processing
                } else {
                    buildAssignment(an, s, values, i, false);
                }
View Full Code Here

Examples of org.jruby.ast.ListNode

                return RuntimeHelpers.parameterListToParameters(runtime, ((MethodArgs2)method).getParameterList(), true);
            } else if (method instanceof MethodArgs) {
                MethodArgs interpMethod = (MethodArgs)method;
                ArgsNode args = interpMethod.getArgsNode();
               
                ListNode requiredArgs = args.getPre();
                for (int i = 0; requiredArgs != null && i < requiredArgs.size(); i++) {
                    Node argNode = requiredArgs.get(i);
                    if (argNode instanceof MultipleAsgn19Node) {
                        argsArray.append(RubyArray.newArray(runtime, req));
                    } else {
                        argsArray.append(RubyArray.newArray(runtime, req, getNameFrom(runtime, (INameNode)argNode)));
                    }
                }
               
                ListNode optArgs = args.getOptArgs();
                for (int i = 0; optArgs != null && i < optArgs.size(); i++) {
                    argsArray.append(RubyArray.newArray(runtime, opt, getNameFrom(runtime, (INameNode) optArgs.get(i))));
                }

                if (args.getRestArg() >= 0) {
                    RestArgNode restArg = (RestArgNode) args.getRestArgNode();

                    if (restArg instanceof UnnamedRestArgNode) {
                        if (((UnnamedRestArgNode) restArg).isStar()) {
                            argsArray.append(RubyArray.newArray(runtime, rest));
                        }
                    } else {
                        argsArray.append(RubyArray.newArray(runtime, rest, getNameFrom(runtime, args.getRestArgNode())));
                    }
                }
               
                ListNode requiredArgsPost = args.getPost();
                for (int i = 0; requiredArgsPost != null && i < requiredArgsPost.size(); i++) {
                    Node argNode = requiredArgsPost.get(i);
                    if (argNode instanceof MultipleAsgn19Node) {
                        argsArray.append(RubyArray.newArray(runtime, req));
                    } else {
                        argsArray.append(RubyArray.newArray(runtime, req, getNameFrom(runtime, (INameNode) requiredArgsPost.get(i))));
                    }
                }

                if (args.getBlock() != null) {
                    argsArray.append(RubyArray.newArray(runtime, block, getNameFrom(runtime, args.getBlock())));
View Full Code Here

Examples of org.jruby.ast.ListNode

    public static IRubyObject multiAssign(Ruby runtime, ThreadContext context, IRubyObject self, MultipleAsgn19Node node, RubyArray value) {
        // Assign the values.
        int valueLen = value.getLength();
        int postCount = node.getPostCount();
        int preCount = node.getPreCount();
        ListNode pre = node.getPre();
        ListNode post = node.getPost();

        int j = 0;
        for (; j < valueLen && j < preCount; j++) {
            pre.get(j).assign(runtime, context, self, value.eltInternal(j), Block.NULL_BLOCK, false);
        }

        Node rest = node.getRest();
        if (rest != null) {
            if (rest.getNodeType() == NodeType.STARNODE) {
                // no check for '*'
            } else if (preCount + postCount < valueLen) {
                rest.assign(runtime, context, self, value.subseqLight(preCount, valueLen - preCount - postCount), Block.NULL_BLOCK, false);
            } else {
                rest.assign(runtime, context, self, RubyArray.newEmptyArray(runtime), Block.NULL_BLOCK, false);
            }

            // FIXME: This is wrong
            int postIndexBase = valueLen - postCount;
            for (int i = 0; i < valueLen && i < postCount; i++) {
                post.get(i).assign(runtime, context, self, value.eltInternal(i + postIndexBase), Block.NULL_BLOCK, false);
            }
        }

        while (j < preCount) {
            pre.get(j++).assign(runtime, context, self, runtime.getNil(), Block.NULL_BLOCK, false);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.