01alchemist / TurboScript

Super charged typed JavaScript dialect for parallel programming which compiles to WebAssembly
Apache License 2.0
494 stars 35 forks source link

Error trying to add a server #25

Closed winksaville closed 7 years ago

winksaville commented 7 years ago

I've created a change which adds a server to be used with tests. But I'm getting in the Browser:

      addTwo.html:17 Uncaught (in promise) CompileError: WebAssembly.compile(): Wasm decoding failedResult = expected version 01 00 00 00, found 0d 00 00 00 @+4
        at init (http://localhost:3000/tests/addTwo.html:17:25)
      addTwo.html:35 Uncaught (in promise) CompileError: WebAssembly.compile(): Wasm decoding failedResult = expected version 01 00 00 00, found 0d 00 00 00 @+4
        at initRef (http://localhost:3000/tests/addTwo.html:35:25)

Here are versions of my system

$ uname -a
Linux wink-envy 4.10.5-1-ARCH #1 SMP PREEMPT Wed Mar 22 14:42:03 CET 2017 x86_64 GNU/Linux
$ node --version
v7.7.3
$ ./node_modules/.bin/tsc --version
Version 2.2.2
$ google-chrome-stable --version
Google Chrome 57.0.2987.110 

What am I doing wrong?

winksaville commented 7 years ago

I figured out the version problem, I needed to recompile addTwo.tbs. Which I did so using:

$ chmod a+x ./bin/tc
$ ./bin/tc ./tests/addTwo.tbs --wasm --out ./tests/addTwo.wasm
TURBO_PATH:/home/wink/prgs/TurboScript.myfork
pre-parsing: 2.686ms
lexing: 35.232ms
preprocessing: 0.121ms
parsing: 11.079ms
checking: 23.554ms
shaking: 0.674ms
emitting: 17.892ms
Done!
$ cp tests/addTwo.wasm tests/reference/addTwo.wasm

But now I have a new problem, the browser doesn't see either reference to addTwo as a function:

TurboScript WASM
addTwo.html:21 ----------------
addTwo.html:37 Reference WASM
addTwo.html:38 ----------------
addTwo.html:22 Uncaught (in promise) TypeError: mod.exports.addTwo is not a function
    at addTwo.html:22
(anonymous) @ addTwo.html:22
addTwo.html:39 Uncaught (in promise) TypeError: modRef.exports.addTwo is not a function
    at addTwo.html:39

So again I ask; What am I doing Wrong?

nidin commented 7 years ago

Most of the tests are broken with latest changes. I'll fix it tomorrow.

nidin commented 7 years ago

Also there is no more reference WASM files since wasm emitter is stable now.

winksaville commented 7 years ago

If you give me a clue I'd like to try to fix addTwo.

On Tue, Mar 28, 2017, 2:03 PM Nidin Vinayakan notifications@github.com wrote:

Also there is no more reference WASM files since wasm emitter is stable now.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/01alchemist/TurboScript/issues/25#issuecomment-289904088, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-hHIvcAbWe86VgBJNyhC8Cv76f3RuCks5rqXWZgaJpZM4MsDgr .

nidin commented 7 years ago

In master i already fixed addTwo, please look in to source and use the same export function names in html page. there is a file make.js just run node make.js it should build tests and copy binary to tests/bin. in make.js i added only few test files. you may add all tests but it might broke.

winksaville commented 7 years ago

The make node.js didn't work for me:

wink@wink-envy:~/prgs/TurboScript.myfork/tests (master)
$ node make.js 
Compiling ASM.JS tests...
Compiling WASM tests...
Object "addTwo.tbs" is unknown, try "tc help".

Object "array.tbs" is unknown, try "tc help".

Object "binary.tbs" is unknown, try "tc help".

Object "block.tbs" is unknown, try "tc help".

Object "addTwo.tbs" is unknown, try "tc help".

Object "array.tbs" is unknown, try "tc help".

Object "binary.tbs" is unknown, try "tc help".

Object "block.tbs" is unknown, try "tc help".

block.tbs failed to compile
binary.tbs failed to compile
array.tbs failed to compile
addTwo.tbs failed to compile
block.tbs failed to compile
binary.tbs failed to compile
array.tbs failed to compile
addTwo.tbs failed to compile

So I tweaked my add-server branch and its now working for addTwo-wasm. You first do npm run test:build and then start the server with npm run server. Finally, something like google-chrome-stable http://localhost:3000/tests/addTwo-wasm.html and looking at the console output and addTwo-wasm.html now worked as expected, THANKS.

So I'm interested maybe doing some tests, but want to know what your goals are.

Do you want browser based tests or nodejs based tests, my own thoughts would be to start with nodejs only?

I'm not really interested in asm.js, long term it seems a dead en, and would like to just test wasm, what do you think?

Disclosure: I'm a retired programmer with lots of experience in C/C++/Java but I'm just learning web development so I'm looking for constructive feed back and opportunities to learn.

nidin commented 7 years ago

Hi @winksaville, Nice work. The goal is to target both browser and node.js. for now we can start with node.js only since TurboScript cannot access DOM or any browser API and scope for the v1 is support all WASM MVP features. No GC, No DOM access, basic interoperability with external JS.

I am also not interested in supporting asm.js for long term. asm.js currently support shared memory but WASM doesn't therefore asm.js is a valuable target to test parallel programming features of TurboScript till WASM shared memory spec ready.

Your knowledge is very valuable to mature this project. I will come up with more ideas to discuss. If you are interested in integrating any testing frameworks like karma or Jest you may check this issues/19 Just create a pull request when you are done.

Happy web development 👍

winksaville commented 7 years ago

SG, I'll work up a PR and we'll see where it goes.

nidin commented 7 years ago

@winksaville make.js script patched for portability and added a task in package.json use npm run test:build could you please pull latest changes from master.