trampolines

MonoDevelop settings to fix “ran out of trampolines type 2” error

自古美人都是妖i 提交于 2019-12-04 02:42:48
we are developing an iOS app. When we tested the app on PC, everything works well but when we ran it on a iPad/iPhone4 we frequently receive the "Ran out of Trampolines type 2" error message and the app crash. We have been spending the last few days trying to identify the cause/fix it and tried all the suggestions we have find on the net, we still have not made any progress. The only solution we have found are from the posts/webpages talking about the adjusting the trampoline settings with compiler settings like this: -aot "nrgctx-trampolines=4048" -aot "nimt-trampolines=4048" in monotouch.

How to create a trampoline function for hook

岁酱吖の 提交于 2019-12-04 00:28:05
I'm interested in hooking and I decided to see if I could hook some functions. I wasn't interested in using a library like detours because I want to have the experience of doing it on my own. With some sources I found on the internet, I was able to create the code below. It's basic, but it works alright. However when hooking functions that are called by multiple threads it proves to be extremely unstable. If two calls are made at nearly the same time, it'll crash. After some research I think I need to create a trampoline function. After looking for hours all I was not able to find anything

What is the standard way to optimise mutual recursion in F#/Scala?

依然范特西╮ 提交于 2019-12-03 13:02:37
These languages do not support mutually recursive functions optimization 'natively', so I guess it must be trampoline or.. heh.. rewriting as a loop) Do I miss something? UPDATE: It seems that I did lie about FSharp, but I just didn't see an example of mutual tail-calls while googling First of all, F# supports mutually recursive functions natively, because it can benefit from the tailcall instruction that's available in the .NET IL ( MSDN ). However, this is a bit tricky and may not work on some alternative implementations of .NET (e.g. Compact Frameworks), so you may sometimes need to deal

How to adapt trampolines to Continuation Passing Style?

亡梦爱人 提交于 2019-12-01 18:17:12
Here is a naive implementation of a right fold: const foldr = f => acc => ([x, ...xs]) => x === undefined ? acc : f(x) (foldkr(f) (acc) (xs)); This is non-tail recursion and hence we cannot apply a trampoline. One approach would be to make the algorithm iterative and use a stack to mimick the function call stack. Another approch would be to transform the recursion into CPS: const Cont = k => ({runCont: k}); const foldkr = f => acc => ([x, ...xs]) => Cont(k => x === undefined ? k(acc) : foldkr(f) (acc) (xs) .runCont(acc_ => k(f(x) (acc_)))); This is still naive, because it is insanely slow.

How to adapt trampolines to Continuation Passing Style?

有些话、适合烂在心里 提交于 2019-12-01 17:34:09
问题 Here is a naive implementation of a right fold: const foldr = f => acc => ([x, ...xs]) => x === undefined ? acc : f(x) (foldkr(f) (acc) (xs)); This is non-tail recursion and hence we cannot apply a trampoline. One approach would be to make the algorithm iterative and use a stack to mimick the function call stack. Another approch would be to transform the recursion into CPS: const Cont = k => ({runCont: k}); const foldkr = f => acc => ([x, ...xs]) => Cont(k => x === undefined ? k(acc) : foldkr

Design pattern for exception-safe trampolines

你说的曾经没有我的故事 提交于 2019-12-01 11:15:49
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 block (let's call it a X-object). Each X-object can invoke functions on this table. These table functions generally have different signatures (see typedefs here ), although it is possible for several functions to share the same signature. There are about 100 of these functions in the table. In C++ I have an associated Final:Base class for each X-object

Design pattern for exception-safe trampolines

核能气质少年 提交于 2019-12-01 08:23:48
问题 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 block (let's call it a X-object). Each X-object can invoke functions on this table. These table functions generally have different signatures (see typedefs here), although it is possible for several functions to share the same signature. There are

Why does return/redo evaluate result functions in the calling context, but block results are not evaluated?

五迷三道 提交于 2019-11-30 09:26:46
Last night I learned about the /redo option for when you return from a function. It lets you return another function, which is then invoked at the calling site and reinvokes the evaluator from the same position >> foo: func [a] [(print a) (return/redo (func [b] [print b + 10]))] >> foo "Hello" 10 Hello 20 Even though foo is a function that only takes one argument, it now acts like a function that took two arguments . Something like that would otherwise require the caller to know you were returning a function, and that caller would have to manually use the do evaluator on it. Thus without

Why does return/redo evaluate result functions in the calling context, but block results are not evaluated?

安稳与你 提交于 2019-11-29 14:29:23
问题 Last night I learned about the /redo option for when you return from a function. It lets you return another function, which is then invoked at the calling site and reinvokes the evaluator from the same position >> foo: func [a] [(print a) (return/redo (func [b] [print b + 10]))] >> foo "Hello" 10 Hello 20 Even though foo is a function that only takes one argument, it now acts like a function that took two arguments . Something like that would otherwise require the caller to know you were

Applicative vs. monadic combinators and the free monad in Scalaz

南笙酒味 提交于 2019-11-29 12:42:15
问题 A couple of weeks ago Dragisa Krsmanovic asked a question here about how to use the free monad in Scalaz 7 to avoid stack overflows in this situation (I've adapted his code a bit): import scalaz._, Scalaz._ def setS(i: Int): State[List[Int], Unit] = modify(i :: _) val s = (1 to 100000).foldLeft(state[List[Int], Unit](())) { case (st, i) => st.flatMap(_ => setS(i)) } s(Nil) I thought that just lifting a trampoline into StateT should work: import Free.Trampoline val s = (1 to 100000).foldLeft