diff options
6 files changed, 117 insertions, 1 deletions
diff --git a/hobgoblin/src/output/lang/rust/ast.hob b/hobgoblin/src/output/lang/rust/ast.hob index a592f4e..bce56f8 100644 --- a/hobgoblin/src/output/lang/rust/ast.hob +++ b/hobgoblin/src/output/lang/rust/ast.hob @@ -139,6 +139,7 @@ sum RustExpression { variant RustStructExpression; variant RustTryPropagationExpression; variant RustTupleExpression; + variant RustTypeCastExpression; variant RustVecRepeatExpression; } @@ -249,6 +250,11 @@ struct RustTupleExpression { field elements: List[RustExpression]; } +struct RustTypeCastExpression { + field left: RustExpression; + field right: RustType; +} + struct RustVecRepeatExpression { field repeatOperand: RustExpression; field lengthOperand: RustExpression; diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java index aa8d6cb..53b9a38 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java @@ -383,6 +383,10 @@ public class RustWriter implements AutoCloseable { this.writeTupleExpression(tupleExpression); } + case RustTypeCastExpression typeCastExpression -> { + this.writeTypeCastExpression(typeCastExpression); + } + case RustVecRepeatExpression vecRepeatExpression -> { this.writeVecRepeatExpression(vecRepeatExpression); } @@ -430,6 +434,7 @@ public class RustWriter implements AutoCloseable { case RustStructExpression _ -> RustPrecedence.PRIMARY; case RustTryPropagationExpression _ -> RustPrecedence.TRY_PROPAGATION; case RustTupleExpression _ -> RustPrecedence.PRIMARY; + case RustTypeCastExpression _ -> RustPrecedence.AS; case RustVecRepeatExpression _ -> RustPrecedence.PRIMARY; }; } @@ -668,6 +673,12 @@ public class RustWriter implements AutoCloseable { this.writer.write(")"); } + private void writeTypeCastExpression(RustTypeCastExpression typeCastExpression) throws IOException { + this.writeSubExpression(typeCastExpression.left(), RustPrecedence.AS, true); + this.writer.write(" as "); + this.writeType(typeCastExpression.right()); + } + private void writeVecRepeatExpression(RustVecRepeatExpression vecRepeatExpression) throws IOException { this.writer.write("vec