Exemplo n.º 1
0
        public void Read(ITcpTypeData dataTarget, ref int startPositionInDataTarget)
        {
            if (dataTarget == null)
            {
                throw new ArgumentNullException(nameof(dataTarget));
            }
            if (startPositionInDataTarget < 0 || startPositionInDataTarget > dataTarget.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(startPositionInDataTarget));
            }
            if (dataTarget.Length < (startPositionInDataTarget + DataLength))
            {
                throw new ArgumentException(string.Empty, nameof(startPositionInDataTarget));
            }

            //-----------------------------------------------------------------
            var tmp = new UnionValue
            {
                Value = _bigEndian ? IPAddress.HostToNetworkOrder(Value) : Value
            };

            //-----------------------------------------------------------------
            dataTarget[startPositionInDataTarget]     = tmp.Data.Part0;
            dataTarget[startPositionInDataTarget + 1] = tmp.Data.Part1;
            dataTarget[startPositionInDataTarget + 2] = tmp.Data.Part2;
            dataTarget[startPositionInDataTarget + 3] = tmp.Data.Part3;
            //-----------------------------------------------------------------
            startPositionInDataTarget += DataLength;
        }
Exemplo n.º 2
0
        public void Eval(Context ctx, ValueStack stack)
        {
            switch (VType)
            {
            case EValueTypes.CONST:
                stack.Push(_Val);
                break;

            case EValueTypes.OP_UNARY:
                Operator.Eval(stack, _operator);
                break;

            case EValueTypes.OP_BINARY:
                Operator.Eval(stack, _operator);
                break;

            case EValueTypes.GET_VAR_OR_CALL:
                if (ctx != null)
                {
                    UnionValue val = ctx.Dispatch(_Val.AsString);
                    stack.Push(val);
                }
                else
                {
                    stack.Push(UnionValue.Error);
                }
                break;
            }
        }
Exemplo n.º 3
0
        public void Write(ITcpTypeData dataSource, ref int startPositionInDataSource)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource));
            }
            if (startPositionInDataSource < 0 || startPositionInDataSource > dataSource.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(startPositionInDataSource));
            }
            if (dataSource.Length < (startPositionInDataSource + DataLength))
            {
                throw new ArgumentException(string.Empty, nameof(startPositionInDataSource));
            }

            //-----------------------------------------------------------------
            var tmp = new UnionValue
            {
                Data =
                {
                    Part0 = dataSource[startPositionInDataSource],
                    Part1 = dataSource[startPositionInDataSource + 1],
                    Part2 = dataSource[startPositionInDataSource + 2],
                    Part3 = dataSource[startPositionInDataSource + 3]
                }
            };

            //-----------------------------------------------------------------
            Value = _bigEndian ? IPAddress.NetworkToHostOrder(tmp.Value) : tmp.Value;
            //-----------------------------------------------------------------
            startPositionInDataSource += DataLength;
        }
Exemplo n.º 4
0
 public Expression(bool isCxtBound, string value)   : this()
 {
     VType = isCxtBound ?
             EValueTypes.GET_VAR_OR_CALL :
             EValueTypes.CONST;
     _Val = new UnionValue(value);
 }
Exemplo n.º 5
0
 public Expression(EOperatorType op) : this()
 {
     VType = op == EOperatorType.Unary_Negation ?
             EValueTypes.OP_UNARY :
             EValueTypes.OP_BINARY;
     _operator = op;
     // to mark it as 'not an error'
     _Val = new UnionValue(true);
 }
Exemplo n.º 6
0
        private static UnionValue EvaluateImpl(
            UnionValue LHS,
            UnionValue RHS,
            EOperatorType op)
        {
            if (RHS.IsError || LHS.IsError || op == EOperatorType.INVALID)
            {
                return(UnionValue.Error);
            }

            if (RHS.Type != LHS.Type)
            {
                UnityEngine.Debug.LogError("! type mismach");
            }

            switch (RHS.Type)
            {
            case EValType.FLOAT:
                return(new UnionValue(ExecAlg(op, RHS.AsFloat, LHS.AsFloat)));

            case EValType.BOOL:
                switch (op)
                {
                case EOperatorType.Bin_OR:
                    return(new UnionValue(LHS.AsBool || RHS.AsBool));

                case EOperatorType.Bin_AND:
                    return(new UnionValue(LHS.AsBool && RHS.AsBool));

                case EOperatorType.Bin_Equal:
                    return(new UnionValue(LHS.AsBool == RHS.AsBool));

                case EOperatorType.Bin_NotEqual:
                    return(new UnionValue(LHS.AsBool != RHS.AsBool));

                default:
                    return(UnionValue.Error);
                }

            case EValType.STR:
                return(UnionValue.Error);
            }

            return(UnionValue.Error);
        }
Exemplo n.º 7
0
 public void Push(UnionValue expr)
 {
     _values.Push(expr);
 }
Exemplo n.º 8
0
 public Expression(float value) : this()
 {
     VType = EValueTypes.CONST;
     _Val  = new UnionValue(value);
 }