source: project/chicken/trunk/manual/Basic mode of operation @ 13670

Last change on this file since 13670 was 13670, checked in by felix winkelmann, 11 years ago

not a fix at all

File size: 2.3 KB
Line 
1[[tags: manual]]
2
3== Basic mode of operation
4
5The compiler translates Scheme source code into fairly portable C that
6can be compiled and linked with most available C compilers. CHICKEN supports
7the generation of executables and libraries, linked either statically or
8dynamically. Compiled Scheme code can be loaded dynamically, or can be
9embedded in applications written in other languages. Separate compilation
10of modules is fully supported.
11
12The most portable way of creating separately linkable entities is
13supported by so-called ''unit''s.  A unit is a single
14compiled object module that contains a number of toplevel expressions that
15are executed either when the unit is the ''main'' unit or if the
16unit is ''used''.  To use a unit, the unit has to be ''declare''ed
17as used, like this:
18
19<enscript highlight=scheme>
20(declare (uses UNITNAME))
21</enscript>
22
23The toplevel expressions of used units are executed in the order in
24which the units appear in the {{uses}} declaration. Units
25may be used multiple times and {{uses}} declarations may
26be circular (the unit is initialized at most once).  To compile a file
27as a unit, add a {{unit}} declaration:
28
29<enscript highlight=scheme>
30(declare (unit UNITNAME))
31</enscript>
32
33When compiling different object modules, make sure to have one main
34unit. This unit is called initially and initializes all used units
35before executing its toplevel expressions. The main-unit has no
36{{unit}} declaration.
37
38Another method of using definitions in separate source files is to
39''include'' them. This simply inserts the code in a given file into
40the current file:
41
42<enscript highlight=scheme>
43(include "FILENAME")
44</enscript>
45
46Macro definitions are only available when processed by {{include}} or
47{{import}}. Macro definitions in separate units are not available,
48since they are defined at compile time, i.e the time when that other
49unit was compiled (macros can optionally be available at runtime, see
50{{define-syntax}} in [[Non-standard macros and special forms|Substitution forms and macros]]).
51
52On platforms that support dynamic loading of compiled code (Windows, most ELF based
53systems like Linux or BSD, MacOS X, and others) code can be compiled into a shared object {{.dll}}, {{.so}}, {{.dylib}}) and loaded
54dynamically into a running application.
55
56Previous: [[Overview]]
57
58Next: [[Using the compiler]]
Note: See TracBrowser for help on using the repository browser.