mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 05:48:37 +00:00
X#
This commit is contained in:
parent
2b7279bce9
commit
fd2d485193
7 changed files with 69 additions and 47 deletions
|
|
@ -8,5 +8,22 @@
|
|||
<p>
|
||||
TODO: Rename Cosmos.IL2CPU to Cosmos.Compiler</p>
|
||||
|
||||
<p>
|
||||
</p>
|
||||
<h2>
|
||||
Projects</h2>
|
||||
<h3>
|
||||
Cosmos.Compiler.XSharp</h3>
|
||||
<p>
|
||||
Compiles X# to C# assembler methods.</p>
|
||||
<h3>
|
||||
Cosmos.Compiler.XSharp.Test</h3>
|
||||
<p>
|
||||
Test for Cosmos.Compiler.XSharp</p>
|
||||
<h3>
|
||||
Cosmos.Compiler.XSharp.XSC</h3>
|
||||
<p>
|
||||
Future command line compiler for X#.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -47,33 +47,19 @@ namespace Cosmos.Compiler.XSharp {
|
|||
mStart = rPos;
|
||||
return;
|
||||
}
|
||||
} else if (xString == "[") {
|
||||
xToken.Type = TokenType.BracketLeft;
|
||||
} else if (xString == "]") {
|
||||
xToken.Type = TokenType.BracketRight;
|
||||
} else if (xString == "+") {
|
||||
xToken.Type = TokenType.Plus;
|
||||
} else if (xString == "-") {
|
||||
xToken.Type = TokenType.Minus;
|
||||
} else if (xString == "=") {
|
||||
xToken.Type = TokenType.Assignment;
|
||||
} else if (char.IsLetter(xChar1)) {
|
||||
if (xString.EndsWith(":")) {
|
||||
xToken.Type = TokenType.Label;
|
||||
string xUpper = xString.ToUpper();
|
||||
if (mRegisters.Contains(xUpper)) {
|
||||
xToken.Type = TokenType.Register;
|
||||
} else if (mOps.Contains(xUpper)) {
|
||||
xToken.Type = TokenType.OpCode;
|
||||
} else {
|
||||
string xUpper = xString.ToUpper();
|
||||
if (mRegisters.Contains(xUpper)) {
|
||||
xToken.Type = TokenType.Register;
|
||||
} else if (mOps.Contains(xUpper)) {
|
||||
xToken.Type = TokenType.OpCode;
|
||||
} else {
|
||||
xToken.Type = TokenType.AlphaNum;
|
||||
}
|
||||
xToken.Type = TokenType.AlphaNum;
|
||||
}
|
||||
} else if (char.IsDigit(xChar1)) {
|
||||
xToken.Type = TokenType.ValueNumberInt;
|
||||
xToken.Type = TokenType.ValueInt;
|
||||
} else {
|
||||
xToken.Type = TokenType.Unknown;
|
||||
xToken.Type = Token.GetTypeForSymbol(xString);
|
||||
}
|
||||
}
|
||||
xToken.Value = xString;
|
||||
|
|
@ -95,8 +81,7 @@ namespace Cosmos.Compiler.XSharp {
|
|||
xChar = mData[i];
|
||||
if (char.IsWhiteSpace(xChar)) {
|
||||
xCharType = CharType.WhiteSpace;
|
||||
} else if (char.IsLetterOrDigit(xChar) || xChar == ':') {
|
||||
// : is for labels
|
||||
} else if (char.IsLetterOrDigit(xChar)) {
|
||||
xCharType = CharType.Identifier;
|
||||
} else {
|
||||
xCharType = CharType.Symbol;
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ using System.Text;
|
|||
namespace Cosmos.Compiler.XSharp {
|
||||
public enum TokenType {
|
||||
// Line based
|
||||
Comment, LiteralAsm,
|
||||
Comment, LiteralAsm
|
||||
//
|
||||
Register, Label, OpCode, AlphaNum,
|
||||
, Register, OpCode, AlphaNum
|
||||
// Values
|
||||
ValueNumberInt,
|
||||
, ValueInt
|
||||
// Symbols
|
||||
Assignment, BracketLeft, BracketRight, Plus, Minus,
|
||||
, Assignment, BracketLeft, BracketRight, Plus, Minus, Colon, Dollar
|
||||
//
|
||||
WhiteSpace,
|
||||
, WhiteSpace
|
||||
// For now used during scanning while user is typing, but in future could be user methods we have to find etc
|
||||
Unknown
|
||||
, Unknown
|
||||
}
|
||||
|
||||
public class Token {
|
||||
|
|
@ -24,5 +24,25 @@ namespace Cosmos.Compiler.XSharp {
|
|||
public int SrcPosStart;
|
||||
public int SrcPosEnd;
|
||||
public string Value;
|
||||
|
||||
public static TokenType GetTypeForSymbol(string aSymbol) {
|
||||
if (aSymbol == "[") {
|
||||
return TokenType.BracketLeft;
|
||||
} else if (aSymbol == "]") {
|
||||
return TokenType.BracketRight;
|
||||
} else if (aSymbol == "+") {
|
||||
return TokenType.Plus;
|
||||
} else if (aSymbol == "-") {
|
||||
return TokenType.Minus;
|
||||
} else if (aSymbol == "=") {
|
||||
return TokenType.Assignment;
|
||||
} else if (aSymbol == ":") {
|
||||
return TokenType.Colon;
|
||||
} else if (aSymbol == "$") {
|
||||
return TokenType.Dollar;
|
||||
} else {
|
||||
return TokenType.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,19 +26,12 @@ namespace Cosmos.Compiler.XSharp {
|
|||
} else if (string.Compare(xPart, "ABC") == 0) {
|
||||
xTokenType = TokenType.AlphaNum;
|
||||
} else if (char.IsDigit(xPart[0])) {
|
||||
xTokenType = TokenType.ValueNumberInt;
|
||||
} else if (xPart == "=") {
|
||||
xTokenType = TokenType.Assignment;
|
||||
} else if (xPart == "[") {
|
||||
xTokenType = TokenType.BracketLeft;
|
||||
} else if (xPart == "]") {
|
||||
xTokenType = TokenType.BracketRight;
|
||||
} else if (xPart == "+") {
|
||||
xTokenType = TokenType.Plus;
|
||||
} else if (xPart == "-") {
|
||||
xTokenType = TokenType.Minus;
|
||||
xTokenType = TokenType.ValueInt;
|
||||
} else {
|
||||
throw new Exception("Unrecognized string token: " + xPart);
|
||||
xTokenType = Token.GetTypeForSymbol(xPart);
|
||||
if (xTokenType == TokenType.Unknown) {
|
||||
throw new Exception("Unrecognized string token: " + xPart);
|
||||
}
|
||||
}
|
||||
xTokenTypes.Add(xTokenType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ namespace Cosmos.Compiler.XSharp {
|
|||
Add(new TokenType[] { TokenType.Comment },
|
||||
"new Comment(\"{0}\");"
|
||||
);
|
||||
Add("ABC:" ,
|
||||
"new Label(\"{0}\");"
|
||||
);
|
||||
|
||||
Add("REG = 123",
|
||||
"new Mov{{ DestinationReg = RegistersEnum.{0}, SourceValue = {2} }};"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@
|
|||
To Do</h3>
|
||||
<ul>
|
||||
<li>X#<ul>
|
||||
<li>Hex Values - $FF</li>
|
||||
<li>Hex Values - $FF<ul>
|
||||
<li>Can scan for $ + AlphaNum or ValueNum and convert to ValueNumHex with value 0x00</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Complete</li>
|
||||
<li>Code Completion</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -28,20 +28,21 @@ namespace Cosmos.VS.XSharp {
|
|||
mTokenMap[i].Color = TokenColor.Text;
|
||||
}
|
||||
|
||||
mTokenMap[(int)XSC.TokenType.Label] = new TokenData { Type = TokenType.Identifier, Color = TokenColor.Identifier };
|
||||
mTokenMap[(int)XSC.TokenType.Comment] = new TokenData { Type = TokenType.LineComment, Color = TokenColor.Comment };
|
||||
|
||||
mTokenMap[(int)XSC.TokenType.LiteralAsm] = new TokenData { Type = TokenType.Literal , Color = TokenColor.String };
|
||||
|
||||
mTokenMap[(int)XSC.TokenType.Register] = new TokenData { Type = TokenType.Keyword , Color = TokenColor.Keyword };
|
||||
mTokenMap[(int)XSC.TokenType.OpCode] = new TokenData { Type = TokenType.Keyword , Color = TokenColor.Keyword };
|
||||
mTokenMap[(int)XSC.TokenType.AlphaNum] = new TokenData { Type = TokenType.Identifier, Color = TokenColor.Identifier };
|
||||
|
||||
mTokenMap[(int)XSC.TokenType.Assignment] = new TokenData { Type = TokenType.Operator, Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.ValueNumberInt] = new TokenData { Type = TokenType.Literal , Color = TokenColor.Number };
|
||||
mTokenMap[(int)XSC.TokenType.ValueInt] = new TokenData { Type = TokenType.Literal, Color = TokenColor.Number };
|
||||
mTokenMap[(int)XSC.TokenType.BracketLeft] = new TokenData { Type = TokenType.Delimiter , Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.BracketRight] = new TokenData { Type = TokenType.Delimiter , Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Plus] = new TokenData { Type = TokenType.Operator , Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Minus] = new TokenData { Type = TokenType.Operator , Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Minus] = new TokenData { Type = TokenType.Operator, Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Colon] = new TokenData { Type = TokenType.Operator, Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Dollar] = new TokenData { Type = TokenType.Operator, Color = TokenColor.Text };
|
||||
|
||||
mTokenMap[(int)XSC.TokenType.WhiteSpace] = new TokenData { Type = TokenType.WhiteSpace, Color = TokenColor.Text };
|
||||
mTokenMap[(int)XSC.TokenType.Unknown] = new TokenData { Type = TokenType.Unknown, Color = TokenColor.Text };
|
||||
|
|
|
|||
Loading…
Reference in a new issue