Next: flonum format, Previous: parser logic, Up: Top [Index]
The library (vicare gcc) is installed along with
Vicare; it implements a toy interface to gcc, the
GNU C Compiler. Its purpose is to build, at runtime, a C language
shared library from possibly dynamically constructed C code; then load
the library and access a C function as FFI callout.
(vicare gcc) must be considered as a toy to demonstrate the
features of Vicare; it is installed only if the POSIX,
GNU C library and Libffi APIs are enabled at package configuration
time.
The following is an example of function to increment an integer:
#!r6rs
(import (vicare)
(prefix (vicare gcc) gcc.))
(gcc.initialise "/usr/local/bin/gcc" "/home/marco/var/tmp/")
(gcc.define-c-function
signed-int incr (signed-int)
"#include <stdio.h>
int incr (int a) {
return 1+a;
}")
(incr 1) ⇒ 2
the code creates a shared library libincr.so in a subdirectory of
the given initialisation directory, then load it and access the symbol
incr.
(vicare gcc) depends upon the following libraries:
(vicare ffi) (vicare posix) (vicare glibc) (vicare platform constants) (vicare language-extensions syntaxes)
Initialise the library. gcc must be the string full filename of the GCC executable. tmpdir must be the string pathname of an existing directory on a partition with executable permissions; it is used to create temporary files, including the shared libraries.
Temporary files go in a subdirectory of tmpdir; it is the responsibility of the system administrator to clean up regularly such subdirectories.
Define a new Scheme function wrapping a C function from a shared library. ?name must be an identifier representing the name of the function.
?retval must be a symbol selecting the type of the return value; ?args must be a list of symbols selecting the types of the arguments; (vicare-scheme)Specifying native types for details.
?code must be a Scheme string representing the C code to be compiled.
References a list of string. Base options for the compiler, it is
initialised to ("-c").
References a list of string. Base options for the linker, it is
initialised to ("-pipe" "-shared" "-fPIC").
References a list of string. Additional options for the compiler, it is
initialised to ("-O2").
References a list of string. Additional options for the linker, it is initialised to nil.
Next: flonum format, Previous: parser logic, Up: Top [Index]