Questions tagged [trampolines]

A technique to emulate (or augment) jumps / function calls by a custom dispatch. A single trampoline is sufficient to express all control transfers of a program.

A technique to emulate (or augment) jumps / function calls by a custom dispatch to converted functions which return control back to the dispatch (a.k.a. the trampoline) instead of making the function calls themselves, using data to control the control flow.

A single trampoline is sufficient to express all control transfers of a program; a program so expressed is trampolined or in "trampolined style"; converting a program to trampolined style is trampolining. Trampolined functions can be used to implement tail recursive function calls in stack-oriented languages.

See Wikipedia.

71 questions
2
votes
1 answer

How to speed up the trampolined cps version fib function and support mutual recursion in python?

I have try to implement trampoline for a cps version of fibonacci function. But I can't make it fast (add cache) and support mutual_recursion. The implement code: import functools from dataclasses import dataclass from typing import Optional, Any,…
jiamo
  • 1,406
  • 1
  • 17
  • 29
2
votes
1 answer

How to combine TaskT with the monad instance of Trampoline to get stackless async computations?

Trampoline is a monad and adds stack-safety to a monad transformer stack. It achieves this by relying on a special interpreter (monadRec), which is fed with the result of a monadic computation (actually it is a specialized version of the free monad…
2
votes
0 answers

Reduce the amount of trampolines type 2 used

we are developing a iOS app using Unity3D and we have run into the "Ran out of trampolines type 2 error" all the time. Since Unity doesn't allow use to adjust the trampoline limit, so we have to reduce the amount of trampoline used. So far, we have…
Richard
  • 111
  • 3
2
votes
0 answers

Use of thunks, trampolines and continuation passing in python

I came to know about the concept of Tail Call Optimization(TCO) from this blog: Sing Me A Song of Stack Overflow: A Musical Tail Call Optimization. Going into this concept(or "feature" or "optimization technique"), I came to know that using TCO in…
Sanip
  • 1,772
  • 1
  • 14
  • 29
2
votes
0 answers

Prevent recursive hooking when using detours

I wanted to build some sort of API monitor by hooking all ntdll functions using Detours API. Each hooked function will call the original implementation and than add notice for this call inside std base data structure. However, I encountered a…
Irad K
  • 867
  • 6
  • 20
2
votes
1 answer

How to make a Hook and Trampoline function in one for WinAPI hooking

So I have been learning about the concept of hooking and using trampolines in order to bypass/execute data in a WinAPI hook function (In a different executable file, using DLL injection). So far I know how to make it (the trampoline and hook) using…
Rivasa
  • 6,510
  • 3
  • 35
  • 64
2
votes
1 answer

Trampolines in C++ Metaprogramming

I am reading a book on metaprogramming and there is secession on Trampolines: struct generic_t { void* obj; void(*del)(void*); }; template // outer template parameter generic_t copy_to_generic(const T& value) { struct…
MEMS
  • 617
  • 1
  • 6
  • 11
2
votes
2 answers

Design pattern for exception-safe trampolines

This question follows from here. However, the previous question was worded so badly (wrongly in fact) that it was suggested I ask again from scratch. I have a table of C-function pointers. Some C code (let us call it lib-X) has a basic building…
P i
  • 29,020
  • 36
  • 159
  • 267
2
votes
1 answer

Trampoline as a Functor

I'm trying to demonstrate a Trampoline[+A] as a Functor (i.e., provides map[B](f: A = >B)). I understand the classic implementation of the Trampoline as a Monad as described in Stackless Scala. However, is there a way to implement the map function…
Shimi Bandiel
  • 5,773
  • 3
  • 40
  • 49
2
votes
1 answer

JSON.NET: Not working with MonoTouch "Ran out of trampolines of type 2 "

I have tried the JSON.NET and the MonoTouch port at https://github.com/ayoung/Newtonsoft.Json but get this Serialization error: Ran out of trampolines of type 2 in…
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
1
vote
1 answer

Full CPS transformation viability when using truffle graalvm?

I'm working on an interpreter, and just recently discovered graal truffle, which promises fast performance if I use it to implement the interpreter. However, from what I can the mileage varies on the interpreter's code and how easily compiler can…
Coderino Javarino
  • 2,819
  • 4
  • 21
  • 43
1
vote
1 answer

JS convert recursive function to trampoline

I am struggling to convert the JS recursive function below into a a trampoline function(s) in order to avoid maxing out the call stack with deep nodes. It returns an array of all children nodes from the initial root node passed in. Note, list is a…
ZRD
  • 15
  • 3
1
vote
1 answer

Set default Execution Context in ZIO

I am trying to use a TrampolineExecutionContext in ZIO in order to test background stream subscriptions on the same thread (so I can run effect in the order I would expect). testM("Using trampoline execution context") { (for { queue <-…
Matroska
  • 6,885
  • 14
  • 63
  • 99
1
vote
1 answer

How do I safely wrap a callback to pass to Windows FFI?

I am trying to write a wrapper on top of winapi. I want to wrap functions that accept pointers for callback functions. As an example, consider this: // The unsafe callback type the FFI function accepts type UnsafeCallback = unsafe extern "system"…
Erik Schulze
  • 119
  • 9
1
vote
1 answer

Weird behavior of trampolining

Recently I've been doing some JS tasks on codewars and encountered this task Tail recursion with trampoline. Here we need to create thunk function and trampoline function in order to get rid of annoying RangeError: Maximum call stack size…
wlukla
  • 83
  • 4