Skip to content

Commit 70b72b8

Browse files
committed
Revert "remove AtomType stub - it was not finished - to be re-added in next iteration"
This reverts commit 5be3b82.
1 parent f4485ce commit 70b72b8

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.enso.compiler.pass.analyse.types.scope;
2+
3+
import java.util.List;
4+
5+
public final class AtomType {
6+
private final String name;
7+
8+
public AtomType(String name, List<Constructor> constructors) {
9+
this.name = name;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
// This is a sibling to BindingsMap.Cons. For now kept separate on purpose.
17+
// TODO do we want arguments or a signature here?
18+
public record Constructor(String name, boolean isProjectPrivate) {}
19+
}

engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/types/scope/StaticModuleScope.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ public final class StaticModuleScope implements ProcessingPass.Metadata {
3232
private final TypeScopeReference associatedType;
3333
private final List<StaticImportExportScope> imports;
3434
private final List<StaticImportExportScope> exports;
35+
private final Map<String, AtomType> typesDefinedHere;
3536
private final Map<TypeScopeReference, Map<String, TypeRepresentation>> methods;
3637

3738
private StaticModuleScope(
3839
QualifiedName moduleName,
3940
TypeScopeReference associatedType,
4041
List<StaticImportExportScope> imports,
4142
List<StaticImportExportScope> exports,
43+
Map<String, AtomType> typesDefinedHere,
4244
Map<TypeScopeReference, Map<String, TypeRepresentation>> methods) {
4345
this.moduleName = moduleName;
4446
this.associatedType = associatedType;
4547
this.imports = imports;
4648
this.exports = exports;
49+
this.typesDefinedHere = typesDefinedHere;
4750
this.methods = methods;
4851
}
4952

@@ -52,6 +55,7 @@ static final class Builder {
5255
private final TypeScopeReference associatedType;
5356
private final List<StaticImportExportScope> imports = new ArrayList<>();
5457
private final List<StaticImportExportScope> exports = new ArrayList<>();
58+
private final Map<String, AtomType> typesDefinedHere = new HashMap<>();
5559
private final Map<TypeScopeReference, Map<String, TypeRepresentation>> methods =
5660
new HashMap<>();
5761

@@ -76,6 +80,7 @@ public StaticModuleScope build() {
7680
associatedType,
7781
Collections.unmodifiableList(imports),
7882
Collections.unmodifiableList(exports),
83+
Collections.unmodifiableMap(typesDefinedHere),
7984
Collections.unmodifiableMap(methods));
8085
}
8186

@@ -87,6 +92,14 @@ public TypeScopeReference getAssociatedType() {
8792
return associatedType;
8893
}
8994

95+
void registerType(AtomType type) {
96+
checkSealed();
97+
var previous = typesDefinedHere.putIfAbsent(type.getName(), type);
98+
if (previous != null) {
99+
throw new IllegalStateException("Type already defined: " + type.getName());
100+
}
101+
}
102+
90103
void registerMethod(TypeScopeReference parentType, String name, TypeRepresentation type) {
91104
checkSealed();
92105
var typeMethods = methods.computeIfAbsent(parentType, k -> new HashMap<>());

engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/types/scope/StaticModuleScopeAnalysis.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,18 @@ protected void processMethodDefinition(Method.Explicit method) {
136136

137137
@Override
138138
protected void processTypeDefinition(Definition.Type typ) {
139+
List<AtomType.Constructor> constructors =
140+
CollectionConverters$.MODULE$.asJava(typ.members()).stream()
141+
.map(
142+
constructorDef ->
143+
new AtomType.Constructor(
144+
constructorDef.name().name(), constructorDef.isPrivate()))
145+
.toList();
146+
147+
AtomType atomType = new AtomType(typ.name().name(), constructors);
139148
var qualifiedName = scopeBuilder.getModuleName().createChild(typ.name().name());
140149
var atomTypeScope = TypeScopeReference.atomType(qualifiedName);
150+
scopeBuilder.registerType(atomType);
141151
registerFieldGetters(scopeBuilder, atomTypeScope, typ);
142152
}
143153

0 commit comments

Comments
 (0)