From 33888c1bac8a1e58fae55f275a0d0eafd16144c5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 20 Nov 2023 19:55:13 +0000 Subject: Introduce explicit notion of a BoundVariable --- src/test/java/org/shedlang/compiler/ast/typed/Typed.java | 4 ++-- .../java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java | 6 +++--- .../org/shedlang/compiler/stackir/StackCompilerValTests.java | 5 +++-- .../compiler/typechecker/TypeCheckerFunctionBodyTests.java | 9 +++++---- .../org/shedlang/compiler/typechecker/TypeCheckerIfTests.java | 9 +++++---- 5 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java index 717e94d0..81958cbe 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java @@ -23,9 +23,9 @@ public class Typed { public static TypedBlockNode block( List statements, - List boundVariableNames + List boundVariables ) { - return new TypedBlockNode(statements, boundVariableNames, Sources.NULL); + return new TypedBlockNode(statements, boundVariables, Sources.NULL); } public static TypedBlockReturnNode blockReturn(TypedExpressionNode expression) { diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java index faf6f31c..bb787024 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java @@ -46,10 +46,10 @@ public class TypedNodeMatchers { return has("statements", x -> x.statements(), statements); } - public static Matcher isTypedBlockNodeWithBoundVariableNames( - Matcher> boundVariableNames + public static Matcher isTypedBlockNodeWithBoundVariables( + Matcher> boundVariables ) { - return has("boundVariableNames", x -> x.boundVariableNames(), boundVariableNames); + return has("boundVariables", x -> x.boundVariables(), boundVariables); } public static Matcher isTypedBlockReturnNode( diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java index b72055fd..4d0e1451 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.stackir; import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.BoundVariable; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.types.Types; @@ -53,7 +54,7 @@ public class StackCompilerValTests { Typed.val("x", Typed.intLiteral(11)), Typed.expressionStatement(Typed.reference("x")) ), - List.of("x") + List.of(BoundVariable.immutable("x")) ) ) ), @@ -62,7 +63,7 @@ public class StackCompilerValTests { Typed.val("x", Typed.intLiteral(12)), Typed.expressionStatement(Typed.reference("x")) ), - List.of("x") + List.of(BoundVariable.immutable("x")) ), Types.INT )), diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java index c6abd22a..6ac002b1 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.typechecker; import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.BoundVariable; import org.shedlang.compiler.ast.untyped.Untyped; import org.shedlang.compiler.ast.untyped.UntypedCallNode; import org.shedlang.compiler.typechecker.errors.CannotCaptureVarError; @@ -504,10 +505,10 @@ public class TypeCheckerFunctionBodyTests { assertThat( typed.value(), isTypedFunctionBodyNode() - .withBlock(isTypedBlockNodeWithBoundVariableNames(containsExactly( - equalTo("argPositional"), - equalTo("argNamed"), - equalTo("local1") + .withBlock(isTypedBlockNodeWithBoundVariables(containsExactly( + equalTo(BoundVariable.immutable("argPositional")), + equalTo(BoundVariable.immutable("argNamed")), + equalTo(BoundVariable.immutable("local1")) ))) ); } diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java index 0cbca567..25347042 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.typechecker; import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.BoundVariable; import org.shedlang.compiler.ast.untyped.Untyped; import org.shedlang.compiler.typechecker.errors.UnexpectedTypeError; import org.shedlang.compiler.typechecker.typesets.TypeSets; @@ -176,13 +177,13 @@ public class TypeCheckerIfTests { isSequence( isTypedConditionalBranchNode( anything(), - isTypedBlockNodeWithBoundVariableNames(containsExactly( - equalTo("local1") + isTypedBlockNodeWithBoundVariables(containsExactly( + equalTo(BoundVariable.immutable("local1")) )) ) ), - isTypedBlockNodeWithBoundVariableNames(containsExactly( - equalTo("local2") + isTypedBlockNodeWithBoundVariables(containsExactly( + equalTo(BoundVariable.immutable("local2")) )) ) ); -- cgit v1.2.3