From e67385e2086ae14c430865e4577986dacba72256 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 13 Dec 2023 21:31:56 +0000 Subject: Extract PatioCodeGenAlloc class --- .../shedlang/compiler/patio/PatioCodeGenAlloc.java | 20 ++++++++++++++++++++ .../compiler/patio/PatioCodeGenClosures.java | 2 +- .../shedlang/compiler/patio/PatioCodeGenEffects.java | 9 +++++---- .../shedlang/compiler/patio/PatioCodeGenStructs.java | 7 ++++--- .../shedlang/compiler/patio/PatioCodeGenTuples.java | 7 ++++--- 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioCodeGenAlloc.java (limited to 'src/main/java') 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); -- cgit v1.2.3