aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-31 13:22:51 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-31 13:23:03 +0100
commit410fff7b7ecf6f36a0a46ab1d90553169e3728f1 (patch)
treea4b4696c8576ad06dae89804ecc8b9eb83cbd902 /src/main/java/org
parent8dce1c07e695c5fe098ecffc6ee9ff8c34725664 (diff)
Add hobgoblin definitions for Patio
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java8
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java8
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java12
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java8
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java19
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitchCase.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java10
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java20
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java6
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java6
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java4
23 files changed, 64 insertions, 101 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java
index 5858159f..fd7932b6 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java
@@ -6,11 +6,9 @@ import org.shedlang.compiler.util.Lists;
import java.util.List;
-/**
- * Execute the instructions in the body of the block. The results may be used in
- * the parent scope, but any other variables (as distinct from values) are no
- * longer in use.
- */
+/// Execute the instructions in the body of the block. The results may be used in
+/// the parent scope, but any other variables (as distinct from values) are no
+/// longer in use.
public record PatioBlock(
List<PatioInstruction> body,
List<? extends PatioOperand> results,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java
index c430b732..02159902 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java
@@ -6,10 +6,8 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Call the function with the given name, and store the returned values in the
- * destination locals.
- */
+/// Call the function with the given name, and store the returned values in the
+/// destination locals.
public record PatioCall(
List<PatioLocalRef> destinations,
String functionName,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java
index 80aa6a3a..f8823b38 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java
@@ -6,10 +6,8 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Call the function pointed to by the function pointer with the given
- * arguments, and store the returned values in the destination locals.
- */
+/// Call the function pointed to by the function pointer with the given
+/// arguments, and store the returned values in the destination locals.
public record PatioCallPointer(
List<PatioLocalRef> destinations,
PatioOperand functionPointer,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java
index edbeb3bb..178663bf 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java
@@ -3,11 +3,9 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.sources.Source;
-/**
- * A catch clause can accept an exception of a given type. If executed, it will
- * stored the value of the exception in the given destination, and then execute the
- * body.
- */
+/// A catch clause can accept an exception of a given type. If executed, it will
+/// stored the value of the exception in the given destination, and then execute the
+/// body.
public record PatioCatchClause(
String exceptionTypeName,
PatioLocalRef destination,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java
index af6bdac9..9e5fe50f 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java
@@ -6,13 +6,11 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * If the condition is true, execute the instructions in the "true" body,
- * otherwise execute the instructions in the "false" body.
- * <p>
- * Each block must have the same number of results as destinations. Each result is
- * assigned to the destination with the same index.
- */
+/// If the condition is true, execute the instructions in the "true" body,
+/// otherwise execute the instructions in the "false" body.
+///
+/// Each block must have the same number of results as destinations. Each result is
+/// assigned to the destination with the same index.
public record PatioIf(
List<PatioLocalRef> destinations,
PatioOperand condition,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java
index b00e0f6d..d1d987f9 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java
@@ -4,10 +4,8 @@ import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.patio.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
-/**
- * Compare the left and right operands. If they are equal, store false in the
- * destination, otherwise store true in the destination.
- */
+/// Compare the left and right operands. If they are equal, store false in the
+/// destination, otherwise store true in the destination.
public record PatioIntNotEqual(
PatioLocalRef destination,
PatioOperand left,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java
index 24f41107..bf6950c8 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java
@@ -4,10 +4,8 @@ import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.patio.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
-/**
- * Calculate the left operand minus the right operand, and store the result in
- * the destination.
- */
+/// Calculate the left operand minus the right operand, and store the result in
+/// the destination.
public record PatioIntSub(
PatioLocalRef destination,
PatioOperand left,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java
index c72d0252..a531c247 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java
@@ -4,9 +4,7 @@ import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.patio.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
-/**
- * Store the given value in the destination local.
- */
+/// Store the given value in the destination local.
public record PatioLocalStore(
PatioLocalRef destination,
PatioOperand value,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java
index 650b1108..5089effb 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java
@@ -4,11 +4,9 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Execute the body. The <code>continue</code> instruction can jump back to the
- * start of the body. The <code>break</code> instruction can jump to the end of
- * the body.
- */
+/// Execute the body. The `continue` instruction can jump back to the
+/// start of the body. The `break` instruction can jump to the end of
+/// the body.
public record PatioLoop(
List<PatioInstruction> body,
Source source
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java
index bad43e15..ae27cf98 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java
@@ -2,9 +2,7 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.sources.Source;
-/**
- * Jump to the end of the enclosing <code>loop</code> instruction's body.
- */
+/// Jump to the end of the enclosing `loop` instruction's body.
public record PatioLoopBreak(Source source) implements PatioInstruction {
@Override
public boolean isBlockTerminator() {
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java
index 41dcc6fd..83517e83 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java
@@ -2,9 +2,7 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.sources.Source;
-/**
- * Jump to the start of the enclosing <code>loop</code> instruction's body.
- */
+/// Jump to the start of the enclosing `loop` instruction's body.
public record PatioLoopContinue(Source source) implements PatioInstruction {
@Override
public boolean isBlockTerminator() {
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java
index 1262d040..5d4642a0 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java
@@ -7,10 +7,8 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Load the value at the given offset from the given pointer and store it in the
- * destination local.
- */
+/// Load the value at the given offset from the given pointer and store it in the
+/// destination local.
public record PatioMemoryLoad(
PatioLocalRef destination,
PatioOperand pointer,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java
index cfcdf9a7..68136b3b 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java
@@ -6,9 +6,7 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Store the given value at the given offset from the given pointer.
- */
+/// Store the given value at the given offset from the given pointer.
public record PatioMemoryStore(
PatioOperand pointer,
PatioDataLayout layout,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java
index c7cfbead..69d294c2 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java
@@ -5,9 +5,7 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Return with the given values from the current function.
- */
+/// Return with the given values from the current function.
public record PatioReturn(List<PatioOperand> values, Source source) implements PatioInstruction {
@Override
public boolean isBlockTerminator() {
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java
index 0b11e9d0..28923ea7 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java
@@ -6,24 +6,19 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Find a case with a value matching that of the instruction's value. If such a
- * case is found, execute the body of that case, otherwise execute the default
- * body.
- * <p>
- * Each block must have the same number of results as destinations. Each result
- * is assigned to the destination with the same index.
- */
+/// Find a case with a value matching that of the instruction's value. If such a
+/// case is found, execute the body of that case, otherwise execute the default
+/// body.
+///
+/// Each block must have the same number of results as destinations. Each result
+/// is assigned to the destination with the same index.
public record PatioSwitch(
List<PatioLocalRef> destinations,
PatioOperand value,
- List<Case> cases,
+ List<PatioSwitchCase> cases,
PatioBlock defaultBody,
Source source
) implements PatioInstruction {
- public record Case(int value, PatioBlock body, Source source) {
- }
-
@Override
public boolean isBlockTerminator() {
return true;
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitchCase.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitchCase.java
new file mode 100644
index 00000000..c446476e
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitchCase.java
@@ -0,0 +1,6 @@
+package org.shedlang.compiler.patio.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+public record PatioSwitchCase(int value, PatioBlock body, Source source) {
+}
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java
index 86a3afbb..95b9dd7c 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java
@@ -3,12 +3,10 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.patio.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
-/**
- * Search the stack for an exception handler with a catch clause matching the
- * thrown exception type. Unwind the stack up to and including this exception
- * handler, and run the body of the catch clause. If no such exception handler
- * is found, the process should abort.
- */
+/// Search the stack for an exception handler with a catch clause matching the
+/// thrown exception type. Unwind the stack up to and including this exception
+/// handler, and run the body of the catch clause. If no such exception handler
+/// is found, the process should abort.
public record PatioThrow(
String exceptionTypeName,
PatioOperand value,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java
index 893750a6..95368141 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java
@@ -5,17 +5,15 @@ import org.shedlang.compiler.sources.Source;
import java.util.List;
-/**
- * Push an exception handler with the given catch clauses onto the control flow
- * stack, and then execute the instructions in its body.
- * <p>
- * If the exception handler catches an exception, the body of the corresponding
- * is executed instead.
- * <p>
- * Each block (that is, the body of the try and the body of each catch clause)
- * must have the same number of results as destinations. Each result is assigned to
- * the destination with the same index.
- */
+/// Push an exception handler with the given catch clauses onto the control flow
+/// stack, and then execute the instructions in its body.
+///
+/// If the exception handler catches an exception, the body of the corresponding
+/// is executed instead.
+///
+/// Each block (that is, the body of the try and the body of each catch clause)
+/// must have the same number of results as destinations. Each result is assigned to
+/// the destination with the same index.
public record PatioTry(
List<PatioLocalRef> destinations,
List<PatioCatchClause> catchClauses,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java
index 1550105c..1ccb6342 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java
@@ -2,10 +2,8 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.sources.Source;
-/**
- * Unreachable instructions have undefined behaviour, and are used to indicate
- * that an instruction sequence is unreachable.
- */
+/// Unreachable instructions have undefined behaviour, and are used to indicate
+/// that an instruction sequence is unreachable.
public record PatioUnreachable(Source source) implements PatioInstruction {
@Override
public boolean isBlockTerminator() {
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java
index 02117bc6..b60007bb 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java
@@ -3,9 +3,7 @@ package org.shedlang.compiler.patio.instructions;
import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.sources.Source;
-/**
- * Load the value from the given var and store it in the destination local.
- */
+/// Load the value from the given var and store it in the destination local.
public record PatioVarLoad(
PatioLocalRef destination,
PatioLocalRef var,
diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java
index dd345af2..80c4ef60 100644
--- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java
+++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java
@@ -4,9 +4,7 @@ import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.patio.operands.PatioOperand;
import org.shedlang.compiler.sources.Source;
-/**
- * Store the given value in the destination var.
- */
+/// Store the given value in the destination var.
public record PatioVarStore(
PatioLocalRef var,
PatioOperand value,
diff --git a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java
index c3df7f0b..1f2e34c8 100644
--- a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java
+++ b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java
@@ -1729,7 +1729,7 @@ public class PatioToFlatbuffers {
private static int serializeSwitchCase(
FlatBufferBuilder builder,
- PatioSwitch.Case case_,
+ PatioSwitchCase case_,
Source parentSource
) {
var sourceFbs = SourceToFlatbuffers.serializeSource(
@@ -1747,7 +1747,7 @@ public class PatioToFlatbuffers {
return PatioSwitchCaseFbs.endPatioSwitchCaseFbs(builder);
}
- private static PatioSwitch.Case deserializeSwitchCase(
+ private static PatioSwitchCase deserializeSwitchCase(
PatioSwitchCaseFbs caseFbs,
Source parentSource
) {
@@ -1758,7 +1758,7 @@ public class PatioToFlatbuffers {
var body = deserializeBlock(caseFbs.body(), source);
- return new PatioSwitch.Case((int) caseFbs.value(), body, source);
+ return new PatioSwitchCase((int) caseFbs.value(), body, source);
}
public static int serializeThrow(
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
index 88d56cf6..062375eb 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java
@@ -821,7 +821,7 @@ public class ShidToPatio {
context
);
- var cases = new ArrayList<PatioSwitch.Case>();
+ var cases = new ArrayList<PatioSwitchCase>();
for (var shidCase : switch_.cases()) {
var bodyResult = generateBlock(
@@ -831,7 +831,7 @@ public class ShidToPatio {
var body = bodyResult.value();
context = bodyResult.context();
- cases.add(new PatioSwitch.Case(
+ cases.add(new PatioSwitchCase(
context.structTag(shidCase.caseType()),
body,
shidCase.source()