diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-03-17 20:49:22 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-03-17 20:49:22 +1000 |
| commit | 18868128e18d38b706e7df14e8e683e1a9739c17 (patch) | |
| tree | 6f0e0e5eee646f10cbad9c0c89c24d330bc58cc6 /Compiler/visitors/Constants.cs | |
| parent | d87ab8af4c86a3fc6ee237444e372d87e536e3ef (diff) | |
chore: Initial commit
Diffstat (limited to 'Compiler/visitors/Constants.cs')
| -rw-r--r-- | Compiler/visitors/Constants.cs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/Compiler/visitors/Constants.cs b/Compiler/visitors/Constants.cs deleted file mode 100644 index 598c642..0000000 --- a/Compiler/visitors/Constants.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace Q1.Compiler.visitors; - -using System.Text; - -public partial class CCompilerVisitor -{ - public Encoding Encoding; - public override string VisitIntConstant(CGrammarParser.IntConstantContext context) - { - string valueString = context.INT().GetText(); - if (int.TryParse(valueString, out int value)) - return $"{value}"; - else - throw new CompilerException($"Invalid integer value: {valueString}"); - } - public override string VisitHexConstant(CGrammarParser.HexConstantContext context) - { - string valueString = context.HEX().GetText(); - valueString = valueString[2..]; // Remove 0x - return $"${valueString}"; - } - - public override object? VisitCharConstant(CGrammarParser.CharConstantContext context) - { - char c = context.LETTER().GetText()[1]; - return $"{this.Encoding.GetBytes(c.ToString())[0]}"; - } - - public override object? VisitStringConstant(CGrammarParser.StringConstantContext context) - { - string text = context.STRING().GetText()[1..^1]; - - int? arrPtr = null; - - if (text.Length == 0) - throw new CompilerException("Cannot create empty string"); - - foreach (char c in text) - { - int itemPtr = Alloc(CType.Int.Size); - - if (arrPtr == null) - arrPtr = itemPtr; - - this.DynamicMove(CType.Int, $"{this.Encoding.GetBytes(c.ToString())[0]}", $"[${itemPtr:X4}]"); - } - - return $"${arrPtr:X4}"; - } -}
\ No newline at end of file |
