summaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-17 10:54:22 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-17 10:54:22 +0100
commit0be52b37ae8e3df1efc47a972eb320ec5964be3a (patch)
tree6bbd7f5ba10a88ca2c4659d21f341acb2cafc83a /src/main/java/org/zwobble
parentdb10b42d361f0ff73a88d34dad1165a736d12024 (diff)
Extract generateEncode/generateDecode for named types
Diffstat (limited to 'src/main/java/org/zwobble')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java105
1 files changed, 76 insertions, 29 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java
index 02b0ae9..4cb385b 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java
@@ -8,9 +8,7 @@ import org.zwobble.hobgoblin.compiler.output.generators.rust.RustGenerator;
import org.zwobble.hobgoblin.compiler.output.generators.rust.RustGeneratorConfig;
import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.*;
import org.zwobble.hobgoblin.compiler.typechecker.TypesInfo;
-import org.zwobble.hobgoblin.compiler.types.NamespaceName;
-import org.zwobble.hobgoblin.compiler.types.SimpleNativeType;
-import org.zwobble.hobgoblin.compiler.types.Type;
+import org.zwobble.hobgoblin.compiler.types.*;
import org.zwobble.json5.reader.Json5ObjectReader;
import java.io.IOException;
@@ -306,23 +304,31 @@ public class RustTransient0Generator implements Generator {
private List<RustStatement> generateEncode(RustExpression value, Type type) {
return switch (type) {
+ case ConstructedNativeType constructedNativeType -> {
+ yield List.of(new RustExpressionStatement(generateTodo()));
+ }
+
+ case EnumType enumType -> {
+ yield List.of(new RustExpressionStatement(generateTodo()));
+ }
+
case SimpleNativeType nativeType -> {
- var rustEncodeFunctionPathSegments = new ArrayList<>(
- this.generateTransient0ModuleName(nativeType.namespaceName())
- );
- rustEncodeFunctionPathSegments.add(encodeMethodName(nativeType));
- var rustEncodeFunctionPath = RustPath.crate(
- rustEncodeFunctionPathSegments
- );
+ yield generateEncode(value, nativeType.namespaceName(), type);
+ }
- yield List.of(
- new RustExpressionStatement(new RustCallExpression(
- rustEncodeFunctionPath,
- List.of(value, RustPath.of(WRITER_NAME))
- ))
- );
+ case StructType structType -> {
+ yield List.of(new RustExpressionStatement(generateTodo()));
+ }
+
+ case SumType sumType -> {
+ yield List.of(new RustExpressionStatement(generateTodo()));
+ }
+
+ case TypeLevelValueType typeLevelValueType -> {
+ yield List.of(new RustExpressionStatement(generateTodo()));
}
- default -> {
+
+ case TypeParam typeParam -> {
yield List.of(new RustExpressionStatement(generateTodo()));
}
};
@@ -330,27 +336,68 @@ public class RustTransient0Generator implements Generator {
private RustExpression generateDecode(Type type) {
return switch (type) {
+ case ConstructedNativeType constructedNativeType -> {
+ yield generateTodo();
+ }
+
+ case EnumType enumType -> {
+ yield generateTodo();
+ }
+
case SimpleNativeType nativeType -> {
- var rustDecodeFunctionPathSegments = new ArrayList<>(
- this.generateTransient0ModuleName(nativeType.namespaceName())
- );
- rustDecodeFunctionPathSegments.add(decodeMethodName(nativeType));
- var rustDecodeFunctionPath = RustPath.crate(
- rustDecodeFunctionPathSegments
- );
+ yield generateDecode(nativeType.namespaceName(), type);
+ }
- yield new RustCallExpression(
- rustDecodeFunctionPath,
- List.of(RustPath.of(READER_NAME))
- );
+ case StructType structType -> {
+ yield generateTodo();
+ }
+
+ case SumType sumType -> {
+ yield generateTodo();
+ }
+
+ case TypeLevelValueType typeLevelValueType -> {
+ yield generateTodo();
}
- default -> {
+ case TypeParam typeParam -> {
yield generateTodo();
}
};
}
+ private List<RustStatement> generateEncode(RustExpression value, NamespaceName typeNamespaceName, Type type) {
+ var rustEncodeFunctionPathSegments = new ArrayList<>(
+ this.generateTransient0ModuleName(typeNamespaceName)
+ );
+ rustEncodeFunctionPathSegments.add(encodeMethodName(type));
+ var rustEncodeFunctionPath = RustPath.crate(
+ rustEncodeFunctionPathSegments
+ );
+
+ return List.of(
+ new RustExpressionStatement(new RustCallExpression(
+ rustEncodeFunctionPath,
+ List.of(value, RustPath.of(WRITER_NAME))
+ ))
+ );
+ }
+
+ private RustExpression generateDecode(NamespaceName typeNamespaceName, Type type) {
+ var rustDecodeFunctionPathSegments = new ArrayList<>(
+ this.generateTransient0ModuleName(typeNamespaceName)
+ );
+ rustDecodeFunctionPathSegments.add(decodeMethodName(type));
+ var rustDecodeFunctionPath = RustPath.crate(
+ rustDecodeFunctionPathSegments
+ );
+
+ return new RustCallExpression(
+ rustDecodeFunctionPath,
+ List.of(RustPath.of(READER_NAME))
+ );
+ }
+
private RustExpression generateWriterWrite(RustExpression valueToWrite) {
return new RustCallExpression(
new RustFieldExpression(