• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revisionf2383b755af90389bc7d00cf2b50f4875e30cb24 (tree)
Time2020-10-12 23:36:20
Authormiyakawataku
Commitermiyakawataku

Log Message

add CallStackSlice.dataStackUsage

Change Summary

Incremental Difference

diff -r 9f467d6700da -r f2383b755af9 src/main/java/org/kink_lang/kink/internal/callstack/CallStackSlice.java
--- a/src/main/java/org/kink_lang/kink/internal/callstack/CallStackSlice.java Sun Oct 11 21:24:01 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/callstack/CallStackSlice.java Mon Oct 12 23:36:20 2020 +0900
@@ -30,6 +30,19 @@
3030 return this.cses;
3131 }
3232
33+ /**
34+ * Returns the total usage of the dataStack by the slice.
35+ *
36+ * @return the total usage of the dataStack by the slice.
37+ */
38+ public int dataStackUsage() {
39+ int sum = 0;
40+ for (Cse cse : this.cses) {
41+ sum += cse.getDataStackUsage();
42+ }
43+ return sum;
44+ }
45+
3346 @Override
3447 public String toString() {
3548 return String.format(Locale.ROOT, "CallStackSlice(%s)",
diff -r 9f467d6700da -r f2383b755af9 src/test/java/org/kink_lang/kink/internal/callstack/CallStackSliceTest.java
--- a/src/test/java/org/kink_lang/kink/internal/callstack/CallStackSliceTest.java Sun Oct 11 21:24:01 2020 +0900
+++ b/src/test/java/org/kink_lang/kink/internal/callstack/CallStackSliceTest.java Mon Oct 12 23:36:20 2020 +0900
@@ -16,6 +16,25 @@
1616 }
1717
1818 @Test
19+ public void test_dataStackUsage() {
20+ Cse[] cses = {
21+ cseWithDataStackUsage(1),
22+ cseWithDataStackUsage(3),
23+ cseWithDataStackUsage(5),
24+ };
25+ CallStackSlice css = new CallStackSlice(cses);
26+ assertThat(css.dataStackUsage()).isEqualTo(1 + 3 + 5);
27+ }
28+
29+ private static Cse cseWithDataStackUsage(int dataStackUsage) {
30+ return new Cse() {
31+ @Override public int getDataStackUsage() {
32+ return dataStackUsage;
33+ }
34+ };
35+ }
36+
37+ @Test
1938 public void test_toString() {
2039 Cse[] cses = new Cse[] { new ResetFrame("foo"), new ResetFrame("bar") };
2140 CallStackSlice css = new CallStackSlice(cses);
Show on old repository browser