Package org.jruby.ast

Examples of org.jruby.ast.Node


        return COMPILE_OK;
    }

    private int compile_array(LinkAnchor ret, Node node_root, boolean opt_p) {
        Node node = node_root;
        int len = ((ArrayNode)node).size();
        int line = nd_line(node);
        LinkAnchor anchor = DECL_ANCHOR();
        List c = node.childNodes();
        for(Iterator iter = c.iterator(); iter.hasNext();) {
            node = (Node)iter.next();
            if(opt_p && !(node instanceof ILiteralNode)) {
                opt_p = false;
            }
View Full Code Here


        return len;
    }

    private int[] setup_arg(LinkAnchor args, IArgumentNode node) {
        int[] n = new int[] {0,0};
        Node argn = node.getArgsNode();
        LinkAnchor arg_block = DECL_ANCHOR();
        LinkAnchor args_push = DECL_ANCHOR();
        boolean blockArgs = false;

        if (argn != null) {
View Full Code Here

        Frame lastFrame = context.preEvalWithBinding(binding);
        try {
            // Binding provided for scope, use it
            IRubyObject newSelf = binding.getSelf();
            RubyString source = src.convertToString();
            Node node = runtime.parseEval(source.getByteList(), file, evalScope, lineNumber);

            return node.interpret(runtime, context, newSelf, binding.getFrame().getBlock());
        } catch (JumpException.BreakJump bj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
        } catch (JumpException.RedoJump rj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, (IRubyObject)rj.getValue(), "unexpected redo");
        } catch (StackOverflowError sfe) {
View Full Code Here

       
        DynamicScope evalScope = context.getCurrentScope().getEvalScope();
        evalScope.getStaticScope().determineModule();
       
        try {
            Node node = runtime.parseEval(source.getByteList(), file, evalScope, lineNumber);
           
            return node.interpret(runtime, context, self, Block.NULL_BLOCK);
        } catch (JumpException.BreakJump bj) {
            throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
        } catch (StackOverflowError sfe) {
            throw runtime.newSystemStackError("stack level too deep");
        } finally {
View Full Code Here

        assert false: "Trying to get block from something which cannot deliver";
        return null;
    }

    private static Block getBlockPassBlock(Node blockNode, Ruby runtime, ThreadContext context, IRubyObject self, Block currentBlock) {
        Node bodyNode = ((BlockPassNode) blockNode).getBodyNode();
        IRubyObject proc;
        if (bodyNode == null) {
            proc = runtime.getNil();
        } else {
            proc = bodyNode.interpret(runtime, context, self, currentBlock);
        }

        return RuntimeHelpers.getBlockFromBlockPassBody(proc, currentBlock);
    }
View Full Code Here

        if (checkArity && j < varLen) {
            throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
        }

        Node argsNode = node.getArgsNode();
        if (argsNode != null) {
            if (argsNode.nodeId == NodeType.STARNODE) {
                // no check for '*'
            } else if (varLen < valueLen) {
                argsNode.assign(runtime, context, self, value.subseqLight(varLen, valueLen), Block.NULL_BLOCK, checkArity);
            } else {
                argsNode.assign(runtime, context, self, RubyArray.newArrayLight(runtime, 0), Block.NULL_BLOCK, checkArity);
            }
        } else if (checkArity && valueLen < varLen) {
            throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
        }

View Full Code Here

        }
    }

    @JRubyMethod(name = "compile", optional = 3, frame = true, module = true)
    public static IRubyObject compile(IRubyObject recv, IRubyObject[] args, Block block) {
        Node node;
        String filename;
        RubyString content;
        if(block.isGiven()) {
            Arity.checkArgumentCount(recv.getRuntime(),args,0,0);
            if(block.getBody() instanceof org.jruby.runtime.CompiledBlock) {
                throw new RuntimeException("Cannot compile an already compiled block. Use -J-Djruby.jit.enabled=false to avoid this problem.");
            }
            content = RubyString.newEmptyString(recv.getRuntime());
            Node bnode = ((InterpretedBlock)block.getBody()).getIterNode().getBodyNode();
            node = new org.jruby.ast.RootNode(bnode.getPosition(), block.getBinding().getDynamicScope(), bnode);
            filename = "__block_" + node.getPosition().getFile();
        } else {
            Arity.checkArgumentCount(recv.getRuntime(),args,1,3);
            filename = "-";
            boolean extraPositionInformation = false;
View Full Code Here

     */
    public IRubyObject evalScriptlet(String script) {
        ThreadContext context = getCurrentContext();
        DynamicScope currentScope = context.getCurrentScope();
        ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(new EvalStaticScope(currentScope.getStaticScope()), currentScope);
        Node node = parseEval(script, "<script>", newScope, 0);
       
        try {
            context.preEvalScriptlet(newScope);
            return node.interpret(this, context, context.getFrameSelf(), Block.NULL_BLOCK);
        } catch (JumpException.ReturnJump rj) {
            throw newLocalJumpError(RubyLocalJumpError.Reason.RETURN, (IRubyObject)rj.getValue(), "unexpected return");
        } catch (JumpException.BreakJump bj) {
            throw newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
        } catch (JumpException.RedoJump rj) {
View Full Code Here

            bytes = script.getBytes(KCode.NONE.getKCode());
        } catch (UnsupportedEncodingException e) {
            bytes = script.getBytes();
        }

        Node node = parseInline(new ByteArrayInputStream(bytes), filename, null);
        ThreadContext context = getCurrentContext();
       
        String oldFile = context.getFile();
        int oldLine = context.getLine();
        try {
            context.setFile(node.getPosition().getFile());
            context.setLine(node.getPosition().getStartLine());
            return runNormally(node, false);
        } finally {
            context.setFile(oldFile);
            context.setLine(oldLine);
        }
View Full Code Here

            new YARVCompiledRunner(this, inputStream, filename).run();
        } else if(config.isRubiniusEnabled()) {
            if (config.isShowBytecode()) System.err.print("error: bytecode printing only works with JVM bytecode");
            new RubiniusRunner(this, inputStream, filename).run();
        } else {
            Node scriptNode = parseFromMain(inputStream, filename);
            ThreadContext context = getCurrentContext();

            String oldFile = context.getFile();
            int oldLine = context.getLine();
            try {
                context.setFile(scriptNode.getPosition().getFile());
                context.setLine(scriptNode.getPosition().getStartLine());

                if (config.isAssumePrinting() || config.isAssumeLoop()) {
                    runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
                            config.isSplit(), config.isYARVCompileEnabled());
                } else {
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.