On Mon, Jun 02, 2008 at 11:31:59PM -0400, Andrew I. Schein wrote:
Can someone provide pointers on the tool that generates the C or more generally about where to start in looking at the source?
Gambit is the tool that generates the C. It compiles from Scheme to C, and the C is then compiled and linked like any other C file. Gambit is written in itself. To avoid problems of circularity the C form of the system is distributed along with the Scheme form, and is used to install the initial copy of the compiler. After that you don't have to worry about the Gambit-generated C files very much.
The C that Gambit generates needs a runtime environment, with a garbage collector and support for first-class continuations and so on. The normal- looking C files you found implement a lot of the runtime environment, including OS-specific glue. They weren't compiled from Scheme. Also some hand-written header files define macros that expand the Gambit-generated code and linkage information into real C. As a general rule, look for files in the gsc, gsi, lib, and include directories that don't start with an underscore.
Gambit has a foreign function interface, so you can combine Scheme and C files in the same program. I'm not sure how much of the system is written using the FFI.
Gambit works with Scheme files containing code (no # in their names) and interfaces and type definitions (# in their names). Gambit itself is organized that way. The system Scheme files' names start with an underscore, so the generated C file names also start with one.
Other organizational details: Inside Scheme files and REPL input, the # character has several uses:
- the standard Scheme syntaxes - multiline comments - #!key #!optional #!rest used in function argument lists - #! at the beginning of "shell scripts" written in Scheme - the namespace feature - in the REPL, the result-history feature
And in C, the runtime environment uses many identifiers starting with three underscores. That allows Gambit's identifiers to coexist with others.
For documentation, the Gambit wiki at http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page is a good place to start. You can get the manual and the mailing list archives. Try these sections in the manual:
1.1 directory organization after installing 4 command-line switches handled in the first phase of starting the Gambit runtime environment (see lib/main.c) 2 and 3 command-line switches handled by gsc and gsi, in a second phase (see gsi/main.scm which is used by gsi/_gsi.scm and gsc/_gsc.scm) 3.4 about linkage information, working with C and object files 16 and 17 the tidy Scheme view of the runtime support code (see most of the files in lib/) 19 the foreign function interface, if you're curious
and these wiki pages:
Configure script options in case you're still installing Gambit Make targets ditto Documentation Internal Documentation skeleton list of things not in the manual Namespaces what all the ##s in the sources mean
The mailing list archives need a better index -- I don't have any ready advice about searching them.
Finally, I can send you an Emacs TAGS file for the lib/ directory. It's from Gambit 4.2.6 but will probably work with 4.2.8.
Let me know if you have more questions.
-- Derek