Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
---
``` ;; fib.scm (define (square x) (expt x 2)) ```
``` % gsc -c fib ```
produces a fib.c file. Then:
``` % clang --target=wasm32 -O1 -Wno-deprecated-declarations -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common -D___SINGLE_HOST -D___DONT_HAVE_MATH_H -D___DONT_HAVE_SETJMP_H -D___DONT_HAVE_SIGNAL_H -D___DONT_HAVE_WCHAR_H -I"/opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include" fib.c ```
Gives this error: ``` In file included from fib.c:36: /opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include/gambit.h:8012:5: error: unknown type name 'jmp_buf' jmp_buf buf; ^ 1 error generated. make: *** [fib.o] Error 1 ```
Afficher les réponses par date
Mar 18, 2023 15:15:38 Winston W winston@nitidbit.com:
Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
Google has released an experimental Scheme to WASM compiler called Schism:
https://github.com/schism-lang/schism
It's not feature-complete, though.
If you like, feel free to pester Marc to add a WASM back end to Gambit, or better yet, start contributing one yourself. Such a feature will be much appreciated.
Cheers,
--Jeff
Chibi Scheme and Spock both run in the browser. You can build Chibi Scheme with a WASM target; Spock is written in JavaScript.
On Sat, Mar 18, 2023 at 3:15 PM Winston W winston@nitidbit.com wrote:
Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
;; fib.scm (define (square x) (expt x 2))
% gsc -c fib
produces a fib.c file. Then:
% clang --target=wasm32 -O1 -Wno-deprecated-declarations -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common -D___SINGLE_HOST -D___DONT_HAVE_MATH_H -D___DONT_HAVE_SETJMP_H -D___DONT_HAVE_SIGNAL_H -D___DONT_HAVE_WCHAR_H -I"/opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include" fib.c
Gives this error:
In file included from fib.c:36: /opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include/gambit.h:8012:5: error: unknown type name 'jmp_buf' jmp_buf buf; ^ 1 error generated. make: *** [fib.o] Error 1
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
Thanks to all the responses in this thread for your advice—John Cowan, Faré, Amirouche.
I'll investigate Chibi Scheme.
—Winston
On Mar 18, 2023, at 12:26 PM, John Cowan cowan@ccil.org wrote:
Chibi Scheme and Spock both run in the browser. You can build Chibi Scheme with a WASM target; Spock is written in JavaScript.
On Sat, Mar 18, 2023 at 3:15 PM Winston W winston@nitidbit.com wrote: Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
;; fib.scm (define (square x) (expt x 2))
% gsc -c fib
produces a fib.c file. Then:
% clang --target=wasm32 -O1 -Wno-deprecated-declarations -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common -D___SINGLE_HOST -D___DONT_HAVE_MATH_H -D___DONT_HAVE_SETJMP_H -D___DONT_HAVE_SIGNAL_H -D___DONT_HAVE_WCHAR_H -I"/opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include" fib.c
Gives this error:
In file included from fib.c:36: /opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include/gambit.h:8012:5: error: unknown type name 'jmp_buf' jmp_buf buf; ^ 1 error generated. make: *** [fib.o] Error 1
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
In the future, it will be possible to host standalone WASM executables in the "cloud" like it is currently possible to host Docker containers. You won't have to rent a Linux server and run your own WASM runtime on Linux; the host will do that for you.
Microsoft Azure has a preview of this, but I haven't tried it: https://learn.microsoft.com/en-us/azure/aks/use-wasi-node-pools
Hello Winston,
Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
Gambit has a JavaScript target, here is a wirlwind tour:
;# cat `which gambit2js` #!/bin/sh podman run -v $(pwd):/mnt --rm -it docker.io/schemers/gambit:head gsc -:r7rs -target js -exe /mnt/$1 tail -n +2 $(basename $1 .scm) > "$(basename $1 .scm).js" rm -f $(basename $1 .scm)
;# echo '(display "hello from gambit js\n")' > main.scm
;# gambit2js main.scm && nodejs main.js hello from gambit js
;#
You can replace podman with docker.
I did prototypes with biwascheme, spock, schism, chibi, and gambit. The easiest to get started is biwascheme. The most promising is Gambit.
By the way, even if you target web assembly or host gambit compiler, and interpreter in wasm, you still need to write some javascript to interop with the browser.
On Sat, Mar 18, 2023 at 12:15:21PM -0700, Winston W wrote:
Hi Gambit List—
I'm searching for a way to write Lisp and have it run on a web browser as WASM, i.e. avoiding JS. I was hoping Gambit Scheme might be the key, by compiling Lisp —> (Gambit compiler) —> C —> (Clang) —> wasm. But I'm encountering problems. My current issue is the 'gambit.h' file checks for lots of things including `setjmp` which doesn't exist in WASM. Below is my test situation. Does anybody think this endeavor of compiling Gambit -> wasm can work? Or are there any other ways to write Lisp and execute it as Wasm?
One problem with cheme in WasM is proper tail-recusrion. It is intended to be implemented in WASM, but it isn't in the standard because not enough implementations have implemented itm though at lest one has.
-- hendrik
;; fib.scm (define (square x) (expt x 2))
% gsc -c fib
produces a fib.c file. Then:
% clang --target=wasm32 -O1 -Wno-deprecated-declarations -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common -D___SINGLE_HOST -D___DONT_HAVE_MATH_H -D___DONT_HAVE_SETJMP_H -D___DONT_HAVE_SIGNAL_H -D___DONT_HAVE_WCHAR_H -I"/opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include" fib.c
Gives this error:
In file included from fib.c:36: /opt/homebrew/Cellar/gambit-scheme/4.9.3_2/v4.9.3/include/gambit.h:8012:5: error: unknown type name 'jmp_buf' jmp_buf buf; ^ 1 error generated. make: *** [fib.o] Error 1
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
Andy Wingo recently gave a talk related to Guile Scheme on WASM.
https://wingolog.org/archives/2023/03/20/a-world-to-win-webassembly-for-the-...