source: project/tcc/tcc.html @ 6865

Last change on this file since 6865 was 6865, checked in by felix winkelmann, 13 years ago

removed deprecated features

File size: 6.2 KB
Line 
1<html>
2<head><title>Eggs Unlimited - tcc</title></head>
3<body>
4
5<center><img src="egg.jpg"></center>
6<center><a href="index.html">back</a></center>
7
8<h2>tcc</h2>
9
10<h3>Description:</h3>
11A library for using the <a href="http://www.tinycc.org">Tiny C compiler</a>.
12
13<h3>Author:</h3>
14<a href="mailto:felix@call-with-current-continuation.org">felix</a>
15
16<h3>Version:</h3>
17<ul>
18<li>1.3
19renamed deprecated use of <code>foreign-callback-lambda</code>.
20<li>1.2
21<code>tcc:get-symbol</code> was fixed to compile with newest tcc version [Thanks to Damian M. Gryski]
22<li>1.1
23Adapted to new setup scheme.
24<li>1.0
25</ul>
26
27<h3>Usage:</h3> 
28<pre>
29(require-extension tcc)
30</pre>
31
32<h3>Download:</h3>
33<a href="tcc.egg">tcc.egg</a>
34
35<h3>Documentation:</h3>
36
37This extension is a thin wrapper around the <code>libtcc</code> library that allows compilation of
38C completely into memory, into an executable or a dynamically loadable library. The following descriptions
39are taken mostly from the <code>libtcc.h</code> header file.
40
41<dl>
42<dt><pre><b>[integer constant] tcc/output-memory
43[integer constant] tcc/output-exe
44[integer constant] tcc/output-dll
45[integer constant] tcc/output-obj</b></pre>
46<dd>Constants specifying the compilation target.
47
48<dt><pre><b>[procedure] (tcc:new)</b></pre>
49<dd>Create a new TCC compilation context.
50
51<dt><pre><b>[procedure] (tcc:delete STATE)</b></pre>
52<dd>Free a TCC compilation context.
53
54<dt><pre><b>[procedure] (tcc:enable-debug STATE)</b></pre>
55<dd>Add debug information in the generated code.
56
57<dt><pre><b>[procedure] (tcc:set-warning STATE STRING BOOL)</b></pre>
58<dd>Set error/warning display callback. If <code>BOOL</code> is true, then compiler errors and warnings
59raise an exception in the procedure invoking the compilation. The exception is a composite exception of the
60kinds <code>exn</code> and <code>tcc</code>.
61
62<dt><pre><b>[procedure] (tcc:add-include-path STATE STRING)</b></pre>
63<dd>Add include path.
64
65<dt><pre><b>[procedure] (tcc:add-sysinclude-path STATE STRING)</b></pre>
66<dd>Add in system include path.
67
68<dt><pre><b>[procedure] (tcc:define-symbol STATE SYMBOL VALUE)</b></pre>
69<dd>Define preprocessor symbol <code>SYMBOL</code> as <code>VALUE</code> (both strings).
70
71<dt><pre><b>[procedure] (tcc:undefine-symbol STATE STRING)</b></pre>
72<dd>Undefine preprocess symbol <code>STRING</code>.
73
74<dt><pre><b>[procedure] (tcc:add-file STATE STRING)</b></pre>
75<dd>Add a file (either a C file, dll, an object, a library or an ld
76   script).
77
78<dt><pre><b>[procedure] (tcc:compile-string STATE STRING)</b></pre>
79<dd>Compile a string containing C source.
80
81<dt><pre><b>[procedure] (tcc:set-output-type STATE TYPE)</b></pre>
82<dd>Set output type (like <code>tcc:output/memory</code>). <b>Must be called</b> before any compilation.
83
84<dt><pre><b>[procedure] (tcc:add-library-path STATE STRING)</b></pre>
85<dd>Equivalent to <code>-L<i>path</i></code> option.
86
87<dt><pre><b>[procedure] (tcc:add-library STATE STRING)</b></pre>
88<dd>The library name is the same as the argument of the <code>-l</code> option.
89
90<dt><pre><b>[procedure] (tcc:add-symbol STATE STRING POINTER)</b></pre>
91<dd>Add a symbol to the compiled program.
92
93<dt><pre><b>[procedure] (tcc:output-file STATE STRING)</b></pre>
94<dd>Output an executable, library or object file. <b>Do not</b> call
95<code>tcc:relocate</code> before.
96
97<dt><pre><b>[procedure] (tcc:run STATE ARGC ARGV)</b></pre>
98<dd>Link and run <code>main</code> function and return its value. <b>Do not</b> call
99   <code>tcc:relocate</code> before.
100
101<dt><pre><b>[procedure] (tcc:relocate STATE)</b></pre>
102<dd>Do all relocations (needed before using <code>tcc:get-symbol</code>).
103
104<dt><pre><b>[procedure] (tcc:get-symbol STATE</b></pre>
105<dd>Return symbol value as a pointer object.
106</dl>
107
108
109<p><h3>Examples:</h3>
110<pre>
111; Compile and run a well known example
112
113(define s (tcc:new))
114(tcc:set-output-type s tcc/output-memory)
115(tcc:compile-string s "int main() { printf(\"Hello, world!\\n\"); return 0; }")
116(tcc:run s '())
117(tcc:delete s)
118
119
120; Compile a file with callbacks into Scheme
121
122(define-external (add (int a) (int b)) int
123  (+ a b) )
124
125(define my-program #&lt;&lt;EOF
126int fib(int n)
127{
128    if (n <= 2)
129        return 1;
130    else
131        return fib(n-1) + fib(n-2);
132}
133
134int foo(int n)
135{
136    printf("Hello World!\n");
137    printf("fib(%d) = %d\n", n, fib(n));
138    printf("add(%d, %d) = %d\n", n, 2 * n, add(n, 2 * n));
139    return 0;
140}
141EOF
142)
143
144(define call
145  (foreign-callback-lambda* int ([c-pointer func] [int arg])
146    "return(((int (*)(int))func)(arg));") )
147
148(define s (tcc:new))
149(tcc:set-output-type s tcc/output-memory)
150(tcc:compile-string s my-program)
151(tcc:add-symbol s "add" (location add))
152(tcc:relocate s)
153(define func (tcc:get-symbol s "foo"))
154(print (call func 32))
155(tcc:delete s)
156</pre>
157
158<h3>License:</h3>
159<pre>
160Copyright (c) 2000-2003, Felix L. Winkelmann
161All rights reserved.
162
163Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
164conditions are met:
165
166  Redistributions of source code must retain the above copyright notice, this list of conditions and the following
167    disclaimer.
168  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
169    disclaimer in the documentation and/or other materials provided with the distribution.
170  Neither the name of the author nor the names of its contributors may be used to endorse or promote
171    products derived from this software without specific prior written permission.
172
173THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
174OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
175AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
176CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
177CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
178SERVICESLOSS OF USE, DATA, OR PROFITSOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
179THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
180OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
181POSSIBILITY OF SUCH DAMAGE.
182</pre>
183
184
185<hr><a href="index.html">back</a>
186
187</body>
188</html>
Note: See TracBrowser for help on using the repository browser.