jsoftware / j-playground

J playground
https://jsoftware.github.io/j-playground/bin/html2/
Other
10 stars 5 forks source link

Port 2018 J Playground to use wasm engine #19

Closed joebo closed 2 years ago

joebo commented 2 years ago

Chris Burke shared the 2018 J Playground code that runs https://code2.jsoftware.com/play.html . The 2018 J Playground has nicer aesthetics and functionality that would be a large step forward from the current implementation.

It should be possible to port this code to use the WASM engine instead of calling out to J on the server.

Upon review, the smallest possible change to make this work seems to be:

Conceptual example:

Instead of:

//websocket.ijs
function wsopen() {

 ws = new WebSocket(wsprotocol() + Config.host + ":" + Config.port);
....

//term.ijs (no change needed here)
function docmd(cmd, log, show) {
 cmd = cmd.trim();
 if (log === undefined)
  log = true;
 if (show === undefined)
  show = false;
 dlog_add(cmd);
 if (log) tcmappend(cmd + "\n");
 if (show)
  ws.send("output_jrx_=:i.0 0\noutput_jrx_=:" + cmd + "\noutput_jrx_");
 else
  ws.send(cmd);
}

To:

//websocket.ijs
function wsopen() {

 ws = {
    send: function(cmd) { jdo1(cmd); }
}
...

Where jdo1 is defined at: https://github.com/jsoftware/j-playground/blob/j903_wasm/bin/html/app.js#L4 or could be easily redefined to a cleaner name (I can't remember why there is the "1" suffix)

Activities:

joebo commented 2 years ago

The approach worked largely as expected (not saying it's the best approach).

There were two modifications to the code:

The html2 folder was populated as follows

# copy the html assets into html2
cp -r jfe/lib ../../../bin/html2/

# copy the wasm engine assets into html2
cp ../html/emj.* .

Some of the codemirror stuff were broken symbolic links and not files so I fixed most of them with this:

cp ./j807/addons/net/websocket/demo3/codemirror/* ../bin/html2/codemirror/

Additional broken dependencies are noted in the issue text (j.js and matchbrackets.js)

jonghough commented 2 years ago

Great!. Pulling your edits, it works, but carriage return is missing after a line is run. I am trying to see where now.

cdburke commented 2 years ago

I don't see the missing carriage return. Can you give an example?

On Thu, Apr 7, 2022 at 5:42 AM Jon Hough @.***> wrote:

Great!. Pulling your edits, it works, but carriage return is missing after a line is run. I am trying to see where now.

— Reply to this email directly, view it on GitHub https://github.com/jsoftware/j-playground/issues/19#issuecomment-1091687517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMDJAMNFMVOXCS3NM4D6DDVD3J3ZANCNFSM5SX4VYOQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jonghough commented 2 years ago

In the modified websocket.js

send: function(cmd) { 
    //console.log(cmd);
    var ret = jdo1(cmd);
    //tcmreturn slices the first character off
    tcmreturn(' ' + ret);
  }

example

  ]a=: i.5 
0 1 2 3 4a
jonghough commented 2 years ago

Solution is

tcmreturn(' ' + ret + '\n');
jonghough commented 2 years ago

This is an odd issue. In Term

a=: i.5

a
0 1 2 3 4
b
|value error: b
b=: 1
|value error: b
b
1
b
1
a=: i.5
1

2 issues that I can see. Even after defining "b", the value error is shown. After redefining "a", the previous result is shown.

Perhaps we need to flush the jengine?

jonghough commented 2 years ago

It seems to be cleared up by doing (the horrible hack)

let ret = jdo1(cmd);
//tcmreturn slices the first character off
tcmreturn(' ' + ret + '\n'); 
jdo1("''");

i.e. flushing jengine with empty jdo1. But obviously that doesn't answer why it is happening.

bilam commented 2 years ago

websocket was used in 2018 J Playground because javascript frontend needed to interface with native code J engine. If both web ui frontend and wasm J engine are javascript, then I think the websocket middle-ware is redundant.

jonghough commented 2 years ago

Yes, but the functions have been modified to call the wasm jengine. Filename is still websockets.js so it will cause confusion. I think it is only intended for proof of concept testing, for now.

cdburke commented 2 years ago

Are you using the old codemirror or have upgraded to a newer version?

On Thu, Apr 7, 2022 at 7:32 AM Jon Hough @.***> wrote:

Yes, but the functions have been modified to call the wasm jengine. Filename is still websockets.js so it will cause confusion.

Message ID: @.***>

joebo commented 2 years ago

Are you using the old codemirror or have upgraded to a newer version?

old codemirror for now. This initial rough port was just to prove it could be integrated with the wasm engine with minimal changes to original j playground code. That's why websockets.ijs was modified instead of hacking into the rest of the jplayground code. We'll rework that as this matures

cdburke commented 1 year ago

On my machine:

a=: i.5 a 0 1 2 3 4 b |value error: b b=: 1 b 1

On Thu, Apr 7, 2022 at 6:18 AM Jon Hough @.***> wrote:

This is an odd issue. In Term

a=: i.5

a 0 1 2 3 4 b |value error: b b=: 1 |value error: b b 1 b 1 a=: i.5 1

2 issues that I can see. Even after defining "b", the value error is shown. After redefining "a", the previous result is shown.

— Reply to this email directly, view it on GitHub https://github.com/jsoftware/j-playground/issues/19#issuecomment-1091727009, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMDJAKNFFEBVEQBZ27NU6TVD3ODFANCNFSM5SX4VYOQ . You are receiving this because you commented.Message ID: @.***>

cdburke commented 1 year ago

Ah, symlinks! Sorry about that, I symlink all the time and just forget about it.

I have updated the play.zip file on google drive with the symlinks resolved.

On Thu, Apr 7, 2022 at 4:41 AM joebo @.***> wrote:

The approach worked largely as expected (not saying it's the best approach).

There were two modifications to the code:

The html2 folder was populated as follows

copy the html assets into html2

cp -r jfe/lib ../../../bin/html2/

copy the wasm engine assets into html2

cp ../html/emj.* .

Some of the codemirror stuff were broken symbolic links and not files so I fixed most of them with this:

cp ./j807/addons/net/websocket/demo3/codemirror/* ../bin/html2/codemirror/

Additional broken dependencies are noted in the issue text (j.js and matchbrackets.js)

— Reply to this email directly, view it on GitHub https://github.com/jsoftware/j-playground/issues/19#issuecomment-1091632222, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMDJAOTQSSA2F6SHZGUUCTVD3CV7ANCNFSM5SX4VYOQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>