예제 #1
0
파일: closure.cpp 프로젝트: hsaransa/puuro
Frame* Closure::call_frame(List* args)
{
    // Check parameter count.

    const std::vector<Name>& pre = code->get_pre_params();
    Name sink = code->get_sink_param();
    const std::vector<Name>& post = code->get_post_params();
    if (sink.valid())
    {
        if (args->get_size() < (int)(pre.size() + post.size()))
            throw new Exception(Name("bad_parameter_count"), *args);
    }
    else
    {
        if (args->get_size() != (int)(pre.size() + post.size()))
            throw new Exception(Name("bad_parameter_count"), *args);
    }

    // Make frame and set local variables.

    Scope* sc = new Scope(scope.get());

    int i = 0;

    for (int j = 0; j < (int)pre.size(); j++)
        sc->set_local(pre[j], args->get(i++));

    if (sink.valid())
    {
        List* l = new List();
        while (i < args->get_size() - (int)post.size())
            l->append(args->get(i++));
        sc->set_local(sink, *l);
        dec_ref(l);
    }

    for (int j = 0; j < (int)post.size(); j++)
        sc->set_local(post[j], args->get(i++));

    return new Frame(sc, 0, code.get());
}