Package org.cx4a.rsense.ruby

Examples of org.cx4a.rsense.ruby.Context


        }
        return args.isEmpty() ? null : args.toArray(new Vertex[0]);
    }

    public static Block setupCallBlock(Graph graph, Node iterNode) {
        Context context = graph.getRuntime().getContext();
        Block block = null;
        if (iterNode != null) {
            switch (iterNode.getNodeType()) {
            case ITERNODE: {
                IterNode inode = (IterNode) iterNode;
                DynamicScope scope = new DynamicScope(context.getCurrentScope().getModule(), context.getCurrentScope());
                block = new Proc(graph.getRuntime(), inode.getVarNode(), inode.getBodyNode(), context.getCurrentFrame(), scope);
                break;
            }
            case BLOCKPASSNODE:
                block = context.getFrameBlock();
                break;
            }
        }
        return block;
    }
View Full Code Here


        }
    }

    public static void dummyCall(Graph graph, MethodDefNode node, Method method, IRubyObject receiver) {
        if (node.getBodyNode() != null) {
            Context context = graph.getRuntime().getContext();
            context.pushFrame(context.getFrameModule(), node.getName(), receiver, null, Visibility.PUBLIC);
            context.pushScope(new LocalScope(method.getModule()));
            graph.createVertex(node.getBodyNode());
            context.popScope();
            context.popFrame();
        }
        Logger.debug(SourceLocation.of(node), "dummy call: %s", method);
    }
View Full Code Here

        for (int i = 0; i < argVertices.length; i++) {
            argVertices[i] = graph.createFreeSingleTypeVertex(args[i]);
        }

        Ruby runtime = graph.getRuntime();
        Context context = runtime.getContext();

        Block block = attr.getBlock();
        Scope scope = new LocalScope(method.getModule());
        context.pushFrame(context.getFrameModule(), name, receiver, block, Visibility.PUBLIC);
        context.pushScope(scope);

        Template template = new Template(method, context.getCurrentFrame(), scope, attr);
        method.addTemplate(attr, template);

        Vertex returnVertex = template.getReturnVertex();
        setFrameTemplate(context.getCurrentFrame(), template);

        AnnotationResolver.Result result = AnnotationHelper.resolveMethodAnnotation(graph, template);
        if (result == AnnotationResolver.Result.UNRESOLVED) {
            Logger.warn(SourceLocation.of(vertex), "annotation unmatched: %s", method);
        }

        Vertex ret = method.call(graph, template, receiver, args, argVertices, block);
        if (ret != null && result != AnnotationResolver.Result.RESOLVED) {
            graph.addEdgeAndUpdate(ret, returnVertex);
        }

        context.popScope();
        context.popFrame();

        return template;
    }
View Full Code Here

    public static Vertex yield(Graph graph, Block block, Collection<IRubyObject> args, boolean expanded, Vertex returnVertex) {
        if (block == null) {
            return Vertex.EMPTY;
        }
        Ruby runtime = graph.getRuntime();
        Context context = runtime.getContext();
       
        Node varNode = block.getVarNode();
        boolean noargblock = false;
        MultipleAsgnNode masgn = null;
        int preCount = 0;
        boolean isRest = false;
        Node rest = null;
        ListNode pre = null;
        Vertex vertex = graph.createFreeVertex();

        if (varNode == null || varNode instanceof ZeroArgNode) {
            noargblock = true;
        } else if (varNode instanceof MultipleAsgnNode) {
            masgn = (MultipleAsgnNode) varNode;
            preCount = masgn.getPreCount();
            isRest = masgn.getRest() != null;
            rest = masgn.getRest();
            pre = masgn.getPre();
        }
       
        if (args != null && !args.isEmpty()) {
            for (IRubyObject value : args) {
                pushLoopFrame(context, block.getFrame(), returnVertex, vertex);
                context.pushScope(block.getScope());

                if (noargblock) {}
                else if (masgn != null) {
                    Array array;
                    if (!expanded) {
                        // FIXME to_ary
                        if (value instanceof Array) {
                            array = (Array) value;
                        } else {
                            array = createArray(graph, new Vertex[] { graph.createFreeSingleTypeVertex(value) });
                        }
                    } else {
                        if (value instanceof Array) {
                            array = (Array) value;
                        } else {
                            array = createArray(graph, new Vertex[] { graph.createFreeSingleTypeVertex(value) });
                        }
                    }
                    multipleAssign(graph, masgn, array);
                } else {
                    assign(graph, varNode, graph.createFreeSingleTypeVertex(value));
                }

                if (block.getBodyNode() != null) {
                    Vertex v = graph.createVertex(block.getBodyNode());
                    graph.addEdgeAndPropagate(v, vertex);
                }

                context.popScope();
                popLoopFrame(context);
            }
        } else {
            pushLoopFrame(context, block.getFrame(), returnVertex, vertex);
            context.pushScope(block.getScope());

            if (block.getBodyNode() != null) {
                Vertex v = graph.createVertex(block.getBodyNode());
                graph.addEdgeAndPropagate(v, vertex);
            }
           
            context.popScope();
            popLoopFrame(context);
        }

        return vertex;
    }
View Full Code Here

TOP

Related Classes of org.cx4a.rsense.ruby.Context

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.