From 51a0d5a8b6db54368872dc3df9ade204f47c59c7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 20 Nov 2023 20:10:02 +0000 Subject: Store mutability of bound variables in namespace node --- .../org/shedlang/compiler/ast/typed/TypedNamespaceNode.java | 12 ++++++------ .../java/org/shedlang/compiler/stackir/StackCompiler.java | 4 ++-- .../org/shedlang/compiler/typechecker/DeclaredVariable.java | 4 ++++ .../java/org/shedlang/compiler/typechecker/TypeChecker.java | 5 ++++- 4 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceNode.java b/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceNode.java index abc325ce..8894fc64 100644 --- a/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceNode.java +++ b/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceNode.java @@ -12,7 +12,7 @@ public record TypedNamespaceNode( NamespaceName namespaceName, List imports, List body, - List boundVariableNames, + List boundVariables, List fieldNames, Source source ) implements TypedNode { @@ -30,7 +30,7 @@ public record TypedNamespaceNode( NamespaceName namespaceName, PVector imports, PVector body, - PVector boundVariableNames, + PVector boundVariables, PVector fieldNames ) { public TypedNamespaceNode build() { @@ -38,7 +38,7 @@ public record TypedNamespaceNode( namespaceName, imports, body, - boundVariableNames, + boundVariables, fieldNames, Sources.NULL ); @@ -49,17 +49,17 @@ public record TypedNamespaceNode( this.namespaceName, this.imports.plus(import_), this.body, - this.boundVariableNames, + this.boundVariables, this.fieldNames ); } - public Builder addBoundVariableName(String variableName) { + public Builder addBoundVariable(BoundVariable boundVariable) { return new Builder( this.namespaceName, this.imports, this.body, - this.boundVariableNames.plus(variableName), + this.boundVariables.plus(boundVariable), this.fieldNames ); } diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index c46e9368..a6da0635 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -410,8 +410,8 @@ public class StackCompiler { )) .addInstruction(new LocalStoreInstruction(printLocalName, node.source())); - for (var boundVariableName : node.boundVariableNames()) { - context = context.addShedVal(boundVariableName); + for (var boundVariable : node.boundVariables()) { + context = context.addShedVariable(boundVariable); } for (var importNode : node.imports()) { diff --git a/src/main/java/org/shedlang/compiler/typechecker/DeclaredVariable.java b/src/main/java/org/shedlang/compiler/typechecker/DeclaredVariable.java index a19916aa..8258208d 100644 --- a/src/main/java/org/shedlang/compiler/typechecker/DeclaredVariable.java +++ b/src/main/java/org/shedlang/compiler/typechecker/DeclaredVariable.java @@ -21,4 +21,8 @@ public record DeclaredVariable( node.source() ); } + + public boolean isMutable() { + return variableType().isMutable(); + } } diff --git a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java index 27210ec5..ca8f89ec 100644 --- a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java @@ -1233,7 +1233,10 @@ public class TypeChecker { typedImportNodes, typedBody, declaredVariables.stream() - .map(boundVariable -> boundVariable.name()) + .map(boundVariable -> new BoundVariable( + boundVariable.name(), + boundVariable.isMutable() + )) .toList(), fieldNames, untyped.source() -- cgit v1.2.3