• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revision80a05a1a4fbfeb170b1f26f1744916d6b29a2f73 (tree)
Zeit2023-01-26 01:29:44
Autormiyakawataku
Commitermiyakawataku

Log Message

stack bound lvar can also be nullable

Ändern Zusammenfassung

Diff

diff -r bfda252179bd -r 80a05a1a4fbf src/main/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSet.java
--- a/src/main/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSet.java Thu Jan 26 00:36:37 2023 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSet.java Thu Jan 26 01:29:44 2023 +0900
@@ -49,20 +49,26 @@
4949
5050 int freeInd = free().indexOf(lvar);
5151 if (freeInd >= 0) {
52- boolean nonnull = lvar instanceof LocalVar.Generated
53- || CONTROL_LVARS.contains(lvar);
54- return new Allocation.Field(freeInd, nonnull);
52+ return new Allocation.Field(freeInd, isNonNull(lvar));
5553 }
5654
5755 int stackInd = stackBound().indexOf(lvar);
5856 if (stackInd >= 0) {
59- return new Allocation.Stack(stackInd, true);
57+ return new Allocation.Stack(stackInd, isNonNull(lvar));
6058 }
6159
6260 return new Allocation.Unused();
6361 }
6462
6563 /**
64+ * Whether the local var is nonnull.
65+ */
66+ private boolean isNonNull(LocalVar lvar) {
67+ return lvar instanceof LocalVar.Generated
68+ || CONTROL_LVARS.contains(lvar);
69+ }
70+
71+ /**
6672 * Analyzes the vars as of the inner SSA fun for the case a local var
6773 * of a control fun is overridden on the top level.
6874 *
diff -r bfda252179bd -r 80a05a1a4fbf src/test/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSetTest.java
--- a/src/test/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSetTest.java Thu Jan 26 00:36:37 2023 +0900
+++ b/src/test/java/org/kink_lang/kink/internal/compile/javaclassir/ValCaptureAllocationSetTest.java Thu Jan 26 01:29:44 2023 +0900
@@ -31,7 +31,9 @@
3131 List.of(
3232 new LocalVar.Generated("X", "x"),
3333 new LocalVar.Generated("Y", "y"),
34- new LocalVar.Generated("Z", "z")));
34+ new LocalVar.Generated("Z", "z"),
35+ new LocalVar.Original("W"),
36+ new LocalVar.Original("raise")));
3537
3638 @Test
3739 public void get_recv() {
@@ -76,6 +78,18 @@
7678 }
7779
7880 @Test
81+ public void get_stacked_nullable() {
82+ assertThat(analysis.get(new LocalVar.Original("W")))
83+ .isEqualTo(new Allocation.Stack(3, false));
84+ }
85+
86+ @Test
87+ public void get_stacked_control_sym() {
88+ assertThat(analysis.get(new LocalVar.Original("raise")))
89+ .isEqualTo(new Allocation.Stack(4, true));
90+ }
91+
92+ @Test
7993 public void get_unused() {
8094 assertThat(analysis.get(new LocalVar.Original("unused")))
8195 .isEqualTo(new Allocation.Unused());
Show on old repository browser