diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-16 15:37:13 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-16 15:37:13 +0000 |
| commit | b6ade34f14bc5049e036a43f640b862f6c3390bc (patch) | |
| tree | c051a8e3a59bd03bbdf3dc195780e3b0d08ceec0 /src/main/java/org | |
| parent | 8042cb4484890a23356550acbdd9133b1e43e40e (diff) | |
Extract PatioCodeGenVars.alloc()
Diffstat (limited to 'src/main/java/org')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java | 18 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java | 33 |
2 files changed, 33 insertions, 18 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index 1f676b6b..81fa758d 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -6,7 +6,6 @@ import org.shedlang.compiler.patio.ast.instructions.*; import org.shedlang.compiler.patio.ast.operands.PatioInt; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.shid.instructions.*; @@ -967,21 +966,12 @@ public class PatioCodeGen { ).context(); } case VAR -> { - var patioLocalResult = context.declareShidVal( + context = PatioCodeGenVars.alloc( boundVariable.name(), - PatioTypes.DATA_POINTER + // TODO: proper source (probably by storing variables on the function/namespace) + Sources.NULL, + context ); - var patioLocal = patioLocalResult.value(); - context = patioLocalResult.context(); - - // TODO: proper source (probably by storing variables on the function/namespace) - context = context.addInstruction(new PatioAllocStack( - patioLocal, - PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), - Sources.NULL - )); - - context = context.initShidLocal(boundVariable.name()); } } } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java index ebf8b847..cd85e2cd 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java @@ -1,10 +1,12 @@ package org.shedlang.compiler.patio; +import org.shedlang.compiler.patio.ast.instructions.PatioAllocStack; import org.shedlang.compiler.patio.ast.instructions.PatioMemoryLoad; import org.shedlang.compiler.patio.ast.instructions.PatioMemoryStore; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; import org.shedlang.compiler.patio.ast.operands.PatioOperand; import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; +import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; import java.util.List; @@ -13,14 +15,37 @@ public class PatioCodeGenVars { private PatioCodeGenVars() { } + public static PatioCodeGenContext alloc( + String shidName, + Source source, + PatioCodeGenContext context + ) { + var patioLocalResult = context.declareShidVal( + shidName, + PatioTypes.DATA_POINTER + ); + var patioLocal = patioLocalResult.value(); + context = patioLocalResult.context(); + + context = context.addInstruction(new PatioAllocStack( + patioLocal, + PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), + source + )); + + context = context.initShidLocal(shidName); + + return context; + } + public static PatioCodeGenContext store( - String name, + String shidName, PatioOperand value, Source source, PatioCodeGenContext context ) { return context.addInstruction(new PatioMemoryStore( - context.shidLocalNameToLocal(name), + context.shidLocalNameToLocal(shidName), PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), List.of(), value, @@ -30,13 +55,13 @@ public class PatioCodeGenVars { public static PatioCodeGenContext load( PatioLocalRef target, - String name, + String shidName, Source source, PatioCodeGenContext context ) { return context.addInstruction(new PatioMemoryLoad( target, - context.shidLocalNameToLocal(name), + context.shidLocalNameToLocal(shidName), PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), List.of(), source |
