示例#1
0
文件: Swap.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     var lhs = context.Stack.Pop();
     var rhs = context.Stack.Pop();
     context.Stack.Push(lhs);
     context.Stack.Push(rhs);
 }
示例#2
0
 /// <summary>
 /// To evaluate the source code.
 /// </summary>
 /// <param name="context"></param>
 public void Evaluate(IContextable context)
 {
     foreach (var command in Progress(context))
     {
         command.Process(context, _bracemap);
     }
 }
示例#3
0
 /// <summary>
 /// If the byte at the data pointer is zero,
 /// then instead of moving the instruction pointer forward to the next command,
 /// jump it forward to the command after the matching ] command.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     if (context.Memory[context.Cursor] == 0)
     {
         context.Counter = bracemap[context.Counter];
     }
 }
示例#4
0
 /// <summary>
 /// Provided next command.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private IEnumerable<ICommandable> Progress(IContextable context)
 {
     while (context.Counter < _commands.Count)
     {
         yield return _commands[context.Counter];
         context.Counter += 1;
     }
 }
示例#5
0
文件: Lshift.cs 项目: loiol/practice
 /// <summary>
 /// Decrement the data pointer (to point to the next cell to the left).
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     context.Cursor -= 1;
     if (context.Cursor < 0)
     {
         throw new FormatException("Subscript out of range.");
     }
 }
示例#6
0
文件: Rshift.cs 项目: loiol/practice
 /// <summary>
 /// Increment the data pointer (to point to the next cell to the right).
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     context.Cursor += 1;
     if (context.Cursor == context.Memory.Count)
     {
         context.Memory.Add(0);
     }
 }
示例#7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 public void Evaluate(IContextable context)
 {
     _commands.Where(c => c is Commands.Register).ToList().ForEach(c => c.Process(context));
     foreach (Command command in Process(context).Where(c => c is Commands.Register == false))
     {
         command.Process(context);
     }
 }
示例#8
0
文件: Test.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     var value = context.Stack.Pop();
     var comparation = Compare(value);
     if (comparation.HasValue && comparation.Value)
     {
         context.ProgramCounter = context.Labels[Name];
     }
 }
示例#9
0
文件: Slide.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     var slideValue = context.Stack.Pop();
     for (var index = 0; index < Value; ++index)
     {
         context.Stack.Pop();
     }
     context.Stack.Push(slideValue);
 }
示例#10
0
        //Создает MomErr или берет уже существующий
        public MomErr MakeError(int number, IContextable addr)
        {
            var errd = Factory.GetDescr(number);

            if (errd == null)
            {
                return(null);
            }
            var dic = _errs[number] ??
                      _errs.Add(number, new Dictionary <IContextable, MomErr>());

            if (dic.ContainsKey(addr))
            {
                return(dic[addr]);
            }
            var err = new MomErr(errd, addr);

            dic.Add(addr, err);
            _usedErrorDescrs.Add(err.Number, err.ErrDescr);
            return(err);
        }
示例#11
0
        private void PrintObject1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            IDesign design = (IDesign)this.FindForm();
            IInput  input  = new InputString();
            string  def    = "";

            if (design.GetSelectObjects().Count == 1)
            {
                IContextable contextable = (IContextable)design.GetSelectObjects()[0];
                def = contextable.Context;
            }
            if (input.Input(def, out def) == true)
            {
                foreach (IPrintObject ins in design.GetSelectObjects())
                {
                    IContextable contextable = (IContextable)ins;
                    contextable.Context = def;
                }
                design.Record();
            }
        }
示例#12
0
文件: Plus.cs 项目: loiol/practice
 /// <summary>
 /// Increment (increase by one) the byte at the data pointer.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     var index = context.Cursor;
     var value = context.Memory[index];
     context.Memory[index] = value < 255 ? value + 1 : 0;
 }
示例#13
0
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.Stack.Push(context.Stack.Pop() + context.Stack.Pop());
示例#14
0
 private void addToContextableStack(IContextable el)
 {
     renderedContextableStack.Add(el);
     renderContext();
 }
示例#15
0
文件: Dot.cs 项目: loiol/practice
 /// <summary>
 /// Output the byte at the data pointer.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     var character = (char)context.Memory[context.Cursor];
     context.Output(character);
 }
示例#16
0
文件: Copy.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.Stack.Push(context.Stack.ElementAt(Value));
示例#17
0
 /// <summary>
 /// To evaluate the source code.
 /// </summary>
 /// <param name="context"></param>
 public void Evaluate(IContextable context)
 {
     _interpreter.Evaluate(context);
 }
示例#18
0
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.Labels.Add(Name, Location);
示例#19
0
文件: Call.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     context.Callstack.Push(Location);
     context.ProgramCounter = context.Labels[Name];
 }
示例#20
0
文件: End.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.ProgramCounter = int.MaxValue - 1;
示例#21
0
文件: Push.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.Stack.Push(Value);
示例#22
0
 private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     this.contextMenuStrip1.Visible = false;
     try
     {
         if (e.ClickedItem.Text == "保存")
         {
             IDesign des = this;
             string  xml = des.xml;
             //
             string t    = sheetType;
             string file = path + "\\print_style\\" + t + ".xml";
             System.IO.File.WriteAllText(file, xml, Encoding.GetEncoding("gb2312"));
         }
         else if (e.ClickedItem.Text == "页面")
         {
             IInputSize          ins  = new InputSizeForPage();
             System.Drawing.Size size = pnl.Size;
             if (ins.Input(size, out size) == true)
             {
                 pnl.Size = size;
                 Record();
             }
         }
         else if (e.ClickedItem.Text == "背景")
         {
             OpenFileDialog f = new OpenFileDialog();
             f.Filter = "*.jpg|*.jpg";
             if (f.ShowDialog() == DialogResult.OK)
             {
                 pnl.BackgroundImage       = Image.FromFile(f.FileName);
                 pnl.BackgroundImageLayout = ImageLayout.Stretch;
             }
         }
         else if (e.ClickedItem.Text == "撤销")
         {
             if (operRecord.Pre == null)
             {
             }
             else
             {
                 operRecord.Pre.Undo(des);
                 operRecord = operRecord.Pre;
             }
         }
         else if (e.ClickedItem.Text == "重做")
         {
             if (operRecord.Next == null)
             {
             }
             else
             {
                 operRecord.Next.Undo(des);
                 operRecord = operRecord.Next;
             }
         }
         else if (e.ClickedItem.Text == "文本")
         {
             IPrintObject ins = new PrintObject1();
             ins.SetSelectControl(this);
             ISizeable    sizeable    = (ISizeable)ins;
             IContextable contextable = (IContextable)ins;
             sizeable.Location   = this.p;
             contextable.Context = "普通文本";
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "表格")
         {
             IPrintObject ins = new PrintObject3();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "竖线")
         {
             IPrintObject ins = new PrintObject4();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "横线")
         {
             IPrintObject ins = new PrintObject5();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "图片")
         {
             IPrintObject ins = new PrintObject6();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "页码")
         {
             IPrintObject ins = new PrintObject7();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
         else if (e.ClickedItem.Text == "时间")
         {
             IPrintObject ins = new PrintObject8();
             ins.SetSelectControl(this);
             ISizeable sizeable = (ISizeable)ins;
             sizeable.Location = this.p;
             ins.Show(pnl);
             Record();
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }
示例#23
0
 //Создание ошибки
 internal MomErr MakeError(int number, IContextable addr)
 {
     return(ErrPool.MakeError(number, addr));
 }
示例#24
0
文件: Back.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.ProgramCounter = context.Callstack.Pop();
示例#25
0
 public MomErr(ErrDescr errDescr, IContextable addr)
 {
     ErrDescr    = errDescr;
     AddressLink = addr;
 }
示例#26
0
文件: Comma.cs 项目: loiol/practice
 /// <summary>
 /// Accept one byte of input,
 /// storing its value in the byte at the data pointer.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="bracemap"></param>
 public void Process(IContextable context, Dictionary<int, int> bracemap)
 {
     var character = context.Input();
     context.Memory[context.Cursor] = (int)character;
 }
示例#27
0
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     var address = context.Stack.Pop();
     context.Stack.Push(context.Heap[address]);
 }
示例#28
0
        private void contextMenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            this.contextMenuStrip2.Visible = false;
            try
            {
                if (e.ClickedItem.Text == "文本内容")
                {
                    IInput input = new InputString();
                    string def   = "";
                    if (SelectObjects.Count == 1)
                    {
                        IContextable contextable = (IContextable)SelectObjects[0];
                        def = contextable.Context;
                    }
                    if (input.Input(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IContextable contextable = (IContextable)ins;
                            contextable.Context = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "文本对齐")
                {
                    ISelectContextAlign align = new SelectContextAlign();
                    int def = 0;
                    if (SelectObjects.Count == 1)
                    {
                        IContextAlignAble contextalignable = (IContextAlignAble)SelectObjects[0];
                        def = contextalignable.Align;
                    }
                    if (align.Select(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IContextAlignAble contextalignable = (IContextAlignAble)ins;
                            contextalignable.Align = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "区域")
                {
                    IInput input = new InputString();
                    int    Area  = -1;
                    if (SelectObjects.Count == 1)
                    {
                        IChangeAreaAble changeareaable = (IChangeAreaAble)SelectObjects[0];
                        Area = changeareaable.Area;
                    }
                    IChangePrintArea printarea = new ChangePrintArea();
                    if (printarea.Change(Area, out Area) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IChangeAreaAble changeareaable = (IChangeAreaAble)ins;
                            changeareaable.Area = Area;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "删除")
                {
                    List <IPrintObject> lst = new List <IPrintObject>();
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        lst.Add(ins);
                    }
                    foreach (IPrintObject ins in lst)
                    {
                        IDeleteable deleteable = (IDeleteable)ins;
                        deleteable.Delete(pnl);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "字体")
                {
                    FontDialog f = new FontDialog();

                    if (SelectObjects.Count == 1)
                    {
                        IFontable fontable = (IFontable)SelectObjects[0];
                        f.Font = fontable.Font;
                    }
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFontable fontable = (IFontable)ins;
                            fontable.Font = f.Font;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "边框")
                {
                    IEditBorder border       = new EditBorder();
                    int         borderLeft   = 0;
                    int         borderRight  = 0;
                    int         borderTop    = 0;
                    int         borderBottom = 0;
                    if (SelectObjects.Count == 1)
                    {
                        IBorderable borderable = (IBorderable)SelectObjects[0];
                        borderLeft   = borderable.BorderLeft;
                        borderRight  = borderable.BorderRight;
                        borderTop    = borderable.BorderTop;
                        borderBottom = borderable.BorderBottom;
                    }
                    if (border.EditBorder(borderLeft, borderRight, borderTop, borderBottom,
                                          out borderLeft, out borderRight, out borderTop, out borderBottom) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IBorderable borderable = (IBorderable)ins;
                            borderable.BorderLeft   = borderLeft;
                            borderable.BorderRight  = borderRight;
                            borderable.BorderTop    = borderTop;
                            borderable.BorderBottom = borderBottom;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "颜色")
                {
                    ColorDialog f   = new ColorDialog();
                    Color       def = Color.Black;
                    if (SelectObjects.Count == 1)
                    {
                        IColorable colorable = (IColorable)SelectObjects[0];
                        def = colorable.Color;
                    }
                    f.Color = def;
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IColorable colorable = (IColorable)ins;
                            colorable.Color = f.Color;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "左对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable2.Location.X, sizeable.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "右对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point((sizeable2.Location.X + sizeable2.Size.Width) - sizeable.Size.Width, sizeable.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "上对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable.Location.X, sizeable2.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "下对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable.Location.X, (sizeable2.Location.Y + sizeable2.Size.Height) - sizeable.Size.Height);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "表格内容")
                {
                    IGridable     gridable = (IGridable)_fistSelectObject;
                    List <string> lst      = new List <string>();

                    if (tbdetail != null)
                    {
                        foreach (System.Data.DataColumn col in tbdetail.Columns)
                        {
                            if (col.ColumnName.StartsWith("#") == false)
                            {
                                lst.Add(col.ColumnName);
                            }
                        }
                    }

                    if (lst.Contains("#") == false)
                    {
                        lst.Add("#");
                    }
                    if (lst.Contains("i") == false)
                    {
                        lst.Add("i");
                    }



                    if (gridable.EditGrid(lst.ToArray()) == true)
                    {
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "表格格式")
                {
                    IGridable gridable = (IGridable)_fistSelectObject;
                    if (gridable.SetStyle() == true)
                    {
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "导入图片")
                {
                    OpenFileDialog f = new OpenFileDialog();
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        var     fileInfo = new System.IO.FileInfo(f.FileName);
                        decimal len      = Conv.ToDecimal(fileInfo.Length);
                        len = len / 1024;
                        if (len > 500)
                        {
                            throw new Exception("图片文件大于500K");
                        }
                        var        img       = Image.FromFile(f.FileName);
                        IImageAble imageable = (IImageAble)_fistSelectObject;
                        imageable.Image = img;
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "导出图片")
                {
                    IImageAble imageable = (IImageAble)_fistSelectObject;
                    if (imageable.Image == null)
                    {
                        throw new Exception("无可导出的图片");
                    }
                    else
                    {
                        SaveFileDialog f = new SaveFileDialog();
                        f.Filter = "*.jpg|*.jpg";
                        if (f.ShowDialog() == DialogResult.OK)
                        {
                            imageable.Image.Save(f.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                }
                else if (e.ClickedItem.Text == "属性")
                {
                    System.Windows.Forms.MessageBox.Show(_fistSelectObject.propertyInfo, "属性");
                }
                else if (e.ClickedItem.Text == "格式化")
                {
                    IInput input = new InputFormatString();
                    string def   = "";
                    if (SelectObjects.Count == 1)
                    {
                        IFormatable formatable = (IFormatable)SelectObjects[0];
                        def = formatable.Format;
                    }
                    if (input.Input(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFormatable formatable = (IFormatable)ins;
                            formatable.Format = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "改字段")
                {
                    string def = "";
                    if (SelectObjects.Count == 1)
                    {
                        IFieldAble fieldable = (IFieldAble)SelectObjects[0];
                        def = fieldable.Field;
                    }
                    IChangeField  chg = new ChangeField();
                    List <string> lst = new List <string>();
                    if (tbmain != null)
                    {
                        foreach (System.Data.DataColumn col in tbmain.Columns)
                        {
                            lst.Add(col.ColumnName);
                        }
                    }
                    if (chg.Change(lst.ToArray(), def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFieldAble fieldable = (IFieldAble)ins;
                            fieldable.Field = def;
                        }
                        Record();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
示例#29
0
文件: Command.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public abstract void Process(IContextable context);
示例#30
0
文件: Store.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context)
 {
     var value = context.Stack.Pop();
     var address = context.Stack.Pop();
     context.Heap[address] = value;
 }
示例#31
0
文件: Jump.cs 项目: loiol/practice
 /// <summary>
 /// Run the command.
 /// </summary>
 /// <param name="context">Execution context.</param>
 public override void Process(IContextable context) => context.ProgramCounter = context.Labels[Name];