Skip to content

Instantly share code, notes, and snippets.

@bentxt
Last active June 17, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentxt/ff4a4ef8e3ee13223613091a052aa641 to your computer and use it in GitHub Desktop.
Save bentxt/ff4a4ef8e3ee13223613091a052aa641 to your computer and use it in GitHub Desktop.
Compile scheme to javascript with Gambit and a minimal runtime library
# Compile scheme to javascript with Gambit and a minimal runtime library
# ======================================================================
#
# This example was posted by Marc Feeley in the Gitter Chat: https://gitter.im/gambit/gambit?at=62ac8949568c2c30d3d0b355
#
gsc -target js -c minimal-lib.scm
gsc -target js -l minimal-lib -exe minimal-app.scm
./minimal-app
# 2022-06-17T13:59:21.496Z
(declare (extended-bindings) (not safe))
(define (show str)
(##inline-host-statement "console.log(@scm2host@(@1@));" str))
(define (date)
(##inline-host-expression "@host2scm@(new Date())"))
(define (##run-each-module)
(let ((mods (##vector-ref ##program-descr 0)))
(let loop ((i 1)) ;; start at module after the current one
(if (##fx< i (##vector-length mods))
(let ((mod (##vector-ref mods i)))
((##vector-ref mod 4)) ;; call module's init procedure
(loop (##fx+ i 1)))))))
(##run-each-module) ;; run each module (after the current one)
@bentxt
Copy link
Author

bentxt commented Jun 17, 2022

This example was posted by Marc Feeley in the Gitter Chat: https://gitter.im/gambit/gambit?at=62ac8949568c2c30d3d0b355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment