thunk

(redirected from thunks)
Also found in: Dictionary, Thesaurus.

thunk

[thəŋk]
(computer science)
An additional subprogram created by the compiler to represent the evaluation of the argument of an expression in the call-by-name procedure.

thunk

(programming)
/thuhnk/ 1. "A piece of coding which provides an address", according to P. Z. Ingerman, who invented thunks in 1961 as a way of binding actual parameters to their formal definitions in ALGOL 60 procedure calls. If a procedure is called with an expression in the place of a formal parameter, the compiler generates a thunk which computes the expression and leaves the address of the result in some standard location.

2. The term was later generalised to mean an expression, frozen together with its environment (variable values), for later evaluation if and when needed (similar to a "closure"). The process of unfreezing these thunks is called "forcing".

3. A stubroutine, in an overlay programming environment, that loads and jumps to the correct overlay.

Compare trampoline.

There are a couple of onomatopoeic myths circulating about the origin of this term. The most common is that it is the sound made by data hitting the stack; another holds that the sound is that of the data hitting an accumulator. Yet another suggests that it is the sound of the expression being unfrozen at argument-evaluation time. In fact, according to the inventors, it was coined after they realised (in the wee hours after hours of discussion) that the type of an argument in ALGOL 60 could be figured out in advance with a little compile-time thought, simplifying the evaluation machinery. In other words, it had "already been thought of"; thus it was christened a "thunk", which is "the past tense of "think" at two in the morning".

4. (Microsoft Windows programming) universal thunk, generic thunk, flat thunk.

thunk

In a PC, to execute the instructions required to switch between segmented addressing of memory and flat addressing. A thunk typically occurs when a 16-bit application is running in a 32-bit address space, and its 16-bit segmented address must be converted into a full 32-bit flat address. On the other hand, if a 32-bit program calls a 16-bit DLL, then the thunk is in the opposite direction: from 32 bit to 16 bit.
References in periodicals archive ?
It does not contain thunks, so we transform this graph into the term succ(0), and conclude that this is the normal form of nth(succ(0), inf(0)).
--we replace, in a bottom-up fashion, lazy nonvariable subterms t by thunks [Theta]([Lambda], [vec.sub.[Alpha]]([x.sub.1], ..., [x.sub.|[Alpha]|])), with [x.sub.1], ..., [x.sub.|[Alpha]|] the variables in t, and [[Alpha].sub.[Iota]] = 0 if and only if [x.sub.i] is a lazy argument in l and does not occur at an active position in r;
Thunks: a way of compiling procedure statements with some comments on procedure declarations.
Then, first the nodes of the lazy graph that are not active are thunked, to prevent that they can be rewritten in an eager fashion.
--[Theta], called a thunk, is a binary function symbol with two eager arguments.
The [vec.sub.[Alpha]] are auxiliary function symbols, which enable one to collect several nodes below the second argument of the thunk [Theta].
In the thunks implementation, we do not need to perform any tests when calling a signature member function.
We improved the code generation for signature member function calls and implemented signature tables using thunks. These changes are not in the released version of GCC-2.7.2; they are available from the authors on request.
To do this, a customized piece of code, called thunk, is generated for each signature table entry that performs all the necessary adjustments and then branches to the class member function.
In the common case of calling a nonvirtual class member function that does not need any this adjustment, we do not need any thunk. Instead, the signature table entry can point to the member function directly.
The thunk needed for calling C: : f is the following short piece of code:
Before branching to the thunk, the compiler will have set up the activation record correctly for calling C: : f.