aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-13 21:31:56 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-13 21:31:56 +0000
commite67385e2086ae14c430865e4577986dacba72256 (patch)
tree7b52d9dbbb81bfa9ce65f03f332eb2dea0e26af1 /src/main/java
parentd00493a763a368825f17f2525c3f1c2cb23ad9de (diff)
Extract PatioCodeGenAlloc class
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenAlloc.java20
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java2
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java9
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java7
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenTuples.java7
5 files changed, 34 insertions, 11 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenAlloc.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenAlloc.java
new file mode 100644
index 00000000..e90592b9
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenAlloc.java
@@ -0,0 +1,20 @@
+package org.shedlang.compiler.patio;
+
+import org.shedlang.compiler.patio.ast.instructions.PatioAllocHeap;
+import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
+import org.shedlang.compiler.patio.ast.types.PatioDataLayout;
+import org.shedlang.compiler.sources.Source;
+
+public class PatioCodeGenAlloc {
+ private PatioCodeGenAlloc() {
+ }
+
+ public static PatioCodeGenContext alloc(
+ PatioLocalRef target,
+ PatioDataLayout layout,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ return context.addInstruction(new PatioAllocHeap(target, layout, source));
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index 9030a5d0..c6c19dce 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -110,7 +110,7 @@ class PatioCodeGenClosures {
var closurePointer = closurePointerResult.value();
context = closurePointerResult.context();
- context = context.addInstruction(new PatioAllocHeap(closurePointer, layout, source));
+ context = PatioCodeGenAlloc.alloc(closurePointer, layout, source, context);
context = context.addInstruction(new PatioMemoryStore(
closurePointer,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
index 4dbb7438..1a740cdd 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
@@ -133,11 +133,12 @@ public class PatioCodeGenEffects {
var effectLayout = userDefinedEffectLayout(effect, context);
- context = context.addInstruction(new PatioAllocHeap(
+ context = PatioCodeGenAlloc.alloc(
effectPointer,
effectLayout,
- source
- ));
+ source,
+ context
+ );
var effectInfo = context.userDefinedEffectInfo(effect);
for (var method : effectInfo.methods()) {
@@ -443,7 +444,7 @@ public class PatioCodeGenEffects {
var closurePointer = closurePointerResult.value();
context = closurePointerResult.context();
- context = context.addInstruction(new PatioAllocHeap(closurePointer, layout, source));
+ context = PatioCodeGenAlloc.alloc(closurePointer, layout, source, context);
context = context.addInstruction(new PatioMemoryStore(
closurePointer,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
index 6ef49080..b0505d69 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
@@ -44,11 +44,12 @@ public class PatioCodeGenStructs {
var structDataLayout = structDataLayout(type, context);
- bodyContext = bodyContext.addInstruction(new PatioAllocHeap(
+ bodyContext = PatioCodeGenAlloc.alloc(
valuePointer,
structDataLayout,
- source
- ));
+ source,
+ bodyContext
+ );
bodyContext = bodyContext
.addInstruction(new PatioMemoryStore(
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenTuples.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenTuples.java
index c3e1c964..9e2f7421 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenTuples.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenTuples.java
@@ -47,11 +47,12 @@ public class PatioCodeGenTuples {
var tupleLayout = tupleDataLayout(elements.size());
- context = context.addInstruction(new PatioAllocHeap(
+ context = PatioCodeGenAlloc.alloc(
tuplePointer,
tupleLayout,
- source
- ));
+ source,
+ context
+ );
for (var elementIndex = 0; elementIndex < elements.size(); elementIndex++) {
var element = elements.get(elementIndex);