From 18868128e18d38b706e7df14e8e683e1a9739c17 Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:49:22 +1000 Subject: chore: Initial commit --- .idea/.idea.Chip8Emu2/.idea/.gitignore | 13 - .idea/.idea.Chip8Emu2/.idea/.name | 1 - .idea/.idea.Chip8Emu2/.idea/encodings.xml | 4 - .idea/.idea.Chip8Emu2/.idea/indexLayout.xml | 8 - .idea/.idea.Chip8Emu2/.idea/vcs.xml | 6 - .idea/.idea.Q1/.idea/.gitignore | 13 - .../.idea/ANTLRv4ToolGrammarProperties.xml | 42 - .idea/.idea.Q1/.idea/encodings.xml | 4 - .idea/.idea.Q1/.idea/misc.xml | 10 - .idea/.idea.Q1/.idea/vcs.xml | 1 + .idea/.idea.Q1/.idea/workspace.xml | 184 ++ .idea/.idea.Q1Emu/.idea/.gitignore | 13 - .idea/.idea.Q1Emu/.idea/encodings.xml | 4 - .idea/.idea.Q1Emu/.idea/indexLayout.xml | 8 - .idea/.idea.Q1Emu/.idea/misc.xml | 10 - .idea/.idea.Q1Emu/.idea/vcs.xml | 6 - Assembler/Assembler.cs | 450 ---- Assembler/Assembler.csproj | 19 - Assembler/Extensions.cs | 15 - Assembler/GlobalUsings.cs | 12 - Assembler/Options.cs | 12 - Assembler/Program.cs | 37 - Compiler.Testing/Compiler.Testing.csproj | 28 - Compiler.Testing/SanityTests.cs | 43 - Compiler.Testing/TestingHelpers.cs | 14 - Compiler/CGrammar.g4 | 133 - Compiler/CType.cs | 31 - Compiler/CommentCompilationMode.cs | 10 - Compiler/Compiler.csproj | 20 - Compiler/CompilerException.cs | 4 - Compiler/CompilerExtensions.cs | 12 - Compiler/CompilerOptions.cs | 18 - Compiler/Context.cs | 23 - Compiler/FunctionReference.cs | 129 - Compiler/Optimizer.cs | 28 - Compiler/PreprocessingCharStream.cs | 25 - Compiler/Preprocessor.cs | 57 - Compiler/Program.cs | 73 - Compiler/Target.cs | 15 - Compiler/VariableReference.cs | 15 - Compiler/gen/CGrammar.interp | 145 - Compiler/gen/CGrammar.tokens | 116 - Compiler/gen/CGrammarBaseVisitor.cs | 781 ------ Compiler/gen/CGrammarLexer.cs | 238 -- Compiler/gen/CGrammarLexer.interp | 203 -- Compiler/gen/CGrammarLexer.tokens | 116 - Compiler/gen/CGrammarParser.cs | 2821 -------------------- Compiler/gen/CGrammarVisitor.cs | 506 ---- Compiler/visitors/Constants.cs | 50 - Compiler/visitors/Definitions.cs | 132 - Compiler/visitors/Expressions.cs | 154 -- Compiler/visitors/FlowControl.cs | 177 -- Compiler/visitors/Main.cs | 183 -- Compiler/visitors/Operations.cs | 305 --- Compiler/visitors/Targets.cs | 40 - Emulator/Assembler/Disassembler.cs | 74 - Emulator/Chip/Bus.cs | 37 - Emulator/Chip/BusDevice.cs | 49 - Emulator/Chip/DisplayDevice.cs | 94 - Emulator/Chip/GraphicsDevice.cs | 6 - Emulator/Chip/HIDDevice.cs | 49 - Emulator/Chip/Q1Cpu.cs | 167 -- Emulator/Chip/Q1CpuAddressingModes.cs | 187 -- Emulator/Chip/Q1CpuInstructions.cs | 278 -- Emulator/Chip/RamDevice.cs | 33 - Emulator/Content/Content.mgcb | 15 - Emulator/DisplayEngine.cs | 116 - Emulator/Emulator.csproj | 32 - Emulator/Extensions.cs | 23 - Emulator/GlobalUsings.cs | 12 - Emulator/Icon.bmp | Bin 262282 -> 0 bytes Emulator/Icon.ico | Bin 147541 -> 0 bytes Emulator/Make.cs | 58 - Emulator/Options.cs | 7 - Emulator/Program.cs | 98 - Emulator/Q1Layout.cs | 23 - Orchestrator/Orchestrator.csproj | 20 - Orchestrator/Program.cs | 74 - Q1.core/Arch/AddressingMode.cs | 13 + Q1.core/Arch/AddressingModes.cs | 331 +++ Q1.core/Arch/Chip.cs | 143 + Q1.core/Arch/ChipLayout.cs | 12 + Q1.core/Arch/IInstruction.cs | 35 + Q1.core/Arch/InstructionSet.cs | 203 ++ Q1.core/GlobalUsings.cs | 12 + Q1.core/IAddressable.cs | 26 + Q1.core/Memory.cs | 15 + Q1.core/Q1.core.csproj | 9 + Q1.sln | 44 +- Q1.tests/Core/AddressingModesTests.cs | 20 + Q1.tests/Core/InstructionsTests.cs | 20 + Q1.tests/Q1.tests.csproj | 27 + ROMs/_old/hello_world.asm | 42 - ROMs/_old/hello_world.q1 | Bin 2151 -> 0 bytes ROMs/_old/manual.q1 | Bin 10 -> 0 bytes ROMs/_old/write_display_direct.asm | 21 - ROMs/_old/write_display_direct.q1 | Bin 51 -> 0 bytes ROMs/font.bin | Bin 2048 -> 0 bytes ROMs/hello_c.asm | 215 -- ROMs/hello_c.c | 55 - ROMs/hello_c.q1 | Bin 2842 -> 0 bytes ROMs/hid.c | 80 - ROMs/logictest.asm | 140 - ROMs/logictest.c | 37 - ROMs/logictest.q1 | Bin 477 -> 0 bytes ROMs/paint.asm | 264 -- ROMs/paint.c | 25 - ROMs/paint.q1 | Bin 872 -> 0 bytes ROMs/screen.c | 48 - ROMs/std.c | 4 - ROMs/typewriter.asm | 461 ---- ROMs/typewriter.c | 75 - ROMs/typewriter.q1 | Bin 3627 -> 0 bytes RegionVisualiser/BoxDrawer.cs | 49 - RegionVisualiser/Program.cs | 74 - RegionVisualiser/Region.cs | 10 - RegionVisualiser/RegionVisualiser.csproj | 14 - RegionVisualiser/SizeFormatter.cs | 25 - RegionVisualiser/output.txt | 24 - 119 files changed, 1061 insertions(+), 10481 deletions(-) delete mode 100644 .idea/.idea.Chip8Emu2/.idea/.gitignore delete mode 100644 .idea/.idea.Chip8Emu2/.idea/.name delete mode 100644 .idea/.idea.Chip8Emu2/.idea/encodings.xml delete mode 100644 .idea/.idea.Chip8Emu2/.idea/indexLayout.xml delete mode 100644 .idea/.idea.Chip8Emu2/.idea/vcs.xml delete mode 100644 .idea/.idea.Q1/.idea/.gitignore delete mode 100644 .idea/.idea.Q1/.idea/ANTLRv4ToolGrammarProperties.xml delete mode 100644 .idea/.idea.Q1/.idea/encodings.xml delete mode 100644 .idea/.idea.Q1/.idea/misc.xml create mode 100644 .idea/.idea.Q1/.idea/workspace.xml delete mode 100644 .idea/.idea.Q1Emu/.idea/.gitignore delete mode 100644 .idea/.idea.Q1Emu/.idea/encodings.xml delete mode 100644 .idea/.idea.Q1Emu/.idea/indexLayout.xml delete mode 100644 .idea/.idea.Q1Emu/.idea/misc.xml delete mode 100644 .idea/.idea.Q1Emu/.idea/vcs.xml delete mode 100644 Assembler/Assembler.cs delete mode 100644 Assembler/Assembler.csproj delete mode 100644 Assembler/Extensions.cs delete mode 100644 Assembler/GlobalUsings.cs delete mode 100644 Assembler/Options.cs delete mode 100644 Assembler/Program.cs delete mode 100644 Compiler.Testing/Compiler.Testing.csproj delete mode 100644 Compiler.Testing/SanityTests.cs delete mode 100644 Compiler.Testing/TestingHelpers.cs delete mode 100644 Compiler/CGrammar.g4 delete mode 100644 Compiler/CType.cs delete mode 100644 Compiler/CommentCompilationMode.cs delete mode 100644 Compiler/Compiler.csproj delete mode 100644 Compiler/CompilerException.cs delete mode 100644 Compiler/CompilerExtensions.cs delete mode 100644 Compiler/CompilerOptions.cs delete mode 100644 Compiler/Context.cs delete mode 100644 Compiler/FunctionReference.cs delete mode 100644 Compiler/Optimizer.cs delete mode 100644 Compiler/PreprocessingCharStream.cs delete mode 100644 Compiler/Preprocessor.cs delete mode 100644 Compiler/Program.cs delete mode 100644 Compiler/Target.cs delete mode 100644 Compiler/VariableReference.cs delete mode 100644 Compiler/gen/CGrammar.interp delete mode 100644 Compiler/gen/CGrammar.tokens delete mode 100644 Compiler/gen/CGrammarBaseVisitor.cs delete mode 100644 Compiler/gen/CGrammarLexer.cs delete mode 100644 Compiler/gen/CGrammarLexer.interp delete mode 100644 Compiler/gen/CGrammarLexer.tokens delete mode 100644 Compiler/gen/CGrammarParser.cs delete mode 100644 Compiler/gen/CGrammarVisitor.cs delete mode 100644 Compiler/visitors/Constants.cs delete mode 100644 Compiler/visitors/Definitions.cs delete mode 100644 Compiler/visitors/Expressions.cs delete mode 100644 Compiler/visitors/FlowControl.cs delete mode 100644 Compiler/visitors/Main.cs delete mode 100644 Compiler/visitors/Operations.cs delete mode 100644 Compiler/visitors/Targets.cs delete mode 100644 Emulator/Assembler/Disassembler.cs delete mode 100644 Emulator/Chip/Bus.cs delete mode 100644 Emulator/Chip/BusDevice.cs delete mode 100644 Emulator/Chip/DisplayDevice.cs delete mode 100644 Emulator/Chip/GraphicsDevice.cs delete mode 100644 Emulator/Chip/HIDDevice.cs delete mode 100644 Emulator/Chip/Q1Cpu.cs delete mode 100644 Emulator/Chip/Q1CpuAddressingModes.cs delete mode 100644 Emulator/Chip/Q1CpuInstructions.cs delete mode 100644 Emulator/Chip/RamDevice.cs delete mode 100644 Emulator/Content/Content.mgcb delete mode 100644 Emulator/DisplayEngine.cs delete mode 100644 Emulator/Emulator.csproj delete mode 100644 Emulator/Extensions.cs delete mode 100644 Emulator/GlobalUsings.cs delete mode 100644 Emulator/Icon.bmp delete mode 100644 Emulator/Icon.ico delete mode 100644 Emulator/Make.cs delete mode 100644 Emulator/Options.cs delete mode 100644 Emulator/Program.cs delete mode 100644 Emulator/Q1Layout.cs delete mode 100644 Orchestrator/Orchestrator.csproj delete mode 100644 Orchestrator/Program.cs create mode 100644 Q1.core/Arch/AddressingMode.cs create mode 100644 Q1.core/Arch/AddressingModes.cs create mode 100644 Q1.core/Arch/Chip.cs create mode 100644 Q1.core/Arch/ChipLayout.cs create mode 100644 Q1.core/Arch/IInstruction.cs create mode 100644 Q1.core/Arch/InstructionSet.cs create mode 100644 Q1.core/GlobalUsings.cs create mode 100644 Q1.core/IAddressable.cs create mode 100644 Q1.core/Memory.cs create mode 100644 Q1.core/Q1.core.csproj create mode 100644 Q1.tests/Core/AddressingModesTests.cs create mode 100644 Q1.tests/Core/InstructionsTests.cs create mode 100644 Q1.tests/Q1.tests.csproj delete mode 100644 ROMs/_old/hello_world.asm delete mode 100644 ROMs/_old/hello_world.q1 delete mode 100644 ROMs/_old/manual.q1 delete mode 100644 ROMs/_old/write_display_direct.asm delete mode 100644 ROMs/_old/write_display_direct.q1 delete mode 100644 ROMs/font.bin delete mode 100644 ROMs/hello_c.asm delete mode 100644 ROMs/hello_c.c delete mode 100644 ROMs/hello_c.q1 delete mode 100644 ROMs/hid.c delete mode 100644 ROMs/logictest.asm delete mode 100644 ROMs/logictest.c delete mode 100644 ROMs/logictest.q1 delete mode 100644 ROMs/paint.asm delete mode 100644 ROMs/paint.c delete mode 100644 ROMs/paint.q1 delete mode 100644 ROMs/screen.c delete mode 100644 ROMs/std.c delete mode 100644 ROMs/typewriter.asm delete mode 100644 ROMs/typewriter.c delete mode 100644 ROMs/typewriter.q1 delete mode 100644 RegionVisualiser/BoxDrawer.cs delete mode 100644 RegionVisualiser/Program.cs delete mode 100644 RegionVisualiser/Region.cs delete mode 100644 RegionVisualiser/RegionVisualiser.csproj delete mode 100644 RegionVisualiser/SizeFormatter.cs delete mode 100644 RegionVisualiser/output.txt diff --git a/.idea/.idea.Chip8Emu2/.idea/.gitignore b/.idea/.idea.Chip8Emu2/.idea/.gitignore deleted file mode 100644 index f0180a3..0000000 --- a/.idea/.idea.Chip8Emu2/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/projectSettingsUpdater.xml -/.idea.Chip8Emu2.iml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.Chip8Emu2/.idea/.name b/.idea/.idea.Chip8Emu2/.idea/.name deleted file mode 100644 index 95e8088..0000000 --- a/.idea/.idea.Chip8Emu2/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Chip8Emu2 \ No newline at end of file diff --git a/.idea/.idea.Chip8Emu2/.idea/encodings.xml b/.idea/.idea.Chip8Emu2/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.Chip8Emu2/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.Chip8Emu2/.idea/indexLayout.xml b/.idea/.idea.Chip8Emu2/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/.idea/.idea.Chip8Emu2/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Chip8Emu2/.idea/vcs.xml b/.idea/.idea.Chip8Emu2/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/.idea.Chip8Emu2/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1/.idea/.gitignore b/.idea/.idea.Q1/.idea/.gitignore deleted file mode 100644 index 842bf41..0000000 --- a/.idea/.idea.Q1/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/projectSettingsUpdater.xml -/.idea.Q1.iml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.Q1/.idea/ANTLRv4ToolGrammarProperties.xml b/.idea/.idea.Q1/.idea/ANTLRv4ToolGrammarProperties.xml deleted file mode 100644 index bb8d49b..0000000 --- a/.idea/.idea.Q1/.idea/ANTLRv4ToolGrammarProperties.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1/.idea/encodings.xml b/.idea/.idea.Q1/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.Q1/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1/.idea/misc.xml b/.idea/.idea.Q1/.idea/misc.xml deleted file mode 100644 index 5207dea..0000000 --- a/.idea/.idea.Q1/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1/.idea/vcs.xml b/.idea/.idea.Q1/.idea/vcs.xml index 35eb1dd..8306744 100644 --- a/.idea/.idea.Q1/.idea/vcs.xml +++ b/.idea/.idea.Q1/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/.idea.Q1/.idea/workspace.xml b/.idea/.idea.Q1/.idea/workspace.xml new file mode 100644 index 0000000..0fc9e8c --- /dev/null +++ b/.idea/.idea.Q1/.idea/workspace.xml @@ -0,0 +1,184 @@ + + + + Assembler/Assembler.csproj + Compiler/Compiler.csproj + Emulator/Q1Emu.csproj + Orchestrator/Orchestrator.csproj + RegionVisualiser/RegionVisualiser.csproj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Q1Emu/.idea/.gitignore b/.idea/.idea.Q1Emu/.idea/.gitignore deleted file mode 100644 index 99ea8f4..0000000 --- a/.idea/.idea.Q1Emu/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/.idea.Q1Emu.iml -/projectSettingsUpdater.xml -/modules.xml -/contentModel.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.Q1Emu/.idea/encodings.xml b/.idea/.idea.Q1Emu/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.Q1Emu/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1Emu/.idea/indexLayout.xml b/.idea/.idea.Q1Emu/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/.idea/.idea.Q1Emu/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1Emu/.idea/misc.xml b/.idea/.idea.Q1Emu/.idea/misc.xml deleted file mode 100644 index 5207dea..0000000 --- a/.idea/.idea.Q1Emu/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.idea.Q1Emu/.idea/vcs.xml b/.idea/.idea.Q1Emu/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/.idea.Q1Emu/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Assembler/Assembler.cs b/Assembler/Assembler.cs deleted file mode 100644 index 71436c4..0000000 --- a/Assembler/Assembler.cs +++ /dev/null @@ -1,450 +0,0 @@ -namespace Q1.Assembler; - -using System.Diagnostics; -using Emulator; -using Emulator.Chip; - -public class Assembler -{ - public static Dictionary RegisterLookup = new() - { - { 0x40, "AX" }, - { 0x41, "AH" }, - { 0x42, "AL" }, - { 0x43, "DX" }, - { 0x44, "DH" }, - { 0x45, "DL" }, - { 0x46, "LX" }, - { 0x50, "PC" }, - { 0x51, "SP" } - }; - private readonly string[] InputLines; - - private readonly Dictionary _labels = new(); - - public Assembler(string[] inputLines) - { - this.InputLines = inputLines; - } - - private void ResolveLabels() - { - int offset = Q1Layout.ProgramStart; - int pos = 0; - foreach (string line in this.InputLines) - { - string trimmedLine = line.Split(";")[0].Trim(); - if (string.IsNullOrEmpty(trimmedLine) || trimmedLine.StartsWith(';')) - continue; - - if (trimmedLine.StartsWith(".org")) - { - string orgValue = trimmedLine[5..].Trim(); - offset = this.GetConstant(orgValue); - } - - else if (trimmedLine.StartsWith(".ascii")) - { - string asciiValue = trimmedLine[7..].Trim() - [1..^1]; // Remove quotes - - for (int i = 0; i < asciiValue.Length; i++) - { - char c = asciiValue[i]; - if (c == '\\') - { - c = asciiValue[++i] switch - { - 'n' => '\n', - 't' => '\t', - '\\' => '\\', - '\'' => '\'', - '"' => '"', - _ => throw new AssemblerException($"Unknown escape sequence: \\{asciiValue[i]}") - }; - } - - pos++; - } - } - - else if (trimmedLine.StartsWith(".raw")) - { - string[] values = trimmedLine[5..].Split(','); - pos += values.Length * 2; // Each value is 2 bytes - } - - else if (trimmedLine.StartsWith(".include")) - { - string includeFile = trimmedLine[9..].Trim()[1..^1]; - if (!File.Exists(includeFile)) - throw new AssemblerException($"Include file '{includeFile}' not found"); - - pos += File.ReadAllBytes(includeFile).Length; - } - - else if (trimmedLine.EndsWith(":")) - { - string label = trimmedLine[..^1].Trim(); - if (this._labels.ContainsKey(label)) - throw new AssemblerException($"Label '{label}' already defined"); - this._labels[label] = (u16) (pos + offset); - } - - else - pos += this.GetInstructionLength(trimmedLine); - } - } - - public IEnumerable Assemble() - { - this.ResolveLabels(); - - foreach (string line in this.InputLines) - { - string trimmedLine = line.Split(";")[0].Trim(); // Remove comments - if (string.IsNullOrEmpty(trimmedLine) || trimmedLine.StartsWith(';')) - continue; - - if (trimmedLine.StartsWith(".org")) - { - // Already handled in ResolveLabels - } - - else if (trimmedLine.StartsWith(".ascii")) - { - string asciiValue = trimmedLine[7..].Trim() - [1..^1]; // Remove quotes - - for (int i = 0; i < asciiValue.Length; i++) - { - char c = asciiValue[i]; - if (c == '\\') - { - c = asciiValue[++i] switch - { - 'n' => '\n', - 't' => '\t', - '\\' => '\\', - '\'' => '\'', - '"' => '"', - _ => throw new AssemblerException($"Unknown escape sequence: \\{asciiValue[i]}") - }; - } - - yield return (byte) c; - } - } - - else if (trimmedLine.StartsWith(".raw")) - { - string[] values = trimmedLine[5..].Split(','); - foreach (string value in values) - { - u16 c = this.GetConstant(value.Trim()); - - yield return c.High(); - yield return c.Low(); - } - } - - else if (trimmedLine.StartsWith(".include")) - { - string includeFile = trimmedLine[9..].Trim()[1..^1]; - if (!File.Exists(includeFile)) - throw new AssemblerException($"Include file '{includeFile}' not found"); - - foreach (byte b in File.ReadAllBytes(includeFile)) - yield return b; - } - - else if (trimmedLine.EndsWith(":")) - { - // Handled in ResolveLabels - } - - else - foreach (byte b in this.GetInstructionBytes(trimmedLine)) - yield return b; - } - } - - private int GetInstructionLength(string instruction) - { - string[] parts = instruction.Split(' ', 2); - string opcode = parts[0].ToUpperInvariant(); - - parts = parts.Length > 1 ? parts[1].Split(',') : []; - if (parts.Length > 2) - throw new AssemblerException("Invalid instruction format"); - - u8 opcodeValue = this.ResolveOpcode(opcode, parts.Length, out u8 addressingIndex); - (u8 m1, u8 m2) = this.ResolveAddressingModes(addressingIndex, parts); - - int length = 2; // Opcode + mode byte - - if (parts.Length > 0) - length += this.GetModeLength(m1); - - if (parts.Length > 1) - length += this.GetModeLength(m2); - - return length; - } - - private IEnumerable GetInstructionBytes(string instruction) - { - string[] parts = instruction.Split(' ', 2); - string opcode = parts[0].ToUpperInvariant(); - - parts = parts.Length > 1 ? parts[1].Split(',') : []; - if (parts.Length > 2) - throw new AssemblerException("Invalid instruction format"); - - u8 opcodeValue = this.ResolveOpcode(opcode, parts.Length, out u8 addressingIndex); - (u8 m1, u8 m2) = this.ResolveAddressingModes(addressingIndex, parts); - - yield return opcodeValue; - yield return (u8) ((m1 << 4) | m2); // Combine m1 and m2 into a single byte - - if (parts.Length > 0) - { - foreach (byte b in this.GetModeBytes(m1, parts[0])) - yield return b; - } - - if (parts.Length > 1) - { - foreach (byte b in this.GetModeBytes(m2, parts[1])) - yield return b; - } - } - private (u8 m1, u8 m2) ResolveAddressingModes(u8 addressingIndex, string[] parts) - { - u8 m1, m2; - switch (addressingIndex) - { - case 0: // Implicit - if (parts.Length > 0) - throw new AssemblerException("Implicit instruction should not have operands"); - - m1 = 0x00; - m2 = 0x00; - break; - - case 1: // Simple addressing mode - if (parts.Length > 2) - throw new AssemblerException("Simple addressing mode should have at most one operand"); - if (parts.Length == 0) - throw new AssemblerException("Simple addressing mode requires an operand"); - - m1 = this.ResolveMode(parts[0]); - m2 = 0x00; - break; - - case 2: // Extended implicit - if (parts.Length > 0) - throw new AssemblerException("Extended implicit instruction should not have operands"); - - m1 = 0x00; - m2 = 0x01; - break; - - case 3: // Dual addressing mode - if (parts.Length != 2) - throw new AssemblerException("Dual addressing mode requires exactly two operands"); - - m1 = this.ResolveMode(parts[0]); - m2 = this.ResolveMode(parts[1]); - break; - - default: - throw new UnreachableException("Invalid addressing index: " + addressingIndex); - } - return (m1, m2); - } - - private u8 ResolveOpcode(string opcode, int parts, out u8 addressingIndex) - { - List addressingIndices = new(); - u8? opCode = null; - foreach ((u8 key, string[] value) in Q1Cpu.InstructionLookupStrings) - { - if (value.Contains(opcode)) - { - addressingIndices.AddRange(value.AllIndexesOf(opcode)); - if (opCode is not null && opCode != key) - throw new AssemblerException($"Ambiguous opcode '{opcode}' matches multiple instructions: {opCode:X4} and {key:X4}"); - - opCode = key; - } - } - - if (opCode is null) - throw new AssemblerException($"Unknown opcode '{opcode}'"); - - int Parts(int index) - => index switch - { - 0 => 0, // Implicit - 1 => 1, // Simple addressing mode - 2 => 0, // Extended implicit - 3 => 2, // Dual addressing mode - _ => throw new UnreachableException("Invalid addressing index: " + index) - }; - - if (addressingIndices.All(x => Parts(x) != parts)) - throw new AssemblerException($"Opcode '{opcode}' does not match the expected number of operands: {parts}"); - - addressingIndex = (u8) addressingIndices.First(x => Parts(x) == parts); - return opCode.Value; - } - - private u8 ResolveMode(string mode) - { - mode = mode.Trim(); - - bool IsRegister(string text) - { - if (text.Length > 1 && text[0] == 'V') - return true; - - return Assembler.RegisterLookup.ContainsValue(text); - } - - if (this._labels.ContainsKey(mode)) - return 0x01; // Immediate - - if (mode.StartsWith("@")) - return 0x03; // Indirect - - if (mode.StartsWith("[") && mode.EndsWith("]")) - { - string inner = mode[1..^1].Trim(); - if (inner.Contains("+")) - return 0x07; // Register indirect with offset - - if (IsRegister(inner)) - return 0x06; // Register indirect - - return 0x02; // Direct - } - - if (IsRegister(mode)) - return 0x05; // Register - - return 0x01; // Immediate - } - - private byte[] GetModeBytes(u8 mode, string operand) - { - operand = operand.Trim(); - - switch (mode) - { - case 0x00: // Implicit - // No additional data needed - return []; - - case 0x01: // Immediate - u16 immediateValue = this.GetConstant(operand); - return [immediateValue.High(), immediateValue.Low()]; - - case 0x02: // Direct - u16 directAddress = this.GetConstant(operand); // Remove brackets - return [directAddress.High(), directAddress.Low()]; - - case 0x03: // Indirect - u16 indirectAddress = this.GetConstant(operand); // Remove brackets and @ - return [indirectAddress.High(), indirectAddress.Low()]; - - case 0x04: // Relative - u16 relativeOffset = this.GetConstant(operand); - return [relativeOffset.High(), relativeOffset.Low()]; - - case 0x05: // Register - u8 regIndex = this.GetRegisterIndex(operand); - return [regIndex]; - - case 0x06: // Register Indirect - u8 indirectRegIndex = this.GetRegisterIndex(operand); // Remove brackets - return [indirectRegIndex]; - - case 0x07: // Register Indirect with Offset - u8 offsetRegIndex = this.GetRegisterIndex(operand[1..^1].Split('+')[0].Trim()); - u16 offsetValue = this.GetConstant(operand[1..^1].Split('+')[1].Trim()); - return [offsetRegIndex, offsetValue.High(), offsetValue.Low()]; - - default: - throw new AssemblerException($"Unknown addressing mode: {mode:X2}"); - } - } - - private int GetModeLength(u8 mode) - { - return mode switch - { - 0x00 => 0, // Implicit - 0x01 => 2, // Immediate - 0x02 => 2, // Direct - 0x03 => 2, // Indirect - 0x04 => 2, // Relative - 0x05 => 1, // Register - 0x06 => 1, // Register indirect - 0x07 => 3, // Register indirect with offset - _ => throw new AssemblerException($"Unknown addressing mode: {mode:X2}") - }; - } - private u8 GetRegisterIndex(string reg) - { - reg = this.Clean(reg); - - if (reg.StartsWith("V")) - { - if (u8.TryParse(reg[1..], out u8 index) && index < 0x3F) - return index; - } - - if (Assembler.RegisterLookup.ContainsValue(reg)) - { - // Find the register index by value - return (u8) Assembler.RegisterLookup.FirstOrDefault(x => x.Value == reg).Key; - } - - throw new AssemblerException($"Invalid register: {reg}"); - } - private u16 GetConstant(string value) - { - value = this.Clean(value); - - if (value.StartsWith("$")) - { - // Hexadecimal constant (backwards) $1FFF - u16 x = Convert.ToUInt16(value[1..], 16); - return x; - } - if (u16.TryParse(value, out u16 result)) - // Decimal constant - return result; - - if (this._labels.TryGetValue(value, out u16 labelAddress)) - // Label reference - return labelAddress; - - return 0; - } - - private string Clean(string value) - { - if (value.StartsWith("@")) - value = value[1..]; // Remove @ for indirect addressing - - if (value.StartsWith("[") && value.EndsWith("]")) - value = value[1..^1].Trim(); // Remove brackets for direct addressing - - return value.Trim(); - } -} - -public class AssemblerException(string message) - : Exception(message); \ No newline at end of file diff --git a/Assembler/Assembler.csproj b/Assembler/Assembler.csproj deleted file mode 100644 index fd4f4fa..0000000 --- a/Assembler/Assembler.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Exe - net9.0 - enable - enable - Q1.Assembler - - - - - - - - - - - diff --git a/Assembler/Extensions.cs b/Assembler/Extensions.cs deleted file mode 100644 index fd4ea1f..0000000 --- a/Assembler/Extensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Q1.Assembler; - -public static class Extensions -{ - - public static u8 High(this u16 value) - { - return (u8)(value >> 8); - } - - public static u8 Low(this u16 value) - { - return (u8)(value & 0xFF); - } -} \ No newline at end of file diff --git a/Assembler/GlobalUsings.cs b/Assembler/GlobalUsings.cs deleted file mode 100644 index ff38a75..0000000 --- a/Assembler/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Integer type aliases -global using i8 = sbyte; // -128 to 127 -global using u8 = byte; // 0 to 255 -global using i16 = short; // -32,768 to 32,767 -global using u16 = ushort; // 0 to 65,535 -global using i32 = int; // -2,147,483,648 to 2,147,483,647 -global using u32 = uint; // 0 to 4,294,967,295 -global using i64 = long; // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 -global using u64 = ulong; // 0 to 18,446,744,073,709,551,615 - -global using ref8 = System.Span; -global using data8 = byte[]; diff --git a/Assembler/Options.cs b/Assembler/Options.cs deleted file mode 100644 index 5b8c618..0000000 --- a/Assembler/Options.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Q1.Assembler; - -using CommandLine; - -public class AssemblerOptions -{ - [Option('i', "input", Required = true, HelpText = "Input file to assemble.")] - public string InputFile { get; set; } - - [Option('o', "output", Required = true, HelpText = "Output file to write the assembled code.")] - public string OutputFile { get; set; } -} \ No newline at end of file diff --git a/Assembler/Program.cs b/Assembler/Program.cs deleted file mode 100644 index 0493057..0000000 --- a/Assembler/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Q1.Assembler; - -using CommandLine; - -public class Program -{ - static void Main(string[] args) - { - Parser.Default.ParseArguments(args).WithParsed(Program.Main); - } - - public static void Main(AssemblerOptions assemblerOptions) - { - assemblerOptions.InputFile = assemblerOptions.InputFile; - - string[] input = File.ReadAllLines(assemblerOptions.InputFile); - - try - { - Assembler assembler = new(input); - byte[] bin = assembler.Assemble().ToArray(); - if (bin.Length > 8 * 1024) - throw new AssemblerException("Assembled binary exceeds maximum size of 8KB."); - - File.WriteAllBytes(assemblerOptions.OutputFile, bin); - - Console.WriteLine($"Assembled {assemblerOptions.InputFile} -> {assemblerOptions.OutputFile}. ({bin.Length} bytes)"); - } - catch (AssemblerException ex) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Error: {ex.Message}"); - Console.ResetColor(); - Environment.Exit(1); - } - } -} \ No newline at end of file diff --git a/Compiler.Testing/Compiler.Testing.csproj b/Compiler.Testing/Compiler.Testing.csproj deleted file mode 100644 index ed9c322..0000000 --- a/Compiler.Testing/Compiler.Testing.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net9.0 - latest - enable - enable - false - - - - - - - - - - - - - - - - - - - - diff --git a/Compiler.Testing/SanityTests.cs b/Compiler.Testing/SanityTests.cs deleted file mode 100644 index 46c0323..0000000 --- a/Compiler.Testing/SanityTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Compiler.Testing; - -using Q1; - -[TestFixture] -public class SanityTests -{ - [Test] - public void BlankProgram() - { - string program = """ - int main() { } - """; - - string result = TestingHelpers.CompileString(program).Trim(); - Assert.That( - result, Is.EqualTo( - """ - jmp _main - _main: - mov 0, V0 - ret - """)); - } - - [Test] - public void ReturnConstant() - { - string program = """ - int main() { return 42; } - """; - - string result = TestingHelpers.CompileString(program).Trim(); - Assert.That( - result, Is.EqualTo( - """ - jmp _main - _main: - mov 42, V0 - ret - """)); - } -} \ No newline at end of file diff --git a/Compiler.Testing/TestingHelpers.cs b/Compiler.Testing/TestingHelpers.cs deleted file mode 100644 index a3d85fe..0000000 --- a/Compiler.Testing/TestingHelpers.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Compiler.Testing; - -using Antlr4.Runtime; -using Q1.Compiler; - -public class TestingHelpers -{ - public static string CompileString(string input) - { - CompilerOptions options = new() { CommentCompilationMode = CommentCompilationMode.None }; - IEnumerable lines = Program.Compile(options, new AntlrInputStream(input)); - return Program.Optimize(lines); - } -} \ No newline at end of file diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4 deleted file mode 100644 index 4bb1342..0000000 --- a/Compiler/CGrammar.g4 +++ /dev/null @@ -1,133 +0,0 @@ -grammar CGrammar; - -options { - contextSuperClass = Q1.Compiler.Context; -} - -HEX: '0x' [0-9a-fA-F]+; - -ID: [a-zA-Z_][a-zA-Z0-9_]*; -INT: [0-9]+; -WS: [ \t\r\n]+ -> skip; -COMMENT: '//' .*? ([\n] | EOF) -> channel(HIDDEN); -DIRECTIVE: '#' .*? ([\n] | EOF) -> channel(HIDDEN); - -LETTER: '\'' . '\''; -STRING: '"' .*? '"'; - -program - : function+ EOF - ; - -function - : rtype=type name=ID '(' ( types+=type params+=ID (',' types+=type params+=ID )* )? ')' ';' #functionPrototype - | rtype=type name=ID '(' ( types+=type params+=ID (',' types+=type params+=ID )* )? ')' block #functionDefinition - ; - -block - : '{' block_item* '}' - ; - -block_item - : statement - | declaration - ; - -statement - : 'return' expression ';' #returnStatement - | 'if' '(' expression ')' then=statement ('else' else=statement)? #ifStatement - | 'for' '(' (initializer=expression)? ';' cond=expression? ';' post=expression? ')' body=statement #forExprStatement - | 'for' '(' initializer=declaration cond=expression? ';' post=expression? ')' body=statement #forDeclStatement - | 'while' '(' cond=expression ')' body=statement #whileStatement - | 'do' body=statement 'while' '(' cond=expression ')' ';' #doWhileStatement - | 'break' ';' #breakStatement - | 'continue' ';' #continueStatement - | expression ';' #expressionStatement - | block #blockStatement - | ';' #nullStatement - ; - - -declaration - : type name=ID ('=' value=expression)? ';' #variableDeclaration - ; - -expression - : '(' expression ')' #parenthesizedExpression -// | left=expression ',' right=expression #commaExpression - | 'new' type '[' INT? ']' ('{' ( params+=expression (',' params+=expression )* )? '}')? #arrayExpression - | constant #constantExpression - | target '=' expression #assignmentExpression - | '*' expression #dereferenceExpression - | '&' target #addressOfExpression - | ID #variableExpression - - | ID '(' ( params+=expression (',' params+=expression )* )? ')' #callExpression - | obj=target '[' indexer=expression ']' #indexExpression - - | '!' expression #notExpression - | '~' expression #invertExpression - - | '++' target #incrementPrefixExpression - | '--' target #decrementPrefixExpression - | target '++' #incrementPostfixExpression - | target '--' #decrementPostfixExpression - - | left=expression '*' right=expression #multiplyExpression - | left=expression '/' right=expression #divideExpression - | left=expression '%' right=expression #modulusExpression - - | left=expression '+' right=expression #addExpression - | left=expression '-' right=expression #subtractExpression - - | left=expression '<' right=expression #lessThanExpression - | left=expression '>' right=expression #greaterThanExpression - | left=expression '<=' right=expression #lessThanOrEqualExpression - | left=expression '>=' right=expression #greaterThanOrEqualExpression - | left=expression '==' right=expression #equalExpression - | left=expression '!=' right=expression #notEqualExpression - - | left=expression '&' right=expression #bitwiseAndExpression - | left=expression '|' right=expression #bitwiseOrExpression - | left=expression '^' right=expression #bitwiseXorExpression - - | left=expression '<<' right=expression #bitwiseLeftShiftExpression - | left=expression '>>' right=expression #bitwiseRightShiftExpression - - | left=expression '&&' right=expression #logicalAndExpression - | left=expression '||' right=expression #logicalOrExpression - - | target '*=' expression #compoundMultiplyExpression - | target '/=' expression #compoundDivideExpression - | target '%=' expression #compoundModulusExpression - - | target '+=' expression #compoundAddExpression - | target '-=' expression #compoundSubtractExpression - - | target '&=' expression #compoundBitwiseAndExpression - | target '|=' expression #compoundBitwiseOrExpression - | target '^=' expression #compoundBitwiseXorExpression - - | target '<<=' expression #compoundBitwiseLeftShiftExpression - | target '>>=' expression #compoundBitwiseRightShiftExpression - - | cond=expression '?' then=expression ':' else=expression #ternaryExpression - ; - -constant - : INT # intConstant - | HEX # hexConstant - | LETTER # charConstant - | STRING # stringConstant - ; - -type - : 'int' - | 'char' - | type '*' - ; - -target - : ID # variableTarget - | obj=target '[' indexer=expression ']' #indexerTarget - ; \ No newline at end of file diff --git a/Compiler/CType.cs b/Compiler/CType.cs deleted file mode 100644 index 61b5108..0000000 --- a/Compiler/CType.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Q1.Compiler.visitors; - -public class CType -{ - public string Name; - public int Size; - - public CType(string name, int size) - { - this.Name = name; - this.Size = size; - - if (size > 2) - throw new CompilerException("Types that take up more than 2 bytes are not supported"); - } - - public override string ToString() => this.Name; - - public static readonly CType Int = new("int", 2); - public static readonly CType Char = new("char", 1); -} - -public class CTypePtr : CType -{ - public CType Sub; - - public CTypePtr(CType sub) : base($"{sub.Name}*",2) - { - this.Sub = sub; - } -} \ No newline at end of file diff --git a/Compiler/CommentCompilationMode.cs b/Compiler/CommentCompilationMode.cs deleted file mode 100644 index 0ee20fd..0000000 --- a/Compiler/CommentCompilationMode.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Q1.Compiler; - -[Flags] -public enum CommentCompilationMode -{ - None = 0, - UserDefined = 1 << 0, - Generated = 1 << 1, - All = CommentCompilationMode.UserDefined | CommentCompilationMode.Generated -} \ No newline at end of file diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj deleted file mode 100644 index 623282e..0000000 --- a/Compiler/Compiler.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net9.0 - enable - enable - Q1.Compiler - - - - - - - - - - - - diff --git a/Compiler/CompilerException.cs b/Compiler/CompilerException.cs deleted file mode 100644 index f5a78f1..0000000 --- a/Compiler/CompilerException.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Q1.Compiler; - -public class CompilerException(string message) - : Exception(message); \ No newline at end of file diff --git a/Compiler/CompilerExtensions.cs b/Compiler/CompilerExtensions.cs deleted file mode 100644 index f1f0ee6..0000000 --- a/Compiler/CompilerExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Q1.Compiler; - -public static class CompilerExtensions -{ - public static string TrimStart(this string source, string search) - { - if (source.StartsWith(search)) - return source[search.Length..]; - - return source; - } -} \ No newline at end of file diff --git a/Compiler/CompilerOptions.cs b/Compiler/CompilerOptions.cs deleted file mode 100644 index 87ec384..0000000 --- a/Compiler/CompilerOptions.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Q1.Compiler; - -using CommandLine; - -public class CompilerOptions -{ - [Option('i', "input", Required = true, HelpText = "Input file to compile.")] - public string InputFile { get; set; } - - [Option('o', "output", Required = true, HelpText = "Output file to write the compiled code.")] - public string OutputFile { get; set; } - - [Option('c', "comment-compilation", Required = false, HelpText = "Comments to preserve in the compiled result")] - public CommentCompilationMode CommentCompilationMode { get; set; } = CommentCompilationMode.UserDefined; - - [Option('v', "verbose", Required = false, HelpText = "Enable verbose output during compilation.")] - public bool Verbose { get; set; } = false; -} \ No newline at end of file diff --git a/Compiler/Context.cs b/Compiler/Context.cs deleted file mode 100644 index 52e577f..0000000 --- a/Compiler/Context.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Q1.Compiler; - -using Antlr4.Runtime; - -public class Context : ParserRuleContext -{ - public string? LoopEndBranch; - public string? LoopBodyBranch; - - public Context() { } - - public Context(ParserRuleContext parent, int invokingStateNumber) - : base((Context) parent, invokingStateNumber) - { - } - - - public void SyncProps(Context childCtx) - { - childCtx.LoopBodyBranch = this.LoopBodyBranch; - childCtx.LoopEndBranch = this.LoopEndBranch; - } -} \ No newline at end of file diff --git a/Compiler/FunctionReference.cs b/Compiler/FunctionReference.cs deleted file mode 100644 index b63247a..0000000 --- a/Compiler/FunctionReference.cs +++ /dev/null @@ -1,129 +0,0 @@ -namespace Q1.Compiler; - -using System.Reflection.Metadata; -using System.Text; -using visitors; - -public class FunctionReference -{ - // TODO: Implement return type - public string Name; - public CType Type; - public List Overloads = new(); - - public FunctionReference(string name, CType type) - { - this.Type = type; - this.Name = name; - } - - public string GetBranchName(FunctionOverload overload) - { - List<(string paramName, CType paramType)> parameters = overload - .ParameterNames - .Zip(overload.ParameterTypes) - .ToList(); - - StringBuilder branchName = new(); - branchName.Append($"_{this.Name}"); - - if (parameters.Count > 0) - { - branchName.Append($"_{string.Join("__", parameters - .Select(x => $"{x.paramType}_{x.paramName}"))}"); - } - - return branchName.ToString(); - } - - public string GetBranchFriendlyName(FunctionOverload overload) - { - List<(string paramName, CType paramType)> parameters = overload - .ParameterNames - .Zip(overload.ParameterTypes) - .ToList(); - - StringBuilder branchName = new(); - branchName.Append($"{this.Type} {this.Name}"); - branchName.Append("("); - - branchName.Append(string.Join(", ", parameters - .Select(x => $"{x.paramType} {x.paramName}"))); - - branchName.Append(")"); - - return branchName.ToString(); - } - - public FunctionOverload CreateOverloadWithBody(List parameterNames, List parameterTypes) - { - FunctionOverload? existingOverload = this.Overloads - .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes)); - - if (existingOverload != null) - { - if (existingOverload.BodyImplemented) - throw new CompilerException($"Cannot define another overload for {this.Name}," - + $" as one with an identical signature and body already exists."); - - existingOverload.BodyImplemented = true; - return existingOverload; - } - else - { - FunctionOverload newOverload = new(parameterNames, parameterTypes, true); - this.Overloads.Add(newOverload); - return newOverload; - } - } - - public FunctionOverload CreateOverloadWithoutBody(List parameterNames, List parameterTypes) - { - FunctionOverload? existingOverload = this.Overloads - .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes)); - - if (existingOverload != null) - { - if (!existingOverload.BodyImplemented) - throw new CompilerException($"Cannot prototype another overload for {this.Name}," - + $" as one with an identical signature already exists."); - return existingOverload; - } - else - { - FunctionOverload newOverload = new(parameterNames, parameterTypes, false); - this.Overloads.Add(newOverload); - return newOverload; - } - } - public FunctionOverload GetOverload(int paramsCount) - { - FunctionOverload? overload = this.Overloads - .FirstOrDefault(x => x.ParameterTypes.Count == paramsCount); - - if (overload != null) - return overload; - - throw new CompilerException($"Overload for {this.Name} with {paramsCount} arguments could not be found."); - } -} - -public class FunctionOverload -{ - public List ParameterTypes; - public List ParameterNames; - public bool BodyImplemented; - - public FunctionOverload(List parameterNames, List parameterTypes, bool bodyImplemented) - { - this.ParameterTypes = parameterTypes; - this.ParameterNames = parameterNames; - this.BodyImplemented = bodyImplemented; - } - - public bool ParamsMatch(List parameterNames, List parameterTypes) - { - return this.ParameterNames.SequenceEqual(parameterNames) - && this.ParameterTypes.SequenceEqual(parameterTypes); - } -} \ No newline at end of file diff --git a/Compiler/Optimizer.cs b/Compiler/Optimizer.cs deleted file mode 100644 index 4646c1c..0000000 --- a/Compiler/Optimizer.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Q1.Compiler; - -using System.Text.RegularExpressions; - -public class Optimizer -{ - private string _instructions; - private int _currentIndex = 0; - - public Optimizer(List instructions) - { - this._instructions = string.Join(Environment.NewLine, instructions); - } - - public string Optimize() - { - string output = this._instructions; - output = this.RemoveRedundantFallbackReturns(output); - - return output; - } - - private string RemoveRedundantFallbackReturns(string input) - { - string pattern = @"(mov .*, V0\n\s*ret\n)\s*mov 0, V0\n\s*ret"; - return Regex.Replace(input, pattern, "$1"); - } -} \ No newline at end of file diff --git a/Compiler/PreprocessingCharStream.cs b/Compiler/PreprocessingCharStream.cs deleted file mode 100644 index 428cbff..0000000 --- a/Compiler/PreprocessingCharStream.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Q1.Compiler; - -using Antlr4.Runtime; -using Antlr4.Runtime.Misc; - -public class PreprocessingCharStream : ICharStream -{ - private readonly AntlrInputStream inner; - - public PreprocessingCharStream(string filePath) - { - string preprocessed = Preprocessor.Process(filePath); - this.inner = new AntlrInputStream(preprocessed); - } - - public int Index => this.inner.Index; - public int Size => this.inner.Size; - public string SourceName => this.inner.SourceName; - public void Consume() => this.inner.Consume(); - public int LA(int i) => this.inner.LA(i); - public int Mark() => this.inner.Mark(); - public void Release(int marker) => this.inner.Release(marker); - public void Seek(int index) => this.inner.Seek(index); - public string GetText(Interval interval) => this.inner.GetText(interval); -} \ No newline at end of file diff --git a/Compiler/Preprocessor.cs b/Compiler/Preprocessor.cs deleted file mode 100644 index f11ae3a..0000000 --- a/Compiler/Preprocessor.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace Q1.Compiler; - -using System.Text.RegularExpressions; - -public static class Preprocessor -{ - private static readonly Dictionary Defines = new(); - - public static string Process(string filePath) - { - List lines = []; - ProcessFile(filePath, lines, []); - return string.Join(Environment.NewLine, lines); - } - - private static void ProcessFile(string filePath, List output, HashSet includeGuard) - { - if (includeGuard.Contains(Path.GetFullPath(filePath))) - return; // prevent recursive includes - - includeGuard.Add(Path.GetFullPath(filePath)); - - foreach (string rawLine in File.ReadAllLines(filePath)) - { - string line = rawLine.Trim(); - - if (line.StartsWith("#include")) - { - Match match = Regex.Match(line, "#include\\s+\"([^\"]+)\""); - if (match.Success) - { - string includePath = Path.Combine(Path.GetDirectoryName(filePath)!, match.Groups[1].Value); - ProcessFile(includePath, output, includeGuard); - } - continue; - } - else if (line.StartsWith("#define")) - { - Match match = Regex.Match(line, "#define\\s+(\\w+)\\s+(.*)"); - if (match.Success) - Defines[match.Groups[1].Value] = match.Groups[2].Value; - continue; - } - else if (line.StartsWith("#load")) - { - output.Add(line.Replace("#load", "#.include")); - continue; - } - - // expand macros - foreach (KeyValuePair kvp in Defines.OrderByDescending(k => k.Key.Length)) - line = line.Replace(kvp.Key, kvp.Value); - - output.Add(line); - } - } -} \ No newline at end of file diff --git a/Compiler/Program.cs b/Compiler/Program.cs deleted file mode 100644 index 7ecbf8e..0000000 --- a/Compiler/Program.cs +++ /dev/null @@ -1,73 +0,0 @@ -namespace Q1.Compiler; - -using System.Text; -using Antlr4.Runtime; -using CommandLine; -using visitors; -using Parser = CommandLine.Parser; - -public class Program -{ - static void Main(string[] args) - { - Parser commandLineParser = new(with => - { - with.CaseInsensitiveEnumValues = true; - }); - - commandLineParser - .ParseArguments(args) - .WithParsed(Program.Main); - } - - public static void Main(CompilerOptions options) - { - options.InputFile = options.InputFile; - - try - { - ICharStream inputStream = new PreprocessingCharStream(options.InputFile); - IEnumerable result = Program.Compile(options, inputStream); - - File.WriteAllLines(options.OutputFile, result); - if (options.Verbose) - { - Console.WriteLine(); - foreach (string line in result) - Console.WriteLine(line); - Console.WriteLine(); - } - - Console.WriteLine($"Compilation successful. ({result.Count(x=>x != string.Empty)} instructions)"); - } - catch (CompilerException ex) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Error: {ex.Message}"); - Console.ResetColor(); - Environment.Exit(1); - } - } - public static IEnumerable Compile(CompilerOptions options, ICharStream inputStream) - { - CGrammarLexer lexer = new(inputStream); - lexer.RemoveErrorListeners(); - - ITokenStream tokenStream = new BufferedTokenStream(lexer); - CGrammarParser parser = new(tokenStream); - parser.RemoveErrorListeners(); - - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - Encoding encoding = Encoding.GetEncoding(437); - CCompilerVisitor compiler = new(options.CommentCompilationMode, encoding); - IEnumerable result = compiler.Compile(parser.program()); - - return result; - } - - public static string Optimize(IEnumerable instructions) - { - Optimizer optimizer = new(instructions.ToList()); - return optimizer.Optimize(); - } -} \ No newline at end of file diff --git a/Compiler/Target.cs b/Compiler/Target.cs deleted file mode 100644 index 84d055d..0000000 --- a/Compiler/Target.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Q1.Compiler.visitors; - -public class Target -{ - public string Value; - public string Address; - public CType Type; - - public Target(CType type, string value, string address) - { - this.Value = value; - this.Address = address; - this.Type = type; - } -} \ No newline at end of file diff --git a/Compiler/VariableReference.cs b/Compiler/VariableReference.cs deleted file mode 100644 index 4682d40..0000000 --- a/Compiler/VariableReference.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Q1.Compiler; - -using visitors; - -public class VariableReference -{ - public int Address; - public CType Type; - - public VariableReference(int address, CType type) - { - this.Address = address; - this.Type = type; - } -} \ No newline at end of file diff --git a/Compiler/gen/CGrammar.interp b/Compiler/gen/CGrammar.interp deleted file mode 100644 index e1368df..0000000 --- a/Compiler/gen/CGrammar.interp +++ /dev/null @@ -1,145 +0,0 @@ -token literal names: -null -'(' -',' -')' -';' -'{' -'}' -'return' -'if' -'else' -'for' -'while' -'do' -'break' -'continue' -'=' -'new' -'[' -']' -'*' -'&' -'!' -'~' -'++' -'--' -'/' -'%' -'+' -'-' -'<' -'>' -'<=' -'>=' -'==' -'!=' -'|' -'^' -'<<' -'>>' -'&&' -'||' -'*=' -'/=' -'%=' -'+=' -'-=' -'&=' -'|=' -'^=' -'<<=' -'>>=' -'?' -':' -'int' -'char' -null -null -null -null -null -null -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -HEX -ID -INT -WS -COMMENT -DIRECTIVE -LETTER -STRING - -rule names: -program -function -block -block_item -statement -declaration -expression -constant -type -target - - -atn: -[4, 1, 62, 361, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 4, 0, 22, 8, 0, 11, 0, 12, 0, 23, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 37, 8, 1, 10, 1, 12, 1, 40, 9, 1, 3, 1, 42, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 56, 8, 1, 10, 1, 12, 1, 59, 9, 1, 3, 1, 61, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 66, 8, 1, 1, 2, 1, 2, 5, 2, 70, 8, 2, 10, 2, 12, 2, 73, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 79, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 92, 8, 4, 1, 4, 1, 4, 1, 4, 3, 4, 97, 8, 4, 1, 4, 1, 4, 3, 4, 101, 8, 4, 1, 4, 1, 4, 3, 4, 105, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 113, 8, 4, 1, 4, 1, 4, 3, 4, 117, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 145, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 151, 8, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 164, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 171, 8, 6, 10, 6, 12, 6, 174, 9, 6, 3, 6, 176, 8, 6, 1, 6, 3, 6, 179, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 196, 8, 6, 10, 6, 12, 6, 199, 9, 6, 3, 6, 201, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 263, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 325, 8, 6, 10, 6, 12, 6, 328, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 334, 8, 7, 1, 8, 1, 8, 1, 8, 3, 8, 339, 8, 8, 1, 8, 1, 8, 5, 8, 343, 8, 8, 10, 8, 12, 8, 346, 9, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 5, 9, 356, 8, 9, 10, 9, 12, 9, 359, 9, 9, 1, 9, 0, 3, 12, 16, 18, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 0, 430, 0, 21, 1, 0, 0, 0, 2, 65, 1, 0, 0, 0, 4, 67, 1, 0, 0, 0, 6, 78, 1, 0, 0, 0, 8, 144, 1, 0, 0, 0, 10, 146, 1, 0, 0, 0, 12, 262, 1, 0, 0, 0, 14, 333, 1, 0, 0, 0, 16, 338, 1, 0, 0, 0, 18, 347, 1, 0, 0, 0, 20, 22, 3, 2, 1, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 5, 0, 0, 1, 26, 1, 1, 0, 0, 0, 27, 28, 3, 16, 8, 0, 28, 29, 5, 56, 0, 0, 29, 41, 5, 1, 0, 0, 30, 31, 3, 16, 8, 0, 31, 38, 5, 56, 0, 0, 32, 33, 5, 2, 0, 0, 33, 34, 3, 16, 8, 0, 34, 35, 5, 56, 0, 0, 35, 37, 1, 0, 0, 0, 36, 32, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 42, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 30, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 44, 5, 3, 0, 0, 44, 45, 5, 4, 0, 0, 45, 66, 1, 0, 0, 0, 46, 47, 3, 16, 8, 0, 47, 48, 5, 56, 0, 0, 48, 60, 5, 1, 0, 0, 49, 50, 3, 16, 8, 0, 50, 57, 5, 56, 0, 0, 51, 52, 5, 2, 0, 0, 52, 53, 3, 16, 8, 0, 53, 54, 5, 56, 0, 0, 54, 56, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, 56, 59, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 49, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 63, 5, 3, 0, 0, 63, 64, 3, 4, 2, 0, 64, 66, 1, 0, 0, 0, 65, 27, 1, 0, 0, 0, 65, 46, 1, 0, 0, 0, 66, 3, 1, 0, 0, 0, 67, 71, 5, 5, 0, 0, 68, 70, 3, 6, 3, 0, 69, 68, 1, 0, 0, 0, 70, 73, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 74, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 74, 75, 5, 6, 0, 0, 75, 5, 1, 0, 0, 0, 76, 79, 3, 8, 4, 0, 77, 79, 3, 10, 5, 0, 78, 76, 1, 0, 0, 0, 78, 77, 1, 0, 0, 0, 79, 7, 1, 0, 0, 0, 80, 81, 5, 7, 0, 0, 81, 82, 3, 12, 6, 0, 82, 83, 5, 4, 0, 0, 83, 145, 1, 0, 0, 0, 84, 85, 5, 8, 0, 0, 85, 86, 5, 1, 0, 0, 86, 87, 3, 12, 6, 0, 87, 88, 5, 3, 0, 0, 88, 91, 3, 8, 4, 0, 89, 90, 5, 9, 0, 0, 90, 92, 3, 8, 4, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 145, 1, 0, 0, 0, 93, 94, 5, 10, 0, 0, 94, 96, 5, 1, 0, 0, 95, 97, 3, 12, 6, 0, 96, 95, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 100, 5, 4, 0, 0, 99, 101, 3, 12, 6, 0, 100, 99, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 104, 5, 4, 0, 0, 103, 105, 3, 12, 6, 0, 104, 103, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 107, 5, 3, 0, 0, 107, 145, 3, 8, 4, 0, 108, 109, 5, 10, 0, 0, 109, 110, 5, 1, 0, 0, 110, 112, 3, 10, 5, 0, 111, 113, 3, 12, 6, 0, 112, 111, 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 116, 5, 4, 0, 0, 115, 117, 3, 12, 6, 0, 116, 115, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 118, 1, 0, 0, 0, 118, 119, 5, 3, 0, 0, 119, 120, 3, 8, 4, 0, 120, 145, 1, 0, 0, 0, 121, 122, 5, 11, 0, 0, 122, 123, 5, 1, 0, 0, 123, 124, 3, 12, 6, 0, 124, 125, 5, 3, 0, 0, 125, 126, 3, 8, 4, 0, 126, 145, 1, 0, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 3, 8, 4, 0, 129, 130, 5, 11, 0, 0, 130, 131, 5, 1, 0, 0, 131, 132, 3, 12, 6, 0, 132, 133, 5, 3, 0, 0, 133, 134, 5, 4, 0, 0, 134, 145, 1, 0, 0, 0, 135, 136, 5, 13, 0, 0, 136, 145, 5, 4, 0, 0, 137, 138, 5, 14, 0, 0, 138, 145, 5, 4, 0, 0, 139, 140, 3, 12, 6, 0, 140, 141, 5, 4, 0, 0, 141, 145, 1, 0, 0, 0, 142, 145, 3, 4, 2, 0, 143, 145, 5, 4, 0, 0, 144, 80, 1, 0, 0, 0, 144, 84, 1, 0, 0, 0, 144, 93, 1, 0, 0, 0, 144, 108, 1, 0, 0, 0, 144, 121, 1, 0, 0, 0, 144, 127, 1, 0, 0, 0, 144, 135, 1, 0, 0, 0, 144, 137, 1, 0, 0, 0, 144, 139, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 143, 1, 0, 0, 0, 145, 9, 1, 0, 0, 0, 146, 147, 3, 16, 8, 0, 147, 150, 5, 56, 0, 0, 148, 149, 5, 15, 0, 0, 149, 151, 3, 12, 6, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 153, 5, 4, 0, 0, 153, 11, 1, 0, 0, 0, 154, 155, 6, 6, -1, 0, 155, 156, 5, 1, 0, 0, 156, 157, 3, 12, 6, 0, 157, 158, 5, 3, 0, 0, 158, 263, 1, 0, 0, 0, 159, 160, 5, 16, 0, 0, 160, 161, 3, 16, 8, 0, 161, 163, 5, 17, 0, 0, 162, 164, 5, 57, 0, 0, 163, 162, 1, 0, 0, 0, 163, 164, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 178, 5, 18, 0, 0, 166, 175, 5, 5, 0, 0, 167, 172, 3, 12, 6, 0, 168, 169, 5, 2, 0, 0, 169, 171, 3, 12, 6, 0, 170, 168, 1, 0, 0, 0, 171, 174, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, 0, 173, 176, 1, 0, 0, 0, 174, 172, 1, 0, 0, 0, 175, 167, 1, 0, 0, 0, 175, 176, 1, 0, 0, 0, 176, 177, 1, 0, 0, 0, 177, 179, 5, 6, 0, 0, 178, 166, 1, 0, 0, 0, 178, 179, 1, 0, 0, 0, 179, 263, 1, 0, 0, 0, 180, 263, 3, 14, 7, 0, 181, 182, 3, 18, 9, 0, 182, 183, 5, 15, 0, 0, 183, 184, 3, 12, 6, 41, 184, 263, 1, 0, 0, 0, 185, 186, 5, 19, 0, 0, 186, 263, 3, 12, 6, 40, 187, 188, 5, 20, 0, 0, 188, 263, 3, 18, 9, 0, 189, 263, 5, 56, 0, 0, 190, 191, 5, 56, 0, 0, 191, 200, 5, 1, 0, 0, 192, 197, 3, 12, 6, 0, 193, 194, 5, 2, 0, 0, 194, 196, 3, 12, 6, 0, 195, 193, 1, 0, 0, 0, 196, 199, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 201, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 200, 192, 1, 0, 0, 0, 200, 201, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 263, 5, 3, 0, 0, 203, 204, 3, 18, 9, 0, 204, 205, 5, 17, 0, 0, 205, 206, 3, 12, 6, 0, 206, 207, 5, 18, 0, 0, 207, 263, 1, 0, 0, 0, 208, 209, 5, 21, 0, 0, 209, 263, 3, 12, 6, 35, 210, 211, 5, 22, 0, 0, 211, 263, 3, 12, 6, 34, 212, 213, 5, 23, 0, 0, 213, 263, 3, 18, 9, 0, 214, 215, 5, 24, 0, 0, 215, 263, 3, 18, 9, 0, 216, 217, 3, 18, 9, 0, 217, 218, 5, 23, 0, 0, 218, 263, 1, 0, 0, 0, 219, 220, 3, 18, 9, 0, 220, 221, 5, 24, 0, 0, 221, 263, 1, 0, 0, 0, 222, 223, 3, 18, 9, 0, 223, 224, 5, 41, 0, 0, 224, 225, 3, 12, 6, 11, 225, 263, 1, 0, 0, 0, 226, 227, 3, 18, 9, 0, 227, 228, 5, 42, 0, 0, 228, 229, 3, 12, 6, 10, 229, 263, 1, 0, 0, 0, 230, 231, 3, 18, 9, 0, 231, 232, 5, 43, 0, 0, 232, 233, 3, 12, 6, 9, 233, 263, 1, 0, 0, 0, 234, 235, 3, 18, 9, 0, 235, 236, 5, 44, 0, 0, 236, 237, 3, 12, 6, 8, 237, 263, 1, 0, 0, 0, 238, 239, 3, 18, 9, 0, 239, 240, 5, 45, 0, 0, 240, 241, 3, 12, 6, 7, 241, 263, 1, 0, 0, 0, 242, 243, 3, 18, 9, 0, 243, 244, 5, 46, 0, 0, 244, 245, 3, 12, 6, 6, 245, 263, 1, 0, 0, 0, 246, 247, 3, 18, 9, 0, 247, 248, 5, 47, 0, 0, 248, 249, 3, 12, 6, 5, 249, 263, 1, 0, 0, 0, 250, 251, 3, 18, 9, 0, 251, 252, 5, 48, 0, 0, 252, 253, 3, 12, 6, 4, 253, 263, 1, 0, 0, 0, 254, 255, 3, 18, 9, 0, 255, 256, 5, 49, 0, 0, 256, 257, 3, 12, 6, 3, 257, 263, 1, 0, 0, 0, 258, 259, 3, 18, 9, 0, 259, 260, 5, 50, 0, 0, 260, 261, 3, 12, 6, 2, 261, 263, 1, 0, 0, 0, 262, 154, 1, 0, 0, 0, 262, 159, 1, 0, 0, 0, 262, 180, 1, 0, 0, 0, 262, 181, 1, 0, 0, 0, 262, 185, 1, 0, 0, 0, 262, 187, 1, 0, 0, 0, 262, 189, 1, 0, 0, 0, 262, 190, 1, 0, 0, 0, 262, 203, 1, 0, 0, 0, 262, 208, 1, 0, 0, 0, 262, 210, 1, 0, 0, 0, 262, 212, 1, 0, 0, 0, 262, 214, 1, 0, 0, 0, 262, 216, 1, 0, 0, 0, 262, 219, 1, 0, 0, 0, 262, 222, 1, 0, 0, 0, 262, 226, 1, 0, 0, 0, 262, 230, 1, 0, 0, 0, 262, 234, 1, 0, 0, 0, 262, 238, 1, 0, 0, 0, 262, 242, 1, 0, 0, 0, 262, 246, 1, 0, 0, 0, 262, 250, 1, 0, 0, 0, 262, 254, 1, 0, 0, 0, 262, 258, 1, 0, 0, 0, 263, 326, 1, 0, 0, 0, 264, 265, 10, 29, 0, 0, 265, 266, 5, 19, 0, 0, 266, 325, 3, 12, 6, 30, 267, 268, 10, 28, 0, 0, 268, 269, 5, 25, 0, 0, 269, 325, 3, 12, 6, 29, 270, 271, 10, 27, 0, 0, 271, 272, 5, 26, 0, 0, 272, 325, 3, 12, 6, 28, 273, 274, 10, 26, 0, 0, 274, 275, 5, 27, 0, 0, 275, 325, 3, 12, 6, 27, 276, 277, 10, 25, 0, 0, 277, 278, 5, 28, 0, 0, 278, 325, 3, 12, 6, 26, 279, 280, 10, 24, 0, 0, 280, 281, 5, 29, 0, 0, 281, 325, 3, 12, 6, 25, 282, 283, 10, 23, 0, 0, 283, 284, 5, 30, 0, 0, 284, 325, 3, 12, 6, 24, 285, 286, 10, 22, 0, 0, 286, 287, 5, 31, 0, 0, 287, 325, 3, 12, 6, 23, 288, 289, 10, 21, 0, 0, 289, 290, 5, 32, 0, 0, 290, 325, 3, 12, 6, 22, 291, 292, 10, 20, 0, 0, 292, 293, 5, 33, 0, 0, 293, 325, 3, 12, 6, 21, 294, 295, 10, 19, 0, 0, 295, 296, 5, 34, 0, 0, 296, 325, 3, 12, 6, 20, 297, 298, 10, 18, 0, 0, 298, 299, 5, 20, 0, 0, 299, 325, 3, 12, 6, 19, 300, 301, 10, 17, 0, 0, 301, 302, 5, 35, 0, 0, 302, 325, 3, 12, 6, 18, 303, 304, 10, 16, 0, 0, 304, 305, 5, 36, 0, 0, 305, 325, 3, 12, 6, 17, 306, 307, 10, 15, 0, 0, 307, 308, 5, 37, 0, 0, 308, 325, 3, 12, 6, 16, 309, 310, 10, 14, 0, 0, 310, 311, 5, 38, 0, 0, 311, 325, 3, 12, 6, 15, 312, 313, 10, 13, 0, 0, 313, 314, 5, 39, 0, 0, 314, 325, 3, 12, 6, 14, 315, 316, 10, 12, 0, 0, 316, 317, 5, 40, 0, 0, 317, 325, 3, 12, 6, 13, 318, 319, 10, 1, 0, 0, 319, 320, 5, 51, 0, 0, 320, 321, 3, 12, 6, 0, 321, 322, 5, 52, 0, 0, 322, 323, 3, 12, 6, 2, 323, 325, 1, 0, 0, 0, 324, 264, 1, 0, 0, 0, 324, 267, 1, 0, 0, 0, 324, 270, 1, 0, 0, 0, 324, 273, 1, 0, 0, 0, 324, 276, 1, 0, 0, 0, 324, 279, 1, 0, 0, 0, 324, 282, 1, 0, 0, 0, 324, 285, 1, 0, 0, 0, 324, 288, 1, 0, 0, 0, 324, 291, 1, 0, 0, 0, 324, 294, 1, 0, 0, 0, 324, 297, 1, 0, 0, 0, 324, 300, 1, 0, 0, 0, 324, 303, 1, 0, 0, 0, 324, 306, 1, 0, 0, 0, 324, 309, 1, 0, 0, 0, 324, 312, 1, 0, 0, 0, 324, 315, 1, 0, 0, 0, 324, 318, 1, 0, 0, 0, 325, 328, 1, 0, 0, 0, 326, 324, 1, 0, 0, 0, 326, 327, 1, 0, 0, 0, 327, 13, 1, 0, 0, 0, 328, 326, 1, 0, 0, 0, 329, 334, 5, 57, 0, 0, 330, 334, 5, 55, 0, 0, 331, 334, 5, 61, 0, 0, 332, 334, 5, 62, 0, 0, 333, 329, 1, 0, 0, 0, 333, 330, 1, 0, 0, 0, 333, 331, 1, 0, 0, 0, 333, 332, 1, 0, 0, 0, 334, 15, 1, 0, 0, 0, 335, 336, 6, 8, -1, 0, 336, 339, 5, 53, 0, 0, 337, 339, 5, 54, 0, 0, 338, 335, 1, 0, 0, 0, 338, 337, 1, 0, 0, 0, 339, 344, 1, 0, 0, 0, 340, 341, 10, 1, 0, 0, 341, 343, 5, 19, 0, 0, 342, 340, 1, 0, 0, 0, 343, 346, 1, 0, 0, 0, 344, 342, 1, 0, 0, 0, 344, 345, 1, 0, 0, 0, 345, 17, 1, 0, 0, 0, 346, 344, 1, 0, 0, 0, 347, 348, 6, 9, -1, 0, 348, 349, 5, 56, 0, 0, 349, 357, 1, 0, 0, 0, 350, 351, 10, 1, 0, 0, 351, 352, 5, 17, 0, 0, 352, 353, 3, 12, 6, 0, 353, 354, 5, 18, 0, 0, 354, 356, 1, 0, 0, 0, 355, 350, 1, 0, 0, 0, 356, 359, 1, 0, 0, 0, 357, 355, 1, 0, 0, 0, 357, 358, 1, 0, 0, 0, 358, 19, 1, 0, 0, 0, 359, 357, 1, 0, 0, 0, 29, 23, 38, 41, 57, 60, 65, 71, 78, 91, 96, 100, 104, 112, 116, 144, 150, 163, 172, 175, 178, 197, 200, 262, 324, 326, 333, 338, 344, 357] \ No newline at end of file diff --git a/Compiler/gen/CGrammar.tokens b/Compiler/gen/CGrammar.tokens deleted file mode 100644 index b6c3179..0000000 --- a/Compiler/gen/CGrammar.tokens +++ /dev/null @@ -1,116 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -T__27=28 -T__28=29 -T__29=30 -T__30=31 -T__31=32 -T__32=33 -T__33=34 -T__34=35 -T__35=36 -T__36=37 -T__37=38 -T__38=39 -T__39=40 -T__40=41 -T__41=42 -T__42=43 -T__43=44 -T__44=45 -T__45=46 -T__46=47 -T__47=48 -T__48=49 -T__49=50 -T__50=51 -T__51=52 -T__52=53 -T__53=54 -HEX=55 -ID=56 -INT=57 -WS=58 -COMMENT=59 -DIRECTIVE=60 -LETTER=61 -STRING=62 -'('=1 -','=2 -')'=3 -';'=4 -'{'=5 -'}'=6 -'return'=7 -'if'=8 -'else'=9 -'for'=10 -'while'=11 -'do'=12 -'break'=13 -'continue'=14 -'='=15 -'new'=16 -'['=17 -']'=18 -'*'=19 -'&'=20 -'!'=21 -'~'=22 -'++'=23 -'--'=24 -'/'=25 -'%'=26 -'+'=27 -'-'=28 -'<'=29 -'>'=30 -'<='=31 -'>='=32 -'=='=33 -'!='=34 -'|'=35 -'^'=36 -'<<'=37 -'>>'=38 -'&&'=39 -'||'=40 -'*='=41 -'/='=42 -'%='=43 -'+='=44 -'-='=45 -'&='=46 -'|='=47 -'^='=48 -'<<='=49 -'>>='=50 -'?'=51 -':'=52 -'int'=53 -'char'=54 diff --git a/Compiler/gen/CGrammarBaseVisitor.cs b/Compiler/gen/CGrammarBaseVisitor.cs deleted file mode 100644 index a9dde6b..0000000 --- a/Compiler/gen/CGrammarBaseVisitor.cs +++ /dev/null @@ -1,781 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.13.2 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using IToken = Antlr4.Runtime.IToken; -using ParserRuleContext = Antlr4.Runtime.ParserRuleContext; - -/// -/// This class provides an empty implementation of , -/// which can be extended to create a visitor which only needs to handle a subset -/// of the available methods. -/// -/// The return type of the visit operation. -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] -[System.Diagnostics.DebuggerNonUserCode] -[System.CLSCompliant(false)] -public partial class CGrammarBaseVisitor : AbstractParseTreeVisitor, ICGrammarVisitor { - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitProgram([NotNull] CGrammarParser.ProgramContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the functionPrototype - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitFunctionPrototype([NotNull] CGrammarParser.FunctionPrototypeContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the functionDefinition - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitFunctionDefinition([NotNull] CGrammarParser.FunctionDefinitionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBlock([NotNull] CGrammarParser.BlockContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBlock_item([NotNull] CGrammarParser.Block_itemContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the returnStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the ifStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIfStatement([NotNull] CGrammarParser.IfStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the forExprStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitForExprStatement([NotNull] CGrammarParser.ForExprStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the forDeclStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitForDeclStatement([NotNull] CGrammarParser.ForDeclStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the whileStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitWhileStatement([NotNull] CGrammarParser.WhileStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the doWhileStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitDoWhileStatement([NotNull] CGrammarParser.DoWhileStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the breakStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBreakStatement([NotNull] CGrammarParser.BreakStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the continueStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitContinueStatement([NotNull] CGrammarParser.ContinueStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the expressionStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitExpressionStatement([NotNull] CGrammarParser.ExpressionStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the blockStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBlockStatement([NotNull] CGrammarParser.BlockStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the nullStatement - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitNullStatement([NotNull] CGrammarParser.NullStatementContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the variableDeclaration - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitVariableDeclaration([NotNull] CGrammarParser.VariableDeclarationContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the addressOfExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitAddressOfExpression([NotNull] CGrammarParser.AddressOfExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundSubtractExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundSubtractExpression([NotNull] CGrammarParser.CompoundSubtractExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the modulusExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the notExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the decrementPrefixExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitDecrementPrefixExpression([NotNull] CGrammarParser.DecrementPrefixExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the multiplyExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the greaterThanExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the bitwiseLeftShiftExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBitwiseLeftShiftExpression([NotNull] CGrammarParser.BitwiseLeftShiftExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the bitwiseRightShiftExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBitwiseRightShiftExpression([NotNull] CGrammarParser.BitwiseRightShiftExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the variableExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitVariableExpression([NotNull] CGrammarParser.VariableExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundDivideExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundDivideExpression([NotNull] CGrammarParser.CompoundDivideExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the parenthesizedExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundAddExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundAddExpression([NotNull] CGrammarParser.CompoundAddExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundMultiplyExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundMultiplyExpression([NotNull] CGrammarParser.CompoundMultiplyExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundBitwiseXorExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundBitwiseXorExpression([NotNull] CGrammarParser.CompoundBitwiseXorExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the bitwiseAndExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the lessThanExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the logicalAndExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the indexExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIndexExpression([NotNull] CGrammarParser.IndexExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the invertExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the dereferenceExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitDereferenceExpression([NotNull] CGrammarParser.DereferenceExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the equalExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the bitwiseXorExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the arrayExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitArrayExpression([NotNull] CGrammarParser.ArrayExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the constantExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundModulusExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundModulusExpression([NotNull] CGrammarParser.CompoundModulusExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the lessThanOrEqualExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the incrementPostfixExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIncrementPostfixExpression([NotNull] CGrammarParser.IncrementPostfixExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundBitwiseRightShiftExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundBitwiseRightShiftExpression([NotNull] CGrammarParser.CompoundBitwiseRightShiftExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the assignmentExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitAssignmentExpression([NotNull] CGrammarParser.AssignmentExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the notEqualExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundBitwiseAndExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundBitwiseAndExpression([NotNull] CGrammarParser.CompoundBitwiseAndExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the logicalOrExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the incrementPrefixExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIncrementPrefixExpression([NotNull] CGrammarParser.IncrementPrefixExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the greaterThanOrEqualExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the divideExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the bitwiseOrExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the callExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCallExpression([NotNull] CGrammarParser.CallExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the addExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the subtractExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundBitwiseOrExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundBitwiseOrExpression([NotNull] CGrammarParser.CompoundBitwiseOrExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the decrementPostfixExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitDecrementPostfixExpression([NotNull] CGrammarParser.DecrementPostfixExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the ternaryExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitTernaryExpression([NotNull] CGrammarParser.TernaryExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the compoundBitwiseLeftShiftExpression - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCompoundBitwiseLeftShiftExpression([NotNull] CGrammarParser.CompoundBitwiseLeftShiftExpressionContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the intConstant - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIntConstant([NotNull] CGrammarParser.IntConstantContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the hexConstant - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitHexConstant([NotNull] CGrammarParser.HexConstantContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the charConstant - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitCharConstant([NotNull] CGrammarParser.CharConstantContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the stringConstant - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitStringConstant([NotNull] CGrammarParser.StringConstantContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitType([NotNull] CGrammarParser.TypeContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the indexerTarget - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitIndexerTarget([NotNull] CGrammarParser.IndexerTargetContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by the variableTarget - /// labeled alternative in . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitVariableTarget([NotNull] CGrammarParser.VariableTargetContext context) { return VisitChildren(context); } -} diff --git a/Compiler/gen/CGrammarLexer.cs b/Compiler/gen/CGrammarLexer.cs deleted file mode 100644 index 368ad2c..0000000 --- a/Compiler/gen/CGrammarLexer.cs +++ /dev/null @@ -1,238 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.13.2 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using System; -using System.IO; -using System.Text; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] -[System.CLSCompliant(false)] -public partial class CGrammarLexer : Lexer { - protected static DFA[] decisionToDFA; - protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); - public const int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, - T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, - T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, - T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, - T__38=39, T__39=40, T__40=41, T__41=42, T__42=43, T__43=44, T__44=45, - T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, T__50=51, T__51=52, - T__52=53, T__53=54, HEX=55, ID=56, INT=57, WS=58, COMMENT=59, DIRECTIVE=60, - LETTER=61, STRING=62; - public static string[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static string[] modeNames = { - "DEFAULT_MODE" - }; - - public static readonly string[] ruleNames = { - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", - "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", - "T__25", "T__26", "T__27", "T__28", "T__29", "T__30", "T__31", "T__32", - "T__33", "T__34", "T__35", "T__36", "T__37", "T__38", "T__39", "T__40", - "T__41", "T__42", "T__43", "T__44", "T__45", "T__46", "T__47", "T__48", - "T__49", "T__50", "T__51", "T__52", "T__53", "HEX", "ID", "INT", "WS", - "COMMENT", "DIRECTIVE", "LETTER", "STRING" - }; - - - public CGrammarLexer(ICharStream input) - : this(input, Console.Out, Console.Error) { } - - public CGrammarLexer(ICharStream input, TextWriter output, TextWriter errorOutput) - : base(input, output, errorOutput) - { - Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); - } - - private static readonly string[] _LiteralNames = { - null, "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'", "'else'", - "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'new'", "'['", - "']'", "'*'", "'&'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", - "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", - "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", - "'|='", "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" - }; - private static readonly string[] _SymbolicNames = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT", - "DIRECTIVE", "LETTER", "STRING" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "CGrammar.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override string[] ChannelNames { get { return channelNames; } } - - public override string[] ModeNames { get { return modeNames; } } - - public override int[] SerializedAtn { get { return _serializedATN; } } - - static CGrammarLexer() { - decisionToDFA = new DFA[_ATN.NumberOfDecisions]; - for (int i = 0; i < _ATN.NumberOfDecisions; i++) { - decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); - } - } - private static int[] _serializedATN = { - 4,0,62,355,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, - 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, - 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, - 7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28, - 7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,2,35, - 7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,39,7,39,2,40,7,40,2,41,7,41,2,42, - 7,42,2,43,7,43,2,44,7,44,2,45,7,45,2,46,7,46,2,47,7,47,2,48,7,48,2,49, - 7,49,2,50,7,50,2,51,7,51,2,52,7,52,2,53,7,53,2,54,7,54,2,55,7,55,2,56, - 7,56,2,57,7,57,2,58,7,58,2,59,7,59,2,60,7,60,2,61,7,61,1,0,1,0,1,1,1,1, - 1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1, - 7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1, - 11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1, - 13,1,13,1,13,1,13,1,14,1,14,1,15,1,15,1,15,1,15,1,16,1,16,1,17,1,17,1, - 18,1,18,1,19,1,19,1,20,1,20,1,21,1,21,1,22,1,22,1,22,1,23,1,23,1,23,1, - 24,1,24,1,25,1,25,1,26,1,26,1,27,1,27,1,28,1,28,1,29,1,29,1,30,1,30,1, - 30,1,31,1,31,1,31,1,32,1,32,1,32,1,33,1,33,1,33,1,34,1,34,1,35,1,35,1, - 36,1,36,1,36,1,37,1,37,1,37,1,38,1,38,1,38,1,39,1,39,1,39,1,40,1,40,1, - 40,1,41,1,41,1,41,1,42,1,42,1,42,1,43,1,43,1,43,1,44,1,44,1,44,1,45,1, - 45,1,45,1,46,1,46,1,46,1,47,1,47,1,47,1,48,1,48,1,48,1,48,1,49,1,49,1, - 49,1,49,1,50,1,50,1,51,1,51,1,52,1,52,1,52,1,52,1,53,1,53,1,53,1,53,1, - 53,1,54,1,54,1,54,1,54,4,54,294,8,54,11,54,12,54,295,1,55,1,55,5,55,300, - 8,55,10,55,12,55,303,9,55,1,56,4,56,306,8,56,11,56,12,56,307,1,57,4,57, - 311,8,57,11,57,12,57,312,1,57,1,57,1,58,1,58,1,58,1,58,5,58,321,8,58,10, - 58,12,58,324,9,58,1,58,3,58,327,8,58,1,58,1,58,1,59,1,59,5,59,333,8,59, - 10,59,12,59,336,9,59,1,59,3,59,339,8,59,1,59,1,59,1,60,1,60,1,60,1,60, - 1,61,1,61,5,61,349,8,61,10,61,12,61,352,9,61,1,61,1,61,3,322,334,350,0, - 62,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27, - 14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51, - 26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75, - 38,77,39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,99, - 50,101,51,103,52,105,53,107,54,109,55,111,56,113,57,115,58,117,59,119, - 60,121,61,123,62,1,0,6,3,0,48,57,65,70,97,102,3,0,65,90,95,95,97,122,4, - 0,48,57,65,90,95,95,97,122,1,0,48,57,3,0,9,10,13,13,32,32,1,1,10,10,361, - 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0, - 0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23, - 1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0, - 0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45, - 1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0, - 0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67, - 1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,0, - 0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,0,89, - 1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,0,99,1,0,0, - 0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,107,1,0,0,0,0,109,1,0,0, - 0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,0,117,1,0,0,0,0,119,1,0,0, - 0,0,121,1,0,0,0,0,123,1,0,0,0,1,125,1,0,0,0,3,127,1,0,0,0,5,129,1,0,0, - 0,7,131,1,0,0,0,9,133,1,0,0,0,11,135,1,0,0,0,13,137,1,0,0,0,15,144,1,0, - 0,0,17,147,1,0,0,0,19,152,1,0,0,0,21,156,1,0,0,0,23,162,1,0,0,0,25,165, - 1,0,0,0,27,171,1,0,0,0,29,180,1,0,0,0,31,182,1,0,0,0,33,186,1,0,0,0,35, - 188,1,0,0,0,37,190,1,0,0,0,39,192,1,0,0,0,41,194,1,0,0,0,43,196,1,0,0, - 0,45,198,1,0,0,0,47,201,1,0,0,0,49,204,1,0,0,0,51,206,1,0,0,0,53,208,1, - 0,0,0,55,210,1,0,0,0,57,212,1,0,0,0,59,214,1,0,0,0,61,216,1,0,0,0,63,219, - 1,0,0,0,65,222,1,0,0,0,67,225,1,0,0,0,69,228,1,0,0,0,71,230,1,0,0,0,73, - 232,1,0,0,0,75,235,1,0,0,0,77,238,1,0,0,0,79,241,1,0,0,0,81,244,1,0,0, - 0,83,247,1,0,0,0,85,250,1,0,0,0,87,253,1,0,0,0,89,256,1,0,0,0,91,259,1, - 0,0,0,93,262,1,0,0,0,95,265,1,0,0,0,97,268,1,0,0,0,99,272,1,0,0,0,101, - 276,1,0,0,0,103,278,1,0,0,0,105,280,1,0,0,0,107,284,1,0,0,0,109,289,1, - 0,0,0,111,297,1,0,0,0,113,305,1,0,0,0,115,310,1,0,0,0,117,316,1,0,0,0, - 119,330,1,0,0,0,121,342,1,0,0,0,123,346,1,0,0,0,125,126,5,40,0,0,126,2, - 1,0,0,0,127,128,5,44,0,0,128,4,1,0,0,0,129,130,5,41,0,0,130,6,1,0,0,0, - 131,132,5,59,0,0,132,8,1,0,0,0,133,134,5,123,0,0,134,10,1,0,0,0,135,136, - 5,125,0,0,136,12,1,0,0,0,137,138,5,114,0,0,138,139,5,101,0,0,139,140,5, - 116,0,0,140,141,5,117,0,0,141,142,5,114,0,0,142,143,5,110,0,0,143,14,1, - 0,0,0,144,145,5,105,0,0,145,146,5,102,0,0,146,16,1,0,0,0,147,148,5,101, - 0,0,148,149,5,108,0,0,149,150,5,115,0,0,150,151,5,101,0,0,151,18,1,0,0, - 0,152,153,5,102,0,0,153,154,5,111,0,0,154,155,5,114,0,0,155,20,1,0,0,0, - 156,157,5,119,0,0,157,158,5,104,0,0,158,159,5,105,0,0,159,160,5,108,0, - 0,160,161,5,101,0,0,161,22,1,0,0,0,162,163,5,100,0,0,163,164,5,111,0,0, - 164,24,1,0,0,0,165,166,5,98,0,0,166,167,5,114,0,0,167,168,5,101,0,0,168, - 169,5,97,0,0,169,170,5,107,0,0,170,26,1,0,0,0,171,172,5,99,0,0,172,173, - 5,111,0,0,173,174,5,110,0,0,174,175,5,116,0,0,175,176,5,105,0,0,176,177, - 5,110,0,0,177,178,5,117,0,0,178,179,5,101,0,0,179,28,1,0,0,0,180,181,5, - 61,0,0,181,30,1,0,0,0,182,183,5,110,0,0,183,184,5,101,0,0,184,185,5,119, - 0,0,185,32,1,0,0,0,186,187,5,91,0,0,187,34,1,0,0,0,188,189,5,93,0,0,189, - 36,1,0,0,0,190,191,5,42,0,0,191,38,1,0,0,0,192,193,5,38,0,0,193,40,1,0, - 0,0,194,195,5,33,0,0,195,42,1,0,0,0,196,197,5,126,0,0,197,44,1,0,0,0,198, - 199,5,43,0,0,199,200,5,43,0,0,200,46,1,0,0,0,201,202,5,45,0,0,202,203, - 5,45,0,0,203,48,1,0,0,0,204,205,5,47,0,0,205,50,1,0,0,0,206,207,5,37,0, - 0,207,52,1,0,0,0,208,209,5,43,0,0,209,54,1,0,0,0,210,211,5,45,0,0,211, - 56,1,0,0,0,212,213,5,60,0,0,213,58,1,0,0,0,214,215,5,62,0,0,215,60,1,0, - 0,0,216,217,5,60,0,0,217,218,5,61,0,0,218,62,1,0,0,0,219,220,5,62,0,0, - 220,221,5,61,0,0,221,64,1,0,0,0,222,223,5,61,0,0,223,224,5,61,0,0,224, - 66,1,0,0,0,225,226,5,33,0,0,226,227,5,61,0,0,227,68,1,0,0,0,228,229,5, - 124,0,0,229,70,1,0,0,0,230,231,5,94,0,0,231,72,1,0,0,0,232,233,5,60,0, - 0,233,234,5,60,0,0,234,74,1,0,0,0,235,236,5,62,0,0,236,237,5,62,0,0,237, - 76,1,0,0,0,238,239,5,38,0,0,239,240,5,38,0,0,240,78,1,0,0,0,241,242,5, - 124,0,0,242,243,5,124,0,0,243,80,1,0,0,0,244,245,5,42,0,0,245,246,5,61, - 0,0,246,82,1,0,0,0,247,248,5,47,0,0,248,249,5,61,0,0,249,84,1,0,0,0,250, - 251,5,37,0,0,251,252,5,61,0,0,252,86,1,0,0,0,253,254,5,43,0,0,254,255, - 5,61,0,0,255,88,1,0,0,0,256,257,5,45,0,0,257,258,5,61,0,0,258,90,1,0,0, - 0,259,260,5,38,0,0,260,261,5,61,0,0,261,92,1,0,0,0,262,263,5,124,0,0,263, - 264,5,61,0,0,264,94,1,0,0,0,265,266,5,94,0,0,266,267,5,61,0,0,267,96,1, - 0,0,0,268,269,5,60,0,0,269,270,5,60,0,0,270,271,5,61,0,0,271,98,1,0,0, - 0,272,273,5,62,0,0,273,274,5,62,0,0,274,275,5,61,0,0,275,100,1,0,0,0,276, - 277,5,63,0,0,277,102,1,0,0,0,278,279,5,58,0,0,279,104,1,0,0,0,280,281, - 5,105,0,0,281,282,5,110,0,0,282,283,5,116,0,0,283,106,1,0,0,0,284,285, - 5,99,0,0,285,286,5,104,0,0,286,287,5,97,0,0,287,288,5,114,0,0,288,108, - 1,0,0,0,289,290,5,48,0,0,290,291,5,120,0,0,291,293,1,0,0,0,292,294,7,0, - 0,0,293,292,1,0,0,0,294,295,1,0,0,0,295,293,1,0,0,0,295,296,1,0,0,0,296, - 110,1,0,0,0,297,301,7,1,0,0,298,300,7,2,0,0,299,298,1,0,0,0,300,303,1, - 0,0,0,301,299,1,0,0,0,301,302,1,0,0,0,302,112,1,0,0,0,303,301,1,0,0,0, - 304,306,7,3,0,0,305,304,1,0,0,0,306,307,1,0,0,0,307,305,1,0,0,0,307,308, - 1,0,0,0,308,114,1,0,0,0,309,311,7,4,0,0,310,309,1,0,0,0,311,312,1,0,0, - 0,312,310,1,0,0,0,312,313,1,0,0,0,313,314,1,0,0,0,314,315,6,57,0,0,315, - 116,1,0,0,0,316,317,5,47,0,0,317,318,5,47,0,0,318,322,1,0,0,0,319,321, - 9,0,0,0,320,319,1,0,0,0,321,324,1,0,0,0,322,323,1,0,0,0,322,320,1,0,0, - 0,323,326,1,0,0,0,324,322,1,0,0,0,325,327,7,5,0,0,326,325,1,0,0,0,327, - 328,1,0,0,0,328,329,6,58,1,0,329,118,1,0,0,0,330,334,5,35,0,0,331,333, - 9,0,0,0,332,331,1,0,0,0,333,336,1,0,0,0,334,335,1,0,0,0,334,332,1,0,0, - 0,335,338,1,0,0,0,336,334,1,0,0,0,337,339,7,5,0,0,338,337,1,0,0,0,339, - 340,1,0,0,0,340,341,6,59,1,0,341,120,1,0,0,0,342,343,5,39,0,0,343,344, - 9,0,0,0,344,345,5,39,0,0,345,122,1,0,0,0,346,350,5,34,0,0,347,349,9,0, - 0,0,348,347,1,0,0,0,349,352,1,0,0,0,350,351,1,0,0,0,350,348,1,0,0,0,351, - 353,1,0,0,0,352,350,1,0,0,0,353,354,5,34,0,0,354,124,1,0,0,0,10,0,295, - 301,307,312,322,326,334,338,350,2,6,0,0,0,1,0 - }; - - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN); - - -} diff --git a/Compiler/gen/CGrammarLexer.interp b/Compiler/gen/CGrammarLexer.interp deleted file mode 100644 index 4aea344..0000000 --- a/Compiler/gen/CGrammarLexer.interp +++ /dev/null @@ -1,203 +0,0 @@ -token literal names: -null -'(' -',' -')' -';' -'{' -'}' -'return' -'if' -'else' -'for' -'while' -'do' -'break' -'continue' -'=' -'new' -'[' -']' -'*' -'&' -'!' -'~' -'++' -'--' -'/' -'%' -'+' -'-' -'<' -'>' -'<=' -'>=' -'==' -'!=' -'|' -'^' -'<<' -'>>' -'&&' -'||' -'*=' -'/=' -'%=' -'+=' -'-=' -'&=' -'|=' -'^=' -'<<=' -'>>=' -'?' -':' -'int' -'char' -null -null -null -null -null -null -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -HEX -ID -INT -WS -COMMENT -DIRECTIVE -LETTER -STRING - -rule names: -T__0 -T__1 -T__2 -T__3 -T__4 -T__5 -T__6 -T__7 -T__8 -T__9 -T__10 -T__11 -T__12 -T__13 -T__14 -T__15 -T__16 -T__17 -T__18 -T__19 -T__20 -T__21 -T__22 -T__23 -T__24 -T__25 -T__26 -T__27 -T__28 -T__29 -T__30 -T__31 -T__32 -T__33 -T__34 -T__35 -T__36 -T__37 -T__38 -T__39 -T__40 -T__41 -T__42 -T__43 -T__44 -T__45 -T__46 -T__47 -T__48 -T__49 -T__50 -T__51 -T__52 -T__53 -HEX -ID -INT -WS -COMMENT -DIRECTIVE -LETTER -STRING - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 62, 355, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 35, 1, 35, 1, 36, 1, 36, 1, 36, 1, 37, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 41, 1, 41, 1, 41, 1, 42, 1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 44, 1, 44, 1, 44, 1, 45, 1, 45, 1, 45, 1, 46, 1, 46, 1, 46, 1, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 1, 49, 1, 49, 1, 50, 1, 50, 1, 51, 1, 51, 1, 52, 1, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 54, 4, 54, 294, 8, 54, 11, 54, 12, 54, 295, 1, 55, 1, 55, 5, 55, 300, 8, 55, 10, 55, 12, 55, 303, 9, 55, 1, 56, 4, 56, 306, 8, 56, 11, 56, 12, 56, 307, 1, 57, 4, 57, 311, 8, 57, 11, 57, 12, 57, 312, 1, 57, 1, 57, 1, 58, 1, 58, 1, 58, 1, 58, 5, 58, 321, 8, 58, 10, 58, 12, 58, 324, 9, 58, 1, 58, 3, 58, 327, 8, 58, 1, 58, 1, 58, 1, 59, 1, 59, 5, 59, 333, 8, 59, 10, 59, 12, 59, 336, 9, 59, 1, 59, 3, 59, 339, 8, 59, 1, 59, 1, 59, 1, 60, 1, 60, 1, 60, 1, 60, 1, 61, 1, 61, 5, 61, 349, 8, 61, 10, 61, 12, 61, 352, 9, 61, 1, 61, 1, 61, 3, 322, 334, 350, 0, 62, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 35, 71, 36, 73, 37, 75, 38, 77, 39, 79, 40, 81, 41, 83, 42, 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 48, 97, 49, 99, 50, 101, 51, 103, 52, 105, 53, 107, 54, 109, 55, 111, 56, 113, 57, 115, 58, 117, 59, 119, 60, 121, 61, 123, 62, 1, 0, 6, 3, 0, 48, 57, 65, 70, 97, 102, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 1, 1, 10, 10, 361, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 95, 1, 0, 0, 0, 0, 97, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 103, 1, 0, 0, 0, 0, 105, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 0, 115, 1, 0, 0, 0, 0, 117, 1, 0, 0, 0, 0, 119, 1, 0, 0, 0, 0, 121, 1, 0, 0, 0, 0, 123, 1, 0, 0, 0, 1, 125, 1, 0, 0, 0, 3, 127, 1, 0, 0, 0, 5, 129, 1, 0, 0, 0, 7, 131, 1, 0, 0, 0, 9, 133, 1, 0, 0, 0, 11, 135, 1, 0, 0, 0, 13, 137, 1, 0, 0, 0, 15, 144, 1, 0, 0, 0, 17, 147, 1, 0, 0, 0, 19, 152, 1, 0, 0, 0, 21, 156, 1, 0, 0, 0, 23, 162, 1, 0, 0, 0, 25, 165, 1, 0, 0, 0, 27, 171, 1, 0, 0, 0, 29, 180, 1, 0, 0, 0, 31, 182, 1, 0, 0, 0, 33, 186, 1, 0, 0, 0, 35, 188, 1, 0, 0, 0, 37, 190, 1, 0, 0, 0, 39, 192, 1, 0, 0, 0, 41, 194, 1, 0, 0, 0, 43, 196, 1, 0, 0, 0, 45, 198, 1, 0, 0, 0, 47, 201, 1, 0, 0, 0, 49, 204, 1, 0, 0, 0, 51, 206, 1, 0, 0, 0, 53, 208, 1, 0, 0, 0, 55, 210, 1, 0, 0, 0, 57, 212, 1, 0, 0, 0, 59, 214, 1, 0, 0, 0, 61, 216, 1, 0, 0, 0, 63, 219, 1, 0, 0, 0, 65, 222, 1, 0, 0, 0, 67, 225, 1, 0, 0, 0, 69, 228, 1, 0, 0, 0, 71, 230, 1, 0, 0, 0, 73, 232, 1, 0, 0, 0, 75, 235, 1, 0, 0, 0, 77, 238, 1, 0, 0, 0, 79, 241, 1, 0, 0, 0, 81, 244, 1, 0, 0, 0, 83, 247, 1, 0, 0, 0, 85, 250, 1, 0, 0, 0, 87, 253, 1, 0, 0, 0, 89, 256, 1, 0, 0, 0, 91, 259, 1, 0, 0, 0, 93, 262, 1, 0, 0, 0, 95, 265, 1, 0, 0, 0, 97, 268, 1, 0, 0, 0, 99, 272, 1, 0, 0, 0, 101, 276, 1, 0, 0, 0, 103, 278, 1, 0, 0, 0, 105, 280, 1, 0, 0, 0, 107, 284, 1, 0, 0, 0, 109, 289, 1, 0, 0, 0, 111, 297, 1, 0, 0, 0, 113, 305, 1, 0, 0, 0, 115, 310, 1, 0, 0, 0, 117, 316, 1, 0, 0, 0, 119, 330, 1, 0, 0, 0, 121, 342, 1, 0, 0, 0, 123, 346, 1, 0, 0, 0, 125, 126, 5, 40, 0, 0, 126, 2, 1, 0, 0, 0, 127, 128, 5, 44, 0, 0, 128, 4, 1, 0, 0, 0, 129, 130, 5, 41, 0, 0, 130, 6, 1, 0, 0, 0, 131, 132, 5, 59, 0, 0, 132, 8, 1, 0, 0, 0, 133, 134, 5, 123, 0, 0, 134, 10, 1, 0, 0, 0, 135, 136, 5, 125, 0, 0, 136, 12, 1, 0, 0, 0, 137, 138, 5, 114, 0, 0, 138, 139, 5, 101, 0, 0, 139, 140, 5, 116, 0, 0, 140, 141, 5, 117, 0, 0, 141, 142, 5, 114, 0, 0, 142, 143, 5, 110, 0, 0, 143, 14, 1, 0, 0, 0, 144, 145, 5, 105, 0, 0, 145, 146, 5, 102, 0, 0, 146, 16, 1, 0, 0, 0, 147, 148, 5, 101, 0, 0, 148, 149, 5, 108, 0, 0, 149, 150, 5, 115, 0, 0, 150, 151, 5, 101, 0, 0, 151, 18, 1, 0, 0, 0, 152, 153, 5, 102, 0, 0, 153, 154, 5, 111, 0, 0, 154, 155, 5, 114, 0, 0, 155, 20, 1, 0, 0, 0, 156, 157, 5, 119, 0, 0, 157, 158, 5, 104, 0, 0, 158, 159, 5, 105, 0, 0, 159, 160, 5, 108, 0, 0, 160, 161, 5, 101, 0, 0, 161, 22, 1, 0, 0, 0, 162, 163, 5, 100, 0, 0, 163, 164, 5, 111, 0, 0, 164, 24, 1, 0, 0, 0, 165, 166, 5, 98, 0, 0, 166, 167, 5, 114, 0, 0, 167, 168, 5, 101, 0, 0, 168, 169, 5, 97, 0, 0, 169, 170, 5, 107, 0, 0, 170, 26, 1, 0, 0, 0, 171, 172, 5, 99, 0, 0, 172, 173, 5, 111, 0, 0, 173, 174, 5, 110, 0, 0, 174, 175, 5, 116, 0, 0, 175, 176, 5, 105, 0, 0, 176, 177, 5, 110, 0, 0, 177, 178, 5, 117, 0, 0, 178, 179, 5, 101, 0, 0, 179, 28, 1, 0, 0, 0, 180, 181, 5, 61, 0, 0, 181, 30, 1, 0, 0, 0, 182, 183, 5, 110, 0, 0, 183, 184, 5, 101, 0, 0, 184, 185, 5, 119, 0, 0, 185, 32, 1, 0, 0, 0, 186, 187, 5, 91, 0, 0, 187, 34, 1, 0, 0, 0, 188, 189, 5, 93, 0, 0, 189, 36, 1, 0, 0, 0, 190, 191, 5, 42, 0, 0, 191, 38, 1, 0, 0, 0, 192, 193, 5, 38, 0, 0, 193, 40, 1, 0, 0, 0, 194, 195, 5, 33, 0, 0, 195, 42, 1, 0, 0, 0, 196, 197, 5, 126, 0, 0, 197, 44, 1, 0, 0, 0, 198, 199, 5, 43, 0, 0, 199, 200, 5, 43, 0, 0, 200, 46, 1, 0, 0, 0, 201, 202, 5, 45, 0, 0, 202, 203, 5, 45, 0, 0, 203, 48, 1, 0, 0, 0, 204, 205, 5, 47, 0, 0, 205, 50, 1, 0, 0, 0, 206, 207, 5, 37, 0, 0, 207, 52, 1, 0, 0, 0, 208, 209, 5, 43, 0, 0, 209, 54, 1, 0, 0, 0, 210, 211, 5, 45, 0, 0, 211, 56, 1, 0, 0, 0, 212, 213, 5, 60, 0, 0, 213, 58, 1, 0, 0, 0, 214, 215, 5, 62, 0, 0, 215, 60, 1, 0, 0, 0, 216, 217, 5, 60, 0, 0, 217, 218, 5, 61, 0, 0, 218, 62, 1, 0, 0, 0, 219, 220, 5, 62, 0, 0, 220, 221, 5, 61, 0, 0, 221, 64, 1, 0, 0, 0, 222, 223, 5, 61, 0, 0, 223, 224, 5, 61, 0, 0, 224, 66, 1, 0, 0, 0, 225, 226, 5, 33, 0, 0, 226, 227, 5, 61, 0, 0, 227, 68, 1, 0, 0, 0, 228, 229, 5, 124, 0, 0, 229, 70, 1, 0, 0, 0, 230, 231, 5, 94, 0, 0, 231, 72, 1, 0, 0, 0, 232, 233, 5, 60, 0, 0, 233, 234, 5, 60, 0, 0, 234, 74, 1, 0, 0, 0, 235, 236, 5, 62, 0, 0, 236, 237, 5, 62, 0, 0, 237, 76, 1, 0, 0, 0, 238, 239, 5, 38, 0, 0, 239, 240, 5, 38, 0, 0, 240, 78, 1, 0, 0, 0, 241, 242, 5, 124, 0, 0, 242, 243, 5, 124, 0, 0, 243, 80, 1, 0, 0, 0, 244, 245, 5, 42, 0, 0, 245, 246, 5, 61, 0, 0, 246, 82, 1, 0, 0, 0, 247, 248, 5, 47, 0, 0, 248, 249, 5, 61, 0, 0, 249, 84, 1, 0, 0, 0, 250, 251, 5, 37, 0, 0, 251, 252, 5, 61, 0, 0, 252, 86, 1, 0, 0, 0, 253, 254, 5, 43, 0, 0, 254, 255, 5, 61, 0, 0, 255, 88, 1, 0, 0, 0, 256, 257, 5, 45, 0, 0, 257, 258, 5, 61, 0, 0, 258, 90, 1, 0, 0, 0, 259, 260, 5, 38, 0, 0, 260, 261, 5, 61, 0, 0, 261, 92, 1, 0, 0, 0, 262, 263, 5, 124, 0, 0, 263, 264, 5, 61, 0, 0, 264, 94, 1, 0, 0, 0, 265, 266, 5, 94, 0, 0, 266, 267, 5, 61, 0, 0, 267, 96, 1, 0, 0, 0, 268, 269, 5, 60, 0, 0, 269, 270, 5, 60, 0, 0, 270, 271, 5, 61, 0, 0, 271, 98, 1, 0, 0, 0, 272, 273, 5, 62, 0, 0, 273, 274, 5, 62, 0, 0, 274, 275, 5, 61, 0, 0, 275, 100, 1, 0, 0, 0, 276, 277, 5, 63, 0, 0, 277, 102, 1, 0, 0, 0, 278, 279, 5, 58, 0, 0, 279, 104, 1, 0, 0, 0, 280, 281, 5, 105, 0, 0, 281, 282, 5, 110, 0, 0, 282, 283, 5, 116, 0, 0, 283, 106, 1, 0, 0, 0, 284, 285, 5, 99, 0, 0, 285, 286, 5, 104, 0, 0, 286, 287, 5, 97, 0, 0, 287, 288, 5, 114, 0, 0, 288, 108, 1, 0, 0, 0, 289, 290, 5, 48, 0, 0, 290, 291, 5, 120, 0, 0, 291, 293, 1, 0, 0, 0, 292, 294, 7, 0, 0, 0, 293, 292, 1, 0, 0, 0, 294, 295, 1, 0, 0, 0, 295, 293, 1, 0, 0, 0, 295, 296, 1, 0, 0, 0, 296, 110, 1, 0, 0, 0, 297, 301, 7, 1, 0, 0, 298, 300, 7, 2, 0, 0, 299, 298, 1, 0, 0, 0, 300, 303, 1, 0, 0, 0, 301, 299, 1, 0, 0, 0, 301, 302, 1, 0, 0, 0, 302, 112, 1, 0, 0, 0, 303, 301, 1, 0, 0, 0, 304, 306, 7, 3, 0, 0, 305, 304, 1, 0, 0, 0, 306, 307, 1, 0, 0, 0, 307, 305, 1, 0, 0, 0, 307, 308, 1, 0, 0, 0, 308, 114, 1, 0, 0, 0, 309, 311, 7, 4, 0, 0, 310, 309, 1, 0, 0, 0, 311, 312, 1, 0, 0, 0, 312, 310, 1, 0, 0, 0, 312, 313, 1, 0, 0, 0, 313, 314, 1, 0, 0, 0, 314, 315, 6, 57, 0, 0, 315, 116, 1, 0, 0, 0, 316, 317, 5, 47, 0, 0, 317, 318, 5, 47, 0, 0, 318, 322, 1, 0, 0, 0, 319, 321, 9, 0, 0, 0, 320, 319, 1, 0, 0, 0, 321, 324, 1, 0, 0, 0, 322, 323, 1, 0, 0, 0, 322, 320, 1, 0, 0, 0, 323, 326, 1, 0, 0, 0, 324, 322, 1, 0, 0, 0, 325, 327, 7, 5, 0, 0, 326, 325, 1, 0, 0, 0, 327, 328, 1, 0, 0, 0, 328, 329, 6, 58, 1, 0, 329, 118, 1, 0, 0, 0, 330, 334, 5, 35, 0, 0, 331, 333, 9, 0, 0, 0, 332, 331, 1, 0, 0, 0, 333, 336, 1, 0, 0, 0, 334, 335, 1, 0, 0, 0, 334, 332, 1, 0, 0, 0, 335, 338, 1, 0, 0, 0, 336, 334, 1, 0, 0, 0, 337, 339, 7, 5, 0, 0, 338, 337, 1, 0, 0, 0, 339, 340, 1, 0, 0, 0, 340, 341, 6, 59, 1, 0, 341, 120, 1, 0, 0, 0, 342, 343, 5, 39, 0, 0, 343, 344, 9, 0, 0, 0, 344, 345, 5, 39, 0, 0, 345, 122, 1, 0, 0, 0, 346, 350, 5, 34, 0, 0, 347, 349, 9, 0, 0, 0, 348, 347, 1, 0, 0, 0, 349, 352, 1, 0, 0, 0, 350, 351, 1, 0, 0, 0, 350, 348, 1, 0, 0, 0, 351, 353, 1, 0, 0, 0, 352, 350, 1, 0, 0, 0, 353, 354, 5, 34, 0, 0, 354, 124, 1, 0, 0, 0, 10, 0, 295, 301, 307, 312, 322, 326, 334, 338, 350, 2, 6, 0, 0, 0, 1, 0] \ No newline at end of file diff --git a/Compiler/gen/CGrammarLexer.tokens b/Compiler/gen/CGrammarLexer.tokens deleted file mode 100644 index b6c3179..0000000 --- a/Compiler/gen/CGrammarLexer.tokens +++ /dev/null @@ -1,116 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -T__27=28 -T__28=29 -T__29=30 -T__30=31 -T__31=32 -T__32=33 -T__33=34 -T__34=35 -T__35=36 -T__36=37 -T__37=38 -T__38=39 -T__39=40 -T__40=41 -T__41=42 -T__42=43 -T__43=44 -T__44=45 -T__45=46 -T__46=47 -T__47=48 -T__48=49 -T__49=50 -T__50=51 -T__51=52 -T__52=53 -T__53=54 -HEX=55 -ID=56 -INT=57 -WS=58 -COMMENT=59 -DIRECTIVE=60 -LETTER=61 -STRING=62 -'('=1 -','=2 -')'=3 -';'=4 -'{'=5 -'}'=6 -'return'=7 -'if'=8 -'else'=9 -'for'=10 -'while'=11 -'do'=12 -'break'=13 -'continue'=14 -'='=15 -'new'=16 -'['=17 -']'=18 -'*'=19 -'&'=20 -'!'=21 -'~'=22 -'++'=23 -'--'=24 -'/'=25 -'%'=26 -'+'=27 -'-'=28 -'<'=29 -'>'=30 -'<='=31 -'>='=32 -'=='=33 -'!='=34 -'|'=35 -'^'=36 -'<<'=37 -'>>'=38 -'&&'=39 -'||'=40 -'*='=41 -'/='=42 -'%='=43 -'+='=44 -'-='=45 -'&='=46 -'|='=47 -'^='=48 -'<<='=49 -'>>='=50 -'?'=51 -':'=52 -'int'=53 -'char'=54 diff --git a/Compiler/gen/CGrammarParser.cs b/Compiler/gen/CGrammarParser.cs deleted file mode 100644 index d090921..0000000 --- a/Compiler/gen/CGrammarParser.cs +++ /dev/null @@ -1,2821 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.13.2 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using System; -using System.IO; -using System.Text; -using System.Diagnostics; -using System.Collections.Generic; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] -[System.CLSCompliant(false)] -public partial class CGrammarParser : Parser { - protected static DFA[] decisionToDFA; - protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); - public const int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, - T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, - T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, - T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, - T__38=39, T__39=40, T__40=41, T__41=42, T__42=43, T__43=44, T__44=45, - T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, T__50=51, T__51=52, - T__52=53, T__53=54, HEX=55, ID=56, INT=57, WS=58, COMMENT=59, DIRECTIVE=60, - LETTER=61, STRING=62; - public const int - RULE_program = 0, RULE_function = 1, RULE_block = 2, RULE_block_item = 3, - RULE_statement = 4, RULE_declaration = 5, RULE_expression = 6, RULE_constant = 7, - RULE_type = 8, RULE_target = 9; - public static readonly string[] ruleNames = { - "program", "function", "block", "block_item", "statement", "declaration", - "expression", "constant", "type", "target" - }; - - private static readonly string[] _LiteralNames = { - null, "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'", "'else'", - "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'new'", "'['", - "']'", "'*'", "'&'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", - "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", - "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", - "'|='", "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" - }; - private static readonly string[] _SymbolicNames = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT", - "DIRECTIVE", "LETTER", "STRING" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "CGrammar.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override int[] SerializedAtn { get { return _serializedATN; } } - - static CGrammarParser() { - decisionToDFA = new DFA[_ATN.NumberOfDecisions]; - for (int i = 0; i < _ATN.NumberOfDecisions; i++) { - decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); - } - } - - public CGrammarParser(ITokenStream input) : this(input, Console.Out, Console.Error) { } - - public CGrammarParser(ITokenStream input, TextWriter output, TextWriter errorOutput) - : base(input, output, errorOutput) - { - Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); - } - - public partial class ProgramContext : Q1.Compiler.Context { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(CGrammarParser.Eof, 0); } - [System.Diagnostics.DebuggerNonUserCode] public FunctionContext[] function() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public FunctionContext function(int i) { - return GetRuleContext(i); - } - public ProgramContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_program; } } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitProgram(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public ProgramContext program() { - ProgramContext _localctx = new ProgramContext(Context, State); - EnterRule(_localctx, 0, RULE_program); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 21; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - do { - { - { - State = 20; - function(); - } - } - State = 23; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } while ( _la==T__52 || _la==T__53 ); - State = 25; - Match(Eof); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class FunctionContext : Q1.Compiler.Context { - public FunctionContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_function; } } - - public FunctionContext() { } - public virtual void CopyFrom(FunctionContext context) { - base.CopyFrom(context); - } - } - public partial class FunctionPrototypeContext : FunctionContext { - public TypeContext rtype; - public IToken name; - public TypeContext _type; - public IList _types = new List(); - public IToken _ID; - public IList _params = new List(); - [System.Diagnostics.DebuggerNonUserCode] public TypeContext[] type() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public TypeContext type(int i) { - return GetRuleContext(i); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] ID() { return GetTokens(CGrammarParser.ID); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID(int i) { - return GetToken(CGrammarParser.ID, i); - } - public FunctionPrototypeContext(FunctionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitFunctionPrototype(this); - else return visitor.VisitChildren(this); - } - } - public partial class FunctionDefinitionContext : FunctionContext { - public TypeContext rtype; - public IToken name; - public TypeContext _type; - public IList _types = new List(); - public IToken _ID; - public IList _params = new List(); - [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public TypeContext[] type() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public TypeContext type(int i) { - return GetRuleContext(i); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] ID() { return GetTokens(CGrammarParser.ID); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID(int i) { - return GetToken(CGrammarParser.ID, i); - } - public FunctionDefinitionContext(FunctionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitFunctionDefinition(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public FunctionContext function() { - FunctionContext _localctx = new FunctionContext(Context, State); - EnterRule(_localctx, 2, RULE_function); - int _la; - try { - State = 65; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,5,Context) ) { - case 1: - _localctx = new FunctionPrototypeContext(_localctx); - EnterOuterAlt(_localctx, 1); - { - State = 27; - ((FunctionPrototypeContext)_localctx).rtype = type(0); - State = 28; - ((FunctionPrototypeContext)_localctx).name = Match(ID); - State = 29; - Match(T__0); - State = 41; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if (_la==T__52 || _la==T__53) { - { - State = 30; - ((FunctionPrototypeContext)_localctx)._type = type(0); - ((FunctionPrototypeContext)_localctx)._types.Add(((FunctionPrototypeContext)_localctx)._type); - State = 31; - ((FunctionPrototypeContext)_localctx)._ID = Match(ID); - ((FunctionPrototypeContext)_localctx)._params.Add(((FunctionPrototypeContext)_localctx)._ID); - State = 38; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__1) { - { - { - State = 32; - Match(T__1); - State = 33; - ((FunctionPrototypeContext)_localctx)._type = type(0); - ((FunctionPrototypeContext)_localctx)._types.Add(((FunctionPrototypeContext)_localctx)._type); - State = 34; - ((FunctionPrototypeContext)_localctx)._ID = Match(ID); - ((FunctionPrototypeContext)_localctx)._params.Add(((FunctionPrototypeContext)_localctx)._ID); - } - } - State = 40; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - - State = 43; - Match(T__2); - State = 44; - Match(T__3); - } - break; - case 2: - _localctx = new FunctionDefinitionContext(_localctx); - EnterOuterAlt(_localctx, 2); - { - State = 46; - ((FunctionDefinitionContext)_localctx).rtype = type(0); - State = 47; - ((FunctionDefinitionContext)_localctx).name = Match(ID); - State = 48; - Match(T__0); - State = 60; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if (_la==T__52 || _la==T__53) { - { - State = 49; - ((FunctionDefinitionContext)_localctx)._type = type(0); - ((FunctionDefinitionContext)_localctx)._types.Add(((FunctionDefinitionContext)_localctx)._type); - State = 50; - ((FunctionDefinitionContext)_localctx)._ID = Match(ID); - ((FunctionDefinitionContext)_localctx)._params.Add(((FunctionDefinitionContext)_localctx)._ID); - State = 57; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__1) { - { - { - State = 51; - Match(T__1); - State = 52; - ((FunctionDefinitionContext)_localctx)._type = type(0); - ((FunctionDefinitionContext)_localctx)._types.Add(((FunctionDefinitionContext)_localctx)._type); - State = 53; - ((FunctionDefinitionContext)_localctx)._ID = Match(ID); - ((FunctionDefinitionContext)_localctx)._params.Add(((FunctionDefinitionContext)_localctx)._ID); - } - } - State = 59; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - - State = 62; - Match(T__2); - State = 63; - block(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class BlockContext : Q1.Compiler.Context { - [System.Diagnostics.DebuggerNonUserCode] public Block_itemContext[] block_item() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public Block_itemContext block_item(int i) { - return GetRuleContext(i); - } - public BlockContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_block; } } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBlock(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public BlockContext block() { - BlockContext _localctx = new BlockContext(Context, State); - EnterRule(_localctx, 4, RULE_block); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 67; - Match(T__4); - State = 71; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7196752204571180466L) != 0)) { - { - { - State = 68; - block_item(); - } - } - State = 73; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - State = 74; - Match(T__5); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class Block_itemContext : Q1.Compiler.Context { - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public DeclarationContext declaration() { - return GetRuleContext(0); - } - public Block_itemContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_block_item; } } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBlock_item(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public Block_itemContext block_item() { - Block_itemContext _localctx = new Block_itemContext(Context, State); - EnterRule(_localctx, 6, RULE_block_item); - try { - State = 78; - ErrorHandler.Sync(this); - switch (TokenStream.LA(1)) { - case T__0: - case T__3: - case T__4: - case T__6: - case T__7: - case T__9: - case T__10: - case T__11: - case T__12: - case T__13: - case T__15: - case T__18: - case T__19: - case T__20: - case T__21: - case T__22: - case T__23: - case HEX: - case ID: - case INT: - case LETTER: - case STRING: - EnterOuterAlt(_localctx, 1); - { - State = 76; - statement(); - } - break; - case T__52: - case T__53: - EnterOuterAlt(_localctx, 2); - { - State = 77; - declaration(); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class StatementContext : Q1.Compiler.Context { - public StatementContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_statement; } } - - public StatementContext() { } - public virtual void CopyFrom(StatementContext context) { - base.CopyFrom(context); - } - } - public partial class WhileStatementContext : StatementContext { - public ExpressionContext cond; - public StatementContext body; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() { - return GetRuleContext(0); - } - public WhileStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitWhileStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class ForDeclStatementContext : StatementContext { - public DeclarationContext initializer; - public ExpressionContext cond; - public ExpressionContext post; - public StatementContext body; - [System.Diagnostics.DebuggerNonUserCode] public DeclarationContext declaration() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public ForDeclStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitForDeclStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class BlockStatementContext : StatementContext { - [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() { - return GetRuleContext(0); - } - public BlockStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBlockStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class NullStatementContext : StatementContext { - public NullStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitNullStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class ForExprStatementContext : StatementContext { - public ExpressionContext initializer; - public ExpressionContext cond; - public ExpressionContext post; - public StatementContext body; - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public ForExprStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitForExprStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class BreakStatementContext : StatementContext { - public BreakStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBreakStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class DoWhileStatementContext : StatementContext { - public StatementContext body; - public ExpressionContext cond; - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public DoWhileStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitDoWhileStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class ContinueStatementContext : StatementContext { - public ContinueStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitContinueStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class ExpressionStatementContext : StatementContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public ExpressionStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitExpressionStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class ReturnStatementContext : StatementContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public ReturnStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitReturnStatement(this); - else return visitor.VisitChildren(this); - } - } - public partial class IfStatementContext : StatementContext { - public StatementContext then; - public StatementContext @else; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext[] statement() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) { - return GetRuleContext(i); - } - public IfStatementContext(StatementContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIfStatement(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public StatementContext statement() { - StatementContext _localctx = new StatementContext(Context, State); - EnterRule(_localctx, 8, RULE_statement); - int _la; - try { - State = 144; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,14,Context) ) { - case 1: - _localctx = new ReturnStatementContext(_localctx); - EnterOuterAlt(_localctx, 1); - { - State = 80; - Match(T__6); - State = 81; - expression(0); - State = 82; - Match(T__3); - } - break; - case 2: - _localctx = new IfStatementContext(_localctx); - EnterOuterAlt(_localctx, 2); - { - State = 84; - Match(T__7); - State = 85; - Match(T__0); - State = 86; - expression(0); - State = 87; - Match(T__2); - State = 88; - ((IfStatementContext)_localctx).then = statement(); - State = 91; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,8,Context) ) { - case 1: - { - State = 89; - Match(T__8); - State = 90; - ((IfStatementContext)_localctx).@else = statement(); - } - break; - } - } - break; - case 3: - _localctx = new ForExprStatementContext(_localctx); - EnterOuterAlt(_localctx, 3); - { - State = 93; - Match(T__9); - State = 94; - Match(T__0); - State = 96; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 95; - ((ForExprStatementContext)_localctx).initializer = expression(0); - } - } - - State = 98; - Match(T__3); - State = 100; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 99; - ((ForExprStatementContext)_localctx).cond = expression(0); - } - } - - State = 102; - Match(T__3); - State = 104; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 103; - ((ForExprStatementContext)_localctx).post = expression(0); - } - } - - State = 106; - Match(T__2); - State = 107; - ((ForExprStatementContext)_localctx).body = statement(); - } - break; - case 4: - _localctx = new ForDeclStatementContext(_localctx); - EnterOuterAlt(_localctx, 4); - { - State = 108; - Match(T__9); - State = 109; - Match(T__0); - State = 110; - ((ForDeclStatementContext)_localctx).initializer = declaration(); - State = 112; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 111; - ((ForDeclStatementContext)_localctx).cond = expression(0); - } - } - - State = 114; - Match(T__3); - State = 116; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 115; - ((ForDeclStatementContext)_localctx).post = expression(0); - } - } - - State = 118; - Match(T__2); - State = 119; - ((ForDeclStatementContext)_localctx).body = statement(); - } - break; - case 5: - _localctx = new WhileStatementContext(_localctx); - EnterOuterAlt(_localctx, 5); - { - State = 121; - Match(T__10); - State = 122; - Match(T__0); - State = 123; - ((WhileStatementContext)_localctx).cond = expression(0); - State = 124; - Match(T__2); - State = 125; - ((WhileStatementContext)_localctx).body = statement(); - } - break; - case 6: - _localctx = new DoWhileStatementContext(_localctx); - EnterOuterAlt(_localctx, 6); - { - State = 127; - Match(T__11); - State = 128; - ((DoWhileStatementContext)_localctx).body = statement(); - State = 129; - Match(T__10); - State = 130; - Match(T__0); - State = 131; - ((DoWhileStatementContext)_localctx).cond = expression(0); - State = 132; - Match(T__2); - State = 133; - Match(T__3); - } - break; - case 7: - _localctx = new BreakStatementContext(_localctx); - EnterOuterAlt(_localctx, 7); - { - State = 135; - Match(T__12); - State = 136; - Match(T__3); - } - break; - case 8: - _localctx = new ContinueStatementContext(_localctx); - EnterOuterAlt(_localctx, 8); - { - State = 137; - Match(T__13); - State = 138; - Match(T__3); - } - break; - case 9: - _localctx = new ExpressionStatementContext(_localctx); - EnterOuterAlt(_localctx, 9); - { - State = 139; - expression(0); - State = 140; - Match(T__3); - } - break; - case 10: - _localctx = new BlockStatementContext(_localctx); - EnterOuterAlt(_localctx, 10); - { - State = 142; - block(); - } - break; - case 11: - _localctx = new NullStatementContext(_localctx); - EnterOuterAlt(_localctx, 11); - { - State = 143; - Match(T__3); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class DeclarationContext : Q1.Compiler.Context { - public DeclarationContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_declaration; } } - - public DeclarationContext() { } - public virtual void CopyFrom(DeclarationContext context) { - base.CopyFrom(context); - } - } - public partial class VariableDeclarationContext : DeclarationContext { - public IToken name; - public ExpressionContext value; - [System.Diagnostics.DebuggerNonUserCode] public TypeContext type() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public VariableDeclarationContext(DeclarationContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitVariableDeclaration(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public DeclarationContext declaration() { - DeclarationContext _localctx = new DeclarationContext(Context, State); - EnterRule(_localctx, 10, RULE_declaration); - int _la; - try { - _localctx = new VariableDeclarationContext(_localctx); - EnterOuterAlt(_localctx, 1); - { - State = 146; - type(0); - State = 147; - ((VariableDeclarationContext)_localctx).name = Match(ID); - State = 150; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if (_la==T__14) { - { - State = 148; - Match(T__14); - State = 149; - ((VariableDeclarationContext)_localctx).value = expression(0); - } - } - - State = 152; - Match(T__3); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class ExpressionContext : Q1.Compiler.Context { - public ExpressionContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_expression; } } - - public ExpressionContext() { } - public virtual void CopyFrom(ExpressionContext context) { - base.CopyFrom(context); - } - } - public partial class AddressOfExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - public AddressOfExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitAddressOfExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundSubtractExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundSubtractExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundSubtractExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class ModulusExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public ModulusExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitModulusExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class NotExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public NotExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitNotExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class DecrementPrefixExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - public DecrementPrefixExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitDecrementPrefixExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class MultiplyExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public MultiplyExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitMultiplyExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class GreaterThanExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public GreaterThanExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitGreaterThanExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class BitwiseLeftShiftExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public BitwiseLeftShiftExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBitwiseLeftShiftExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class BitwiseRightShiftExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public BitwiseRightShiftExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBitwiseRightShiftExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class VariableExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); } - public VariableExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitVariableExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundDivideExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundDivideExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundDivideExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class ParenthesizedExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public ParenthesizedExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitParenthesizedExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundAddExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundAddExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundAddExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundMultiplyExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundMultiplyExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundMultiplyExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundBitwiseXorExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundBitwiseXorExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundBitwiseXorExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class BitwiseAndExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public BitwiseAndExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBitwiseAndExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class LessThanExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public LessThanExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitLessThanExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class LogicalAndExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public LogicalAndExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitLogicalAndExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class IndexExpressionContext : ExpressionContext { - public TargetContext obj; - public ExpressionContext indexer; - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public IndexExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIndexExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class InvertExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public InvertExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitInvertExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class DereferenceExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public DereferenceExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitDereferenceExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class EqualExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public EqualExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitEqualExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class BitwiseXorExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public BitwiseXorExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBitwiseXorExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class ArrayExpressionContext : ExpressionContext { - public ExpressionContext _expression; - public IList _params = new List(); - [System.Diagnostics.DebuggerNonUserCode] public TypeContext type() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(CGrammarParser.INT, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public ArrayExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitArrayExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class ConstantExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public ConstantContext constant() { - return GetRuleContext(0); - } - public ConstantExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitConstantExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundModulusExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundModulusExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundModulusExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class LessThanOrEqualExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public LessThanOrEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitLessThanOrEqualExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class IncrementPostfixExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - public IncrementPostfixExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIncrementPostfixExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundBitwiseRightShiftExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundBitwiseRightShiftExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundBitwiseRightShiftExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class AssignmentExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public AssignmentExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitAssignmentExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class NotEqualExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public NotEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitNotEqualExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundBitwiseAndExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundBitwiseAndExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundBitwiseAndExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class LogicalOrExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public LogicalOrExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitLogicalOrExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class IncrementPrefixExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - public IncrementPrefixExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIncrementPrefixExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class GreaterThanOrEqualExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public GreaterThanOrEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitGreaterThanOrEqualExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class DivideExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public DivideExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitDivideExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class BitwiseOrExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public BitwiseOrExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitBitwiseOrExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CallExpressionContext : ExpressionContext { - public ExpressionContext _expression; - public IList _params = new List(); - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public CallExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCallExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class AddExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public AddExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitAddExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class SubtractExpressionContext : ExpressionContext { - public ExpressionContext left; - public ExpressionContext right; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public SubtractExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitSubtractExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundBitwiseOrExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundBitwiseOrExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundBitwiseOrExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class DecrementPostfixExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - public DecrementPostfixExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitDecrementPostfixExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class TernaryExpressionContext : ExpressionContext { - public ExpressionContext cond; - public ExpressionContext then; - public ExpressionContext @else; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext(i); - } - public TernaryExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitTernaryExpression(this); - else return visitor.VisitChildren(this); - } - } - public partial class CompoundBitwiseLeftShiftExpressionContext : ExpressionContext { - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public CompoundBitwiseLeftShiftExpressionContext(ExpressionContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCompoundBitwiseLeftShiftExpression(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public ExpressionContext expression() { - return expression(0); - } - - private ExpressionContext expression(int _p) { - ParserRuleContext _parentctx = Context; - int _parentState = State; - ExpressionContext _localctx = new ExpressionContext(Context, _parentState); - ExpressionContext _prevctx = _localctx; - int _startState = 12; - EnterRecursionRule(_localctx, 12, RULE_expression, _p); - int _la; - try { - int _alt; - EnterOuterAlt(_localctx, 1); - { - State = 262; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,22,Context) ) { - case 1: - { - _localctx = new ParenthesizedExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - - State = 155; - Match(T__0); - State = 156; - expression(0); - State = 157; - Match(T__2); - } - break; - case 2: - { - _localctx = new ArrayExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 159; - Match(T__15); - State = 160; - type(0); - State = 161; - Match(T__16); - State = 163; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if (_la==INT) { - { - State = 162; - Match(INT); - } - } - - State = 165; - Match(T__17); - State = 178; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,19,Context) ) { - case 1: - { - State = 166; - Match(T__4); - State = 175; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 167; - ((ArrayExpressionContext)_localctx)._expression = expression(0); - ((ArrayExpressionContext)_localctx)._params.Add(((ArrayExpressionContext)_localctx)._expression); - State = 172; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__1) { - { - { - State = 168; - Match(T__1); - State = 169; - ((ArrayExpressionContext)_localctx)._expression = expression(0); - ((ArrayExpressionContext)_localctx)._params.Add(((ArrayExpressionContext)_localctx)._expression); - } - } - State = 174; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - - State = 177; - Match(T__5); - } - break; - } - } - break; - case 3: - { - _localctx = new ConstantExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 180; - constant(); - } - break; - case 4: - { - _localctx = new AssignmentExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 181; - target(0); - State = 182; - Match(T__14); - State = 183; - expression(41); - } - break; - case 5: - { - _localctx = new DereferenceExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 185; - Match(T__18); - State = 186; - expression(40); - } - break; - case 6: - { - _localctx = new AddressOfExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 187; - Match(T__19); - State = 188; - target(0); - } - break; - case 7: - { - _localctx = new VariableExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 189; - Match(ID); - } - break; - case 8: - { - _localctx = new CallExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 190; - Match(ID); - State = 191; - Match(T__0); - State = 200; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { - { - State = 192; - ((CallExpressionContext)_localctx)._expression = expression(0); - ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression); - State = 197; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__1) { - { - { - State = 193; - Match(T__1); - State = 194; - ((CallExpressionContext)_localctx)._expression = expression(0); - ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression); - } - } - State = 199; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - - State = 202; - Match(T__2); - } - break; - case 9: - { - _localctx = new IndexExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 203; - ((IndexExpressionContext)_localctx).obj = target(0); - State = 204; - Match(T__16); - State = 205; - ((IndexExpressionContext)_localctx).indexer = expression(0); - State = 206; - Match(T__17); - } - break; - case 10: - { - _localctx = new NotExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 208; - Match(T__20); - State = 209; - expression(35); - } - break; - case 11: - { - _localctx = new InvertExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 210; - Match(T__21); - State = 211; - expression(34); - } - break; - case 12: - { - _localctx = new IncrementPrefixExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 212; - Match(T__22); - State = 213; - target(0); - } - break; - case 13: - { - _localctx = new DecrementPrefixExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 214; - Match(T__23); - State = 215; - target(0); - } - break; - case 14: - { - _localctx = new IncrementPostfixExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 216; - target(0); - State = 217; - Match(T__22); - } - break; - case 15: - { - _localctx = new DecrementPostfixExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 219; - target(0); - State = 220; - Match(T__23); - } - break; - case 16: - { - _localctx = new CompoundMultiplyExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 222; - target(0); - State = 223; - Match(T__40); - State = 224; - expression(11); - } - break; - case 17: - { - _localctx = new CompoundDivideExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 226; - target(0); - State = 227; - Match(T__41); - State = 228; - expression(10); - } - break; - case 18: - { - _localctx = new CompoundModulusExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 230; - target(0); - State = 231; - Match(T__42); - State = 232; - expression(9); - } - break; - case 19: - { - _localctx = new CompoundAddExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 234; - target(0); - State = 235; - Match(T__43); - State = 236; - expression(8); - } - break; - case 20: - { - _localctx = new CompoundSubtractExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 238; - target(0); - State = 239; - Match(T__44); - State = 240; - expression(7); - } - break; - case 21: - { - _localctx = new CompoundBitwiseAndExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 242; - target(0); - State = 243; - Match(T__45); - State = 244; - expression(6); - } - break; - case 22: - { - _localctx = new CompoundBitwiseOrExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 246; - target(0); - State = 247; - Match(T__46); - State = 248; - expression(5); - } - break; - case 23: - { - _localctx = new CompoundBitwiseXorExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 250; - target(0); - State = 251; - Match(T__47); - State = 252; - expression(4); - } - break; - case 24: - { - _localctx = new CompoundBitwiseLeftShiftExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 254; - target(0); - State = 255; - Match(T__48); - State = 256; - expression(3); - } - break; - case 25: - { - _localctx = new CompoundBitwiseRightShiftExpressionContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - State = 258; - target(0); - State = 259; - Match(T__49); - State = 260; - expression(2); - } - break; - } - Context.Stop = TokenStream.LT(-1); - State = 326; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,24,Context); - while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - if ( ParseListeners!=null ) - TriggerExitRuleEvent(); - _prevctx = _localctx; - { - State = 324; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,23,Context) ) { - case 1: - { - _localctx = new MultiplyExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((MultiplyExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 264; - if (!(Precpred(Context, 29))) throw new FailedPredicateException(this, "Precpred(Context, 29)"); - State = 265; - Match(T__18); - State = 266; - ((MultiplyExpressionContext)_localctx).right = expression(30); - } - break; - case 2: - { - _localctx = new DivideExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((DivideExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 267; - if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)"); - State = 268; - Match(T__24); - State = 269; - ((DivideExpressionContext)_localctx).right = expression(29); - } - break; - case 3: - { - _localctx = new ModulusExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((ModulusExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 270; - if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)"); - State = 271; - Match(T__25); - State = 272; - ((ModulusExpressionContext)_localctx).right = expression(28); - } - break; - case 4: - { - _localctx = new AddExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((AddExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 273; - if (!(Precpred(Context, 26))) throw new FailedPredicateException(this, "Precpred(Context, 26)"); - State = 274; - Match(T__26); - State = 275; - ((AddExpressionContext)_localctx).right = expression(27); - } - break; - case 5: - { - _localctx = new SubtractExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((SubtractExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 276; - if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)"); - State = 277; - Match(T__27); - State = 278; - ((SubtractExpressionContext)_localctx).right = expression(26); - } - break; - case 6: - { - _localctx = new LessThanExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((LessThanExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 279; - if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)"); - State = 280; - Match(T__28); - State = 281; - ((LessThanExpressionContext)_localctx).right = expression(25); - } - break; - case 7: - { - _localctx = new GreaterThanExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((GreaterThanExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 282; - if (!(Precpred(Context, 23))) throw new FailedPredicateException(this, "Precpred(Context, 23)"); - State = 283; - Match(T__29); - State = 284; - ((GreaterThanExpressionContext)_localctx).right = expression(24); - } - break; - case 8: - { - _localctx = new LessThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((LessThanOrEqualExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 285; - if (!(Precpred(Context, 22))) throw new FailedPredicateException(this, "Precpred(Context, 22)"); - State = 286; - Match(T__30); - State = 287; - ((LessThanOrEqualExpressionContext)_localctx).right = expression(23); - } - break; - case 9: - { - _localctx = new GreaterThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((GreaterThanOrEqualExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 288; - if (!(Precpred(Context, 21))) throw new FailedPredicateException(this, "Precpred(Context, 21)"); - State = 289; - Match(T__31); - State = 290; - ((GreaterThanOrEqualExpressionContext)_localctx).right = expression(22); - } - break; - case 10: - { - _localctx = new EqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((EqualExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 291; - if (!(Precpred(Context, 20))) throw new FailedPredicateException(this, "Precpred(Context, 20)"); - State = 292; - Match(T__32); - State = 293; - ((EqualExpressionContext)_localctx).right = expression(21); - } - break; - case 11: - { - _localctx = new NotEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((NotEqualExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 294; - if (!(Precpred(Context, 19))) throw new FailedPredicateException(this, "Precpred(Context, 19)"); - State = 295; - Match(T__33); - State = 296; - ((NotEqualExpressionContext)_localctx).right = expression(20); - } - break; - case 12: - { - _localctx = new BitwiseAndExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((BitwiseAndExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 297; - if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)"); - State = 298; - Match(T__19); - State = 299; - ((BitwiseAndExpressionContext)_localctx).right = expression(19); - } - break; - case 13: - { - _localctx = new BitwiseOrExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((BitwiseOrExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 300; - if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)"); - State = 301; - Match(T__34); - State = 302; - ((BitwiseOrExpressionContext)_localctx).right = expression(18); - } - break; - case 14: - { - _localctx = new BitwiseXorExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((BitwiseXorExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 303; - if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)"); - State = 304; - Match(T__35); - State = 305; - ((BitwiseXorExpressionContext)_localctx).right = expression(17); - } - break; - case 15: - { - _localctx = new BitwiseLeftShiftExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((BitwiseLeftShiftExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 306; - if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)"); - State = 307; - Match(T__36); - State = 308; - ((BitwiseLeftShiftExpressionContext)_localctx).right = expression(16); - } - break; - case 16: - { - _localctx = new BitwiseRightShiftExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((BitwiseRightShiftExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 309; - if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)"); - State = 310; - Match(T__37); - State = 311; - ((BitwiseRightShiftExpressionContext)_localctx).right = expression(15); - } - break; - case 17: - { - _localctx = new LogicalAndExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((LogicalAndExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 312; - if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)"); - State = 313; - Match(T__38); - State = 314; - ((LogicalAndExpressionContext)_localctx).right = expression(14); - } - break; - case 18: - { - _localctx = new LogicalOrExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((LogicalOrExpressionContext)_localctx).left = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 315; - if (!(Precpred(Context, 12))) throw new FailedPredicateException(this, "Precpred(Context, 12)"); - State = 316; - Match(T__39); - State = 317; - ((LogicalOrExpressionContext)_localctx).right = expression(13); - } - break; - case 19: - { - _localctx = new TernaryExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((TernaryExpressionContext)_localctx).cond = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 318; - if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); - State = 319; - Match(T__50); - State = 320; - ((TernaryExpressionContext)_localctx).then = expression(0); - State = 321; - Match(T__51); - State = 322; - ((TernaryExpressionContext)_localctx).@else = expression(2); - } - break; - } - } - } - State = 328; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,24,Context); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - UnrollRecursionContexts(_parentctx); - } - return _localctx; - } - - public partial class ConstantContext : Q1.Compiler.Context { - public ConstantContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_constant; } } - - public ConstantContext() { } - public virtual void CopyFrom(ConstantContext context) { - base.CopyFrom(context); - } - } - public partial class CharConstantContext : ConstantContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode LETTER() { return GetToken(CGrammarParser.LETTER, 0); } - public CharConstantContext(ConstantContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitCharConstant(this); - else return visitor.VisitChildren(this); - } - } - public partial class IntConstantContext : ConstantContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(CGrammarParser.INT, 0); } - public IntConstantContext(ConstantContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIntConstant(this); - else return visitor.VisitChildren(this); - } - } - public partial class StringConstantContext : ConstantContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode STRING() { return GetToken(CGrammarParser.STRING, 0); } - public StringConstantContext(ConstantContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitStringConstant(this); - else return visitor.VisitChildren(this); - } - } - public partial class HexConstantContext : ConstantContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(CGrammarParser.HEX, 0); } - public HexConstantContext(ConstantContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitHexConstant(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public ConstantContext constant() { - ConstantContext _localctx = new ConstantContext(Context, State); - EnterRule(_localctx, 14, RULE_constant); - try { - State = 333; - ErrorHandler.Sync(this); - switch (TokenStream.LA(1)) { - case INT: - _localctx = new IntConstantContext(_localctx); - EnterOuterAlt(_localctx, 1); - { - State = 329; - Match(INT); - } - break; - case HEX: - _localctx = new HexConstantContext(_localctx); - EnterOuterAlt(_localctx, 2); - { - State = 330; - Match(HEX); - } - break; - case LETTER: - _localctx = new CharConstantContext(_localctx); - EnterOuterAlt(_localctx, 3); - { - State = 331; - Match(LETTER); - } - break; - case STRING: - _localctx = new StringConstantContext(_localctx); - EnterOuterAlt(_localctx, 4); - { - State = 332; - Match(STRING); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class TypeContext : Q1.Compiler.Context { - [System.Diagnostics.DebuggerNonUserCode] public TypeContext type() { - return GetRuleContext(0); - } - public TypeContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_type; } } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitType(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public TypeContext type() { - return type(0); - } - - private TypeContext type(int _p) { - ParserRuleContext _parentctx = Context; - int _parentState = State; - TypeContext _localctx = new TypeContext(Context, _parentState); - TypeContext _prevctx = _localctx; - int _startState = 16; - EnterRecursionRule(_localctx, 16, RULE_type, _p); - try { - int _alt; - EnterOuterAlt(_localctx, 1); - { - State = 338; - ErrorHandler.Sync(this); - switch (TokenStream.LA(1)) { - case T__52: - { - State = 336; - Match(T__52); - } - break; - case T__53: - { - State = 337; - Match(T__53); - } - break; - default: - throw new NoViableAltException(this); - } - Context.Stop = TokenStream.LT(-1); - State = 344; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,27,Context); - while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - if ( ParseListeners!=null ) - TriggerExitRuleEvent(); - _prevctx = _localctx; - { - { - _localctx = new TypeContext(_parentctx, _parentState); - PushNewRecursionContext(_localctx, _startState, RULE_type); - State = 340; - if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); - State = 341; - Match(T__18); - } - } - } - State = 346; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,27,Context); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - UnrollRecursionContexts(_parentctx); - } - return _localctx; - } - - public partial class TargetContext : Q1.Compiler.Context { - public TargetContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_target; } } - - public TargetContext() { } - public virtual void CopyFrom(TargetContext context) { - base.CopyFrom(context); - } - } - public partial class IndexerTargetContext : TargetContext { - public TargetContext obj; - public ExpressionContext indexer; - [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { - return GetRuleContext(0); - } - public IndexerTargetContext(TargetContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitIndexerTarget(this); - else return visitor.VisitChildren(this); - } - } - public partial class VariableTargetContext : TargetContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); } - public VariableTargetContext(TargetContext context) { CopyFrom(context); } - [System.Diagnostics.DebuggerNonUserCode] - public override TResult Accept(IParseTreeVisitor visitor) { - ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; - if (typedVisitor != null) return typedVisitor.VisitVariableTarget(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public TargetContext target() { - return target(0); - } - - private TargetContext target(int _p) { - ParserRuleContext _parentctx = Context; - int _parentState = State; - TargetContext _localctx = new TargetContext(Context, _parentState); - TargetContext _prevctx = _localctx; - int _startState = 18; - EnterRecursionRule(_localctx, 18, RULE_target, _p); - try { - int _alt; - EnterOuterAlt(_localctx, 1); - { - { - _localctx = new VariableTargetContext(_localctx); - Context = _localctx; - _prevctx = _localctx; - - State = 348; - Match(ID); - } - Context.Stop = TokenStream.LT(-1); - State = 357; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,28,Context); - while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - if ( ParseListeners!=null ) - TriggerExitRuleEvent(); - _prevctx = _localctx; - { - { - _localctx = new IndexerTargetContext(new TargetContext(_parentctx, _parentState)); - ((IndexerTargetContext)_localctx).obj = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_target); - State = 350; - if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); - State = 351; - Match(T__16); - State = 352; - ((IndexerTargetContext)_localctx).indexer = expression(0); - State = 353; - Match(T__17); - } - } - } - State = 359; - ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,28,Context); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - UnrollRecursionContexts(_parentctx); - } - return _localctx; - } - - public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) { - switch (ruleIndex) { - case 6: return expression_sempred((ExpressionContext)_localctx, predIndex); - case 8: return type_sempred((TypeContext)_localctx, predIndex); - case 9: return target_sempred((TargetContext)_localctx, predIndex); - } - return true; - } - private bool expression_sempred(ExpressionContext _localctx, int predIndex) { - switch (predIndex) { - case 0: return Precpred(Context, 29); - case 1: return Precpred(Context, 28); - case 2: return Precpred(Context, 27); - case 3: return Precpred(Context, 26); - case 4: return Precpred(Context, 25); - case 5: return Precpred(Context, 24); - case 6: return Precpred(Context, 23); - case 7: return Precpred(Context, 22); - case 8: return Precpred(Context, 21); - case 9: return Precpred(Context, 20); - case 10: return Precpred(Context, 19); - case 11: return Precpred(Context, 18); - case 12: return Precpred(Context, 17); - case 13: return Precpred(Context, 16); - case 14: return Precpred(Context, 15); - case 15: return Precpred(Context, 14); - case 16: return Precpred(Context, 13); - case 17: return Precpred(Context, 12); - case 18: return Precpred(Context, 1); - } - return true; - } - private bool type_sempred(TypeContext _localctx, int predIndex) { - switch (predIndex) { - case 19: return Precpred(Context, 1); - } - return true; - } - private bool target_sempred(TargetContext _localctx, int predIndex) { - switch (predIndex) { - case 20: return Precpred(Context, 1); - } - return true; - } - - private static int[] _serializedATN = { - 4,1,62,361,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7, - 7,7,2,8,7,8,2,9,7,9,1,0,4,0,22,8,0,11,0,12,0,23,1,0,1,0,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,5,1,37,8,1,10,1,12,1,40,9,1,3,1,42,8,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,56,8,1,10,1,12,1,59,9,1,3,1, - 61,8,1,1,1,1,1,1,1,3,1,66,8,1,1,2,1,2,5,2,70,8,2,10,2,12,2,73,9,2,1,2, - 1,2,1,3,1,3,3,3,79,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4, - 92,8,4,1,4,1,4,1,4,3,4,97,8,4,1,4,1,4,3,4,101,8,4,1,4,1,4,3,4,105,8,4, - 1,4,1,4,1,4,1,4,1,4,1,4,3,4,113,8,4,1,4,1,4,3,4,117,8,4,1,4,1,4,1,4,1, - 4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4, - 1,4,1,4,1,4,1,4,1,4,3,4,145,8,4,1,5,1,5,1,5,1,5,3,5,151,8,5,1,5,1,5,1, - 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,3,6,164,8,6,1,6,1,6,1,6,1,6,1,6,5,6, - 171,8,6,10,6,12,6,174,9,6,3,6,176,8,6,1,6,3,6,179,8,6,1,6,1,6,1,6,1,6, - 1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,5,6,196,8,6,10,6,12,6,199, - 9,6,3,6,201,8,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1, - 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6, - 1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1, - 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,3,6,263,8,6,1,6,1,6,1,6, - 1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1, - 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6, - 1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1, - 6,1,6,1,6,1,6,1,6,5,6,325,8,6,10,6,12,6,328,9,6,1,7,1,7,1,7,1,7,3,7,334, - 8,7,1,8,1,8,1,8,3,8,339,8,8,1,8,1,8,5,8,343,8,8,10,8,12,8,346,9,8,1,9, - 1,9,1,9,1,9,1,9,1,9,1,9,1,9,5,9,356,8,9,10,9,12,9,359,9,9,1,9,0,3,12,16, - 18,10,0,2,4,6,8,10,12,14,16,18,0,0,430,0,21,1,0,0,0,2,65,1,0,0,0,4,67, - 1,0,0,0,6,78,1,0,0,0,8,144,1,0,0,0,10,146,1,0,0,0,12,262,1,0,0,0,14,333, - 1,0,0,0,16,338,1,0,0,0,18,347,1,0,0,0,20,22,3,2,1,0,21,20,1,0,0,0,22,23, - 1,0,0,0,23,21,1,0,0,0,23,24,1,0,0,0,24,25,1,0,0,0,25,26,5,0,0,1,26,1,1, - 0,0,0,27,28,3,16,8,0,28,29,5,56,0,0,29,41,5,1,0,0,30,31,3,16,8,0,31,38, - 5,56,0,0,32,33,5,2,0,0,33,34,3,16,8,0,34,35,5,56,0,0,35,37,1,0,0,0,36, - 32,1,0,0,0,37,40,1,0,0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,42,1,0,0,0,40, - 38,1,0,0,0,41,30,1,0,0,0,41,42,1,0,0,0,42,43,1,0,0,0,43,44,5,3,0,0,44, - 45,5,4,0,0,45,66,1,0,0,0,46,47,3,16,8,0,47,48,5,56,0,0,48,60,5,1,0,0,49, - 50,3,16,8,0,50,57,5,56,0,0,51,52,5,2,0,0,52,53,3,16,8,0,53,54,5,56,0,0, - 54,56,1,0,0,0,55,51,1,0,0,0,56,59,1,0,0,0,57,55,1,0,0,0,57,58,1,0,0,0, - 58,61,1,0,0,0,59,57,1,0,0,0,60,49,1,0,0,0,60,61,1,0,0,0,61,62,1,0,0,0, - 62,63,5,3,0,0,63,64,3,4,2,0,64,66,1,0,0,0,65,27,1,0,0,0,65,46,1,0,0,0, - 66,3,1,0,0,0,67,71,5,5,0,0,68,70,3,6,3,0,69,68,1,0,0,0,70,73,1,0,0,0,71, - 69,1,0,0,0,71,72,1,0,0,0,72,74,1,0,0,0,73,71,1,0,0,0,74,75,5,6,0,0,75, - 5,1,0,0,0,76,79,3,8,4,0,77,79,3,10,5,0,78,76,1,0,0,0,78,77,1,0,0,0,79, - 7,1,0,0,0,80,81,5,7,0,0,81,82,3,12,6,0,82,83,5,4,0,0,83,145,1,0,0,0,84, - 85,5,8,0,0,85,86,5,1,0,0,86,87,3,12,6,0,87,88,5,3,0,0,88,91,3,8,4,0,89, - 90,5,9,0,0,90,92,3,8,4,0,91,89,1,0,0,0,91,92,1,0,0,0,92,145,1,0,0,0,93, - 94,5,10,0,0,94,96,5,1,0,0,95,97,3,12,6,0,96,95,1,0,0,0,96,97,1,0,0,0,97, - 98,1,0,0,0,98,100,5,4,0,0,99,101,3,12,6,0,100,99,1,0,0,0,100,101,1,0,0, - 0,101,102,1,0,0,0,102,104,5,4,0,0,103,105,3,12,6,0,104,103,1,0,0,0,104, - 105,1,0,0,0,105,106,1,0,0,0,106,107,5,3,0,0,107,145,3,8,4,0,108,109,5, - 10,0,0,109,110,5,1,0,0,110,112,3,10,5,0,111,113,3,12,6,0,112,111,1,0,0, - 0,112,113,1,0,0,0,113,114,1,0,0,0,114,116,5,4,0,0,115,117,3,12,6,0,116, - 115,1,0,0,0,116,117,1,0,0,0,117,118,1,0,0,0,118,119,5,3,0,0,119,120,3, - 8,4,0,120,145,1,0,0,0,121,122,5,11,0,0,122,123,5,1,0,0,123,124,3,12,6, - 0,124,125,5,3,0,0,125,126,3,8,4,0,126,145,1,0,0,0,127,128,5,12,0,0,128, - 129,3,8,4,0,129,130,5,11,0,0,130,131,5,1,0,0,131,132,3,12,6,0,132,133, - 5,3,0,0,133,134,5,4,0,0,134,145,1,0,0,0,135,136,5,13,0,0,136,145,5,4,0, - 0,137,138,5,14,0,0,138,145,5,4,0,0,139,140,3,12,6,0,140,141,5,4,0,0,141, - 145,1,0,0,0,142,145,3,4,2,0,143,145,5,4,0,0,144,80,1,0,0,0,144,84,1,0, - 0,0,144,93,1,0,0,0,144,108,1,0,0,0,144,121,1,0,0,0,144,127,1,0,0,0,144, - 135,1,0,0,0,144,137,1,0,0,0,144,139,1,0,0,0,144,142,1,0,0,0,144,143,1, - 0,0,0,145,9,1,0,0,0,146,147,3,16,8,0,147,150,5,56,0,0,148,149,5,15,0,0, - 149,151,3,12,6,0,150,148,1,0,0,0,150,151,1,0,0,0,151,152,1,0,0,0,152,153, - 5,4,0,0,153,11,1,0,0,0,154,155,6,6,-1,0,155,156,5,1,0,0,156,157,3,12,6, - 0,157,158,5,3,0,0,158,263,1,0,0,0,159,160,5,16,0,0,160,161,3,16,8,0,161, - 163,5,17,0,0,162,164,5,57,0,0,163,162,1,0,0,0,163,164,1,0,0,0,164,165, - 1,0,0,0,165,178,5,18,0,0,166,175,5,5,0,0,167,172,3,12,6,0,168,169,5,2, - 0,0,169,171,3,12,6,0,170,168,1,0,0,0,171,174,1,0,0,0,172,170,1,0,0,0,172, - 173,1,0,0,0,173,176,1,0,0,0,174,172,1,0,0,0,175,167,1,0,0,0,175,176,1, - 0,0,0,176,177,1,0,0,0,177,179,5,6,0,0,178,166,1,0,0,0,178,179,1,0,0,0, - 179,263,1,0,0,0,180,263,3,14,7,0,181,182,3,18,9,0,182,183,5,15,0,0,183, - 184,3,12,6,41,184,263,1,0,0,0,185,186,5,19,0,0,186,263,3,12,6,40,187,188, - 5,20,0,0,188,263,3,18,9,0,189,263,5,56,0,0,190,191,5,56,0,0,191,200,5, - 1,0,0,192,197,3,12,6,0,193,194,5,2,0,0,194,196,3,12,6,0,195,193,1,0,0, - 0,196,199,1,0,0,0,197,195,1,0,0,0,197,198,1,0,0,0,198,201,1,0,0,0,199, - 197,1,0,0,0,200,192,1,0,0,0,200,201,1,0,0,0,201,202,1,0,0,0,202,263,5, - 3,0,0,203,204,3,18,9,0,204,205,5,17,0,0,205,206,3,12,6,0,206,207,5,18, - 0,0,207,263,1,0,0,0,208,209,5,21,0,0,209,263,3,12,6,35,210,211,5,22,0, - 0,211,263,3,12,6,34,212,213,5,23,0,0,213,263,3,18,9,0,214,215,5,24,0,0, - 215,263,3,18,9,0,216,217,3,18,9,0,217,218,5,23,0,0,218,263,1,0,0,0,219, - 220,3,18,9,0,220,221,5,24,0,0,221,263,1,0,0,0,222,223,3,18,9,0,223,224, - 5,41,0,0,224,225,3,12,6,11,225,263,1,0,0,0,226,227,3,18,9,0,227,228,5, - 42,0,0,228,229,3,12,6,10,229,263,1,0,0,0,230,231,3,18,9,0,231,232,5,43, - 0,0,232,233,3,12,6,9,233,263,1,0,0,0,234,235,3,18,9,0,235,236,5,44,0,0, - 236,237,3,12,6,8,237,263,1,0,0,0,238,239,3,18,9,0,239,240,5,45,0,0,240, - 241,3,12,6,7,241,263,1,0,0,0,242,243,3,18,9,0,243,244,5,46,0,0,244,245, - 3,12,6,6,245,263,1,0,0,0,246,247,3,18,9,0,247,248,5,47,0,0,248,249,3,12, - 6,5,249,263,1,0,0,0,250,251,3,18,9,0,251,252,5,48,0,0,252,253,3,12,6,4, - 253,263,1,0,0,0,254,255,3,18,9,0,255,256,5,49,0,0,256,257,3,12,6,3,257, - 263,1,0,0,0,258,259,3,18,9,0,259,260,5,50,0,0,260,261,3,12,6,2,261,263, - 1,0,0,0,262,154,1,0,0,0,262,159,1,0,0,0,262,180,1,0,0,0,262,181,1,0,0, - 0,262,185,1,0,0,0,262,187,1,0,0,0,262,189,1,0,0,0,262,190,1,0,0,0,262, - 203,1,0,0,0,262,208,1,0,0,0,262,210,1,0,0,0,262,212,1,0,0,0,262,214,1, - 0,0,0,262,216,1,0,0,0,262,219,1,0,0,0,262,222,1,0,0,0,262,226,1,0,0,0, - 262,230,1,0,0,0,262,234,1,0,0,0,262,238,1,0,0,0,262,242,1,0,0,0,262,246, - 1,0,0,0,262,250,1,0,0,0,262,254,1,0,0,0,262,258,1,0,0,0,263,326,1,0,0, - 0,264,265,10,29,0,0,265,266,5,19,0,0,266,325,3,12,6,30,267,268,10,28,0, - 0,268,269,5,25,0,0,269,325,3,12,6,29,270,271,10,27,0,0,271,272,5,26,0, - 0,272,325,3,12,6,28,273,274,10,26,0,0,274,275,5,27,0,0,275,325,3,12,6, - 27,276,277,10,25,0,0,277,278,5,28,0,0,278,325,3,12,6,26,279,280,10,24, - 0,0,280,281,5,29,0,0,281,325,3,12,6,25,282,283,10,23,0,0,283,284,5,30, - 0,0,284,325,3,12,6,24,285,286,10,22,0,0,286,287,5,31,0,0,287,325,3,12, - 6,23,288,289,10,21,0,0,289,290,5,32,0,0,290,325,3,12,6,22,291,292,10,20, - 0,0,292,293,5,33,0,0,293,325,3,12,6,21,294,295,10,19,0,0,295,296,5,34, - 0,0,296,325,3,12,6,20,297,298,10,18,0,0,298,299,5,20,0,0,299,325,3,12, - 6,19,300,301,10,17,0,0,301,302,5,35,0,0,302,325,3,12,6,18,303,304,10,16, - 0,0,304,305,5,36,0,0,305,325,3,12,6,17,306,307,10,15,0,0,307,308,5,37, - 0,0,308,325,3,12,6,16,309,310,10,14,0,0,310,311,5,38,0,0,311,325,3,12, - 6,15,312,313,10,13,0,0,313,314,5,39,0,0,314,325,3,12,6,14,315,316,10,12, - 0,0,316,317,5,40,0,0,317,325,3,12,6,13,318,319,10,1,0,0,319,320,5,51,0, - 0,320,321,3,12,6,0,321,322,5,52,0,0,322,323,3,12,6,2,323,325,1,0,0,0,324, - 264,1,0,0,0,324,267,1,0,0,0,324,270,1,0,0,0,324,273,1,0,0,0,324,276,1, - 0,0,0,324,279,1,0,0,0,324,282,1,0,0,0,324,285,1,0,0,0,324,288,1,0,0,0, - 324,291,1,0,0,0,324,294,1,0,0,0,324,297,1,0,0,0,324,300,1,0,0,0,324,303, - 1,0,0,0,324,306,1,0,0,0,324,309,1,0,0,0,324,312,1,0,0,0,324,315,1,0,0, - 0,324,318,1,0,0,0,325,328,1,0,0,0,326,324,1,0,0,0,326,327,1,0,0,0,327, - 13,1,0,0,0,328,326,1,0,0,0,329,334,5,57,0,0,330,334,5,55,0,0,331,334,5, - 61,0,0,332,334,5,62,0,0,333,329,1,0,0,0,333,330,1,0,0,0,333,331,1,0,0, - 0,333,332,1,0,0,0,334,15,1,0,0,0,335,336,6,8,-1,0,336,339,5,53,0,0,337, - 339,5,54,0,0,338,335,1,0,0,0,338,337,1,0,0,0,339,344,1,0,0,0,340,341,10, - 1,0,0,341,343,5,19,0,0,342,340,1,0,0,0,343,346,1,0,0,0,344,342,1,0,0,0, - 344,345,1,0,0,0,345,17,1,0,0,0,346,344,1,0,0,0,347,348,6,9,-1,0,348,349, - 5,56,0,0,349,357,1,0,0,0,350,351,10,1,0,0,351,352,5,17,0,0,352,353,3,12, - 6,0,353,354,5,18,0,0,354,356,1,0,0,0,355,350,1,0,0,0,356,359,1,0,0,0,357, - 355,1,0,0,0,357,358,1,0,0,0,358,19,1,0,0,0,359,357,1,0,0,0,29,23,38,41, - 57,60,65,71,78,91,96,100,104,112,116,144,150,163,172,175,178,197,200,262, - 324,326,333,338,344,357 - }; - - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN); - - -} diff --git a/Compiler/gen/CGrammarVisitor.cs b/Compiler/gen/CGrammarVisitor.cs deleted file mode 100644 index be6f92e..0000000 --- a/Compiler/gen/CGrammarVisitor.cs +++ /dev/null @@ -1,506 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.13.2 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using IToken = Antlr4.Runtime.IToken; - -/// -/// This interface defines a complete generic visitor for a parse tree produced -/// by . -/// -/// The return type of the visit operation. -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] -[System.CLSCompliant(false)] -public interface ICGrammarVisitor : IParseTreeVisitor { - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitProgram([NotNull] CGrammarParser.ProgramContext context); - /// - /// Visit a parse tree produced by the functionPrototype - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitFunctionPrototype([NotNull] CGrammarParser.FunctionPrototypeContext context); - /// - /// Visit a parse tree produced by the functionDefinition - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitFunctionDefinition([NotNull] CGrammarParser.FunctionDefinitionContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitBlock([NotNull] CGrammarParser.BlockContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitBlock_item([NotNull] CGrammarParser.Block_itemContext context); - /// - /// Visit a parse tree produced by the returnStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context); - /// - /// Visit a parse tree produced by the ifStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIfStatement([NotNull] CGrammarParser.IfStatementContext context); - /// - /// Visit a parse tree produced by the forExprStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitForExprStatement([NotNull] CGrammarParser.ForExprStatementContext context); - /// - /// Visit a parse tree produced by the forDeclStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitForDeclStatement([NotNull] CGrammarParser.ForDeclStatementContext context); - /// - /// Visit a parse tree produced by the whileStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitWhileStatement([NotNull] CGrammarParser.WhileStatementContext context); - /// - /// Visit a parse tree produced by the doWhileStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitDoWhileStatement([NotNull] CGrammarParser.DoWhileStatementContext context); - /// - /// Visit a parse tree produced by the breakStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBreakStatement([NotNull] CGrammarParser.BreakStatementContext context); - /// - /// Visit a parse tree produced by the continueStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitContinueStatement([NotNull] CGrammarParser.ContinueStatementContext context); - /// - /// Visit a parse tree produced by the expressionStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitExpressionStatement([NotNull] CGrammarParser.ExpressionStatementContext context); - /// - /// Visit a parse tree produced by the blockStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBlockStatement([NotNull] CGrammarParser.BlockStatementContext context); - /// - /// Visit a parse tree produced by the nullStatement - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitNullStatement([NotNull] CGrammarParser.NullStatementContext context); - /// - /// Visit a parse tree produced by the variableDeclaration - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitVariableDeclaration([NotNull] CGrammarParser.VariableDeclarationContext context); - /// - /// Visit a parse tree produced by the addressOfExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitAddressOfExpression([NotNull] CGrammarParser.AddressOfExpressionContext context); - /// - /// Visit a parse tree produced by the compoundSubtractExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundSubtractExpression([NotNull] CGrammarParser.CompoundSubtractExpressionContext context); - /// - /// Visit a parse tree produced by the modulusExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context); - /// - /// Visit a parse tree produced by the notExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context); - /// - /// Visit a parse tree produced by the decrementPrefixExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitDecrementPrefixExpression([NotNull] CGrammarParser.DecrementPrefixExpressionContext context); - /// - /// Visit a parse tree produced by the multiplyExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context); - /// - /// Visit a parse tree produced by the greaterThanExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context); - /// - /// Visit a parse tree produced by the bitwiseLeftShiftExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBitwiseLeftShiftExpression([NotNull] CGrammarParser.BitwiseLeftShiftExpressionContext context); - /// - /// Visit a parse tree produced by the bitwiseRightShiftExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBitwiseRightShiftExpression([NotNull] CGrammarParser.BitwiseRightShiftExpressionContext context); - /// - /// Visit a parse tree produced by the variableExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitVariableExpression([NotNull] CGrammarParser.VariableExpressionContext context); - /// - /// Visit a parse tree produced by the compoundDivideExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundDivideExpression([NotNull] CGrammarParser.CompoundDivideExpressionContext context); - /// - /// Visit a parse tree produced by the parenthesizedExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context); - /// - /// Visit a parse tree produced by the compoundAddExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundAddExpression([NotNull] CGrammarParser.CompoundAddExpressionContext context); - /// - /// Visit a parse tree produced by the compoundMultiplyExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundMultiplyExpression([NotNull] CGrammarParser.CompoundMultiplyExpressionContext context); - /// - /// Visit a parse tree produced by the compoundBitwiseXorExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundBitwiseXorExpression([NotNull] CGrammarParser.CompoundBitwiseXorExpressionContext context); - /// - /// Visit a parse tree produced by the bitwiseAndExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context); - /// - /// Visit a parse tree produced by the lessThanExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context); - /// - /// Visit a parse tree produced by the logicalAndExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context); - /// - /// Visit a parse tree produced by the indexExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIndexExpression([NotNull] CGrammarParser.IndexExpressionContext context); - /// - /// Visit a parse tree produced by the invertExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context); - /// - /// Visit a parse tree produced by the dereferenceExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitDereferenceExpression([NotNull] CGrammarParser.DereferenceExpressionContext context); - /// - /// Visit a parse tree produced by the equalExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context); - /// - /// Visit a parse tree produced by the bitwiseXorExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context); - /// - /// Visit a parse tree produced by the arrayExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitArrayExpression([NotNull] CGrammarParser.ArrayExpressionContext context); - /// - /// Visit a parse tree produced by the constantExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context); - /// - /// Visit a parse tree produced by the compoundModulusExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundModulusExpression([NotNull] CGrammarParser.CompoundModulusExpressionContext context); - /// - /// Visit a parse tree produced by the lessThanOrEqualExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context); - /// - /// Visit a parse tree produced by the incrementPostfixExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIncrementPostfixExpression([NotNull] CGrammarParser.IncrementPostfixExpressionContext context); - /// - /// Visit a parse tree produced by the compoundBitwiseRightShiftExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundBitwiseRightShiftExpression([NotNull] CGrammarParser.CompoundBitwiseRightShiftExpressionContext context); - /// - /// Visit a parse tree produced by the assignmentExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitAssignmentExpression([NotNull] CGrammarParser.AssignmentExpressionContext context); - /// - /// Visit a parse tree produced by the notEqualExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context); - /// - /// Visit a parse tree produced by the compoundBitwiseAndExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundBitwiseAndExpression([NotNull] CGrammarParser.CompoundBitwiseAndExpressionContext context); - /// - /// Visit a parse tree produced by the logicalOrExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context); - /// - /// Visit a parse tree produced by the incrementPrefixExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIncrementPrefixExpression([NotNull] CGrammarParser.IncrementPrefixExpressionContext context); - /// - /// Visit a parse tree produced by the greaterThanOrEqualExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context); - /// - /// Visit a parse tree produced by the divideExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context); - /// - /// Visit a parse tree produced by the bitwiseOrExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context); - /// - /// Visit a parse tree produced by the callExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCallExpression([NotNull] CGrammarParser.CallExpressionContext context); - /// - /// Visit a parse tree produced by the addExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context); - /// - /// Visit a parse tree produced by the subtractExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context); - /// - /// Visit a parse tree produced by the compoundBitwiseOrExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundBitwiseOrExpression([NotNull] CGrammarParser.CompoundBitwiseOrExpressionContext context); - /// - /// Visit a parse tree produced by the decrementPostfixExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitDecrementPostfixExpression([NotNull] CGrammarParser.DecrementPostfixExpressionContext context); - /// - /// Visit a parse tree produced by the ternaryExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitTernaryExpression([NotNull] CGrammarParser.TernaryExpressionContext context); - /// - /// Visit a parse tree produced by the compoundBitwiseLeftShiftExpression - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCompoundBitwiseLeftShiftExpression([NotNull] CGrammarParser.CompoundBitwiseLeftShiftExpressionContext context); - /// - /// Visit a parse tree produced by the intConstant - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIntConstant([NotNull] CGrammarParser.IntConstantContext context); - /// - /// Visit a parse tree produced by the hexConstant - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitHexConstant([NotNull] CGrammarParser.HexConstantContext context); - /// - /// Visit a parse tree produced by the charConstant - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitCharConstant([NotNull] CGrammarParser.CharConstantContext context); - /// - /// Visit a parse tree produced by the stringConstant - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitStringConstant([NotNull] CGrammarParser.StringConstantContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitType([NotNull] CGrammarParser.TypeContext context); - /// - /// Visit a parse tree produced by the indexerTarget - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitIndexerTarget([NotNull] CGrammarParser.IndexerTargetContext context); - /// - /// Visit a parse tree produced by the variableTarget - /// labeled alternative in . - /// - /// The parse tree. - /// The visitor result. - Result VisitVariableTarget([NotNull] CGrammarParser.VariableTargetContext context); -} 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 diff --git a/Compiler/visitors/Definitions.cs b/Compiler/visitors/Definitions.cs deleted file mode 100644 index c27405e..0000000 --- a/Compiler/visitors/Definitions.cs +++ /dev/null @@ -1,132 +0,0 @@ -namespace Q1.Compiler.visitors; - -public partial class CCompilerVisitor -{ - private List<(CGrammarParser.FunctionDefinitionContext context, - FunctionReference function, FunctionOverload overload, - List paramNames, List paramTypes)> _functionBodies = new(); - - private VariableReference FindVariable(string varName) - { - foreach (Dictionary variables in this._variableStack) - { - if (variables.TryGetValue(varName, out VariableReference? reference)) - return reference; - } - - throw new CompilerException($"Variable {varName} could not be found in current scope."); - } - private int Alloc(int size) - { - int loc = CCompilerVisitor._memPointer; - CCompilerVisitor._memPointer += size; - - return loc; - } - private FunctionReference CreateOrGetFunctionReference(string name, CType type) - { - FunctionReference? function = this._methods.FirstOrDefault(x => x.Name == name); - if (function != null) - return function; - - function = new FunctionReference(name, type); - this._methods.Add(function); - - return function; - } - private FunctionReference GetFunctionReference(string name) - { - FunctionReference? function = this._methods.FirstOrDefault(x => x.Name == name); - if (function != null) - return function; - - throw new CompilerException($"Function '{name}' has not been defined or prototyped."); - } - - public override string? VisitFunctionPrototype(CGrammarParser.FunctionPrototypeContext context) - { - string functionName = context.name.Text; - CType type = this.VisitCType(context._type); - - List parameterTypes = context._types.Select(this.VisitCType).ToList(); - List parameterNames = context._params.Select(x => x.Text).ToList(); - - FunctionReference function = this.CreateOrGetFunctionReference(functionName, type); - FunctionOverload overload = - function.CreateOverloadWithoutBody(parameterNames, parameterTypes); - - function.Overloads.Add(overload); - - return null; - } - public override string? VisitFunctionDefinition( - CGrammarParser.FunctionDefinitionContext context) - { - string functionName = context.name.Text; - CType type = this.VisitCType(context.rtype); - - List paramTypes = context._types.Select(this.VisitCType).ToList(); - List paramNames = context._params.Select(x => x.Text).ToList(); - - FunctionReference function = this.CreateOrGetFunctionReference(functionName, type); - FunctionOverload overload = function.CreateOverloadWithBody(paramNames, paramTypes); - - this._functionBodies.Add((context, function, overload, paramNames, paramTypes)); - - return null; - } - private void VisitFunctionBody( - CGrammarParser.FunctionDefinitionContext context, - FunctionReference function, - FunctionOverload overload, - List paramNames, - List paramTypes) - { - this.Branch(function.GetBranchName(overload), function.GetBranchFriendlyName(overload)); - - if (paramNames.Count > 0) - this.Instruction("pop V0", "preserve function return address"); - - Dictionary scope = this.EnterScope(); - foreach ((string paramName, CType paramType) in paramNames.Zip(paramTypes)) - { - int addr = this.Alloc(paramType.Size); - scope[paramName] = new(addr, paramType); - this.Instruction($"pop [${addr:X4}]", $"param {paramType} {paramName}"); - } - - if (paramNames.Count > 0) - this.Instruction("push V0", "restore function return address"); - - this.VisitChildren(context); - this.ExitScope(); - - this.Instruction("mov 0, V0", "fallback return 0"); - this.Instruction("ret"); - - this.Blank(); - } - public override string? VisitVariableDeclaration( - CGrammarParser.VariableDeclarationContext context) - { - CType type = this.VisitCType(context.type()); - int addr = this.Alloc(CType.Int.Size); - string name = context.name.Text; - - Dictionary scope = this._variableStack.Peek(); - if (scope.ContainsKey(name)) - throw new CompilerException($"Variable {name} already exists in current scope."); - - scope[name] = new VariableReference(addr, type); - string initialValue = "0"; - - if (context.value != null) - { - initialValue = this.VisitExpression(context.value); - } - - this.DynamicMove(CType.Int, initialValue, $"[${addr:X4}]", $"int {name} = {initialValue}"); - - return null; - } -} \ No newline at end of file diff --git a/Compiler/visitors/Expressions.cs b/Compiler/visitors/Expressions.cs deleted file mode 100644 index 1cc4291..0000000 --- a/Compiler/visitors/Expressions.cs +++ /dev/null @@ -1,154 +0,0 @@ -namespace Q1.Compiler.visitors; - -public partial class CCompilerVisitor -{ - private string VisitExpression(CGrammarParser.ExpressionContext expression) - { - string? expressionString = this.Visit(expression) as string; - if (expressionString == null) - throw new CompilerException("Expression did not return a string"); - - return expressionString; - } - - public override string VisitCallExpression(CGrammarParser.CallExpressionContext context) - { - string functionName = context.ID().GetText(); - - FunctionReference function = this.GetFunctionReference(functionName); - FunctionOverload overload = function.GetOverload(context._params.Count); - - // We reverse arugments so when we perform pop, its in the right order - CGrammarParser.ExpressionContext[] argumentsReversed = context._params.Reverse().ToArray(); - - for (int i = 0; i < argumentsReversed.Length; i++) - { - CGrammarParser.ExpressionContext argument = argumentsReversed[i]; - string result = this.VisitExpression(argument); - - int indexReverse = argumentsReversed.Length - i - 1; - - this.Instruction( - $"push {result}", $"arg {overload.ParameterTypes[indexReverse]} {overload.ParameterNames[indexReverse]}"); - } - - this.Instruction( - $"call {function.GetBranchName(overload)}", function.GetBranchFriendlyName(overload)); - - return "V0"; - } - public override string VisitParenthesizedExpression( - CGrammarParser.ParenthesizedExpressionContext context) - { - return this.VisitExpression(context.expression()); - } - public override string VisitVariableExpression(CGrammarParser.VariableExpressionContext context) - { - string varName = context.ID().GetText(); - VariableReference reference = this.FindVariable(varName); - - return $"[${reference.Address:X4}]"; - } - public override string VisitAssignmentExpression( - CGrammarParser.AssignmentExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - string value = this.VisitExpression(context.expression()); - - this.DynamicMove(target.Type, value, target.Value, $"{target.Value} = {value}"); - return target.Value; - } - public override string VisitTernaryExpression(CGrammarParser.TernaryExpressionContext context) - { - string cond = this.VisitExpression(context.cond); - - string thenBranch = this.GenerateBranchLabel("then"); - string endBranch = this.GenerateBranchLabel("end"); - string result; - - // Else branch is first since it saves us from having to perform a NOT operation. - // If cond, jump to then, else fall through to else, then jump to end - - this.Instruction($"bz {cond}", "check ternary condition"); - this.Instruction($"jmp {thenBranch}"); - - result = this.VisitExpression(context.@else); - this.Instruction($"mov {result}, V0", "store ternary fail result"); - this.Instruction($"jmp {endBranch}"); - - this.Branch(thenBranch); - result = this.VisitExpression(context.then); - this.Instruction($"mov {result}, V0", "store ternary success result"); - - this.Branch(endBranch); - - return "V0"; - } - public override string VisitAddressOfExpression( - CGrammarParser.AddressOfExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - - return target.Address; - } - public override string VisitDereferenceExpression( - CGrammarParser.DereferenceExpressionContext context) - { - string value = this.VisitExpression(context.expression()); - - this.Instruction($"mov {value}, V0", "move pointer into register for dereference"); - return "[V0]"; - } - - public override object? VisitIndexExpression(CGrammarParser.IndexExpressionContext context) - { - Target obj = this.VisitTarget(context.obj); - if (obj.Type is not CTypePtr ptr) - throw new CompilerException("Indexer target was not a pointer!"); - - this.Instruction($"push {obj.Value}", "store index obj"); - - string indexer = this.VisitExpression(context.indexer); - - this.Instruction($"mov {indexer}, V1", "store indexer"); - this.Instruction($"pop V0", "restore index obj"); - this.Instruction($"mul V1, {ptr.Sub.Size}", $"multiply indexer by {ptr.Sub.Size}"); - this.Instruction($"add AX, V0", "add indexer and index obj"); - this.Instruction($"mov AX, V0", "move to general purpose register"); - return "[V0]"; - } - - public override object? VisitArrayExpression(CGrammarParser.ArrayExpressionContext context) - { - CType type = this.VisitCType(context.type()); - int? arrPtr = null; - - int length = context.INT() != null - ? int.Parse(context.INT().GetText()) - : context._params.Count; - - if (length == 0) - throw new CompilerException("Cannot create empty array"); - - foreach (CGrammarParser.ExpressionContext? param in context._params) - { - int itemPtr = Alloc(type.Size); - - if (arrPtr == null) - arrPtr = itemPtr; - - string value = this.VisitExpression(param); - this.DynamicMove(type, value, $"[${itemPtr:X4}]"); - } - - int remainingSize = (length - context._params.Count) * type.Size; - if (remainingSize < 0) - throw new CompilerException("Array length larger than specified length"); - int blockPtr = Alloc(remainingSize); - - if (arrPtr == null) - arrPtr = blockPtr; - - return $"${arrPtr:X4}"; - } -} \ No newline at end of file diff --git a/Compiler/visitors/FlowControl.cs b/Compiler/visitors/FlowControl.cs deleted file mode 100644 index 944595d..0000000 --- a/Compiler/visitors/FlowControl.cs +++ /dev/null @@ -1,177 +0,0 @@ -namespace Q1.Compiler.visitors; - -public partial class CCompilerVisitor -{ - public override string? VisitBlock(CGrammarParser.BlockContext context) - { - this.EnterScope(); - - this.VisitChildren(context); - - this.ExitScope(); - - return null; - } - public override string? VisitReturnStatement(CGrammarParser.ReturnStatementContext context) - { - if (context.expression() != null) - { - string expression = this.VisitExpression(context.expression()); - this.Instruction($"mov {expression}, V0", "return value"); - this.Instruction($"ret"); - } - else - this.Instruction("ret"); - - return null; - } - public override string? VisitIfStatement(CGrammarParser.IfStatementContext context) - { - string cond = this.VisitExpression(context.expression()); - string endBranch = this.GenerateBranchLabel("end"); - - if (context.@else != null) - { - this.Instruction($"bz {cond}", "check if condition"); - // Else branch is first since it saves us from having to perform a NOT operation. - // If cond, jump to then, else fall through to else, then jump to end - - string thenBranch = this.GenerateBranchLabel("then"); - - this.Instruction($"jmp {thenBranch}"); - - this.GeneratedComment("if failed"); - if (context.@else != null) - this.Visit(context.@else); - this.Instruction($"jmp {endBranch}"); - - this.Branch(thenBranch, "if succeeded"); - this.Visit(context.then); - } - else - { - this.Instruction($"not {cond}"); - this.Instruction($"bz", "check if condition"); - this.Instruction($"jmp {endBranch}", "if succeeds, continue, else jump to end"); - this.Visit(context.then); - } - - this.Branch(endBranch); - - return null; - } - public override string? VisitForExprStatement(CGrammarParser.ForExprStatementContext context) - { - string bodyBranch = this.GenerateBranchLabel("body"); - string endBranch = this.GenerateBranchLabel("end"); - - context.LoopBodyBranch = bodyBranch; - context.LoopEndBranch = endBranch; - - this.EnterScope(); - this.Visit(context.initializer); - - this.Branch(bodyBranch); - string cond = this.VisitExpression(context.cond); - - this.Instruction($"not {cond}"); - this.Instruction($"bz"); - this.Instruction($"jmp {endBranch}", "if for condition fails, jump to end"); - - this.Visit(context.body); - this.Visit(context.post); - - this.Branch(endBranch); - this.ExitScope(); - - return null; - } - public override string? VisitForDeclStatement(CGrammarParser.ForDeclStatementContext context) - { - string bodyBranch = this.GenerateBranchLabel("body"); - string endBranch = this.GenerateBranchLabel("end"); - - context.LoopBodyBranch = bodyBranch; - context.LoopEndBranch = endBranch; - - this.EnterScope(); - this.Visit(context.initializer); - - this.Branch(bodyBranch); - string cond = this.VisitExpression(context.cond); - - this.Instruction($"not {cond}"); - this.Instruction($"bz"); - this.Instruction($"jmp {endBranch}", "if for condition fails, jump to end"); - - this.Visit(context.body); - this.Visit(context.post); - - this.Instruction($"jmp {bodyBranch}"); - - this.Branch(endBranch); - this.ExitScope(); - - return null; - } - public override string? VisitWhileStatement(CGrammarParser.WhileStatementContext context) - { - string bodyBranch = this.GenerateBranchLabel("body"); - string endBranch = this.GenerateBranchLabel("end"); - - context.LoopBodyBranch = bodyBranch; - context.LoopEndBranch = endBranch; - - this.Branch(bodyBranch); - string cond = this.VisitExpression(context.cond); - - this.Instruction($"not {cond}"); - this.Instruction($"bz"); - this.Instruction($"jmp {endBranch}", "if while condition fails, jump to end"); - - this.Visit(context.body); - this.Instruction($"jmp {bodyBranch}"); - - this.Branch(endBranch); - - return null; - } - public override string? VisitDoWhileStatement(CGrammarParser.DoWhileStatementContext context) - { - string bodyBranch = this.GenerateBranchLabel("body"); - string endBranch = this.GenerateBranchLabel("end"); - - context.LoopBodyBranch = bodyBranch; - context.LoopEndBranch = endBranch; - - this.Branch(bodyBranch); - this.Visit(context.body); - - string cond = this.VisitExpression(context.cond); - - this.Instruction($"bz {cond}"); - this.Instruction($"jmp {bodyBranch}", "if while condition succeeds, jump back to start"); - - this.Branch(endBranch); - - return null; - } - public override string? VisitBreakStatement(CGrammarParser.BreakStatementContext context) - { - if (context.LoopEndBranch == null) - throw new CompilerException("Cannot break, not inside loop with end"); - - this.Instruction($"jmp {context.LoopEndBranch}", "break"); - - return null; - } - public override string? VisitContinueStatement(CGrammarParser.ContinueStatementContext context) - { - if (context.LoopBodyBranch == null) - throw new CompilerException("Cannot skip body (continue), not inside loop with body"); - - this.Instruction($"jmp {context.LoopBodyBranch}", "continue"); - - return null; - } -} \ No newline at end of file diff --git a/Compiler/visitors/Main.cs b/Compiler/visitors/Main.cs deleted file mode 100644 index 3b32399..0000000 --- a/Compiler/visitors/Main.cs +++ /dev/null @@ -1,183 +0,0 @@ -namespace Q1.Compiler.visitors; - -using System.Text; -using Antlr4.Runtime.Tree; -using Q1.Emulator; - -public partial class CCompilerVisitor : CGrammarBaseVisitor -{ - private int _branchCount = 1; - private List _instructions = new(); - private Stack> _variableStack = new(); - private List _methods = new(); - private static int _memLowest = Q1Layout.FreeMemoryStart; - private static int _memPointer = CCompilerVisitor._memLowest; - - private const int ColumnWidth = 30; - - public readonly CommentCompilationMode CommentMode; - - public CCompilerVisitor(CommentCompilationMode commentMode, Encoding encoding) - { - this.CommentMode = commentMode; - this.Encoding = encoding; - } - - private string GenerateBranchLabel(string type) - { - return $"_{type}_{this._branchCount++}"; - } - private void Instruction(string instruction, string? generatedComment = null) - { - this._instructions.Add($" {instruction}"); - if (generatedComment != null) - this.CommentLastInstruction(generatedComment); - } - private void Blank() - { - this._instructions.Add(""); - } - private void Branch(string name, string? generatedComment = null) - { - this._instructions.Add($"{name}:"); - if (generatedComment != null) - this.CommentLastInstruction(generatedComment); - } - private void UserComment(string comment) - { - if (this.CommentMode.HasFlag(CommentCompilationMode.UserDefined)) - this._instructions.Add($" ; {comment}"); - } - - private void GeneratedComment(string comment) - { - if (this.CommentMode.HasFlag(CommentCompilationMode.Generated)) - this._instructions.Add($"{"".PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"); - } - - private void CommentLastInstruction(string comment) - { - if (!this.CommentMode.HasFlag(CommentCompilationMode.Generated)) - return; - - if (this._instructions.Count == 0) - throw new Exception("Cannot add comment to last instruction, there are none"); - - string lastInstruction = this._instructions[^1]; - lastInstruction = $"{lastInstruction.PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"; - - this._instructions[^1] = lastInstruction; - } - - - public IEnumerable Compile(CGrammarParser.ProgramContext program) - { - this.Instruction("jmp _main"); - this.Visit(program); - - foreach ((CGrammarParser.FunctionDefinitionContext context, - FunctionReference function, FunctionOverload overload, - List paramNames, List paramTypes) in this._functionBodies) - this.VisitFunctionBody(context, function, overload, paramNames, paramTypes); - - return this._instructions; - } - - private Dictionary EnterScope() - { - Dictionary scope = new(); - this._variableStack.Push(scope); - - return scope; - } - private void ExitScope() - { - foreach ((string key, VariableReference value) in this._variableStack.Peek()) - { - // CCompilerVisitor._memPointer -= value.Type.Size; - // if (CCompilerVisitor._memPointer < CCompilerVisitor._memLowest) - // throw new CompilerException("Memory pointer is lower than mem lowest!"); - } - - // Delete scope - this._variableStack.Pop(); - } - - public void DynamicMove(CType type, string source, string dest, string? comment = null) - { - if (type.Size == 1) - this.Instruction($"movb {source}, {dest}", comment); - else if (type.Size == 2) - this.Instruction($"mov {source}, {dest}", comment); - else - throw new CompilerException($"Cannot move {type.Size} bytes {source} to {dest}"); - } - - private CType VisitCType(CGrammarParser.TypeContext typeContext) - { - return GetCType(typeContext.GetText().Trim()); - } - - private CType GetCType(string type) - { - return type switch - { - "int" => CType.Int, - "char" => CType.Char, - _ when type.EndsWith("*") => new CTypePtr(this.GetCType(type[..^1])), - _ => throw new CompilerException($"Unknown CTYPE '{type}'") - }; - } - - public override object? VisitErrorNode(IErrorNode node) - { - if (node.Symbol.Type == CGrammarParser.COMMENT) - { - // strip // and \n and whitespace - string comment = node - .Symbol.Text - .TrimStart("//") - .TrimEnd('\n') - .Trim(); - - this.UserComment(comment); - } - - if (node.Symbol.Type == CGrammarParser.DIRECTIVE) - { - // strip // and \n and whitespace - string directive = node - .Symbol.Text - .TrimStart("#") - .TrimEnd('\n') - .Trim(); - - this.Instruction(directive); - } - - return base.VisitErrorNode(node); - } - - public override object? Visit(IParseTree tree) - { - if (tree is Context childCtx && tree.Parent is Context ctx) - ctx.SyncProps(childCtx); - - return base.Visit(tree); - } - - /// - /// Basically identical to base version, except calls Visit on each child, making Visit not redundant. - /// - public override object? VisitChildren(IRuleNode node) - { - object? result = this.DefaultResult; - int childCount = node.ChildCount; - for (int i = 0; i < childCount && this.ShouldVisitNextChild(node, result); ++i) - { - object? nextResult = this.Visit(node.GetChild(i)); - result = this.AggregateResult(result, nextResult); - } - return result; - } -} \ No newline at end of file diff --git a/Compiler/visitors/Operations.cs b/Compiler/visitors/Operations.cs deleted file mode 100644 index 8483747..0000000 --- a/Compiler/visitors/Operations.cs +++ /dev/null @@ -1,305 +0,0 @@ -namespace Q1.Compiler.visitors; - -public partial class CCompilerVisitor -{ - private void BaseBinaryOperation(CGrammarParser.ExpressionContext leftExpr, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName) - { - string left = this.VisitExpression(leftExpr); - - this.Instruction($"push {left}", "left operand"); - - string right = this.VisitExpression(rightExpr); - - this.Instruction($"mov {right}, V1", "right operand"); - this.Instruction($"pop V0", "get left operand back"); - this.Instruction($"{operation} V0, V1", $"compute {operationFriendlyName}"); - } - - private string BaseBinaryCompoundOperation(CGrammarParser.TargetContext leftTarget, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName, string operationOutput) - { - Target left = this.VisitTarget(leftTarget); - - this.Instruction($"push {left.Value}", "left operand"); - - string? right = this.VisitExpression(rightExpr); - if (right == null) - throw new CompilerException($"Right operand for {operationFriendlyName} was not an expression."); - - this.Instruction($"mov {right}, V1", "right operand"); - this.Instruction($"pop V0", "get left operand back"); - this.Instruction($"{operation} V0, V1", $"compute {operationFriendlyName}"); - - this.Instruction($"push {operationOutput}", "computation results"); - - left = this.VisitTarget(leftTarget); - this.Instruction("pop V1", "get computation results back"); - this.DynamicMove(left.Type, "V1", left.Value, "store back into left param"); - - return left.Value; - } - - public override string VisitNotExpression(CGrammarParser.NotExpressionContext context) - { - string value = this.VisitExpression(context.expression()); - - this.Instruction($"not {value}"); - return "LX"; - } - public override string VisitInvertExpression(CGrammarParser.InvertExpressionContext context) - { - string value = this.VisitExpression(context.expression()); - - this.Instruction($"inv {value}"); - return "DX"; - } - public override string VisitAddExpression(CGrammarParser.AddExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "add", "addition"); - return "AX"; - } - public override string VisitSubtractExpression(CGrammarParser.SubtractExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "sub", "subtraction"); - return "AX"; - } - public override string VisitMultiplyExpression(CGrammarParser.MultiplyExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "mul", "multiplication"); - return "AX"; - } - public override string VisitDivideExpression(CGrammarParser.DivideExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "div", "division"); - return "AX"; - } - public override string VisitModulusExpression(CGrammarParser.ModulusExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "mod", "modulus"); - return "AX"; - } - public override string VisitEqualExpression(CGrammarParser.EqualExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - return "LX"; - } - public override string VisitNotEqualExpression(CGrammarParser.NotEqualExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "cmp", "inequality check"); - this.Instruction($"not"); // lx is implicit - return "LX"; - } - public override string VisitGreaterThanExpression(CGrammarParser.GreaterThanExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "gt", "greater than check"); - return "LX"; - } - public override string VisitLessThanExpression(CGrammarParser.LessThanExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "lt", "less than check"); - return "LX"; - } - public override string VisitLogicalOrExpression(CGrammarParser.LogicalOrExpressionContext context) - { - string left = this.VisitExpression(context.left); - - string clauseBranch = this.GenerateBranchLabel("clause"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction($"cmp {left}, 0", "logical or"); - this.Instruction("bz"); // implicit LX - this.Instruction($"jmp {clauseBranch}"); // only if bz is not 0 - this.Instruction("mov 1, V0", "first operand succeeded, store 1 and skip second operand"); - this.Instruction($"jmp {endBranch}"); - this.Branch(clauseBranch); - - string right = this.VisitExpression(context.right); - - this.Instruction($"cmp {right}, 0", "compare result from second operand to 0"); - this.Instruction("not"); - this.Instruction("mov LX, V0", "store second operand result"); - this.Branch(endBranch); - - return "V0"; - } - public override string VisitLogicalAndExpression(CGrammarParser.LogicalAndExpressionContext context) - { - string left = this.VisitExpression(context.left); - - string clauseBranch = this.GenerateBranchLabel("clause"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction($"cmp {left}, 0", "logical and"); - this.Instruction("not"); - this.Instruction("bz"); // implicit LX - this.Instruction($"jmp {clauseBranch}"); // only if bz is not 0 - this.Instruction("mov 0, V0", "first operand failed, store 0 and skip second"); - this.Instruction($"jmp {endBranch}"); - this.Branch(clauseBranch); - - string right = this.VisitExpression(context.right); - - this.Instruction($"cmp {right}, 0", "compare result from second operand to 0"); - this.Instruction("not"); - this.Instruction("mov LX, V0", "store second operand result"); - this.Branch(endBranch); - - return "V0"; - } - public override string VisitGreaterThanOrEqualExpression(CGrammarParser.GreaterThanOrEqualExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction("bz"); - this.Instruction($"jmp {endBranch}"); - this.Instruction($"gt V0, V1"); - this.Branch(endBranch); - - return "LX"; - } - public override string VisitLessThanOrEqualExpression(CGrammarParser.LessThanOrEqualExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction("bz"); - this.Instruction($"jmp {endBranch}"); - this.Instruction($"lt V0, V1"); - this.Branch(endBranch); - - return "LX"; - } - public override string VisitBitwiseXorExpression(CGrammarParser.BitwiseXorExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "xor", "exclusive or"); - return "DX"; - } - public override string VisitBitwiseOrExpression(CGrammarParser.BitwiseOrExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "or", "or"); - return "DX"; - } - public override string VisitBitwiseAndExpression(CGrammarParser.BitwiseAndExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "and", "and"); - return "DX"; - } - public override string VisitBitwiseLeftShiftExpression(CGrammarParser.BitwiseLeftShiftExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "shl", "left shift"); - return "DX"; - } - public override string VisitBitwiseRightShiftExpression(CGrammarParser.BitwiseRightShiftExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "shr", "right shift"); - return "DX"; - } - public override string VisitCompoundAddExpression(CGrammarParser.CompoundAddExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "add", - "addition", - "AX"); - } - public override string VisitCompoundSubtractExpression(CGrammarParser.CompoundSubtractExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "sub", - "subtraction", - "AX"); - } - public override string VisitCompoundMultiplyExpression(CGrammarParser.CompoundMultiplyExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "mul", - "multiplication", - "AX"); - } - public override string VisitCompoundDivideExpression(CGrammarParser.CompoundDivideExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "div", - "division", - "AX"); - } - public override string VisitCompoundModulusExpression(CGrammarParser.CompoundModulusExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "mod", - "modulus", - "AX"); - } - public override string VisitCompoundBitwiseOrExpression(CGrammarParser.CompoundBitwiseOrExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "or", - "or", - "DX"); - } - public override string VisitCompoundBitwiseXorExpression(CGrammarParser.CompoundBitwiseXorExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "xor", - "exclusive or", - "DX"); - } - public override string VisitCompoundBitwiseAndExpression(CGrammarParser.CompoundBitwiseAndExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "and", - "and", - "DX"); - } - public override string VisitCompoundBitwiseLeftShiftExpression(CGrammarParser.CompoundBitwiseLeftShiftExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "shl", - "left shift", - "DX"); - } - public override string VisitCompoundBitwiseRightShiftExpression(CGrammarParser.CompoundBitwiseRightShiftExpressionContext context) - { - return this.BaseBinaryCompoundOperation(context.target(), - context.expression(), - "shr", - "right shift", - "DX"); - } - public override string VisitIncrementPrefixExpression(CGrammarParser.IncrementPrefixExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - this.Instruction($"inc {target.Value}", "++i"); - return target.Value; - } - public override string VisitDecrementPrefixExpression(CGrammarParser.DecrementPrefixExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - this.Instruction($"dec {target.Value}", "--i"); - return target.Value; - } - public override string VisitIncrementPostfixExpression(CGrammarParser.IncrementPostfixExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - this.Instruction($"push {target.Value}", "i++"); - this.Instruction($"inc {target.Value}"); - this.Instruction("pop V0"); - return "V0"; - } - public override string VisitDecrementPostfixExpression(CGrammarParser.DecrementPostfixExpressionContext context) - { - Target target = this.VisitTarget(context.target()); - this.Instruction($"push {target.Value}", "i--"); - this.Instruction($"dec {target.Value}"); - this.Instruction($"pop V0"); - return "V0"; - } -} \ No newline at end of file diff --git a/Compiler/visitors/Targets.cs b/Compiler/visitors/Targets.cs deleted file mode 100644 index 10d97f4..0000000 --- a/Compiler/visitors/Targets.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace Q1.Compiler.visitors; - -public partial class CCompilerVisitor -{ - private Target VisitTarget(CGrammarParser.TargetContext target) - { - Target? expressionString = this.Visit(target) as Target; - if (expressionString == null) - throw new CompilerException("Target did not return a target"); - - return expressionString; - } - - public override Target VisitVariableTarget(CGrammarParser.VariableTargetContext context) - { - string varName = context.ID().GetText(); - VariableReference reference = this.FindVariable(varName); - - return new Target(reference.Type, $"[${reference.Address:X4}]", $"${reference.Address:X4}"); - } - - public override object? VisitIndexerTarget(CGrammarParser.IndexerTargetContext context) - { - Target obj = this.VisitTarget(context.obj); - if (obj.Type is not CTypePtr ptr) - throw new CompilerException("Indexer target was not a pointer!"); - - this.Instruction($"push {obj.Value}", "store index obj"); - - string indexer = this.VisitExpression(context.indexer); - - this.Instruction($"mov {indexer}, V1", "store indexer"); - this.Instruction($"pop V0", "restore index obj"); - this.Instruction($"mul V1, {ptr.Sub.Size}", $"multiply indexer by {ptr.Sub.Size}"); - this.Instruction($"add AX, V0", "add indexer and index obj"); - this.Instruction($"mov AX, V0", "move to general purpose register"); - - return new Target(ptr.Sub, $"[V0]", $"V0"); - } -} \ No newline at end of file diff --git a/Emulator/Assembler/Disassembler.cs b/Emulator/Assembler/Disassembler.cs deleted file mode 100644 index d49d2eb..0000000 --- a/Emulator/Assembler/Disassembler.cs +++ /dev/null @@ -1,74 +0,0 @@ -namespace Q1.Emulator.Assembler; - -using System; -using System.Collections.Generic; -using System.IO; -using Chip; - -public class Disassembler -{ - public readonly StringWriter Writer; - public readonly BinaryReader Reader; - - public Disassembler(StringWriter writer, BinaryReader reader) - { - this.Writer = writer; - this.Reader = reader; - } - - private static Dictionary ModeLookup = new() - { - { 0x00, "" }, - { 0x01, "c" }, - { 0x02, "[a]" }, - { 0x03, "@[a]" }, - { 0x04, "pc + c" }, - { 0x05, "r" }, - { 0x06, "[r]" }, - { 0x07, "[r + c]" }, - }; - - public static string ParseInstruction(u16 instruction) - { - u8 op = (u8) ((instruction >> 8) & 0xFF); // 256 opcodes - u8 m1 = (u8) ((instruction >> 4) & 0x0F); // 16 modes - u8 m2 = (u8) (instruction & 0x0F); // 16 modes - - u8 i = (m1, m2) switch - { - (0x00, 0x00) => 0, // Implicit - (0x00, 0x01) => 2, // Extended implicit - (_, 0x00) => 1, // Simple addressing mode - _ => 3 // Extended addressing mode - }; - - string opcodeName = Disassembler.GetOpcodeName(op, i); - - if (i == 0 || i == 2) - return opcodeName; - - if (i == 1) - return $"{opcodeName} {Disassembler.GetModeName(m1)}"; - - if (i == 3) - return $"{opcodeName} {Disassembler.GetModeName(m1)}, {Disassembler.GetModeName(m2)}"; - - throw new InvalidOperationException($"Unknown instruction format for opcode {op:X2} with modes {m1:X2}, {m2:X2}"); - } - - private static string GetOpcodeName(u8 opcode, u8 i) - { - if (!Q1Cpu.InstructionLookupStrings.TryGetValue(opcode, out string[]? opNames)) - return $"[{opcode:X2}]"; // Fallback for unknown opcodes - - return opNames[i]; - } - - private static string GetModeName(u8 mode) - { - if (Disassembler.ModeLookup.TryGetValue(mode, out string? modeName)) - return modeName; - - return $"[{mode:X2}]"; // Fallback for unknown modes - } -} \ No newline at end of file diff --git a/Emulator/Chip/Bus.cs b/Emulator/Chip/Bus.cs deleted file mode 100644 index 0907f61..0000000 --- a/Emulator/Chip/Bus.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System.Collections.Generic; -using System.Linq; - -public class Bus : BusDevice -{ - public List Devices; - - public Bus(u16 addressableStart, u16 addressableEnd) : base(addressableStart, addressableEnd) - { - this.Devices = []; - } - private BusDevice? GetDevice(u16 address) - { - BusDevice? device = this.Devices.FirstOrDefault(x => address >= x.AddressableStart && address < x.AddressableEnd); - return device; - } - - public override u8 Read(u16 address) - { - BusDevice? device = this.GetDevice(address); - if (device == null) - return 0; - - return device.Read(address); - } - - public override void Write(u16 address, u8 value) - { - BusDevice? device = this.GetDevice(address); - if (device == null) - return; - - device.Write(address, value); - } -} \ No newline at end of file diff --git a/Emulator/Chip/BusDevice.cs b/Emulator/Chip/BusDevice.cs deleted file mode 100644 index 1e1e972..0000000 --- a/Emulator/Chip/BusDevice.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System.Runtime.CompilerServices; - -public abstract class BusDevice -{ - public BusDevice(u16 addressableStart, u16 addressableEnd) - { - this.AddressableStart = addressableStart; - this.AddressableEnd = addressableEnd; - } - - public Bus Bus { get; set; } - public abstract u8 Read(u16 address); - public abstract void Write(u16 address, u8 value); - - public u16 ReadWord(u16 address) - { - u8 high = this.Read(address); - u8 low = this.Read((u16) (address + 1)); - u16 value = Make.u16(high, low); - return value; - } - - public void WriteWord(u16 address, u16 value) - { - ref8 data = Make.ref8(value); - this.Write(address, data[0]); - this.Write((u16) (address + 1), data[1]); - } - - public virtual void Clock() { } - public virtual void Reset() { } - - public void AttachToBus(Bus bus) - { - this.Bus = bus; - bus.Devices.Add(this); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected u16 GetRelativeAddress(u16 address) - { - return (u16) (address - this.AddressableStart); - } - - public u16 AddressableStart { get; } - public u16 AddressableEnd { get; } -} \ No newline at end of file diff --git a/Emulator/Chip/DisplayDevice.cs b/Emulator/Chip/DisplayDevice.cs deleted file mode 100644 index c8889ba..0000000 --- a/Emulator/Chip/DisplayDevice.cs +++ /dev/null @@ -1,94 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -public class DisplayDevice : RamDevice -{ - public Texture2D? OutputTexture; - - private readonly u16 _paletteSize; - private readonly u16 _displayWidth; - private readonly u16 _displayHeight; - - private Color[] textureData; - private Color[] palette; - private bool _paletteDirty; - - public DisplayDevice(u16 paletteSize, u16 displayWidth, u16 displayHeight, u16 addressableStart) - : base( - addressableStart, DisplayDevice.DetermineSize(paletteSize, displayWidth, displayHeight)) - { - this._paletteSize = paletteSize; - this._displayWidth = displayWidth; - this._displayHeight = displayHeight; - this.textureData = new Color[this._displayWidth * this._displayHeight]; - } - - public static u16 DetermineSize(u16 paletteSize, u16 displayWidth, u16 displayHeight) - { - return (u16) ((paletteSize * 3) + (displayWidth * displayHeight)); - } - - public override void Clock() - { - if (this._paletteDirty) - this.ReadPalette(); - - ref8 pixelData = this.Memory.AsSpan( - (u16) (this._paletteSize * 3), (u16) (this._displayWidth * this._displayHeight)); - - for (u16 i = 0; i < this.textureData.Length; i++) - { - u8 pixelValue = pixelData[i]; - this.textureData[i] = palette[pixelValue % this._paletteSize]; - } - - if (this.OutputTexture != null) - this.OutputTexture.SetData(this.textureData); - } - - private void ReadPalette() - { - ref8 paletteData = this.Memory.AsSpan(0, (u16) (this._paletteSize * 3)); - Color[] colors = new Color[this._paletteSize + 1]; - colors[0] = Color.Transparent; - - for (u16 i = 0; i < this._paletteSize; i++) - { - u16 offset = (u16) (i * 3); - byte r = paletteData[offset]; - byte g = paletteData[offset + 1]; - byte b = paletteData[offset + 2]; - colors[(u16) (i + 1)] = new Color(r, g, b); - } - - this._paletteDirty = false; - this.palette = colors; - } - - public void SetPalette(Color[] palette) - { - if (palette.Length != this._paletteSize) - throw new ArgumentException($"Palette must have {this._paletteSize} colors."); - - ref8 paletteData = this.Memory.AsSpan(0, (u16) (this._paletteSize * 3)); - for (u16 i = 0; i < this._paletteSize; i++) - { - u16 offset = (u16) (i * 3); - paletteData[offset] = palette[i].R; - paletteData[offset + 1] = palette[i].G; - paletteData[offset + 2] = palette[i].B; - } - - this._paletteDirty = true; - } - - public override u8 Read(u16 address) => base.Read(address); - public override void Write(u16 address, u8 value) - { - this._paletteDirty = true; - base.Write(address, value); - } -} \ No newline at end of file diff --git a/Emulator/Chip/GraphicsDevice.cs b/Emulator/Chip/GraphicsDevice.cs deleted file mode 100644 index 0f649ac..0000000 --- a/Emulator/Chip/GraphicsDevice.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Q1.Emulator.Chip; - -public class GraphicsDevice -{ - -} \ No newline at end of file diff --git a/Emulator/Chip/HIDDevice.cs b/Emulator/Chip/HIDDevice.cs deleted file mode 100644 index c8a7d04..0000000 --- a/Emulator/Chip/HIDDevice.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System; - -public class HIDDevice : RamDevice -{ - public HIDDevice(u16 start) : base(start, HIDDevice.CalculateSize()) { } - - public static u16 CalculateSize() - { - return 4 + 256; - } - - public void SetMouse(u16 positionalIndex, bool leftDown, bool rightDown, bool middleDown) - { - this.WriteWord(this.AddressableStart, positionalIndex); - u16 buttons = (u16) ((leftDown ? 1 : 0) - | ((rightDown ? 1 : 0) << 1) - | ((middleDown ? 1 : 0) << 2)); - this.WriteWord((u16) (this.AddressableStart + 2), buttons); - } - - public void SetKeyboard(u8 scanCode, bool pressed) - { - int index = scanCode >> 3; // keyCode / 8 - int bit = scanCode & 7; // keyCode % 8 - - ushort addr = (ushort) (4 + index); - u8 value = this.Read((u16) (this.AddressableStart + addr)); - - if (pressed) - value |= (u8) (1 << bit); - else - value &= (u8) ~(1 << bit); - - this.Write((u16) (this.AddressableStart + addr), value); - } - - public bool GetKeyboard(int scanCode) - { - int index = scanCode >> 3; - int bit = scanCode & 7; - - ushort addr = (ushort) (4 + index); - byte value = this.Read((u16) (this.AddressableStart + addr)); - - return (value & (1 << bit)) != 0; - } -} \ No newline at end of file diff --git a/Emulator/Chip/Q1Cpu.cs b/Emulator/Chip/Q1Cpu.cs deleted file mode 100644 index 81f9908..0000000 --- a/Emulator/Chip/Q1Cpu.cs +++ /dev/null @@ -1,167 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System; -using Assembler; - -public partial class Q1Cpu -{ - public Random Random; - - public u16 AX = 0; // Accumulator register - public u16 DX = 0; // Data register - public u16 LX = 0; // Logical register - - public u16 SP { get; set; } // Stack pointer - public u16 PC { get; set; } // Program counter - - public u16[] V { get; set; } // Variable registers (64 total) - public u16 Cycles { get; set; } // Number of cycles - - public Bus Bus { get; set; } - public bool AbortRequested = false; - - public Q1Cpu() - { - this.LoadInstructionLookup(); - } - - public void Reset() - { - this.AbortRequested = false; - - this.V = new u16[64]; - - this.SP = Q1Layout.StackStart; - this.PushStack(0xFFFF); - - this.PC = Q1Layout.ProgramStart; - } - - public void Clock() - { - var pc = this.PC; - if (pc == 0xFFFF) - { - this.AbortRequested = true; - return; - } - - u16 instruction = this.FetchInstruction(out u8 op, out u8 m1, out u8 m2, out _); - // if (instruction != 0x0101) - // Console.WriteLine($"CPU.Clock: {pc:X4} | {Disassembler.ParseInstruction(instruction)}"); - - bool ex = m2 > 0; - switch (m1, ex) - { - case (0x00, false): - this.InstructionLookup[op].Item1(); // Implicit - break; - case (> 0x00, false): - this.InstructionLookup[op].Item2(m1); // Simple addressing mode - break; - case (0x00, true): - this.InstructionLookup[op].Item3(); // Extended implicit - break; - case (> 0x00, true): - this.InstructionLookup[op].Item4(m1, m2); // Extended addressing mode - break; - } - - this.Cycles++; - } - public u16 FetchInstruction(out u8 op, out u8 m1, out u8 m2, out u8 length) - { - u16 instruction = this.Bus.ReadWord(this.PC); - this.PC += 2; - - op = (u8) ((instruction >> 8) & 0xFF); // 256 opcodes - m1 = (u8) ((instruction >> 4) & 0x0F); // 16 modes - m2 = (u8) (instruction & 0x0F); // 16 modes - - length = (u8) (this.AddressingModeLength(m1) + this.AddressingModeLength(m2)); - return instruction; - } - - private void PushStack(u16 value) - { - if (this.SP + 2 >= Q1Layout.StackStart + Q1Layout.StackLength) - throw new InvalidOperationException("Stack overflow"); - - this.Bus.WriteWord(this.SP, value); - this.SP += 2; - } - - private u16 PopStack() - { - if (this.SP - 2 < Q1Layout.StackStart) - throw new InvalidOperationException("Stack underflow"); - - this.SP -= 2; - return this.Bus.ReadWord(this.SP); - } - - private u16 FetchRegister(u8 regIndex) - { - return regIndex switch - { - <= 0x3F => this.V[regIndex], - - 0x40 => this.AX, - 0x41 => (u16) (this.AX >> 8), // High byte of AX - 0x42 => (u16) (this.AX & 0xFF), // Low byte of AX - - 0x43 => this.DX, - 0x44 => (u16) (this.DX >> 8), // High byte of DX - 0x45 => (u16) (this.DX & 0xFF), // Low byte of DX - - 0x46 => this.LX, - 0x50 => this.PC, - 0x51 => this.SP, - - _ => throw new InvalidOperationException($"Unknown register index: {regIndex:X2}"), - }; - } - - private void StoreRegister(u8 regIndex, u16 value) - { - switch (regIndex) - { - case <= 0x3F: - this.V[regIndex] = value; - break; - - case 0x40: - this.AX = value; - break; - case 0x41: - this.AX = (u16) ((this.AX & 0x00FF) | (value << 8)); - break; // Set high byte - case 0x42: - this.AX = (u16) ((this.AX & 0xFF00) | (value & 0x00FF)); - break; // Set low byte - - case 0x43: - this.DX = value; - break; - case 0x44: - this.DX = (u16) ((this.DX & 0x00FF) | (value << 8)); - break; // Set high byte - case 0x45: - this.DX = (u16) ((this.DX & 0xFF00) | (value & 0x00FF)); - break; // Set low byte - - case 0x46: - this.LX = value; - break; - case 0x50: - this.PC = value; - break; - case 0x51: - this.SP = value; - break; - - default: - throw new InvalidOperationException($"Unknown register index: {regIndex:X2}"); - } - } -} \ No newline at end of file diff --git a/Emulator/Chip/Q1CpuAddressingModes.cs b/Emulator/Chip/Q1CpuAddressingModes.cs deleted file mode 100644 index 40020f1..0000000 --- a/Emulator/Chip/Q1CpuAddressingModes.cs +++ /dev/null @@ -1,187 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System; - -public partial class Q1Cpu -{ - public (Func read, Action write, Action writeByte) Address(u8 mode) - { - return mode switch - { - 0x0 => this.AddressingMode_Implicit(), - 0x1 => this.AddressingMode_Immediate(), - 0x2 => this.AddressingMode_Direct(), - 0x3 => this.AddressingMode_Indirect(), - 0x4 => this.AddressingMode_Relative(), - 0x5 => this.AddressingMode_Register(), - 0x6 => this.AddressingMode_RegisterIndirect(), - 0x7 => this.AddressingMode_RegisterIndirectOffset(), - _ => throw new InvalidOperationException($"Unknown addressing mode: {mode:X2}"), - }; - } - - private u8 AddressingModeLength(u8 mode) - { - return mode switch - { - 0x0 => 0, // Implicit - 0x1 => 2, // Immediate - 0x2 => 2, // Direct - 0x3 => 2, // Indirect - 0x4 => 2, // Relative - 0x5 => 1, // Register - 0x6 => 1, // Register indirect - 0x7 => 3, // Register indirect with offset - _ => throw new InvalidOperationException($"Unknown addressing mode: {mode:X2}"), - }; - } - - public (Func read, Action write, Action writeByte) AddressingMode_Implicit() - { - u16 Read() => throw new InvalidOperationException("Cannot read from implicit mode."); - void Write(u16 value) => throw new InvalidOperationException("Cannot write to implicit mode."); - void WriteByte(u8 value) => throw new InvalidOperationException("Cannot write byte to implicit mode."); - - return (Read, Write, WriteByte); - } - - - public (Func read, Action write, Action writeByte) AddressingMode_Immediate() - { - u16 value = this.Bus.ReadWord(this.PC); - this.PC += 2; - - u16 Read() => value; - void Write(u16 v) => throw new InvalidOperationException("Cannot write to immediate mode."); - void WriteByte(u8 v) => throw new InvalidOperationException("Cannot write byte to immediate mode."); - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_Direct() - { - u16 address = this.Bus.ReadWord(this.PC); - this.PC += 2; - - u16 Read() => this.Bus.ReadWord(address); - void Write(u16 value) => this.Bus.WriteWord(address, value); - void WriteByte(u8 value) => this.Bus.Write(address, value); - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_Indirect() - { - u16 address = this.Bus.ReadWord(this.PC); - this.PC += 2; - - u16 Read() - { - u16 indirectAddress = this.Bus.ReadWord(address); - u16 value = this.Bus.ReadWord(indirectAddress); - return value; - } - - void Write(u16 value) - { - u16 indirectAddress = this.Bus.ReadWord(address); - this.Bus.WriteWord(indirectAddress, value); - } - - void WriteByte(u8 value) - { - u16 indirectAddress = this.Bus.ReadWord(address); - this.Bus.Write(indirectAddress, value); - } - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_Relative() - { - u16 offset = this.Bus.ReadWord(this.PC); - this.PC += 2; - - u16 address = (u16) (this.PC + offset); - - u16 Read() => address; - void Write(u16 value) => throw new InvalidOperationException("Cannot write to relative mode."); - void WriteByte(u8 value) => throw new InvalidOperationException("Cannot write byte to relative mode."); - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_Register() - { - u8 regIndex = this.Bus.Read(this.PC); - this.PC += 1; - - u16 Read() => this.FetchRegister(regIndex); - void Write(u16 value) => this.StoreRegister(regIndex, value); - void WriteByte(u8 value) - { - u16 currentValue = this.FetchRegister(regIndex); - u16 newValue = (u16) ((currentValue & 0xFF00) | (value & 0x00FF)); // Update low byte - this.StoreRegister(regIndex, newValue); - } - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_RegisterIndirect() - { - u8 regIndex = this.Bus.Read(this.PC); - this.PC += 1; - - u16 Read() - { - u16 address = this.FetchRegister(regIndex); - u16 value = this.Bus.ReadWord(address); - return value; - } - - void Write(u16 value) - { - u16 address = this.FetchRegister(regIndex); - this.Bus.WriteWord(address, value); - } - - void WriteByte(u8 value) - { - u16 address = this.FetchRegister(regIndex); - this.Bus.Write(address, value); - } - - return (Read, Write, WriteByte); - } - - public (Func read, Action write, Action writeByte) AddressingMode_RegisterIndirectOffset() - { - u8 regIndex = this.Bus.Read(this.PC); - this.PC += 1; - - u16 offset = this.Bus.ReadWord(this.PC); - this.PC += 2; - - u16 Read() - { - u16 address = (u16) (this.FetchRegister(regIndex) + offset); - u16 value = this.Bus.ReadWord(address); - return value; - } - - void Write(u16 value) - { - u16 address = (u16) (this.FetchRegister(regIndex) + offset); - this.Bus.WriteWord(address, value); - } - - void WriteByte(u8 value) - { - u16 address = (u16) (this.FetchRegister(regIndex) + offset); - this.Bus.Write(address, value); - } - - return (Read, Write, WriteByte); - } -} \ No newline at end of file diff --git a/Emulator/Chip/Q1CpuInstructions.cs b/Emulator/Chip/Q1CpuInstructions.cs deleted file mode 100644 index 0041b25..0000000 --- a/Emulator/Chip/Q1CpuInstructions.cs +++ /dev/null @@ -1,278 +0,0 @@ -namespace Q1.Emulator.Chip; - -using System; -using System.Collections.Generic; - -public partial class Q1Cpu -{ - public static Dictionary InstructionLookupStrings = new() - { - { 0x00, ["NOP", "JMP", "HALT", "MOV"] }, - { 0x01, ["RET", "CALL", "SUS", "MOVB"] }, - { 0x02, ["BZ", "BZ", "BR", "NOP"] }, - { 0x03, ["NOP", "PUSH", "NOP", "NOP"] }, - { 0x04, ["NOP", "POP", "NOP", "NOP"] }, - - { 0x10, ["INV", "INV", "NOP", "AND"] }, - { 0x11, ["NOP", "NOP", "NOP", "OR"] }, - { 0x12, ["NOP", "NOP", "NOP", "XOR"] }, - { 0x13, ["NOP", "NOP", "NOP", "SHL"] }, - { 0x14, ["NOP", "NOP", "NOP", "SHR"] }, - - { 0x20, ["NOT", "NOT", "NOP", "CMP"] }, - { 0x21, ["NOP", "NOP", "NOP", "LT"] }, - { 0x22, ["NOP", "NOP", "NOP", "GT"] }, - - { 0x30, ["INC_AX", "INC", "NOP", "ADD"] }, - { 0x31, ["DEC_AX", "DEC", "NOP", "SUB"] }, - { 0x32, ["NOP", "NOP", "NOP", "DIV"] }, - { 0x33, ["NOP", "NOP", "NOP", "MUL"] }, - { 0x34, ["NOP", "NOP", "NOP", "MOD"] }, - }; - - public Dictionary, Action, Action)> InstructionLookup; - private void LoadInstructionLookup() - { - this.InstructionLookup = new Dictionary, Action, Action)> - { - { 0x00, (this.Instruction_NOP, this.Instruction_JMP, this.Instruction_HALT, this.Instruction_MOV) }, - { 0x01, (this.Instruction_RET, this.Instruction_CALL, this.Instruction_SUS, this.Instruction_MOVB) }, - { 0x02, (this.Instruction_BZ_LX, this.Instruction_BZ, this.Instruction_BR, this.Instruction_NOP) }, - { 0x03, (this.Instruction_NOP, this.Instruction_PUSH, this.Instruction_NOP, this.Instruction_NOP) }, - { 0x04, (this.Instruction_NOP, this.Instruction_POP, this.Instruction_NOP, this.Instruction_NOP) }, - - { 0x10, (this.Instruction_INV_DX, this.Instruction_INV, this.Instruction_NOP, this.Instruction_AND) }, - { 0x11, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_OR) }, - { 0x12, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_XOR) }, - { 0x13, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_SHL) }, - { 0x14, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_SHR) }, - - { 0x20, (this.Instruction_NOT_LX, this.Instruction_NOT, this.Instruction_NOP, this.Instruction_CMP) }, - { 0x21, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_LT) }, - { 0x22, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_GT) }, - - { 0x30, (this.Instruction_INC_AX, this.Instruction_INC, this.Instruction_NOP, this.Instruction_ADD) }, - { 0x31, (this.Instruction_DEC_AX, this.Instruction_DEC, this.Instruction_NOP, this.Instruction_SUB) }, - { 0x32, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_DIV) }, - { 0x33, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_MUL) }, - { 0x34, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_MOD) }, - }; - } - private void Instruction_ADD(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 + v2); - this.AX = result; - } - private void Instruction_SUB(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 - v2); - this.AX = result; - } - private void Instruction_MUL(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 * v2); - this.AX = result; - } - private void Instruction_DIV(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - if (v2 == 0) - throw new DivideByZeroException("Cannot perform division by zero."); - u16 result = (u16) (v1 / v2); - this.AX = result; - } - private void Instruction_MOD(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - if (v2 == 0) - throw new DivideByZeroException("Cannot perform modulo operation with divisor zero."); - u16 result = (u16) (v1 % v2); - this.AX = result; - } - private void Instruction_INC(u8 obj) - { - var address = this.Address(obj); - u16 value = address.read(); - address.write((u16) (value + 1)); - } - private void Instruction_DEC(u8 obj) - { - var address = this.Address(obj); - u16 value = address.read(); - address.write((u16) (value - 1)); - } - private void Instruction_INC_AX() - { - this.AX = (u16) (this.AX + 1); - } - private void Instruction_DEC_AX() - { - this.AX = (u16) (this.AX - 1); - } - private void Instruction_SHL(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - u16 shifted = (u16) (v1 << v2); - this.DX = shifted; - } - private void Instruction_SHR(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - u16 shifted = (u16) (v1 >> v2); - this.DX = shifted; - } - private void Instruction_XOR(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 ^ v2); - this.DX = result; - } - private void Instruction_OR(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 | v2); - this.DX = result; - } - private void Instruction_INV(u8 obj) - { - var address = this.Address(obj); - u16 value = address.read(); - u16 result = (u16) ~value; - this.DX = result; - } - private void Instruction_INV_DX() - { - this.DX = (u16) ~this.DX; - } - private void Instruction_AND(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - u16 result = (u16) (v1 & v2); - this.DX = result; - } - private void Instruction_NOT(u8 obj) - { - u16 value = this.Address(obj).read(); - u16 result = value == 0 ? (u16) 1 : (u16) 0; - this.LX = result; - } - private void Instruction_NOT_LX() - { - this.LX = this.LX == 0 ? (u16) 1 : (u16) 0; - } - private void Instruction_GT(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - this.LX = (u16) (v1 > v2 ? 1 : 0); - } - private void Instruction_LT(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - this.LX = (u16) (v1 < v2 ? 1 : 0); - } - - private void Instruction_BR() - { - this.FetchInstruction(out _, out _, out _, out u8 length); - this.PC += length; - } - private void Instruction_BZ_LX() - { - if (this.LX == 0) - this.Instruction_BR(); - } - private void Instruction_BZ(u8 obj) - { - u16 value = this.Address(obj).read(); - if (value == 0) - this.Instruction_BR(); - } - private void Instruction_CMP(u8 m1, u8 m2) - { - u16 v1 = this.Address(m1).read(); - u16 v2 = this.Address(m2).read(); - - // Set LX based on comparison - this.LX = (u16) (v1 == v2 ? 1 : 0); - } - private void Instruction_MOV(u8 m1, u8 m2) - { - u16 value = this.Address(m1).read(); - this.Address(m2).write(value); - } - - private void Instruction_MOVB(u8 m1, u8 m2) - { - u16 value = this.Address(m1).read(); - u8 low = Make.ref8(value)[1]; - this.Address(m2).writeByte(low); - } - - public void Instruction_NOP() { } - public void Instruction_NOP(u8 m1) { } - public void Instruction_NOP(u8 m1, u8 m2) { } - - public void Instruction_JMP(u8 m1) - { - this.PC = this.Address(m1).read(); - } - - public void Instruction_RET() - { - this.PC = this.PopStack(); - } - - public void Instruction_CALL(u8 m1) - { - u16 address = this.Address(m1).read(); - this.PushStack(this.PC); - this.PC = address; - } - - public void Instruction_HALT() - { - this.AbortRequested = true; - } - - public void Instruction_SUS() - { - this.PC -= 2; - } - - public void Instruction_PUSH(u8 m1) - { - u16 value = this.Address(m1).read(); - this.PushStack(value); - } - - public void Instruction_POP(u8 m1) - { - u16 value = this.PopStack(); - this.Address(m1).write(value); - } -} \ No newline at end of file diff --git a/Emulator/Chip/RamDevice.cs b/Emulator/Chip/RamDevice.cs deleted file mode 100644 index a40713a..0000000 --- a/Emulator/Chip/RamDevice.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Q1.Emulator.Chip; - -public class RamDevice : BusDevice -{ - public u8[] Memory; - - public RamDevice(u16 start, u16 size) : base(start, (u16) (start + size)) - { - this.Memory = new u8[size]; - } - - public override void Reset() - { - this.Memory = new u8[this.AddressableEnd - this.AddressableStart]; - } - - public override void Clock() - { - // No clocking needed for RAM - } - - public override u8 Read(u16 address) - { - u16 relativeAddress = this.GetRelativeAddress(address); - return this.Memory[relativeAddress]; - } - - public override void Write(u16 address, u8 value) - { - u16 relativeAddress = this.GetRelativeAddress(address); - this.Memory[relativeAddress] = value; - } -} \ No newline at end of file diff --git a/Emulator/Content/Content.mgcb b/Emulator/Content/Content.mgcb deleted file mode 100644 index ddc4c36..0000000 --- a/Emulator/Content/Content.mgcb +++ /dev/null @@ -1,15 +0,0 @@ - -#----------------------------- Global Properties ----------------------------# - -/outputDir:bin/$(Platform) -/intermediateDir:obj/$(Platform) -/platform:DesktopGL -/config: -/profile:Reach -/compress:False - -#-------------------------------- References --------------------------------# - - -#---------------------------------- Content ---------------------------------# - diff --git a/Emulator/DisplayEngine.cs b/Emulator/DisplayEngine.cs deleted file mode 100644 index 7aa8e2e..0000000 --- a/Emulator/DisplayEngine.cs +++ /dev/null @@ -1,116 +0,0 @@ -namespace Q1.Emulator; - -using System; -using System.Linq; -using Chip; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; - -public class DisplayEngine : Game -{ - private readonly HIDDevice _hid; - private readonly Action _onScreenTextureLoaded; - private readonly Action _requestUpdate; - private readonly Func _checkAbort; - private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; - - private Texture2D _texture; - private Keys[]? _oldKeys = null; - public int Scaling { get; } - public int Width { get; } - public int Height { get; } - - public DisplayEngine( - int width, - int height, - int scaling, - HIDDevice hid, - Action onScreenTextureLoaded, - Action requestUpdate, - Func checkAbort) - { - this.Width = width; - this.Height = height; - this.Scaling = scaling; - this._hid = hid; - this._onScreenTextureLoaded = onScreenTextureLoaded; - this._requestUpdate = requestUpdate; - this._checkAbort = checkAbort; - - this._graphics = new GraphicsDeviceManager(this); - this.Content.RootDirectory = "Content"; - this.IsMouseVisible = true; - } - - protected override void Initialize() - { - this._texture = new Texture2D(this.GraphicsDevice, this.Width, this.Height); - this._onScreenTextureLoaded?.Invoke(this._texture); - // set window size - this._graphics.PreferredBackBufferWidth = this.Width * this.Scaling; - this._graphics.PreferredBackBufferHeight = this.Height * this.Scaling; - this._graphics.ApplyChanges(); - - base.Initialize(); - } - - protected override void LoadContent() - { - this._spriteBatch = new SpriteBatch(this.GraphicsDevice); - } - - protected override void Update(GameTime gameTime) - { - var keyboard = Keyboard.GetState(); - var mouse = Mouse.GetState(); - - u16 mousePos = (u16) (((mouse.Y / this.Scaling) * this.Width) + (mouse.X / this.Scaling)); - this._hid.SetMouse( - mousePos, - mouse.LeftButton == ButtonState.Pressed, - mouse.RightButton == ButtonState.Pressed, - mouse.MiddleButton == ButtonState.Pressed); - - Keys[] keys = keyboard.GetPressedKeys(); - foreach (Keys newKey in keys.Except(this._oldKeys ?? [])) - { - this._hid.SetKeyboard((u8) newKey, true); - } - - foreach (Keys oldKey in this._oldKeys?.Except(keys) ?? []) - { - this._hid.SetKeyboard((u8) oldKey, false); - } - - this._oldKeys = keys; - - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed - || keyboard.IsKeyDown(Keys.Escape) - || this._checkAbort()) - this.Exit(); - - base.Update(gameTime); - } - - protected override void Draw(GameTime gameTime) - { - // GraphicsDevice.Clear(Color.CornflowerBlue); - - this._requestUpdate(); - - this._spriteBatch.Begin( - SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, - DepthStencilState.None, RasterizerState.CullNone); - // Draw the texture to the screen - this._spriteBatch.Draw( - this._texture, - new Rectangle(0, 0, this.Width * this.Scaling, this.Height * this.Scaling), - Color.White); - - this._spriteBatch.End(); - - base.Draw(gameTime); - } -} \ No newline at end of file diff --git a/Emulator/Emulator.csproj b/Emulator/Emulator.csproj deleted file mode 100644 index 8cb327c..0000000 --- a/Emulator/Emulator.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - WinExe - net8.0 - Major - false - false - Q1.Emulator - enable - - - - - - - - Icon.ico - - - Icon.bmp - - - - - - - - - - - - \ No newline at end of file diff --git a/Emulator/Extensions.cs b/Emulator/Extensions.cs deleted file mode 100644 index 3cc980d..0000000 --- a/Emulator/Extensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Q1.Emulator; - -using System.Collections.Generic; - -public static class Extensions -{ - public static IEnumerable AllIndexesOf(this IEnumerable arr, T q) - { - var indexes = new List(); - int index = 0; - - foreach (var item in arr) - { - if (EqualityComparer.Default.Equals(item, q)) - { - indexes.Add(index); - } - index++; - } - - return indexes; - } -} \ No newline at end of file diff --git a/Emulator/GlobalUsings.cs b/Emulator/GlobalUsings.cs deleted file mode 100644 index ff38a75..0000000 --- a/Emulator/GlobalUsings.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Integer type aliases -global using i8 = sbyte; // -128 to 127 -global using u8 = byte; // 0 to 255 -global using i16 = short; // -32,768 to 32,767 -global using u16 = ushort; // 0 to 65,535 -global using i32 = int; // -2,147,483,648 to 2,147,483,647 -global using u32 = uint; // 0 to 4,294,967,295 -global using i64 = long; // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 -global using u64 = ulong; // 0 to 18,446,744,073,709,551,615 - -global using ref8 = System.Span; -global using data8 = byte[]; diff --git a/Emulator/Icon.bmp b/Emulator/Icon.bmp deleted file mode 100644 index 2b48165..0000000 Binary files a/Emulator/Icon.bmp and /dev/null differ diff --git a/Emulator/Icon.ico b/Emulator/Icon.ico deleted file mode 100644 index 7d9dec1..0000000 Binary files a/Emulator/Icon.ico and /dev/null differ diff --git a/Emulator/Make.cs b/Emulator/Make.cs deleted file mode 100644 index aad9644..0000000 --- a/Emulator/Make.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace Q1.Emulator; - -using System; -using System.Buffers.Binary; - -public static class Make -{ - public static u16 u16(u8 high, u8 low) - { - return (u16) ((high << 8) | low); - } - - public static u16 u16(ref8 data) - { - if (data.Length < 2) - throw new ArgumentException("Data must contain at least 2 bytes to form a u16."); - - return Make.u16(data[0], data[1]); - } - - public static u32 u32(u8 b1, u8 b2, u8 b3, u8 b4) - { - return (u32) ((b1 << 24) | (b2 << 16) | (b3 << 8) | b4); - } - - public static u32 u32(ref8 data) - { - if (data.Length < 4) - throw new ArgumentException("Data must contain at least 4 bytes to form a u32."); - - return Make.u32(data[0], data[1], data[2], data[3]); - } - - public static ref8 ref8(u16 value) - { - u8 high = (u8) (value >> 8); - u8 low = (u8) (value & 0xFF); - return new ref8([high, low], 0, 2); - } - - public static ref8 ref8(u32 value) - { - u8 b1 = (u8) (value >> 24); - u8 b2 = (u8) (value >> 16); - u8 b3 = (u8) (value >> 8); - u8 b4 = (u8) (value & 0xFF); - return new ref8([b1, b2, b3, b4], 0, 4); - } - public static i16 i16(ref8 value) - { - return BinaryPrimitives.ReadInt16BigEndian(value); - } - - public static i16 i16(u8 high, u8 low) - { - return BinaryPrimitives.ReadInt16BigEndian(new ReadOnlySpan([high, low])); - } -} \ No newline at end of file diff --git a/Emulator/Options.cs b/Emulator/Options.cs deleted file mode 100644 index f27b55d..0000000 --- a/Emulator/Options.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Q1.Emulator; - -public class EmulatorOptions -{ - [CommandLine.Option('i', "input", Required = true, HelpText = "Input file to run.")] - public string InputFile { get; set; } -} \ No newline at end of file diff --git a/Emulator/Program.cs b/Emulator/Program.cs deleted file mode 100644 index f6fa932..0000000 --- a/Emulator/Program.cs +++ /dev/null @@ -1,98 +0,0 @@ -namespace Q1.Emulator; - -using System; -using System.IO; -using System.Threading; -using Chip; -using CommandLine; -using Microsoft.Xna.Framework; - -public class Program -{ - public static void Main(string[] args) - { - Parser.Default.ParseArguments(args).WithParsed(Program.Main); - } - - public static void Main(EmulatorOptions emulatorOptions) - { - Q1Cpu cpu = new(); - Bus bus = new(u16.MinValue, u16.MaxValue); - RamDevice rom = new(Q1Layout.Rom.start, Q1Layout.Rom.size); - File.ReadAllBytes(emulatorOptions.InputFile).CopyTo(rom.Memory, 0); - - DisplayDevice display = new(Q1Layout.DisplayPaletteSize, Q1Layout.DisplayWidth, Q1Layout.DisplayHeight, Q1Layout.Display.start); - display.SetPalette([ - Color.Red, - Color.Green, - Color.Blue, - Color.Yellow, - Color.Cyan, - Color.Magenta, - Color.White, - Color.Black, - Color.Gray, - Color.Orange, - Color.Purple, - Color.Brown, - Color.LightGray, - Color.DarkGray, - Color.LightBlue, - Color.LightGreen - ]); - - HIDDevice hid = new(Q1Layout.Hid.start); - - RamDevice memory = new(Q1Layout.Memory.start, Q1Layout.Memory.size); - - cpu.Bus = bus; - rom.AttachToBus(bus); - display.AttachToBus(bus); - memory.AttachToBus(bus); - hid.AttachToBus(bus); - - Thread t = new(() => - { - cpu.Reset(); - while (!cpu.AbortRequested) - { - // for (int i = 0; i < 64; i++) - // cpu.Clock(); - // - // Thread.Sleep(1); - // - cpu.Clock(); - } - Console.WriteLine($"Exit code: 0x{cpu.V[0]:X4}"); - MemoryDump(memory, Q1Layout.FreeMemoryStart, (u16) (Q1Layout.Memory.start + Q1Layout.Memory.size - 1)); - }); - t.IsBackground = true; - t.Start(); - - using DisplayEngine game = new(Q1Layout.DisplayWidth, Q1Layout.DisplayHeight, 5, - hid, - tex => - { - display.OutputTexture = tex; - Console.WriteLine("Display surface initialized."); - }, () => display.Clock(), () => cpu.AbortRequested); - game.Run(); - - Console.WriteLine("Display surface closed. Waiting for CPU thread to finish..."); - t.Join(); - } - - private static void MemoryDump(RamDevice memory, u16 start, u16 end) - { - for (u16 addr = start; addr <= end; addr += 16) - { - Console.Write($"0x{addr:X4}: "); - for (u16 offset = 0; offset < 16; offset++) - { - if (addr + offset > end) break; - Console.Write($"{memory.Read((u16) (addr + offset)):X2} "); - } - Console.WriteLine(); - } - } -} \ No newline at end of file diff --git a/Emulator/Q1Layout.cs b/Emulator/Q1Layout.cs deleted file mode 100644 index 60a99c0..0000000 --- a/Emulator/Q1Layout.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Q1.Emulator; - -using Chip; - -public static class Q1Layout -{ - public static readonly u16 DisplayWidth = 128; - public static readonly u16 DisplayHeight = 64; - public static readonly u16 DisplayPaletteSize = 16; - - // Bus locations - public static readonly (u16 start, u16 size) Rom = (0x1FFF, 1024 * 8); - public static readonly (u16 start, u16 size) Hid = (0x602F, HIDDevice.CalculateSize()); - public static readonly (u16 start, u16 size) Memory = (0x6FFF, 1024 * 16); - public static readonly (u16 start, u16 size) Display = (0x3FFF, - DisplayDevice.DetermineSize(Q1Layout.DisplayPaletteSize, Q1Layout.DisplayWidth, Q1Layout.DisplayHeight)); - - - public static readonly u16 StackStart = Q1Layout.Memory.start; - public static readonly u16 StackLength = 256 * 2; // 256 16-bit values - public static readonly u16 FreeMemoryStart = (u16) (Q1Layout.StackStart + Q1Layout.StackLength); - public static readonly u16 ProgramStart = Q1Layout.Rom.start; -} \ No newline at end of file diff --git a/Orchestrator/Orchestrator.csproj b/Orchestrator/Orchestrator.csproj deleted file mode 100644 index 4701bf4..0000000 --- a/Orchestrator/Orchestrator.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net9.0 - enable - enable - - - - - - - - - - - - - diff --git a/Orchestrator/Program.cs b/Orchestrator/Program.cs deleted file mode 100644 index c5d7538..0000000 --- a/Orchestrator/Program.cs +++ /dev/null @@ -1,74 +0,0 @@ -namespace Orchestrator; - -using CommandLine; -using Q1.Assembler; -using Q1.Compiler; -using Q1.Emulator; - -class Program -{ - static void Main(string[] args) - { - Parser p = new(with => - { - with.CaseInsensitiveEnumValues = true; - }); - - p.ParseArguments(args).WithParsed(Main); - } - - private static void Main(Options options) - { - string compiledFile = Path.ChangeExtension(options.InputFile, "asm"); - string assembledFile = Path.ChangeExtension(options.InputFile, "q1"); - - if (!options.NoCompile) - Q1.Compiler.Program.Main( - new CompilerOptions - { - CommentCompilationMode = options.CommentCompilationMode, - InputFile = options.InputFile, - OutputFile = compiledFile, - Verbose = options.Verbose - }); - - if (!options.NoAssemble) - Q1.Assembler.Program.Main( - new AssemblerOptions - { - InputFile = compiledFile, - OutputFile = assembledFile - }); - - if (!options.NoEmulate) - Q1.Emulator.Program.Main( - new EmulatorOptions - { - InputFile = assembledFile, - }); - } -} - -class Options -{ - [Option('i', "input", Required = true, HelpText = "Input file to process.")] - public string InputFile { get; set; } - - [Option( - 'c', "comment-compilation", Required = false, - HelpText = "Comments to preserve in the compiled result")] - public CommentCompilationMode CommentCompilationMode { get; set; } = - CommentCompilationMode.UserDefined; - - [Option("no-compile", HelpText = "Skip compilation")] - public bool NoCompile { get; set; } = false; - - [Option("no-assemble", HelpText = "Skip assembling")] - public bool NoAssemble { get; set; } = false; - - [Option("no-emulate", HelpText = "Skip emulation")] - public bool NoEmulate { get; set; } = false; - - [Option('v', "verbose", HelpText = "Enable verbose output")] - public bool Verbose { get; set; } = false; -} \ No newline at end of file diff --git a/Q1.core/Arch/AddressingMode.cs b/Q1.core/Arch/AddressingMode.cs new file mode 100644 index 0000000..190439b --- /dev/null +++ b/Q1.core/Arch/AddressingMode.cs @@ -0,0 +1,13 @@ +namespace Q1.core.Arch; + +public record struct AddressingMode +{ + public string Name; + public u8 SizeB; + public u8 SizeW; + + public Func LoadByte; + public Func LoadWord; + public Action StoreByte; + public Action StoreWord; +} \ No newline at end of file diff --git a/Q1.core/Arch/AddressingModes.cs b/Q1.core/Arch/AddressingModes.cs new file mode 100644 index 0000000..206ee4f --- /dev/null +++ b/Q1.core/Arch/AddressingModes.cs @@ -0,0 +1,331 @@ +namespace Q1.core.Arch; + +public static class AddressingModes +{ + public static AddressingMode[] Lookup = new AddressingMode[8]; + + static AddressingModes() + { + AddressingModes.Lookup[0x00] = new AddressingMode + { + Name = "Implicit", + SizeB = 0, + SizeW = 0, + LoadByte = AddressingModes.ImplicitLoadByte, + LoadWord = AddressingModes.ImplicitLoadWord, + StoreByte = AddressingModes.ImplicitStoreByte, + StoreWord = AddressingModes.ImplicitStoreWord + }; + + AddressingModes.Lookup[0x01] = new AddressingMode + { + Name = "Immediate", + SizeB = 1, + SizeW = 2, + LoadByte = AddressingModes.ImmediateLoadByte, + LoadWord = AddressingModes.ImmediateLoadWord, + StoreByte = AddressingModes.ImmediateStoreByte, + StoreWord = AddressingModes.ImmediateStoreWord + }; + + AddressingModes.Lookup[0x02] = new AddressingMode + { + Name = "Direct", + SizeB = 2, + SizeW = 2, + LoadByte = AddressingModes.DirectLoadByte, + LoadWord = AddressingModes.DirectLoadWord, + StoreByte = AddressingModes.DirectStoreByte, + StoreWord = AddressingModes.DirectStoreWord + }; + + AddressingModes.Lookup[0x03] = new AddressingMode + { + Name = "Indirect", + SizeB = 2, + SizeW = 2, + LoadByte = AddressingModes.IndirectLoadByte, + LoadWord = AddressingModes.IndirectLoadWord, + StoreByte = AddressingModes.IndirectStoreByte, + StoreWord = AddressingModes.IndirectStoreWord + }; + + AddressingModes.Lookup[0x04] = new AddressingMode + { + Name = "Relative", + SizeB = 2, + SizeW = 2, + LoadByte = AddressingModes.RelativeLoadByte, + LoadWord = AddressingModes.RelativeLoadWord, + StoreByte = AddressingModes.RelativeStoreByte, + StoreWord = AddressingModes.RelativeStoreWord + }; + + AddressingModes.Lookup[0x05] = new AddressingMode + { + Name = "Register", + SizeB = 1, + SizeW = 1, + LoadByte = AddressingModes.RegisterLoadByte, + LoadWord = AddressingModes.RegisterLoadWord, + StoreByte = AddressingModes.RegisterStoreByte, + StoreWord = AddressingModes.RegisterStoreWord + }; + + AddressingModes.Lookup[0x06] = new AddressingMode + { + Name = "Register Indirect", + SizeB = 1, + SizeW = 1, + LoadByte = AddressingModes.RegisterIndirectLoadByte, + LoadWord = AddressingModes.RegisterIndirectLoadWord, + StoreByte = AddressingModes.RegisterIndirectStoreByte, + StoreWord = AddressingModes.RegisterIndirectStoreWord + }; + + AddressingModes.Lookup[0x07] = new AddressingMode + { + Name = "Register Indirect with Offset", + SizeB = 3, + SizeW = 3, + LoadByte = AddressingModes.RegisterIndirectOffsetLoadByte, + LoadWord = AddressingModes.RegisterIndirectOffsetLoadWord, + StoreByte = AddressingModes.RegisterIndirectOffsetStoreByte, + StoreWord = AddressingModes.RegisterIndirectOffsetStoreWord + }; + } + + private static u8 ImplicitLoadByte(Chip chip) + => throw new InvalidOperationException("Cannot load from an implicit value"); + private static u16 ImplicitLoadWord(Chip chip) + => throw new InvalidOperationException("Cannot load from an implicit value"); + private static void ImplicitStoreByte(Chip chip, u8 value) + => throw new InvalidOperationException("Cannot store to an implicit value"); + private static void ImplicitStoreWord(Chip chip, u16 value) + => throw new InvalidOperationException("Cannot store to an implicit value"); + + + private static u8 ImmediateLoadByte(Chip chip) + { + u8 value = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + return value; + } + private static u16 ImmediateLoadWord(Chip chip) + { + u16 value = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + return value; + } + private static void ImmediateStoreByte(Chip chip, u8 value) + => throw new InvalidOperationException("Cannot store to an immediate value"); + private static void ImmediateStoreWord(Chip chip, u16 value) + => throw new InvalidOperationException("Cannot store to an immediate value"); + + + private static u8 DirectLoadByte(Chip chip) + { + u16 address = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + return chip.Bus.Read(address); + } + private static u16 DirectLoadWord(Chip chip) + { + u16 address = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + return chip.Bus.ReadWord(address); + } + private static void DirectStoreByte(Chip chip, u8 value) + { + u16 address = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + chip.Bus.Write(address, value); + } + private static void DirectStoreWord(Chip chip, u16 value) + { + u16 address = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + chip.Bus.WriteWord(address, value); + } + + + private static u8 IndirectLoadByte(Chip chip) + { + u16 pointer = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = chip.Bus.ReadWord(pointer); + return chip.Bus.Read(address); + } + private static u16 IndirectLoadWord(Chip chip) + { + u16 pointer = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = chip.Bus.ReadWord(pointer); + return chip.Bus.ReadWord(address); + } + private static void IndirectStoreByte(Chip chip, u8 value) + { + u16 pointer = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = chip.Bus.ReadWord(pointer); + chip.Bus.Write(address, value); + } + private static void IndirectStoreWord(Chip chip, u16 value) + { + u16 pointer = chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = chip.Bus.ReadWord(pointer); + chip.Bus.WriteWord(address, value); + } + + + private static u8 RelativeLoadByte(Chip chip) + { + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16) (chip.Pc + offset); + return chip.Bus.Read(address); + } + private static u16 RelativeLoadWord(Chip chip) + { + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16) (chip.Pc + offset); + return chip.Bus.ReadWord(address); + } + private static void RelativeStoreByte(Chip chip, u8 value) + { + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16) (chip.Pc + offset); + chip.Bus.Write(address, value); + } + private static void RelativeStoreWord(Chip chip, u16 value) + { + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16) (chip.Pc + offset); + chip.Bus.WriteWord(address, value); + } + + private static u8 RegisterLoadByte(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + return (u8) (chip.GetRegister(regIndex) & 0xFF); + } + private static u16 RegisterLoadWord(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + return chip.GetRegister(regIndex); + } + private static void RegisterStoreByte(Chip chip, u8 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + u16 current = chip.GetRegister(regIndex); + u16 newValue = (u16)((current & 0xFF00) | value); + chip.SetRegister(regIndex, newValue); + } + private static void RegisterStoreWord(Chip chip, u16 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + chip.SetRegister(regIndex, value); + } + + private static u8 RegisterIndirectLoadByte(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + u16 address = chip.GetRegister(regIndex); + return chip.Bus.Read(address); + } + private static u16 RegisterIndirectLoadWord(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + u16 address = chip.GetRegister(regIndex); + return chip.Bus.ReadWord(address); + } + private static void RegisterIndirectStoreByte(Chip chip, u8 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + u16 address = chip.GetRegister(regIndex); + chip.Bus.Write(address, value); + } + private static void RegisterIndirectStoreWord(Chip chip, u16 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + u16 address = chip.GetRegister(regIndex); + chip.Bus.WriteWord(address, value); + } + + private static u8 RegisterIndirectOffsetLoadByte(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16)(chip.GetRegister(regIndex) + offset); + return chip.Bus.Read(address); + } + private static u16 RegisterIndirectOffsetLoadWord(Chip chip) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16)(chip.GetRegister(regIndex) + offset); + return chip.Bus.ReadWord(address); + } + private static void RegisterIndirectOffsetStoreByte(Chip chip, u8 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16)(chip.GetRegister(regIndex) + offset); + chip.Bus.Write(address, value); + } + private static void RegisterIndirectOffsetStoreWord(Chip chip, u16 value) + { + u8 regIndex = chip.Bus.Read(chip.Pc); + chip.Pc += 1; + + i16 offset = (i16) chip.Bus.ReadWord(chip.Pc); + chip.Pc += 2; + + u16 address = (u16)(chip.GetRegister(regIndex) + offset); + chip.Bus.WriteWord(address, value); + } +} \ No newline at end of file diff --git a/Q1.core/Arch/Chip.cs b/Q1.core/Arch/Chip.cs new file mode 100644 index 0000000..af131dd --- /dev/null +++ b/Q1.core/Arch/Chip.cs @@ -0,0 +1,143 @@ +namespace Q1.core.Arch; + +// Big endian +public class Chip +{ + public IAddressable Bus; + public u16 Pc, Sp; + public u16 Ax, Dx, Lx; + + private u16[] _registers; + + public void Reset() + { + this._registers = new u16[64]; + this.Pc = ChipLayout.PROGRAM_START; + this.Sp = ChipLayout.STACK_START; + } + + public void Clock() + { + this.Bus.Clock(); + + this.Fetch(out u8 opcode, out u8 m1, out u8 m2, out bool word); + + switch (m1, m2) + { + case (0x00, 0x00): + InstructionSet.Lookup[opcode].Implicit.Execute(this, word); + break; + + case (_, 0x00): + InstructionSet.Lookup[opcode].SimpleAddressing.Execute(this, m1, word); + break; + + case (0x00, 0x01): + InstructionSet.Lookup[opcode].ExtendedImplicit.Execute(this, word); + break; + + case (_, _): + InstructionSet.Lookup[opcode].ExtendedAddressing.Execute(this, m1, m2, word); + break; + } + } + + /// [opcode: 7 bits] [word: 1 bits] [m1: 4 bits] [m2: 4 bits] + public void Fetch(out u8 opcode, out u8 m1, out u8 m2, out bool word) + { + u16 instruction = this.Bus.ReadWord(this.Pc); + this.Pc += 2; + + opcode = (u8) ((instruction >> 8) & 0xFE); // 128 opcodes + word = ((instruction >> 8) & 0x1) != 0; // flag for word mode + + m1 = (u8) ((instruction >> 4) & 0x0F); // 16 modes + m2 = (u8) (instruction & 0x0F); // 16 modes + } + + public void SkipInstruction() + { + this.Fetch(out u8 _, out u8 m1, out u8 m2, out bool word); + this.Pc += (u8)(Size(m1, word) + Size(m2, word)); + } + + public u16 Load(u8 mode, bool word) + { + AddressingMode am = AddressingModes.Lookup[mode]; + return word ? am.LoadWord(this) : am.LoadByte(this); + } + + public void Store(u8 mode, u16 value, bool word) + { + AddressingMode am = AddressingModes.Lookup[mode]; + if (word) am.StoreWord(this, value); + else am.StoreByte(this, (u8)(value & 0xFF)); + } + + public u8 Size(u8 mode, bool word) + { + AddressingMode am = AddressingModes.Lookup[mode]; + return word ? am.SizeW : am.SizeB; + } + + public void Push(u16 value) + { + if (this.Sp + 2 > ChipLayout.STACK_START + ChipLayout.STACK_SIZE) + throw new InvalidOperationException("Stack overflow"); + + this.Bus.WriteWord(this.Sp, value); + + this.Sp += 2; + } + + public u16 Pop() + { + if (this.Sp - 2 < ChipLayout.STACK_START) + throw new InvalidOperationException("Stack underflow"); + + this.Sp -= 2; + u16 value = this.Bus.ReadWord(this.Sp); + + return value; + } + + public u16 GetRegister(u8 index) + { + if (index < 64) return this._registers[index]; + + if (index == 0x40) return this.Ax; + if (index == 0x41) return (u16) (this.Ax >> 8); // High byte of Ax + if (index == 0x42) return (u16) (this.Ax & 0xFF); // Low byte of Ax + + if (index == 0x44) return this.Dx; + if (index == 0x45) return (u16) (this.Dx >> 8); // High byte of Dx + if (index == 0x46) return (u16) (this.Dx & 0xFF); // Low byte of Dx + + if (index == 0x48) return this.Lx; + + if (index == 0x4C) return this.Pc; + if (index == 0x4D) return this.Sp; + + throw new InvalidOperationException($"Invalid register index: {index}"); + } + + public void SetRegister(u8 index, u16 value) + { + if (index < 64) this._registers[index] = value; + + else if (index == 0x40) this.Ax = value; + else if (index == 0x41) this.Ax = (u16)((this.Ax & 0x00FF) | ((value & 0xFF) << 8)); // Set high byte of Ax + else if (index == 0x42) this.Ax = (u16)((this.Ax & 0xFF00) | (value & 0xFF)); // Set low byte of Ax + + else if (index == 0x44) this.Dx = value; + else if (index == 0x45) this.Dx = (u16)((this.Dx & 0x00FF) | ((value & 0xFF) << 8)); // Set high byte of Dx + else if (index == 0x46) this.Dx = (u16)((this.Dx & 0xFF00) | (value & 0xFF)); // Set low byte of Dx + + else if (index == 0x48) this.Lx = value; + + else if (index == 0x4C) this.Pc = value; + else if (index == 0x4D) this.Sp = value; + + else throw new InvalidOperationException($"Invalid register index: {index}"); + } +} \ No newline at end of file diff --git a/Q1.core/Arch/ChipLayout.cs b/Q1.core/Arch/ChipLayout.cs new file mode 100644 index 0000000..8c916f6 --- /dev/null +++ b/Q1.core/Arch/ChipLayout.cs @@ -0,0 +1,12 @@ +namespace Q1.core.Arch; + +public static class ChipLayout +{ + public const u16 MEMORY_START = 0x0000; + public const u16 MEMORY_SIZE = 0xFF00; // 64KB - 256 bytes reserved for stack + + public const u16 STACK_START = ChipLayout.MEMORY_START; + public const u16 STACK_SIZE = 256 * 2; // 256 words (512 bytes) + + public const u16 PROGRAM_START = ChipLayout.MEMORY_START + ChipLayout.STACK_SIZE; +} \ No newline at end of file diff --git a/Q1.core/Arch/IInstruction.cs b/Q1.core/Arch/IInstruction.cs new file mode 100644 index 0000000..2889937 --- /dev/null +++ b/Q1.core/Arch/IInstruction.cs @@ -0,0 +1,35 @@ +namespace Q1.core.Arch; + +public interface IInstruction +{ + public string Name { get; } +} + +public record struct ImplicitInstruction : IInstruction +{ + public string Name { get; set; } + + public Action Execute; +} + +public record struct SimpleInstruction : IInstruction +{ + public string Name { get; set; } + + public Action Execute; +} + +public record struct ExtendedInstruction : IInstruction +{ + public string Name { get; set; } + + public Action Execute; +} + +public record struct InstructionGroup +{ + public ImplicitInstruction Implicit; + public SimpleInstruction SimpleAddressing; + public ImplicitInstruction ExtendedImplicit; + public ExtendedInstruction ExtendedAddressing; +} \ No newline at end of file diff --git a/Q1.core/Arch/InstructionSet.cs b/Q1.core/Arch/InstructionSet.cs new file mode 100644 index 0000000..68a9b55 --- /dev/null +++ b/Q1.core/Arch/InstructionSet.cs @@ -0,0 +1,203 @@ +namespace Q1.core.Arch; + +public static class InstructionSet +{ + public static readonly InstructionGroup[] Lookup = new InstructionGroup[128]; + + static InstructionSet() + { + var nop = new ImplicitInstruction { Name = "NOP", Execute = InstructionSet.Nop }; + var nopSimple = new SimpleInstruction { Name = "NOP", Execute = InstructionSet.Nop }; + var nopExtended = new ExtendedInstruction { Name = "NOP", Execute = InstructionSet.Nop }; + + #region Control Group + + InstructionSet.Lookup[0x00] = new InstructionGroup + { + Implicit = nop, + SimpleAddressing = new SimpleInstruction { Name = "JMP", Execute = InstructionSet.Jump }, + ExtendedImplicit = new ImplicitInstruction { Name = "HALT", Execute = InstructionSet.Halt }, + ExtendedAddressing = new ExtendedInstruction { Name = "MOV", Execute = InstructionSet.Move } + }; + + InstructionSet.Lookup[0x01] = new InstructionGroup + { + Implicit = new ImplicitInstruction { Name = "RET", Execute = InstructionSet.Return }, + SimpleAddressing = new SimpleInstruction { Name = "CALL", Execute = InstructionSet.Call }, + ExtendedImplicit = new ImplicitInstruction { Name = "SUS", Execute = InstructionSet.Suspend }, + ExtendedAddressing = nopExtended + }; + + InstructionSet.Lookup[0x02] = new InstructionGroup + { + Implicit = new ImplicitInstruction { Name = "BZ(LX)", Execute = InstructionSet.BranchIfZeroLx }, + SimpleAddressing = new SimpleInstruction { Name = "BZ", Execute = InstructionSet.BranchIfZero }, + ExtendedImplicit = new ImplicitInstruction { Name = "BR", Execute = InstructionSet.Branch }, + ExtendedAddressing = nopExtended + }; + + InstructionSet.Lookup[0x03] = new InstructionGroup + { + Implicit = nop, + SimpleAddressing = new SimpleInstruction { Name = "PUSH", Execute = InstructionSet.Push }, + ExtendedImplicit = nop, + ExtendedAddressing = nopExtended + }; + + InstructionSet.Lookup[0x04] = new InstructionGroup + { + Implicit = nop, + SimpleAddressing = new SimpleInstruction { Name = "POP", Execute = InstructionSet.Pop }, + ExtendedImplicit = nop, + ExtendedAddressing = nopExtended + }; + + #endregion + + #region Data Group + + InstructionSet.Lookup[0x10] = new InstructionGroup + { + Implicit = new ImplicitInstruction { Name = "INV(DX)", Execute = InstructionSet.InverseDx }, + SimpleAddressing = new SimpleInstruction { Name = "INV", Execute = InstructionSet.Inverse }, + ExtendedImplicit = nop, + ExtendedAddressing = new ExtendedInstruction { Name = "AND", Execute = InstructionSet.And } + }; + + InstructionSet.Lookup[0x11] = new InstructionGroup + { + Implicit = nop, + SimpleAddressing = nopSimple, + ExtendedImplicit = nop, + ExtendedAddressing = new ExtendedInstruction { Name = "OR", Execute = InstructionSet.Or } + }; + + InstructionSet.Lookup[0x12] = new InstructionGroup + { + Implicit = nop, + SimpleAddressing = nopSimple, + ExtendedImplicit = nop, + ExtendedAddressing = new ExtendedInstruction { Name = "XOR", Execute = InstructionSet.Xor } + }; + + InstructionSet.Lookup[0x13] = new InstructionGroup + { + Implicit = new ImplicitInstruction { Name = "SHPL(DX)", Execute = InstructionSet.ShiftPlaceLeftDx }, + SimpleAddressing = new SimpleInstruction { Name = "SHPL", Execute = InstructionSet.ShiftPlaceLeft }, + ExtendedImplicit = nop, + ExtendedAddressing = new ExtendedInstruction { Name = "SHL", Execute = InstructionSet.ShiftLeft } + }; + + InstructionSet.Lookup[0x14] = new InstructionGroup + { + Implicit = new ImplicitInstruction { Name = "SHPR(DX)", Execute = InstructionSet.ShiftPlaceRightDx }, + SimpleAddressing = new SimpleInstruction { Name = "SHPR", Execute = InstructionSet.ShiftPlaceRight }, + ExtendedImplicit = nop, + ExtendedAddressing = new ExtendedInstruction { Name = "SHL", Execute = InstructionSet.ShiftRight } + }; + + #endregion + } + + private static void Nop(Chip chip, bool word) { /* No operation */ } + private static void Nop(Chip chip, u8 m1, bool word) { /* No operation */ } + private static void Nop(Chip chip, u8 m1, u8 m2, bool word) { /* No operation */ } + + #region Control Instructions + + private static void Halt(Chip chip, bool word) + { + throw new NotImplementedException("HALT instruction is not implemented yet."); + } + + private static void Suspend(Chip chip, bool word) + { + throw new NotImplementedException("SUS instruction is not implemented yet."); + } + + private static void Move(Chip chip, u8 m1, u8 m2, bool word) + { + u16 value = chip.Load(m1, word); + chip.Store(m2, value, word); + } + + private static void Jump(Chip chip, u8 m1, bool word) + { + u16 address = chip.Load(m1, word); + chip.Pc = address; + } + + private static void Call(Chip chip, u8 m1, bool word) + { + u16 targetAddress = chip.Load(m1, word); + chip.Push(chip.Pc); + chip.Pc = targetAddress; + } + + private static void Return(Chip chip, bool word) + { + u16 returnAddress = chip.Pop(); + chip.Pc = returnAddress; + } + + private static void BranchIfZero(Chip chip, u8 m1, bool word) + { + u16 value = chip.Load(m1, word); + if (value == 0) + chip.SkipInstruction(); + } + + private static void BranchIfZeroLx(Chip chip, bool word) + { + if (chip.Lx == 0) + chip.SkipInstruction(); + } + + private static void Branch(Chip chip, bool word) + { + chip.SkipInstruction(); + } + + private static void Push(Chip chip, u8 m1, bool word) + { + u16 value = chip.Load(m1, word); + chip.Push(value); + } + + private static void Pop(Chip chip, u8 m1, bool word) + { + u16 value = chip.Pop(); + chip.Store(m1, value, word); + } + + #endregion + + #region Data Instructions + + private static void Inverse(Chip chip, u8 m1, bool word) + { + u16 value = chip.Load(m1, word); + value = (u16)~value; + + chip.Dx = value; + } + + private static void InverseDx(Chip chip, bool word) + { + chip.Dx = (u16)~chip.Dx; + } + + #endregion + + #region Logic Instructions + + + + #endregion + + #region Arithmetic Instructions + + + + #endregion +} \ No newline at end of file diff --git a/Q1.core/GlobalUsings.cs b/Q1.core/GlobalUsings.cs new file mode 100644 index 0000000..aca802e --- /dev/null +++ b/Q1.core/GlobalUsings.cs @@ -0,0 +1,12 @@ +// Integer type aliases +global using i8 = sbyte; // -128 to 127 +global using u8 = byte; // 0 to 255 +global using i16 = short; // -32,768 to 32,767 +global using u16 = ushort; // 0 to 65,535 +global using i32 = int; // -2,147,483,648 to 2,147,483,647 +global using u32 = uint; // 0 to 4,294,967,295 +global using i64 = long; // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 +global using u64 = ulong; // 0 to 18,446,744,073,709,551,615 + +global using ref8 = System.Span; +global using data8 = byte[]; \ No newline at end of file diff --git a/Q1.core/IAddressable.cs b/Q1.core/IAddressable.cs new file mode 100644 index 0000000..49a697e --- /dev/null +++ b/Q1.core/IAddressable.cs @@ -0,0 +1,26 @@ +namespace Q1.core; + +public interface IAddressable +{ + public u8 Read(u16 address); + public void Write(u16 address, u8 value); + public void Clock(); +} + +public static class AddressableExtensions +{ + public static u16 ReadWord(this IAddressable bus, u16 address) + { + u8 high = bus.Read(address); + u8 low = bus.Read((u16)(address + 1)); + return (u16)((high << 8) | low); + } + + public static void WriteWord(this IAddressable bus, u16 address, u16 value) + { + u8 high = (u8) (value & 0xFF); + u8 low = (u8)((value >> 8) & 0xFF); + bus.Write(address, low); + bus.Write((u16)(address + 1), high); + } +} \ No newline at end of file diff --git a/Q1.core/Memory.cs b/Q1.core/Memory.cs new file mode 100644 index 0000000..d140809 --- /dev/null +++ b/Q1.core/Memory.cs @@ -0,0 +1,15 @@ +namespace Q1.core; + +public class Memory : IAddressable +{ + private readonly u8[] _memory; + + public Memory(int size) + { + _memory = new u8[size]; + } + + public u8 Read(u16 address) => _memory[address]; + public void Write(u16 address, u8 value) => _memory[address] = value; + public void Clock() { /* No timing behavior for simple memory */ } +} \ No newline at end of file diff --git a/Q1.core/Q1.core.csproj b/Q1.core/Q1.core.csproj new file mode 100644 index 0000000..17b910f --- /dev/null +++ b/Q1.core/Q1.core.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/Q1.sln b/Q1.sln index 6dae249..50084ca 100644 --- a/Q1.sln +++ b/Q1.sln @@ -1,16 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emulator", "Emulator\Emulator.csproj", "{04CE77A9-E0DC-4CAB-9382-5F84B4275B6B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Q1.core", "Q1.core\Q1.core.csproj", "{D65792DC-AFC1-4D0E-800E-1D943C8CECB2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compiler", "Compiler\Compiler.csproj", "{F3A482AD-855E-49B2-9E62-A7C68AB6250D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembler", "Assembler\Assembler.csproj", "{330B7F43-7267-4A2C-8EB0-257458231B7E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchestrator", "Orchestrator\Orchestrator.csproj", "{0A0B231E-39B7-470D-B008-6B40DBA7A8B8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegionVisualiser", "RegionVisualiser\RegionVisualiser.csproj", "{43523E07-07BD-456A-BD53-C1515ED8148E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compiler.Testing", "Compiler.Testing\Compiler.Testing.csproj", "{2BE81C5F-2117-412D-9FAF-8AA31C2E7000}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Q1.tests", "Q1.tests\Q1.tests.csproj", "{0F156DB9-1029-4D97-B659-6A680981B96E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -18,29 +10,13 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {04CE77A9-E0DC-4CAB-9382-5F84B4275B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {04CE77A9-E0DC-4CAB-9382-5F84B4275B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {04CE77A9-E0DC-4CAB-9382-5F84B4275B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {04CE77A9-E0DC-4CAB-9382-5F84B4275B6B}.Release|Any CPU.Build.0 = Release|Any CPU - {F3A482AD-855E-49B2-9E62-A7C68AB6250D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F3A482AD-855E-49B2-9E62-A7C68AB6250D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F3A482AD-855E-49B2-9E62-A7C68AB6250D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F3A482AD-855E-49B2-9E62-A7C68AB6250D}.Release|Any CPU.Build.0 = Release|Any CPU - {330B7F43-7267-4A2C-8EB0-257458231B7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {330B7F43-7267-4A2C-8EB0-257458231B7E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {330B7F43-7267-4A2C-8EB0-257458231B7E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {330B7F43-7267-4A2C-8EB0-257458231B7E}.Release|Any CPU.Build.0 = Release|Any CPU - {0A0B231E-39B7-470D-B008-6B40DBA7A8B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A0B231E-39B7-470D-B008-6B40DBA7A8B8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A0B231E-39B7-470D-B008-6B40DBA7A8B8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A0B231E-39B7-470D-B008-6B40DBA7A8B8}.Release|Any CPU.Build.0 = Release|Any CPU - {43523E07-07BD-456A-BD53-C1515ED8148E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {43523E07-07BD-456A-BD53-C1515ED8148E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {43523E07-07BD-456A-BD53-C1515ED8148E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {43523E07-07BD-456A-BD53-C1515ED8148E}.Release|Any CPU.Build.0 = Release|Any CPU - {2BE81C5F-2117-412D-9FAF-8AA31C2E7000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2BE81C5F-2117-412D-9FAF-8AA31C2E7000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2BE81C5F-2117-412D-9FAF-8AA31C2E7000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2BE81C5F-2117-412D-9FAF-8AA31C2E7000}.Release|Any CPU.Build.0 = Release|Any CPU + {D65792DC-AFC1-4D0E-800E-1D943C8CECB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D65792DC-AFC1-4D0E-800E-1D943C8CECB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D65792DC-AFC1-4D0E-800E-1D943C8CECB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D65792DC-AFC1-4D0E-800E-1D943C8CECB2}.Release|Any CPU.Build.0 = Release|Any CPU + {0F156DB9-1029-4D97-B659-6A680981B96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F156DB9-1029-4D97-B659-6A680981B96E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F156DB9-1029-4D97-B659-6A680981B96E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F156DB9-1029-4D97-B659-6A680981B96E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Q1.tests/Core/AddressingModesTests.cs b/Q1.tests/Core/AddressingModesTests.cs new file mode 100644 index 0000000..19be64d --- /dev/null +++ b/Q1.tests/Core/AddressingModesTests.cs @@ -0,0 +1,20 @@ +namespace Q1.tests.Core; + +using core; +using core.Arch; + +[TestFixture] +public class AddressingModesTests +{ + + [Test] + public void LookupShouldHaveAddressingModes() + { + var populatedModes = AddressingModes.Lookup + .Where(x => x != default) + .ToArray(); + + Assert.That(populatedModes, Has.Length.EqualTo(8), + "Expected 8 addressing modes to be defined"); + } +} \ No newline at end of file diff --git a/Q1.tests/Core/InstructionsTests.cs b/Q1.tests/Core/InstructionsTests.cs new file mode 100644 index 0000000..cc7be78 --- /dev/null +++ b/Q1.tests/Core/InstructionsTests.cs @@ -0,0 +1,20 @@ +namespace Q1.tests.Core; + +using core; +using core.Arch; + +[TestFixture] +public class InstructionsTests +{ + + [Test] + public void LookupShouldHaveInstructions() + { + var populatedSets = InstructionSet.Lookup + .Where(x => x != default) + .ToArray(); + + Assert.That(populatedSets, Has.Length.EqualTo(18), + "Expected 8 instruction groups to be defined"); + } +} \ No newline at end of file diff --git a/Q1.tests/Q1.tests.csproj b/Q1.tests/Q1.tests.csproj new file mode 100644 index 0000000..022add0 --- /dev/null +++ b/Q1.tests/Q1.tests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + + diff --git a/ROMs/_old/hello_world.asm b/ROMs/_old/hello_world.asm deleted file mode 100644 index 1d812fb..0000000 --- a/ROMs/_old/hello_world.asm +++ /dev/null @@ -1,42 +0,0 @@ -.org $1FFF -JMP program - -font: - .include "font.bin" - -program: - MOV 0, V0 ; Load character #12 - MOV 0, V1 ; X position - MOV 0, V2 ; Y position - MOV 1, V3 ; Color (1 = white) - CALL write_char ; Call function to write character - SUS - -write_char: - ; V0: Character to write - ; V1: X position - ; V2: Y position - ; V3: Color - ; Write a character to the screen at (V1, V2) with color V3 - - MUL V0, 64 ; V0 = Character * 64 (character size) - MOV AX, V0 ; Store result back into character - - MUL V2, 64 - ADD AX, V1 - MOV AX, V4 ; V4 = X position + Y position * 64 (screen index) - - MOV V4, [$EFFF] ; Debug - - MOV [V0 + $2003], V5 ; Read character (1FFF + 4 since jump address is 1FFF) - MOV V5, [$EFFF] ; Debug - AND V5, $01 ; Mask to get first bit (color) - MOV DX, V5 - MOV V5, [$EFFF] ; Debug - MUL V5, V3 ; V5 = Character * Color (color index) - MOV AX, V5 ; Store result into V5 - - MOV V5, [$EFFF] ; Debug - - MOVB V5, [V4 + $402F] ; Write character to screen memory - RET \ No newline at end of file diff --git a/ROMs/_old/hello_world.q1 b/ROMs/_old/hello_world.q1 deleted file mode 100644 index fd66ffe..0000000 Binary files a/ROMs/_old/hello_world.q1 and /dev/null differ diff --git a/ROMs/_old/manual.q1 b/ROMs/_old/manual.q1 deleted file mode 100644 index b166c7a..0000000 Binary files a/ROMs/_old/manual.q1 and /dev/null differ diff --git a/ROMs/_old/write_display_direct.asm b/ROMs/_old/write_display_direct.asm deleted file mode 100644 index 9fde417..0000000 --- a/ROMs/_old/write_display_direct.asm +++ /dev/null @@ -1,21 +0,0 @@ -.org $1FFF - -program: -MOV $0000, V0 -MUL 32, 64 ; Set AX to 32 * 64 -MOV AX, V1 ; Copy AX to V1 -MOV 1, V2 ; Color value 1 - -reset: -MOV 0, V0 -INC V2 ; Increment color value - -draw: -GT V0, V1 ; V0 > V1? -BZ ; If number exceeds, branch to reset -JMP reset - -MOVB V2, [V0+$402F] ; Set pixel at V0 to color 6 -INC V0 ; Increment V0 - -JMP draw ; Repeat drawing \ No newline at end of file diff --git a/ROMs/_old/write_display_direct.q1 b/ROMs/_old/write_display_direct.q1 deleted file mode 100644 index 4041649..0000000 Binary files a/ROMs/_old/write_display_direct.q1 and /dev/null differ diff --git a/ROMs/font.bin b/ROMs/font.bin deleted file mode 100644 index 89f2af5..0000000 Binary files a/ROMs/font.bin and /dev/null differ diff --git a/ROMs/hello_c.asm b/ROMs/hello_c.asm deleted file mode 100644 index 16eb6bc..0000000 --- a/ROMs/hello_c.asm +++ /dev/null @@ -1,215 +0,0 @@ - jmp _main - .include "font.bin" -_drawChar_int_ch__int_x__int_y__int_color:; int drawChar(int ch, int x, int y, int color) - pop V0 ; preserve function return address - pop [$71FF] ; param int ch - pop [$7201] ; param int x - pop [$7203] ; param int y - pop [$7205] ; param int color - push V0 ; restore function return address - ; adjust for jmp instruction - push $1FFF ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$7207] ; int fontStart = AX - push [$71FF] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, [$7209] ; int charStart = AX - mov 0, [$720B] ; int yOff = 0 -_body_1: - push [$720B] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_2 ; if for condition fails, jump to end - push [$7207] ; store index obj - push [$7209] ; left operand - mov [$720B], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$720D] ; int row = [V0] - mov 0, [$720F] ; int xOff = 0 -_body_3: - push [$720F] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_4 ; if for condition fails, jump to end - push [$720D] ; left operand - push 7 ; left operand - mov [$720F], V1 ; right operand - pop V0 ; get left operand back - sub V0, V1 ; compute subtraction - mov AX, V1 ; right operand - pop V0 ; get left operand back - shr V0, V1 ; compute right shift - push DX ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - mov DX, [$7211] ; int bit = DX - bz [$7211] ; check ternary condition - jmp _then_5 - mov [$7205], V0 ; store ternary fail result - jmp _end_6 -_then_5: - mov 0, V0 ; store ternary success result -_end_6: - mov V0, [$7213] ; int pix = V0 - push [$7213] ; arg int c - push [$7203] ; left operand - mov [$720B], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int y - push [$7201] ; left operand - mov [$720F], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int x - call _setPixel_int_x__int_y__int_c; int setPixel(int x, int y, int c) - push [$720F] ; i++ - inc [$720F] - pop V0 - jmp _body_3 -_end_4: - push [$720B] ; i++ - inc [$720B] - pop V0 - jmp _body_1 -_end_2: - mov 0, V0 ; fallback return 0 - ret - -_setPixel_int_x__int_y__int_c:; int setPixel(int x, int y, int c) - pop V0 ; preserve function return address - pop [$7215] ; param int x - pop [$7217] ; param int y - pop [$7219] ; param int c - push V0 ; restore function return address - mov $402F, [$721B] ; int screenStart = $402F - push [$7217] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; left operand - mov [$7215], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$721D] ; int i = AX - push [$721B] ; store index obj - mov [$721D], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7219], [V0] ; [V0] = [$7219] - mov 0, V0 ; fallback return 0 - ret - -_clear_int_c: ; int clear(int c) - pop V0 ; preserve function return address - pop [$721F] ; param int c - push V0 ; restore function return address - mov $402F, [$7221] ; int screenStart = $402F - push 64 ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, [$7223] ; int screenSize = AX - mov 0, [$7225] ; int i = 0 -_body_7: - push [$7225] ; left operand - mov [$7223], V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_8 ; if for condition fails, jump to end - push [$7221] ; store index obj - mov [$7225], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$721F], [V0] ; [V0] = [$721F] - push [$7225] ; i++ - inc [$7225] - pop V0 - jmp _body_7 -_end_8: - mov 0, V0 ; fallback return 0 - ret - -_main: ; int main() - mov 1, [$7227] ; int color = 1 - mov 72, [$722B] - mov 69, [$722D] - mov 76, [$722F] - mov 76, [$7231] - mov 79, [$7233] - mov 32, [$7235] - mov 87, [$7237] - mov 79, [$7239] - mov 82, [$723B] - mov 76, [$723D] - mov 68, [$723F] - mov 33, [$7241] - mov $722B, [$7229] ; int text = $722B - mov 12, [$7243] ; int len = 12 - push 0 ; arg int c - call _clear_int_c ; int clear(int c) -_body_9: - not 1 - bz - jmp _end_10 ; if while condition fails, jump to end - mov 0, [$7245] ; int i = 0 -_body_11: - push [$7245] ; left operand - mov [$7243], V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_12 ; if for condition fails, jump to end - push [$7229] ; store index obj - mov [$7245], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 2 ; multiply indexer by 2 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7247] ; int ch = [V0] - push [$7227] ; arg int color - push 0 ; arg int y - push [$7245] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; arg int x - push [$7247] ; arg int ch - call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) - push [$7245] ; i++ - inc [$7245] - pop V0 - jmp _body_11 -_end_12: - push [$7227] ; i++ - inc [$7227] - pop V0 - jmp _body_9 -_end_10: - mov 0, V0 ; fallback return 0 - ret - diff --git a/ROMs/hello_c.c b/ROMs/hello_c.c deleted file mode 100644 index 6be9385..0000000 --- a/ROMs/hello_c.c +++ /dev/null @@ -1,55 +0,0 @@ -#load "font.bin" - -int drawChar(int ch, int x, int y, int color) -{ - // adjust for jmp instruction - char* fontStart = 0x1FFF + 2; - int charStart = ch * 8; - - for (int yOff = 0; yOff < 8; yOff++) - { - int row = fontStart[charStart + yOff]; - - for (int xOff = 0; xOff < 8; xOff++) - { - int bit = (row >> (7 - xOff)) & 1; - int pix = bit ? 0 : color; - setPixel(x + xOff, y + yOff, pix); - } - } -} - -int setPixel(int x, int y, int c) -{ - char* screenStart = 0x402F; - int i = (y * 128) + x; - screenStart[i] = c; -} - -int clear(int c) -{ - char* screenStart = 0x402F; - char screenSize = 64 * 128; - for (int i = 0; i < screenSize; i++) - { - screenStart[i] = c; - } -} - -int main() -{ - int color = 1; - int* text = "HELLO WORLD!"; - int len = 12; - - clear(0); - while (1) - { - for (int i = 0; i < len; i++) - { - int ch = text[i]; - drawChar(ch, i * 8, 0, color); - } - color++; - } -} \ No newline at end of file diff --git a/ROMs/hello_c.q1 b/ROMs/hello_c.q1 deleted file mode 100644 index 5e3248c..0000000 Binary files a/ROMs/hello_c.q1 and /dev/null differ diff --git a/ROMs/hid.c b/ROMs/hid.c deleted file mode 100644 index 11730e9..0000000 --- a/ROMs/hid.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "std.c" - -#define BUS_HID_SK_START 0x6033 -#define BUS_HID_MS_INDEX 0x602F -#define BUS_HID_MS_STATE 0x602F + 2 - -#define SK_MAX 256 -#define SK_NEWLINE 13 -#define SK_BACKSPACE 8 -#define SK_SHIFT 160 -#define SK_A 65 -#define SK_B 66 -#define SK_C 67 -#define SK_D 68 -#define SK_E 69 -#define SK_F 70 -#define SK_G 71 -#define SK_H 72 -#define SK_I 73 -#define SK_J 74 -#define SK_K 75 -#define SK_L 76 -#define SK_M 77 -#define SK_N 78 -#define SK_O 79 -#define SK_P 80 -#define SK_Q 81 -#define SK_R 82 -#define SK_S 83 -#define SK_T 84 -#define SK_U 85 -#define SK_V 86 -#define SK_W 87 -#define SK_X 88 -#define SK_Y 89 -#define SK_Z 90 - -#define MS_LEFT 1 -#define MS_RIGHT 2 -#define MS_MIDDLE 4 - -int hid_getKeyState(int scanCode) -{ - char* sk_table = BUS_HID_SK_START; - int index = scanCode / 8; - int bit = scanCode % 8; - - int val = sk_table[index - 1]; - return (val & (1 << bit)) != 0; -} - -int hid_getPressedKey() -{ - for (int sk = 0; sk < SK_MAX; sk++) - { - if (hid_getKeyState(sk) && sk != SK_SHIFT) - return sk; - } - return 0; -} - -int hid_waitForPressedKey() -{ - while (true) - { - int sk = hid_getPressedKey(); - if (sk != 0) - return sk; - } -} - -int hid_getMouseIndex() -{ - return *(BUS_HID_MS_INDEX); -} - -int hid_getMouseState() -{ - return *(BUS_HID_MS_STATE); -} \ No newline at end of file diff --git a/ROMs/logictest.asm b/ROMs/logictest.asm deleted file mode 100644 index 6a2aac1..0000000 --- a/ROMs/logictest.asm +++ /dev/null @@ -1,140 +0,0 @@ - jmp _main -_screen_setPixel_int_x__int_y__int_c:; int screen_setPixel(int x, int y, int c) - pop V0 ; preserve function return address - pop [$71FF] ; param int x - pop [$7201] ; param int y - pop [$7203] ; param int c - push V0 ; restore function return address - mov $402F, [$7205] ; int screenStart = $402F - push [$7201] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; left operand - mov [$71FF], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$7207] ; int i = AX - push [$7205] ; store index obj - mov [$7207], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7203], [V0] ; [V0] = [$7203] - mov 0, V0 ; fallback return 0 - ret - -_screen_setPixel_int_i__int_c:; int screen_setPixel(int i, int c) - pop V0 ; preserve function return address - pop [$7209] ; param int i - pop [$720B] ; param int c - push V0 ; restore function return address - mov $402F, [$720D] ; int screenStart = $402F - push [$720D] ; store index obj - mov [$7209], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720B], [V0] ; [V0] = [$720B] - mov 0, V0 ; fallback return 0 - ret - -_screen_clear_int_c: ; int screen_clear(int c) - pop V0 ; preserve function return address - pop [$720F] ; param int c - push V0 ; restore function return address - mov $402F, [$7211] ; int screenStart = $402F - mov 0, [$7213] ; int i = 0 -_body_1: - push [$7213] ; left operand - push 128 ; left operand - mov 64, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_2 ; if for condition fails, jump to end - push [$7211] ; store index obj - mov [$7213], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720F], [V0] ; [V0] = [$720F] - push [$7213] ; i++ - inc [$7213] - pop V0 - jmp _body_1 -_end_2: - mov 0, V0 ; fallback return 0 - ret - -_main: ; int main() - ; Test values - mov 0, [$7215] ; int a = 0 - ; 170 - mov 0, [$7217] ; int b = 0 - ; 204 - mov 0, [$7219] ; int c = 0 - ; AND - movb [$7215], [$7219] ; [$7219] = [$7215] - push [$7219] ; left operand - mov [$7217], V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - ; expect 0b10001000 = 136 - mov $7100, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; OR - movb [$7215], [$7219] ; [$7219] = [$7215] - push [$7219] ; left operand - mov [$7217], V1 ; right operand - pop V0 ; get left operand back - or V0, V1 ; compute or - ; expect 0b11101110 = 238 - mov $7101, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; XOR - movb [$7215], [$7219] ; [$7219] = [$7215] - push [$7219] ; left operand - mov [$7217], V1 ; right operand - pop V0 ; get left operand back - xor V0, V1 ; compute exclusive or - ; expect 0b01100110 = 102 - mov $7102, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; NOT - inv [$7215] - movb DX, [$7219] ; [$7219] = DX - ; expect 0b01010101 = 85 - mov $7103, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; SHL - movb [$7215], [$7219] ; [$7219] = [$7215] - push [$7219] ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - shl V0, V1 ; compute left shift - ; expect 0b10101000 = 168 - mov $7104, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; SHR - movb [$7215], [$7219] ; [$7219] = [$7215] - push [$7219] ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - shr V0, V1 ; compute right shift - ; expect 0b00101010 = 42 - mov $7105, V0 ; move pointer into register for dereference - mov [V0], V0 ; move pointer into register for dereference - ; Program ends cleanly - mov 0, V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - diff --git a/ROMs/logictest.c b/ROMs/logictest.c deleted file mode 100644 index f2ef6d9..0000000 --- a/ROMs/logictest.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "std.c" -#include "screen.c" - -int main() -{ - // Test values - char a = 0b10101010; // 170 - char b = 0b11001100; // 204 - char c; - - // AND - c = a & b; // expect 0b10001000 = 136 - *((char*)0x7100) = c; - - // OR - c = a | b; // expect 0b11101110 = 238 - *((char*)0x7101) = c; - - // XOR - c = a ^ b; // expect 0b01100110 = 102 - *((char*)0x7102) = c; - - // NOT - c = ~a; // expect 0b01010101 = 85 - *((char*)0x7103) = c; - - // SHL - c = a << 2; // expect 0b10101000 = 168 - *((char*)0x7104) = c; - - // SHR - c = a >> 2; // expect 0b00101010 = 42 - *((char*)0x7105) = c; - - // Program ends cleanly - return 0; -} \ No newline at end of file diff --git a/ROMs/logictest.q1 b/ROMs/logictest.q1 deleted file mode 100644 index f68eb77..0000000 Binary files a/ROMs/logictest.q1 and /dev/null differ diff --git a/ROMs/paint.asm b/ROMs/paint.asm deleted file mode 100644 index 9a853a4..0000000 --- a/ROMs/paint.asm +++ /dev/null @@ -1,264 +0,0 @@ - jmp _main -_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) - pop V0 ; preserve function return address - pop [$71FF] ; param int scanCode - push V0 ; restore function return address - mov $6033, [$7201] ; int sk_table = $6033 - push [$71FF] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - div V0, V1 ; compute division - mov AX, [$7203] ; int index = AX - push [$71FF] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mod V0, V1 ; compute modulus - mov AX, [$7205] ; int bit = AX - push [$7201] ; store index obj - push [$7203] ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - sub V0, V1 ; compute subtraction - mov AX, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7207] ; int val = [V0] - push [$7207] ; left operand - push 1 ; left operand - mov [$7205], V1 ; right operand - pop V0 ; get left operand back - shl V0, V1 ; compute left shift - mov DX, V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - push DX ; left operand - mov 0, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - mov LX, V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_getPressedKey: ; int hid_getPressedKey() - mov 0, [$7209] ; int sk = 0 -_body_1: - push [$7209] ; left operand - mov 256, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_2 ; if for condition fails, jump to end - push [$7209] ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - cmp V0, 0 ; logical and - not - bz - jmp _clause_3 - mov 0, V0 ; first operand failed, store 0 and skip second - jmp _end_4 -_clause_3: - push [$7209] ; left operand - mov 160, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - cmp LX, 0 ; compare result from second operand to 0 - not - mov LX, V0 ; store second operand result -_end_4: - not V0 - bz ; check if condition - jmp _end_5 ; if succeeds, continue, else jump to end - mov [$7209], V0 ; return value - ret -_end_5: - push [$7209] ; i++ - inc [$7209] - pop V0 - jmp _body_1 -_end_2: - mov 0, V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_waitForPressedKey: ; int hid_waitForPressedKey() -_body_6: - not 1 - bz - jmp _end_7 ; if while condition fails, jump to end - call _hid_getPressedKey ; int hid_getPressedKey() - mov V0, [$720B] ; int sk = V0 - push [$720B] ; left operand - mov 0, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - not LX - bz ; check if condition - jmp _end_8 ; if succeeds, continue, else jump to end - mov [$720B], V0 ; return value - ret -_end_8: - jmp _body_6 -_end_7: - mov 0, V0 ; fallback return 0 - ret - -_hid_getMouseIndex: ; int hid_getMouseIndex() - mov $602F, V0 ; move pointer into register for dereference - mov [V0], V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_getMouseState: ; int hid_getMouseState() - push $602F ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, V0 ; move pointer into register for dereference - mov [V0], V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_screen_setPixel_int_x__int_y__int_c:; int screen_setPixel(int x, int y, int c) - pop V0 ; preserve function return address - pop [$720D] ; param int x - pop [$720F] ; param int y - pop [$7211] ; param int c - push V0 ; restore function return address - mov $402F, [$7213] ; int screenStart = $402F - push [$720F] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; left operand - mov [$720D], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$7215] ; int i = AX - push [$7213] ; store index obj - mov [$7215], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7211], [V0] ; [V0] = [$7211] - mov 0, V0 ; fallback return 0 - ret - -_screen_setPixel_int_i__int_c:; int screen_setPixel(int i, int c) - pop V0 ; preserve function return address - pop [$7217] ; param int i - pop [$7219] ; param int c - push V0 ; restore function return address - mov $402F, [$721B] ; int screenStart = $402F - push [$721B] ; store index obj - mov [$7217], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7219], [V0] ; [V0] = [$7219] - mov 0, V0 ; fallback return 0 - ret - -_screen_clear_int_c: ; int screen_clear(int c) - pop V0 ; preserve function return address - pop [$721D] ; param int c - push V0 ; restore function return address - mov $402F, [$721F] ; int screenStart = $402F - mov 0, [$7221] ; int i = 0 -_body_9: - push [$7221] ; left operand - push 128 ; left operand - mov 64, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_10 ; if for condition fails, jump to end - push [$721F] ; store index obj - mov [$7221], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$721D], [V0] ; [V0] = [$721D] - push [$7221] ; i++ - inc [$7221] - pop V0 - jmp _body_9 -_end_10: - mov 0, V0 ; fallback return 0 - ret - -_main: ; int main() - mov 0, [$7223] ; int color = 0 -_body_11: - not 1 - bz - jmp _end_12 ; if while condition fails, jump to end - call _hid_getMouseIndex ; int hid_getMouseIndex() - mov V0, [$7225] ; int mouseIndex = V0 - call _hid_getMouseState ; int hid_getMouseState() - mov V0, [$7227] ; int mouseState = V0 - push [$7227] ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - not DX - bz ; check if condition - jmp _end_13 ; if succeeds, continue, else jump to end - push [$7223] ; left operand - mov 3, V1 ; right operand - pop V0 ; get left operand back - mod V0, V1 ; compute modulus - push AX ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int i - push [$7225] ; arg int c - call _screen_setPixel_int_i__int_c; int screen_setPixel(int i, int c) -_end_13: - push 67 ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - not V0 - bz ; check if condition - jmp _end_14 ; if succeeds, continue, else jump to end - push 8 ; arg int c - call _screen_clear_int_c ; int screen_clear(int c) -_end_14: - push 65 ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - not V0 - bz ; check if condition - jmp _end_15 ; if succeeds, continue, else jump to end - push [$7223] ; i++ - inc [$7223] - pop V0 -_body_16: - push 65 ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - not V0 - bz - jmp _end_17 ; if while condition fails, jump to end - jmp _body_16 -_end_17: -_end_15: - jmp _body_11 -_end_12: - mov 0, V0 ; fallback return 0 - ret - diff --git a/ROMs/paint.c b/ROMs/paint.c deleted file mode 100644 index 71c478e..0000000 --- a/ROMs/paint.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "std.c" -#include "hid.c" -#include "screen.c" - -int main() -{ - int color = 0; - while (true) - { - int mouseIndex = hid_getMouseIndex(); - int mouseState = hid_getMouseState(); - - if (mouseState & MS_LEFT) - screen_setPixel(mouseIndex, (color % 3) + 1); - - if (hid_getKeyState(SK_C)) - screen_clear(COLOR_BLACK); - - if (hid_getKeyState(SK_A)) - { - color++; - while (hid_getKeyState(SK_A)) { } - } - } -} \ No newline at end of file diff --git a/ROMs/paint.q1 b/ROMs/paint.q1 deleted file mode 100644 index ecf446d..0000000 Binary files a/ROMs/paint.q1 and /dev/null differ diff --git a/ROMs/screen.c b/ROMs/screen.c deleted file mode 100644 index 0eff8c7..0000000 --- a/ROMs/screen.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "std.c" - -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 64 -#define SCREEN_MAX 128 * 64 - -#define COLOR_TRANSPARENT 0 -#define COLOR_RED 1 -#define COLOR_GREEN 2 -#define COLOR_BLUE 3 -#define COLOR_YELLOW 4 -#define COLOR_CYAN 5 -#define COLOR_MAGENTA 6 -#define COLOR_WHITE 7 -#define COLOR_BLACK 8 -#define COLOR_GRAY 9 -#define COLOR_ORANGE 10 -#define COLOR_PURPLE 11 -#define COLOR_BROWN 12 -#define COLOR_LIGHTGRAY 13 -#define COLOR_DARKGRAY 14 -#define COLOR_LIGHTBLUE 15 -#define COLOR_LIGHTGREEN 16 - -#define BUS_SCREEN_PALETTE_START 0x3FFF -#define BUS_SCREEN_PIXELS_START 0x402F - -int screen_setPixel(int x, int y, int c) -{ - char* screenStart = BUS_SCREEN_PIXELS_START; - int i = (y * SCREEN_WIDTH) + x; - screenStart[i] = c; -} - -int screen_setPixel(int i, int c) -{ - char* screenStart = BUS_SCREEN_PIXELS_START; - screenStart[i] = c; -} - -int screen_clear(int c) -{ - char* screenStart = BUS_SCREEN_PIXELS_START; - for (int i = 0; i < SCREEN_MAX; i++) - { - screenStart[i] = c; - } -} \ No newline at end of file diff --git a/ROMs/std.c b/ROMs/std.c deleted file mode 100644 index aa0b85f..0000000 --- a/ROMs/std.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "std.c" - -#define true 1 -#define false 0 \ No newline at end of file diff --git a/ROMs/typewriter.asm b/ROMs/typewriter.asm deleted file mode 100644 index e9a5a4a..0000000 --- a/ROMs/typewriter.asm +++ /dev/null @@ -1,461 +0,0 @@ - jmp _main - .include "font.bin" -_screen_setPixel_int_x__int_y__int_c:; int screen_setPixel(int x, int y, int c) - pop V0 ; preserve function return address - pop [$71FF] ; param int x - pop [$7201] ; param int y - pop [$7203] ; param int c - push V0 ; restore function return address - mov $402F, [$7205] ; int screenStart = $402F - push [$7201] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - push AX ; left operand - mov [$71FF], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$7207] ; int i = AX - push [$7205] ; store index obj - mov [$7207], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$7203], [V0] ; [V0] = [$7203] - mov 0, V0 ; fallback return 0 - ret - -_screen_setPixel_int_i__int_c:; int screen_setPixel(int i, int c) - pop V0 ; preserve function return address - pop [$7209] ; param int i - pop [$720B] ; param int c - push V0 ; restore function return address - mov $402F, [$720D] ; int screenStart = $402F - push [$720D] ; store index obj - mov [$7209], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720B], [V0] ; [V0] = [$720B] - mov 0, V0 ; fallback return 0 - ret - -_screen_clear_int_c: ; int screen_clear(int c) - pop V0 ; preserve function return address - pop [$720F] ; param int c - push V0 ; restore function return address - mov $402F, [$7211] ; int screenStart = $402F - mov 0, [$7213] ; int i = 0 -_body_1: - push [$7213] ; left operand - push 128 ; left operand - mov 64, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_2 ; if for condition fails, jump to end - push [$7211] ; store index obj - mov [$7213], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - movb [$720F], [V0] ; [V0] = [$720F] - push [$7213] ; i++ - inc [$7213] - pop V0 - jmp _body_1 -_end_2: - mov 0, V0 ; fallback return 0 - ret - -_hid_getKeyState_int_scanCode:; int hid_getKeyState(int scanCode) - pop V0 ; preserve function return address - pop [$7215] ; param int scanCode - push V0 ; restore function return address - mov $6033, [$7217] ; int sk_table = $6033 - push [$7215] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - div V0, V1 ; compute division - mov AX, [$7219] ; int index = AX - push [$7215] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mod V0, V1 ; compute modulus - mov AX, [$721B] ; int bit = AX - push [$7217] ; store index obj - push [$7219] ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - sub V0, V1 ; compute subtraction - mov AX, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$721D] ; int val = [V0] - push [$721D] ; left operand - push 1 ; left operand - mov [$721B], V1 ; right operand - pop V0 ; get left operand back - shl V0, V1 ; compute left shift - mov DX, V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - push DX ; left operand - mov 0, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - mov LX, V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_getPressedKey: ; int hid_getPressedKey() - mov 0, [$721F] ; int sk = 0 -_body_3: - push [$721F] ; left operand - mov 256, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_4 ; if for condition fails, jump to end - push [$721F] ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - cmp V0, 0 ; logical and - not - bz - jmp _clause_5 - mov 0, V0 ; first operand failed, store 0 and skip second - jmp _end_6 -_clause_5: - push [$721F] ; left operand - mov 160, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - cmp LX, 0 ; compare result from second operand to 0 - not - mov LX, V0 ; store second operand result -_end_6: - not V0 - bz ; check if condition - jmp _end_7 ; if succeeds, continue, else jump to end - mov [$721F], V0 ; return value - ret -_end_7: - push [$721F] ; i++ - inc [$721F] - pop V0 - jmp _body_3 -_end_4: - mov 0, V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_waitForPressedKey: ; int hid_waitForPressedKey() -_body_8: - not 1 - bz - jmp _end_9 ; if while condition fails, jump to end - call _hid_getPressedKey ; int hid_getPressedKey() - mov V0, [$7221] ; int sk = V0 - push [$7221] ; left operand - mov 0, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute inequality check - not - not LX - bz ; check if condition - jmp _end_10 ; if succeeds, continue, else jump to end - mov [$7221], V0 ; return value - ret -_end_10: - jmp _body_8 -_end_9: - mov 0, V0 ; fallback return 0 - ret - -_hid_getMouseIndex: ; int hid_getMouseIndex() - mov $602F, V0 ; move pointer into register for dereference - mov [V0], V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_hid_getMouseState: ; int hid_getMouseState() - push $602F ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, V0 ; move pointer into register for dereference - mov [V0], V0 ; return value - ret - mov 0, V0 ; fallback return 0 - ret - -_drawChar_int_ch__int_x__int_y__int_color:; int drawChar(int ch, int x, int y, int color) - pop V0 ; preserve function return address - pop [$7223] ; param int ch - pop [$7225] ; param int x - pop [$7227] ; param int y - pop [$7229] ; param int color - push V0 ; restore function return address - ; adjust for jmp instruction - push $1FFF ; left operand - mov 2, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, [$722B] ; int fontStart = AX - push [$7223] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, [$722D] ; int charStart = AX - mov 0, [$722F] ; int yOff = 0 -_body_11: - push [$722F] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_12 ; if for condition fails, jump to end - push [$722B] ; store index obj - push [$722D] ; left operand - mov [$722F], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - mov AX, V1 ; store indexer - pop V0 ; restore index obj - mul V1, 1 ; multiply indexer by 1 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7231] ; int row = [V0] - mov 0, [$7233] ; int xOff = 0 -_body_13: - push [$7233] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_14 ; if for condition fails, jump to end - push [$7231] ; left operand - push 7 ; left operand - mov [$7233], V1 ; right operand - pop V0 ; get left operand back - sub V0, V1 ; compute subtraction - mov AX, V1 ; right operand - pop V0 ; get left operand back - shr V0, V1 ; compute right shift - push DX ; left operand - mov 1, V1 ; right operand - pop V0 ; get left operand back - and V0, V1 ; compute and - mov DX, [$7235] ; int bit = DX - bz [$7235] ; check ternary condition - jmp _then_15 - mov [$7229], V0 ; store ternary fail result - jmp _end_16 -_then_15: - mov 8, V0 ; store ternary success result -_end_16: - mov V0, [$7237] ; int pix = V0 - push [$7237] ; arg int c - push [$7227] ; left operand - mov [$722F], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int y - push [$7225] ; left operand - mov [$7233], V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int x - call _screen_setPixel_int_x__int_y__int_c; int screen_setPixel(int x, int y, int c) - push [$7233] ; i++ - inc [$7233] - pop V0 - jmp _body_13 -_end_14: - push [$722F] ; i++ - inc [$722F] - pop V0 - jmp _body_11 -_end_12: - mov 0, V0 ; fallback return 0 - ret - -_print_int*_text__int_len__int_x__int_y__int_color:; int print(int* text, int len, int x, int y, int color) - pop V0 ; preserve function return address - pop [$7239] ; param int* text - pop [$723B] ; param int len - pop [$723D] ; param int x - pop [$723F] ; param int y - pop [$7241] ; param int color - push V0 ; restore function return address - mov 0, [$7243] ; int i = 0 -_body_17: - push [$7243] ; left operand - mov [$723B], V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz - jmp _end_18 ; if for condition fails, jump to end - push [$7239] ; store index obj - mov [$7243], V1 ; store indexer - pop V0 ; restore index obj - mul V1, 2 ; multiply indexer by 2 - add AX, V0 ; add indexer and index obj - mov AX, V0 ; move to general purpose register - mov [V0], [$7245] ; int ch = [V0] - push [$7241] ; arg int color - push [$723F] ; arg int y - push [$723D] ; left operand - push [$7243] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - mul V0, V1 ; compute multiplication - mov AX, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; arg int x - push [$7245] ; arg int ch - call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) - push [$7243] ; i++ - inc [$7243] - pop V0 - jmp _body_17 -_end_18: - mov 0, V0 ; fallback return 0 - ret - -_main: ; int main() - mov 0, [$7247] ; int x = 0 - mov 0, [$7249] ; int y = 0 -_body_19: - not 1 - bz - jmp _end_20 ; if while condition fails, jump to end - push [$7247] ; left operand - mov 128, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute equality check - bz - jmp _end_21 - gt V0, V1 -_end_21: - not LX - bz ; check if condition - jmp _end_22 ; if succeeds, continue, else jump to end - mov 0, [$7247] ; [$7247] = 0 - push [$7249] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; computation results - pop V1 ; get computation results back - mov V1, [$7249] ; store back into left param -_end_22: - push [$7249] ; left operand - mov 64, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute equality check - bz - jmp _end_23 - gt V0, V1 -_end_23: - not LX - bz ; check if condition - jmp _end_24 ; if succeeds, continue, else jump to end - mov 0, [$7247] ; [$7247] = 0 - mov 0, [$7249] ; [$7249] = 0 - push 8 ; arg int c - call _screen_clear_int_c ; int screen_clear(int c) -_end_24: - call _hid_waitForPressedKey; int hid_waitForPressedKey() - mov V0, [$724B] ; int sk = V0 -_body_25: - push [$724B] ; arg int scanCode - call _hid_getKeyState_int_scanCode; int hid_getKeyState(int scanCode) - not V0 - bz - jmp _end_26 ; if while condition fails, jump to end - jmp _body_25 -_end_26: - push [$724B] ; left operand - mov 13, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute equality check - not LX - bz ; check if condition - jmp _end_27 ; if succeeds, continue, else jump to end - push [$7249] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; computation results - pop V1 ; get computation results back - mov V1, [$7249] ; store back into left param - mov 0, [$7247] ; [$7247] = 0 - jmp _body_19 ; continue -_end_27: - push [$724B] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - cmp V0, V1 ; compute equality check - not LX - bz ; check if condition - jmp _end_28 ; if succeeds, continue, else jump to end - push [$7247] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - sub V0, V1 ; compute subtraction - push AX ; computation results - pop V1 ; get computation results back - mov V1, [$7247] ; store back into left param - push [$7247] ; left operand - mov 0, V1 ; right operand - pop V0 ; get left operand back - lt V0, V1 ; compute less than check - not LX - bz ; check if condition - jmp _end_29 ; if succeeds, continue, else jump to end - mov 0, [$7247] ; [$7247] = 0 -_end_29: - push 1 ; arg int color - push [$7249] ; arg int y - push [$7247] ; arg int x - push 32 ; arg int ch - call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) - jmp _body_19 ; continue -_end_28: - push 1 ; arg int color - push [$7249] ; arg int y - push [$7247] ; arg int x - push [$724B] ; arg int ch - call _drawChar_int_ch__int_x__int_y__int_color; int drawChar(int ch, int x, int y, int color) - push [$7247] ; left operand - mov 8, V1 ; right operand - pop V0 ; get left operand back - add V0, V1 ; compute addition - push AX ; computation results - pop V1 ; get computation results back - mov V1, [$7247] ; store back into left param - jmp _body_19 -_end_20: - mov 0, V0 ; fallback return 0 - ret - diff --git a/ROMs/typewriter.c b/ROMs/typewriter.c deleted file mode 100644 index df8f3b7..0000000 --- a/ROMs/typewriter.c +++ /dev/null @@ -1,75 +0,0 @@ -#load "font.bin" -#include "std.c" -#include "screen.c" -#include "hid.c" - -int drawChar(int ch, int x, int y, int color) -{ - // adjust for jmp instruction - char* fontStart = 0x1FFF + 2; - int charStart = ch * 8; - - for (int yOff = 0; yOff < 8; yOff++) - { - int row = fontStart[charStart + yOff]; - - for (int xOff = 0; xOff < 8; xOff++) - { - int bit = (row >> (7 - xOff)) & 1; - int pix = bit ? COLOR_BLACK : color; - screen_setPixel(x + xOff, y + yOff, pix); - } - } -} - -int print(int* text, int len, int x, int y, int color) -{ - for (int i = 0; i < len; i++) - { - int ch = text[i]; - drawChar(ch, x + (i * 8), y, color); - } -} - -int main() -{ - int x = 0; - int y = 0; - while (true) - { - if (x >= SCREEN_WIDTH) - { - x = 0; - y += 8; - } - - if (y >= SCREEN_HEIGHT) - { - x = 0; - y = 0; - screen_clear(COLOR_BLACK); - } - - int sk = hid_waitForPressedKey(); - while (hid_getKeyState(sk)) { } - - if (sk == SK_NEWLINE) - { - y += 8; - x = 0; - continue; - } - - if (sk == SK_BACKSPACE) - { - x -= 8; - if (x < 0) - x = 0; - drawChar(' ', x, y, 1); - continue; - } - - drawChar(sk, x, y, COLOR_RED); - x += 8; - } -} \ No newline at end of file diff --git a/ROMs/typewriter.q1 b/ROMs/typewriter.q1 deleted file mode 100644 index 163bb6f..0000000 Binary files a/ROMs/typewriter.q1 and /dev/null differ diff --git a/RegionVisualiser/BoxDrawer.cs b/RegionVisualiser/BoxDrawer.cs deleted file mode 100644 index 77d0fc7..0000000 --- a/RegionVisualiser/BoxDrawer.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace RegionVisualiser; - -public static class BoxDrawer -{ - public static void DrawBox(string title, string body, int width = 0, string head = "", string tail = "") - { - int leftPad = Math.Max(head.Length, tail.Length); - var lines = body.Split('\n'); - int maxWidth = Math.Max(Math.Max(title.Length + 2, BoxDrawer.GetMaxWidth(lines) + 1), width); - - // Top border with centered title - string top = "┌" + BoxDrawer.CenterText($" {title} ", maxWidth, '─') + "┐"; - Console.Write(head); - Console.CursorLeft = leftPad; - Console.WriteLine(top); - - // Body lines, left aligned - foreach (var line in lines) - { - Console.CursorLeft = leftPad; - Console.WriteLine("│ " + line.PadRight(maxWidth - 1) + "│"); - } - - // Bottom border - string bottom = "└" + new string('─', maxWidth) + "┘"; - Console.Write(tail); - Console.CursorLeft = leftPad; - Console.WriteLine(bottom); - } - - private static int GetMaxWidth(string[] lines) - { - int width = 0; - foreach (var l in lines) - if (l.Length + 1 > width) width = l.Length + 1; - return width; - } - - private static string CenterText(string text, int width, char fill) - { - int totalPad = width - text.Length; - if (totalPad <= 0) return text; - - int left = totalPad / 2; - int right = totalPad - left; - - return new string(fill, left) + text + new string(fill, right); - } -} \ No newline at end of file diff --git a/RegionVisualiser/Program.cs b/RegionVisualiser/Program.cs deleted file mode 100644 index 029f324..0000000 --- a/RegionVisualiser/Program.cs +++ /dev/null @@ -1,74 +0,0 @@ -namespace RegionVisualiser; - -using Q1.Emulator; - -class Program -{ - static void Main(string[] args) - { - Region[] regions = - [ - new Region - { - Name = "ROM", - Info = $"ProgramStart: 0x{Q1Layout.ProgramStart:X4}", - Start = Q1Layout.Rom.start, - Size = Q1Layout.Rom.size - }, - new Region - { - Name = "Memory", - Info = - $"Stack: 0x{Q1Layout.StackStart:X4}-0x{Q1Layout.StackStart + Q1Layout.StackLength:X4}" - + $" ({Q1Layout.StackLength}b)\n" - + $"Free : 0x{Q1Layout.FreeMemoryStart:X4}", - Start = Q1Layout.Memory.start, - Size = Q1Layout.Memory.size - }, - new Region - { - Name = "Display", - Info = $"Palette : {Q1Layout.DisplayPaletteSize} colors\n" - + $"Offset : 0x{Q1Layout.Display.start + Q1Layout.DisplayPaletteSize * 3:X4}\n" - + $"Dimensions: {Q1Layout.DisplayWidth}x{Q1Layout.DisplayHeight}", - Start = Q1Layout.Display.start, - Size = Q1Layout.Display.size - }, - new Region - { - Name = "HID Module", - Info = $"Mouse IDX : 0x{Q1Layout.Hid.start:X4}\n" - + $"Mouse state: 0x{Q1Layout.Hid.start + 2:X4}\n" - + $"Keyboard SK: 0x{Q1Layout.Hid.start + 4:X4}", - Start = Q1Layout.Hid.start, - Size = Q1Layout.Hid.size - }, - ]; - - regions = regions.OrderBy(x => x.Start).ToArray(); - - int lastRegionEnd = -1; - for (int i = 0; i < regions.Length; i++) - { - Region r = regions[i]; - if (r.Start != lastRegionEnd + 1) - { - Console.WriteLine($" 0x{lastRegionEnd + 1:X4} ────" + new string('─', 50)); - Console.WriteLine($" [ Unmapped / Reserved ({SizeFormatter.HumanReadable(r.Start - lastRegionEnd)}) ]"); - } - BoxDrawer.DrawBox( - $"{r.Name} ({SizeFormatter.HumanReadable(r.Size)})", - r.Info, - width: 50, - head: $" 0x{r.Start:X4} ── "); - - lastRegionEnd = r.End; - } - - if (lastRegionEnd + 1 != UInt16.MaxValue) - { - Console.WriteLine($" 0x{lastRegionEnd + 1:X4} ────" + new string('─', 50)); - Console.WriteLine($" [ Unmapped / Reserved ({SizeFormatter.HumanReadable(UInt16.MaxValue - lastRegionEnd)}) ]"); - } - } -} \ No newline at end of file diff --git a/RegionVisualiser/Region.cs b/RegionVisualiser/Region.cs deleted file mode 100644 index bee39f5..0000000 --- a/RegionVisualiser/Region.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace RegionVisualiser; - -public class Region -{ - public string Name; - public int Start; - public int Size; - public int End => this.Start + this.Size -1; - public string Info; -} \ No newline at end of file diff --git a/RegionVisualiser/RegionVisualiser.csproj b/RegionVisualiser/RegionVisualiser.csproj deleted file mode 100644 index d7bfae3..0000000 --- a/RegionVisualiser/RegionVisualiser.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net9.0 - enable - enable - - - - - - - diff --git a/RegionVisualiser/SizeFormatter.cs b/RegionVisualiser/SizeFormatter.cs deleted file mode 100644 index 3479bd8..0000000 --- a/RegionVisualiser/SizeFormatter.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace RegionVisualiser; - -public static class SizeFormatter -{ - private static readonly string[] Units = ["bytes", "KB", "MB", "GB", "TB"]; - - public static string HumanReadable(long bytes) - { - if (bytes < 1024) return $"{bytes} {SizeFormatter.Units[0]}"; - - double value = bytes; - int unit = 0; - - while (value >= 1024 && unit < SizeFormatter.Units.Length - 1) - { - value /= 1024; - unit++; - } - - // Show up to 2 decimal places if not whole - return value % 1 == 0 - ? $"{value:0} {SizeFormatter.Units[unit]}" - : $"{value:0.##} {SizeFormatter.Units[unit]}"; - } -} \ No newline at end of file diff --git a/RegionVisualiser/output.txt b/RegionVisualiser/output.txt deleted file mode 100644 index 10d7970..0000000 --- a/RegionVisualiser/output.txt +++ /dev/null @@ -1,24 +0,0 @@ - - 0x0000 ────────────────────────────────────────────────────── - [ Unmapped / Reserved (8 KB) ] - 0x1FFF ── ┌─────────────────── ROM (8 KB) ───────────────────┐ - │ ProgramStart: 0x1FFF │ - └──────────────────────────────────────────────────┘ - 0x3FFF ── ┌─────────────── Display (8.05 KB) ────────────────┐ - │ Palette : 16 colors │ - │ Offset : 0x402F │ - │ Dimensions: 128x64 │ - └──────────────────────────────────────────────────┘ - 0x602F ── ┌───────────── HID Module (260 bytes) ─────────────┐ - │ Mouse IDX : 0x602F │ - │ Mouse state: 0x6031 │ - │ Keyboard SK: 0x6033 │ - └──────────────────────────────────────────────────┘ - 0x6133 ────────────────────────────────────────────────────── - [ Unmapped / Reserved (3.7 KB) ] - 0x6FFF ── ┌───────────────── Memory (16 KB) ─────────────────┐ - │ Stack: 0x6FFF-0x71FF (512b) │ - │ Free : 0x71FF │ - └──────────────────────────────────────────────────┘ - 0xAFFF ────────────────────────────────────────────────────── - [ Unmapped / Reserved (20 KB) ] \ No newline at end of file -- cgit v1.3.1