This page starts with a few examples to introduce the problem of module generation, and to show the spirit of the solution in the Ravi system. There is an enormous amount of technical problems related to module generation - these are handled piece by piece.
Command line is one of the following ravitool --generate options source_files ravi -mod r-ig options source_files source-files either is a single .ph file, or a (possibly empty) list of header files. Options are the following:
Preprocessor defaults: when the source file is a .ph file, the preprocessor is not active. When the source file(s) are header files, the preprocessor is active. The preprocessor symbol RAVI_INTERFACE always is defined during module generation.
This example shows how to extend the shell - the Scheme interpreter - with functions written in C. Globally our goal is the following. Our C-code is composed of a header file essai1.h and an implementation file essai1.cc. The code implements just one function: ilog2. We want to be able to use this function in the shell. Header file
Commands:
ravitool --generate -o modessai1.cc -i essai1.cc essai1.h
The first of these commands generates the file modessai1.cc which is then compiled and link-edited to produce the file modessai1.so. The commands are emitted via the command ravitool which in turn calls the C++ compiler with the appropriate options. Use in the shell (C-syntax)The file modessai1.so is a shared object file which can be dynamically loaded into the Ravi interpreter:
Use in the shell (Scheme-syntax)
As can be seen in this example, the classical compile-link cycle is replaced here by a cycle generate-compile-link. It is useful to have some understanding of the generated file, to understand the difficulties to come. Include source files Generated function Sc_ilog2: argument check, argument conversion, function call, result conversion. Initialization code, defines symbol ilo2 in the shell.
The above procedure generate-compile-link-loadworks for C and C++ code, in the case where no particular difficulties arise. You can look at a few more examples to realize how powerful the method is. Interfacing a library Now let's come to the difficulties. memory management preprocessor commands C++ syntax templates shell interface miscellaneous information: names |