public static void ForEachBit(this FuncBuilder f, IntExpression expr, int offset, int count, bool bigEndian, ActionOnIntExpr action)
        {
            int inclusiveStart;
            int exclusiveEnd;
            int increment;

            if (!bigEndian)
            {
                inclusiveStart = offset;
                exclusiveEnd   = offset + count;
                increment      = 1;
            }
            else
            {
                inclusiveStart = offset + count - 1;
                exclusiveEnd   = offset - 1;
                increment      = -1;
            }

            f.For(i => i.Value = inclusiveStart, i => i < exclusiveEnd, i => i.Value = i + increment)
            .Do(i => {
                var mask            = ((IntExpression)1).ShiftLeft(i);
                var bitInPosition   = f.Declare.Int("bitInPosition");
                bitInPosition.Value = expr & mask;
                action(bitInPosition);
            });
        }
示例#2
0
        private readonly Format16OpCode inverseOpCode; //should we wish to invert this operator, because (a<b)==!(a>=b), therefore BGE

        private CompareOp(IntExpression lhs, IntExpression rhs, Format16OpCode branchOpCode, Format16OpCode inverseOpCode)
        {
            this.lhs           = lhs;
            this.rhs           = rhs;
            this.branchOpCode  = branchOpCode;
            this.inverseOpCode = inverseOpCode;
        }
示例#3
0
 public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
 {
     if (type == typeof(IntExpression))
     {
         IntExpression result = new IntExpression(null, "", dictionary["abbr"] as string)
         {
             Data = dictionary["data"],
             Min  = Convert.ToInt32(dictionary["min"]),
             Max  = Convert.ToInt32(dictionary["max"]),
         };
         return(result);
     }
     else if (type == typeof(UTrack))
     {
         UTrack result = new UTrack()
         {
             Name    = dictionary["name"] as string,
             Comment = dictionary["comment"] as string,
             TrackNo = Convert.ToInt32(dictionary["trackno"]),
             Singer  = new USinger(dictionary["singer"] as string),
         };
         return(result);
     }
     else if (type == typeof(USinger))
     {
         USinger result = new USinger(dictionary["name"] as string);
         return(result);
     }
     else
     {
         return(null);
     }
 }
 public void Write(IntExpression value)
 {
     var f=FuncBuilder.Instance;
       f.If(value!=0)
     .Then(Set)
     .Else(Clear)
     .Endif();
 }
        private static IEnumerable <IInstruction> GetIntExpressionInstructions(this IntExpression intExpression)
        {
            List <IInstruction> instructions = new List <IInstruction>();

            instructions.Add(LdcInstruction.WithValue(intExpression.Value.ToString()));
            //instructions.AddRange(JasminLibraryFunctionsHelper.GetIntegerValueOf(JasminReferenceConstants.JavaIntegerClass));
            return(instructions);
        }
示例#6
0
        public void Write(IntExpression value)
        {
            var f = FuncBuilder.Instance;

            f.If(value != 0)
            .Then(Set)
            .Else(Clear)
            .Endif();
        }
 public void Initialize(MethodDispatchTablePointer firmware, IntExpression pinNumber, bool initialValue)
 {
     firmware.GetPIOAndBitmask(pinNumber, ref pio, ref bitmask);
       pio.PER=bitmask; //enable PIO function
       if(initialValue) {
     pio.SODR=bitmask; //output should start high
       } else {
     pio.CODR=bitmask; //output should start low
       }
       pio.OER=bitmask; //enable output
 }
示例#8
0
 // branchOpCode: the normal case: (a<b) therefore BLT
 // flipOpCode: the flipped case: (a<b)==(b>a), therefore BGT
 // inverseOpCode: the inverse case: (a<b)==!(a>=b), therefore BGE
 // flipInverseOpCode: the flipped inverse case: (a<b)==!(b<=a), therefore BLE
 private static CompareOp CreateHelper(IntExpression lhs, IntExpression rhs,
                                       Format16OpCode branchOpCode, Format16OpCode flipOpCode, Format16OpCode inverseOpCode, Format16OpCode flipInverseOpCode)
 {
     if (lhs.IsConstant())
     {
         if (rhs.IsConstant())
         {
             throw new Exception("ridiculous");
         }
         //flip the constant over to the right side, for better code generation
         return(new CompareOp(rhs, lhs, flipOpCode, flipInverseOpCode));
     }
     return(new CompareOp(lhs, rhs, branchOpCode, inverseOpCode));
 }
示例#9
0
 public void Initialize(MethodDispatchTablePointer firmware, IntExpression pinNumber, bool initialValue)
 {
     firmware.GetPIOAndBitmask(pinNumber, ref pio, ref bitmask);
     pio.PER = bitmask; //enable PIO function
     if (initialValue)
     {
         pio.SODR = bitmask; //output should start high
     }
     else
     {
         pio.CODR = bitmask; //output should start low
     }
     pio.OER = bitmask;      //enable output
 }
示例#10
0
        internal static int?GetValueOrNull(this IntExpression expression, DialogStateManager state)
        {
            if (expression != null)
            {
                var(value, valueError) = expression.TryGetValue(state);
                if (valueError != null)
                {
                    throw new InvalidOperationException($"Expression evaluation resulted in an error. Expression: {expression.ExpressionText}. Error: {valueError}");
                }

                return(value);
            }

            return(null);
        }
示例#11
0
            public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
            {
                UProject result      = new UProject();
                string   ustxVersion = dictionary["ustxversion"] as string;

                USTx.Project      = result;
                result.Name       = dictionary["name"] as string;
                result.Comment    = dictionary["comment"] as string;
                result.OutputDir  = dictionary["output"] as string;
                result.CacheDir   = dictionary["cache"] as string;
                result.BPM        = Convert.ToDouble(dictionary["bpm"]);
                result.BeatPerBar = Convert.ToInt32(dictionary["bpbar"]);
                result.BeatUnit   = Convert.ToInt32(dictionary["bunit"]);
                result.Resolution = Convert.ToInt32(dictionary["res"]);

                foreach (var pair in (Dictionary <string, object>)(dictionary["exptable"]))
                {
                    var exp  = serializer.ConvertToType(pair.Value, typeof(IntExpression)) as IntExpression;
                    var _exp = new IntExpression(null, pair.Key, exp.Abbr)
                    {
                        Data = exp.Data,
                        Min  = exp.Min,
                        Max  = exp.Max,
                    };
                    result.ExpressionTable.Add(pair.Key, _exp);
                }

                var singers = dictionary["singers"] as ArrayList;

                foreach (var singer in singers)
                {
                    result.Singers.Add(serializer.ConvertToType(singer, typeof(USinger)) as USinger);
                }

                foreach (var track in dictionary["tracks"] as ArrayList)
                {
                    var _tarck = serializer.ConvertToType(track, typeof(UTrack)) as UTrack;
                    result.Tracks.Add(_tarck);
                }

                foreach (var part in dictionary["parts"] as ArrayList)
                {
                    result.Parts.Add(serializer.ConvertToType(part, typeof(UPart)) as UPart);
                }

                USTx.Project = null;
                return(result);
            }
示例#12
0
        public void NodeQuery_Bug2125()
        {
            Expression     exp;
            ExpressionList expList;

            var query1 = new NodeQuery();

            exp = new SearchExpression("dummy");
            query1.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals(exp.Parent, query1), "#1");

            expList = new ExpressionList(ChainOperator.And);
            query1.Add(expList);

            Assert.IsTrue(Object.ReferenceEquals(expList.Parent, query1), "#2");

            exp = new StringExpression(StringAttribute.Name, StringOperator.Equal, "Root");
            expList.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals(exp.Parent, expList), "#3");

            exp = new IntExpression(IntAttribute.Id, ValueOperator.Equal, 2);
            expList.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals(exp.Parent, expList), "#4");

            //------------------------------------------------------------------------------------

            var query2 = new NodeQuery
                         (
                new SearchExpression("dummy"),
                new ExpressionList
                (
                    ChainOperator.And,
                    new StringExpression(StringAttribute.Name, StringOperator.Equal, "Root"),
                    new IntExpression(IntAttribute.Id, ValueOperator.Equal, 2)
                )
                         );

            Assert.IsTrue(Object.ReferenceEquals(query2.Expressions[0].Parent, query2), "#5");
            Assert.IsTrue(Object.ReferenceEquals(query2.Expressions[1].Parent, query2), "#6");
            Assert.IsTrue(Object.ReferenceEquals(((ExpressionList)query2.Expressions[1]).Expressions[0].Parent, query2.Expressions[1]), "#7");
            Assert.IsTrue(Object.ReferenceEquals(((ExpressionList)query2.Expressions[1]).Expressions[1].Parent, query2.Expressions[1]), "#8");
        }
        public static void Return(this FuncBuilder f, IntExpression expr)
        {
            using (f.OpenScope("return")) {
                var emitter       = CodeGenerator.Emitter;
                var resultStorage = f.Declare.Int("result");
                var exprResult    = expr.EvaluateTo(resultStorage);

                var exprRegOrByte = exprResult.ToRegisterOrByte(f.Scratch0);
                if (exprRegOrByte.IsRegister)
                {
                    emitter.EmitRegisterMoveIfDifferent(Register.R0, exprRegOrByte.Register);
                }
                else
                {
                    emitter.Emit(Format3OpCode.MOV, Register.R0, exprRegOrByte.Byte);
                }
                BranchLogic.UnconditionalBranchTo(f.TheExitLabel);
            }
        }
示例#14
0
 public IndirectIntReference this[IntExpression index]
 {
     get {
     return new IndirectIntReference(this, index);
       }
 }
示例#15
0
 private void SetHelper(int offset, IntExpression value)
 {
     this.AsIntPointer()[offset].Value=value;
 }
示例#16
0
            public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
            {
                UProject result = new UProject();
                string ustxVersion = dictionary["ustxversion"] as string;
                USTx.Project = result;
                result.Name = dictionary["name"] as string;
                result.Comment = dictionary["comment"] as string;
                result.OutputDir = dictionary["output"] as string;
                result.CacheDir = dictionary["cache"] as string;
                result.BPM = Convert.ToDouble(dictionary["bpm"]);
                result.BeatPerBar = Convert.ToInt32(dictionary["bpbar"]);
                result.BeatUnit = Convert.ToInt32(dictionary["bunit"]);
                result.Resolution = Convert.ToInt32(dictionary["res"]);

                foreach (var pair in (Dictionary<string, object>)(dictionary["exptable"]))
                {
                    var exp = serializer.ConvertToType(pair.Value, typeof(IntExpression)) as IntExpression;
                    var _exp = new IntExpression(null, pair.Key, exp.Abbr)
                    {
                        Data = exp.Data,
                        Min = exp.Min,
                        Max = exp.Max,
                    };
                    result.ExpressionTable.Add(pair.Key, _exp);
                }

                var singers = dictionary["singers"] as ArrayList;
                foreach (var singer in singers)
                    result.Singers.Add(serializer.ConvertToType(singer, typeof(USinger)) as USinger);

                foreach (var track in dictionary["tracks"] as ArrayList)
                {
                    var _tarck = serializer.ConvertToType(track, typeof(UTrack)) as UTrack;
                    result.Tracks.Add(_tarck);
                }

                foreach (var part in dictionary["parts"] as ArrayList)
                    result.Parts.Add(serializer.ConvertToType(part, typeof(UPart)) as UPart);

                USTx.Project = null;
                return result;
            }
示例#17
0
 public IntVariable Int(string name, IntExpression optionalInitialValue = null)
 {
     return((IntVariable)DeclareHelper(name, new IntVariable(), optionalInitialValue));
 }
示例#18
0
 public void EnqueueDelta(MethodDispatchTablePointer firmware, IntExpression delayInMicroseconds)
 {
     firmware.HAL_EnqueueDelta(storage, delayInMicroseconds);
 }
示例#19
0
 public static CompareOp CreateEqual(IntExpression lhs, IntExpression rhs)
 {
     return(CreateHelper(lhs, rhs, Format16OpCode.BEQ, Format16OpCode.BEQ, Format16OpCode.BNE, Format16OpCode.BNE));
 }
示例#20
0
 public IndirectByteReference this[IntExpression index] {
     get {
         return(new IndirectByteReference(this, index));
     }
 }
示例#21
0
 private void SetHelper(int offset, IntExpression value)
 {
     this.AsIntPointer()[offset].Value = value;
 }
示例#22
0
 public static CompareOp CreateLessThanOrEqual(IntExpression lhs, IntExpression rhs)
 {
     return(CreateHelper(lhs, rhs, Format16OpCode.BLE, Format16OpCode.BGE, Format16OpCode.BGT, Format16OpCode.BLT));
 }
示例#23
0
 public void EnqueueDelta(MethodDispatchTablePointer firmware, IntExpression delayInMicroseconds)
 {
     firmware.HAL_EnqueueDelta(storage, delayInMicroseconds);
 }
示例#24
0
 public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
 {
     if (type == typeof(IntExpression))
     {
         IntExpression result = new IntExpression(null, "", dictionary["abbr"] as string)
         {
             Data = dictionary["data"],
             Min = Convert.ToInt32(dictionary["min"]),
             Max = Convert.ToInt32(dictionary["max"]),
         };
         return result;
     }
     else if (type == typeof(UTrack))
     {
         UTrack result = new UTrack()
         {
             Name = dictionary["name"] as string,
             Comment = dictionary["comment"] as string,
             TrackNo = Convert.ToInt32(dictionary["trackno"]),
             Singer = new USinger() { Name = dictionary["singer"] as string }
         };
         return result;
     }
     else if (type == typeof(USinger))
     {
         USinger result = new USinger()
         {
             Name = dictionary["name"] as string,
             Path = dictionary["path"] as string
         };
         return result;
     }
     else return null;
 }
 public static void GetPIOAndBitmask(this MethodDispatchTablePointer md, IntExpression pin, ref PIOReferenceVariable pio, ref IntVariable bitmask)
 {
     md.GetPIOReference(ref pio, pin.ShiftRight(5));           // pin/32
     bitmask.Value = ((IntExpression)1).ShiftLeft(pin & 0x1f); // 1<<(pin%32)
 }