gerbil-loader
v0.0.0
Published
A loader from Gerbil Scheme to Javascript
Downloads
2
Readme
Gerbil Loader: Use gxc
and gsc
load Gerbil to JavaScript
The gerbil-loader
package makes it easy to load a gerbil file into a
JavaScript runtime.
The gerbil-scheme
package is based off of Gerbil, a scheme written in itself
that compiles to Gambit Scheme.
The gerbil-scheme
UMD library allows many different uses of that runtime and will at some point allow loading of gerbil modules.
Installation
Easy! I choose yarn
, but npm
also works.
yarn add gerbil-loader --dev
yarn add gerbil-scheme
Documentation
For details see the repo, man! https://github.com/drewc/gxjs
Usage
Let’s have a scheme
file that uses a few js
features.
Here is gambit-scheme-usage.ss
.
(import :js)
(js#declaration "console.log('started gerbil scheme!')")
(def (this-is-gerbil!! (val 42))
(js#statement "console.log('This is GxJS!', (@1@), (@2@))"
val
(js#expression "{ foo: 'bar' };")))
(js#statement "console.log('finished gerbil scheme init');
module.exports = RTS.scm2host(@1@);" this-is-gerbil!!)
To load an .ss
file, gerbil-loader
is the easy way. The options are the same
as gxjs-loader
.
Now for a JavaScript file, gerbil-scheme-usage.js
. We’ll make this a
CommonJS module.
We do not actually need to require('gerbil-scheme')
here at all and we export
the RTS
is exported pretty much so we can see just that. Just wait :)
const RTS = require('gerbil-scheme');
const thisIsGerbil = require('gerbil-loader!./gerbil-scheme-usage.ss');
thisIsGerbil('*');
module.exports = RTS;
That outputs this to the console. As you can see the function automagically converts the string into a Gerbil/Gambit string, but this is the JavaScript output.
started gerbil scheme!
finished gerbil scheme init
This is GxJS! { codes: [ 42 ] } { foo: 'bar' }
By default gerbil-loader
automagically requires gerbil-scheme
by prepending const RTS = require('gerbil-scheme');
to the top of the “file”.
The RTS.glo
is the symbol table.
(import :js)
(js#declaration #<<EOF
console.log('Ok, auto RTS!', Object.keys(RTS.glo).length)
module.exports = RTS;
EOF
)
Now we’ll use that in a js
module. This time around es6.
import RTS from './gerbil-scheme-usage.js'
import sameRTS from 'gerbil-loader!./gerbil-scheme-auto.ss';
console.log('Same Runtime?', RTS === sameRTS);
That outputs the following.
started gerbil scheme!
finished gerbil scheme init
This is GxJS! { codes: [ 42 ] } { foo: 'bar' }
Ok, auto RTS! 165
Same Runtime? true
So we just need to use gerbil-loader
and have gerbil-scheme
as a dependency
and there you go.
Support
Go to https://github.com/drewc/gxjs/issues or contact the author.