示例#1
0
 public static void Main(String[] args) {
 Console.WriteLine("CO_Interlocked ...");
 Fred	f = new Fred( );
 Inc				inc				= new Inc(f);
 Dec				dec				= new Dec(f);
 Thread			Incer			= new Thread(new ThreadStart(inc.ThreadStart));
 Thread			Incer2			= new Thread(new ThreadStart(inc.ThreadStart));
 Thread			Decer			= new Thread(new ThreadStart(dec.ThreadStart));
 Thread			Decer2			= new Thread(new ThreadStart(dec.ThreadStart));
 Thread			Decer3			= new Thread(new ThreadStart(dec.ThreadStart));
 try	{
 Incer.Start( );
 Incer2.Start( );
 Decer.Start( );
 Decer2.Start( );
 Decer3.Start( );
 Incer.Join( );
 Incer2.Join( );
 Decer.Join( );
 Decer2.Join( );
 Decer3.Join( );
 }
 catch (ThreadStateException e)			{Console.WriteLine(e);}
 catch (ThreadInterruptedException e)	{Console.WriteLine(e);}
 Console.WriteLine("... CO_Interlocked");
 Environment.ExitCode = 0;
 return;
 }
示例#2
0
        public Node StatementInc()
        {
            Expect(TokenCategory.INC);
            var inc = new Inc();

            Expect(TokenCategory.SEMICOL);
            return(inc);
        }
示例#3
0
文件: Sicp.cs 项目: ramilabd/Csharp
        public static int RepeatedRecursion(int number, int count, Inc func)
        {
            if (count == 0)
            {
                return(number);
            }

            number = func(number);
            return(Repeated(number, count - 1, func));
        }
示例#4
0
        public void IncBoolTest()
        {
            var parameters = new ParameterCollection()
            {
                new Parameter("x", true)
            };
            var inc = new Inc(Variable.X);

            Assert.Throws <NotSupportedException>(() => inc.Execute(parameters));
        }
示例#5
0
        public void IncCalcTest()
        {
            var parameters = new ParameterCollection()
            {
                new Parameter("x", 10)
            };
            var inc    = new Inc(Variable.X);
            var result = (double)inc.Execute(parameters);

            Assert.Equal(11.0, result);
            Assert.Equal(11.0, parameters["x"]);
        }
示例#6
0
文件: Sicp.cs 项目: ramilabd/Csharp
        public static int Repeated(int number, int count, Inc func)
        {
            var counter = 0;

            while (counter < count)
            {
                number  = func(number);
                counter = counter + 1;
            }

            return(number);
        }
示例#7
0
        public Node StmtInc()
        {
            var result = new Inc()
            {
                AnchorToken = Expect(TokenCategory.INC)
            };

            result.Add(new Identifier()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            });

            Expect(TokenCategory.SEMICOLON);
            return(result);
        }
示例#8
0
        //-----------------------------------------------------------
        public void Visit(Inc node)
        {
            var variableName = node.AnchorToken.Lexeme;

            if (Table[funName].table.Contains(variableName) || GlobalVars.Contains(variableName))
            {
                VisitChildren(node);
            }
            else
            {
                throw new SemanticError(
                          "Undeclared variable: " + variableName,
                          node.AnchorToken);
            }
        }
        public string Visit(Inc node)
        {
            var variableName = node[0].AnchorToken.Lexeme;
            var sb           = new StringBuilder();
            var props        = FunTable[currentFunction];

            if (props.reference.ContainsKey(variableName))
            {
                sb.Append($"    local.set ${variableName}\n");
            }
            else
            {
                sb.Append($"    global.set ${variableName}\n");
            }


            return(Visit((dynamic)node[0])
                   + $"    i32.const 1\n"
                   + $"    i32.add\n"
                   + sb.ToString());
        }
示例#10
0
        private void label1_DragDrop(object sender, DragEventArgs e)
        {
            this.Activate();
            string[]  s        = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            ArrayList imgpaths = new ArrayList();

            foreach (string fpath in s)
            {
                if (Inc.IsWebImg(fpath))
                {
                    imgpaths.Add(fpath);
                }
            }
            if (imgpaths.Count != 0)
            {
                foreach (string item in imgpaths)
                {
                    Inc.ImgToBase64(item);
                }
                MessageBox.Show("转换完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#11
0
        public static void Run(Module module)
        {
            var functions = module.GetFunctionEnumerator();

            while (functions.MoveNext())
            {
                Block block = functions.Current.Code;

                var maths = from Statement s in block
                            where s is Add || s is Sub
                            select s;
                foreach (MathStatement op in maths)
                {
                    Immediate imm = op.RValue as Immediate;
                    if (imm != null)
                    {
                        int immValue = int.Parse(imm.ToString());
                        if (immValue <= 4)
                        {
                            int offset = block.Statements.IndexOf(op);
                            block.Statements.Remove(op);
                            for (int i = 0; i < immValue; i++)
                            {
                                Statement replacement = null;
                                if (op is Sub)
                                {
                                    replacement = new Dec(op.LValue);
                                }
                                else
                                {
                                    replacement = new Inc(op.LValue);
                                }
                                block.Statements.Insert(offset, replacement);
                            }
                        }
                    }
                }
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            if (args.Length != 0)
            {
                string a = Inc.IsCssOrImg(args[0].ToString()).ToString();
                switch (a)
                {
                case "img":
                    Inc.ImgToBase64(args[0].ToString());
                    break;

                case "css":
                    Inc.Base64ToImg(args[0].ToString(), Inc.GenerateTimeStamp());
                    break;
                }
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
示例#13
0
        private void label2_DragDrop(object sender, DragEventArgs e)
        {
            this.Activate();
            string[]  s        = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            ArrayList csspaths = new ArrayList();

            foreach (string csslj in s)
            {
                if (Path.GetExtension(csslj) == ".css" || Path.GetExtension(csslj) == ".txt")
                {
                    csspaths.Add(csslj);
                }
            }
            if (csspaths.Count != 0)
            {
                int j = 0;
                foreach (string item in csspaths)
                {
                    j++;
                    Inc.Base64ToImg(item, j.ToString());
                }
                MessageBox.Show("转换完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#14
0
 /// <summary>
 /// Analyzes the specified expression.
 /// </summary>
 /// <param name="exp">The expression.</param>
 /// <returns>
 /// The result of analysis.
 /// </returns>
 /// <exception cref="System.NotSupportedException">Always.</exception>
 public virtual TResult Analyze(Inc exp)
 {
     throw new NotSupportedException();
 }
示例#15
0
 /// <summary>
 /// Analyzes the specified expression.
 /// </summary>
 /// <param name="exp">The expression.</param>
 /// <returns>The result of analysis.</returns>
 public string Analyze(Inc exp)
 {
     return(ToString(exp, "{0}++"));
 }
示例#16
0
        public void TestIncNumber()
        {
            var exp = new Inc(new Number(3));

            Test(exp, ResultType.Number);
        }
示例#17
0
        public void IncToString()
        {
            var exp = new Inc(Variable.X);

            Assert.Equal("x++", exp.ToString(commoonFormatter));
        }
 public void Visit(Inc node)
 {
     Visit((dynamic)node[0]);
 }
示例#19
0
 public bool Equals(Inc other)
 {
     return(Register == other.Register);
 }
示例#20
0
        protected static bool Add <T>(SortedDictionary <DateTime, T> dict, DateTime key, Inc <T> incrementor, T defaultvalue)
        {
            T    count  = default(T);
            bool result = dict.TryGetValue(key, out count);

            if (result)
            {
                count = incrementor(count);
            }
            else
            {
                count = defaultvalue;
            }
            dict[key] = count;
            return(result);
        }
示例#21
0
 //-----------------------------------------------------------
 public string Visit(Inc node)
 {
     return("\t\tldloc '" + node.AnchorToken.Lexeme + "'\n"
            + "\t\tldc.i4.1\n"
            + "\t\tadd.ovf\n");
 }
示例#22
0
        public ISearchParameterGeneric Parse(Hl7.Fhir.Rest.SearchParams SearchParams)
        {
            this.ParameterList = new List <Tuple <string, string> >();

            //We need to go through the SearchParams.Parameters and pull out the
            //includes. This is because the API correctly pulls out the normal '_includes'
            //into it's set property yet '_includes:recurse' incorrectly are placed in the
            //SearchParams.Parameters list.

            if (SearchParams.Include != null && SearchParams.Include.Count > 0)
            {
                if (this.Include == null)
                {
                    this.Include = new List <Tuple <string, string> >();
                }
                foreach (var Inc in SearchParams.Include)
                {
                    this.Include.Add(new Tuple <string, string>(SearchParams.SEARCH_PARAM_INCLUDE, Inc.Trim()));
                }
            }

            if (SearchParams.RevInclude != null && SearchParams.RevInclude.Count > 0)
            {
                if (this.RevInclude == null)
                {
                    this.RevInclude = new List <Tuple <string, string> >();
                }
                foreach (var Inc in SearchParams.RevInclude)
                {
                    this.RevInclude.Add(new Tuple <string, string>(SearchParams.SEARCH_PARAM_REVINCLUDE, Inc.Trim()));
                }
            }



            foreach (var Para in SearchParams.Parameters)
            {
                bool IsNoramlParameter = true;
                if (ParseIncludeSearchParameters(Para.Item1, Para.Item2) != null)
                {
                    if (this.Include == null)
                    {
                        this.Include = new List <Tuple <string, string> >();
                    }
                    this.Include.Add(ParseIncludeSearchParameters(Para.Item1, Para.Item2));
                    IsNoramlParameter = false;
                }

                if (ParseRevIncludeSearchParameters(Para.Item1, Para.Item2) != null)
                {
                    if (this.RevInclude == null)
                    {
                        this.RevInclude = new List <Tuple <string, string> >();
                    }
                    this.RevInclude.Add(ParseRevIncludeSearchParameters(Para.Item1, Para.Item2));
                    IsNoramlParameter = false;
                }
                //Add parameters left to the main search parameter list
                if (IsNoramlParameter)
                {
                    this.ParameterList.Add(Para);
                }
            }

            this.Sort        = SearchParams.Sort;
            this.Count       = SearchParams.Count;
            this.SummaryType = SearchParams.Summary;
            return(this);
        }
示例#23
0
        public void IncNumberTest()
        {
            var inc = new Inc(new Number(1));

            Assert.Equal(2.0, inc.Execute());
        }