当前位置: 首页>>代码示例>>C++>>正文


C++ Environment::Globals方法代码示例

本文整理汇总了C++中Environment::Globals方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::Globals方法的具体用法?C++ Environment::Globals怎么用?C++ Environment::Globals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Environment的用法示例。


在下文中一共展示了Environment::Globals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InterpretCall

/**
 * Interpret a builtin call. Yes, this can be slow because each time we invoke
 * this we must query the mapping in the builtins table to see if it can be 
 * executed (builtin implementation). HOWEVER, this also allows us to swap out
 * builtin implementations on the fly.
 *
 * @return The interpreted element.
 */
Element Builtin_::InterpretCall( Environment& environment
                               , Element const& builtin_element
                               , std::vector<Element> const& parms )
{
    std::shared_ptr<Builtin_> builtin(std::dynamic_pointer_cast<Builtin_>(builtin_element.ElementHandle()));
    BuiltinsTable& table = *(builtin->table);
    BuiltinImplementation* impl = table.Get(builtin->Name());

    Element result;

    if (0 != builtin && 0 != impl)
    {
        std::vector<Element> output_parameters; 
        GlobalEnvironment globals(environment.Globals());
        Environment output_environment = Environment::Create(globals);
        bool success = Funcall_::CreateEnvironment( environment
                                                  , parms
                                                  , output_parameters);


        if (success && (0 != impl))
        {
            result = impl->Interpret( output_environment
                                    , output_parameters 
                                    , builtin->AdditionalParameter() );
        }
    }

    return result;
}
开发者ID:signatal,项目名称:codeography,代码行数:38,代码来源:builtin_.cpp

示例2: InterpretCall

/**
 * Interpret a function call.
 *
 * @param environment The environment to make the interpretation of a call 
 *                    over. This could be another function environment.
 *                    We use it to parse arguments in and to obtain the 
 *                    global environment.
 * @param function_element The function we want to evaluate the call of.
 * @param parms The container of parameters into the call.
 *
 *
 * @return The interpreted element.
 */
Element Function_::InterpretCall( Environment& environment
                                , Element const& function_element
                                , std::vector<Element> const& parms )
{
    GlobalEnvironment globals(environment.Globals());

    bool hasFunction = false;
    Function function = CastToFunction(function_element, hasFunction);
    Element result;

    if (hasFunction)
    {
        bool tailRecursion = true;
        std::vector<Element> parameters(parms);

        while(tailRecursion)
        {
            tailRecursion = false;

            Environment function_environment = Environment::Create(globals);
            globals.PushCallStack(function, function_environment);

            bool success = Funcall_::CreateEnvironment( function.Arguments()
                                                      , parameters
                                                      , function_environment ); 
            if (success)
            {
                Element body(function.Body());
                result = body.Interpret(function_environment);

                // Making a recursive call using tail recursion.
                if (Types::TAILRECURSE == result.Type())
                {
                    TailRecurse tailRecurse = CastToTailRecurse(result, success);
                    parameters = tailRecurse.Parameters();
          
                    // Go again! :D
                    tailRecursion = true; 
                }
            }

            globals.PopCallStack();
        }
    }

    return result;
}
开发者ID:signatal,项目名称:codeography,代码行数:60,代码来源:function_.cpp


注:本文中的Environment::Globals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。