diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-20 20:10:02 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-20 20:10:02 +0000 |
| commit | 51a0d5a8b6db54368872dc3df9ade204f47c59c7 (patch) | |
| tree | 10f6640f1f924cb9fea737c122eb0b6268f183a9 /src/main/java | |
| parent | 23c76b64213fbe54dafd5bbf6b9d10efb051d16d (diff) | |
Store mutability of bound variables in namespace node
Diffstat (limited to 'src/main/java')
4 files changed, 16 insertions, 9 deletions
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<TypedImportNode> imports, List<TypedNamespaceStatementNode> body, - List<String> boundVariableNames, + List<BoundVariable> boundVariables, List<String> fieldNames, Source source ) implements TypedNode { @@ -30,7 +30,7 @@ public record TypedNamespaceNode( NamespaceName namespaceName, PVector<TypedImportNode> imports, PVector<TypedNamespaceStatementNode> body, - PVector<String> boundVariableNames, + PVector<BoundVariable> boundVariables, PVector<String> 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() |
