From 38912eaf6d9c7baaed9d7207c30993de52f56f28 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Fri, 13 Jul 2012 16:15:01 +0000 Subject: [PATCH] X# Size specifier for comparisons. --- XSharp/source/XSharp.Test/MainForm.cs | 3 + .../Cosmos.Compiler.DebugStub/CmdProcess.asm | 23 ++----- .../Cosmos.Compiler.DebugStub/CmdProcess.xs | 36 ++++++++++ .../Cosmos.Compiler.DebugStub/CmdSend.xs | 2 +- .../Cosmos.Compiler.DebugStub/Screen.asm | 15 +--- .../Cosmos.Compiler.DebugStub/Screen.xs | 2 +- source2/Compiler/Cosmos.XSharp/Parser.cs | 3 +- .../Compiler/Cosmos.XSharp/TokenPatterns.cs | 68 ++++++++++--------- 8 files changed, 85 insertions(+), 67 deletions(-) diff --git a/XSharp/source/XSharp.Test/MainForm.cs b/XSharp/source/XSharp.Test/MainForm.cs index f5a97c548..0027c04f1 100644 --- a/XSharp/source/XSharp.Test/MainForm.cs +++ b/XSharp/source/XSharp.Test/MainForm.cs @@ -51,6 +51,9 @@ namespace XSharp.Test { } private void MainForm_Load(object sender, EventArgs e) { + // For testing + //Test(Path.Combine(mPath, "CmdProcess.xs")); + var xFiles = Directory.GetFiles(mPath, "*.xs"); foreach (var xFile in xFiles) { Test(xFile); diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.asm b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.asm index 7e29d24c9..2bf89d545 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.asm +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.asm @@ -1,23 +1,8 @@ -DebugStub_AckCommand: +DebugStub_ProcessCommand2: +Call DebugStub_ComReadAL +Push EAX -Mov AL, DebugStub_Const_Ds2Vs_CmdCompleted -Call DebugStub_ComWriteAL - -Mov EAX, [DebugStub_CommandID] -Call DebugStub_ComWriteAL -DebugStub_AckCommand_Exit: -Ret - -DebugStub_ProcessCommandBatch: -DebugStub_ProcessCommandBatch_Begin: -Call DebugStub_ProcessCommand - -Cmp AL, 8 -JNE DebugStub_ProcessCommandBatch_Begin - -Call DebugStub_AckCommand -DebugStub_ProcessCommandBatch_Exit: -Ret +Line 14, Parsing error: if AL = #Vs2Ds_Noop exit diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.xs b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.xs index 21eaea157..7a505eac5 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.xs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdProcess.xs @@ -1,5 +1,41 @@ Group DebugStub +// Modifies: AL, DX (ComReadAL) +// Returns: AL +function ProcessCommand2 { + ComReadAL() + // Some callers expect AL to be returned, so we preserve it + // in case any commands modify AL. + // We push EAX to keep stack aligned. + +EAX + + // Noop has no data at all (see notes in client DebugConnector), so skip Command ID + // Noop also does not send ACK. + if AL = #Vs2Ds_Noop return + + // Read Command ID + ComReadAL() + .CommandID = EAX + + // Get AL back so we can compare it, but also put it back for later + EAX = ESP[0] + //CheckCmd("TraceOff", Vs2Ds.TraceOff) + //CheckCmd("TraceOn", Vs2Ds.TraceOn) + //CheckCmd("Break", Vs2Ds.Break) + //CheckCmd("BreakOnAddress", Vs2Ds.BreakOnAddress) + //CheckCmd("SendMethodContext", Vs2Ds.SendMethodContext) + //CheckCmd("SendMemory", Vs2Ds.SendMemory) + //CheckCmd("SendRegisters", Vs2Ds.SendRegisters) + //CheckCmd("SendFrame", Vs2Ds.SendFrame) + //CheckCmd("SendStack", Vs2Ds.SendStack) + //CheckCmd("Ping", Vs2Ds.Ping) + +Exit: + // Restore AL for callers who check the command and do + // further processing, or for commands not handled by this routine. + -EAX +} + function AckCommand { // We acknowledge receipt of the command AND the processing of it. // -In the past the ACK only acknowledged receipt. diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdSend.xs b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdSend.xs index 1c4cd4fc8..d436cca9f 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/CmdSend.xs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/CmdSend.xs @@ -111,7 +111,7 @@ Exit: // Modifies: EAX, ESI function SendTrace { - if .DebugStatus = #Status_Run goto Normal + if dword .DebugStatus = #Status_Run goto Normal AL = #Ds2Vs_BreakPoint goto Type diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.asm b/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.asm index bd9cd2682..e08b06512 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.asm +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.asm @@ -1,4 +1,5 @@ DebugWaitMsg db "Waiting for debugger connection..." +db 0 DebugStub_Const_VidBase equ 0xB8000 @@ -7,7 +8,7 @@ DebugStub_Cls: Mov ESI, DebugStub_Const_VidBase DebugStub_Cls_Block1Begin: -Cmp dword ESI, 0xB8FA0 +Cmp ESI, 0xB8FA0 JAE DebugStub_Cls_Block1End Mov dword [ESI + 0], 0x00 Inc ESI @@ -25,15 +26,5 @@ Mov ESI, DebugWaitMsg Mov EDI, DebugStub_Const_VidBase Add EDI, 1640 -DebugStub_DisplayWaitMsg_Block2Begin: -Cmp dword [ESI + 0], 0 -JE DebugStub_DisplayWaitMsg_Block2End -Mov AL, [ESI + 0] -Mov [EDI + 0], AL -Inc ESI -Add EDI, 2 -jmp DebugStub_DisplayWaitMsg_Block2Begin -DebugStub_DisplayWaitMsg_Block2End: -DebugStub_DisplayWaitMsg_Exit: -Ret +Line 30, Parsing error: while byte ESI[0] != 0 { diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.xs b/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.xs index 5b05b9faa..8698a3a30 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.xs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.xs @@ -27,7 +27,7 @@ function DisplayWaitMsg { EDI + 1640 // Read and copy string till 0 terminator - while ESI[0] != 0 { + while byte ESI[0] != 0 { AL = ESI[0] EDI[0] = AL ESI++ diff --git a/source2/Compiler/Cosmos.XSharp/Parser.cs b/source2/Compiler/Cosmos.XSharp/Parser.cs index c509c00e4..149742668 100644 --- a/source2/Compiler/Cosmos.XSharp/Parser.cs +++ b/source2/Compiler/Cosmos.XSharp/Parser.cs @@ -23,13 +23,12 @@ namespace Cosmos.Compiler.XSharp { + ",BYTE" + ",CALL,CONST" + ",DWORD" - + ",end,exit" + ",function" + ",GOTO,GROUP" + ",IF,INTERRUPT" + ",JUMP" + ",PORT" - + ",RETURN,RETURNINTERRUPT,REPEAT" + + ",return,RETURNINTERRUPT,REPEAT" + ",times" + ",var" + ",word,while" diff --git a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs index a66a5a6c4..7531e1f9f 100644 --- a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs +++ b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs @@ -36,25 +36,29 @@ namespace Cosmos.Compiler.XSharp { public TokenPatterns() { mCompareOps = "< > = != <= >= 0".Split(" ".ToCharArray()); - foreach (var xComparison in mCompareOps) { - if (xComparison != "0") { - mCompares.Add("_REG " + xComparison + " 123"); - mCompares.Add("_REG " + xComparison + " _REG"); - mCompares.Add("_REG " + xComparison + " _REGADDR[1]"); - mCompares.Add("_REG " + xComparison + " _REGADDR[-1]"); - mCompares.Add("_REG " + xComparison + " _ABC"); - mCompares.Add("_REG " + xComparison + " #_ABC"); - // - mCompares.Add("_REGADDR[1] " + xComparison + " 123"); - mCompares.Add("_REGADDR[-1] " + xComparison + " 123"); - mCompares.Add("_REGADDR[1] " + xComparison + " _REG"); - mCompares.Add("_REGADDR[-1] " + xComparison + " _REG"); - mCompares.Add("_REGADDR[1] " + xComparison + " #_ABC"); - mCompares.Add("_REGADDR[-1] " + xComparison + " #_ABC"); - // - mCompares.Add("_ABC " + xComparison + " 123"); - mCompares.Add("_ABC " + xComparison + " _REG"); - mCompares.Add("_ABC " + xComparison + " #_ABC"); + var xSizes = "byte , word , dword ".Split(",".ToCharArray()).ToList(); + xSizes.Add(""); + foreach (var xSize in xSizes) { + foreach (var xComparison in mCompareOps) { + if (xComparison != "0") { + mCompares.Add(xSize + "_REG " + xComparison + " 123"); + mCompares.Add(xSize + "_REG " + xComparison + " _REG"); + mCompares.Add(xSize + "_REG " + xComparison + " _REGADDR[1]"); + mCompares.Add(xSize + "_REG " + xComparison + " _REGADDR[-1]"); + mCompares.Add(xSize + "_REG " + xComparison + " _ABC"); + mCompares.Add(xSize + "_REG " + xComparison + " #_ABC"); + // + mCompares.Add(xSize + "_REGADDR[1] " + xComparison + " 123"); + mCompares.Add(xSize + "_REGADDR[-1] " + xComparison + " 123"); + mCompares.Add(xSize + "_REGADDR[1] " + xComparison + " _REG"); + mCompares.Add(xSize + "_REGADDR[-1] " + xComparison + " _REG"); + mCompares.Add(xSize + "_REGADDR[1] " + xComparison + " #_ABC"); + mCompares.Add(xSize + "_REGADDR[-1] " + xComparison + " #_ABC"); + // + mCompares.Add(xSize + "_ABC " + xComparison + " 123"); + mCompares.Add(xSize + "_ABC " + xComparison + " _REG"); + mCompares.Add(xSize + "_ABC " + xComparison + " #_ABC"); + } } } @@ -86,7 +90,7 @@ namespace Cosmos.Compiler.XSharp { return FuncLabel("Block" + mBlockLabel + aLabel); } protected string GetLabel(Token aToken) { - if (aToken.Type != TokenType.AlphaNum && !aToken.Matches("Exit")) { + if (aToken.Type != TokenType.AlphaNum) { throw new Exception("Label must be AlphaNum."); } @@ -159,8 +163,7 @@ namespace Cosmos.Compiler.XSharp { return xResult; } - protected string GetRef(TokenList aTokens, ref int rIdx, out bool oSizeIsKnown) { - oSizeIsKnown = false; + protected string GetRef(TokenList aTokens, ref int rIdx) { var xToken1 = aTokens[rIdx]; Token xToken2 = null; if (rIdx + 1 < aTokens.Count) { @@ -175,7 +178,6 @@ namespace Cosmos.Compiler.XSharp { rIdx += 4; return "[" + xToken1 + " + " + aTokens[rIdx - 2] + "]"; } - oSizeIsKnown = true; rIdx += 1; return xToken1.ToString(); @@ -197,18 +199,20 @@ namespace Cosmos.Compiler.XSharp { } protected string GetCompare(TokenList aTokens, ref int rStart, out Token aComparison) { - bool xLeftSizeKnown; - string xLeft = GetRef(aTokens, ref rStart, out xLeftSizeKnown); + string xSize = ""; + if (aTokens[rStart].Type == TokenType.Keyword) { + xSize = aTokens[rStart] + " "; + rStart++; + } + + string xLeft = GetRef(aTokens, ref rStart); aComparison = aTokens[rStart]; rStart++; - bool xRightSizeKnown; - string xRight = GetRef(aTokens, ref rStart, out xRightSizeKnown); - - return "Cmp " - + (xLeftSizeKnown || xRightSizeKnown ? "" : "dword ") - + xLeft + ", " + xRight; + string xRight = GetRef(aTokens, ref rStart); + + return "Cmp " + xSize + xLeft + ", " + xRight; } protected string GetJump(Token aToken) { @@ -306,7 +310,7 @@ namespace Cosmos.Compiler.XSharp { }); AddPattern("var _ABC = 'Text'", delegate(TokenList aTokens, Assembler aAsm) { // , 0 adds null term to our strings. - aAsm.Data.Add(GetLabel(aTokens[1]) + " db \"" + aTokens[3].Value + "\", 0"); + aAsm.Data.Add(GetLabel(aTokens[1]) + " db \"" + aTokens[3].Value + "\""); }); AddPattern(new string[] { "var _ABC byte[123]",