diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-03-17 20:49:22 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-03-17 20:49:22 +1000 |
| commit | 18868128e18d38b706e7df14e8e683e1a9739c17 (patch) | |
| tree | 6f0e0e5eee646f10cbad9c0c89c24d330bc58cc6 /Compiler/visitors/Targets.cs | |
| parent | d87ab8af4c86a3fc6ee237444e372d87e536e3ef (diff) | |
chore: Initial commit
Diffstat (limited to 'Compiler/visitors/Targets.cs')
| -rw-r--r-- | Compiler/visitors/Targets.cs | 40 |
1 files changed, 0 insertions, 40 deletions
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 |
