ATS+Emscripten

50 views
Skip to first unread message

gmhwxi

unread,
Oct 19, 2015, 9:01:57 AM10/19/15
to ats-lang-users

Emscripten is a compiler for translating LLVM in to JavaScript.
I added a few examples in the following directory showing how ATS and
Emscripten can be used together:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/JS-emscripten

There are now two ways of generating JS from ATS source:

1) ATS -> C -(via Atscc2js)-> JS
2) ATS -> C -(via Emscripten)-> JS

JS code generated from 1) and 2) can actually be combined for use. The fact2 example
in the above directory is such a case.

H Zhang

unread,
Oct 21, 2015, 1:24:45 AM10/21/15
to ats-lang-users
Which one do you expect people to use in the long term? I thought ATS translated C is rather close to assembly and JS engines have optimizing JIT compiling. It is interesting to note that Google's Dart VM does not use byte code as they claim it is better to JIT from source.

One thing I've read is that asm.js does not currently support GC. So does Emscipten compiled ATS support GC or no?

Haitao

Hongwei Xi

unread,
Oct 21, 2015, 7:54:53 AM10/21/15
to ats-lan...@googlegroups.com
I would use both. Compared to Emscripten, Atscc2js make it so much easier
for ATS to interact with JS. I often use Atscc2js to do what I call ATS and JS
co-programming. For writing performant JS code, going the Emscripten route should
likely be a sensible option.

To use GC in the JS code generated by Emscripten, one needs to compile a garbage
collector (like libgc) to JS via Emscripten. I have not tried it yet. Of course, using
linear types to avoid GC is another option, especially, for performant code.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com.

gmhwxi

unread,
Oct 21, 2015, 6:01:55 PM10/21/15
to ats-lang-users

The GC issue actually came up today.

When I ran patsopt in the browser, it worked the first time
(to generate C code correctly) but it did not work the second
time. I guess that this was due to excessive use of memory.

To circumvent the issue, I had to reload the JS script for patsopt
after using it once :(


On Wednesday, October 21, 2015 at 7:54:53 AM UTC-4, gmhwxi wrote:
I would use both. Compared to Emscripten, Atscc2js make it so much easier
for ATS to interact with JS. I often use Atscc2js to do what I call ATS and JS
co-programming. For writing performant JS code, going the Emscripten route should
likely be a sensible option.

To use GC in the JS code generated by Emscripten, one needs to compile a garbage
collector (like libgc) to JS via Emscripten. I have not tried it yet. Of course, using
linear types to avoid GC is another option, especially, for performant code.

On Wed, Oct 21, 2015 at 1:24 AM, H Zhang <zh...@gmail.com> wrote:
Which one do you expect people to use in the long term? I thought ATS translated C is rather close to assembly and JS engines have optimizing JIT compiling. It is interesting to note that Google's Dart VM does not use byte code as they claim it is better to JIT from source.

One thing I've read is that asm.js does not currently support GC. So does Emscipten compiled ATS support GC or no?

Haitao

On Monday, October 19, 2015 at 6:01:57 AM UTC-7, gmhwxi wrote:

Emscripten is a compiler for translating LLVM in to JavaScript.
I added a few examples in the following directory showing how ATS and
Emscripten can be used together:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/JS-emscripten

There are now two ways of generating JS from ATS source:

1) ATS -> C -(via Atscc2js)-> JS
2) ATS -> C -(via Emscripten)-> JS

JS code generated from 1) and 2) can actually be combined for use. The fact2 example
in the above directory is such a case.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

Brandon Barker

unread,
Oct 21, 2015, 6:25:56 PM10/21/15
to ats-lang-users
I've never used emscripten, so I don't quite understand why you would need a GC for it. Won't the browser's javascript engine use GC regardless of how the javascript was generated (admittedly perhaps unpredictably, as always)?

To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.

H Zhang

unread,
Oct 21, 2015, 6:29:27 PM10/21/15
to ats-lang-users
Is atscc2js compiled js not fast enough? Since GC pause is not an issue here and I remember ats compilers are quite fast, I would hope the js version should just work.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.

H Zhang

unread,
Oct 21, 2015, 6:41:36 PM10/21/15
to ats-lang-users
I have not used emscripten either but as I understand it the idea is that asm.js emulates the virtual memory with a large array. When you compile with emscripten pointers become indices into the array. The supporting browsers have the choice of translating the restricted js of asm.js back into native code and run the native code directly and just trap foreign (in this case javascript) calls like a hypervisor would (essentially you have an embedded hypervisor in your browser). However whether ahead of time compilation is supported or not, as far as js is concerned the whole thing is a big blob so it can't GC any objects embedded in the array as it has no idea of how structures are embedded in the array (managed by indices translated from pointers). If your code is from a manually managed C/C++ code you are okay. But if your code is allocation happy like ML you will run out of memory eventually.

gmhwxi

unread,
Oct 21, 2015, 9:53:42 PM10/21/15
to ats-lang-users
Atscc2js can only compile an ML-like subset of ATS. In particular,
it does not handle pointers, which are abundantly used in patsopt.

H Zhang

unread,
Oct 21, 2015, 10:45:01 PM10/21/15
to ats-lang-users
I see. The C instruction set https://github.com/githwxi/ATS-Postiats/blob/master/ccomp/runtime/pats_ccomp_instrset.h is a bit incongruent with js semantics. I was actually surprised that the js code was generated from the c code. Is it possible to tweak the instructions and generate js code directly? The underlying concepts should be translatable? For heap allocations one can translate ATS_MALLOC into a returning a js array; pointer arithmetic into index arithmetic; and free into null assignment. On stack arrays can be treated similarly. Other pointer semantics need to be replaced with value semantics of js objects.

Haitao

gmhwxi

unread,
Oct 22, 2015, 7:28:14 AM10/22/15
to ats-lang-users
Also, various libc functions (e.g., fopen) needs to be replaced, which
requires a lot of work.
Reply all
Reply to author
Forward
0 new messages