Recent

Author Topic: WebAssembly?  (Read 15789 times)

Benjiro

  • Guest
WebAssembly?
« on: July 07, 2017, 01:09:09 pm »
Seeing this topic coming up more and more in other programming languages, is there any information regarding WebAssembly support for freePascal?

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: WebAssembly?
« Reply #1 on: July 07, 2017, 02:39:56 pm »
I just tested (http://webassembly.org/demo/)
It would be nice to have a compiler-target for WASM
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: WebAssembly?
« Reply #2 on: July 07, 2017, 05:14:17 pm »
The toolchain is already there: pastojs... And Florian is/(was?) experimenting with a compile to javascript according to the branches...
webassembly has a pure ecmascript 5 api.
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #3 on: July 07, 2017, 07:12:22 pm »
@thaddy: webassembly <>js ... its possible to run wasm binaries in js vm using libraries but the true force wasm is in the compiler that generates not an bytecode but a tree like structure that can be jit and runs natively inside the browser... it also not like NaCl .... anyway webasm as a target for fpc is not impossible but very difficult to implement..on the other hand  if you want t use pas to js best option is smart mobile studio... the rtl is complete and the platform is pretty stable...
Speak postscript or die!
Translate to pdf and live!

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: WebAssembly?
« Reply #4 on: July 08, 2017, 12:38:20 pm »
@thaddy: webassembly <>js ... its possible to run wasm binaries in js vm using libraries but the true force wasm is in the compiler that generates not an bytecode but a tree like structure that can be jit and runs natively inside the browser... it also not like NaCl .... anyway webasm as a target for fpc is not impossible but very difficult to implement..on the other hand  if you want t use pas to js best option is smart mobile studio... the rtl is complete and the platform is pretty stable...
An external, concurrent Product ?
Next thing to suggest to use CodeTyphoon for cross compile ?
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #5 on: July 08, 2017, 02:30:39 pm »
im not promoting any external or. concurent product ... just saying that sms is pas to js... i have never used it for serious work.... also the same for ct ... not even know where to download ct.. >:D
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: WebAssembly?
« Reply #6 on: July 08, 2017, 06:04:52 pm »
@thaddy: webassembly <>js ... its possible to run wasm binaries in js vm using libraries but the true force wasm is in the compiler that generates not an bytecode but a tree like structure that can be jit and runs natively inside the browser... it also not like NaCl .... anyway webasm as a target for fpc is not impossible but very difficult to implement..on the other hand  if you want t use pas to js best option is smart mobile studio... the rtl is complete and the platform is pretty stable...
From what I have seen and experimented with, it is not THAT difficult. The HLCG from FPC is sufficiently abstracted to do such a thing. Basically a parsetree transform and a back-end. Hence I wrote that the webassembly has a strict js API and we can provide js to it? It is probably the easiest back-end... Lazarus is a different question. FPC itself is very doable.
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #7 on: July 08, 2017, 06:11:57 pm »
in fact the core of pascal can be easely targeted to a stack machine ... espesitaly its strictly typed ... the gui including lazarus is another story ... abstraxting a wisgetset is very very complex... i will investigate how unity did.it!
« Last Edit: July 08, 2017, 06:15:40 pm by Blestan »
Speak postscript or die!
Translate to pdf and live!

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: WebAssembly?
« Reply #8 on: July 08, 2017, 08:36:54 pm »
in fact the core of pascal can be easely targeted to a stack machine ... espesitaly its strictly typed ... the gui including lazarus is another story ... abstraxting a wisgetset is very very complex... i will investigate how unity did.it!
That's what i meant, we get our own things running, first the compiler, then the HMI/GUI.
PS.: I also don't know http://www.pilotlogic.com
« Last Edit: July 08, 2017, 08:38:37 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #9 on: July 08, 2017, 09:05:18 pm »
we do not have to reinvent the wheel ...we do not have to convert pas to wasm... i think that we have. 2 viable options:
1: llvm ir as a source for the wasm compiler... so fpc llvm taget must be booted
2. x86 to wasm  is also posible... so use fpc generated asm files ro feed the wasm compiler

take a look on that:
https://www.google.bg/url?sa=t&source=web&rct=j&url=https://mbebenita.github.io/WasmExplorer/&ved=0ahUKEwj43KvYsPrUAhUmEJoKHfxNB9sQFggxMAI&usg=AFQjCNG6rcqlNAoORXlmgQpkRJuUp19gcg
« Last Edit: July 08, 2017, 09:07:35 pm by Blestan »
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: WebAssembly?
« Reply #10 on: July 08, 2017, 09:37:44 pm »
in fact the core of pascal can be easely targeted to a stack machine ... espesitaly its strictly typed ... the gui including lazarus is another story ... abstraxting a wisgetset is very very complex... i will investigate how unity did.it!
No silly..... I am referring to the fact that pas2js is not feature complete. If it was... Lazarus was too, at least with an owner drawn (html5 canvas, which I already have) widgetset.
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #11 on: July 08, 2017, 09:48:33 pm »
@thaddy:what do you think about using llvm ir or x86 asm to feed  wasm compilation?
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: WebAssembly?
« Reply #12 on: July 08, 2017, 10:22:24 pm »
@thaddy:what do you think about using llvm ir or x86 asm to feed  wasm compilation?
Well, that's also not feature complete.... wasm is designed to be fed by js. Re-use existing skills. Sorry, you do not seem to know (but pretend to know) much about toolchains or - more important - compiler engineering in general. Nuance: I write compilers (security related) on an almost  monthly basis, but nothing near as complex as a Pascal compiler. It's the only job I have  8-) O:-) (But i don't need it)
« Last Edit: July 08, 2017, 10:32:13 pm by Thaddy »
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: WebAssembly?
« Reply #13 on: July 08, 2017, 10:36:28 pm »
 js ?
https://mbebenita.github.io/WasmExplorer/
 O:-)
looks more like c / c++ to me ;)
Speak postscript or die!
Translate to pdf and live!

Benjiro

  • Guest
Re: WebAssembly?
« Reply #14 on: July 08, 2017, 10:56:09 pm »
Well, that's also not feature complete.... wasm is designed to be fed by js.

I was under the impression that WebAssembly for the actually running on the browser: "WebAssembly must currently be loaded and compiled by JavaScript". That is the wasm file that gets send by the server, to the browser. It will surprise me that C/C++/Rust all have some JS-Wasm conversion going in. Quote: "WebAssembly code defines an AST (Abstract Syntax Tree) represented in a binary format.".

Unless you are referring to the fact that currently WebAssembly module do not have access to the browser dome. And yes, by that definition wasm needs to be fed by JS. But its kind of a crude explanation and will only confuse people. And is irrelevant to the question if FreePascal is able to generate wasm files.

The goal is that in the next version of wasm that it can access the browser dome without using any JS. Making it possible for any compile language to write wasm modules without any JS code involved at the frontend.

In simple term so everybody can understand the idea is:

* C/C++/FreePascal generate a AST with actual code, think of it as a simplified instruction set.
* This wasm file is send to the browser + accompanying JS file to initialize/compile the wasm on the front end.
* The browser receives the file, initialize it. JS is used to interact between the wasm and the browser dome.

In the future, the goal is that no JS is needed for the initialize and dome interaction and a single pure wasm file. But that is still some time away. Similar to the standard GC for Web Assembly.

 

TinyPortal © 2005-2018