aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-21 13:48:48 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-21 13:49:17 +0100
commit07eeb10e60c198be0e744881189daae810f9c603 (patch)
tree5d30c12db8fbb03c8ec665fcdf4f250f3367dae4 /src/main/java
parent4767848c0272da0468df8ff66c88daa39018de5e (diff)
Add Patio code gen for namespace-field-store
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java16
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java28
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java3
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java1
4 files changed, 43 insertions, 5 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index 452a044e..491b50ae 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -215,6 +215,22 @@ public class PatioCodeGen {
yield context.temporaryPopIntoLocal(local, localStore.source());
}
+ case NamespaceFieldStoreInstruction namespaceFieldStore -> {
+ var fieldValueResult = context.temporaryPop();
+ var fieldValue = fieldValueResult.value();
+ context = fieldValueResult.context();
+
+ context = PatioCodeGenNamespaces.fieldStore(
+ namespaceFieldStore.namespaceName(),
+ namespaceFieldStore.fieldName(),
+ fieldValue,
+ namespaceFieldStore.source(),
+ context
+ );
+
+ yield context;
+ }
+
case NamespaceImportInstruction namespaceImport -> {
var namespaceValueResult = context.allocateLocal(
PatioCodeGenLocalSpace.NAMESPACE_VALUE,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
index 824fbc79..eed8e7ec 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
@@ -6,6 +6,7 @@ import org.shedlang.compiler.patio.ast.instructions.*;
import org.shedlang.compiler.patio.ast.operands.PatioBool;
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.PatioType;
import org.shedlang.compiler.patio.ast.types.PatioTypes;
@@ -155,17 +156,17 @@ public class PatioCodeGenNamespaces {
public static PatioCodeGenContext fieldLoad(
PatioLocalRef target,
PatioLocalRef receiver,
- NamespaceName nameSpaceName,
+ NamespaceName namespaceName,
String fieldName,
Source source,
PatioCodeGenContext context
) {
- var namespaceTypeInfo = context.namespaceTypeInfo(nameSpaceName);
+ var namespaceTypeInfo = context.namespaceTypeInfo(namespaceName);
var layout = namespaceDataLayout(namespaceTypeInfo);
var namespacePointerResult = context.allocateLocal(
PatioCodeGenLocalSpace.NAMESPACE_POINTER,
- namespaceNameToPatioIdentifier(nameSpaceName),
+ namespaceNameToPatioIdentifier(namespaceName),
PatioTypes.DATA_POINTER
);
var namespacePointer = namespacePointerResult.value();
@@ -188,6 +189,27 @@ public class PatioCodeGenNamespaces {
return context;
}
+ public static PatioCodeGenContext fieldStore(
+ NamespaceName namespaceName,
+ String fieldName,
+ PatioOperand fieldValue,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ var namespaceTypeInfo = context.namespaceTypeInfo(namespaceName);
+ var layout = namespaceDataLayout(namespaceTypeInfo);
+
+ context = context.addInstruction(new PatioMemoryStore(
+ new PatioDataPtr(globalNameNamespaceValue(namespaceName)),
+ layout,
+ List.of(namespaceTypeInfo.fieldIndex(fieldName)),
+ fieldValue,
+ source
+ ));
+
+ return context;
+ }
+
private static PatioDataLayout namespaceDataLayout(NamespaceTypeInfo namespaceTypeInfo) {
return PatioTypes.structFlat(
Lists.repeat(
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java
index 7680645a..60ae81de 100644
--- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java
+++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java
@@ -1,11 +1,12 @@
package org.shedlang.compiler.patio.ast.instructions;
import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
+import org.shedlang.compiler.patio.ast.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
public record PatioIntToDataPtr(
PatioLocalRef target,
- PatioLocalRef value,
+ PatioOperand value,
Source source
) implements PatioInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java
index f48f0a75..ca283284 100644
--- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java
+++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java
@@ -1,6 +1,5 @@
package org.shedlang.compiler.patio.ast.instructions;
-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.sources.Source;