Hi -
I recently downloaded the source for gambit v4.2.8 with the idea of looking at how it fits together. I am a little bit baffled... there are quite a few (~33) files with a "_" prefix that seem to be generated C code as well as 9 normal looking C files.
Can someone provide pointers on the tool that generates the C or more generally about where to start in looking at the source?
Thanks,
Andy
Afficher les réponses par date
Andrew I. Schein wrote:
Hi -
I recently downloaded the source for gambit v4.2.8 with the idea of looking at how it fits together. I am a little bit baffled... there are quite a few (~33) files with a "_" prefix that seem to be generated C code as well as 9 normal looking C files.
Can someone provide pointers on the tool that generates the C
The tool is the Gambit compiler, gsc; when bootstrapping (make bootstrap), a gsc binary is generated and placed as "gsc-comp" binary in the toplevel directory of the sources.
or more generally about where to start in looking at the source?
For those autogenerated C files, there is a corresponding .scm file from which it has been compiled. Look at the .scm file.
Check the wiki for a few insights into the system, as well as a few papers from Marc (check his homepage and/or the mailing list archives, for example "Paper on the compiler"; there's a search form for the mailing list on http://scheme.mine.nu/gambit/). You should try to get a general understanding of Gambit, first, like how namespaces are being handled, what define-type does (it's the same as define-structure, but not all features which are being used by the Gambit sources are documented in the manual).
Christian.
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