Last active
June 17, 2022 14:16
-
-
Save bentxt/ff4a4ef8e3ee13223613091a052aa641 to your computer and use it in GitHub Desktop.
Compile scheme to javascript with Gambit and a minimal runtime library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(show (date)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example was posted by Marc Feeley in the Gitter Chat: https://gitter.im/gambit/gambit?at=62ac8949568c2c30d3d0b355