public PostfixSelectVisitor(LE.ParameterExpression row, Func<String, IProjection> projectionCreator)
 {
     projections = new List<IProjection>();
     ProjectionsPropertyNames = new List<String>();
     this.projectionCreator = projectionCreator;
     this.row = row;
 }
示例#2
0
 public static MemberMemberBinding Serialize(E.MemberMemberBinding binding)
 {
     return new MemberMemberBinding()
     {
         Member = MemberRef.Serialize(binding.Member),
         Bindings = binding.Bindings.Select(Serialize).ToArray(),
     };
 }
示例#3
0
 public static ElementInit Serialize(E.ElementInit elementInit)
 {
     return new ElementInit()
     {
         AddMethod = MethodRef.Serialize(elementInit.AddMethod),
         Arguments = elementInit.Arguments.Select(Node.Serialize).ToArray(),
     };
 }
 public override MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global)
 {
     return new LookupGlobalVariable(
         globalContext,
         variable.Name,
         variable.Kind == VariableKind.Local
     );
 }
示例#5
0
 public static MemberListBinding Serialize(E.MemberListBinding binding)
 {
     return new MemberListBinding()
     {
         Member = MemberRef.Serialize(binding.Member),
         Initializers = binding.Initializers.Select(ElementInit.Serialize).ToArray(),
     };
 }
示例#6
0
 public static MemberAssignment Serialize(E.MemberAssignment binding)
 {
     return new MemberAssignment()
     {
         Member = MemberRef.Serialize(binding.Member),
         Expression = Node.Serialize(binding.Expression),
     };
 }
示例#7
0
 public GroupVisitor(
     LE.ParameterExpression row,
     Int32 currentColumnIndex)
 {
     projections = new List<IProjection>();
     ProjectionsPropertyNames = new List<String>();
     this.row = row;
 }
示例#8
0
 internal static SwitchCase Serialize(E.SwitchCase @case)
 {
     return new SwitchCase()
     {
         TestValues = @case.TestValues.Select(Node.Serialize).ToArray(),
         Body = Node.Serialize(@case.Body),
     };
 }
示例#9
0
 public static SymbolDocumentInfo Serialize(E.SymbolDocumentInfo document)
 {
     return new SymbolDocumentInfo()
     {
         FileName = document.FileName,
         Language = document.Language,
         LanguageVendor = document.LanguageVendor,
         DocumentType = document.DocumentType,
     };
 }
示例#10
0
 internal static LabelTarget Serialize(E.LabelTarget target)
 {
     return new LabelTarget()
     {
         Name = target.Name,
         Type = target.Type != typeof(void)
             ? TypeRef.Serialize(target.Type)
             : null,
     };
 }
示例#11
0
        static MSAst.ExpressionType GetOp(MSAst.ExpressionType assignOp)
        {
            switch (assignOp)
            {
                case MSAst.ExpressionType.Assign:
                default: return MSAst.ExpressionType.Default;

                case MSAst.ExpressionType.AddAssign: return MSAst.ExpressionType.Add;
                case MSAst.ExpressionType.SubtractAssign: return MSAst.ExpressionType.Subtract;
            }
        }
示例#12
0
 internal static CatchBlock Serialize(E.CatchBlock handler)
 {
     return new CatchBlock()
     {
         Test = handler.Variable == null
             ? TypeRef.Serialize(handler.Test)
             : null,
         Variable = handler.Variable.Null(v => Node.Parameter(v)),
         Filter = handler.Filter.Null(e => Node.Serialize(e)),
         Body = Node.Serialize(handler.Body),
     };
 }
        public override MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global)
        {
            Assert.NotNull(global);

            return new TotemGlobalVariableExpression(
                Ast.ArrayIndex(
                    TotemAst._globalArray,
                    Ast.Constant(arrayIndex)
                ),
                variable,
                global
            );
        }
示例#14
0
 public static MemberBinding Serialize(E.MemberBinding binding)
 {
     switch (binding.BindingType)
     {
         case E.MemberBindingType.Assignment:
             return MemberAssignment.Serialize((E.MemberAssignment) binding);
         case E.MemberBindingType.MemberBinding:
             return MemberMemberBinding.Serialize((E.MemberMemberBinding) binding);
         case E.MemberBindingType.ListBinding:
             return MemberListBinding.Serialize((E.MemberListBinding) binding);
         default:
             throw new ArgumentOutOfRangeException("binding.BindingType");
     }
 }
示例#15
0
        internal override MSAst.Expression TransformSet(SourceSpan span, MSAst.Expression right, MSAst.ExpressionType op)
        {
            if (op != MSAst.ExpressionType.Default)
            {
                right = GlobalParent.Operation(
                    typeof(object),
                    op,
                    this,
                    right
                );
            }

            var index = GlobalParent.SetIndex(new[] { _target, Parent.LocalContext }.Concat(_indexes).Concat(new[] { right }).ToArray());
            return GlobalParent.AddDebugInfo(index, Span);
        }
示例#16
0
        internal override MSAst.Expression TransformSet(SourceSpan span, MSAst.Expression right, MSAst.ExpressionType op)
        {
            if (op != MSAst.ExpressionType.Default)
            {
                right = GlobalParent.Operation(
                    typeof(object),
                    op,
                    this,
                    right
                );
            }

            var index = GlobalParent.Set(_name, _target, right);
            return GlobalParent.AddDebugInfo(index, Span);
        }
示例#17
0
        /*!*/
        public MSAst.Expression Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0)
        {
            if (retType == typeof(object))
            {
                throw new NotImplementedException();
                //return new TotemDynamicExpression1(binder, this, arg0);
            }
            else if (retType == typeof(bool))
            {
                throw new NotImplementedException();
                //return new TotemDynamicExpression1<bool>(binder, this, arg0);
            }

            return ReduceDynamic(binder, retType, arg0);
        }
示例#18
0
        private MSAst.Expression ReduceWorker(MSAst.Expression expression)
        {
            if (Parent.PrintExpressions)
            {
                MSAst.Expression printable = ConvertIfNeeded(expression, typeof(object));
                if (printable.Type != typeof(string))
                {
                    printable = GlobalParent.Convert(typeof(string), ConversionResultKind.ExplicitCast, printable);
                }

                expression = Ast.Call(
                    AstMethods.PrintExpressionValue,
                    Parent.LocalContext,
                    printable
                );
            }

            return GlobalParent.AddDebugInfoAndVoid(expression, _expression.Span);
        }
示例#19
0
        public void OverloadResolution_Block1()
        {
            var scope = Context.EmptyScope;
            var proc = new Proc(ProcKind.Proc, null, scope, new BlockDispatcher0(BlockSignatureAttributes.None, null, 0).
                SetMethod(new BlockCallTarget0((x, y) => null)));

            var arguments = new[] {
                // 1.times
                new CallArguments(Context, MO(scope), new[] { MO(1) }, RubyCallSignature.WithScope(0)),
                // 1.times &nil
                new CallArguments(Context, MO(scope), new[] {  MO(1), MO(null) }, RubyCallSignature.WithScopeAndBlock(0)),
                // 1.times &p
                new CallArguments(Context, MO(1), new[] {  MO(proc) }, RubyCallSignature.WithBlock(0)),
                // obj.times &p
                new CallArguments(Context, MO("foo"), new[] {  MO(proc) }, RubyCallSignature.WithBlock(0)),
            };

            var results = new[] {
                "Times2",
                "Times1",
                "Times3",
                "Times4",
            };

            var metaBuilder = new MetaObjectBuilder(null);
            for (int i = 0; i < arguments.Length; i++) {
                RubyOverloadResolver resolver;

                var methods = GetStaticMethodsStartingWith(typeof(OverloadsWithBlock), "Times");

                var bindingTarget = RubyMethodGroupInfo.ResolveOverload(
                    metaBuilder, arguments[i], "times", methods, SelfCallConvention.SelfIsParameter,
                    false, out resolver
                );

                Assert(bindingTarget.Success);
                Assert(bindingTarget.Overload.Name == results[i]);
            }
        }
示例#20
0
        private DLR.Expression BuildPickAssign(AplusScope scope, DLR.Expression value)
        {
            DyadicFunction function = (DyadicFunction)this.target;
            bool isValueinContext = Node.TestDyadicToken(function.Left, Grammar.Tokens.VALUEINCONTEXT);
            bool isValue = Node.TestMonadicToken(function.Right, Grammar.Tokens.VALUE);

            if (!(function.Right is Identifier || isValueinContext || isValue))
            {
                throw new ParseException("assign pick target", false);
            }

            DLR.Expression left = function.Left.Generate(scope);

            scope.IsAssignment = true;
            DLR.Expression right = function.Right.Generate(scope);
            scope.IsAssignment = false;

            var method = DyadicFunctionInstance.Pick;
            DLR.Expression pickDLR = DLR.Expression.Call(
                DLR.Expression.Constant(method),
                method.GetType().GetMethod("AssignExecute"),
                right,
                left,
                scope.GetRuntimeExpression()
            );

            DLR.ParameterExpression errorParam = DLR.Expression.Parameter(typeof(Error.Signal));

            var flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static;

            DLR.ParameterExpression temp = DLR.Expression.Parameter(typeof(AType));
            DLR.Expression callback = BuildCallbackCall(scope, temp);
            DLR.Expression presetCallback = BuildPresetCallbackCall(scope, temp);

            DLR.Expression result =
                DLR.Expression.Block(
                    new DLR.ParameterExpression[] { temp },
                    DLR.Expression.Assign(scope.CallbackInfo.Path, left),
                    DLR.Expression.Assign(temp, value),
                    DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(false)),
                    DLR.Expression.TryCatch(
                        DLR.Expression.Block(
                            typeof(void),
                            DLR.Expression.Assign(temp, presetCallback),
                            DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(true))
                        ),
                        DLR.Expression.Catch(
                            errorParam,
                            DLR.Expression.Empty()
                        )
                    ),
                    DLR.Expression.IfThen(
                        scope.AssignDone,
                        DLR.Expression.Block(
                            DLR.Expression.Call(
                                typeof(Assign).GetMethod("PickAssignHelper", flags),
                                temp,
                                pickDLR
                            ),
                            callback
                        )
                    ),
                    scope.CallbackInfo.NonPresetValue
                );

            return result;
        }
示例#21
0
        /// <summary>
        /// Build DLR expression for: (,target)[indexExpression]
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="target"></param>
        /// <param name="indexExpression">The indexer expression containing the expression returned from <see cref="BuildIndicesList"/></param>
        /// <returns></returns>
        internal static DLR.Expression BuildIndexing(AplusScope scope, DLR.Expression target, DLR.Expression indexExpression)
        {
            var execute = typeof(AbstractMonadicFunction).GetMethod("Execute");
            DLR.ParameterExpression indexes = DLR.Expression.Parameter(typeof(List<AType>), "_INDEX_");

            // (,x)
            DLR.Expression raveledRight = DLR.Expression.Call(
                DLR.Expression.Constant(MonadicFunctionInstance.Ravel),
                execute,
                target,
                scope.GetRuntimeExpression()
            );

            // (,x)[indexExpression] := ..
            DLR.Expression result =
                DLR.Expression.Convert(
                    DLR.Expression.Block(
                        new DLR.ParameterExpression[] { indexes },
                        DLR.Expression.Assign(
                            indexes,
                            DLR.Expression.Call(
                                typeof(Helpers).GetMethod("BuildIndexerArray"),
                                DLR.Expression.NewArrayInit(typeof(AType), indexExpression)
                            )
                        ),
                        DLR.Expression.Assign(
                            scope.CallbackInfo.Index,
                            DLR.Expression.Call(
                                typeof(Tools).GetMethod("ConvertATypeListToAType", BindingFlags.NonPublic | BindingFlags.Static),
                                indexes
                            )
                        ),
                        DLR.Expression.Dynamic(
                            scope.GetRuntime().GetIndexBinder(new DYN.CallInfo(1)),
                            typeof(object),
                            raveledRight,
                            indexes
                        )
                    ),
                    typeof(AType)
                );

            return result;
        }
示例#22
0
        /// <summary>
        /// Builds DLR expression for:  (iota rho argument)
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        internal static DLR.Expression BuildIndicesList(AplusScope scope, DLR.Expression argument)
        {
            DLR.ParameterExpression environment = scope.GetRuntimeExpression();
            var execute = typeof(AbstractMonadicFunction).GetMethod("Execute");

            // (iota rho x)
            DLR.Expression indexes = DLR.Expression.Call(
                DLR.Expression.Constant(MonadicFunctionInstance.Interval),
                execute,
                DLR.Expression.Call(
                    DLR.Expression.Constant(MonadicFunctionInstance.Shape),
                    execute,
                    argument,
                    environment
                ),
                environment
            );

            return indexes;
        }
示例#23
0
 internal static DLR.Expression BuildCallbackCall(AplusScope scope, DLR.ParameterExpression valueParam)
 {
     // callback
     /* 
      * CallbackItem callback;
      * if(CallbackManager.TryGetCallback(globalName, out callback)
      * {
      *     CallbackBinder.Invoke(...);
      * }
      */
     DLR.ParameterExpression callbackParameter = DLR.Expression.Parameter(typeof(CallbackItem), "__CALLBACK__");
     DLR.Expression callback = DLR.Expression.Block(
         new DLR.ParameterExpression[] { callbackParameter },
         DLR.Expression.IfThen(
             DLR.Expression.Call(
                 scope.GetRuntimeExpression().Property("CallbackManager"),
                 typeof(CallbackManager).GetMethod("TryGetCallback"),
                 scope.CallbackInfo.QualifiedName,
                 callbackParameter
             ),
             DLR.Expression.Dynamic(
         // TODO: do not instantiate the binder here
                 new Runtime.Binder.CallbackBinder(),
                 typeof(object),
                 callbackParameter,
                 scope.GetRuntimeExpression(),
                 valueParam,
                 scope.CallbackInfo.Index,
                 scope.CallbackInfo.Path
             )
         )
     );
     return callback;
 }
示例#24
0
 internal static DLR.Expression BuildPresetCallbackCall(AplusScope scope, DLR.ParameterExpression valueParam)
 {
     DLR.ParameterExpression callbackParameter = DLR.Expression.Parameter(typeof(CallbackItem), "__CALLBACK__");
     DLR.Expression callback = DLR.Expression.Block(
         new DLR.ParameterExpression[] { callbackParameter },
         DLR.Expression.Condition(
             DLR.Expression.Call(
                 scope.GetRuntimeExpression().Property("CallbackManager"),
                 typeof(CallbackManager).GetMethod("TryGetPresetCallback"),
                 scope.CallbackInfo.QualifiedName,
                 callbackParameter
             ),
             DLR.Expression.Dynamic(
         // TODO: do not instantiate the binder here
                 new Runtime.Binder.CallbackBinder(),
                 typeof(object),
                 callbackParameter,
                 scope.GetRuntimeExpression(),
                 valueParam,
                 scope.CallbackInfo.Index,
                 scope.CallbackInfo.Path
             ).To<AType>(),
             (DLR.Expression)valueParam.To<AType>()
         )
     );
     return callback;
 }
示例#25
0
        internal static DLR.Expression GenerateIdentifierAssign(
            AplusScope scope, Identifier target, DLR.Expression value, bool isStrand = false, bool needCallback = true)
        {
            Aplus runtime = scope.GetRuntime();
            DLR.Expression result = null;

            if (scope.IsMethod)
            {
                string qualifiedName = target.BuildQualifiedName(runtime.CurrentContext);

                // If the generation is inside of a method
                // check if it has the variablename as function parameter
                DLR.Expression functionParameter = scope.FindIdentifier(target.Name);
                if (functionParameter != null)
                {
                    // Found variable as a function parameter, do a simple assign
                    // the variable is already defined in AST.UserDefFunction
                    return DLR.Expression.Assign(functionParameter, value);
                }

                DLR.Expression functionScopeParam = scope.GetModuleExpression();
                DLR.Expression globalScopeParam = scope.Parent.GetModuleExpression();

                switch (target.Type)
                {
                    case IdentifierType.UnQualifiedName:
                        // Need to check if we are inside an eval block:
                        if (scope.IsEval)
                        {
                            // Code is inside an eval block, we behave slightly differently!

                            #region description about what are we doing in this case

                            //
                            // Check if the variable exists in the function's scope
                            //  |-> Exists: set that variable's value
                            //  |-> otherwise: set the global variable's value
                            //
                            // if(((IDictionary<String, Object>)($FunctionScope).ContainsKey($VARIABLE))
                            // {
                            //      $FunctionScope.$VARIABLE = $VALUE;
                            // }
                            // else
                            // {
                            //      $GlobalScope.$VARIABLE = $VALUE;
                            // }
                            //
                            #endregion

                            result = DLR.Expression.Condition(
                                // Check if the varaible exists in the function scope
                                DLR.Expression.Call(
                                    DLR.Expression.Convert(functionScopeParam, typeof(IDictionary<string, object>)),
                                    typeof(IDictionary<string, object>).GetMethod("ContainsKey"),
                                    DLR.Expression.Constant(target.Name)
                                ),
                                // found the variable in function scope, so assign a value to it
                                DLR.Expression.Block(
                                    needCallback
                                    ? DLR.Expression.Assign(scope.CallbackInfo.QualifiedName, DLR.Expression.Constant(qualifiedName))
                                    : (DLR.Expression)DLR.Expression.Empty(),
                                    DLR.Expression.Dynamic(
                                        runtime.SetMemberBinder(target.Name),
                                        typeof(object),
                                        functionScopeParam,
                                        value
                                    ),
                                    value
                                ),
                                // did NOT found the variable in the function scope
                                // perform the assignment in the global scope
                                BuildGlobalAssignment(scope, runtime, globalScopeParam, target, value, isStrand, needCallback)
                            );

                        }
                        else if (target.IsEnclosed)
                        {
                            result = BuildGlobalAssignment(scope, runtime, globalScopeParam, target, value, isStrand, needCallback);
                        }
                        else
                        {
                            // Simple case, we are inside a user defined function, but not inside an eval block
                            result =
                                DLR.Expression.Block(
                                    needCallback
                                    ? DLR.Expression.Assign(scope.CallbackInfo.QualifiedName, DLR.Expression.Constant(qualifiedName))
                                    : (DLR.Expression)DLR.Expression.Empty(),
                                    DLR.Expression.Dynamic(
                                    runtime.SetMemberBinder(target.Name),
                                    typeof(object),
                                    functionScopeParam,
                                    value
                                    )
                                );
                        }
                        break;

                    case IdentifierType.QualifiedName:
                    case IdentifierType.SystemName:
                    default:
                        // Do an assignment on the global scope
                        result = BuildGlobalAssignment(scope, runtime, globalScopeParam, target, value, isStrand, needCallback);
                        break;
                }
            }
            else
            {
                result = BuildGlobalAssignment(scope, runtime, scope.GetModuleExpression(), target, value, isStrand, needCallback);
            }


            return DLR.Expression.Convert(result, typeof(AType));
        }
示例#26
0
        private static DLR.Expression GenerateIndexAssign(AplusScope scope, Indexing target, DLR.Expression value)
        {
            DLR.Expression result;

            if (target.IndexExpression == null)
            {
                result = DLR.Expression.Dynamic(
                    scope.GetRuntime().SetIndexBinder(new DYN.CallInfo(0)),
                    typeof(object),
                    target.Item.Generate(scope),
                    DLR.Expression.Constant(null),
                    value
                );
            }
            else
            {
                IEnumerable<DLR.Expression> indexerValues = target.IndexExpression.Items.Reverse().Select(
                    item => { return item.Generate(scope); }
                );

                DLR.ParameterExpression indexerParam = DLR.Expression.Parameter(typeof(List<AType>), "__INDEX__");

                DLR.Expression call =
                    DLR.Expression.Call(
                        typeof(Helpers).GetMethod("BuildIndexerArray"),
                        DLR.Expression.NewArrayInit(typeof(AType), indexerValues)
                    );

                Aplus runtime = scope.GetRuntime();
                string qualifiedName = ((Identifier)target.Item).BuildQualifiedName(runtime.CurrentContext);
                DLR.ParameterExpression temp = DLR.Expression.Parameter(typeof(AType));
                DLR.ParameterExpression errorParam = DLR.Expression.Parameter(typeof(Error.Signal));
                DLR.Expression callback = BuildCallbackCall(scope, temp);
                DLR.Expression presetCallback = BuildPresetCallbackCall(scope, temp);

                result =
                    DLR.Expression.Block(
                        new DLR.ParameterExpression[] { indexerParam, temp },
                        DLR.Expression.Assign(
                            indexerParam,
                            call
                        ),
                        DLR.Expression.Assign(
                            scope.CallbackInfo.Index,
                            DLR.Expression.Call(
                                typeof(Tools).GetMethod("ConvertATypeListToAType", BindingFlags.NonPublic | BindingFlags.Static),
                                indexerParam
                            )
                        ),
                        DLR.Expression.Assign(
                                scope.CallbackInfo.QualifiedName,
                                DLR.Expression.Constant(qualifiedName)
                        ),
                        DLR.Expression.Assign(temp, value),
                        DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(false)),
                        DLR.Expression.TryCatch(
                            DLR.Expression.Block(
                                typeof(void),
                                DLR.Expression.Assign(value, presetCallback),
                                DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(true))
                            ),
                            DLR.Expression.Catch(
                                errorParam,
                                DLR.Expression.Empty()
                            )
                        ),
                        DLR.Expression.IfThen(
                            scope.AssignDone,
                            DLR.Expression.Block(
                                DLR.Expression.Dynamic(
                                    scope.GetRuntime().SetIndexBinder(new System.Dynamic.CallInfo(target.IndexExpression.Length)),
                                    typeof(object),
                                    target.Item.Generate(scope),
                                    indexerParam,
                                    value
                                ),
                                DLR.Expression.Assign(temp, value),
                                callback
                            )
                        ),
                        scope.CallbackInfo.NonPresetValue
                    );

            }
            return DLR.Expression.Convert(result, typeof(AType));
        }
示例#27
0
        /// <summary>Generates a DLR Expression for Strand assignment.</summary>
        /// <remarks>
        ///  Transform this:
        /// (a;b;...) := .....    // don't care what is there :)
        /// 
        /// to this in DLR:
        /// 
        /// $__VALUES__ = (AType) .....; // ..... is a generated DLR expression now!
        /// 
        /// if($__VALUES__.IsArray)     // case A
        /// {
        ///     if($VALUES.length != 2)  // 2 the # of targets
        ///     {
        ///         throw new Error.Length("assign");
        ///     }
        ///     
        ///     a = disclose( ((AArray)$__VALUES__)[0] );
        ///     b = disclose( ((AArray)$__VALUES__)[1] );
        ///     ...
        /// }
        /// else    // case B
        /// {
        ///     // need to disclose the box
        ///     if($__VALUES__.Type == ATypes.Box)
        ///     {
        ///         $__VALUES__ = disclose($__VALUES__);
        ///     }
        ///     a = $VALUES.Clone();
        ///     b = $VALUES.Clone();
        ///     ...
        /// }
        /// $__DependencyManager__.InvalidateDependencies(string[] { a,b, .. })
        /// $__DependencyManager__.ValidateDependencies(string[] { a,b, .. })
        /// </remarks>
        /// <param name="scope"></param>
        /// <param name="targets">
        /// Strand containing Identifiers.
        /// If a node which in not an Identifier found, ParseException is thrown
        /// </param>
        /// <param name="value">The generated value which will be assigned to the targets</param>
        /// <returns>A generated DLR expression for strand assignment</returns>
        private static DLR.Expression GenerateStrandAssign(AplusScope scope, Strand targets, DLR.Expression value)
        {
            AbstractMonadicFunction disclose = MonadicFunctionInstance.Disclose;
            Aplus runtime = scope.GetRuntime();
            DLR.ParameterExpression environment = scope.GetRuntimeExpression();

            DLR.ParameterExpression valuesParam = DLR.Expression.Parameter(typeof(AType), "__VALUES__");
            // for dependency evaluation
            List<string> targetVariables = new List<string>();

            // for case A) assigns
            List<DLR.Expression> strand2StrandAssigns = new List<DLR.Expression>();
            // for case B) assigns
            List<DLR.Expression> strand2ValueAssigns = new List<DLR.Expression>()
            {
                DLR.Expression.Assign(
                    valuesParam,
                    DLR.Expression.Call(
                        DLR.Expression.Constant(disclose),
                        disclose.GetType().GetMethod("Execute"),
                        valuesParam,
                        environment
                    )
                )
            };

            int indexCounter = 0;

            foreach (Node node in targets.Items)
            {
                if (!(node is Identifier))
                {
                    throw new ParseException("assign lhs");
                }
                Identifier id = (Identifier)node;

                DLR.Expression strandValue =
                    DLR.Expression.Call(
                        DLR.Expression.Constant(disclose),
                        disclose.GetType().GetMethod("Execute"),
                        DLR.Expression.MakeIndex(
                            valuesParam,
                            typeof(AType).GetIndexerProperty(typeof(int)), // The indexer property which will be used
                            new DLR.Expression[] { DLR.Expression.Constant(indexCounter, typeof(int)) }
                        ),
                        environment
                );

                // case A) $TARGETS[i] = disclose($VALUES[i])
                strand2StrandAssigns.Add(GenerateIdentifierAssign(scope, id, strandValue, isStrand: true));

                // case B) $TARGETS[i] = $VALUE.Clone()
                strand2ValueAssigns.Add(
                    GenerateIdentifierAssign(
                        scope,
                        id,
                        DLR.Expression.Condition(
                            DLR.Expression.Property(valuesParam, "IsMemoryMappedFile"),
                            valuesParam,
                            DLR.Expression.Call(
                                valuesParam,
                                typeof(AType).GetMethod("Clone")
                            )
                        ),
                        isStrand: true
                    )
                );

                // gather the global variables for dependency validation/invalidation. 
                if ((scope.IsMethod && id.IsEnclosed) || !scope.IsMethod)
                {
                    targetVariables.Add(id.BuildQualifiedName(runtime.CurrentContext));
                }

                indexCounter++;
            }

            // case A)
            DLR.Expression caseStrand2Strand =
                DLR.Expression.IfThenElse(
                    DLR.Expression.NotEqual(
                        DLR.Expression.PropertyOrField(valuesParam, "Length"),
                        DLR.Expression.Constant(indexCounter, typeof(int))
                    ),
                    DLR.Expression.Throw(
                        DLR.Expression.New(
                            typeof(Error.Length).GetConstructor(new Type[] { typeof(string) }),
                            DLR.Expression.Constant("assign", typeof(string))
                        )
                    ),
                    DLR.Expression.Block(strand2StrandAssigns)
            );

            DLR.Expression dependencyManager = DLR.Expression.Property(scope.GetRuntimeExpression(), "DependencyManager");

            DLR.Expression result = DLR.Expression.Block(
                new DLR.ParameterExpression[] { valuesParam },
                DLR.Expression.Assign(valuesParam, DLR.Expression.Convert(value, typeof(AType))),
                DLR.Expression.IfThenElse(
                    DLR.Expression.PropertyOrField(valuesParam, "IsArray"),
                // case A)
                    caseStrand2Strand,
                // case B)
                    DLR.Expression.Block(strand2ValueAssigns)
                ),
                DLR.Expression.Call(
                    dependencyManager,
                    typeof(DependencyManager).GetMethod("InvalidateDependencies", new Type[] { typeof(string[]) }),
                    DLR.Expression.Constant(targetVariables.ToArray())
                ),
                DLR.Expression.Call(
                    dependencyManager,
                    typeof(DependencyManager).GetMethod("ValidateDependencies"),
                    DLR.Expression.Constant(targetVariables.ToArray())
                ),
                valuesParam
            );

            return DLR.Expression.Block(result, DLR.Expression.Assign(scope.CallbackInfo.NonPresetValue, value));
        }
示例#28
0
 /*!*/
 private static MSAst.Expression AddDefaultReturn(MSAst.Expression/*!*/ body, Type returnType)
 {
     if (body.Type == typeof(void) && returnType != typeof(void))
     {
         body = Ast.Block(body, ConstantExpression.Undefined);
     }
     return body;
 }
示例#29
0
        private static DLR.Expression BuildGlobalAssignment(
            AplusScope scope,
            Aplus runtime,
            DLR.Expression variableContainer,
            Identifier target,
            DLR.Expression value,
            bool isStrand = false,
            bool needCallback = true
            )
        {
            // Build the ET for updating the dependency
            DLR.Expression dependencyCall;
            string qualifiedName = target.BuildQualifiedName(runtime.CurrentContext);

            if (isStrand)
            {
                // We are inside a starnd assignment, do nothing.
                // Dependency update will be handled later.
                dependencyCall = DLR.Expression.Empty();
            }
            else
            {
                // Otherwise build the dependency invalidation call.
                DLR.Expression dependencyManager = DLR.Expression.Property(scope.GetRuntimeExpression(), "DependencyManager");
                dependencyCall = DLR.Expression.Call(
                    dependencyManager,
                    typeof(DependencyManager).GetMethod("InvalidateDependencies", new Type[] { typeof(string) }),
                    DLR.Expression.Constant(qualifiedName)
                );
            }

            DLR.ParameterExpression errorParam = DLR.Expression.Parameter(typeof(Error.Signal), "__ERRORPARAM__");
            DLR.ParameterExpression valueParam = DLR.Expression.Parameter(typeof(AType), "__VALUEPARAMETER__");
            scope.AssignDone = (scope.AssignDone == null) ? DLR.Expression.Parameter(typeof(bool), "__ASSIGNDONE__") : scope.AssignDone;

            DLR.Expression presetCallback = BuildPresetCallbackCall(scope, valueParam);
            DLR.Expression callback = BuildCallbackCall(scope, valueParam);

            DLR.Expression variableSet =
                DLR.Expression.Block(
                        VariableHelper.SetVariable(
                            runtime,
                            variableContainer,
                            target.CreateContextNames(runtime.CurrentContext),
                            valueParam
                        ),
                        dependencyCall
                    );

            DLR.Expression codebody;

            if (needCallback)
            {
                codebody =
                    DLR.Expression.Block(
                        typeof(void),
                        DLR.Expression.Assign(scope.CallbackInfo.QualifiedName, DLR.Expression.Constant(qualifiedName)),
                        DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(false)),
                        DLR.Expression.TryCatch(
                            DLR.Expression.Block(
                                typeof(void),
                                DLR.Expression.Assign(valueParam, presetCallback),
                                DLR.Expression.Assign(scope.AssignDone, DLR.Expression.Constant(true))
                            ),
                            DLR.Expression.Catch(
                                errorParam,
                                DLR.Expression.Empty()
                            )
                        ),
                        DLR.Expression.IfThen(
                            scope.AssignDone,
                            DLR.Expression.Block(
                                variableSet,
                                callback
                            )
                        )
                    );
            }
            else
            {
                codebody = variableSet;
            }

            // value assignment
            DLR.Expression result = DLR.Expression.Block(
                new DLR.ParameterExpression[] { valueParam },
                DLR.Expression.Assign(valueParam, value),
                codebody,
                valueParam
            );

            return result;
        }
示例#30
0
 private void InitializeParameters(List<MSAst.Expression> init, MSAst.Expression[] parameters)
 {
     for (int i = 0; i < _parameters.Length; i++)
     {
         Parameter p = _parameters[i];
         init.Add(
             AssignValue(
                 GetVariableExpression(p.TotemVariable),
                 AstUtils.LightDynamic(
                     TotemContext.GetIndex(1),
                     parameters[1],
                     Ast.Constant(i)
                 )
             )
         );
     }
 }