[gambit-list] Status of compiling R7RS programs

Marc Feeley feeley at iro.umontreal.ca
Mon Nov 11 23:50:33 EST 2019


> On Nov 11, 2019, at 5:58 PM, Marc Feeley <feeley at iro.umontreal.ca> wrote:
> 
> Sorry for the long explanation.  The situation will improve when the compiler can analyze the module dependencies at compile time and include in the executable all of the required modules.

I forgot to mention that you can combine all of the modules in a single executable, but here too the steps are a little contrived currently (because the module-ref has to be specified separately for each compiled module for no good reason):

% gsc-script -c -module-ref srfi/175 srfi/175.sld
% gsc-script -c -module-ref srfi/examples . srfi/examples.scm
% gsc-script -exe -nopreload srfi/175.c srfi/examples.c
% srfi/examples
(hex-digit #\a) => 10
(hex-digit #\0) => 0
(hex-digit #\9) => 9
...

The executable will contain the following registered modules (obtained by adding a trace at the end of srfi/examples.scm):

(#(srfi/examples 2 #(#(srfi/examples) #(srfi/175) () 0 #<procedure #2 srfi/examples#> #<foreign #3 0x10400c3b0>))
 #(srfi/175 2 #(#(srfi/175) #() () 0 #<procedure #4 srfi/175#> #<foreign #5 0x104008bf0>))
 #(_repl 2 #(#(_repl) #() () 1 #<procedure #6 _repl#> #<foreign #7 0x10416a740>))
 #(_thread 2 #(#(_thread) #() () 1 #<procedure #8 _thread#> #<foreign #9 0x10415ae60>))
 #(_nonstd 2 #(#(_nonstd) #() () 1 #<procedure #10 _nonstd#> #<foreign #11 0x104145f40>))
 #(_io 2 #(#(_io) #() () 1 #<procedure #12 _io#> #<foreign #13 0x10410c320>))
 #(_module 2 #(#(_module) #() () 1 #<procedure #14 _module#> #<foreign #15 0x1040e7500>))
 #(_eval 2 #(#(_eval) #() () 1 #<procedure #16 _eval#> #<foreign #17 0x1040c8aa0>))
 #(_std 2 #(#(_std) #() () 1 #<procedure #18 _std#> #<foreign #19 0x104070dc0>))
 #(_num 2 #(#(_num) #() () 1 #<procedure #20 _num#> #<foreign #21 0x104033f00>))
 #(_system 2 #(#(_system) #() () 1 #<procedure #22 _system#> #<foreign #23 0x10401fe00>))
 #(_kernel 2 #(#(_kernel) #() () 1 #<procedure #24 _kernel#> #<foreign #25 0x104011d00>)))

The next step in the evolution of the compiler is to allow this simpler invocation to build the executable:

% gsc-script -exe . srfi/examples

The compiler will first get the source code of the srfi/examples module, then it sees that it does an (import (srfi 175)) so it then gets the source code of module srfi/175, which does not contain dependencies on any other module.  So the compiler needs the files srfi/175.c and srfi/examples.c, which it can generate from the Scheme source code, or reuse previously generated .c files if they are not stale.  In general figuring out when a .c file is stale is not easy (when module dependencies don’t use explicit versioning).  To simplify, no staleness check could be performed in normal use and the compiler could have an option to force rebuilding all the required .c files from the .scm files.

Marc





More information about the Gambit-list mailing list