aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-03 18:37:40 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-03 18:37:40 +0000
commit88fb47120e293fad7cf3ecf5439a28136cb93eb2 (patch)
tree5dcad1e13634ebbd431a5227ff712abc3a2265d3 /src/main/java
parent806236a75e0cb2241d6a6e97b33da049e069f8b1 (diff)
Add Shid instruction to declare native type
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/shid/ShidSerializer.java11
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDeclareNativeType.java18
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java2
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java4
4 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java
index fa38365f..6a60ccc8 100644
--- a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java
+++ b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java
@@ -3,6 +3,7 @@ package org.shedlang.compiler.shid;
import org.shedlang.compiler.shid.instructions.*;
import org.shedlang.compiler.treetext.Tree;
import org.shedlang.compiler.types.NamespaceName;
+import org.shedlang.compiler.types.SimpleNativeType;
import org.shedlang.compiler.types.SimpleStructType;
import org.shedlang.compiler.types.UserDefinedEffect;
@@ -83,6 +84,12 @@ public class ShidSerializer {
namedParamsToTree(declareNativeFunction.namedParams())
);
+ case ShidDeclareNativeType declareNativeType ->
+ treeList(
+ treeIdentifier("declare-native-type"),
+ nativeTypeToTree(declareNativeType.type())
+ );
+
case ShidDefineEffect defineEffectInstruction ->
treeList(
treeIdentifier("define-effect"),
@@ -363,6 +370,10 @@ public class ShidSerializer {
return treeString(effect.describe());
}
+ private static Tree nativeTypeToTree(SimpleNativeType type) {
+ return treeString(type.describe());
+ }
+
private static Tree structTypeToTree(SimpleStructType type) {
return treeString(type.describe());
}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidDeclareNativeType.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDeclareNativeType.java
new file mode 100644
index 00000000..d4ffbeda
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDeclareNativeType.java
@@ -0,0 +1,18 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+import org.shedlang.compiler.types.SimpleNativeType;
+
+/**
+ * Push a native native type value onto the temporary value stack with the given
+ * declaration.
+ */
+public record ShidDeclareNativeType(
+ SimpleNativeType type,
+ Source source
+) implements ShidInstruction {
+ @Override
+ public boolean isBlockTerminator() {
+ return false;
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java
index 682a7e6a..36de2a53 100644
--- a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java
@@ -3,7 +3,7 @@ package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
public sealed interface ShidInstruction
- permits ShidBlock, ShidCall, ShidDeclareNativeFunction, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShidEffectHandlerBreak, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntGreaterThan, ShidIntGreaterThanOrEqual, ShidIntLessThan, ShidIntLessThanOrEqual, ShidIntMultiply, ShidIntNotEqual, ShidIntSub, ShidLocalDrop, ShidLocalLoad, ShidLocalStore, ShidLoop, ShidLoopBreak, ShidLoopContinue, ShidMethodLoad, ShidMethodStore, ShidNamespaceFieldStore, ShidNamespaceImport, ShidPushBool, ShidPushInt, ShidPushString, ShidPushUnit, ShidResume, ShidReturn, ShidStringAdd, ShidSwitch, ShidTry, ShidTupleCreate, ShidTupleGet, ShidVarLoad, ShidVarStore {
+ permits ShidBlock, ShidCall, ShidDeclareNativeFunction, ShidDeclareNativeType, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShidEffectHandlerBreak, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntGreaterThan, ShidIntGreaterThanOrEqual, ShidIntLessThan, ShidIntLessThanOrEqual, ShidIntMultiply, ShidIntNotEqual, ShidIntSub, ShidLocalDrop, ShidLocalLoad, ShidLocalStore, ShidLoop, ShidLoopBreak, ShidLoopContinue, ShidMethodLoad, ShidMethodStore, ShidNamespaceFieldStore, ShidNamespaceImport, ShidPushBool, ShidPushInt, ShidPushString, ShidPushUnit, ShidResume, ShidReturn, ShidStringAdd, ShidSwitch, ShidTry, ShidTupleCreate, ShidTupleGet, ShidVarLoad, ShidVarStore {
/**
* If an instruction is a terminator, execution is guaranteed to leave the
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
index 9d585912..cd315f86 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
@@ -223,6 +223,10 @@ public class ShidToPatio {
).temporaryPush(destination);
}
+ case ShidDeclareNativeType declareNativeType -> {
+ throw new UnsupportedOperationException("TODO");
+ }
+
case ShidDefineEffect defineEffect -> {
var destinationResult = context.allocateVal(
ShidToPatioLocalSpace.USER_DEFINED_EFFECT,