1TRAMPOLINE(3)              Library Functions Manual              TRAMPOLINE(3)
2
3
4

NAME

6       trampoline - closures as first-class C functions
7

SYNOPSIS

9       #include <trampoline_r.h>
10
11       function = alloc_trampoline_r(address, data0, data1);
12
13       free_trampoline_r(function);
14
15       is_trampoline_r(function)
16       trampoline_r_address(function)
17       trampoline_r_data0(function)
18       trampoline_r_data1(function)
19

DESCRIPTION

21       These  functions implement closures as first-class C functions.  A clo‐
22       sure consists of a regular C function and a piece of  data  which  gets
23       passed to the C function when the closure is called.
24
25       Closures as first-class C functions means that they fit into a function
26       pointer and can be called exactly like any other C function.   function
27       =  alloc_trampoline_r(address,  data0, data1) allocates a closure. When
28       function gets called, it stores in a special "lexical chain register" a
29       pointer  to a storage area containing data0 in its first word and data1
30       in its second word and calls the C function at address.   The  function
31       at address is responsible for fetching data0 and data1 off the pointer.
32       Note that the "lexical chain register" is a call-used register, i.e. is
33       clobbered by function calls.
34
35       This  is  much  like gcc's local functions, except that the GNU C local
36       functions have dynamic extent (i.e. are deallocated when  the  creating
37       function  returns), while trampoline provides functions with indefinite
38       extent: function is only deallocated  when  free_trampoline_r(function)
39       is called.
40
41       is_trampoline_r(function)  checks  whether  the C function function was
42       produced by a call to alloc_trampoline_r.  If this  returns  true,  the
43       arguments given to alloc_trampoline_r can be retrieved:
44
45           trampoline_r_address(function) returns address,
46
47           trampoline_r_data0(function) returns data0,
48
49           trampoline_r_data1(function) returns data1.
50
51

SEE ALSO

53       trampoline(3), gcc(1), varargs(3)
54
55

PORTING

57       The way gcc builds local functions is described in the gcc source, file
58       gcc-2.6.3/config/cpu/cpu.h.
59
60

AUTHOR

62       Bruno Haible <bruno@clisp.org>
63
64

ACKNOWLEDGEMENTS

66       Many ideas were cribbed from the gcc source.
67
68
69
70
71                                22 October 1997                  TRAMPOLINE(3)
Impressum