Skip to content

Commit 73feb5f

Browse files
CAG2MarkLPTK
authored andcommitted
fix possible bug
1 parent a2388e2 commit 73feb5f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

hkmc2/shared/src/main/scala/hkmc2/codegen/StackSafeTransform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class StackSafeTransform(depthLimit: Int)(using State):
8383
) :: Nil,
8484
blockBuilder
8585
.assignFieldN(predefPath, STACK_LIMIT_IDENT, intLit(depthLimit)) // set stackLimit before call
86+
.assignFieldN(predefPath, STACK_OFFSET_IDENT, intLit(0)) // set stackOffset = 0 before call
8687
.assignFieldN(predefPath, STACK_DEPTH_IDENT, intLit(1)) // set stackDepth = 1 before call
8788
.assignFieldN(predefPath, STACK_HANDLER_IDENT, handlerSym.asPath) // assign stack handler
8889
.rest(HandleBlockReturn(res)),

hkmc2/shared/src/test/mlscript/handlers/StackSafety.mls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ hi(0)
147147
//│ toString() { return "Cont$(" + this.pc + ")"; }
148148
//│ };
149149
//│ globalThis.Predef.__stackLimit = 5;
150+
//│ globalThis.Predef.__stackOffset = 0;
150151
//│ globalThis.Predef.__stackDepth = 1;
151152
//│ globalThis.Predef.__stackHandler = stackHandler;
152153
//│ res1 = hi1(0);
@@ -339,6 +340,7 @@ sum(10000)
339340
//│ toString() { return "Cont$(" + this.pc + ")"; }
340341
//│ };
341342
//│ globalThis.Predef.__stackLimit = 1000;
343+
//│ globalThis.Predef.__stackOffset = 0;
342344
//│ globalThis.Predef.__stackDepth = 1;
343345
//│ globalThis.Predef.__stackHandler = stackHandler;
344346
//│ res2 = sum3(10000);

hkmc2/shared/src/test/mlscript/handlers/ZCombinator.mls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ let fact =
9191
:expect 3628800
9292
:stackSafe 5
9393
fact(10)
94-
//│ > 2 993
95-
//│ > 4 1
94+
//│ > 2 0
95+
//│ > 4 0
9696
//│ > 6 4
9797
//│ > 8 4
9898
//│ > 10 8

0 commit comments

Comments
 (0)