unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche Boubekki <amirouche@hypermove.net>
To: Ian Price <ianprice90@gmail.com>
Cc: guile-user@gnu.org,
	guile-user <guile-user-bounces+amirouche=hypermove.net@gnu.org>
Subject: Re: Summer of Code Recap
Date: Sat, 02 Sep 2017 00:09:04 +0200	[thread overview]
Message-ID: <40d9af53c985dfe680d8df822ace02a3@hypermove.net> (raw)
In-Reply-To: <CACpaFSQYy-md+VyuFc1+0T99XkdP1WB0_=LVF0tJkk4Y-OO=2A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2933 bytes --]

On 2017-08-28 20:56, Ian Price wrote:

> 1 Introduction
> ==============
> 
>   As many of you are aware, I have been working on compiling Guile
>   Scheme to JavaScript this summer, as part of the Google Summer of
>   Code. This post serves to bookend my work for the year.
> 
>   Before I go any further, I have to give my thanks to my mentor [Chris
>   Webber], without whom this project would have fizzled out weeks ago;
>   Google and the Gnu Project, naturally, for providing the Summer of
>   Code and allowing me to work on this project; and our fearless 
> leader,
>   [Andy Wingo], for answering a wide variety of stupid questions.
> 

Sorry, for my last mail I was a bit upset a minimal scm file with "42"
will crash.

Anyway, I did a bit of exploration:

Apparently webkit does ship TCO and safari is the only browser [0] 
shipping it.
So it will happen soon enough for chrome, but chrome is not a solution 
for many
of us. I don't know when firefox with ship TCO.

[0] https://www.chromestatus.com/feature/5516876633341952

Anyway, TCO requires "use strict"; thing to work, so I prefixed the 
output
of guild jslink with that and it lead to discover a bug where there is 
two
times the same argument called `v_rest`. You can run the file with
the following command:

    node --harmony_tailcalls main.js

It will tell you where the error is.

Here is the fixed code:

     var k_27363 = function(v_19412, k_27499) {
       var k_27364 = function(v_19412, v_e, v_p, v_w, v_mod) {
         var v_19413 = v_e;
         var v_19414 = v_p;
         var v_19415 = v_w;
         var v_19416 = v_mod;
         if (scheme["is_true"](scheme["primitives"]["pair?"](v_19413))) {
           {
             var v_19417 = scheme["primitives"]["car"](v_19413);
             var v_19418 = scheme["EMPTY"];
             scheme["primitives"]["handle-interrupts"]();
             var k_27370 = function(v_first, v_rest) {
               var v_19419 = v_first;
               var v_19420 = v_rest;
               if (scheme["is_true"](v_19419)) {
                 {
                   var v_19421 = scheme["primitives"]["cdr"](v_19413);
                   scheme["primitives"]["handle-interrupts"]();
                   var k_27375 = function(v_rest, v_rest2) {  // The 
error is HERE!
                     var v_19422 = v_rest;
                     var v_19423 = v_rest2;

With that "fix" it run under nodejs v8.4.0 without increasing the 
callstack.
So it's good news!

I can't make it work with Google Chrome Version 60.0.3112.113 which use
a more recent version of v8 than my nodejs.

chrome://flags/#enable-javascript-harmony

The babel-plugin-tailcall-optimization doesn't work on my machine. It 
crash
with an OOM failure.

Also Google's traceur does not work.

Finally, there is this heavy page that is supposed to tell what is 
supported:

https://kangax.github.io/compat-table/es6/#test-proper_tail_calls_(tail_call_optimisation)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-add-a-few-ffi-procedures-inspired-from-biwascheme.patch --]
[-- Type: text/x-diff; name=0002-add-a-few-ffi-procedures-inspired-from-biwascheme.patch, Size: 1203 bytes --]

From 4ac41ad82300b5f35862d51ebac7c661f526809a Mon Sep 17 00:00:00 2001
From: amirouche <amirouche+dev@hypermove.net>
Date: Fri, 1 Sep 2017 21:58:45 +0200
Subject: [PATCH 2/2] add a few ffi procedures inspired from biwascheme

---
 module/language/js-il/runtime.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 583f21d93..26090055e 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -926,6 +926,24 @@ function scm_list (self, cont) {
 };
 def_guile0("list", scm_list);
 
+def_guile0("js-eval", function(self, cont, string) {
+  return cont(eval(string.s))
+});
+
+def_guile0("js-ref", function(self, cont, js, attrname) {
+  return cont(js[attrname.s]);
+});
+
+def_guile0("js-invoke", function(self, cont, jsobj, methodname) {
+  var args = Array.prototype.slice.call(arguments).slice(4);
+  cont(jsobj[methodname.s].apply(jsobj, args));
+});
+
+def_guile0("js-call", function(self, cont, jsfunc) {
+  var args = Array.prototype.slice.call(arguments).slice(3);
+  cont(jsfunc.apply(undefined, args));
+});
+
 // Numbers
 function scm_add(self, cont) {
 
-- 
2.11.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-always-throw-an-Error-object-to-have-a-nice-tracebac.patch --]
[-- Type: text/x-diff; name=0001-always-throw-an-Error-object-to-have-a-nice-tracebac.patch, Size: 715 bytes --]

From 0f4fdac6347631b8e12d02a91f5ff40d056dfbd9 Mon Sep 17 00:00:00 2001
From: amirouche <amirouche+dev@hypermove.net>
Date: Fri, 1 Sep 2017 21:09:36 +0200
Subject: [PATCH 1/2] always throw an Error object to have a nice traceback

---
 module/language/js-il/runtime.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 142e3db86..583f21d93 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -38,7 +38,7 @@ var scheme = {
 };
 
 function not_implemented_yet() {
-    throw "not implemented yet";
+    throw new Error("not implemented yet");
 };
 
 function coerce_bool(obj) {
-- 
2.11.0


  parent reply	other threads:[~2017-09-01 22:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 18:56 Summer of Code Recap Ian Price
2017-08-28 19:25 ` Christopher Allan Webber
2017-08-28 19:58   ` Nala Ginrut
2017-08-28 21:39 ` Amirouche
2017-08-29  3:27   ` Christopher Allan Webber
2017-09-01 22:09 ` Amirouche Boubekki [this message]
2017-09-02  6:58   ` Arne Babenhauserheide
2017-09-06 18:25   ` Amirouche Boubekki
2017-09-07  6:32     ` Amirouche Boubekki
2017-09-08 12:18       ` Amirouche Boubekki
2021-05-11 14:45 ` Christopher Lemmer Webber
2021-05-11 15:08   ` Christopher Lemmer Webber
2021-05-11 15:19     ` Christopher Lemmer Webber
2021-10-11  1:50       ` Christine Lemmer-Webber
2021-10-11  5:28         ` Dr. Arne Babenhauserheide
2021-05-11 15:50   ` Dr. Arne Babenhauserheide

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40d9af53c985dfe680d8df822ace02a3@hypermove.net \
    --to=amirouche@hypermove.net \
    --cc=guile-user-bounces+amirouche=hypermove.net@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=ianprice90@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).