~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to ffcall/callback/trampoline_r/trampoline_r.html

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HEAD>
2
 
<TITLE> TRAMPOLINE_R manual page </TITLE>
3
 
</HEAD>
4
 
<BODY>
5
 
<H1>TRAMPOLINE_R manual page</H1>
6
 
 
7
 
<UL>
8
 
<LI> <A HREF="#Name">Name</A>
9
 
<LI> <A HREF="#Synopsis">Synopsis</A>
10
 
<LI> <A HREF="#Description">Description</A>
11
 
<LI> <A HREF="#See also">See also</A>
12
 
<LI> <A HREF="#Porting">Porting</A>
13
 
<LI> <A HREF="#Author">Author</A>
14
 
<LI> <A HREF="#Acknowledgements">Acknowledgements</A>
15
 
</UL>
16
 
<P>
17
 
 
18
 
<HR>
19
 
 
20
 
<A NAME="Name">
21
 
<H2>Name</H2>
22
 
</A>
23
 
 
24
 
trampoline_r -  closures as first-class C functions
25
 
 
26
 
<A NAME="Synopsis">
27
 
<H2>Synopsis</H2>
28
 
</A>
29
 
 
30
 
<PRE>
31
 
<CODE>#include &lt;trampoline_r.h&gt;</CODE>
32
 
<CODE><VAR>function</VAR> = alloc_trampoline_r(<VAR>address</VAR>, <VAR>data0</VAR>, <VAR>data1</VAR>);</CODE>
33
 
<CODE>free_trampoline_r(<VAR>function</VAR>);</CODE>
34
 
<CODE>is_trampoline_r(<VAR>function</VAR>)</CODE>
35
 
<CODE>trampoline_r_address(<VAR>function</VAR>)</CODE>
36
 
<CODE>trampoline_r_data0(<VAR>function</VAR>)</CODE>
37
 
<CODE>trampoline_r_data1(<VAR>function</VAR>)</CODE>
38
 
</PRE>
39
 
 
40
 
<A NAME="Description">
41
 
<H2>Description</H2>
42
 
</A>
43
 
 
44
 
These  functions implement <EM>closures</EM>  as first-class
45
 
C functions.  A closure consists of a regular C function  and  a
46
 
piece of data which gets passed to the C function when the
47
 
closure is called.
48
 
<P>
49
 
Closures as <EM>first-class C functions</EM> means  that  they  fit
50
 
into a function pointer and can be called exactly like any
51
 
other C function.  <CODE><VAR>function</VAR> =  alloc_trampoline_r(<VAR>address</VAR>, <VAR>data0</VAR>, <VAR>data1</VAR>)</CODE>
52
 
allocates  a  closure.  When <VAR>function</VAR> gets
53
 
called, it stores in a special &quot;lexical chain register&quot;  a
54
 
pointer  to  a  storage area containing <VAR>data0</VAR> in its first
55
 
word and <VAR>data1</VAR> in its second word and calls the C function
56
 
at  <VAR>address</VAR>.   The  function at <VAR>address</VAR> is responsible for
57
 
fetching <VAR>data0</VAR> and  <VAR>data1</VAR>  off  the  pointer.  Note  that  the
58
 
&quot;lexical  chain register&quot; is a call-used register, i.e. is
59
 
clobbered by function calls.
60
 
<P>
61
 
This is much like gcc's local functions, except  that  the
62
 
GNU  C local functions have dynamic extent (i.e. are
63
 
deallocated when the creating function returns), while <EM>trampoline</EM>
64
 
  provides  functions with indefinite extent: <CODE><VAR>function</VAR></CODE>
65
 
is  only  deallocated  when  <CODE>free_trampoline_r(<VAR>function</VAR>)</CODE>  is
66
 
called.
67
 
<P>
68
 
<CODE>is_trampoline_r(<VAR>function</VAR>)</CODE>
69
 
checks  whether  the  C  function <CODE><VAR>function</VAR></CODE>
70
 
was  produced by a call to <CODE>alloc_trampoline_r</CODE>.
71
 
If this returns true, the arguments given to <CODE>alloc_trampoline_r</CODE>
72
 
can  be  retrieved:
73
 
<UL>
74
 
<LI> <CODE>trampoline_r_address(<VAR>function</VAR>)</CODE> returns <VAR>address</VAR>,
75
 
<LI> <CODE>trampoline_r_data0(<VAR>function</VAR>)</CODE> returns <VAR>data0</VAR>,
76
 
<LI> <CODE>trampoline_r_data1(<VAR>function</VAR>)</CODE> returns <VAR>data1</VAR>.
77
 
</UL>
78
 
 
79
 
<A NAME="See also">
80
 
<H2>See also</H2>
81
 
</A>
82
 
<A HREF="trampoline(3)"><CODE><B>trampoline</B></CODE></A>(3), <A HREF="gcc(1)"><CODE><B>gcc</B></CODE></A>(1), <A HREF="varargs(3)"><CODE><B>varargs</B></CODE></A>(3)
83
 
 
84
 
<A NAME="Porting">
85
 
<H2>Porting</H2>
86
 
</A>
87
 
 
88
 
The way gcc builds local functions is described in the gcc
89
 
source, file <SAMP>gcc-2.6.3/config/<VAR>cpu</VAR>/<VAR>cpu</VAR>.h</SAMP>.
90
 
 
91
 
<A NAME="Author">
92
 
<H2>Author</H2>
93
 
</A>
94
 
 
95
 
Bruno Haible &lt;bruno@clisp.org&gt;
96
 
 
97
 
<A NAME="Acknowledgements">
98
 
<H2>Acknowledgements</H2>
99
 
</A>
100
 
 
101
 
Many ideas were cribbed from the gcc source.
102
 
<P>
103
 
 
104
 
<HR>
105
 
 
106
 
<ADDRESS>TRAMPOLINE_R manual page<BR>
107
 
Bruno Haible &lt;bruno@clisp.org&gt;
108
 
</ADDRESS>
109
 
<P>
110
 
Last modified: 22 October 1997.
111
 
 
112
 
</BODY>