Skip to content

Commit 9ee42c3

Browse files
author
Killian Perlin
committed
address some MR comments and add doc
1 parent d2b73b8 commit 9ee42c3

File tree

14 files changed

+65
-29
lines changed

14 files changed

+65
-29
lines changed

lkql/lkql.lkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ class ClassField : LkqlNode {
12291229
}
12301230

12311231
|" Special annotation to specify the entry point for the nanopass framework.
1232-
|" The pass designated by the associate identifier and all its transitive
1232+
|" The pass designated by the associated identifier and all its transitive
12331233
|" dependencies are going to be executed.
12341234
class RunPass: LkqlNode {
12351235
@parse_field

lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/Hierarchy.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ public class Hierarchy {
6969
private boolean[] inheritanceMatrix;
7070
private HashMap<String, Integer> classNamesToIndex;
7171

72+
/** Setter for all the fields of the class. */
7273
private void become(int size, boolean[] matrix, HashMap<String, Integer> index) {
7374
this.classCount = size;
7475
this.inheritanceMatrix = matrix;
7576
this.classNamesToIndex = index;
7677
}
7778

79+
/**
80+
* Computes a hierarchy of currently available classes in the Lkt bindings.
81+
*/
7882
@TruffleBoundary
7983
public static Hierarchy initial() {
8084
// Collect all inital classes
@@ -125,11 +129,17 @@ public boolean isInstance(String classX, String classY) {
125129
classNamesToIndex.get(classY)];
126130
}
127131

132+
/**
133+
* Add a new class to the hierarchy, with no superclass nor subclass.
134+
*/
128135
@TruffleBoundary
129136
public void add(String classX) {
130137
addAll(Collections.singleton(classX));
131138
}
132139

140+
/**
141+
* Add new classes to the hierarchy, with no superclasses nor subclasses.
142+
*/
133143
@TruffleBoundary
134144
public void addAll(Collection<String> classes) {
135145
final int size = this.size() + classes.size();
@@ -176,11 +186,17 @@ public void addInstanceOfRelation(String classX, String classY) {
176186
}
177187
}
178188

189+
/**
190+
* Remove a class and all its subclasses from the hierarchy.
191+
*/
179192
@TruffleBoundary
180193
public void remove(String classX) {
181194
removeAll(Collections.singleton(classX));
182195
}
183196

197+
/**
198+
* Remove all classes and all their subclasses from the hierarchy.
199+
*/
184200
@TruffleBoundary
185201
public void removeAll(Collection<String> classes) {
186202
// Compute all the subtypes of X to mask wich row/column to keep
@@ -236,6 +252,7 @@ public void removeAll(Collection<String> classes) {
236252
}
237253

238254
// Primarily used in testing
255+
/** Equality implementation */
239256
@TruffleBoundary
240257
public boolean equals(Object otherObject) {
241258
if (otherObject == null) return false;

lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/PassContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class PassContext {
2323

24-
/** maps a class name to its available members */
24+
/** This is a map from class names to all its available members. */
2525
public final HashMap<String, ClassDescriptor> env;
2626

2727
private PassContext() {

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/expressions/DynamicConstructorCall.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* {@link ConstructorCall}. The type of node is decided in the lowering
1919
* pass, thanks to a flag set when entering a pass node.
2020
*/
21-
2221
public final class DynamicConstructorCall extends Expr {
2322

2423
// ----- Children -----
@@ -39,8 +38,10 @@ public DynamicConstructorCall(SourceSection location, String nodeKind, ArgList a
3938
this.nodeKind = nodeKind;
4039
this.args = argList;
4140
for (var arg : argList.getArgs()) {
42-
if (arg instanceof NamedArg) continue;
43-
throw LKQLRuntimeException.fromMessage("constructors in passes only accept named args");
41+
if (!(arg instanceof NamedArg)) throw LKQLRuntimeException.fromMessage(
42+
"constructors in passes only accept named args",
43+
arg
44+
);
4445
}
4546
}
4647

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/expressions/FunExpr.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ public final class FunExpr extends Expr {
2727
/** Closure descriptor of the function. */
2828
private final ClosureDescriptor closureDescriptor;
2929

30-
/** The root node representing the function execution. */
30+
/**
31+
* The root node representing the function execution.
32+
*
33+
* This field doesn't need to be a child for execution purposes,
34+
* but this is temporarilly needed until the {@link ResolutionPass}
35+
* is removed and the nanopass framework rellies on static typing only.
36+
*/
3137
@Child
3238
private FunctionRootNode functionRootNode;
3339

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/AddBlock.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public Object executeGeneric(VirtualFrame frame) {
3434

3535
@Override
3636
public String toString(int indentLevel) {
37-
// TODO Auto-generated method stub
38-
throw new UnsupportedOperationException("Unimplemented method 'toString'");
37+
return nodeRepresentation(
38+
indentLevel,
39+
new String[] { "classes", "fields" },
40+
new Object[] { classes, fields }
41+
);
3942
}
4043
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/ClassDecl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public Object executeGeneric(VirtualFrame frame) {
3434

3535
@Override
3636
public String toString(int indentLevel) {
37-
// TODO Auto-generated method stub
38-
throw new UnsupportedOperationException("Unimplemented method 'toString'");
37+
return nodeRepresentation(
38+
indentLevel,
39+
new String[] { "name", "fields" },
40+
new Object[] { name, fields }
41+
);
3942
}
4043
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/DelBlock.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public Object executeGeneric(VirtualFrame frame) {
3434

3535
@Override
3636
public String toString(int indentLevel) {
37-
// TODO Auto-generated method stub
38-
throw new UnsupportedOperationException("Unimplemented method 'toString'");
37+
return nodeRepresentation(
38+
indentLevel,
39+
new String[] { "classes", "fields" },
40+
new Object[] { classes, fields }
41+
);
3942
}
4043
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/PassExpr.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@
2828
@NodeChild(value = "readInput", type = ReadArgument.class)
2929
public abstract class PassExpr extends Expr {
3030

31+
// This field doesn't need to be a child with regard to execution,
32+
// and so its contents could be merged into this class.
3133
@Child
3234
private AddBlock add;
3335

36+
// This field doesn't need to be a child with regard to execution,
37+
// and so its contents could be merged into this class.
3438
@Child
3539
private DelBlock del;
3640

41+
// This field doesn't need to be a child with regard to execution,
42+
// and so its contents could be merged into this class.
3743
@Child
3844
private RewriteBlock rewrite;
3945

4046
/**
41-
* the previous pass slot, None if this is the first pass in the chain
47+
* The previous pass slot, (or `None` if this is the first pass in the chain).
4248
*/
4349
private final Optional<Integer> previousSlot;
4450

@@ -56,8 +62,6 @@ protected PassExpr(
5662
this.rewrite = rewrite;
5763
}
5864

59-
// TODO insert dynamic checks to verify AST integrity wrt. add / del blocks
60-
// this can be removed if pattern matching exhaustivity is pre-checked
6165
@Specialization
6266
public Object onDynamicAdaNode(VirtualFrame frame, DynamicAdaNode input) {
6367
final var typingContext = LKQLLanguage.getContext(this).getTypingContext();
@@ -70,7 +74,7 @@ public Object onDynamicAdaNode(VirtualFrame frame, DynamicAdaNode input) {
7074
}
7175

7276
@Fallback
73-
public Object onOther(VirtualFrame frame, Object _obj1) {
77+
public Object onOther(VirtualFrame frame, @SuppressWarnings("unused") Object obj) {
7478
throw LKQLRuntimeException.shouldNotExecute(this);
7579
}
7680

@@ -103,7 +107,6 @@ public Optional<Integer> getPreviousSlot() {
103107

104108
// core logic
105109

106-
// bottom up rewriting of the tree
107110
@TruffleBoundary
108111
private DynamicAdaNode getUpdatedTree(DynamicAdaNode tree, MaterializedFrame frame) {
109112
// recurse on children first (bottom up)

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/pass/PrefixField.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import com.oracle.truffle.api.source.SourceSection;
1313

1414
/**
15-
* PrefixField
16-
* this is a POJO, it needs to be an LKQLNode
15+
* This is a POJO, it needs to be an LKQLNode
1716
* to simplify lowering and the resolution pass
1817
* (see {@link ResolutionPass})
1918
*/
@@ -35,7 +34,10 @@ public Object executeGeneric(VirtualFrame frame) {
3534

3635
@Override
3736
public String toString(int indentLevel) {
38-
// TODO Auto-generated method stub
39-
throw new UnsupportedOperationException("Unimplemented method 'toString'");
37+
return nodeRepresentation(
38+
indentLevel,
39+
new String[] { "prefix", "field" },
40+
new Object[] { prefix, field }
41+
);
4042
}
4143
}

0 commit comments

Comments
 (0)