Exemplo n.º 1
0
        public override void OnMouseDown(MouseActionEventArgs e)
        {
            var scene = Folding.SceneHandler();

            if (HitCount == 0)
            {
                Focused = scene.Focused;
                                #if TraceMouse
                Trace.WriteLine(string.Format("GraphSceneMouseFolding OnMouseDown Focused: {0}", Focused));
                                #endif
            }
            base.OnMouseDown(e);

            if (Focused != null && Focused != scene.Focused)
            {
                                #if TraceMouse
                Trace.WriteLine(string.Format("GraphSceneMouseFolding OnMouseDown HitCount=0, was: {0}", HitCount));
                                #endif
                HitCount = 0;
            }
                        #if TraceMouse
            Trace.WriteLine(string.Format("GraphSceneMouseFolding OnMouseDown HitCount {0}", HitCount));
                        #endif
            Resolved = HitCount > 0;
        }
Exemplo n.º 2
0
        private void OnFoldNeeded(int firstLine, int lastLine, ScNotification scn)
        {
            var end = LineCount;

            while (GetLineIndentation(firstLine) != 0 && firstLine > 0)
            {
                firstLine--;
            }

            while (GetLineIndentation(lastLine) != 0 && lastLine > end)
            {
                lastLine--;
            }

            if (firstLine < 0 || lastLine > end)
            {
                return;
            }

            var ev = new FoldNeededEventArgs(firstLine, lastLine);
            var h  = FoldNeeded;

            if (h != null)
            {
                h(this, ev);
                Folding.Fold(ev.Regions);
            }
        }
        private string ExpressionToString(IExpression <T> exp, AssemblyContext <T> assemblyContext)
        {
            switch (exp.Type)
            {
            case EAExpressionType.List:
                return(exp.GetChildren().ToElementWiseString(", ", "[", "]"));

            case EAExpressionType.Code:
                var code = (Code <T>)exp;

                return(code.CodeName.Name + code.Parameters.Select(
                           x => ExpressionToString(x, assemblyContext)).ToElementWiseString(" ", " ", ""));

            case EAExpressionType.XOR:
            case EAExpressionType.AND:
            case EAExpressionType.OR:
            case EAExpressionType.LeftShift:
            case EAExpressionType.RightShift:
            case EAExpressionType.Division:
            case EAExpressionType.Multiply:
            case EAExpressionType.Modulus:
            case EAExpressionType.Minus:
            case EAExpressionType.Sum:
            case EAExpressionType.Value:
            case EAExpressionType.Symbol:
                return((from val in Folding.Fold(exp, y => GetSymbolVal(y, assemblyContext), intType)
                        select intType.ToString(val, 16)).ValueOrDefault(exp.ToString));

            //case EAExpressionType.Scope:
            //case EAExpressionType.Labeled:
            //case EAExpressionType.Assignment:
            default:
                throw new ArgumentException("malformed tree");
            }
        }
 private void HandleBuiltInProtect(Code <int> code, ScopeStructure <int> scope)
 {
     if (code.ParameterCount.IsInRange(1, 1))
     {
         CanCauseError <int> canCauseError = Folding.Fold(code [0], (x => this.GetSymbolValue(scope, x)));
         if (!canCauseError.CausedError)
         {
             this.protectedRegions.Add(new Tuple <int, int> (canCauseError.Result, 4));
         }
     }
     else if (code.ParameterCount.IsInRange(2, 2))
     {
         CanCauseError <int> firstParam  = Folding.Fold(code [0], (x => this.GetSymbolValue(scope, x)));
         CanCauseError <int> secondParam = Folding.Fold(code [1], (x => this.GetSymbolValue(scope, x)));
         if (!firstParam.CausedError && !secondParam.CausedError)
         {
             if (firstParam.Result < secondParam.Result)
             {
                 this.protectedRegions.Add(new Tuple <int, int> (firstParam.Result, secondParam.Result - firstParam.Result));
             }
             else
             {
                 this.log.AddWarning("Protected region not valid (end offset not after start offset). No region protected.");
             }
         }
     }
     else
     {
         this.AddNotCorrectParameters <int> (code, 2);
     }
 }
 public Draw()
 {
     _dimensions        = new Dimensions();
     _rootPanel         = new Panel();
     _rootPanelPosition = new Position();
     _folding           = new Folding(_dimensions, _rootPanelPosition, _rootPanel);
 }
        private string ExpressionToString(IExpression <int> exp, ScopeStructure <int> scope)
        {
            switch (exp.Type)
            {
            case EAExpressionType.Code:
                Code <int> code = exp as Code <int>;
                return(code.CodeName.Name + ((IEnumerable <IExpression <int> >)code.Parameters).Select((x => this.ExpressionToString(x, scope))).ToElementWiseString <string> (" ", " ", ""));

            case EAExpressionType.XOR:
            case EAExpressionType.AND:
            case EAExpressionType.OR:
            case EAExpressionType.LeftShift:
            case EAExpressionType.RightShift:
            case EAExpressionType.ArithmeticRightShift:
            case EAExpressionType.Division:
            case EAExpressionType.Multiply:
            case EAExpressionType.Modulus:
            case EAExpressionType.Minus:
            case EAExpressionType.Sum:
            case EAExpressionType.Value:
            case EAExpressionType.Symbol:
                CanCauseError <int> canCauseError = Folding.Fold(exp, (y => this.GetSymbolValue(scope, y)));
                if (canCauseError.CausedError)
                {
                    return(exp.ToString());
                }
                return(canCauseError.Result.ToHexString("0x"));

            case EAExpressionType.List:
                return(exp.GetChildren().ToElementWiseString <IExpression <int> > (", ", "[", "]"));

            default:
                throw new ArgumentException("malformed tree");
            }
        }
        private void HandleBuiltInAssert(Code <int> code, ScopeStructure <int> scope)
        {
            if (code.ParameterCount.IsInRange(1, 1))
            {
                if (code [0] is ExpressionList <int> )
                {
                    this.AddNotAtomTypeParameter <int> (code [0]);
                }
                else
                {
                    CanCauseError <int> error = Folding.Fold(code [0], (x => this.GetSymbolValue(scope, x)));

                    if (error.CausedError)
                    {
                        this.AddError((IExpression <int>)code, error);
                    }
                    else if (error.Result < 0)
                    {
                        this.AddError(code, "Assertion failed.");
                    }
                }
            }
            else
            {
                this.AddNotCorrectParameters <int> (code, 1);
            }
        }
        private void HandleBuiltInOffsetAlign(Code <int> code, ScopeStructure <int> scope)
        {
            if (code.ParameterCount.IsInRange(1, 1))
            {
                if (code [0] is ExpressionList <int> )
                {
                    this.AddNotAtomTypeParameter <int> (code [0]);
                }
                else
                {
                    CanCauseError <int> error = Folding.Fold(code [0], (x => this.GetSymbolValue(scope, x)));

                    if (error.CausedError)
                    {
                        this.AddError <int, int> ((IExpression <int>)code, error);
                    }
                    else
                    {
                        this.currentOffset = this.currentOffset.ToMod(error.Result);
                    }
                }
            }
            else
            {
                this.AddNotCorrectParameters <int> (code, 1);
            }
        }
        private void PrintAssemblyCode(Code <int> code, ScopeStructure <int> scope, TextWriter output)
        {
            output.Write("\t");
            for (int i = 0; i < code.Parameters.Length; i++)
            {
                // support EA macro in inline assembly
                if (!scope.IsLocalLabelExisted(code.Parameters[i].ToString()) && !scope.GetSymbolValue(code.Parameters[i].ToString()).CausedError)
                {
                    output.Write(" #0x{0:X}", Folding.Fold(code.Parameters[i], (x => this.GetSymbolValue(scope, x))).Result);
                }
                else
                {
                    output.Write(" {0}", code.Parameters[i].ToString());
                }

                if (i == 0)
                {
                    output.Write("\t");
                    if (code.Parameters[0].ToString() == "push" || code.Parameters[0].ToString() == "pop")
                    {
                        output.Write("{");
                    }
                }
                if (i != code.Parameters.Length - 1)
                {
                    if (i != 0)
                    {
                        output.Write(",");
                    }

                    if (code.Parameters[0].ToString().StartsWith("ldr") || code.Parameters[0].ToString().StartsWith("str"))
                    {
                        if (i == 1)
                        {
                            output.Write("[");
                        }
                    }

                    // Console.WriteLine(code.Parameters[i + 1].ToString());
                    if (System.Text.RegularExpressions.Regex.IsMatch(code.Parameters[i + 1].ToString(), @"^\d+$"))
                    {
                        output.Write("#");
                    }
                }
                else
                {
                    if (code.Parameters[0].ToString() == "push" || code.Parameters[0].ToString() == "pop")
                    {
                        output.Write(" }");
                    }
                    else
                    if (code.Parameters[0].ToString().StartsWith("ldr") || code.Parameters[0].ToString().StartsWith("str"))
                    {
                        output.Write(" ]");
                    }
                    output.Write("\n");
                }
            }
        }
Exemplo n.º 10
0
 public UserOptions(Folding foldingMode, Title titleMode, 
     bool moveToNewForder, string secondDirPath)
 {
     FoldingMode = foldingMode;
     TitleMode = titleMode;
     MoveToNewFolder = moveToNewForder;
     SecondDirPath = secondDirPath;
 }
Exemplo n.º 11
0
 public UserOptions(Folding foldingMode, Title titleMode,
                    bool moveToNewForder, string secondDirPath)
 {
     FoldingMode     = foldingMode;
     TitleMode       = titleMode;
     MoveToNewFolder = moveToNewForder;
     SecondDirPath   = secondDirPath;
 }
Exemplo n.º 12
0
        public void AttachBuffer(IBuffer buf)
        {
            var buffer = buf as DocumentBuffer;

            if (buffer == null)
            {
                throw new NotSupportedException();
            }

            if (Buffer != null && buffer != Buffer)
            {
                DetachBuffer();
            }
            else if (Buffer == buffer)
            {
                return;
            }

            var @lock = Buffer?.ObtainLock();

            try
            {
                buffer.LastAccess = DateTime.Now;

                if (buffer != Buffer)
                {
                    buffer.Editors.Add(this);
                    Buffer = buffer;
                }

                if (Buffer.GrammarKey == null)
                {
                    Buffer.GrammarKey = App.Component <IModeManager>()
                                        .SelectMode(buffer.File).Key;
                }

                Scroll.InvalidateLines(InvalidateFlags.Force);
                Scroll.ScrollPosition = buffer.ScrollPosition;
                Styles.RestyleDocument();
                Folding.RebuildFolding(full: true);
                Redraw();
                MatchBrackets.Match();
                Search.HideSearch();
                TopMargins.ResetMargins();
                BottomMargins.ResetMargins();
                LeftMargins.ResetMargins();
                RightMargins.ResetMargins();
            }
            finally
            {
                if (@lock != null)
                {
                    @lock.Release();
                }
            }
        }
 private void HandleBuiltInOffsetChange(Code <int> code, ScopeStructure <int> scope)
 {
     if (code.ParameterCount.IsInRange(1, 1) && !(code [0] is ExpressionList <int>))
     {
         CanCauseError <int> canCauseError = Folding.Fold(code [0], (x => this.GetSymbolValue(scope, x)));
         if (!canCauseError.CausedError)
         {
             this.currentOffset = canCauseError.Result;
         }
     }
 }
Exemplo n.º 14
0
        protected override bool CheckDoubleClickHit(double x, double y)
        {
            if (Focused == null)
            {
                return(false);
            }

            var scene = Folding.SceneHandler();
            var pt    = Camera().ToSource(new Point(x, y));

            return(scene.Hit(pt, HitSize) == Focused);
        }
Exemplo n.º 15
0
        public ICanvas Draw(Folding folding)
        {
            if (folding == null)
            {
                throw new ArgumentNullException(nameof(folding));
            }
            var emptyCanvas          = _emptyCanvasFactory.Create(folding.Dimensions);
            var panelRectangles      = _panelRectangleFactory.Create(folding.RootPanel, folding.RootPanelPosition);
            var canvasWithRectangles = panelRectangles
                                       .Select(panelRectangle => panelRectangle.Rectangle)
                                       .Aggregate(emptyCanvas, (canvas, rectangle) => _rectangleDrawer.Draw(canvas, rectangle));

            return(canvasWithRectangles);
        }
Exemplo n.º 16
0
 private CanCauseError <T> GetSymbolVal(string symbolName, AssemblyContext <T> assemblyContext)
 {
     if (symbolName.Equals(currentOffsetCode, stringComparison) ||
         symbolName.Equals(offsetChanger, stringComparison))
     {
         return(intType.FromInt(assemblyContext.CurrentOffset));
     }
     else
     {
         return(from expression in assemblyContext.CurrentScope.GetSymbolValue(symbolName)
                from foldResult in Folding.Fold(expression, x => GetSymbolVal(x, assemblyContext), intType)
                select foldResult);
     }
 }
        public Bitmap Render(Folding folding)
        {
            var img = new Bitmap(folding.OriginalDocumentWidth, folding.OriginalDocumentHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);

            var canvas = Graphics.FromImage(img);

            var rootPanel = folding.Panels[0];

            var(rootX, rootY) = (folding.RootX - (rootPanel.PanelWidth / 2), folding.RootY - rootPanel.PanelHeight);

            canvas.TranslateTransform(rootX, rootY);

            RenderPanel(canvas, rootPanel, null, new Stack <GraphicsState>());

            return(img);
        }
Exemplo n.º 18
0
        public CanCauseError <byte[]> GetData(IExpression <int>[] code, Func <string, int?> getSymbolValue)
        {
            List <byte> byteList = new List <byte>(this.GetLengthBytes(code));

            for (int index = 0; index < code.Length; ++index)
            {
                CanCauseError <int> aResult = Folding.TryFold(code[index], getSymbolValue);
                if (aResult.CausedError)
                {
                    return(aResult.ConvertError <byte[]>());
                }
                byteList.AddRange((IEnumerable <byte>)BitConverter.GetBytes((short)aResult.Result));
            }
            //int num = code.Length / this.AmountOfParams;
            return((CanCauseError <byte[]>)byteList.ToArray());
            //throw new NotImplementedException();
        }
Exemplo n.º 19
0
 internal static CanCauseError <int[]> GetValues(IExpression <int> parameter, TemplateParameter paramTemp, Func <string, int?> getSymbolValue, IPointerMaker pointerMaker)
 {
     int[] numArray;
     if (parameter is ExpressionList <int> )
     {
         ExpressionList <int> expressionList = parameter as ExpressionList <int>;
         numArray = new int[expressionList.ComponentCount];
         for (int index = 0; index < expressionList.ComponentCount; ++index)
         {
             CanCauseError <int> canCauseError = Folding.Fold(expressionList[index], getSymbolValue);
             if (canCauseError.CausedError)
             {
                 return(canCauseError.ConvertError <int[]>());
             }
             numArray[index] = canCauseError.Result;
         }
     }
     else
     {
         CanCauseError <int> canCauseError = Folding.Fold(parameter, getSymbolValue);
         if (canCauseError.CausedError)
         {
             return(canCauseError.ConvertError <int[]>());
         }
         if (paramTemp.pointer && pointerMaker != null)
         {
             numArray = new int[1]
             {
                 pointerMaker.MakePointer(canCauseError.Result)
             }
         }
         ;
         else
         {
             numArray = new int[1]
             {
                 canCauseError.Result
             }
         };
     }
     return((CanCauseError <int[]>)numArray);
 }
Exemplo n.º 20
0
 protected override void EndAction()
 {
                 #if TraceMouse
     Trace.WriteLine(string.Format("GraphSceneMouseFolding EndAction HitCount {0}", HitCount));
     Trace.WriteLine(string.Format("GraphSceneMouseFolding EndAction Focused: {0}", Focused));
                 #endif
     if (HitCount == 1)
     {
         Folding.Fold(() => Folding.Folder.Toggle());
         LastMouseTime = 0;
         HitCount      = 0;
         Focused       = null;
     }
     if (HitCount > 1)
     {
         Focused  = null;
         HitCount = 0;
     }
     base.EndAction();
 }
Exemplo n.º 21
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            var mouse = e.GetSpecialKey();

            if (e.Button == MouseButtons.Left)
            {
                var mlist = Locations.FindMargin(e.Location);

                if (mlist != null)
                {
                    mlist.CallMarginMethod(MarginMethod.MouseDown, e.Location);
                }
                else
                {
                    var pos = Locations.LocationToPosition(e.Location);
                    Caret = pos.IsEmpty ? default(Pos) : pos;
                    RunCommand(new KeyInput(ModifierKeys.ToModifiers(), mouse));
                    var idx = Buffer.Selections.IndexOfCaret(pos);

                    if (idx != -1)
                    {
                        var sca = Buffer.Selections[idx].Caret;
                        Buffer.Selections[idx].SetToRestore(
                            Document.Lines[sca.Line].GetStripeCol(sca.Col));
                    }

                    if (Lines[pos.Line].Length == pos.Col && Folding.IsCollapsedHeader(pos.Line))
                    {
                        Folding.ToggleExpand(pos.Line);
                        Scroll.InvalidateLines();
                        Redraw();
                    }

                    if (!Focused)
                    {
                        Focus();
                    }
                }
            }
        }
        private int?GetSymbolValue(ScopeStructure <int> scope, string symbolName)
        {
            if (symbolName.Equals(currentOffsetCode, StringComparison.OrdinalIgnoreCase) || symbolName.Equals(offsetChanger, StringComparison.OrdinalIgnoreCase))
            {
                return(new int?(this.currentOffset));
            }

            CanCauseError <IExpression <int> > symbolValue = scope.GetSymbolValue(symbolName);

            if (symbolValue.CausedError)
            {
                return(new int?());
            }

            CanCauseError <int> canCauseError = Folding.Fold(symbolValue.Result, (x => this.GetSymbolValue(scope, x)));

            if (canCauseError.CausedError)
            {
                return(new int?());
            }

            return(new int?(canCauseError.Result));
        }
Exemplo n.º 23
0
 public bool Check()
 {
     return(Folding != null && Folding.Check());
 }
Exemplo n.º 24
0
        private bool HandleBuiltInCode(Code <T> code, AssemblyContext <T> assemblyContext, bool addToLog)
        {
            string text;

            switch (code.CodeName.Name)
            {
            case messagePrinterCode:
                if (addToLog)
                {
                    text = ExpressionToString(code, assemblyContext);
                    assemblyContext.Log.AddMessage(text.Substring(code.CodeName.Name.Length + 1));
                }
                return(true);

            case errorPrinterCode:
                if (addToLog)
                {
                    text = ExpressionToString(code, assemblyContext);
                    assemblyContext.Log.AddError(text.Substring(code.CodeName.Name.Length + 1));
                }
                return(true);

            case warningPrinterCode:
                if (addToLog)
                {
                    text = ExpressionToString(code, assemblyContext);
                    assemblyContext.Log.AddWarning(text.Substring(code.CodeName.Name.Length + 1));
                }
                return(true);

            case currentOffsetCode:
            case offsetAlinger:
                if (code.ParameterCount.IsInRange(1, 1))
                {
                    if (code[0] is ExpressionList <T> )
                    {
                        if (addToLog)
                        {
                            assemblyContext.AddNotAtomTypeParameter(code[0]);
                        }
                    }
                    else
                    {
                        var align = Folding.Fold(code[0], x => CanCauseError <T> .Error("No symbols available."), intType);
                        if (align.CausedError)
                        {
                            if (addToLog)
                            {
                                assemblyContext.AddError(code, align);
                            }
                        }
                        else
                        {
                            assemblyContext.CurrentOffset = assemblyContext.CurrentOffset.ToMod(intType.GetIntValue(align.Result));
                        }
                    }
                }
                else
                {
                    if (addToLog)
                    {
                        assemblyContext.AddNotCorrectParameters(code, 1);
                    }
                }
                return(true);

            case offsetChanger:
                if (code.ParameterCount.IsInRange(1, 1))
                {
                    if (code[0] is ExpressionList <T> )
                    {
                        if (addToLog)
                        {
                            assemblyContext.AddNotAtomTypeParameter(code[0]);
                        }
                    }
                    else
                    {
                        var newOffset = Folding.Fold(code[0], x => CanCauseError <T> .Error("No symbols available."), intType);
                        if (newOffset.CausedError)
                        {
                            if (addToLog)
                            {
                                assemblyContext.AddError(code, newOffset);
                            }
                        }
                        else
                        {
                            assemblyContext.CurrentOffset = intType.GetIntValue(newOffset.Result);
                        }
                    }
                }
                else
                {
                    if (addToLog)
                    {
                        assemblyContext.AddNotCorrectParameters(code, 1);
                    }
                }
                return(true);

            default:
                return(false);
            }
        }
        private ScopeStructure <int> ExecuteLayoutPass <T>(IExpression <int> expression, ScopeStructure <int> scope, T output)
        {
            switch (expression.Type)
            {
            case EAExpressionType.Scope:
            {
                ScopeStructure <int> newScope = new ScopeStructure <int> (scope);
                scopeStructures [(Scope <int>)expression] = newScope;

                foreach (IExpression <int> child in expression.GetChildren())
                {
                    ExecuteLayoutPass(child, newScope, output);
                }

                break;
            }

            case EAExpressionType.Code:
            {
                Code <int> code = expression as Code <int>;

                if (code.IsEmpty || HandleBuiltInCodeLayout(code, scope))
                {
                    break;
                }

                if (code.CodeName.Name == "ASMC" && code.Parameters[0].ToString() != "" && !System.Text.RegularExpressions.Regex.IsMatch(code.Parameters[0].ToString(), @"\A\b(0[xX])?[0-9a-fA-F]+\b\Z"))
                {
                    scope.RegisterASMCLabel(code.Parameters[0].ToString());
                }

                Types.Type[] sig = ((IEnumerable <IExpression <int> >)code.Parameters).Select(new Func <IExpression <int>, Types.Type> (Types.Type.GetType <int>)).ToArray();

                CanCauseError <ICodeTemplate> templateError = this.storer.FindTemplate(code.CodeName.Name, sig);

                if (templateError.CausedError)
                {
                    AddError <int, ICodeTemplate> ((IExpression <int>)code, templateError);
                    break;
                }

                ICodeTemplate template = templateError.Result;

                // Checking alignment
                if (currentOffset % template.OffsetMod != 0)
                {
                    this.AddError <int> ((IExpression <int>)code, "Code {0}'s offset {1} is not divisible by {2}", (object)code.CodeName.Name, (object)this.currentOffset.ToHexString("$"), (object)template.OffsetMod);
                }

                // TODO: maybe we want to store the template somewhere to lookup for later?
                // May or may not be faster than computing it again in the write pass

                this.currentOffset += template.GetLengthBytes(((IEnumerable <IExpression <int> >)code.Parameters).ToArray());
                break;
            }

            case EAExpressionType.Labeled:
            {
                // record label names
                scope.SetLocalLabelAddress(((LabelExpression <int>)expression).LabelName, currentOffset);

                CanCauseError err = scope.AddNewSymbol(((LabelExpression <int>)expression).LabelName, new ValueExpression <int> (this.currentOffset, new FilePosition()));

                if (err.CausedError)
                {
                    AddWarning(expression, err.ErrorMessage);
                }

                break;
            }

            case EAExpressionType.Assignment:
            {
                Assignment <int>    assingment = (Assignment <int>)expression;
                CanCauseError <int> value      = Folding.Fold(assingment.Value, x => this.GetSymbolValue(scope, x));

                CanCauseError err = null;

                if (value.CausedError)
                {
                    err = scope.AddNewSymbol(assingment.Name, assingment.Value);
                }
                else
                {
                    err = scope.AddNewSymbol(assingment.Name, new ValueExpression <int> (value.Result, new FilePosition()));
                }

                if (err.CausedError)
                {
                    AddWarning(expression, err.ErrorMessage);
                }

                break;
            }

            case EAExpressionType.RawData:
            {
                RawData <int> rawData = (RawData <int>)expression;
                this.currentOffset += rawData.Data.Length;

                break;
            }

            default:
                throw new ArgumentException("Badly formed tree.");
            }

            // DeclareExternASMCLabels<T>(scope, output);
            return(scope);
        }
        private void ExecuteWritePass(TextWriter output, IExpression <int> expression, ScopeStructure <int> scope)
        {
            // This is to be executed *after* the layout pass

            switch (expression.Type)
            {
            case EAExpressionType.Scope:
            {
                ScopeStructure <int> newScope = scopeStructures [(Scope <int>)expression];

                foreach (IExpression <int> child in expression.GetChildren())
                {
                    ExecuteWritePass(output, child, newScope);
                }

                break;
            }

            case EAExpressionType.Code:
            {
                Code <int> code = expression as Code <int>;

                // alignment. ALIGN 2^n => .align n
                if (!code.IsEmpty && code.CodeName.Name == offsetAligner && code.ParameterCount.IsInRange(1, 1) && !(code.Parameters[0] is ExpressionList <int>))
                {
                    output.WriteLine("\t.align {0}", Math.Ceiling(Math.Log(Folding.Fold(code.Parameters[0], (x => this.GetSymbolValue(scope, x))).Result, 2)));
                }

                if (code.IsEmpty || HandleBuiltInCodeWrite(code, scope, output))
                {
                    break;
                }

                bool TFlag = false;
                // bool ExtFlag = false;

                if (code.CodeName.Name == "ASMC")
                {
                    if (code.Parameters.Length > 0 && code.Parameters[0].ToString() != "" && !scope.IsLocalLabelExisted(code.Parameters[0].ToString()) && !System.Text.RegularExpressions.Regex.IsMatch(code.Parameters[0].ToString(), @"\A\b(0[xX])?[0-9a-fA-F]+\b\Z"))
                    {
                        // ExtFlag = true;
                    }
                    else
                    {
                        TFlag = true;
                    }
                }

                // Maybe all of this template lookup up can be made faster by
                // storing the found template from the layout pass?

                Types.Type[] sig = ((IEnumerable <IExpression <int> >)code.Parameters).Select(new Func <IExpression <int>, Types.Type> (Types.Type.GetType <int>)).ToArray();

                CanCauseError <ICodeTemplate> templateError = this.storer.FindTemplate(code.CodeName.Name, sig);

                if (templateError.CausedError)
                {
                    AddError <int, ICodeTemplate> ((IExpression <int>)code, templateError);
                    break;
                }

                // We won't check for alignment as it should already have been done in the layout pass

                ICodeTemplate template = templateError.Result;

                /*if (template is CodeTemplate && code.Parameters.Length > 0)
                 * {
                 *  for (int i = 0; i < code.Parameters.Length; i++)
                 *  {
                 *      if(scope.GetRegisteredASMCLabels().Exists(o => o == code.Parameters[i].ToString()))
                 *      {
                 *          (template as CodeTemplate).AddExternLabel(i, code.Parameters[i].ToString());
                 *      }
                 *  }
                 * }*/

                CanCauseError <byte[]> data = template.GetData(code.Parameters, x => this.GetSymbolValue(scope, x), scope);

                Dictionary <int, string> localLabels  = template.GetLocalLabels();
                Dictionary <int, string> externLabels = template.GetExternLabels();
                var labels = localLabels.Union(externLabels).ToList();

                if (data.CausedError)
                {
                    // Can't compute code data, so we err
                    this.AddError <int, byte[]> (expression, data);
                }
                else
                {
                    // Write data
                    if (labels.Count == 0)
                    {
                        TryWrite(output, expression, currentOffset, data.Result);
                    }
                    else
                    {
                        int startIndex = 0;
                        foreach (KeyValuePair <int, string> k in labels)
                        {
                            // Console.WriteLine("pos:" + k.Key + " label:" + k.Value);
                            if (k.Key - startIndex > 0)
                            {
                                TryWrite(output, expression, currentOffset, data.Result.Skip(startIndex).Take(k.Key - startIndex).ToArray());
                            }
                            startIndex = k.Key + 4;

                            if (TFlag == true && scope.IsLocalLabelExisted(k.Value))
                            {
                                output.WriteLine("\t.word {0}+1", k.Value);
                                TFlag = false;
                            }
                            else
                            {
                                output.WriteLine("\t.word {0}", k.Value);
                            }
                        }
                        if (data.Result.Length - startIndex > 4)
                        {
                            TryWrite(output, expression, currentOffset, data.Result.Skip(startIndex).Take(data.Result.Length - startIndex).ToArray());
                        }
                    }
                }

                this.currentOffset += data.Result.Length;

                /*for (int i = 0; i < code.Parameters.Length; i++)
                 * {
                 *  // Console.WriteLine(code.Parameters[i]);
                 *  if (scope.IsLabelExisted(code.Parameters[i].ToString()))
                 *  {
                 *      output.WriteLine("\t.word {0}", code.Parameters[i]);
                 *      this.currentOffset += 4;
                 *  }
                 *  else
                 *  {
                 *      IExpression<int>[] parameter = new IExpression<int>[] { code.Parameters[i] };
                 *      CanCauseError<byte[]> data = template.GetDataUnit(parameter, x => this.GetSymbolValue(scope, x));
                 *      if (data.CausedError)
                 *          // Can't compute code data, so we err
                 *          this.AddError<int, byte[]>(expression, data);
                 *      else
                 *      {
                 *          // Write data
                 *          TryWrite(output, expression, currentOffset, data.Result);
                 *          this.currentOffset += data.Result.Length;
                 *      }
                 *  }
                 * }*/

                break;
            }

            case EAExpressionType.RawData:
            {
                RawData <int> rawData = (RawData <int>)expression;

                TryWrite(output, expression, this.currentOffset, rawData.Data);
                this.currentOffset += rawData.Data.Length;

                break;
            }

            case EAExpressionType.Labeled:

                //TODO Add label attribute: ".global LabelName"
                output.WriteLine(((LabelExpression <int>)expression).LabelName + ":");

                break;

            case EAExpressionType.Assignment:
                //TODO .set/.equ, but it doesn't matter
                break;

            default:
                throw new ArgumentException("Badly formed tree.");
            }
        }
Exemplo n.º 27
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (Buffer == null)
            {
                return;
            }

            if (mouseThief != null)
            {
                mouseThief.MouseMove(e.Location);
                return;
            }

            var mlist = Locations.FindMargin(e.Location);

            if (mlist != null)
            {
                mlist.CallMarginMethod(MarginMethod.MouseMove, e.Location);
                Cursor = Cursors.Arrow;
            }

            var leftMouseDown = e.Button == MouseButtons.Left;
            var p             = Locations.LocationToPosition(e.Location);

            if (leftMouseDown && p.IsEmpty)
            {
                if (e.Y - Scroll.ScrollPosition.Y > Info.TextIntegralHeight && Scroll.LastVisibleLine < Lines.Count - 1)
                {
                    p = new Pos(Scroll.LastVisibleLine + 1, Lines[Scroll.LastVisibleLine + 1].Length);
                }
                else if (e.Y < Info.TextTop && Scroll.FirstVisibleLine > 0)
                {
                    p = new Pos(Scroll.FirstVisibleLine - 1, 0);
                }
            }

            if (!p.IsEmpty && Lines[p.Line].Length == p.Col && Folding.IsCollapsedHeader(p.Line))
            {
                Cursor = Cursors.Arrow;
            }
            else if (mlist == null)
            {
                Cursor = Cursors.IBeam;
            }

            mousePosition = e.Location;
            movePosition  = p;
            Caret         = p;

            if (!p.IsEmpty)
            {
                var keys  = ModifierKeys.ToModifiers();
                var mouse = e.GetSpecialKey();

                if (mouse != SpecialKey.None || keys != Modifiers.None)
                {
                    RunCommand(new KeyInput(keys | Modifiers.Move, mouse));
                }

                timer.Start();
            }
        }