aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-02-02 19:06:21 +0000
committerMichael Williamson <mike@zwobble.org>2025-02-02 19:07:53 +0000
commitcab0787d8c259b21baa376ba1ec2d95740964bd9 (patch)
tree11b812255db683766ac3b85b7023e7d85017210c /src/main/java
parent7001d0eef3e6139c3033570a463e02d845f3cbac (diff)
Add Shid to Patio codegen for relational int operations
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java52
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java108
2 files changed, 156 insertions, 4 deletions
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
index efadc62a..4ea228b2 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
@@ -479,16 +479,60 @@ public class ShidToPatio {
);
case ShidIntGreaterThan intGreaterThan ->
- throw new UnsupportedOperationException("TODO");
+ generateComparison(
+ (destination, left, right, operationContext) ->
+ ShidToPatioInts.greaterThan(
+ destination,
+ left,
+ right,
+ intGreaterThan.source(),
+ operationContext
+ ),
+ intGreaterThan.source(),
+ context
+ );
case ShidIntGreaterThanOrEqual intGreaterThanOrEqual ->
- throw new UnsupportedOperationException("TODO");
+ generateComparison(
+ (destination, left, right, operationContext) ->
+ ShidToPatioInts.greaterThanOrEqual(
+ destination,
+ left,
+ right,
+ intGreaterThanOrEqual.source(),
+ operationContext
+ ),
+ intGreaterThanOrEqual.source(),
+ context
+ );
case ShidIntLessThan intLessThan ->
- throw new UnsupportedOperationException("TODO");
+ generateComparison(
+ (destination, left, right, operationContext) ->
+ ShidToPatioInts.lessThan(
+ destination,
+ left,
+ right,
+ intLessThan.source(),
+ operationContext
+ ),
+ intLessThan.source(),
+ context
+ );
case ShidIntLessThanOrEqual intLessThanOrEqual ->
- throw new UnsupportedOperationException("TODO");
+ generateComparison(
+ (destination, left, right, operationContext) ->
+ ShidToPatioInts.lessThanOrEqual(
+ destination,
+ left,
+ right,
+ intLessThanOrEqual.source(),
+ operationContext
+ ),
+ intLessThanOrEqual.source(),
+ context
+ );
case ShidIntNotEqual intNotEqual ->
generateComparison(
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java
index 68b9547c..3fe08470 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java
@@ -65,6 +65,46 @@ public class ShidToPatioInts {
Sources.RUNTIME
);
+ private static final PatioFunctionDeclaration INT_LESS_THAN_DECLARATION = new PatioFunctionDeclaration(
+ "shed__runtime__int_less_than",
+ List.of(
+ PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE),
+ PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE)
+ ),
+ PatioTypes.BOOL,
+ Sources.RUNTIME
+ );
+
+ private static final PatioFunctionDeclaration INT_LESS_THAN_OR_EQUAL_DECLARATION = new PatioFunctionDeclaration(
+ "shed__runtime__int_less_than_or_equal",
+ List.of(
+ PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE),
+ PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE)
+ ),
+ PatioTypes.BOOL,
+ Sources.RUNTIME
+ );
+
+ private static final PatioFunctionDeclaration INT_GREATER_THAN_DECLARATION = new PatioFunctionDeclaration(
+ "shed__runtime__int_greater_than",
+ List.of(
+ PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE),
+ PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE)
+ ),
+ PatioTypes.BOOL,
+ Sources.RUNTIME
+ );
+
+ private static final PatioFunctionDeclaration INT_GREATER_THAN_OR_EQUAL_DECLARATION = new PatioFunctionDeclaration(
+ "shed__runtime__int_greater_than_or_equal",
+ List.of(
+ PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE),
+ PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE)
+ ),
+ PatioTypes.BOOL,
+ Sources.RUNTIME
+ );
+
public static final PatioType INT_TYPE = ShidToPatioTypes.VALUE_TYPE;
private ShidToPatioInts() {
@@ -153,4 +193,72 @@ public class ShidToPatioInts {
source
));
}
+
+ public static ShidToPatioContext lessThan(
+ PatioLocalRef destination,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ ShidToPatioContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(INT_LESS_THAN_DECLARATION)
+ .addInstruction(new PatioCall(
+ Optional.of(destination),
+ INT_LESS_THAN_DECLARATION.name(),
+ List.of(left, right),
+ source
+ ));
+ }
+
+ public static ShidToPatioContext lessThanOrEqual(
+ PatioLocalRef destination,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ ShidToPatioContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(INT_LESS_THAN_OR_EQUAL_DECLARATION)
+ .addInstruction(new PatioCall(
+ Optional.of(destination),
+ INT_LESS_THAN_OR_EQUAL_DECLARATION.name(),
+ List.of(left, right),
+ source
+ ));
+ }
+
+ public static ShidToPatioContext greaterThan(
+ PatioLocalRef destination,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ ShidToPatioContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(INT_GREATER_THAN_DECLARATION)
+ .addInstruction(new PatioCall(
+ Optional.of(destination),
+ INT_GREATER_THAN_DECLARATION.name(),
+ List.of(left, right),
+ source
+ ));
+ }
+
+ public static ShidToPatioContext greaterThanOrEqual(
+ PatioLocalRef destination,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ ShidToPatioContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(INT_GREATER_THAN_OR_EQUAL_DECLARATION)
+ .addInstruction(new PatioCall(
+ Optional.of(destination),
+ INT_GREATER_THAN_OR_EQUAL_DECLARATION.name(),
+ List.of(left, right),
+ source
+ ));
+ }
}