|
| 1 | +diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs |
| 2 | +index 6991896..a086433 100644 |
| 3 | +--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs |
| 4 | ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs |
| 5 | +@@ -1166,7 +1166,7 @@ namespace CLPS2C_Compiler |
| 6 | + string Value_1 = ""; |
| 7 | + string Value_2 = ""; |
| 8 | + // Handle a bit differently in case there's a label at the start |
| 9 | +- if (command.Type.EndsWith(':')) |
| 10 | ++ if (command.Type.EndsWith(":")) |
| 11 | + { |
| 12 | + OpCode = command.Data[0].ToUpper(); |
| 13 | + Register = command.Data[1]; |
| 14 | +@@ -1201,7 +1201,7 @@ namespace CLPS2C_Compiler |
| 15 | + } |
| 16 | + |
| 17 | + Output = $"lui {Register},0x{Value_1}; {OpCode} {Register},{Value_2}({Register})"; |
| 18 | +- if (command.Type.EndsWith(':')) |
| 19 | ++ if (command.Type.EndsWith(":")) |
| 20 | + { |
| 21 | + Output = $"{command.FullLine.Substring(0, command.FullLine.IndexOf(':'))}: {Output}"; |
| 22 | + } |
| 23 | +@@ -1589,7 +1589,7 @@ namespace CLPS2C_Compiler |
| 24 | + |
| 25 | + while (IfIndex != -1) |
| 26 | + { |
| 27 | +- int ExtraIfCount = commands[IfIndex].FullLine.Split("&&", StringSplitOptions.None).Length - 1; |
| 28 | ++ int ExtraIfCount = commands[IfIndex].FullLine.Split(new string[] { "&&" }, StringSplitOptions.None).Length - 1; |
| 29 | + for (int i = 0; i < ExtraIfCount; i++) |
| 30 | + { |
| 31 | + // Add more IF commands |
| 32 | +@@ -1807,7 +1807,7 @@ namespace CLPS2C_Compiler |
| 33 | + for (int j = 0; j < commands[i].Data.Count; j++) |
| 34 | + { |
| 35 | + string Target = commands[i].Data[j]; |
| 36 | +- if (Target.StartsWith('+') || Target.StartsWith(',')) |
| 37 | ++ if (Target.StartsWith("+") || Target.StartsWith(",")) |
| 38 | + { |
| 39 | + Target = Target.Substring(1).TrimStart(); |
| 40 | + } |
| 41 | +@@ -1815,14 +1815,14 @@ namespace CLPS2C_Compiler |
| 42 | + if (IsVarDeclared(Target, listSets)) |
| 43 | + { |
| 44 | + List<string> ListValues = GetSetValueFromTarget(Target, commands[i].ID, listSets); |
| 45 | +- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(',')) |
| 46 | ++ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(",")) |
| 47 | + { |
| 48 | + ListValues[0] = commands[i].Data[j][0] + ListValues[0]; |
| 49 | + } |
| 50 | + |
| 51 | + for (int k = 1; k < ListValues.Count; k++) |
| 52 | + { |
| 53 | +- if (ListValues[k].StartsWith('+') || ListValues[k].StartsWith(',')) |
| 54 | ++ if (ListValues[k].StartsWith("+") || ListValues[k].StartsWith(",")) |
| 55 | + { |
| 56 | + ListValues[k] = ListValues[k][0] + ListValues[k].Substring(1).TrimStart(); |
| 57 | + } |
| 58 | +@@ -1834,7 +1834,7 @@ namespace CLPS2C_Compiler |
| 59 | + continue; |
| 60 | + } |
| 61 | + |
| 62 | +- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(',')) |
| 63 | ++ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(",")) |
| 64 | + { |
| 65 | + commands[i].Data[j] = commands[i].Data[j][0] + Target; |
| 66 | + } |
| 67 | +@@ -1912,7 +1912,7 @@ namespace CLPS2C_Compiler |
| 68 | + |
| 69 | + for (i = i + 1; i < command.Data.Count; i++) |
| 70 | + { |
| 71 | +- if (!command.Data[i].StartsWith('+')) |
| 72 | ++ if (!command.Data[i].StartsWith("+")) |
| 73 | + { |
| 74 | + break; |
| 75 | + } |
| 76 | +@@ -1940,12 +1940,12 @@ namespace CLPS2C_Compiler |
| 77 | + |
| 78 | + for (i = i + 1; i < command.Data.Count; i++) |
| 79 | + { |
| 80 | +- if (command.Data[i].StartsWith(',')) |
| 81 | ++ if (command.Data[i].StartsWith(",")) |
| 82 | + { |
| 83 | + ListOffs.Add(TmpAddress.ToString("X8")); |
| 84 | + TmpAddress = 0; |
| 85 | + } |
| 86 | +- else if (!command.Data[i].StartsWith('+')) |
| 87 | ++ else if (!command.Data[i].StartsWith("+")) |
| 88 | + { |
| 89 | + ListOffs.Add(TmpAddress.ToString("X8")); |
| 90 | + TmpAddress = 0; |
| 91 | +@@ -1980,7 +1980,7 @@ namespace CLPS2C_Compiler |
| 92 | + |
| 93 | + for (i = i + 1; i < command.Data.Count; i++) |
| 94 | + { |
| 95 | +- if (!command.Data[i].StartsWith('+')) |
| 96 | ++ if (!command.Data[i].StartsWith("+")) |
| 97 | + { |
| 98 | + break; |
| 99 | + } |
| 100 | +@@ -2008,7 +2008,7 @@ namespace CLPS2C_Compiler |
| 101 | + |
| 102 | + for (i = i + 1; i < command.Data.Count; i++) |
| 103 | + { |
| 104 | +- if (!command.Data[i].StartsWith('+')) |
| 105 | ++ if (!command.Data[i].StartsWith("+")) |
| 106 | + { |
| 107 | + break; |
| 108 | + } |
| 109 | +@@ -2040,7 +2040,7 @@ namespace CLPS2C_Compiler |
| 110 | + { |
| 111 | + string Value = ""; |
| 112 | + uint Sum = 0; |
| 113 | +- if (command.Data[i].StartsWith('"')) |
| 114 | ++ if (command.Data[i].StartsWith("\"")) |
| 115 | + { |
| 116 | + // string |
| 117 | + Value = command.Data[i]; |
| 118 | +@@ -2059,7 +2059,7 @@ namespace CLPS2C_Compiler |
| 119 | + for (i = i + 1; i < command.Data.Count; i++) |
| 120 | + { |
| 121 | + string Element = command.Data[i]; |
| 122 | +- if (!Element.StartsWith('+') || Element == "+") |
| 123 | ++ if (!Element.StartsWith("+") || Element == "+") |
| 124 | + { |
| 125 | + // without +, or just '+' |
| 126 | + SetError(ERROR.WRONG_SYNTAX, command); |
| 127 | +@@ -2072,7 +2072,7 @@ namespace CLPS2C_Compiler |
| 128 | + // string |
| 129 | + if (Sum > 0) |
| 130 | + { |
| 131 | +- if (Value.EndsWith('"')) |
| 132 | ++ if (Value.EndsWith("\"")) |
| 133 | + { |
| 134 | + Value = Value.TrimEnd('"') + Sum.ToString() + '"'; |
| 135 | + } |
| 136 | +@@ -2089,7 +2089,7 @@ namespace CLPS2C_Compiler |
| 137 | + return ""; |
| 138 | + } |
| 139 | + string Tmp = GetSubstringInQuotes(Element, false); |
| 140 | +- if (Value.EndsWith('"')) |
| 141 | ++ if (Value.EndsWith("\"")) |
| 142 | + { |
| 143 | + Value = Value.TrimEnd('"') + Tmp + '"'; |
| 144 | + } |
| 145 | +@@ -2112,7 +2112,7 @@ namespace CLPS2C_Compiler |
| 146 | + |
| 147 | + if (Sum > 0) |
| 148 | + { |
| 149 | +- if (Value.EndsWith('"')) |
| 150 | ++ if (Value.EndsWith("\"")) |
| 151 | + { |
| 152 | + Value = Value.TrimEnd('"') + Sum.ToString() + '"'; |
| 153 | + } |
| 154 | +diff --git a/CLPS2C-Compiler/Util.cs b/CLPS2C-Compiler/Util.cs |
| 155 | +index 4560c73..7f82ae6 100644 |
| 156 | +--- a/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs |
| 157 | ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs |
| 158 | +@@ -48,7 +48,7 @@ namespace CLPS2C_Compiler |
| 159 | + // ([^ \t\n\r\f\v(+,]+) - Any other word. This is \S, and '(', '+', ',' |
| 160 | + MatchCollection Matches = Regex.Matches(line, @"(\(.*\))|(""(?:\\.|[^""])*""?)|(\+\s*((""(?:\\.|[^""])*""?)|([^+""]+?))?(?=\+|$| |,))|(,(""?)([^,""]+?)\8(?=,|$| |\+))|([^ \t\n\r\f\v(+,]+)"); |
| 161 | + Type = Matches[0].Value.ToUpper(); |
| 162 | +- Data = Matches.Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first |
| 163 | ++ Data = Matches.Cast<Match>().Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first |
| 164 | + } |
| 165 | + |
| 166 | + public void AppendToTraceback(string file, string fullLine, int lineIdx) |
| 167 | +@@ -165,7 +165,7 @@ namespace CLPS2C_Compiler |
| 168 | + else |
| 169 | + { |
| 170 | + // It's a comment, count new lines |
| 171 | +- int newLinesCount = match.Value.Split(Program._newLine).Length - 1; |
| 172 | ++ int newLinesCount = match.Value.Split(new string[] { Program._newLine }, StringSplitOptions.None).Length - 1; |
| 173 | + return string.Concat(Enumerable.Repeat(Program._newLine, newLinesCount)); |
| 174 | + } |
| 175 | + }); |
| 176 | +@@ -486,7 +486,7 @@ namespace CLPS2C_Compiler |
| 177 | + for (int i = 0; i < Output.Count; i++) |
| 178 | + { |
| 179 | + string Element = Output[i]; |
| 180 | +- if (Element.StartsWith('+')) |
| 181 | ++ if (Element.StartsWith("+")) |
| 182 | + { |
| 183 | + Element = Element.Substring(1).TrimStart(); |
| 184 | + } |
| 185 | +@@ -496,7 +496,7 @@ namespace CLPS2C_Compiler |
| 186 | + List<string> RecursiveValues = GetSetValueFromTarget(Element, SetID, listSets); |
| 187 | + if (RecursiveValues.Count != 0) |
| 188 | + { |
| 189 | +- if (Output[i].StartsWith('+')) |
| 190 | ++ if (Output[i].StartsWith("+")) |
| 191 | + { |
| 192 | + RecursiveValues[0] = "+" + RecursiveValues[0]; |
| 193 | + } |
0 commit comments