[gambit-list] Separate compilation targeting JavaScript

Marc Feeley feeley at iro.umontreal.ca
Sat Jan 2 19:35:57 EST 2016


First of all happy new year to you and all the other members of this list!

Yes separate compilation is supported by the linker (the -link option to gsc).  Here is an example.  Please do a “git pull;make from-scratch;make install” to use the latest Gambit.

First you need to build the JS version of the Gambit library (the file lib/_gambit.js).  So from the Gambit source directory do:

% cd lib;rm _gambit.js;make _gambit.js;cd ..
../gsc/gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(##include \"header.scm\")" -o _gambit.js ../lib/_univlib.scm

Ideally the Gambit library should be copied to the Gambit installation directory in the lib subdirectory, but it is not essential because you can specify the Gambit library to the linker with the “-l <path>” option (see below).

Then separately compile your Scheme files to JS.  Here I use two files “a.scm” and “b.scm”:

% cat a.scm
(println "a.scm loaded")
(define (f x) (println x))
% cat b.scm
(println "b.scm loaded")
(f "hello world!")
% gsc -target js -c a.scm
% gsc -target js -c b.scm

Now link the files with the Gambit library to generate the link file b_.js :

% gsc -link -l lib/_gambit.js a.js b.js

And finally run the code by loading the link file, the Gambit library, and the compiled files:

% d8 b_.js lib/_gambit.js a.js b.js
a.scm loaded
b.scm loaded
hello world!

Note that the link file must be loaded first, but the other files can be loaded in any order:

% d8 b_.js b.js lib/_gambit.js a.js
a.scm loaded
b.scm loaded
hello world!

Currently there is no support for dynamically loading compiled files (i.e. the “load” procedure) but that’s something that could be added fairly easily (the hardest part is finding a portable way to do this across the supported target languages… even for JS this will vary between target environments, i.e. node.js vs browser).

Marc

> On Dec 31, 2015, at 9:49 PM, Blake McBride <blake at mcbride.name> wrote:
> 
> Any progress on separate compilation for a JavaScript target?  (I am interested in using it for a large project that can't be done without separate compilation ability - 450+ screens).
> 
> Thanks.
> 
> Blake McBride
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list