Run the action, m, with no stack info
Moduleghc-9.10.3GHC2021
GHC.StgToJS.Stack
Utilities and wrappers for Stack manipulation in JS Land.
In general, functions suffixed with a tick do the actual work, functions
suffixed with an I are identical to the non-I versions but work on Idents
The stack in JS land is held in the special JS array 'h$stack' and the stack pointer is held in 'h$sp'. The top of the stack thus exists at 'h$stack[h$sp]'. h$stack[h$sp + i] where i > 0, moves deeper into the stack into older entries, whereas h$stack[h$sp - i] moves towards the top of the stack.
The stack layout algorithm is slightly peculiar. It makes an effort to remember recently popped things so that if these values need to be pushed then they can be quickly. The implementation for this is storing these values above the stack pointer, and the pushing will skip slots that we know we will use and fill in slots marked as unknown. Thus, you may find that our push and pop functions do some non-traditional stack manipulation such as adding slots in pop or removing slots in push.
- 27 values
- Packageghc-9.10.3
- Exports27
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceStack.hs
run the action, m, with current stack info, but don't let modifications
propagate
overwrite our stack knowledge
retrieve our current stack knowledge
add knowledge about the stack slots
drop n slots from our stack knowledge
add n unknown slots to our stack knowledge
Shrink the stack and stack pointer. NB: This function is unsafe when the
input n, is negative. This function wraps around adjSpN which actually
performs the work.
Shrink the stack pointer by n. The stack grows downward so substract
Grow the stack pointer by n without modifying the stack depth. The stack
is just a JS array so we add to grow (instead of the traditional subtract)
Partial Push functions. Like pushN except these push functions skip
slots. For example,
function h$pp33(x1, x2) {
h$sp += 6;
h$stack[(h$sp - 5)] = x1;
h$stack[(h$sp - 0)] = x2;
};
The 33rd entry skips slots 1-4 to bind the top of the stack and the 6th slot. See pushOptimized and pushOptimized' for use cases.
Like pushN' but for the partial push functions
Convert all function symbols in pushN to global top-level functions. This
is a hack which converts the function symbols to variables. This hack is
caught in GHC.StgToJS.Printer.prettyBlock' to turn these into global
functions.
A constant array that holds global function symbols which do N pushes onto
the stack. For example:
function h$p1(x1) {
++h$sp;
h$stack[(h$sp - 0)] = x1;
};
function h$p2(x1, x2) {
h$sp += 2;
h$stack[(h$sp - 1)] = x1;
h$stack[(h$sp - 0)] = x2;
};
and so on up to 32.
pushOptimized optimized push that reuses existing values on stack automatically chooses an optimized partial push (h$ppN) function when possible.
push a let-no-escape frame onto the stack
Blindly pop N slots
popSkip Pop things, don't update the stack knowledge in G
Pop but preserve the first N slots
Load 'length (xs :: [JStgExpr])' things from the stack at offset 'n :: Int'.
This function does no stack pointer manipulation, it merely indexes into the
stack and loads payloads into xs.
Thunk update
3 declarationsWrapper around updateThunk', performs the stack manipulation before updating the Thunk.
Update a thunk by checking StgToJSConfig. If the config inlines black holes then update inline, else make an explicit call to the black hole handler.
Generate statements to update the current node with a blackhole