larsbrinkhoff / lbForth

Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
GNU General Public License v3.0
418 stars 112 forks source link

Add support for node.js, Firefox, Chromium #39

Closed pipcet closed 7 years ago

pipcet commented 7 years ago

Start addressing #36. nodejs ./forth should simply work; Firefox should work after copying forth to forth.js and forth.html to forth.html in the lbForth/ directory; with the right security settings, a file:/// url will work, but with a web server, it should always work. Chromium won't work with file:/// urls (I believe there are command line options to fix this but I keep forgetting them), but should work with a web server just like Firefox does.

I can't really test Microsoft browsers, but I'm optimistic it shouldn't be too hard to get them working.

No VT100 emulation yet, and the first line of output ("lbForth") gets eaten right now.

larsbrinkhoff commented 7 years ago

Thank you.

I tried to test this. I loaded the forth.html file locally in Firefox, and also made a gh-pages thing: http://larsbrinkhoff.github.io/lbForth/targets/asmjs/forth.html

In both cases, typing something in the input field displays something above it, but quickly dissapears. If I type e.g. words, I don't see the expected output.

larsbrinkhoff commented 7 years ago

Tested with nodejs:

$nodejs --version
v0.10.25
$nodejs asmjs-forth

readline.js:73
    terminal = !!output.isTTY;
                       ^
TypeError: Cannot read property 'isTTY' of undefined
    at new Interface (readline.js:73:24)
    at Object.exports.createInterface (readline.js:39:10)
    at Object.<anonymous> (/home/lars/src/lbForth/asmjs-forth:52:23)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Maybe that version is ancient. It's what I got in Ubuntu 14.

larsbrinkhoff commented 7 years ago

I added testing with nodejs to the Travis build. I expect it to fail for now, but I'll fix that.

larsbrinkhoff commented 7 years ago

Newlines in stdin doesn't quite work in nodejs. SpiderMonkey is fine:

(echo 42; echo 42 .s) | js24 asmjs-forth
lbForth
ok
 ok
<2> 42 42  ok

But nodejs:

(echo 42; echo 42 .s) | nodejs asmjs-forth
lbForth
ok
<1> 4242  ok
larsbrinkhoff commented 7 years ago

I made a hack to add a newline to the nodejs input. This makes the tests pass. BUT it now seems the newlines are sometimes doubled in the input.

pipcet commented 7 years ago

The forth.html needs to be in the lbForth/ folder, not targets/asmjs/, or we won't find load.fth.

larsbrinkhoff commented 7 years ago

Ok! This seems good:
http://larsbrinkhoff.github.io/lbForth/targets/asmjs/forth.html

pipcet commented 7 years ago

It seems old versions of readline require an output parameter even if no output is intended. Furthermore, as you've discovered, they don't necessarily wait for one line to complete handling before queueing the second.

I think I've fixed both issues, can you verify the duplicated newlines are gone?

pipcet commented 7 years ago

I think you still have the wrong URL there. http://larsbrinkhoff.github.io/lbForth/forth.html works for me.

larsbrinkhoff commented 7 years ago

Yes, sorry. I mean that URL.

larsbrinkhoff commented 7 years ago

Newlines seem good.

Node.js echoes doubly when used from the command line.

pipcet commented 7 years ago

I can reproduce that within Emacs, which readline presumably doesn't recognize as a "terminal", but not in an xterm.

Hopefully fixed. It'd probably be best to avoid the readline library entirely and rely on OS buffering...

larsbrinkhoff commented 7 years ago

Right, I run my shell in Emacs 99% of the time. It does produce strange effects occasionally.

larsbrinkhoff commented 7 years ago

I think this is fine for merging now.

pipcet commented 7 years ago

Okay, cool. I've squashed the commits.

larsbrinkhoff commented 7 years ago

Thanks!

larsbrinkhoff commented 7 years ago

IE11 doesn't work, but meh.