diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-16 15:34:14 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-16 15:34:14 +0000 |
| commit | 8042cb4484890a23356550acbdd9133b1e43e40e (patch) | |
| tree | fa84f5175585b65bb41da13449e25a56c859fbff /src/main/java | |
| parent | a05815c8267903d12470f1e5915d04e7260ce035 (diff) | |
Extract PatioCodeGenVars
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java | 22 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java | 45 |
2 files changed, 55 insertions, 12 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index 0c5db60b..1f676b6b 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -774,13 +774,12 @@ public class PatioCodeGen { var varValue = varValueResult.value(); context = varValueResult.context(); - context = context.addInstruction(new PatioMemoryLoad( + context = PatioCodeGenVars.load( varValue, - context.shidLocalNameToLocal(varLoad.name()), - PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), - List.of(), - varLoad.source() - )); + varLoad.name(), + varLoad.source(), + context + ); context = context.temporaryPush(varValue); @@ -792,13 +791,12 @@ public class PatioCodeGen { var value = valueResult.value(); context = valueResult.context(); - context = context.addInstruction(new PatioMemoryStore( - context.shidLocalNameToLocal(varStore.name()), - PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), - List.of(), + context = PatioCodeGenVars.store( + varStore.name(), value, - varStore.source() - )); + varStore.source(), + context + ); yield context; } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java new file mode 100644 index 00000000..ebf8b847 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenVars.java @@ -0,0 +1,45 @@ +package org.shedlang.compiler.patio; + +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.sources.Source; + +import java.util.List; + +public class PatioCodeGenVars { + private PatioCodeGenVars() { + } + + public static PatioCodeGenContext store( + String name, + PatioOperand value, + Source source, + PatioCodeGenContext context + ) { + return context.addInstruction(new PatioMemoryStore( + context.shidLocalNameToLocal(name), + PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), + List.of(), + value, + source + )); + } + + public static PatioCodeGenContext load( + PatioLocalRef target, + String name, + Source source, + PatioCodeGenContext context + ) { + return context.addInstruction(new PatioMemoryLoad( + target, + context.shidLocalNameToLocal(name), + PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), + List.of(), + source + )); + } +} |
