implements PR-05.0.2

This commit is contained in:
2026-03-24 13:42:29 +00:00
parent 3b5e8e0b24
commit bafab68eac
4 changed files with 123 additions and 48 deletions
@@ -0,0 +1,17 @@
package p.studio.compiler.source.tables;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.Objects;
public record ModuleReference(
String project,
ReadOnlyList<String> pathSegments) {
public ModuleReference {
project = Objects.requireNonNull(project, "project");
if (project.isBlank()) {
throw new IllegalArgumentException("project must not be blank");
}
pathSegments = pathSegments == null ? ReadOnlyList.empty() : pathSegments;
}
}
@@ -0,0 +1,10 @@
package p.studio.compiler.source.tables;
import p.studio.compiler.source.identifiers.ModuleId;
public class ModuleTable extends InternTable<ModuleId, ModuleReference> {
public ModuleTable() {
super(ModuleId::new);
}
}
@@ -0,0 +1,31 @@
package p.studio.compiler.source.tables;
import org.junit.jupiter.api.Test;
import p.studio.utilities.structures.ReadOnlyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
class ModuleTableTest {
@Test
void shouldInternSameReferenceWithStableId() {
final var table = new ModuleTable();
final var reference = new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("math", "vec")));
final var first = table.register(reference);
final var second = table.register(reference);
assertEquals(first, second);
}
@Test
void shouldAllocateDifferentIdForDifferentReference() {
final var table = new ModuleTable();
final var first = table.register(new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("math"))));
final var second = table.register(new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("gfx"))));
assertNotEquals(first, second);
}
}