aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-03-21 15:36:58 +0000
committerMichael Williamson <mike@zwobble.org>2026-03-21 15:36:58 +0000
commit7785c220bcef000aedfbe2b9c95a32272786f370 (patch)
tree6d57a74a1c129a6eb95234ae6d88690d19d95702 /src/main/java
parent8db8026f1ce7d31eab18b02dab5ed54a512dcb48 (diff)
Serialize Patio operands to Protobuf
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/protobuf/PatioToProtobuf.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/protobuf/PatioToProtobuf.java b/src/main/java/org/shedlang/compiler/patio/protobuf/PatioToProtobuf.java
index a08f42b6..f3142428 100644
--- a/src/main/java/org/shedlang/compiler/patio/protobuf/PatioToProtobuf.java
+++ b/src/main/java/org/shedlang/compiler/patio/protobuf/PatioToProtobuf.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.patio.protobuf;
import org.shedlang.compiler.patio.*;
+import org.shedlang.compiler.patio.operands.*;
import org.shedlang.compiler.patio.types.*;
import org.shedlang.compiler.patio.values.*;
import org.shedlang.compiler.sources.Source;
@@ -300,6 +301,85 @@ public class PatioToProtobuf {
};
}
+ // == Operands ==
+
+ public static PatioProtobuf.PatioOperand serializeOperand(PatioOperand operand) {
+ var builder = PatioProtobuf.PatioOperand.newBuilder();
+
+ switch (operand) {
+ case PatioBoolConst boolConst -> {
+ var boolConstBuilder = builder.getBoolConstBuilder();
+ boolConstBuilder.setValue(boolConst.value());
+ }
+
+ case PatioByteConst byteConst -> {
+ var byteConstBuilder = builder.getByteConstBuilder();
+ byteConstBuilder.setValue(byteConst.value());
+ }
+
+ case PatioDataPtrConst dataPtrConst -> {
+ var dataPtrConstBuilder = builder.getDataPtrConstBuilder();
+ dataPtrConstBuilder.setValue(serializeDataPtrValue(dataPtrConst.value()));
+ }
+
+ case PatioFunctionPtrConst functionPtrConst -> {
+ var functionPtrConstBuilder = builder.getFunctionPtrConstBuilder();
+ functionPtrConstBuilder.setName(functionPtrConst.name());
+ }
+
+ case PatioIntConst intConst -> {
+ var intConstBuilder = builder.getIntConstBuilder();
+ intConstBuilder.setValue(serializeIntValue(intConst.value()));
+ }
+
+ case PatioInt32Const int32Const -> {
+ var int32ConstBuilder = builder.getInt32ConstBuilder();
+ int32ConstBuilder.setValue(serializeIntValue(int32Const.value()));
+ }
+
+ case PatioLocalRef localRef -> {
+ var localRefBuilder = builder.getLocalRefBuilder();
+ localRefBuilder.setName(localRef.name());
+ }
+ }
+
+ return builder.build();
+ }
+
+ public static PatioOperand deserializeOperand(PatioProtobuf.PatioOperand operandProtobuf) {
+ return switch (operandProtobuf.getValueCase()) {
+ case BOOL_CONST ->
+ new PatioBoolConst(operandProtobuf.getBoolConst().getValue());
+
+ case BYTE_CONST ->
+ new PatioByteConst((byte) operandProtobuf.getByteConst().getValue());
+
+ case DATA_PTR_CONST ->
+ new PatioDataPtrConst(
+ deserializeDataPtrValue(operandProtobuf.getDataPtrConst().getValue())
+ );
+
+ case FUNCTION_PTR_CONST ->
+ new PatioFunctionPtrConst(operandProtobuf.getFunctionPtrConst().getName());
+
+ case INT_CONST ->
+ new PatioIntConst(
+ deserializeIntValue(operandProtobuf.getIntConst().getValue())
+ );
+
+ case INT32_CONST ->
+ new PatioInt32Const(
+ deserializeIntValue(operandProtobuf.getInt32Const().getValue())
+ );
+
+ case LOCAL_REF ->
+ new PatioLocalRef(operandProtobuf.getLocalRef().getName());
+
+ case VALUE_NOT_SET ->
+ throw new UnsupportedOperationException("TODO");
+ };
+ }
+
// == Data ptr values ==
public static PatioProtobuf.PatioDataPtrValue serializeDataPtrValue(PatioDataPtrValue value) {