source: project/inline/inline.html @ 2964

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

easyffi bugfix, wiki, minor things

File size: 5.3 KB
Line 
1<html>
2<head><title>Eggs Unlimited - inline</title></head>
3<body>
4
5<center><img src="egg.jpg"></center>
6<center><a href="index.html">back</a></center>
7
8<h2>inline</h2>
9
10<h3>Description:</h3>
11Allows compiled C inside interpreter scripts.
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.5
19Fixed dependencies on new easyffi egg
20<li>1.4
21Fixed dependency on <code>utils</code> unit [Thanks to Benedikt Rosenau]
22<li>1.3
23<code>inline-support</code> wasn't installed properly [Thanks to Peter Wang]
24<li>1.2
25Adapted to new setup scheme
26<li>1.1
27Now uses easyffi stuff, which is much simpler and more powerful. Does the right thing when compiled.
28<li>1.0
29</ul>
30
31<h3>Usage:</h3>
32<pre>
33(require-extension inline)
34</pre>
35
36<h3>Download:</h3>
37<a href="inline.egg">inline.egg</a>
38
39<h3>Documentation:</h3>
40
41This extension library provides a simple macro for using C code in the Chicken interpreter (``csi'').
42The program text is embedded into a thin Scheme wrapper and compiled on the fly into a dynamically
43loadable library. A local directory caches the compiled code and subsequent definitions of
44the same source text will load the already compiled library from the cache.
45<br>Callbacks back into Scheme are not supported.
46
47<dl>
48<dt><pre><b>[syntax] (inline STRING [OPTIONS])</b></pre>
49<dd>Expands into a call of <code>inline:compile</code> and compiles the code given in <code>STRING</code>.
50If encountered in compiled code, then this form
51will directly expand into a <code>(declare (foreign-declare ...) (foreign-parse ...))</code> form, effectively
52embedding the inline code in the compiled file (so no run-time compilation is needed).
53The optional string argument <code>OPTIONS</code> may contain additional compilation parameters (these are
54ignored, when <code>inline</code> is used in compiled code).
55
56<pre>
57(inline "int foo(int n) { return(n * 2); }")
58
59  ==> (inline:compile "int foo(int n) { return(n * 2); }") ; when interpreted
60  ==> (declare                                             ; when compiled
61        (foreign-declare "int foo(int n) { return(n * 2); }")
62        (foreign-parse "int foo(int n) { return(n * 2); }") )
63</pre>
64
65<dt><pre><b>[procedure] (inline:compile STRING [OPTIONS])</b></pre>
66<dd>Compiles the C source code in <code>STRING</code> dynamically. If a compiled library with the same source text is
67currently loaded (and has been cached), then nothing is done. If it is not loaded, the
68<i>inline cache</i> is consulted, whether a compiled file for the same text is stored,
69and, if it is, it's loaded and the procedure is returned. If no such file exists, the compiler
70(``csc'') is invoked to create a compiled library (with any extra options passed in <code>OPTIONS</code>),
71which is stored in the cache. The code will be compiled as
72if wrapped in <code>#&gt;! ... &lt;#</code>. Note that you will have to shield <code>#include</code> forms, if you
73don't want them to be processed by the FFI parser:
74
75<pre>
76(inline #&lt;&lt;EOF
77#ifndef CHICKEN
78#include "gd.h"
79#include &lt;stdio.h&gt;
80#endif
81
82void genimages(int w, int h) {
83  gdImagePtr im;
84  FILE *pngout, *jpegout;
85  int black;
86  int white;
87
88  im = gdImageCreate(w, h);
89  black = gdImageColorAllocate(im, 0, 0, 0);   
90  white = gdImageColorAllocate(im, 255, 255, 255);     
91  gdImageLine(im, 0, 0, w - 1, h - 1, white);   
92  pngout = fopen("test.png", "wb");
93  jpegout = fopen("test.jpg", "wb");
94  gdImagePng(im, pngout);
95  gdImageJpeg(im, jpegout, -1);
96  fclose(pngout);
97  fclose(jpegout);
98  gdImageDestroy(im);
99}
100EOF
101"-L -lgd -L -lpng -L -lz -L -ljpeg -L -lfreetype"
102)
103
104(genimages 64 64)
105</pre>
106
107<dt><pre><b>[parameter] inline:cache</b></pre>
108<dd>Holds the name of the directory which is used as a cache for compiled code and defaults
109to <code>./.cache</code>.
110
111</dl>
112
113<h3>License:</h3>
114<pre>
115Copyright (c) 2003-2007, Felix L. Winkelmann
116All rights reserved.
117
118Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
119conditions are met:
120
121  Redistributions of source code must retain the above copyright notice, this list of conditions and the following
122    disclaimer.
123  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
124    disclaimer in the documentation and/or other materials provided with the distribution.
125  Neither the name of the author nor the names of its contributors may be used to endorse or promote
126    products derived from this software without specific prior written permission.
127
128THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
129OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
130AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
131CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
132CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
133SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
134THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
135OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
136POSSIBILITY OF SUCH DAMAGE.
137</pre>
138
139
140<hr><a href="index.html">back</a>
141
142</body>
143</html>
Note: See TracBrowser for help on using the repository browser.