thunk

How to thunk a function in x86 and x64? (Like std::bind in C++, but dynamic)

北慕城南 提交于 2019-11-30 21:09:37
How do I thunk an arbitrary function with an arbitrary (fixed) number of arguments, on x86 and x64? (I don't need floating-point, SSE, or the like. The arguments are all integers or pointers.) Here's my generic implementation. I initially made it with AsmJit , then modified it by hand to remove the dependency. It works for both x86 and x64! It works for both cdecl and stdcall! It should also work for "thiscall", both on VC++ and GCC, but I haven't tested it. (VC++ would probably not touch the 'this' pointer, whereas GCC would treat it as the first argument.) It can bind an arbitrary number of

Thunk table in import address table?

两盒软妹~` 提交于 2019-11-30 07:15:00
问题 What is a thunk table in relation to the import address table that's used in EXE files to import functions used in external DLLs? Is this thunk table just a table containing 'Thunks' to other functions? 回答1: Thunks are a part of the Import table ( IMAGE_DIRECTORY_ENTRY_IMPORT ) and Delay Import Table ( IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT ). They are described http://msdn.microsoft.com/en-us/library/ms809762.aspx. I'll look at my old source code and will post later a working code which dump

More succinct delayed evaluation than function(){return x}?

北城以北 提交于 2019-11-28 11:42:58
I'm porting some Python code that relies heavily on delayed evaluation. This is accomplished by via thunks . More specifically, any Python expression <expr> for which delayed evaluation is desired gets enclosed within a Python "lambda expression", i.e. lambda:<expr> . AFAIK, the closest JavaScript equivalent of this is function(){return <expr>} . Since the code I'm working with is absolutely awash in such thunks, I'd like to make the code for them more succinct, if at all possible. The reason for this is not only to save characters (a non-negligible consideration when it comes to JS), but also

More succinct delayed evaluation than function(){return x}?

最后都变了- 提交于 2019-11-27 06:24:17
问题 I'm porting some Python code that relies heavily on delayed evaluation. This is accomplished by via thunks. More specifically, any Python expression <expr> for which delayed evaluation is desired gets enclosed within a Python "lambda expression", i.e. lambda:<expr> . AFAIK, the closest JavaScript equivalent of this is function(){return <expr>} . Since the code I'm working with is absolutely awash in such thunks, I'd like to make the code for them more succinct, if at all possible. The reason

What is a 'thunk'?

雨燕双飞 提交于 2019-11-26 21:24:31
I've seen it used in programming (specifically in the C++ domain) and have no idea what it is. Presumably it is a design pattern, but I could be wrong. Can anyone give a good example of a thunk? Chris Dodd A thunk usually refers to a small piece of code that is called as a function, does some small thing, and then JUMP s to another location (usually a function) instead of returning to its caller. Assuming the JUMP target is a normal function, when it returns, it will return to the thunk's caller. Thunks can be used to implement lots of useful things efficiently protocol translation -- when

:sprint for polymorphic values?

≡放荡痞女 提交于 2019-11-26 16:43:24
I am wondering why :sprint reports xs = _ in this case: Prelude> xs = map (+1) [1..10] Prelude> length xs 10 Prelude> :sprint xs xs = _ but not in this case: Prelude> xs = map (+1) [1..10] :: [Int] Prelude> length xs 10 Prelude> :sprint xs xs = [_,_,_,_,_,_,_,_,_,_] Note: I am running ghci with -XNoMonomorphismRestriction . Does it have to do with the fact that the type of xs is polymorphic in the first case but not in the second? I'd like to know what's going on internally. jozefg The gist is that the with the polymorphic xs it has a type of the form xs :: Num a => [a] typeclasses under the

:sprint for polymorphic values?

纵然是瞬间 提交于 2019-11-26 04:55:27
问题 I am wondering why :sprint reports xs = _ in this case: Prelude> xs = map (+1) [1..10] Prelude> length xs 10 Prelude> :sprint xs xs = _ but not in this case: Prelude> xs = map (+1) [1..10] :: [Int] Prelude> length xs 10 Prelude> :sprint xs xs = [_,_,_,_,_,_,_,_,_,_] Note: I am running ghci with -XNoMonomorphismRestriction . Does it have to do with the fact that the type of xs is polymorphic in the first case but not in the second? I\'d like to know what\'s going on internally. 回答1: The gist