# ATS+Emscripten

**URL:** <https://discourse.ats-lang.org/t/ats-emscripten/365>\
**Category:** Google Group\
**Created:** [October 19, 2015, 1:01pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365 "2015-10-19T13:01:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 19, 2015, 1:01pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/1 "2015-10-19T13:01:57Z")

</div>

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:

> **[githwxi/ATS-Postiats](https://github.com/githwxi/ATS-Postiats/tree/master/doc/EXAMPLE/JS-emscripten)**
>
> ATS2: Unleashing the Potentials of Types and Templates - githwxi/ATS-Postiats

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.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 21, 2015, 11:54am UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/2 "2015-10-21T11:54:52Z")

</div>

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 [zht...@gmail.com](mailto:zht...@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](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-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![H\_Zhang](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@H\_Zhang](https://discourse.ats-lang.org/u/H_Zhang)\
**Post date:** [October 21, 2015, 10:41pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/3 "2015-10-21T22:41:35Z")

</div>

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.On Wednesday, October 21, 2015 at 3:25:56 PM UTC-7, Brandon Barker wrote:

> 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)?
> 
> On Wed, Oct 21, 2015 at 6:01 PM, gmhwxi \<[gmh...@gmail.com](mailto:gmh...@gmail.com) \<javascript:\>\> wrote:
> 
> > 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](mailto: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](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...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > > > \<javascript:\>.  
> > > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > –  
> > > 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...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > > \<javascript:\>.  
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](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/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> 
> –  
> Brandon Barker  
> [brand...@gmail.com](mailto:brand...@gmail.com) \<javascript:\>

---

<div class="post-metadata">

**Author:** ![H\_Zhang](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@H\_Zhang](https://discourse.ats-lang.org/u/H_Zhang)\
**Post date:** [October 22, 2015, 2:45am UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/4 "2015-10-22T02:45:01Z")

</div>

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.

HaitaoOn Wednesday, October 21, 2015 at 6:53:42 PM UTC-7, gmhwxi wrote:

> Atscc2js can only compile an ML-like subset of ATS. In particular,  
> it does not handle pointers, which are abundantly used in patsopt.
> 
> On Wednesday, October 21, 2015 at 6:29:27 PM UTC-4, H Zhang wrote:
> 
> > 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.
> > 
> > On Wednesday, October 21, 2015 at 3:01:55 PM UTC-7, gmhwxi wrote:
> > 
> > > 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](mailto: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](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...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).  
> > > > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [October 21, 2015, 10:25pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/5 "2015-10-21T22:25:36Z")

</div>

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)?On Wed, Oct 21, 2015 at 6:01 PM, gmhwxi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> 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](mailto: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](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-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> > > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > –  
> > 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](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](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/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/594efae0-a344-4f3f-9065-2a98908bde2a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .

Brandon Barker  
[brandon...@gmail.com](mailto:brandon...@gmail.com)

---

<div class="post-metadata">

**Author:** ![H\_Zhang](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@H\_Zhang](https://discourse.ats-lang.org/u/H_Zhang)\
**Post date:** [October 21, 2015, 10:29pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/6 "2015-10-21T22:29:27Z")

</div>

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.On Wednesday, October 21, 2015 at 3:01:55 PM UTC-7, gmhwxi wrote:

> 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](mailto: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](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...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > > \<javascript:\>.  
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .

---

<div class="post-metadata">

**Author:** ![H\_Zhang](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@H\_Zhang](https://discourse.ats-lang.org/u/H_Zhang)\
**Post date:** [October 21, 2015, 5:24am UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/7 "2015-10-21T05:24:44Z")

</div>

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?

HaitaoOn 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](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.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 22, 2015, 11:28am UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/8 "2015-10-22T11:28:13Z")

</div>

Also, various libc functions (e.g., fopen) needs to be replaced, which  
requires a lot of work.On Wednesday, October 21, 2015 at 10:45:01 PM UTC-4, H Zhang wrote:

> I see. The C instruction set  
> [https://github.com/githwxi/ATS-Postiats/blob/master/ccomp/runtime/pats\_ccomp\_instrset.h](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
> 
> On Wednesday, October 21, 2015 at 6:53:42 PM UTC-7, gmhwxi wrote:
> 
> > Atscc2js can only compile an ML-like subset of ATS. In particular,  
> > it does not handle pointers, which are abundantly used in patsopt.
> > 
> > On Wednesday, October 21, 2015 at 6:29:27 PM UTC-4, H Zhang wrote:
> > 
> > > 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.
> > > 
> > > On Wednesday, October 21, 2015 at 3:01:55 PM UTC-7, gmhwxi wrote:
> > > 
> > > > 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](mailto: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](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...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > > > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).  
> > > > > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 22, 2015, 1:53am UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/9 "2015-10-22T01:53:41Z")

</div>

Atscc2js can only compile an ML-like subset of ATS. In particular,  
it does not handle pointers, which are abundantly used in patsopt.On Wednesday, October 21, 2015 at 6:29:27 PM UTC-4, H Zhang wrote:

> 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.
> 
> On Wednesday, October 21, 2015 at 3:01:55 PM UTC-7, gmhwxi wrote:
> 
> > 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](mailto: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](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...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).  
> > > > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 21, 2015, 10:01pm UTC](https://discourse.ats-lang.org/t/ats-emscripten/365/10 "2015-10-21T22:01:55Z")

</div>

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](mailto: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](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-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/47bcb600-9bf4-4798-97b2-cb7764b86e54%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
