From 0d57c3b1aad4137a6c96db0b9f71dfb04038def1 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 21 Jul 2023 16:30:51 +0100 Subject: Create separate PatioDataLayouts util class --- .../compiler/patio/PatioCodeGenClosures.java | 13 +++++------- .../compiler/patio/PatioCodeGenNamespaces.java | 9 ++++---- .../compiler/patio/ast/types/PatioDataLayouts.java | 24 ++++++++++++++++++++++ .../compiler/patio/ast/types/PatioTypes.java | 18 ---------------- 4 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 590c41ba..9d7f8729 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -6,10 +6,7 @@ import org.shedlang.compiler.patio.ast.PatioVisibility; import org.shedlang.compiler.patio.ast.instructions.*; import org.shedlang.compiler.patio.ast.operands.PatioFunctionPtr; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioStruct; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.ast.types.*; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; import org.shedlang.compiler.util.Lists; @@ -31,14 +28,14 @@ class PatioCodeGenClosures { private static PatioDataLayout closureDataLayoutForCall() { return new PatioStruct(List.of( - PatioTypes.scalar(PatioTypes.FUNCTION_POINTER) + PatioDataLayouts.scalar(PatioTypes.FUNCTION_POINTER) )); } private static PatioDataLayout closureDataLayout(int freeVariableCount) { - return PatioTypes.struct(List.of( - PatioTypes.scalar(PatioTypes.FUNCTION_POINTER), - PatioTypes.structFlat(Lists.repeat(PatioCodeGenTypes.VALUE_TYPE, freeVariableCount)) + return PatioDataLayouts.struct(List.of( + PatioDataLayouts.scalar(PatioTypes.FUNCTION_POINTER), + PatioDataLayouts.structFlat(Lists.repeat(PatioCodeGenTypes.VALUE_TYPE, freeVariableCount)) )); } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java index eed8e7ec..fbbd5c79 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java @@ -8,6 +8,7 @@ import org.shedlang.compiler.patio.ast.operands.PatioDataPtr; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; import org.shedlang.compiler.patio.ast.operands.PatioOperand; import org.shedlang.compiler.patio.ast.types.PatioDataLayout; +import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; import org.shedlang.compiler.patio.ast.types.PatioType; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; @@ -44,7 +45,7 @@ public class PatioCodeGenNamespaces { context = context.addDataElement( globalNameNamespaceIsInited(namespaceName), - PatioTypes.scalar(PatioTypes.BOOL), + PatioDataLayouts.scalar(PatioTypes.BOOL), source ); @@ -58,7 +59,7 @@ public class PatioCodeGenNamespaces { initContext = initContext.addInstruction(new PatioMemoryStore( new PatioDataPtr(globalNameNamespaceIsInited(namespaceName)), - PatioTypes.scalar(PatioTypes.BOOL), + PatioDataLayouts.scalar(PatioTypes.BOOL), List.of(), new PatioBool(true), source @@ -84,7 +85,7 @@ public class PatioCodeGenNamespaces { importContext = importContext.addInstruction(new PatioMemoryLoad( isInited, new PatioDataPtr(globalNameNamespaceIsInited(namespaceName)), - PatioTypes.scalar(PatioTypes.BOOL), + PatioDataLayouts.scalar(PatioTypes.BOOL), List.of(), source )); @@ -211,7 +212,7 @@ public class PatioCodeGenNamespaces { } private static PatioDataLayout namespaceDataLayout(NamespaceTypeInfo namespaceTypeInfo) { - return PatioTypes.structFlat( + return PatioDataLayouts.structFlat( Lists.repeat( PatioCodeGenTypes.VALUE_TYPE, namespaceTypeInfo.fieldCount() diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java new file mode 100644 index 00000000..b2a83f7a --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.patio.ast.types; + +import java.util.List; + +public class PatioDataLayouts { + private PatioDataLayouts() { + } + + public static PatioDataLayout scalar(PatioType type) { + return new PatioScalar(type); + } + + public static PatioDataLayout structFlat(List elements) { + return new PatioStruct( + elements.stream() + .map(element -> scalar(element)) + .toList() + ); + } + + public static PatioDataLayout struct(List elements) { + return new PatioStruct(elements); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java index 8e53c095..35f82222 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java @@ -1,7 +1,5 @@ package org.shedlang.compiler.patio.ast.types; -import java.util.List; - public class PatioTypes { private PatioTypes() { } @@ -11,20 +9,4 @@ public class PatioTypes { public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE; public static final PatioIntType INT = PatioIntType.INSTANCE; public static final PatioVoidType VOID = PatioVoidType.INSTANCE; - - public static PatioDataLayout scalar(PatioType type) { - return new PatioScalar(type); - } - - public static PatioDataLayout structFlat(List elements) { - return new PatioStruct( - elements.stream() - .map(element -> scalar(element)) - .toList() - ); - } - - public static PatioDataLayout struct(List elements) { - return new PatioStruct(elements); - } } -- cgit v1.2.3