public DefaultVirtualPathMonitor(IClock clock, IVirtualPathProvider virtualPathProvider)
 {
     _clock = clock;
     _virtualPathProvider = virtualPathProvider;
     _thunk = new Thunk(this);
     Logger = NullLogger.Instance;
 }
 public static void ExpectEof(Thunk thunk)
 {
     try
     {
         thunk();
         Assert.Fail("expected System.IO.EndOfStreamException");
     }
     catch (System.IO.EndOfStreamException) { }
 }
Exemplo n.º 3
0
            public static void ComposeBack()
            {
                // Arrange
                var f = Thunk <AnyT1> .Return(AnyT2.Some);

                var g = Thunk <AnyT2> .Return(AnyResult.Some);

                // Act & Assert
                Assert.Some(AnyResult.Value, g.ComposeBack(f, AnyT1.Value));
            }
Exemplo n.º 4
0
 public unsafe void SdcaL1UpdateSU()
 {
     fixed(float *psrc = src)
     fixed(float *pdst = dst)
     fixed(float *pres = result)
     fixed(int *pidx   = idx)
     {
         Thunk.SdcaL1UpdateSU(DefaultScale, psrc, pidx, DefaultScale, pdst, pres, IndexLength);
     }
 }
Exemplo n.º 5
0
 public unsafe void MatMulP()
 {
     fixed(float *psrc = &src[0])
     fixed(float *pdst  = &dst[0])
     fixed(float *psrc1 = &src1[0])
     fixed(int *pidx    = &matrixIdx[0])
     {
         Thunk.MatMulP(psrc1, pidx, psrc, 0, 0, MatrixIndexLength, pdst, 1000, 1000);
     }
 }
Exemplo n.º 6
0
            public static void Invoke_WithSome()
            {
                // Arrange
                var f = Thunk <AnyT1> .Return(AnyResult.Some);

                var g = Thunk <AnyT1> .Return(AnyResult.None);

                // Act & Assert
                Assert.Some(AnyResult.Value, f.Invoke(AnyT1.Some));
                Assert.None(g.Invoke(AnyT1.Some));
            }
Exemplo n.º 7
0
        internal void CreateFilteredView(IFilter eventfilter, Thunk initialAction, bool oldDisplayStyle)
        {
            StandardView view = new StandardView(this, model, eventfilter, multipleExecutions, oldDisplayStyle);

            lock (this)
            {
                views.Add(view);
            }
            view.SetInitialAction(initialAction);
            view.StartView();
        }
Exemplo n.º 8
0
        public void ObjectChanged()
        {
            object o = model.CurrentObject;

            if (o != null && (tv.SelectedNode == null || !IsLeafType(o) || o != ((Thunk)n2thunk[tv.SelectedNode]).Object))
            {
                Thunk thunk = AddRoot(o, tv);
                tv.SelectedNode = thunk.ThisNode;
            }
            previousNode = tv.SelectedNode;
        }
Exemplo n.º 9
0
        public static object BindReadSuppress(bool value, Thunk thunk)
        {
            ValueCell <bool> oldReadSuppress = readSuppress;

            try {
                readSuppress = new ValueCell <bool> (value);
                return(thunk());
            }
            finally {
                readSuppress = oldReadSuppress;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Build the actual manual text
        /// </summary>
        private void WriteBody(Thunk tocWriter, Thunk sectionWriter)
        {
#if ClassDocumentation
            BuildSubclassTable();
#endif
            tocWriter();
            sectionWriter();
            //WriteLispTOC();
            //WriteClassHierarchyTOC();
            //WriteLispSections();
            //WriteClassHierarchySections();
        }
Exemplo n.º 11
0
 public void Case05()
 {
     try {
         var expr1 = Thunk.Create((int x, long y) => x + y);
         var expr2 = Thunk.Create((int x, int y) => x + y);
         var expr3 = Thunk.Create((long x, long y) => x + y);
         expr1.Compose(expr2, expr3);
     } catch (Exception ex) {
         TestContext.WriteLine(ex.Message);
         throw;
     }
 }
Exemplo n.º 12
0
 public static void DoesNotThrow <T>(Thunk thunk, string message = "@@@ DoesNotThrow<Exception>") where T : Exception
 {
     try
     {
         thunk.Invoke();
     }
     catch (T ex)
     {
         Assert.Fail($"{Environment.NewLine + message + Environment.NewLine}, type: {ex.GetType() + Environment.NewLine}," +
                     $" message: {ex.Message + Environment.NewLine}, stackTrace: {ex.StackTrace + Environment.NewLine}");
     }
 }
Exemplo n.º 13
0
 public static ThunkAsync <B> MapAsync <A, B>(this Thunk <A> ma, Func <A, ValueTask <B> > f) =>
 ThunkAsync <B> .Lazy(async() =>
 {
     var ra = ma.Value();
     if (ra.IsSucc)
     {
         return(FinSucc(await f(ra.Value).ConfigureAwait(false)));
     }
     else
     {
         return(FinFail <B>(ra.Error));
     }
 });
Exemplo n.º 14
0
 public static ThunkAsync <Env, B> MapAsync <Env, A, B>(this Thunk <A> ma, Func <A, ValueTask <B> > f) where Env : struct, HasCancel <Env> =>
 ThunkAsync <Env, B> .Lazy(async env =>
 {
     var ra = ma.Value();
     if (ra.IsSucc)
     {
         return(FinSucc(await f(ra.Value).ConfigureAwait(false)));
     }
     else
     {
         return(FinFail <B>(ra.Error));
     }
 });
Exemplo n.º 15
0
        // The signature of this method is intentionally identical to
        // .Net 4.6's Buffer.MemoryCopy.
        // REVIEW: Remove once we're on a version of .NET which includes
        // Buffer.MemoryCopy.
        public static unsafe void MemoryCopy(void *source, void *destination, long destinationSizeInBytes, long sourceBytesToCopy)
        {
            // MemCpy has undefined behavior when handed overlapping source and
            // destination buffers.
            // Do not pass it overlapping source and destination buffers.
            Contracts.Check((byte *)destination + sourceBytesToCopy <= source || destination >= (byte *)source + sourceBytesToCopy);
            Contracts.Check(destinationSizeInBytes >= sourceBytesToCopy);
#if CORECLR
            System.Buffer.MemoryCopy(source, destination, destinationSizeInBytes, sourceBytesToCopy);
#else
            Thunk.MemCpy(destination, source, sourceBytesToCopy);
#endif
        }
Exemplo n.º 16
0
        public async Task Interpret_impure_effect_should_execute_side_effect_broker()
        {
            //Arrange
            var sideEffect = Thunk.From(() => 3);
            //Mock.Of<ISideEffect<int>>();
            var sideEffectBroker = new Mock <ISideEffectBroker>();
            var sut    = new Interpreter(sideEffectBroker.Object);
            var effect = Effect.Of <Thunk.SideEffect <int>, int>(sideEffect);

            //Act
            var result = await sut.Interpret(effect);

            //Assert
            sideEffectBroker.Verify(x => x.Run <Thunk.SideEffect <int>, int>(sideEffect, default), Times.Once);
        }
Exemplo n.º 17
0
        /// <nodoc />
        public TopLevelValueInfo(
            Thunk activeThunk,
            FullSymbol valueName,
            AbsolutePath specFile,
            LineInfo valueDeclarationLineInfo,
            object templateValue)
        {
            Contract.Requires(activeThunk != null);
            Contract.Requires(valueName.IsValid);
            Contract.Requires(specFile.IsValid);

            ActiveThunk = activeThunk;
            ValueName   = valueName;
            SpecFile    = specFile;
            ValueDeclarationLineInfo = valueDeclarationLineInfo;
            CapturedTemplateValue    = templateValue;
        }
Exemplo n.º 18
0
        public void Case02()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 10))
            {
                int a = random.Next(-100, 100);
                int b = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}, b={b}");

                var expr1 = Thunk.Create((int x, int y) => x - y);
                var expr2 = Thunk.Create((int x) => x / 2);

                var expr3 = expr1.Then(expr2).WithParams((int x, int y) => default(int));

                Assert.AreEqual((a - b) / 2, expr3.Compile().Invoke(a, b));
            }
        }
Exemplo n.º 19
0
            public override Verb CreateVerb(string[] tokens)
            {
                var memberName = tokens[2];

                Color(position, tokens[1].Length, Whitespaces);
                Color(memberName.Length, Variables);
                Color(tokens[3].Length, Structures);

                if (GetExpression(source, NextPosition, EndOfLineConsuming()).If(out var exp, out var index))
                {
                    overridePosition = index;
                    MemberName       = memberName;
                    Thunk            = new Thunk(exp);
                    return(new NullOp());
                }

                return(null);
            }
Exemplo n.º 20
0
        public void Case04()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 10))
            {
                int a = random.Next(-100, 100);
                int b = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}, b={b}");

                var expr1 = Thunk.Create((long x, long y) => x + 3 * y);
                var expr2 = Thunk.Create((int x, int y) => (long)(2 * x + y));

                var expr3 = expr1.Compose(expr2, expr2).WithParams((int x, int y) => default(long));

                Assert.AreEqual(4 * (2 * a + b), expr3.Compile().Invoke(a, b));
            }
        }
Exemplo n.º 21
0
        public bool CheckCode(string emailstr, string codestr)
        {
            /*R[11] = -(R[24] + R[66]);
             * R[32] = -(R[07] + R[55] - 1);
             * R[69] = -(R[81] + R[15] - 175);
             * R[27] = -(R[14] + R[52] - 0);
             * R[0] = 1;
             * //R[1] = 1;//test
             * if (R[13] <= 30)
             *  R[93] = 30 - R[13]; //days left*/

            var r       = lazy(R);
            var elen    = lazy(emailstr.Length);
            var codelen = lazy(codestr.Length);
            var email   = ofString(emailstr);
            var code    = ofString(codestr);

            //Thunk fmain = () => run<Kont<Pair<Kont<Kont<int[]>>, Kont<int[]>>>>(x0 => () => run<Pair<Kont<Kont<int[]>>, Kont<int[]>>>(x0, pair<Kont<Kont<int[]>>, Kont<int[]>>(k1 => () => run<Kont<Pair<Kont<Kont<int[]>>, Kont<int[]>>>>(x2 => () => run<Pair<Kont<Kont<int[]>>, Kont<int[]>>>(x2, pair<Kont<Kont<int[]>>, Kont<int[]>>(k3 => () => run<Kont<int[]>>(r, m44 => () => run<int>(i45 => () => run<int>(a47 => () => run<Kont<int[]>>(r, m53 => () => run<int>(i54 => () => run<int>(a49 => () => run<Kont<int[]>>(r, m51 => () => run<int>(i52 => () => run<int>(b50 => () => run<int>(b48 => () => run<int>(v46 => () => run<int[]>(m31 => () => run<int>(i32 => () => run<int>(a34 => () => run<Kont<int[]>>(r, m42 => () => run<int>(i43 => () => run<int>(a38 => () => run<Kont<int[]>>(r, m40 => () => run<int>(i41 => () => run<int>(b39 => () => run<int>(a36 => () => run<int>(b37 => () => run<int>(b35 => () => run<int>(v33 => () => run<int[]>(m18 => () => run<int>(i19 => () => run<int>(a21 => () => run<Kont<int[]>>(r, m29 => () => run<int>(i30 => () => run<int>(a25 => () => run<Kont<int[]>>(r, m27 => () => run<int>(i28 => () => run<int>(b26 => () => run<int>(a23 => () => run<int>(b24 => () => run<int>(b22 => () => run<int>(v20 => () => run<int[]>(m7 => () => run<int>(i8 => () => run<int>(a10 => () => run<Kont<int[]>>(r, m16 => () => run<int>(i17 => () => run<int>(a12 => () => run<Kont<int[]>>(r, m14 => () => run<int>(i15 => () => run<int>(b13 => () => run<int>(b11 => () => run<int>(v9 => () => run<int[]>(m4 => () => run<int>(i5 => () => run<int>(v6 => () => run<int[]>(k3, set(m4, i5, v6)), 1), 0), set(m7, i8, v9)), (a10 - b11)), (a12 + b13)), m14[i15]), 52)), m16[i17]), 14)), 0), 27), set(m18, i19, v20)), (a21 - b22)), (a23 - b24)), 175), (a25 + b26)), m27[i28]), 15)), m29[i30]), 81)), 0), 69), set(m31, i32, v33)), (a34 - b35)), (a36 - b37)), 1), (a38 + b39)), m40[i41]), 55)), m42[i43]), 7)), 0), 32), set(m44, i45, v46)), (a47 - b48)), (a49 + b50)), m51[i52]), 66)), m53[i54]), 24)), 0), 11)), k1)), w55 => () => run<Kont<int[]>>(w55.fst, m68 => () => run<int>(i69 => () => run<int>(a66 => () => run<int>(b67 => () => run<Sum<Unit, Unit>>(z58 => match<Unit, Unit>(z58, u56 => () => run<Kont<int[]>>(w55.fst, w55.snd), u57 => () => run<Kont<int[]>>(w55.fst, m59 => () => run<int>(i60 => () => run<int>(a62 => () => run<Kont<int[]>>(w55.fst, m64 => () => run<int>(i65 => () => run<int>(b63 => () => run<int>(v61 => () => run<int[]>(w55.snd, set(m59, i60, v61)), (a62 - b63)), m64[i65]), 13)), 30), 93))), less(a66, b67)), 31), m68[i69]), 13))), x => { throw new Res<int[]>(x); })), w70 => () => run<Kont<int>>(elen, a217 => () => run<int>(b218 => () => run<Sum<Unit, Unit>>(z73 => match<Unit, Unit>(z73, u71 => () => run<Kont<int>>(codelen, a215 => () => run<int>(b216 => () => run<Sum<Unit, Unit>>(z76 => match<Unit, Unit>(z76, u74 => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int[]>>>>(x77 => () => run<Pair<Kont<Kont<int>>, Kont<int[]>>>(x77, pair<Kont<Kont<int>>, Kont<int[]>>(k78 => () => run<Kont<Pair<Kont<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>, Kont<int>>>>(x79 => () => run<Pair<Kont<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>, Kont<int>>>(x79, pair<Kont<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>, Kont<int>>(k80 => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>(k80, w81 => () => run<Kont<int>>(w81.fst, a89 => () => run<int>(b90 => () => run<Sum<Unit, Unit>>(z84 => match<Unit, Unit>(z84, u82 => () => run<Kont<int>>(w81.fst, a85 => () => run<int>(b86 => () => run<int>(w81.snd, (a85 - b86)), 55)), u83 => () => run<Kont<int>>(w81.fst, a87 => () => run<int>(b88 => () => run<int>(w81.snd, (a87 - b88)), 48))), less(a89, b90)), 60))), k78)), w91 => () => run<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>(w91.fst, x108 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x108, pair<Kont<Kont<int>>, Kont<int>>(k109 => () => run<Kont<int[]>>(code, m110 => () => run<int>(i111 => () => run<int>(k109, m110[i111]), 3)), a106 => () => run<int>(b107 => () => run<int>(a98 => () => run<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>(w91.fst, x102 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x102, pair<Kont<Kont<int>>, Kont<int>>(k103 => () => run<Kont<int[]>>(code, m104 => () => run<int>(i105 => () => run<int>(k103, m104[i105]), 4)), a100 => () => run<int>(b101 => () => run<int>(b99 => () => run<int>(a92 => () => run<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>(w91.fst, x94 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x94, pair<Kont<Kont<int>>, Kont<int>>(k95 => () => run<Kont<int[]>>(code, m96 => () => run<int>(i97 => () => run<int>(k95, m96[i97]), 5)), b93 => () => run<int>(w91.snd, (a92 + b93))))), (a98 + b99)), (a100 * b101)), 16)))), (a106 * b107)), 256))))), w70.snd)), w112 => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int[]>>>>(x113 => () => run<Pair<Kont<Kont<int>>, Kont<int[]>>>(x113, pair<Kont<Kont<int>>, Kont<int[]>>(k114 => () => run<Kont<Pair<Kont<Kont<int[]>>, Kont<int>>>>(x115 => () => run<Pair<Kont<Kont<int[]>>, Kont<int>>>(x115, pair<Kont<Kont<int[]>>, Kont<int>>(k116 => () => run<int>(sz165 => () => run<int[]>(m162 => () => run<int>(i163 => () => run<int>(v164 => () => run<int[]>(m159 => () => run<int>(i160 => () => run<int>(v161 => () => run<int[]>(m156 => () => run<int>(i157 => () => run<int>(v158 => () => run<int[]>(m153 => () => run<int>(i154 => () => run<int>(v155 => () => run<int[]>(m150 => () => run<int>(i151 => () => run<int>(v152 => () => run<int[]>(m147 => () => run<int>(i148 => () => run<int>(v149 => () => run<int[]>(m144 => () => run<int>(i145 => () => run<int>(v146 => () => run<int[]>(m141 => () => run<int>(i142 => () => run<int>(v143 => () => run<int[]>(m138 => () => run<int>(i139 => () => run<int>(v140 => () => run<int[]>(m135 => () => run<int>(i136 => () => run<int>(v137 => () => run<int[]>(m132 => () => run<int>(i133 => () => run<int>(v134 => () => run<int[]>(m129 => () => run<int>(i130 => () => run<int>(v131 => () => run<int[]>(m126 => () => run<int>(i127 => () => run<int>(v128 => () => run<int[]>(m123 => () => run<int>(i124 => () => run<int>(v125 => () => run<int[]>(m120 => () => run<int>(i121 => () => run<int>(v122 => () => run<int[]>(m117 => () => run<int>(i118 => () => run<int>(v119 => () => run<int[]>(k116, set(m117, i118, v119)), 69), 15), set(m120, i121, v122)), 239), 14), set(m123, i124, v125)), 115), 13), set(m126, i127, v128)), 209), 12), set(m129, i130, v131)), 241), 11), set(m132, i133, v134)), 71), 10), set(m135, i136, v137)), 22), 9), set(m138, i139, v140)), 158), 8), set(m141, i142, v143)), 215), 7), set(m144, i145, v146)), 66), 6), set(m147, i148, v149)), 106), 5), set(m150, i151, v152)), 156), 4), set(m153, i154, v155)), 135), 3), set(m156, i157, v158)), 156), 2), set(m159, i160, v161)), 218), 1), set(m162, i163, v164)), 103), 0), new int[sz165]), 16), k114)), w166 => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>(x167 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x167, pair<Kont<Kont<int>>, Kont<int>>(k168 => () => run<int>(k168, 0), w166.snd)), unrec<Pair<Kont<Kont<int>>, Kont<int>>>((w169, rec170) => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>(x172 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x172, pair<Kont<Kont<int>>, Kont<int>>(k173 => () => run<Kont<int[]>>(w166.fst, m182 => () => run<Kont<int>>(w169.fst, i183 => () => run<int>(a176 => () => run<Kont<int[]>>(email, m178 => () => run<Kont<int>>(w169.fst, a180 => () => run<Kont<int>>(elen, b181 => () => run<int>(i179 => () => run<int>(b177 => () => run<int>(a174 => () => run<int>(b175 => () => run<int>(k173, (a174 % b175)), 256), (a176 * b177)), m178[i179]), (a180 % b181))))), m182[i183]))), w169.snd)), w184 => () => run<Kont<int>>(w169.fst, a194 => () => run<int>(b195 => () => run<Sum<Unit, Unit>>(z187 => match<Unit, Unit>(z187, u185 => () => run<Kont<int>>(w184.fst, a188 => () => run<Kont<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>>(u171 => () => run<Kont<Pair<Kont<Kont<int>>, Kont<int>>>>(u171, rec170), x190 => () => run<Pair<Kont<Kont<int>>, Kont<int>>>(x190, pair<Kont<Kont<int>>, Kont<int>>(k191 => () => run<Kont<int>>(w169.fst, a192 => () => run<int>(b193 => () => run<int>(k191, (a192 + b193)), 1)), b189 => () => run<int>(w184.snd, (a188 + b189)))))), u186 => () => run<Kont<int>>(w184.fst, w184.snd)), eql(a194, b195)), 15)))))), w112.snd)), w196 => () => run<Kont<int>>(w112.fst, a213 => () => run<Kont<int>>(w196.fst, b214 => () => run<Sum<Unit, Unit>>(z199 => match<Unit, Unit>(z199, u197 => () => run<Kont<int[]>>(w70.fst, w196.snd), u198 => () => run<Kont<Pair<Kont<Kont<int[]>>, Kont<int[]>>>>(x200 => () => run<Pair<Kont<Kont<int[]>>, Kont<int[]>>>(x200, pair<Kont<Kont<int[]>>, Kont<int[]>>(k201 => () => run<Kont<int[]>>(w70.fst, m202 => () => run<int>(i203 => () => run<int>(v204 => () => run<int[]>(k201, set(m202, i203, v204)), 1), 1)), w196.snd)), w205 => () => run<Kont<int[]>>(w205.fst, m206 => () => run<int>(i207 => () => run<Kont<int[]>>(w205.fst, m211 => () => run<int>(i212 => () => run<int>(a209 => () => run<int>(b210 => () => run<int>(v208 => () => run<int[]>(w205.snd, set(m206, i207, v208)), (a209 + b210)), 1), m211[i212]), 27)), 27)))), eql(a213, b214)))))), u75 => () => run<Kont<int[]>>(w70.fst, w70.snd)), less(a215, b216)), 6)), u72 => () => run<Kont<int[]>>(w70.fst, w70.snd)), less(a217, b218)), 1)));
            Thunk fmain = () => run <Kont <Pair <Kont <Kont <int[]> >,
                                                 Kont <int[]> > > >(x0 => () => run <Pair <Kont <Kont <int[]> >,
                                                                                           Kont <int[]> > >(x0, pair <Kont <Kont <int[]> >,
                                                                                                                      Kont <int[]> >(k1 => () => run <Kont <Pair <Kont <Kont <int[]> >, Kont <int[]> > > >(x2 => () => run <Pair <Kont <Kont <int[]> >, Kont <int[]> > >(x2, pair <Kont <Kont <int[]> >, Kont <int[]> >(k3 => () => run <Kont <int[]> >(r, m41 => () => run <int>(i42 => () => run <int>(a44 => () => run <Kont <int[]> >(r, m50 => () => run <int>(i51 => () => run <int>(a46 => () => run <Kont <int[]> >(r, m48 => () => run <int>(i49 => () => run <int>(b47 => () => run <int>(b45 => () => run <int>(v43 => () => run <int[]>(m28 => () => run <int>(i29 => () => run <int>(a31 => () => run <Kont <int[]> >(r, m39 => () => run <int>(i40 => () => run <int>(a35 => () => run <Kont <int[]> >(r, m37 => () => run <int>(i38 => () => run <int>(b36 => () => run <int>(a33 => () => run <int>(b34 => () => run <int>(b32 => () => run <int>(v30 => () => run <int[]>(m15 => () => run <int>(i16 => () => run <int>(a18 => () => run <Kont <int[]> >(r, m26 => () => run <int>(i27 => () => run <int>(a22 => () => run <Kont <int[]> >(r, m24 => () => run <int>(i25 => () => run <int>(b23 => () => run <int>(a20 => () => run <int>(b21 => () => run <int>(b19 => () => run <int>(v17 => () => run <int[]>(m4 => () => run <int>(i5 => () => run <int>(a7 => () => run <Kont <int[]> >(r, m13 => () => run <int>(i14 => () => run <int>(a9 => () => run <Kont <int[]> >(r, m11 => () => run <int>(i12 => () => run <int>(b10 => () => run <int>(b8 => () => run <int>(v6 => () => run <int[]>(k3, set(m4, i5, v6)), (a7 - b8)), (a9 + b10)), m11[i12]), 52)), m13[i14]), 14)), 0), 27), set(m15, i16, v17)), (a18 - b19)), (a20 - b21)), 175), (a22 + b23)), m24[i25]), 15)), m26[i27]), 81)), 0), 69), set(m28, i29, v30)), (a31 - b32)), (a33 - b34)), 1), (a35 + b36)), m37[i38]), 55)), m39[i40]), 7)), 0), 32), set(m41, i42, v43)), (a44 - b45)), (a46 + b47)), m48[i49]), 66)), m50[i51]), 24)), 0), 11)), k1)), w52 => () => run <Kont <int[]> >(w52.fst, m65 => () => run <int>(i66 => () => run <int>(a63 => () => run <int>(b64 => () => run <Sum <Unit, Unit> >(z55 => match <Unit, Unit>(z55, u53 => () => run <Kont <int[]> >(w52.fst, w52.snd), u54 => () => run <Kont <int[]> >(w52.fst, m56 => () => run <int>(i57 => () => run <int>(a59 => () => run <Kont <int[]> >(w52.fst, m61 => () => run <int>(i62 => () => run <int>(b60 => () => run <int>(v58 => () => run <int[]>(w52.snd, set(m56, i57, v58)), (a59 - b60)), m61[i62]), 13)), 30), 93))), less(a63, b64)), 31), m65[i66]), 13))), x => { throw new Res <int[]>(x); })), w67 => () => run <Kont <int> >(elen, a226 => () => run <int>(b227 => () => run <Sum <Unit, Unit> >(z70 => match <Unit, Unit>(z70, u68 => () => run <Kont <int> >(codelen, a221 => () => run <int>(b222 => () => run <Sum <Unit, Unit> >(z73 => match <Unit, Unit>(z73, u71 => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int[]> > > >(x74 => () => run <Pair <Kont <Kont <int> >, Kont <int[]> > >(x74, pair <Kont <Kont <int> >, Kont <int[]> >(k75 => () => run <Kont <Pair <Kont <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >, Kont <int> > > >(x76 => () => run <Pair <Kont <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >, Kont <int> > >(x76, pair <Kont <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >, Kont <int> >(k77 => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int> > > >(k77, w78 => () => run <Kont <int> >(w78.fst, a86 => () => run <int>(b87 => () => run <Sum <Unit, Unit> >(z81 => match <Unit, Unit>(z81, u79 => () => run <Kont <int> >(w78.fst, a82 => () => run <int>(b83 => () => run <int>(w78.snd, (a82 - b83)), 55)), u80 => () => run <Kont <int> >(w78.fst, a84 => () => run <int>(b85 => () => run <int>(w78.snd, (a84 - b85)), 48))), less(a86, b87)), 60))), k75)), w88 => () => run <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >(w88.fst, x105 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x105, pair <Kont <Kont <int> >, Kont <int> >(k106 => () => run <Kont <int[]> >(code, m107 => () => run <int>(i108 => () => run <int>(k106, m107[i108]), 3)), a103 => () => run <int>(b104 => () => run <int>(a95 => () => run <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >(w88.fst, x99 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x99, pair <Kont <Kont <int> >, Kont <int> >(k100 => () => run <Kont <int[]> >(code, m101 => () => run <int>(i102 => () => run <int>(k100, m101[i102]), 4)), a97 => () => run <int>(b98 => () => run <int>(b96 => () => run <int>(a89 => () => run <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >(w88.fst, x91 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x91, pair <Kont <Kont <int> >, Kont <int> >(k92 => () => run <Kont <int[]> >(code, m93 => () => run <int>(i94 => () => run <int>(k92, m93[i94]), 5)), b90 => () => run <int>(w88.snd, (a89 + b90))))), (a95 + b96)), (a97 * b98)), 16)))), (a103 * b104)), 256))))), w67.snd)), w109 => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int[]> > > >(x110 => () => run <Pair <Kont <Kont <int> >, Kont <int[]> > >(x110, pair <Kont <Kont <int> >, Kont <int[]> >(k111 => () => run <Kont <Pair <Kont <Kont <int[]> >, Kont <int> > > >(x112 => () => run <Pair <Kont <Kont <int[]> >, Kont <int> > >(x112, pair <Kont <Kont <int[]> >, Kont <int> >(k113 => () => run <int>(sz162 => () => run <int[]>(m159 => () => run <int>(i160 => () => run <int>(v161 => () => run <int[]>(m156 => () => run <int>(i157 => () => run <int>(v158 => () => run <int[]>(m153 => () => run <int>(i154 => () => run <int>(v155 => () => run <int[]>(m150 => () => run <int>(i151 => () => run <int>(v152 => () => run <int[]>(m147 => () => run <int>(i148 => () => run <int>(v149 => () => run <int[]>(m144 => () => run <int>(i145 => () => run <int>(v146 => () => run <int[]>(m141 => () => run <int>(i142 => () => run <int>(v143 => () => run <int[]>(m138 => () => run <int>(i139 => () => run <int>(v140 => () => run <int[]>(m135 => () => run <int>(i136 => () => run <int>(v137 => () => run <int[]>(m132 => () => run <int>(i133 => () => run <int>(v134 => () => run <int[]>(m129 => () => run <int>(i130 => () => run <int>(v131 => () => run <int[]>(m126 => () => run <int>(i127 => () => run <int>(v128 => () => run <int[]>(m123 => () => run <int>(i124 => () => run <int>(v125 => () => run <int[]>(m120 => () => run <int>(i121 => () => run <int>(v122 => () => run <int[]>(m117 => () => run <int>(i118 => () => run <int>(v119 => () => run <int[]>(m114 => () => run <int>(i115 => () => run <int>(v116 => () => run <int[]>(k113, set(m114, i115, v116)), 69), 15), set(m117, i118, v119)), 239), 14), set(m120, i121, v122)), 115), 13), set(m123, i124, v125)), 209), 12), set(m126, i127, v128)), 241), 11), set(m129, i130, v131)), 71), 10), set(m132, i133, v134)), 22), 9), set(m135, i136, v137)), 158), 8), set(m138, i139, v140)), 215), 7), set(m141, i142, v143)), 66), 6), set(m144, i145, v146)), 106), 5), set(m147, i148, v149)), 156), 4), set(m150, i151, v152)), 135), 3), set(m153, i154, v155)), 156), 2), set(m156, i157, v158)), 218), 1), set(m159, i160, v161)), 103), 0), new int[sz162]), 16), k111)), w163 => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int> > > >(x164 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x164, pair <Kont <Kont <int> >, Kont <int> >(k165 => () => run <int>(k165, 0), w163.snd)), unrec <Pair <Kont <Kont <int> >, Kont <int> > >((w166, rec167) => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int> > > >(x169 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x169, pair <Kont <Kont <int> >, Kont <int> >(k170 => () => run <Kont <int[]> >(w163.fst, m179 => () => run <Kont <int> >(w166.fst, i180 => () => run <int>(a173 => () => run <Kont <int[]> >(email, m175 => () => run <Kont <int> >(w166.fst, a177 => () => run <Kont <int> >(elen, b178 => () => run <int>(i176 => () => run <int>(b174 => () => run <int>(a171 => () => run <int>(b172 => () => run <int>(k170, (a171 % b172)), 256), (a173 * b174)), m175[i176]), (a177 % b178))))), m179[i180]))), w166.snd)), w181 => () => run <Kont <int> >(w166.fst, a191 => () => run <int>(b192 => () => run <Sum <Unit, Unit> >(z184 => match <Unit, Unit>(z184, u182 => () => run <Kont <int> >(w181.fst, a185 => () => run <Kont <Kont <Pair <Kont <Kont <int> >, Kont <int> > > > >(u168 => () => run <Kont <Pair <Kont <Kont <int> >, Kont <int> > > >(u168, rec167), x187 => () => run <Pair <Kont <Kont <int> >, Kont <int> > >(x187, pair <Kont <Kont <int> >, Kont <int> >(k188 => () => run <Kont <int> >(w166.fst, a189 => () => run <int>(b190 => () => run <int>(k188, (a189 + b190)), 1)), b186 => () => run <int>(w181.snd, (a185 + b186)))))), u183 => () => run <Kont <int> >(w181.fst, w181.snd)), eql(a191, b192)), 15)))))), w109.snd)), w193 => () => run <Kont <int> >(w109.fst, a216 => () => run <Kont <int> >(w193.fst, b217 => () => run <Sum <Unit, Unit> >(z196 => match <Unit, Unit>(z196, u194 => () => run <Kont <int[]> >(w67.fst, m197 => () => run <int>(i198 => () => run <int>(v199 => () => run <int[]>(w193.snd, set(m197, i198, v199)), 1), 0)), u195 => () => run <Kont <Pair <Kont <Kont <int[]> >, Kont <int[]> > > >(x203 => () => run <Pair <Kont <Kont <int[]> >, Kont <int[]> > >(x203, pair <Kont <Kont <int[]> >, Kont <int[]> >(k204 => () => run <Kont <int[]> >(w67.fst, m205 => () => run <int>(i206 => () => run <int>(v207 => () => run <int[]>(k204, set(m205, i206, v207)), 1), 1)), m200 => () => run <int>(i201 => () => run <int>(v202 => () => run <int[]>(w193.snd, set(m200, i201, v202)), 1), 0))), w208 => () => run <Kont <int[]> >(w208.fst, m209 => () => run <int>(i210 => () => run <Kont <int[]> >(w208.fst, m214 => () => run <int>(i215 => () => run <int>(a212 => () => run <int>(b213 => () => run <int>(v211 => () => run <int[]>(w208.snd, set(m209, i210, v211)), (a212 + b213)), 1), m214[i215]), 27)), 27)))), eql(a216, b217)))))), u72 => () => run <Kont <int[]> >(w67.fst, m218 => () => run <int>(i219 => () => run <int>(v220 => () => run <int[]>(w67.snd, set(m218, i219, v220)), 1), 0))), less(a221, b222)), 6)), u69 => () => run <Kont <int[]> >(w67.fst, m223 => () => run <int>(i224 => () => run <int>(v225 => () => run <int[]>(w67.snd, set(m223, i224, v225)), 1), 0))), less(a226, b227)), 1)));

            try
            {
                while (true)
                {
                    fmain = fmain();
                }
            }
            catch (Res <int[]> rr)
            {
                /*var a = rr.res;
                 * var s11 = a[11] + a[24] + a[66];
                 * var s32 = a[32] + a[07] + a[55];
                 * var s69 = a[69] + a[81] + a[15];
                 * var s27 = a[27] + a[14] + a[52];
                 * Console.WriteLine("result: {0} {1} {2} {3} {4} {5} {6}", a[0], a[1], s11, s32, s69, s27, a[93]);
                 * Console.WriteLine("R: {0} {1}", R[0], R[1]);*/
            }
            evtDone.Set();
            Program.mainform.BeginInvoke(new MethodInvoker(Program.mainform.HideRegisterButton));
            return(R[1] > 0);
        }
Exemplo n.º 22
0
        public void TestSpeed_AddRange()
        {
            // Break-even point is about 100
            Vector3[]      source = new Vector3[120];
            List <Vector3> dest   = new List <Vector3>(500);

            // Our new overload, that internally uses GetBackingArray
            Thunk backing = () =>
            {
                List <Vector3> mydest = dest;
                mydest.Clear();
                mydest.AddRange(source, 5, source.Length - 10);
                return(0);
            };

            // Uses linq (and internally optimized, maybe?)
            Thunk linq = () =>
            {
                List <Vector3> mydest = dest;
                mydest.Clear();
                mydest.AddRange(source.Skip(5).Take(source.Length - 10));
                return(0);
            };

            // Write it out by hand
            Thunk byhand = () =>
            {
                Vector3[]      mysource = source;
                List <Vector3> mydest   = dest;
                mydest.Clear();
                int max = source.Length - 10;
                for (int i = 5; i < max; ++i)
                {
                    mydest.Add(mysource[i]);
                }
                return(0);
            };

            int iters = 30;

            SpeedTester(backing, linq, iters, "vs linq");
            SpeedTester(backing, byhand, iters, "vs byhand");
        }
Exemplo n.º 23
0
        public void Case07()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 10))
            {
                int a = random.Next(-100, 100);
                int b = random.Next(-100, 100);
                int c = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}, b={b}, c={c}");

                var expr1 = Thunk.Create((int x, int y) => x + 3 * y);
                var expr2 = Thunk.Create((int x, int y) => 2 * x + y);
                var expr3 = Thunk.Create((int x, int z) => 2 * x - z);

                var expr4 = expr1.Compose(expr3, expr2).WithParams((int x, int z, int y) => default(int));
                TestContext.WriteLine(expr4.Expression.ToString());
                Assert.AreEqual((2 * a - c) + 3 * (2 * a + b), expr4.Compile().Invoke(a, c, b));
            }
        }
Exemplo n.º 24
0
        public void Case03()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var articlesSelector = Thunk.Create <Auther, IEnumerable <Article> >(x => x.Articles);
                var articles         = db.Authers.SelectMany(articlesSelector.Expression).Select(x => x.Title).ToList();
                CollectionAssert.AreEquivalent(new[] { "Article1", "Article2", "Article3" }, articles);

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                Assert.AreEqual(1, logs.Count(s => s.Contains("SELECT")));
            }
        }
Exemplo n.º 25
0
        // Check that a is faster than b
        static void SpeedTester(Thunk a, Thunk b, int iters, string label, int warmup = 20)
        {
            // There is enough noise in this data that these asserts aren't reliable;
            // so only do them when testing performance.
            if (!sm_checkPerformance)
            {
                return;
            }

            // warm up JIT
            for (int i = 0; i < warmup; ++i)
            {
                a();
                b();
            }
            var watch = new System.Diagnostics.Stopwatch();

            watch.Reset();
            watch.Start();
            for (int i = 0; i < iters; ++i)
            {
                a();
            }
            watch.Stop();
            var ta = watch.Elapsed;

            watch.Reset();
            watch.Start();
            for (int i = 0; i < iters; ++i)
            {
                b();
            }
            watch.Stop();
            var tb = watch.Elapsed;

            Debug.LogFormat("{0}: x{3:f4}   {1:e5} vs {2:e5}", label,
                            ta.TotalSeconds,
                            tb.TotalSeconds,
                            ta.TotalSeconds / tb.TotalSeconds);
            Assert.IsTrue(ta < tb, "{2}: Expected {0} < {1}", ta, tb, label);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a mutable named child context.
        /// </summary>
        /// <remarks>
        /// Until all mutable child contexts have been disposed, no mutations are allowed on the current context.
        /// </remarks>
        public Context CreateWithName(Thunk activeThunk, FullSymbol name, ModuleLiteral module, object templateValue, LineInfo location)
        {
            Contract.Requires(name.IsValid);
            Contract.Requires(module != null);

            var topLevelValueState = new TopLevelValueInfo(
                activeThunk,
                name,
                module.Path,
                location,
                templateValue);

            return(new Context(
                       ContextTree,
                       this,
                       module,
                       topLevelValueState,
                       FileType,
                       EvaluatorConfiguration,
                       EvaluationScheduler));
        }
Exemplo n.º 27
0
        public void Case01()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 10))
            {
                int a = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}");

                var expr1 = Thunk.Create((int x) => x - 1);
                var expr2 = Thunk.Create((int x) => x / 2);

                var expr3 = expr1.Then(expr2);
                var expr4 = expr2.Then(expr1);

                TestContext.WriteLine(expr3.Expression.ToString());

                Assert.AreEqual((a - 1) / 2, expr3.ExpressionWithParams((int x) => default(int)).Compile().Invoke(a));
                Assert.AreEqual(a / 2 - 1, expr4.ExpressionWithParams((int x) => default(int)).Compile().Invoke(a));
            }
        }
Exemplo n.º 28
0
        public override Verb CreateVerb(string[] tokens)
        {
            var fieldName = tokens[2];

            Color(position, tokens[1].Length, KeyWords);
            Color(fieldName.Length, Variables);
            Color(tokens[3].Length, Operators);

            if (GetExpression(source, NextPosition, EndOfLine()).If(out var block, out var i))
            {
                overridePosition = i;
                var thunk = new Thunk(block);
                result.Value = thunk;
                return(new DefineExpression(fieldName, thunk)
                {
                    Index = NextPosition
                });
            }

            return(null);
        }
Exemplo n.º 29
0
        public void Case05()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var cond1    = Thunk.Create((Article x) => x.Content.Length < 10);
                var cond2    = Thunk.Create((Article x) => x.Content.Length > 8);
                var cond     = cond1.AndAlso(cond2).WithParams((Article x) => default(bool));
                var articles = db.Articles.Where(cond.Expression).Select(x => x.Title).ToList();

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                CollectionAssert.AreEquivalent(new[] { "Article2", }, articles);
                Assert.AreEqual(1, logs.Count(s => s.Contains("SELECT")));
            }
        }
Exemplo n.º 30
0
        // process pending jobs for GUI thread (closing, updates)
        private void HandleTimerTick(Object sender, EventArgs eargs)
        {
            if (!closed)
            {
                if (needs_closing)
                {
                    actual_close(true);
                    needs_closing = false;
                }
                else if (needs_update)
                {
                    ProcessUpdates();
                    needs_update = false;
                }

                if (initialAction != null)
                {
                    initialAction();
                    initialAction = null;
                }
            }
        }
Exemplo n.º 31
0
        public void TestSpeed_SetCountUp()
        {
            List <Vector3> list = new List <Vector3>(70);

            Thunk setcount = () => {
                list.SetCount(list.Capacity);
                list.Clear();
                return(0);
            };

            Thunk forloop = () => {
                var mylist = list;
                var num    = mylist.Capacity;
                for (int i = 0; i < num; ++i)
                {
                    mylist.Add(default(Vector3));
                }
                list.Clear();
                return(0);
            };

            SpeedTester(setcount, forloop, 10, "vs forloop");
        }
Exemplo n.º 32
0
        public void Case02()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var contentSelector = Thunk.Create((Article x) => x.Content);
                var resultSelector  = Thunk.Create((Article x) => "XXX " + x.Title + " XXX");

                var contents = db.Articles.OrderBy(contentSelector.Expression).Select(resultSelector.Expression).ToList();
                CollectionAssert.AreEqual(new[] { "XXX Article2 XXX", "XXX Article1 XXX", "XXX Article3 XXX" }, contents);

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                var log       = logs.Single(x => x.Contains("SELECT"));
                var selecters = Regex.Match(log, @"SELECT\s+(.*?)\s+FROM").Groups[1].Value;
                Assert.IsTrue(selecters.Contains("XXX"));
            }
        }
Exemplo n.º 33
0
 public static Thunk<float> Plus(Thunk<float> a, Thunk<float> b)
 {
     return Help.MakePureThunk(a.GetUserValue() + b.GetUserValue());
 }
Exemplo n.º 34
0
 public WebSiteFolder(IClock clock)
 {
     _clock = clock;
     _thunk = new Thunk(this);
 }
Exemplo n.º 35
0
 static Dictionary<long, int> runThunk(int samples, int iterations, Thunk thunk)
 {
     Dictionary<long,int> histogram = new Dictionary<long, int> ();
     for (int i = 0; i < samples; i++) {
         Stopwatch watch = Stopwatch.StartNew ();
         for (int j = 0; j < iterations; j++)
             thunk ();
         long ticks = watch.ElapsedTicks;
         int oldCount;
         if (histogram.TryGetValue (ticks, out oldCount)) {
             histogram [ticks] = oldCount + 1;
         }
         else {
             histogram [ticks] = 1;
         }
     }
     return histogram;
 }
 public DefaultVirtualPathMonitor(IClock clock)
 {
     _clock = clock;
     _thunk = new Thunk(this);
     Logger = NullLogger.Instance;
 }