Eric,

I don't have the source code that was run through emscripten since that was
done by 'f211'. I am familiar with emscipten though, so I can comment on it
high level.

You can probably get much more from
http://kripken.github.io/emscripten-site/

In a nutshell, I assume f211 compiled the J gpl source with clang, removed
out anything that wasn't compatible with javascript (e.g. dll calls) and
then ran it through emscripten. emscripten takes the LLVM ir and then
compiles it to javascript.

In some early benchmarking it is 1-4x slower than the C code in some cases.
It's quite fast.

emscripten recreates a C-style platform in javascript. The javascript is
accessing large typed arrays that simulate the heap and stack. It's
basically just pushing bits back and forth. The transpiled J code looks
very much like the original C source


For example, here's one of the  iota implementations:

function _jtiota1(a, f, d) {
    var c, b;
    c = 0 == (HEAP32[f + 24 >> 2] | 0) ? 1 : HEAP32[f + 28 >> 2];
    f = _jtga(a, 4, c, 1, 0);
    if (0 == (f | 0)) return 0;
    if (0 == (c | 0)) return f;
    a = 0;
    for (d = f + HEAP32[f >> 2];;)
        if (a += 1, HEAP32[d >> 2] = a, (a | 0) == (c | 0)) {
            b = f;
            break
        } else d += 4;
    return b
}

The HEAP[...] calls are offsets to the struct. Here are some helpers I
defined after reverse engineering

var rank = function(f) { return HEAP32[16+f>>2] }
var shape = function(f) { return HEAP32[20+f>>2] }
var ravelPtr = function(f) { return HEAP32[f>>2]; }
var val = function(f,size,idx) {
    return HEAP32[(ravelPtr(f) + (idx*size) +f)>>2];
}
var typei = function(f) { return HEAP32[12+f>>2] };

Here's the C code:

F1(jtiota){A z;I m,n,*v;
 F1RANK(1,jtiota,0);
 if(AT(w)&XNUM+RAT)R cvt(XNUM,iota(vi(w)));
 RZ(w=vi(w)); n=AN(w); v=AV(w);
 if(1==n){m=*v; R 0>m?apv(-m,-m-1,-1L):IX(m);}
 RE(m=prod(n,v)); z=reshape(mag(w),IX(ABS(m)));
 DO(n, if(0>v[i])z=irs1(z,0L,n-i,jtreverse););
 R z;
}

I intend to write up a more thorough analysis of it. I probably spent
12'ish hours working everything out so it would be worthwhile to write it
down.








On Tue, Nov 25, 2014 at 5:53 PM, Eric Iverson <[email protected]>
wrote:

> This does look very interesting. I'd love to have the time to dig into
> this a bit. But alas. Could you perhaps describe what has been done
> (the overall architecture). I'm a bit confused by the compiled claim.
>
> On Tue, Nov 25, 2014 at 4:53 PM, Joe Bogner <[email protected]> wrote:
> > I found out a few weeks ago that someone had ported J to emscripten[1]
> >
> > I couldn't find any contact information for the author, so I just went
> > ahead and scraped the site to get the source.
> >
> > I've posted it to github with a demo ide
> >
> > http://joebo.github.io/j-emscripten/
> >
> > I think there's a tremendous amount of potential here. It runs on my
> ipad,
> > android and desktop. It can integrate in with javascript canvas -- see my
> > interop example:
> >
> > 'drawRect' (15!:0) (10,10,10,10)
> >
> > I can envision making the labs interactive and also allowing people to
> save
> > and share their code. All of this running safely in the browser without
> an
> > install required.
> >
> > We can also play with different IDE concepts. For example, I added quick
> > picklists to Devon's Minimal Beginning J.
> >
> > I went through the painful effort of trying to cut down the javascript
> > required to run the environment. I've been able to get j-called.min.js
> down
> > to 446KB minified and compressed.  The full version is also available at
> > http://joebo.github.io/j-emscripten/full.html and weighs in at 2MB of
> > javascript. If you get an error about something missing, try the full
> > version.
> >
> > My IDE code is still messy but posted here:
> > https://github.com/joebo/j-emscripten/blob/master/index.html. One of the
> > most challenging parts was figuring out how to interop with emscripten,
> but
> > I was able to implement a function that lets the script get loaded and
> also
> > a fake 15!:0 for interop calls.
> >
> > Try it out and provide any feedback and I can update it. Alternatively,
> > fork it and make your own version and post it here. Javascript makes J
> > incredibly hackable and shareable.
> >
> >
> > [1] - found originally at http://tryj.tk/
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to