Changeset 35528 in project


Ignore:
Timestamp:
05/07/18 16:20:06 (7 months ago)
Author:
felix
Message:

Fix links, resurrected Declarations page, minor fixes.

Location:
wiki/man/5
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/5/Deployment

    r35472 r35528  
    8282and place them in the application directory.
    8383
     84=== Distributing compiled C files
     85
     86It is possible to create distributions of Scheme projects that
     87have been compiled to C.  The runtime system of CHICKEN consists of only
     88two handcoded C files ({{runtime.c}} and {{chicken.h}}), plus the files
     89{{chicken-config.h}} and {{buildtag.h}}, which are generated by the
     90build process. All other modules of the runtime system and the extension
     91libraries are just compiled Scheme code. The following example shows a
     92minimal application, which should run without changes on most operating
     93systems, like Windows, Linux or FreeBSD (note however that static
     94binaries are not supported on Mac OS X).
     95
     96Take the following "Hello World" program:
     97
     98<enscript highlight=scheme>
     99; hello.scm
     100
     101(print "Hello, world!")
     102</enscript>
     103
     104  % csc -t hello.scm -optimize-level 3 -output-file hello.c
     105
     106Compiled to C, we get {{hello.c}}. We need the files {{chicken.h}},
     107{{chicken-config.h}}, {{buildtag.h}} and {{runtime.c}}, which contain
     108the basic runtime system, plus the library files {{build-version.c}},
     109{{chicken-syntax.c}}, {{eval.c}}, {{expand.c}}, {{internal.c}},
     110{{library.c}} and {{modules.c}}, which contain the same functionality as
     111the library that is linked into plain CHICKEN-compiled applications:
     112
     113  % cd /tmp
     114  % echo '(print "Hello World.")' > hello.scm
     115  % csc -t hello.scm
     116  % cp $CHICKEN_BUILD/build-version.c .
     117  % cp $CHICKEN_BUILD/chicken-syntax.c .
     118  % cp $CHICKEN_BUILD/eval.c .
     119  % cp $CHICKEN_BUILD/expand.c .
     120  % cp $CHICKEN_BUILD/internal.c .
     121  % cp $CHICKEN_BUILD/library.c .
     122  % cp $CHICKEN_BUILD/modules.c .
     123  % cp $CHICKEN_BUILD/runtime.c .
     124  % cp $CHICKEN_BUILD/chicken.h .
     125  % cp $CHICKEN_BUILD/chicken-config.h .
     126  % cp $CHICKEN_BUILD/buildtag.h .
     127  % gcc -Os -fomit-frame-pointer -DHAVE_CHICKEN_CONFIG_H hello.c \
     128    build-version.c eval.c expand.c internal.c library.c modules.c runtime.c \
     129    -o hello -lm
     130
     131Once we have all the files together, we can create a tarball:
     132
     133 % tar czf hello.tar.gz hello.c build-version.c chicken-syntax.c eval.c \
     134   expand.c internal.c library.c modules.c runtime.c chicken.h \
     135   chicken-config.h buildtag.h
     136
     137This is naturally rather simplistic. Things like enabling dynamic
     138loading and selecting supported features of the host system would need
     139more configuration- and build-time support. All this can be addressed
     140using more elaborate build-scripts, makefiles or by using
     141autoconf/automake.
     142
     143The {{chicken-config.h}} file may contain incorrect settings for your
     144deployment target. Especially when the architecture is different. In
     145that case you will have to adjust the values as needed.
     146
     147For more information, study the CHICKEN source code and/or ask on the CHICKEN
     148mailing lists to understand the implications and difficulties of this deployment
     149method in more detail.
     150
    84151=== Platform specific notes
    85152
  • wiki/man/5/Extensions

    r35525 r35528  
    265265
    266266---
    267 Previous: [[Interface to external functions and variables]]
     267Previous: [[Declarations]]
    268268
    269269Next: [[Extension tools]]
  • wiki/man/5/Interface to external functions and variables

    r35525 r35528  
    2020Previous: [[Included modules]]
    2121
    22 Next: [[Extensions]]
     22Next: [[Declarations]]
  • wiki/man/5/The User's Manual

    r35527 r35528  
    1616* [[Included modules]] : A reference to CHICKEN's core module library
    1717* [[Interface to external functions and variables]] : Accessing C/C++ code and data
     18* [[Declarations]] : Compiler declarations
    1819* [[Extensions]] : Packaging and installing extension libraries
    1920* [[Extension tools]] : {{chicken-[un]install}} and {{chicken-status}}
  • wiki/man/5/Using the compiler

    r35525 r35528  
    1515=== Compiler command line format
    1616
    17  csc FILENAME-OR-OPTION
     17 chicken FILENAME OPTION ...
    1818
    1919{{FILENAME}} is the pathname of the source file that is to
     
    2525; -analyze-only : Stop compilation after first analysis pass.
    2626
    27 ; -block : Enable block-compilation. When this option is specified, the compiler assumes that global variables are not modified outside this compilation-unit.  Specifically, toplevel bindings are not seen by {{eval}} and unused toplevel bindings are removed.
     27; -block : Enable block-compilation. When this option is specified, the compiler assumes that global variables are not modified outside of this compilation-unit.  Specifically, toplevel bindings are not seen by {{eval}} and unused toplevel bindings are removed.
    2828
    2929; -case-insensitive : Enables the reader to read symbols case insensitive. The default is to read case sensitive (in violation of R5RS).  This option registers the {{case-insensitive}} feature identifier.
     
    3737; -debug MODES : Enables one or more compiler debugging modes. {{MODES}} is a string of characters that select debugging information about the compiler that will be printed to standard output. Use {{-debug h}} to see a list of available debugging options.
    3838
    39 ; -debug-level LEVEL : Selects amount of debug-information. {{LEVEL}} should be an integer.
    40 
    41      -debug-level 0             is equivalent to -no-trace -no-lambda-info
    42      -debug-level 1             is equivalent to -no-trace
    43      -debug-level 2             is the default behaviour
    44      -debug-level 3             is equivalent to -debug-info
    45 
    46 ; -disable-interrupts : Equivalent to the {{(disable-interrupts)}} declaration. No interrupt-checks are generated for compiled programs.
     39; -debug-level LEVEL : Selects amount of debug-information. {{LEVEL}} should be an integer, where {{0}} is equivalent to {{-no-trace -no-lambda-info}}, {{1}} is equivalent to {{-no-trace}}, {{2}} is the default behaviour and {{3}} is equivalent to {{-debug-mode}}.
     40
     41; -disable-interrupts : Equivalent to the {{(disable-interrupts)}} declaration. No interrupt-checks are generated for compiled programs, which disables thread context switches in this (and only this) compilation unit.
    4742
    4843; -disable-stack-overflow-checks : Disables detection of stack overflows. This is equivalent to running the compiled executable with the {{-:o}} runtime option.
     
    7065; -feature SYMBOL : Registers {{SYMBOL}} to be a valid feature identifier for {{cond-expand}}. Multiple symbols may be given, if comma-separated.
    7166
    72 ; -fixnum-arithmetic : Equivalent to {{(fixnum-arithmetic)}} declaration. Assume all mathematical operations use small integer arguments.
    73 
    74 ; -heap-size NUMBER : Sets a fixed heap size of the generated executable to {{NUMBER}} bytes. The parameter may be followed by a  {{M}} ({{m}}) or {{K}} ({{k}}) suffix which stand for mega- and kilobytes, respectively.  The default heap size is 5 kilobytes. Note that only half of it is in use at every given time.
     67; -fixnum-arithmetic : Equivalent to the {{(fixnum-arithmetic)}} declaration. Assume all mathematical operations use small integer arguments.
     68
     69; -heap-size NUMBER : Sets a fixed heap size of {{NUMBER}} bytes for the generated executable. The parameter may be followed by a  {{M}} ({{m}}) or {{K}} ({{k}}) suffix which stand for mega- and kilobytes, respectively.  The default heap size is 500 kilobytes. Note that only half of it is in use at every given time. Note also that by default the heap is dynamically resized unless this option is given.
    7570
    7671; -help : Print a summary of available options and the format of the command line parameters and exit the compiler.
    7772
    78 ; -ignore-repository : Do not load any extensions from the repository (treat repository as empty). Also do not consult compiled (only interpreted) import libraries in {{import}} forms.
    79 
    80 ; -include-path PATHNAME : Specifies an additional search path for files included via the {{include}} special form. This option may be given multiple times. If the environment variable {{CHICKEN_INCLUDE_PATH}} is set, it should contain a list of alternative include pathnames separated by {{:}} (unix) or {{;}} (windows).
     73; -ignore-repository : Do not load any extensions from the repository (treat the repository as empty). Also do not consult compiled (only interpreted) import libraries in {{import}} forms.
     74
     75; -include-path PATHNAME : Specifies an additional search path for files included via the {{include}} special form. This option may be given multiple times. If the environment variable {{CHICKEN_INCLUDE_PATH}} is set, it should contain a list of alternative include pathnames separated by {{:}} (UNIX) or {{;}} (Windows).
    8176
    8277; -inline : Enable procedure inlining for known procedures of a size below the threshold (which can be set through the {{-inline-limit}} option).
     
    8681; -inline-limit THRESHOLD : Sets the maximum size of a potentially inlinable procedure. The default threshold is {{20}}.
    8782
    88 ; -keyword-style STYLE : Enables alternative keyword syntax, where {{STYLE}} may be either {{prefix}} (as in Common Lisp, e.g. :keyword), {{suffix}} (as in DSSSL, e.g. keyword:) or {{none}}. Any other value is ignored. The default is {{suffix}}.
     83; -keyword-style STYLE : Enables alternative keyword syntax, where {{STYLE}} may be either {{prefix}} (as in Common Lisp, e.g. :keyword), {{suffix}} (as in DSSSL, e.g. keyword:) or {{none}} (where only the {{#:KEYWORD}} is allowed). Any other value is ignored. The default is {{suffix}}.
    8984
    9085; -keep-shadowed-macros : Do not remove macro definitions with the same name as assigned toplevel variables (the default is to remove the macro definition).
     
    10297; -no-bound-checks : disable bound variable checks
    10398
    104 ; -no-feature SYMBOL : Disables the predefined feature-identifier {{SYMBOL}}. Multiple symbols may be given, if comma-separated.
    105 
    106 ; -no-lambda-info : Don't emit additional information for each {{lambda}} expression (currently the argument-list, after alpha-conversion/renaming).
    107 
    108 ; -no-module-registration : Do not generate module-registration code in the compiled code. This is only needed if you want to use an import library that is generated by other means (manually, for example).
     99; -no-feature SYMBOL : Disables the predefined feature-identifier {{SYMBOL}}. Multiple comma-separated symbols may be given.
     100
     101; -no-lambda-info : Do not emit additional information for each {{lambda}} expression (currently the argument-list, after alpha-conversion/renaming).
     102
     103; -no-module-registration : Do not generate module-registration code in the compiled code. This is needed if you want to use an import library that is generated by other means (manually, for example), or when you do not intend to use modules in the program at runtime (using {{eval}}).
    109104
    110105; -no-parentheses-synonyms : Disables list delimiter synonyms, [..] and {...} for (...).
     
    127122; -optimize-leaf-routines : Enable leaf routine optimization.
    128123
    129 ; -optimize-level LEVEL : Enables certain sets of optimization options. {{LEVEL}} should be an integer.
    130 
    131      -optimize-level 0          is equivalent to -no-usual-integrations -no-compiler-syntax
    132      -optimize-level 1          is equivalent to -optimize-leaf-routines
    133      -optimize-level 2          is equivalent to -optimize-leaf-routines -inline
    134      -optimize-level 3          is equivalent to -optimize-leaf-routines -local -inline -inline-global -specialize
    135      -optimize-level 4          is equivalent to -optimize-leaf-routines -local -inline -inline-global -specialize -unsafe
    136      -optimize-level 5          is equivalent to -optimize-leaf-routines -block -inline -inline-global -specialize -unsafe -disable-interrupts -no-trace -no-lambda-info -clustering -lfa2
    137 
    138 ; -output-file FILENAME : Specifies the pathname of the generated C file. Default is {{FILENAME.c}}.
     124; -optimize-level LEVEL : Enables certain sets of optimization options. {{LEVEL}} should be an integer. Level {{0}} is equivalent to {{-no-usual-integrations -no-compiler-syntax}} (no optimization), level {{1}  is equivalent to {{-optimize-leaf-routines}} (minimal optimization), level {{2}} is equivalent to {{-optimize-leaf-routines -inline}} (enable optimizations that do not break standard compliance, this is the default), level {{3}} is equivalent to {{-optimize-leaf-routines -local -inline -inline-global -specialize}} (maximal optimization, while still "safe"), level {{4}} is equivalent to {{-optimize-leaf-routines -local -inline -inline-global -specialize -unsafe}} (maximal optimization, "unsafe") and any higher level is equivalent to {{-optimize-leaf-routines -block -inline -inline-global -specialize -unsafe -disable-interrupts -no-trace -no-lambda-info -clustering -lfa2}} (all possible optimizations, "unsafe").
     125
     126; -output-file FILENAME : Specifies the pathname of the generated C file. Default is to use the source filename with the extension replaced by {{.c}}.
    139127
    140128; -postlude EXPRESSIONS : Add {{EXPRESSIONS}} after all other toplevel expressions in the compiled file.  This option may be given multiple times. Processing of this option takes place after processing of {{-epilogue}}.
     
    143131
    144132; -profile :
    145 ; -accumulate-profile : Instruments the source code to count procedure calls and execution times. After the program terminates (either via an explicit {{exit}} or implicitly), profiling statistics are written to a file named {{PROFILE.<randomnumber>}}. Each line of the generated file contains a list with the procedure name, the number of calls and the time spent executing it. Use the {{chicken-profile}} program to display the profiling information in a more user-friendly form. Enter {{chicken-profile -help}} at the command line to get a list of available options. The {{-accumulate-profile}} option is similar to {{-profile}}, but the resulting profile information will be appended to any existing {{PROFILE}} file. {{chicken-profile}} will merge and sum up the accumulated timing information, if several entries for the same procedure calls exist. Only profiling information for global procedures will be collected.  See the {{-:p}} option under [[#runtime-options|"Runtime options"]] below for statistical profiling support.
     133; -accumulate-profile : Instruments the source code to count procedure calls and execution times. After the program terminates (either via an explicit {{exit}} or implicitly), profiling statistics are written to a file named {{PROFILE.<randomnumber>}}. Each line of the generated file contains a list with the procedure name, the number of calls and the time spent executing it. Use the {{chicken-profile}} program to display the profiling information in a more user-friendly form. Enter {{chicken-profile -help}} at the command line to get a list of available options. The {{-accumulate-profile}} option is similar to {{-profile}}, but the resulting profile information will be appended to any existing {{PROFILE}} file. {{chicken-profile}} will merge and sum up the accumulated timing information, if several entries for the same procedure calls exist. Only profiling information for global procedures will be collected.  See the {{-:p}} option under [[#Runtime options|"Runtime options"]] below for statistical profiling support.
    146134
    147135; -profile-name FILENAME : Specifies name of the generated profile information (which defaults to {{PROFILE.<randomnumber>}}. Implies {{-profile}}.
     
    149137; -prologue FILENAME : Includes the file named {{FILENAME}} at the start of the compiled source file.  The include-path is not searched. This option may be given multiple times.
    150138
    151 ; -r5rs-syntax : Disables the CHICKEN extensions to R5RS syntax. Does not disable [[Non-standard read syntax|non-standard read syntax]].
    152 
    153 ; -raw : Disables the generation of any implicit code that uses the Scheme libraries (that is all runtime system files besides {{runtime.c}} and {{chicken.h}}).
     139; -r5rs-syntax : Disables the CHICKEN extensions to R5RS syntax. Does not disable non-standard read syntax.
     140
     141; -raw : Disables the generation of any implicit code that uses the Scheme libraries (that is all runtime system files besides {{runtime.c}} and {{chicken.h}}). Use this only when you know what you are doing.
    154142
    155143; -require-extension NAME : Loads the extension {{NAME}} before the compilation process commences. This is identical to adding {{(require-extension NAME)}} at the start of the compiled program. If {{-uses NAME}} is also given on the command line, then any occurrences of {{-require-extension NAME}} are replaced with {{(declare (uses NAME))}}. Multiple names may be given and should be separated by commas.
     
    161149; -static : Link extensions statically, if possible.
    162150
    163 ; -strict-types : Assume that the type of variables is not changed by assignments. This gives more type-information during specialization, but violating this assumption will result in unsafe and incorrectly behaving code.
     151; -strict-types : Assume that the type of variables is not changed by assignments. This gives more type-information during specialization, but violating this assumption will result in unsafe and incorrectly behaving code. Use with care.
    164152
    165153; -consult-types-file FILENAME : load additional type database from {{FILENAME}}. Type-definitions in {{FILENAME}} will override previous type-definitions.
     
    173161; -unsafe : Disable runtime safety checks.
    174162
    175 ; -uses NAME : Use definitions from the library unit {{NAME}}. This is equivalent to {{-prelude "(declare (uses NAME))"}}. Multiple arguments may be given, separated by {{,}}.
     163; -uses NAME : Use definitions from the library unit {{NAME}}. This is equivalent to {{-prelude "(declare (uses NAME))"}}. Multiple arguments may be given, separated by {{,}} (comma).
    176164
    177165; -no-usual-integrations : Specifies that standard procedures and certain internal procedures may be redefined, and can not be inlined. This is equivalent to declaring {{(not usual-integrations)}}.
     
    196184After successful compilation a C source file is generated and can be
    197185compiled with a C compiler. Executables generated with CHICKEN (and the
    198 compiler itself) accept a small set of runtime options:
     186compiler itself) accept a small set of runtime options. These are filtered out
     187by the startup code and will not be contained in the result of
     188{{(command-line-arguments)}}.
    199189
    200190; {{-:?}} : Shows a list of the available runtime options and exits the program.
     
    202192; {{-:aNUMBER}} : Specifies the length of the buffer for recording a trace of the last invoked procedures. Defaults to 16.
    203193
    204 ; {{-:ANUMBER}} : Specifies fixed "temporary stack" size. This is used mostly for {{apply}}. If you supply a zero size (the default), the stack will be dynamically reallocated as needed.
     194; {{-:ANUMBER}} : Specifies fixed ''temporary stack'' size. This is used mostly for {{apply}}. If you supply a zero size (the default), the temorary stack will be dynamically reallocated as needed.
    205195
    206196; {{-:b}} : Enter a read-eval-print-loop when an error is encountered.
    207197
    208 ; {{-:B}} : Sounds a bell (ASCII 7) on every major garbage collection.
     198; {{-:B}} : Sounds a bell (by writing ASCII 7 to stdout) on every major garbage collection.
    209199
    210200; {{-:c}} : Forces console mode. Currently this is only used in the interpreter ({{csi}}) to force output of the {{#;N>}} prompt even if stdin is not a terminal (for example if running in an {{emacs}} buffer under Windows).
     
    216206; {{-:g}} : Prints information about garbage-collection.
    217207
    218 ; {{-:G}} : Force GUI mode (show error messages in dialog box, suitable for platform).
     208; {{-:G}} : Force GUI mode (show error messages in dialog box if running under MacOS X or Windows).
    219209
    220210; {{-:H}} : Before terminating, dump heap usage to stderr.
     
    238228; {{-:PFREQUENCY}} : Same as {{-:p}} but set the sampling frequency in microseconds (default is 10000 microseconds or every 10 milliseconds).
    239229
    240 ; {{-:r}} : Writes trace output to stderr. This option has no effect with in files compiled with the {{-no-trace}} options.
     230; {{-:r}} : Writes trace output to stderr. This option has no effect in files compiled with the {{-no-trace}} options.
    241231
    242232; {{-:sNUMBER}} : Specifies stack size.
    243233
    244234; {{-:tNUMBER}} : Specifies symbol table size.
    245 
    246 ; {{-:w}} : Enables garbage collection of unused symbols. By default unused and unbound symbols are not garbage collected.
    247235
    248236; {{-:x}} : Raises uncaught exceptions of separately spawned threads in primordial thread. By default uncaught exceptions in separate threads are not handled, unless the primordial one explicitly joins them. When warnings are enabled (the default) and {{-:x}} is not given, a warning will be shown, though.
     
    254242
    255243Runtime options may be combined, like {{-:dc}}, but everything following
    256 an argument is ignored. So {{-:wh64m}} is OK, but {{-:h64mw}} will not
    257 enable GC of unused symbols.
    258 
    259 === Examples
    260 
    261 ==== A simple example (with one source file)
    262 
    263 To compile a Scheme program (assuming a UNIX-like environment) consisting of a single source file, perform the following steps.
    264 
    265 ===== Writing your source file
    266 
    267 In this example we will assume your source file is called {{foo.scm}}:
    268 
    269 <enscript highlight=scheme>
    270 ;;; foo.scm
    271 
    272 (define (fac n)
    273   (if (zero? n)
    274       1
    275       (* n (fac (- n 1))) ) )
    276 
    277 (write (fac 10))
    278 (newline)
    279 </enscript>
    280 
    281 ===== Compiling your program
    282 
    283 Compile the file {{foo.scm}}:
    284 
    285  % csc foo.scm
    286 
    287 This will produce the {{foo}} executable:
    288 
    289  % ls
    290  foo  foo.scm
    291 
    292 ===== Running your program
    293 
    294 To run your newly compiled executable use:
    295 
    296  % ./foo
    297  3628800
    298 
    299 
    300 ==== An example with multiple files
    301 
    302 If multiple bodies of Scheme code are to be combined into a single
    303 executable, then we have to compile each file and link the resulting
    304 object files together with the runtime system.
    305 
    306 Let's consider an example where your program consists of multiple source files.
    307 
    308 ===== Writing your source files
    309 
    310 The declarations in these files specify which of the compiled files is the main
    311 module, and which is the library module. An executable can only have
    312 one main module, since a program has only a single entry-point. In this
    313 case {{foo.scm}} is the main module, because it doesn't have a
    314 {{unit}} declaration:
    315 
    316 <enscript highlight=scheme>
    317 ;;; foo.scm
    318 
    319 ; The declaration marks this source file as dependant on the symbols provided
    320 ; by the bar unit:
    321 (declare (uses bar))
    322 
    323 (write (fac 10)) (newline)
    324 </enscript>
    325 
    326 {{bar.scm}} will be our library:
    327 
    328 <enscript highlight=scheme>
    329 ;;; bar.scm
    330 
    331 ; The declaration marks this source file as the bar unit.  The names of the
    332 ; units and your files don't need to match.
    333 (declare (unit bar))
    334 
    335 (define (fac n)
    336   (if (zero? n)
    337       1
    338       (* n (fac (- n 1))) ) )
    339 </enscript>
    340 
    341 ===== Compiling and running your program
    342 
    343 You should compile your two files with the following commands:
    344 
    345  % csc -c bar.scm
    346  % csc -c foo.scm
    347 
    348 That should produce two files, {{bar.o}} and {{foo.o}}.
    349 They contain the code from your source files in compiled form.
    350 
    351 To link your compiled files use the following command:
    352 
    353  % csc foo.o bar.o -o foo
    354 
    355 This should produce the {{foo}} executable, which you can run just as in the previous example.
    356 At this point you can also erase the {{*.o}} files.
    357 
    358 You could avoid one step and link the two files just as {{foo.scm}} is compiled:
    359 
    360  % csc -c bar.scm
    361  % csc foo.scm bar.o -o foo
    362 
    363 Note that if you want to distribute your program, you might want it to
    364 follow the GNU Coding Standards.  One relatively easy way to achieve
    365 this is to use Autoconf and Automake, two tools made for this specific
    366 purpose.
     244an argument is ignored. So {{-:oh64m}} is OK, but {{-:h64mo}} will not
     245disable stack overflow checks.
    367246
    368247=== Extending the compiler
     
    374253{{user-preprocessor-pass}}, {{user-pass}} and {{user-post-analysis-pass}}
    375254can be set to procedures that are called to perform certain compilation
    376 passes instead of the usual processing (for more information about
    377 parameters see [[Supported language]]).
     255passes in addition to the usual processing.
    378256
    379257These parameters are provided by the {{(chicken compiler user-pass)}}
     
    404282seen by {{user-preprocessor-pass}}, but are seen by {{user-pass}}.
    405283
    406 === Distributing compiled C files
    407 
    408 It is relatively easy to create distributions of Scheme projects that
    409 have been compiled to C.  The runtime system of CHICKEN consists of only
    410 two handcoded C files ({{runtime.c}} and {{chicken.h}}), plus the files
    411 {{chicken-config.h}} and {{buildtag.h}}, which are generated by the
    412 build process. All other modules of the runtime system and the extension
    413 libraries are just compiled Scheme code. The following example shows a
    414 minimal application, which should run without changes on most operating
    415 systems, like Windows, Linux or FreeBSD (note however that static
    416 binaries are not supported on Mac OS X).
    417 
    418 Take the following "Hello World" program:
    419 
    420 <enscript highlight=scheme>
    421 ; hello.scm
    422 
    423 (print "Hello, world!")
    424 </enscript>
    425 
    426   % csc -t hello.scm -optimize-level 3 -output-file hello.c
    427 
    428 Compiled to C, we get {{hello.c}}. We need the files {{chicken.h}},
    429 {{chicken-config.h}}, {{buildtag.h}} and {{runtime.c}}, which contain
    430 the basic runtime system, plus the library files {{build-version.c}},
    431 {{chicken-syntax.c}}, {{eval.c}}, {{expand.c}}, {{internal.c}},
    432 {{library.c}} and {{modules.c}}, which contain the same functionality as
    433 the library that is linked into plain CHICKEN-compiled applications:
    434 
    435   % cd /tmp
    436   % echo '(print "Hello World.")' > hello.scm
    437   % csc -t hello.scm
    438   % cp $CHICKEN_BUILD/build-version.c .
    439   % cp $CHICKEN_BUILD/chicken-syntax.c .
    440   % cp $CHICKEN_BUILD/eval.c .
    441   % cp $CHICKEN_BUILD/expand.c .
    442   % cp $CHICKEN_BUILD/internal.c .
    443   % cp $CHICKEN_BUILD/library.c .
    444   % cp $CHICKEN_BUILD/modules.c .
    445   % cp $CHICKEN_BUILD/runtime.c .
    446   % cp $CHICKEN_BUILD/chicken.h .
    447   % cp $CHICKEN_BUILD/chicken-config.h .
    448   % cp $CHICKEN_BUILD/buildtag.h .
    449   % gcc -static -Os -fomit-frame-pointer -DHAVE_CHICKEN_CONFIG_H hello.c \
    450     build-version.c eval.c expand.c internal.c library.c modules.c runtime.c \
    451     -o hello -lm
    452 
    453 Once we have all the files together, we can create a tarball:
    454 
    455  % tar cf hello.tar hello.c build-version.c chicken-syntax.c eval.c \
    456    expand.c internal.c library.c modules.c runtime.c chicken.h \
    457    chicken-config.h buildtag.h
    458  % gzip hello.tar
    459 
    460 This is naturally rather simplistic. Things like enabling dynamic
    461 loading and selecting supported features of the host system would need
    462 more configuration- and build-time support. All this can be addressed
    463 using more elaborate build-scripts, makefiles or by using
    464 autoconf/automake.
    465 
    466 The {{chicken-config.h}} file may contain incorrect settings for your
    467 deployment target. Especially when the architecture is different. In
    468 that case you will have to adjust the values as needed.
    469 
    470 Note that the size of the application can still be reduced by removing
    471 any of the C files besides {{build-version.c}}, {{library.c}}, and
    472 {{runtime.c}}, and compiling {{hello.scm}} with the {{-explicit-use}}
    473 option.
    474 
    475 For more information, study the CHICKEN source code and/or ask on the CHICKEN
    476 mailing list.
    477 
    478284---
    479285Previous: [[Using the interpreter]]
  • wiki/man/5/Using the interpreter

    r35525 r35528  
    2727The parameter {{command-line-arguments}} is set to a list of the
    2828parameters that were passed to the Scheme script.  Scripts can be compiled
    29 to standalone executables (don't forget to declare used library units).
     29to standalone executables.
    3030
    3131CHICKEN supports writing shell scripts in Scheme for other platforms as well,
     
    132132
    133133You can define your own toplevel commands using the {{toplevel-command}}
    134 procedure:
     134procedure (see [[Module (chicken csi)]]).
    135135
    136136
     
    189189=== History access
    190190
    191 The interpreter toplevel accepts the special object {{#[INDEX]}} which
     191The interpreter toplevel accepts the special object {{#INDEX}} which
    192192returns the result of entry number {{INDEX}} in the history list. If
    193193the expression for that entry resulted in multiple values, the first
     
    195195{{INDEX}} is given (and if a whitespace or closing paranthesis
    196196character follows the {{#}}, then the result of the last expression is
    197 returned.  Note that the value returned is implicitly quoted.
    198 
    199 === Auto-completion and edition
     197returned.  Note that the value that {{#INDEX}} stands for is an expression,
     198not a literal, and so is implicitly quoted, so
     199
     200 #;1> 123
     201 123
     202 #;2> '(1 2 #)
     203
     204will not return the result you expected.
     205
     206=== Auto-completion and editing
    200207
    201208On platforms that support it, it is possible to get auto-completion of
     
    241248; -h  -help : Write a summary of the available command line options to standard output and exit.
    242249
    243 ; -I  -include-path PATHNAME : Specifies an alternative search-path for files included via the {{include}} special form. This option may be given multiple times. If the environment variable {{CHICKEN_INCLUDE_PATH}} is set, it should contain a list of alternative include pathnames separated by {{;}}.
     250; -I  -include-path PATHNAME : Specifies an alternative search-path for files included via the {{include}} special form. This option may be given multiple times. If the environment variable {{CHICKEN_INCLUDE_PATH}} is set, it should contain a list of alternative include pathnames separated by {{:}} (UNIX) or {{;}} (Windows).
    244251
    245252; -K  -keyword-style STYLE : Enables alternative keyword syntax, where {{STYLE}} may be either {{prefix}} (as in Common Lisp) or {{suffix}} (as in DSSSL). Any other value is ignored.
     
    255262; -q  -quiet : Do not print a startup message. Also disables generation of call-trace information for interpreted code.
    256263
    257 ;     -r5rs-syntax : Disables the CHICKEN extensions to R5RS syntax. Does not disable [[Non-standard read syntax|non-standard read syntax]].
     264;     -r5rs-syntax : Disables the CHICKEN extensions to R5RS syntax. Does not disable non-standard read syntax.
    258265
    259266; -s  -script PATHNAME : This is equivalent to {{-batch -quiet -no-init PATHNAME}}. Arguments following {{PATHNAME}} are available by using  {{command-line-arguments}} and are not processed as interpreter options. Extra options in the environment variable {{CSI_OPTIONS}} are ignored.
Note: See TracChangeset for help on using the changeset viewer.