Continued pass style versus aggressively clipped call stack?

I am considering something like CPS for use in the interpreter for the acting language.

The arguments to the function are passed in an array of options, and the continuation is returned in the same array, so a simple function

def add (x,y) => x + y

so the call from the read / eval / loop will

print( add(7, 5) )

will be at the input

[&add, x, y, &print, _, &repl, ...]

where _ is the empty slot in which the return value of the function is written.

At the next stage of execution, the arguments become

[&print, 12, &repl, ...]

then

[repl, ...]

etc. The implementation in C is mainly

for (;;)
   args = (args[0].function_pointer)(args);

with checks to run the end of the args array and allocate more space.

The arguments are contiguous, and the “continuation” as an object is just a subset of the arguments.

, ; . - , .

​​ CPS, CPS, , C- - .

, ? + , , "", , .

+3
1

. .

+2

Source: https://habr.com/ru/post/1702824/


All Articles