Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/tcc|the CHICKEN 4 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == Introduction A library for using the [[http://www.tinycc.org|Tiny C compiler]]. == Examples Compile and run a well known example: <enscript highlight="scheme"> (define s (tcc:new)) (tcc:set-output-type s tcc/output-memory) (tcc:compile-string s "int main() { printf(\"Hello, world!\\n\"); return 0; }") (tcc:run s '()) (tcc:delete s) </enscript> Compile a file with callbacks into Scheme: <enscript highlight="scheme"> (define-external (add (int a) (int b)) int (+ a b) ) (define my-program <<EOF int fib(int n) { if (n <= 2) return 1; else return fib(n-1) + fib(n-2); } int foo(int n) { printf("Hello World!\n"); printf("fib(%d) = %d\n", n, fib(n)); printf("add(%d, %d) = %d\n", n, 2 * n, add(n, 2 * n)); return 0; } EOF ) (define call (foreign-callback-lambda* int ([c-pointer func] [int arg]) "return(((int (*)(int))func)(arg));") ) (define s (tcc:new)) (tcc:set-output-type s tcc/output-memory) (tcc:compile-string s my-program) (tcc:add-symbol s "add" (location add)) (tcc:relocate s) (define func (tcc:get-symbol s "foo")) (print (call func 32)) (tcc:delete s) </enscript> == Author [[felix winkelmann|Felix Winkelmann]] == License Copyright (c) 2000-2003, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICESLOSS OF USE, DATA, OR PROFITSOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. == Requirements {{libtcc}} must be installed on the host system. == Documentation This extension is a thin wrapper around the {{libtcc}} library that allows compilation of C completely into memory, into an executable or a dynamically loadable library. The following descriptions are taken mostly from the {{libtcc.h}} header file. <constant>tcc/output-memory</constant> <constant>tcc/output-exe</constant> <constant>tcc/output-dll</constant> <constant>tcc/output-obj</constant> Constants specifying the compilation target. <procedure>(tcc:new)</procedure> Create a new TCC compilation context. <procedure>(tcc:delete STATE)</procedure> Free a TCC compilation context. <procedure>(tcc:enable-debug STATE)</procedure> Add debug information in the generated code. <procedure>(tcc:set-warning STATE STRING BOOL)</procedure> Set error/warning display callback. If {{BOOL}} is true, then compiler errors and warnings raise an exception in the procedure invoking the compilation. The exception is a composite exception of the kinds {{exn}} and {{tcc}}. <procedure>(tcc:add-include-path STATE STRING)</procedure> Add include path. <procedure>(tcc:add-sysinclude-path STATE STRING)</procedure> Add in system include path. <procedure>(tcc:define-symbol STATE SYMBOL VALUE)</procedure> Define preprocessor symbol {{SYMBOL}} as {{VALUE}} (both strings). <procedure>(tcc:undefine-symbol STATE STRING)</procedure> Undefine preprocess symbol {{STRING}}. <procedure>(tcc:add-file STATE STRING)</procedure> Add a file (either a C file, dll, an object, a library or an ld script). <procedure>(tcc:compile-string STATE STRING)</procedure> Compile a string containing C source. <procedure>(tcc:set-output-type STATE TYPE)</procedure> Set output type (like {{tcc:output/memory}}). '''Must be called''' before any compilation. <procedure>(tcc:add-library-path STATE STRING)</procedure> Equivalent to {{-L}}''{{path}}'' option. <procedure>(tcc:add-library STATE STRING)</procedure> The library name is the same as the argument of the {{-l}} option. <procedure>(tcc:add-symbol STATE STRING POINTER)</procedure> Add a symbol to the compiled program. <procedure>(tcc:output-file STATE STRING)</procedure> Output an executable, library or object file. '''Do not''' call {{tcc:relocate}} before. <procedure>(tcc:run STATE ARGC ARGV)</procedure> Link and run {{main}} function and return its value. '''Do not''' call {{tcc:relocate}} before. <procedure>(tcc:relocate STATE)</procedure> Do all relocations (needed before using {{tcc:get-symbol}}). <procedure>(tcc:get-symbol STATE</procedure> Return symbol value as a pointer object. == Version History * 1.3: renamed deprecated use of {{foreign-callback-lambda}}. * 1.2: {{tcc:get-symbol}} was fixed to compile with newest tcc version [Thanks to Damian M. Gryski] * 1.1: Adapted to new setup scheme. * 1.0
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 8 by 9?