Example #1
0
        public void TestFunRecursion()
        {
            var var = new TypeVariable();

            var input = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var, new FunType(new List <DataType>()
                    {
                        IntType.Instance
                    }, var) }
            };

            var expectedType = new FunType(new List <DataType>()
            {
                IntType.Instance
            }, null);

            expectedType.ResultType = expectedType;

            var output = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var, expectedType }
            };

            CheckOutput(input, output);
        }
Example #2
0
 private DataType ResolveCall(
     Application c,
     DataType fun,
     List <DataType> pos,
     IDictionary <string, DataType> hash,
     DataType kw,
     DataType star)
 {
     if (fun is FunType)
     {
         FunType ft = (FunType)fun;
         return(Apply(analyzer, ft, pos, hash, kw, star, c));
     }
     else if (fun is ClassType)
     {
         var instance = new InstanceType(fun);
         ApplyConstructor(analyzer, instance, c, pos);
         return(instance);
     }
     else
     {
         AddWarning(c, "calling non-function and non-class: " + fun);
         return(DataType.Unknown);
     }
 }
Example #3
0
 public void AddUncalled(FunType cl)
 {
     if (cl.Definition != null && !cl.Definition.called)
     {
         uncalled.Add(cl);
     }
 }
Example #4
0
        public void TestArrayRecursion()
        {
            var var0 = new TypeVariable();
            var var1 = new TypeVariable();
            var var2 = new TypeVariable();

            var rhs = new FunType(
                new List <DataType>()
            {
                BoolType.Instance,
                new ArrayType(new ArrayType(var1)),
                BoolType.Instance
            },
                IntType.Instance);

            var input = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var0, new FunType(new List <DataType>(), var1) },
                { var1, new ArrayType(var2) },
                { var2, new FunType(new List <DataType>()
                    {
                        var0
                    }, UnitType.Instance) }
            };

            CheckThrows(input);
        }
Example #5
0
        /// <summary>
        /// 解包协议
        /// </summary>
        /// <param name="buffer">待解包的数组</param>
        /// <param name="startSit">ASDU起始位置</param>
        /// <param name="lenth">长度</param>
        /// <returns></returns>
        public TransRes UnPack(byte[] buffer, int startSit, int lenth)
        {
            if ((lenth + startSit > buffer.Length) || (lenth - startSit < 4))
            {
                return(TransRes.UnDef);
            }
            this.type     = (FunType)buffer[startSit];
            this.sqn      = buffer[startSit + 1];
            this.transRes = buffer[startSit + 2];
            this.apduAddr = buffer[startSit + 4];
            TransRes res = this.GetTransRes(this.transRes);

            switch (res)
            {
            case TransRes.ResAll:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case TransRes.AutoSend:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case TransRes.ActiveEnd:
                break;

            case TransRes.Active:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case TransRes.ActiveConfirm:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case ASDUClass.TransRes.Res001:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case ASDUClass.TransRes.Res002:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case ASDUClass.TransRes.Res003:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case ASDUClass.TransRes.Res004:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            case ASDUClass.TransRes.Telecontrolling:
                GetDataUnpack(buffer, startSit + 6, lenth - 6);
                break;

            default:
                return(TransRes.UnDef);
            }
            return(res);
        }
Example #6
0
        private void ResetMainText(List <RunModel> runModel)
        {
            runs = GetRuns(Title, FunType.ToString(), tbMain, runModel);

            tbMain.Inlines.Clear();
            foreach (var item in runs)
            {
                tbMain.Inlines.Add(item);
            }
        }
Example #7
0
        /// <summary>
        /// 打包
        /// </summary>
        /// <param name="active">激活/行动类型(传输原因)</param>
        /// <param name="funType">功能(数据类型)</param>
        public void Pack(TransRes active, FunType funType)
        {
            switch (active)
            {
            case TransRes.Active:
            {
                switch (funType)
                {
                case FunType.ClockConfirm:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type     = funType;
                    this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = 0, Time = DateTime.Now
                        });
                    break;

                case FunType.CalAll:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type     = funType;
                    this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = 0, Data = 0x14
                        });
                    break;

                case FunType.CalEnergyPulse:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type     = funType;
                    this.apduAddr = 1;              //0x6401
                    this.data.Add(new DataStruct()
                        {
                            Addr = 0, Data = 0x05
                        });
                    break;
                }
            }
            break;

            case TransRes.ActiveEnd:
                break;

            case TransRes.ActiveStop:
                break;

            default:
                break;
            }
        }
Example #8
0
    public static IEnumerator Flash(Text text, Color st, Color ed, float time, FunType t = FunType.X)
    {
        float delta = Mathf.Min(1, Time.fixedDeltaTime / time), p = 0;

        while (p < 1)
        {
            p         += delta;
            text.color = new Color(FixFun(t, st.r, ed.r, p), FixFun(t, st.g, ed.g, p), FixFun(t, st.b, ed.b, p), FixFun(t, st.a, ed.a, p));
            yield return(new WaitForFixedUpdate());
        }
    }
Example #9
0
        public DataType VisitLambda(Lambda lambda)
        {
            State env = scope.getForwarding();
            var   fun = new FunType(lambda, env);

            fun.Table.Parent = this.scope;
            fun.Table.Path   = scope.extendPath(analyzer, "{lambda}");
            fun.setDefaultTypes(ResolveList(lambda.args.Select(p => p.test)));
            analyzer.AddUncalled(fun);
            return(fun);
        }
Example #10
0
        public static byte[] BuildMessage(int taskId, TransportType transportType, FunType funType, string mac, byte[] content)
        {
            var buffer = Unpooled.Buffer(100);

            try
            {
                // start sign
                buffer.WriteByte(LoraConst.StartSign);
                // task sn
                buffer.WriteByte(taskId);
                // msg sn
                buffer.WriteByte(SearialUtil.GetSerial(mac));
                // ttl
                buffer.WriteByte(0);
                // 通信方式
                // 0x81 - 以太网,  0x82 - GPRS , 0x83 - NBIOT
                buffer.WriteByte((int)transportType);
                // 时间戳
                buffer.WriteInt(TimestampUtil.GetUtcSecondsStamp());
                // 控制命令 心跳 - 0x4064
                buffer.WriteShort((int)funType);
                // src mac - 6B
                var macBytes = BytesUtil.Hex2Bytes(mac);
                buffer.WriteBytes(macBytes);
                // dst mac
                buffer.WriteBytes(macBytes);
                // content length
                if (content != null)
                {
                    buffer.WriteShort(content.Length);
                    buffer.WriteBytes(content);
                }
                else
                {
                    buffer.WriteShort(0);
                }

                var validatingData = new byte[buffer.ReadableBytes];
                buffer.GetBytes(buffer.ReaderIndex, validatingData);
                // crc
                var crc = CRC16.calcCrc16(validatingData);
                buffer.WriteShort(crc);

                var msg = new byte[buffer.ReadableBytes];
                buffer.ReadBytes(msg);
                return(msg);
            }
            finally
            {
                buffer.Release();
            }
        }
Example #11
0
        static void AddReadOnlyAttr(
            Analyzer analyzer,
            FunType fun,
            string name,
            DataType type,
            BindingKind kind)
        {
            Node    loc = Builtins.newDataModelUrl("the-standard-type-hierarchy");
            Binding b   = analyzer.CreateBinding(name, loc, type, kind);

            fun.Table.Update(name, b);
            b.IsSynthetic = true;
            b.IsStatic    = true;
        }
Example #12
0
 static void BindMethodAttrs(Analyzer analyzer, FunType cl)
 {
     if (cl.Table.Parent != null)
     {
         DataType cls = cl.Table.Parent.Type;
         if (cls != null && cls is ClassType)
         {
             AddReadOnlyAttr(analyzer, cl, "im_class", cls, BindingKind.CLASS);
             AddReadOnlyAttr(analyzer, cl, "__class__", cls, BindingKind.CLASS);
             AddReadOnlyAttr(analyzer, cl, "im_self", cls, BindingKind.ATTRIBUTE);
             AddReadOnlyAttr(analyzer, cl, "__self__", cls, BindingKind.ATTRIBUTE);
         }
     }
 }
Example #13
0
        public DataType VisitFunctionDef(FunctionDef f)
        {
            State   env = scope.getForwarding();
            FunType fun = new FunType(f, env);

            fun.Table.Parent = this.scope;
            fun.Table.Path   = scope.extendPath(analyzer, f.name.Name);
            fun.setDefaultTypes(ResolveList(f.parameters
                                            .Where(p => p.test != null)
                                            .Select(p => p.test)));
            analyzer.AddUncalled(fun);
            BindingKind funkind;

            if (scope.stateType == State.StateType.CLASS)
            {
                if ("__init__" == f.name.Name)
                {
                    funkind = BindingKind.CONSTRUCTOR;
                }
                else
                {
                    funkind = BindingKind.METHOD;
                }
            }
            else
            {
                funkind = BindingKind.FUNCTION;
            }

            DataType outType = scope.Type;

            if (outType is ClassType)
            {
                fun.Class = ((ClassType)outType);
            }

            scope.Bind(analyzer, f.name, fun, funkind);

            var sOld = this.scope;

            this.scope = fun.Table;
            f.body.Accept(this);
            this.scope = sOld;

            return(DataType.Cont);
        }
Example #14
0
 public static DataType FirstArgumentType(FunctionDef f, FunType func, DataType selfType)
 {
     if (f.parameters.Count == 0)
     {
         return(null);
     }
     if (!func.Definition.IsStaticMethod())
     {
         if (func.Definition.IsClassMethod())
         {
             if (func.Class != null)
             {
                 return(func.Class);
             }
             else if (selfType != null && selfType is InstanceType inst)
             {
                 return(inst.classType);
             }
         }
         else
         {
             // usual method
             if (selfType != null)
             {
                 return(selfType);
             }
             else
             {
                 if (func.Class != null)
                 {
                     if (func.Definition.name.Name != "__init__")
                     {
                         throw new NotImplementedException("return func.Class.getInstance(null, this, call));");
                     }
                     else
                     {
                         return(func.Class.GetInstance());
                     }
                 }
             }
         }
     }
     return(null);
 }
Example #15
0
        public ILabel GenerateClosureCall(
            ILocation result,
            IEnumerable <VirtualRegister> callArguments,
            ILabel onReturn,
            Function.Function callerFunction,
            FunType funType,
            VirtualRegister funPtr)
        {
            var needStackOffset = funType.GetStackArgumentsCount() % 2 == 1 ? 8 : 0;
            var funPtrRead      = new RegisterRead(funPtr);
            var funCodePtr      = new MemoryRead(
                new ArithmeticBinaryOperation(AST.ArithmeticOperationType.Addition, funPtrRead, new IntegerImmediateValue(0)));
            var funClosurePtr = new MemoryRead(
                new ArithmeticBinaryOperation(AST.ArithmeticOperationType.Addition, funPtrRead, new IntegerImmediateValue(16)));
            var preCall = new List <Node>
            {
                new AlignStackPointer(needStackOffset)
            }
            .Append(new Comment("Pass arguments"))
            .Concat(this.PassClosureArguments(callArguments, funClosurePtr))
            .Append(new ClearDF())
            .Append(new Comment($"Call closure function"))
            .Append(
                new UsesDefinesNode(
                    HardwareRegisterUtils.ArgumentRegisters.Take(callArguments.Count() + 1).ToList(),
                    HardwareRegisterUtils.CallerSavedRegisters))
            .Append(new RegisterWrite(HardwareRegister.RAX, funCodePtr));

            var postCall = new List <Node>
            {
                new Comment("Copy function result to variable"),
                this.readWriteGenerator.GenerateWrite(callerFunction, result, new RegisterRead(HardwareRegister.RAX)),
                new Comment("Restore RSP alignment"),
                new AlignStackPointer(-(needStackOffset + (8 * funType.GetStackArgumentsCount()))),
                new Comment("End of call"),
            };

            var controlFlow = new ComputedFunctionCall(postCall.MakeTreeChain(this.labelFactory, onReturn));

            return(preCall.MakeTreeChain(this.labelFactory, controlFlow));
        }
Example #16
0
        public void TestUninstantiated()
        {
            var var0 = new TypeVariable();
            var var1 = new TypeVariable();

            var rhs = new FunType(
                new List <DataType>()
            {
                BoolType.Instance,
                new ArrayType(new ArrayType(var1)),
                BoolType.Instance
            },
                IntType.Instance);

            var input = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var0, rhs }
            };

            CheckThrows(input);
        }
Example #17
0
        public static string Format(string str, FunType funType, FunFormat funFormat)
        {
            if (funType != FunType.Null)
            {
                string formatstring = "YYYY-MM-DD";
                if (funFormat == FunFormat.YYYYMM)
                {
                    formatstring = "YYYY-MM";
                }
                else if (funFormat == FunFormat.YYYYMMDDHH24MI)
                {
                    formatstring = "YYYY-MM-DD HH24:MI";
                }
                else if (funFormat == FunFormat.YYYYMMDDHH24MISS)
                {
                    formatstring = "YYYY-MM-DD HH24:MI:SS";
                }

                return(string.Format(" {0}({1},'{2}')", funType.ToString(), str, formatstring));
            }
            return(str);
        }
Example #18
0
 private (CodeTypeReference, ISet <string>) TranslateFunc(FunType fun)
 {
     if (fun.arrows.Count != 0)
     {
         // Pick an arrow at random.
         var arrow = fun.arrows.First();
         var(args, nms) = Translate(arrow.Key);
         var s = arrow.Value.GetType().Name;
         if (arrow.Value is InstanceType i && i.classType is ClassType c && c.name == "None")
         {
             return(
                 new CodeTypeReference("Action", args),
                 Join(nms, SystemNamespace));
         }
         else
         {
             var(ret, nmsRet) = Translate(arrow.Value);
             return(
                 new CodeTypeReference("Func", args),
                 Join(nms, Join(nmsRet, SystemNamespace)));
         }
     }
Example #19
0
        public void TestNested()
        {
            var var0 = new TypeVariable();
            var var1 = new TypeVariable();
            var var2 = new TypeVariable();

            var input = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var0, new FunType(new List <DataType>(), new FunType(new List <DataType>(), var1)) },
                { var1, new ArrayType(new ArrayType(new ArrayType(var2))) },
                { var2, IntType.Instance }
            };

            var output2 = IntType.Instance;
            var output1 = new ArrayType(new ArrayType(new ArrayType(output2)));
            var output0 = new FunType(new List <DataType>(), new FunType(new List <DataType>(), output1));

            var output = new Dictionary <TypeVariable, IHerbrandObject>()
            {
                { var0, output0 }, { var1, output1 }, { var2, output2 }
            };

            CheckOutput(input, output);
        }
Example #20
0
    //将size从startsize到endsize的平滑移动,这里的step是百分比
    public static float FixFun(FunType type, float startsize, float endsize, float step)
    {
        //if (startsize > endsize)//若是下降形式,那么将其反向处理,转成上升
        //{
        //	float tmp = startsize;
        //	startsize = endsize;
        //	endsize = tmp;
        //	step = 1 - step;
        //}
        //保证startsize < endsize且step在(0,1)
        switch (type)
        {
        case FunType.X: { return(startsize + (endsize - startsize) * step); }; break;

        case FunType.X2: { return(startsize + (endsize - startsize) * step * step); } break;

        case FunType.LogX: { return(startsize + (endsize - startsize) * Mathf.Log(step)); }; break;

        case FunType.SqrtX: { return(startsize + (endsize - startsize) * Mathf.Sqrt(step)); } break;

        default: Debug.LogAssertion("Wrong FunType!"); break;
        }
        return(0);
    }
Example #21
0
        //Перевод типа функции в строку
        public static string ToString(this FunType f)
        {
            switch (f)
            {
            case FunType.Scalar:
                return("Scalar");

            case FunType.CalcData:
                return("CalcData");

            case FunType.Moments:
                return("Moments");

            case FunType.Operator:
                return("Operator");

            case FunType.Const:
                return("Const");

            case FunType.ScalarObject:
                return("ScalarObject");

            case FunType.Object:
                return("Object");

            case FunType.ScalarComplex:
                return("ScalarComplex");

            case FunType.Val:
                return("Val");

            case FunType.Calc:
                return("Calc");
            }
            return("Val");
        }
Example #22
0
 public void AddUncalled(FunType cl)
 {
     if (cl.Definition != null && !cl.Definition.called)
     {
         uncalled.Add(cl);
     }
 }
Example #23
0
 public static void BetweenAnd <T>(T value1, T value2, string fieldName, FunType funType, FunFormat funFormat, List <IDbDataParameter> paramList)
 {
     Add(value1, value2, fieldName, funType, funFormat, paramList);
 }
Example #24
0
 FunType newFunc(DataType type)
 {
     if (type == null)
     {
         type = DataType.Unknown;
     }
     var fun = new FunType(DataType.Unknown, type);
     fun.Table.addSuper(analyzer.Builtins.BaseFunction.Table);
     fun.Table.Path = analyzer.Builtins.BaseFunction.Table.Path;
     return fun;
 }
Example #25
0
        public static void Add <T>(T value, string fieldName, FunType funType, FunFormat funFormat, IDbCommand cmd, OperateType operateType)
        {
            if (value != null)
            {
                string           str;
                IDbDataParameter parameter;
                string           str2;
                string           str3 = Regex.Replace(fieldName, "[.,\\(\\)\\s]", "", RegexOptions.IgnoreCase);


                switch (operateType)
                {
                case OperateType.NotEqual:
                    str2 = string.Format(":{0}", str3);
                    str  = string.Format(" AND {0}<>{1}", fieldName, Format(str2, funType, funFormat));
                    break;

                case OperateType.Min:
                    str2 = string.Format(":Min{0}", str3);
                    str  = string.Format(" AND {0}>={1}", fieldName, Format(str2, funType, funFormat));
                    break;

                case OperateType.Max:
                    str2 = string.Format(":Max{0}", str3);
                    str  = string.Format(" AND {0}<={1}", fieldName, Format(str2, funType, funFormat));
                    break;

                case OperateType.Like:
                    str2 = string.Format(":{0}", str3);
                    str  = string.Format(" AND {0} like '%'||{1}||'%'", fieldName, Format(str2, funType, funFormat));
                    break;

                case OperateType.Or:
                    str2 = string.Format(":{0}", str3);
                    str  = string.Format(" Or {0}={1}", fieldName, Format(str2, funType, funFormat));
                    break;

                case OperateType.IsNull:
                    str2 = string.Format(":{0}", str3);
                    str  = string.Format(" AND {0} IS NULL", fieldName);
                    break;

                default:
                    str2 = string.Format(":{0}", str3);
                    str  = string.Format(" AND {0}={1}", fieldName, Format(str2, funType, funFormat));
                    break;
                }
                if (operateType != OperateType.IsNull)
                {
                    if (value.GetType() == typeof(string))
                    {
                        object obj2 = value;
                        if (string.IsNullOrEmpty((string)obj2))
                        {
                            Conditions.Add("");
                            return;
                        }
                        parameter = Driver.GenerateParameter(str2, (DbType)13);
                    }
                    else if (value.GetType() == typeof(int))
                    {
                        parameter = Driver.GenerateParameter(str2, (DbType)2);
                    }
                    else if (value.GetType() == typeof(float))
                    {
                        parameter = Driver.GenerateParameter(str2, (DbType)2);
                    }
                    else if (value.GetType() == typeof(DateTime))
                    {
                        parameter = Driver.GenerateParameter(str2, (DbType)11);
                    }
                    else
                    {
                        if (value.GetType() != typeof(decimal))
                        {
                            throw new Exception("不支持的参数类型");
                        }
                        parameter = Driver.GenerateParameter(str2, (DbType)7);
                    }
                    parameter.Value = value;
                    cmd.Parameters.Add(parameter);
                }
                //sqltext.Replace("{0}", str.ToString());
                Conditions.Add(str);
            }
        }
Example #26
0
        //for between...and
        public static void Add <T>(T value1, T value2, string fieldName, FunType funType, FunFormat funFormat, IDbCommand cmd)
        {
            if (value1 != null && value2 != null)
            {
                IDbDataParameter parameter1;
                IDbDataParameter parameter2;
                string           str1 = fieldName.Replace('.', '_') + "_1";
                string           str2 = string.Format(":{0}", str1);
                string           str3 = fieldName.Replace('.', '_') + "_2";
                string           str4 = string.Format(":{0}", str3);
                string           str  = string.Format(" AND {0} BETWEEN {1} AND {2}", fieldName, str2, str4);
                if (funType != FunType.Null)
                {
                    string formatstring = "YYYY-MM-DD";
                    if (funFormat == FunFormat.YYYYMM)
                    {
                        formatstring = "YYYY-MM";
                    }
                    else if (funFormat == FunFormat.YYYYMMDDHH24MI)
                    {
                        formatstring = "YYYY-MM-DD HH24:MI";
                    }
                    else if (funFormat == FunFormat.YYYYMMDDHH24MISS)
                    {
                        formatstring = "YYYY-MM-DD HH24:MI:SS";
                    }

                    str = string.Format(" AND {0} BETWEEN {1}({2},'{3}') AND {1}({4},'{3}')", fieldName, funType.ToString(), str2, formatstring, str4);
                }
                if (value1.GetType() == typeof(string) && value2.GetType() == typeof(string))
                {
                    object obj1 = value1;
                    object obj2 = value2;
                    if (string.IsNullOrEmpty((string)obj1) || string.IsNullOrEmpty((string)obj2))
                    {
                        Conditions.Add("");
                        return;
                    }
                    parameter1 = Driver.GenerateParameter(str2, (DbType)13);
                    parameter2 = Driver.GenerateParameter(str4, (DbType)13);
                }
                else if (value1.GetType() == typeof(int) && value2.GetType() == typeof(int))
                {
                    parameter1 = Driver.GenerateParameter(str2, (DbType)2);
                    parameter2 = Driver.GenerateParameter(str4, (DbType)2);
                }
                else if (value1.GetType() == typeof(float) && value2.GetType() == typeof(float))
                {
                    parameter1 = Driver.GenerateParameter(str2, (DbType)2);
                    parameter2 = Driver.GenerateParameter(str4, (DbType)2);
                }
                else if (value1.GetType() == typeof(DateTime) && value2.GetType() == typeof(DateTime))
                {
                    parameter1 = Driver.GenerateParameter(str2, (DbType)11);
                    parameter2 = Driver.GenerateParameter(str4, (DbType)11);
                }
                else
                {
                    if (value1.GetType() != typeof(decimal) || value2.GetType() != typeof(decimal))
                    {
                        throw new Exception("不支持的参数类型");
                    }
                    parameter1 = Driver.GenerateParameter(str2, (DbType)7);
                    parameter2 = Driver.GenerateParameter(str4, (DbType)7);
                }
                parameter1.Value = value1;
                parameter2.Value = value2;
                cmd.Parameters.Add(parameter1);
                cmd.Parameters.Add(parameter2);
                //sqltext.Replace("{0}", str.ToString());
                Conditions.Add(str);
            }
        }
Example #27
0
        /// <summary>
        /// Called when an application of a function is encountered.
        /// </summary>
        //$TODO: move to Analyzer.
        public static DataType Apply(
            Analyzer analyzer,
            FunType func,
            List <DataType> pos,
            IDictionary <string, DataType> hash,
            DataType kw,
            DataType star,
            Exp call)
        {
            analyzer.RemoveUncalled(func);

            if (func.Definition != null && !func.Definition.called)
            {
                analyzer.CalledFunctions++;
                func.Definition.called = true;
            }

            if (func.Definition == null)
            {
                // func without definition (possibly builtins)
                return(func.GetReturnType());
            }
            else if (call != null && analyzer.InStack(call))
            {
                // Recursive call, ignore.
                func.SelfType = null;
                return(DataType.Unknown);
            }

            if (call != null)
            {
                analyzer.pushStack(call);
            }

            var pTypes = new List <DataType>();

            // Python: bind first parameter to self type
            if (func.SelfType != null)
            {
                pTypes.Add(func.SelfType);
            }
            else if (func.Class != null)
            {
                pTypes.Add(func.Class.getCanon());
            }

            if (pos != null)
            {
                pTypes.AddRange(pos);
            }

            BindMethodAttrs(analyzer, func);

            State funcTable = new State(func.env, State.StateType.FUNCTION);

            if (func.Table.Parent != null)
            {
                funcTable.Path = func.Table.Parent.ExtendPath(analyzer, func.Definition.name.Name);
            }
            else
            {
                funcTable.Path = func.Definition.name.Name;
            }

            DataType fromType = BindParameters(analyzer,
                                               call, func.Definition, funcTable, func.Definition.parameters,
                                               func.Definition.vararg, func.Definition.kwarg,
                                               pTypes, func.defaultTypes, hash, kw, star);

            if (func.arrows.TryGetValue(fromType, out var cachedTo))
            {
                func.SelfType = null;
                return(cachedTo);
            }
            else
            {
                DataType toType = func.Definition.body.Accept(new TypeTransformer(funcTable, analyzer));
                if (MissingReturn(toType))
                {
                    analyzer.putProblem(func.Definition.name, "Function doesn't always return a value");
                    if (call != null)
                    {
                        analyzer.putProblem(call, "Call doesn't always return a value");
                    }
                }

                toType = UnionType.remove(toType, DataType.Cont);
                func.addMapping(fromType, toType);
                func.SelfType = null;
                return(toType);
            }
        }
Example #28
0
        /// <summary>
        /// 打包
        /// </summary>
        /// <param name="active">激活/行动类型(传输原因)</param>
        /// <param name="funType">功能(数据类型)</param>
        public void Pack(TransRes active, FunType funType, int?addr = null, double dValue = 0.0, byte qds = (byte)0)
        {
            switch (active)
            {
            case TransRes.Active:
            {
                switch (funType)
                {
                case FunType.ClockConfirm:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    //this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Time = DateTime.Now
                        });
                    break;

                case FunType.CalAll:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    //this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    //this.data.Add(new DataStruct(0, new byte[4]{0x14, 0, 0, 0}, 0, 4));
                    break;
                }
            }
            break;

            case TransRes.ActiveEnd:
                break;

            case TransRes.ActiveStop:
            {
                switch (funType)
                {
                case FunType.CalAll:
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    //this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    //this.data.Add(new DataStruct(0, new byte[4]{0x14, 0, 0, 0}, 0, 4));
                    break;
                }
            }
            break;

            case TransRes.ActiveConfirm:
            {
                switch (funType)
                {
                case FunType.CalAll:
                    this.sqn = 1;
                    this.SetTransRes(false, false, TransRes.ActiveConfirm);
                    this.type = funType;
                    //this.apduAddr = 1;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    //this.data.Add(new DataStruct(0, new byte[4] { 0x14, 0, 0, 0 }, 0, 4));
                    break;
                }
            }
            break;

            case TransRes.Res001:       //Group 1
            {
                switch (funType)
                {
                case FunType.CalAll:             //下行
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    break;

                case FunType.FloatMValue:                                 //上行
                    //遥测信息+品质描述词
                    this.sqn = (byte)(Convert.ToByte("10000000", 2) + 3); //3个连续信息体
                    this.SetTransRes(false, false, TransRes.Res001);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = dValue
                        });
                    DataStruct temp = this.data[this.data.Count - 1];
                    temp.DataLength = 4;
                    temp.Quality    = DataStruct.QualityType.OK;
                    break;
                }
            }
            break;

            case TransRes.Res002:       //Group 2
            {
                switch (funType)
                {
                case FunType.CalAll:                    //下行
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    break;

                case FunType.FloatMValue:                                 //上行
                    //遥测信息+品质描述词
                    this.sqn = (byte)(Convert.ToByte("10000000", 2) + 6); //6个连续信息体
                    this.SetTransRes(false, false, TransRes.Res002);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = dValue
                        });
                    DataStruct temp = this.data[this.data.Count - 1];
                    temp.DataLength = 4;
                    temp.Quality    = DataStruct.QualityType.OK;
                    //this.data.Add(new DataStruct() { Data = qds });
                    break;
                }
            }
            break;

            case TransRes.Res003:       //Group 3
            {
                switch (funType)
                {
                case FunType.CalAll:                    //下行
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    break;

                case FunType.Single_point:                                //上行
                    //遥信(不带品质描述词,单点数据已经包含品质描述 )
                    this.sqn = (byte)(Convert.ToByte("00000000", 2) + 1); //1个单点信息
                    this.SetTransRes(false, false, TransRes.Res003);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = dValue
                        });
                    DataStruct temp = this.data[this.data.Count - 1];
                    temp.DataLength = 1;

                    break;
                }
            }
            break;

            case TransRes.Telecontrolling:
            {
                switch (funType)
                {
                case FunType.CalAll:                    //下行
                    this.sqn = 1;
                    this.SetTransRes(false, false, active);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = 0x14
                        });
                    break;

                case FunType.Single_point:                                //上行
                    //遥信(不带品质描述词,单点数据已经包含品质描述 )
                    this.sqn = (byte)(Convert.ToByte("00000000", 2) + 1); //1个单点信息
                    this.SetTransRes(false, false, TransRes.Telecontrolling);
                    this.type = funType;
                    this.data.Add(new DataStruct()
                        {
                            Addr = addr, Data = dValue
                        });
                    DataStruct temp = this.data[this.data.Count - 1];
                    temp.DataLength = 1;

                    break;
                }
            }
            break;

            default:
                break;
            }
        }
Example #29
0
    public static IEnumerator MoveWorld(Transform transform, Vector3 st, Transform ted, float time, FunType t = FunType.X, float offset = 0)
    {
        float delta = Mathf.Min(1, Time.fixedDeltaTime / time), p = 0;

        while (p < 1)
        {
            p += delta;
            var ed = ted.position;
            ed.z = offset;
            //Debug.Log(ed);
            transform.position = new Vector3(FixFun(t, st.x, ed.x, p), FixFun(t, st.y, ed.y, p), FixFun(t, st.z, ed.z, p));
            yield return(new WaitForFixedUpdate());
        }
    }
Example #30
0
 public static void AddMax <T>(T value, string fieldName, FunType funType, FunFormat funFormat, IDbCommand cmd)
 {
     Add <T>(value, fieldName, funType, funFormat, cmd, OperateType.Max);
 }
Example #31
0
 public void RemoveUncalled(FunType f)
 {
     uncalled.Remove(f);
 }
Example #32
0
 public void RemoveUncalled(FunType f)
 {
     uncalled.Remove(f);
 }
Example #33
0
 public static void BetweenAnd <T>(T value1, T value2, string fieldName, FunType funType, FunFormat funFormat, IDbCommand cmd)
 {
     Add <T>(value1, value2, fieldName, funType, funFormat, cmd);
 }