Is there any documentation on compiling to javascript, or is it mostly in the mailing list archives? After some scrounging, I was finally able to figure out how to compile and get a simple (println (fib 5)) working:
$ cd gambit/lib $ gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(##include "header.scm")" -o _gambit.js ../lib/_univlib.scm
$ gsc -warnings -target js code.scm $ gsc -warnings -link -l _gambit.js code.js $ cat code_.js _gambit.js code.js > p.js $ node p.js
1) Is that mostly correct? I take it it is still a WIP because I couldn't find documentation.
2) What if I want to use the Python backend? I tried swapping in all of the targets with -target python but then get this error: $ python2 p.py Traceback (most recent call last): File "p.py", line 26310, in <module> g_bb1_serial_2d_number_2d__3e_object.name = g_cst1727___gambit NameError: global name 'g_cst1727___gambit' is not defined
3) Is there a concise example of #inline-host-expression (-statement & -declaration) to be able to have scheme call javascript and vice versa? Same with python? I'm not sure what is correct from my reading of the mailing archive.
Thanks, -Jon
Afficher les réponses par date
Yes that is mostly correct. However I would recommend the following commands:
for JavaScript:
$ cd lib $ make _gambit.js $ cd .. $ gsc/gsc -:=. -warnings -target js code.scm $ gsc/gsc -:=. -warnings -target js -link -l lib/_gambit.js code.js $ cat code_.js code.js lib/_gambit.js > p.js $ node p.js
for Python:
$ cd lib $ make _gambit.py $ cd .. $ gsc/gsc -:=. -warnings -target python code.scm $ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.py $ cat code_.py code.py lib/_gambit.py > p.py $ python p.py
Note that there was a small ordering problem in the generated code (now fixed) that prevented the Python code to run properly.
The universal backend is a WIP but close to a “final product”. Remaining on the TODO:
1) changes to the Gambit library (lib/*.scm) and the runtime system to support more of the Gambit system features, in particular non-blocking I/O which is needed to support Gambit’s green threads 2) integration to the main installation process (to build and install _gambit.js, _gambit.py, etc in the Gambit installation directory) 3) documentation (!)
The universal backend is definitely usable without #1 (some users have built commercial products with it) as long as the application uses ##inline-host-* to interface with hand written code to do the user-interface or I/O.
Here is a simple example for using ##inline-host-* in JavaScript:
(declare (extended-bindings))
(##inline-host-declaration "
function rand(n) { return Math.floor(n * Math.random()); }
")
(define (rand n) (+ 1 (##inline-host-expression "g_host2scm(rand(g_scm2host(@1@)))" n)))
(println (rand 6)) (println (rand 6)) (println (rand 6)) (println (rand 6))
(##inline-host-statement "console.log(@1@);" 123) (##inline-host-statement "console.log(@1@);" "hello") (##inline-host-statement "console.log(@1@);" 'world) (##inline-host-statement "console.log(@1@);" (cons 11 22)) (##inline-host-statement "console.log(@1@);" (vector 11 22 33)) (##inline-host-statement "console.log(@1@);" rand)
Hope that helps!
Marc
On Aug 14, 2016, at 12:23 AM, Jon Woodring woodring.jon@gmail.com wrote:
Is there any documentation on compiling to javascript, or is it mostly in the mailing list archives? After some scrounging, I was finally able to figure out how to compile and get a simple (println (fib 5)) working:
$ cd gambit/lib $ gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(##include "header.scm")" -o _gambit.js ../lib/_univlib.scm
$ gsc -warnings -target js code.scm $ gsc -warnings -link -l _gambit.js code.js $ cat code_.js _gambit.js code.js > p.js $ node p.js
Is that mostly correct? I take it it is still a WIP because I couldn't find documentation.
What if I want to use the Python backend? I tried swapping in all of the targets with -target python but then get this error:
$ python2 p.py Traceback (most recent call last): File "p.py", line 26310, in <module> g_bb1_serial_2d_number_2d__3e_object.name = g_cst1727___gambit NameError: global name 'g_cst1727___gambit' is not defined
- Is there a concise example of #inline-host-expression (-statement & -declaration) to be able to have scheme call javascript and vice versa? Same with python? I'm not sure what is correct from my reading of the mailing archive.
Thanks, -Jon
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Thanks for the help. This was really useful.
I'm still getting errors on the python backend though, FWIW. It's not a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
I may have botched something, and you'll see it immediately, but I'm not seeing it if I made a mistake. Here's what I did:
code.scm ;(declare ; (standard-bindings) ; (extended-bindings) ; (not safe) ; (fixnum) ; (block) ;)
(define (fib n) (define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))) (fib n))
;(println (eval `(* 1 1))) (println (fib 5))
This is with that top declare block commented out: $ python2 p.py Traceback (most recent call last): File "p.py", line 799, in <module> g_bb1_fib.name = g_cst0_code NameError: global name 'g_cst0_code' is not defined
And if I have the top declare block on: $ python2 p.py Traceback (most recent call last): File "p.py", line 26612, in <module> g_bb1_serial_2d_number_2d__3e_object.name = g_cst1727___gambit NameError: global name 'g_cst1727___gambit' is not defined
These were the sequence of commands I used to build (after rebuilding the _gambit.py with make _gambit.py): $ gsc -:=. -warnings -target python code.scm $ gsc -:=. -warnings -target python -link -l ~/gambit/lib/_gambit.py code.py $ cat code_.py code.py ~/gambit/lib/_gambit.py > p.py $ python2 p.py
Thanks for your help.
-Jon
On Sun, Aug 14, 2016 at 6:26 AM Marc Feeley feeley@iro.umontreal.ca wrote:
Yes that is mostly correct. However I would recommend the following commands:
for JavaScript:
$ cd lib $ make _gambit.js $ cd .. $ gsc/gsc -:=. -warnings -target js code.scm $ gsc/gsc -:=. -warnings -target js -link -l lib/_gambit.js code.js $ cat code_.js code.js lib/_gambit.js > p.js $ node p.js
for Python:
$ cd lib $ make _gambit.py $ cd .. $ gsc/gsc -:=. -warnings -target python code.scm $ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.py $ cat code_.py code.py lib/_gambit.py > p.py $ python p.py
Note that there was a small ordering problem in the generated code (now fixed) that prevented the Python code to run properly.
The universal backend is a WIP but close to a “final product”. Remaining on the TODO:
- changes to the Gambit library (lib/*.scm) and the runtime system to
support more of the Gambit system features, in particular non-blocking I/O which is needed to support Gambit’s green threads 2) integration to the main installation process (to build and install _gambit.js, _gambit.py, etc in the Gambit installation directory) 3) documentation (!)
The universal backend is definitely usable without #1 (some users have built commercial products with it) as long as the application uses ##inline-host-* to interface with hand written code to do the user-interface or I/O.
Here is a simple example for using ##inline-host-* in JavaScript:
(declare (extended-bindings))
(##inline-host-declaration "
function rand(n) { return Math.floor(n * Math.random()); }
")
(define (rand n) (+ 1 (##inline-host-expression "g_host2scm(rand(g_scm2host(@1@)))" n)))
(println (rand 6)) (println (rand 6)) (println (rand 6)) (println (rand 6))
(##inline-host-statement "console.log(@1@);" 123) (##inline-host-statement "console.log(@1@);" "hello") (##inline-host-statement "console.log(@1@);" 'world) (##inline-host-statement "console.log(@1@);" (cons 11 22)) (##inline-host-statement "console.log(@1@);" (vector 11 22 33)) (##inline-host-statement "console.log(@1@);" rand)
Hope that helps!
Marc
On Aug 14, 2016, at 12:23 AM, Jon Woodring woodring.jon@gmail.com
wrote:
Is there any documentation on compiling to javascript, or is it mostly
in the mailing list archives? After some scrounging, I was finally able to figure out how to compile and get a simple (println (fib 5)) working:
$ cd gambit/lib $ gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js
-prelude "(##include "header.scm")" -o _gambit.js ../lib/_univlib.scm
$ gsc -warnings -target js code.scm $ gsc -warnings -link -l _gambit.js code.js $ cat code_.js _gambit.js code.js > p.js $ node p.js
- Is that mostly correct? I take it it is still a WIP because I
couldn't find documentation.
- What if I want to use the Python backend? I tried swapping in all of
the targets with -target python but then get this error:
$ python2 p.py Traceback (most recent call last): File "p.py", line 26310, in <module> g_bb1_serial_2d_number_2d__3e_object.name = g_cst1727___gambit NameError: global name 'g_cst1727___gambit' is not defined
- Is there a concise example of #inline-host-expression (-statement &
-declaration) to be able to have scheme call javascript and vice versa? Same with python? I'm not sure what is correct from my reading of the mailing archive.
Thanks, -Jon
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py 5
Are you sure the gsc you are using is the latest you have built? Try gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com wrote:
I'm still getting errors on the python backend though, FWIW. It's not a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
I'm using v4.8.5. Should I use the HEAD? I'm trying to compile it now to see if that is the problem.
On Sun, Aug 14, 2016 at 10:38 AM Marc Feeley feeley@iro.umontreal.ca wrote:
Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py 5
Are you sure the gsc you are using is the latest you have built? Try gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm still getting errors on the python backend though, FWIW. It's not a
huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
Yes use HEAD (I committed a change to the universal backend yesterday, and you need that).
Marc
On Aug 14, 2016, at 1:33 PM, Jon Woodring woodring.jon@gmail.com wrote:
I'm using v4.8.5. Should I use the HEAD? I'm trying to compile it now to see if that is the problem.
On Sun, Aug 14, 2016 at 10:38 AM Marc Feeley feeley@iro.umontreal.ca wrote: Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py 5
Are you sure the gsc you are using is the latest you have built? Try gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com wrote:
I'm still getting errors on the python backend though, FWIW. It's not a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
Unfortunately I ran into a compile problem with msys2 and mingw-w64. I'll post an issue on github:
gcc -D_WINDOWS -D_WIN32_WINNT=0x0502 -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-strict-aliasing -fno-trapping-math -fwrapv -fno-keep-inline-dllexport -fno-common -mieee-fp -mpc64 -I"../include" -c -o "_kernel.o" -I. -DHAVE_CONFIG_H -D___GAMBITDIR=""\\mingw64"" -D___SYS_TYPE_CPU=""x86_64"" -D___SYS_TYPE_VENDOR=""w64"" -D___SYS_TYPE_OS=""mingw32"" -D___CONFIGURE_COMMAND=""./configure '--enable-single-host'"" -D___OBJ_EXTENSION="".o"" -D___EXE_EXTENSION="".exe"" -D___BAT_EXTENSION="".bat"" -D___PRIMAL _kernel.c -D___LIBRARY _kernel.c: In function '___H__20___kernel': _kernel.c:14100:37: error: '___gstate_mem {aka struct ___gstate_mem_struct}' has no member named 'glo_list_head' ___glo_struct *p = ___GSTATE->mem.glo_list_head; ^ make[1]: *** [makefile:164: _kernel.o] Error 1 make[1]: Leaving directory '/home/woodring/gambit/lib' make: *** [makefile:414: all-recursive] Error 1
On Sun, Aug 14, 2016 at 4:44 PM Marc Feeley feeley@iro.umontreal.ca wrote:
Yes use HEAD (I committed a change to the universal backend yesterday, and you need that).
Marc
On Aug 14, 2016, at 1:33 PM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm using v4.8.5. Should I use the HEAD? I'm trying to compile it now to
see if that is the problem.
On Sun, Aug 14, 2016 at 10:38 AM Marc Feeley feeley@iro.umontreal.ca
wrote:
Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py
code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py
5
Are you sure the gsc you are using is the latest you have built? Try
gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm still getting errors on the python backend though, FWIW. It's not
a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
Jon,
Just checking, did you follow the build process in the README? Gambit requires a couple of extra steps in order to be built from the git repo.
James
On Mon, Aug 15, 2016 at 9:03 AM, Jon Woodring woodring.jon@gmail.com wrote:
Unfortunately I ran into a compile problem with msys2 and mingw-w64. I'll post an issue on github:
gcc -D_WINDOWS -D_WIN32_WINNT=0x0502 -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-strict-aliasing -fno-trapping-math -fwrapv -fno-keep-inline-dllexport -fno-common -mieee-fp -mpc64 -I"../include" -c -o "_kernel.o" -I. -DHAVE_CONFIG_H -D___GAMBITDIR=""\\mingw64"" -D___SYS_TYPE_CPU=""x86_64"" -D___SYS_TYPE_VENDOR=""w64"" -D___SYS_TYPE_OS=""mingw32"" -D___CONFIGURE_COMMAND=""./configure '--enable-single-host'"" -D___OBJ_EXTENSION="".o"" -D___EXE_EXTENSION="".exe"" -D___BAT_EXTENSION="".bat"" -D___PRIMAL _kernel.c -D___LIBRARY _kernel.c: In function '___H__20___kernel': _kernel.c:14100:37: error: '___gstate_mem {aka struct ___gstate_mem_struct}' has no member named 'glo_list_head' ___glo_struct *p = ___GSTATE->mem.glo_list_head; ^ make[1]: *** [makefile:164: _kernel.o] Error 1 make[1]: Leaving directory '/home/woodring/gambit/lib' make: *** [makefile:414: all-recursive] Error 1
On Sun, Aug 14, 2016 at 4:44 PM Marc Feeley feeley@iro.umontreal.ca wrote:
Yes use HEAD (I committed a change to the universal backend yesterday, and you need that).
Marc
On Aug 14, 2016, at 1:33 PM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm using v4.8.5. Should I use the HEAD? I'm trying to compile it now
to see if that is the problem.
On Sun, Aug 14, 2016 at 10:38 AM Marc Feeley feeley@iro.umontreal.ca
wrote:
Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py
code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py
5
Are you sure the gsc you are using is the latest you have built? Try
gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm still getting errors on the python backend though, FWIW. It's not
a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Oh. I didn't read it and missed the extra ./configure and make.
RTFM and all that. Sorry! I suspect that will fix it.
On Sun, Aug 14, 2016 at 5:32 PM James Baker james@waveformdynamics.com.au wrote:
Jon,
Just checking, did you follow the build process in the README? Gambit requires a couple of extra steps in order to be built from the git repo.
James On Mon, Aug 15, 2016 at 9:03 AM, Jon Woodring woodring.jon@gmail.com wrote:
Unfortunately I ran into a compile problem with msys2 and mingw-w64. I'll post an issue on github:
gcc -D_WINDOWS -D_WIN32_WINNT=0x0502 -Wno-unused -Wno-write-strings -O1 -fno-math-errno -fschedule-insns2 -fno-strict-aliasing -fno-trapping-math -fwrapv -fno-keep-inline-dllexport -fno-common -mieee-fp -mpc64 -I"../include" -c -o "_kernel.o" -I. -DHAVE_CONFIG_H -D___GAMBITDIR=""\\mingw64"" -D___SYS_TYPE_CPU=""x86_64"" -D___SYS_TYPE_VENDOR=""w64"" -D___SYS_TYPE_OS=""mingw32"" -D___CONFIGURE_COMMAND=""./configure '--enable-single-host'"" -D___OBJ_EXTENSION="".o"" -D___EXE_EXTENSION="".exe"" -D___BAT_EXTENSION="".bat"" -D___PRIMAL _kernel.c -D___LIBRARY _kernel.c: In function '___H__20___kernel': _kernel.c:14100:37: error: '___gstate_mem {aka struct ___gstate_mem_struct}' has no member named 'glo_list_head' ___glo_struct *p = ___GSTATE->mem.glo_list_head; ^ make[1]: *** [makefile:164: _kernel.o] Error 1 make[1]: Leaving directory '/home/woodring/gambit/lib' make: *** [makefile:414: all-recursive] Error 1
On Sun, Aug 14, 2016 at 4:44 PM Marc Feeley feeley@iro.umontreal.ca wrote:
Yes use HEAD (I committed a change to the universal backend yesterday, and you need that).
Marc
On Aug 14, 2016, at 1:33 PM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm using v4.8.5. Should I use the HEAD? I'm trying to compile it now
to see if that is the problem.
On Sun, Aug 14, 2016 at 10:38 AM Marc Feeley feeley@iro.umontreal.ca
wrote:
Strange… with your code (with and without the declarations) I get:
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py
code.scm;cat code_.py code.py lib/_gambit.py > p.py;python p.py
5
Are you sure the gsc you are using is the latest you have built? Try
gsc/gsc from the Gambit build directory.
Marc
On Aug 14, 2016, at 10:57 AM, Jon Woodring woodring.jon@gmail.com
wrote:
I'm still getting errors on the python backend though, FWIW. It's
not a huge deal, because I'm mostly targeting javascript, but I am a heavy python user, too, so it would be nice for future reference.
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list