예제 #1
0
        public VariableInstance CompileVariableInstance(CmlContext context)
        {
            CmlScriptRequest request = InitializeRequest(context);

            ILValue il_value        = GetExpression().GetValue().GetILValue();
            Type    expression_type = il_value.GetValueType();

            CmlScriptValue_Argument value_argument = request.AddPrimaryArgument(
                new CmlScriptValue_Argument_Single_Placeholder(expression_type)
                );

            CmlScriptDefinition_Link definition = definitions.GetOrCreateValue(request.GetSignature(), delegate() {
                return(new CmlScriptDefinition_Link(
                           expression_type,

                           "CmlLink[" + stored_text + "]",

                           il_value.CanStore().IfTrue(() =>
                                                      GetType().CreateDynamicMethodDelegate <Process <object, object, object> >(
                                                          "CmlLink_Store[" + stored_text + "]",
                                                          new ILAssign(il_value, value_argument.GetILValue())
                                                          )
                                                      ),

                           il_value.CanLoad().IfTrue(() =>
                                                     GetType().CreateDynamicMethodDelegate <Operation <object, object, object, object> >(
                                                         "CmlLink_Load[" + stored_text + "]",
                                                         new ILReturn(il_value)
                                                         )
                                                     )
                           ));
            });

            return(definition.CreateVariableInstance(request));
        }
예제 #2
0
        public FunctionInstance CompileFunctionInstance(CmlContext context)
        {
            CmlScriptRequest request = InitializeRequest(context);

            CmlScriptDefinition_Function definition = definitions.GetOrCreateValue(request.GetSignature(), delegate() {
                string name = "CmlFunction[" + GetFunctionParameters() + stored_text + "]";

                return(new CmlScriptDefinition_Function(
                           name,
                           GetFunctionParameters().IfNotNull(p => p.GetParameterTypes()),

                           GetType().CreateDynamicMethodDelegate <Process <object, object, object> >(
                               name,
                               GetLambda().GetILStatement()
                               )
                           ));
            });

            return(definition.CreateFunctionInstance(request));
        }