<div dir="ltr">Thanks for the help. This was really useful.<div><br></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div>code.scm</div><div><div>;(declare</div><div>;  (standard-bindings)</div><div>;  (extended-bindings)</div><div>;  (not safe)</div><div>;  (fixnum)</div><div>;  (block)</div><div>;)</div><div><br></div><div>(define (fib n)</div><div>  (define (fib n)</div><div>    (if (< n 2)</div><div>        n</div><div>        (+ (fib (- n 1))</div><div>           (fib (- n 2)))))</div><div>  (fib n))</div><div><br></div><div>;(println (eval `(* 1 1)))</div><div>(println (fib 5))</div></div><div><br></div><div>This is with that top declare block commented out:</div><div></div><div dir="ltr"><div><div>$ python2 p.py</div><div>Traceback (most recent call last):</div></div></div><div dir="ltr"><div><div>  File "p.py", line 799, in <module></div><div>    <a href="http://g_bb1_fib.name" target="_blank">g_bb1_fib.name</a> = g_cst0_code</div><div>NameError: global name 'g_cst0_code' is not defined</div></div><div><br></div><div>And if I have the top declare block on:</div><div></div></div><div dir="ltr"><div><div>$ python2 p.py</div><div>Traceback (most recent call last):</div></div></div><div dir="ltr"><div><div>  File "p.py", line 26612, in <module></div></div></div><div dir="ltr"><div><div>    <a href="http://g_bb1_serial_2d_number_2d__3e_object.name" target="_blank">g_bb1_serial_2d_number_2d__3e_object.name</a> = g_cst1727___gambit</div><div>NameError: global name 'g_cst1727___gambit' is not defined</div></div></div><div dir="ltr"><div></div><div><br></div><div>These were the sequence of commands I used to build (after rebuilding the _gambit.py with make _gambit.py):</div><div><div><span style="line-height:1.5">$ gsc -:=. -warnings -target python code.scm</span><br></div><div><span style="line-height:1.5">$ gsc -:=. -warnings -target python -link -l ~/gambit/lib/_gambit.py code.py</span><br></div><div><span style="line-height:1.5">$ cat code_.py code.py ~/gambit/lib/_gambit.py > p.py</span><br></div><div><span style="line-height:1.5">$ python2 p.py</span><br></div></div><div><br></div><div>Thanks for your help.</div><div><br></div><div>-Jon</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Aug 14, 2016 at 6:26 AM Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes that is mostly correct.  However I would recommend the following commands:<br>
<br>
for JavaScript:<br>
<br>
$ cd lib<br>
$ make _gambit.js<br>
$ cd ..<br>
$ gsc/gsc -:=. -warnings -target js code.scm<br>
$ gsc/gsc -:=. -warnings -target js -link -l lib/_gambit.js code.js<br>
$ cat code_.js code.js lib/_gambit.js > p.js<br>
$ node p.js<br>
<br>
for Python:<br>
<br>
$ cd lib<br>
$ make _gambit.py<br>
$ cd ..<br>
$ gsc/gsc -:=. -warnings -target python code.scm<br>
$ gsc/gsc -:=. -warnings -target python -link -l lib/_gambit.py code.py<br>
$ cat code_.py code.py lib/_gambit.py > p.py<br>
$ python p.py<br>
<br>
Note that there was a small ordering problem in the generated code (now fixed) that prevented the Python code to run properly.<br>
<br>
The universal backend is a WIP but close to a “final product”.  Remaining on the TODO:<br>
<br>
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<br>
2) integration to the main installation process (to build and install _gambit.js, _gambit.py, etc in the Gambit installation directory)<br>
3) documentation (!)<br>
<br>
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.<br>
<br>
Here is a simple example for using ##inline-host-* in JavaScript:<br>
<br>
(declare (extended-bindings))<br>
<br>
(##inline-host-declaration "<br>
<br>
function rand(n) {<br>
  return Math.floor(n * Math.random());<br>
}<br>
<br>
")<br>
<br>
(define (rand n)<br>
  (+ 1 (##inline-host-expression "g_host2scm(rand(g_scm2host(@1@)))" n)))<br>
<br>
(println (rand 6))<br>
(println (rand 6))<br>
(println (rand 6))<br>
(println (rand 6))<br>
<br>
(##inline-host-statement "console.log(@1@);" 123)<br>
(##inline-host-statement "console.log(@1@);" "hello")<br>
(##inline-host-statement "console.log(@1@);" 'world)<br>
(##inline-host-statement "console.log(@1@);" (cons 11 22))<br>
(##inline-host-statement "console.log(@1@);" (vector 11 22 33))<br>
(##inline-host-statement "console.log(@1@);" rand)<br>
<br>
Hope that helps!<br>
<br>
Marc<br>
<br>
<br>
> On Aug 14, 2016, at 12:23 AM, Jon Woodring <<a href="mailto:woodring.jon@gmail.com" target="_blank">woodring.jon@gmail.com</a>> wrote:<br>
><br>
> 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:<br>
><br>
> $ cd gambit/lib<br>
> $ gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -target js -prelude "(##include \"header.scm\")" -o _gambit.js ../lib/_univlib.scm<br>
><br>
> $ gsc -warnings -target js code.scm<br>
> $ gsc -warnings -link -l _gambit.js code.js<br>
> $ cat code_.js _gambit.js code.js > p.js<br>
> $ node p.js<br>
><br>
> 1) Is that mostly correct? I take it it is still a WIP because I couldn't find documentation.<br>
><br>
> 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:<br>
> $ python2 p.py<br>
> Traceback (most recent call last):<br>
>   File "p.py", line 26310, in <module><br>
>     <a href="http://g_bb1_serial_2d_number_2d__3e_object.name" rel="noreferrer" target="_blank">g_bb1_serial_2d_number_2d__3e_object.name</a> = g_cst1727___gambit<br>
> NameError: global name 'g_cst1727___gambit' is not defined<br>
><br>
> 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.<br>
><br>
> Thanks,<br>
> -Jon<br>
><br>
> _______________________________________________<br>
> Gambit-list mailing list<br>
> <a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
> <a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br>
</blockquote></div></div>