From 72f814103f94f65f02c67d1ee0bd0f76768bddad Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 2 Feb 2025 18:54:58 +0000 Subject: Add Shid int relational instructions --- .../java/org/shedlang/compiler/shid/ShidSerializer.java | 12 ++++++++++++ .../compiler/shid/instructions/ShidInstruction.java | 2 +- .../compiler/shid/instructions/ShidIntGreaterThan.java | 15 +++++++++++++++ .../shid/instructions/ShidIntGreaterThanOrEqual.java | 15 +++++++++++++++ .../compiler/shid/instructions/ShidIntLessThan.java | 15 +++++++++++++++ .../shid/instructions/ShidIntLessThanOrEqual.java | 15 +++++++++++++++ .../org/shedlang/compiler/shidtopatio/ShidToPatio.java | 12 ++++++++++++ 7 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThan.java create mode 100644 src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThanOrEqual.java create mode 100644 src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThan.java create mode 100644 src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThanOrEqual.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java index 590c3d39..b5be44ce 100644 --- a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java +++ b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java @@ -173,6 +173,18 @@ public class ShidSerializer { case ShidIntEquals intEquals -> treeList(treeIdentifier("int-eq")); + case ShidIntGreaterThan intGreaterThan -> + treeList(treeIdentifier("int-gt")); + + case ShidIntGreaterThanOrEqual intGreaterThanOrEqual -> + treeList(treeIdentifier("int-gte")); + + case ShidIntLessThan intLessThan -> + treeList(treeIdentifier("int-lt")); + + case ShidIntLessThanOrEqual intLessThanOrEqual -> + treeList(treeIdentifier("int-lte")); + case ShidIntNotEqual intNotEqual -> treeList(treeIdentifier("int-ne")); 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 963b9b80..c04e3687 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, 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, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShidEffectHandlerBreak, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntGreaterThan, ShidIntGreaterThanOrEqual, ShidIntLessThan, ShidIntLessThanOrEqual, 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/shid/instructions/ShidIntGreaterThan.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThan.java new file mode 100644 index 00000000..9d33319f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThan.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop two values from the temporary value stack, compare them as Ints, and push + * a Bool onto the temporary value stack: true if the first is greater than the + * second, false otherwise. + */ +public record ShidIntGreaterThan(Source source) implements ShidInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThanOrEqual.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThanOrEqual.java new file mode 100644 index 00000000..d0517181 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntGreaterThanOrEqual.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop two values from the temporary value stack, compare them as Ints, and push + * a Bool onto the temporary value stack: true if the first is greater than or + * equal to the second, false otherwise. + */ +public record ShidIntGreaterThanOrEqual(Source source) implements ShidInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThan.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThan.java new file mode 100644 index 00000000..b16e032a --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThan.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop two values from the temporary value stack, compare them as Ints, and push + * a Bool onto the temporary value stack: true if the first is less than the + * second, false otherwise. + */ +public record ShidIntLessThan(Source source) implements ShidInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThanOrEqual.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThanOrEqual.java new file mode 100644 index 00000000..1d8a16a3 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntLessThanOrEqual.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop two values from the temporary value stack, compare them as Ints, and push + * a Bool onto the temporary value stack: true if the first is less than or + * equal to the second, false otherwise. + */ +public record ShidIntLessThanOrEqual(Source source) implements ShidInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java index b039789a..efadc62a 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java @@ -478,6 +478,18 @@ public class ShidToPatio { context ); + case ShidIntGreaterThan intGreaterThan -> + throw new UnsupportedOperationException("TODO"); + + case ShidIntGreaterThanOrEqual intGreaterThanOrEqual -> + throw new UnsupportedOperationException("TODO"); + + case ShidIntLessThan intLessThan -> + throw new UnsupportedOperationException("TODO"); + + case ShidIntLessThanOrEqual intLessThanOrEqual -> + throw new UnsupportedOperationException("TODO"); + case ShidIntNotEqual intNotEqual -> generateComparison( (destination, left, right, operationContext) -> -- cgit v1.2.3