# Tetris: ATS+Bacon.js

**URL:** <https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618>\
**Category:** Google Group\
**Created:** [May 2, 2015, 10:39pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618 "2015-05-02T22:39:14Z")\
**Posts on this page:** 12\
**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:** [May 2, 2015, 10:39pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/1 "2015-05-02T22:39:14Z")

</div>

Here is an implementation of Tetris in ATS+Bacon.js:

> **[githwxi/ATS-Postiats-contrib](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)**
>
> ATS-Postiats-contrib is primarily for packages contributed to ATS-Postiats - githwxi/ATS-Postiats-contrib

The graphics for the game uses easel.js by createjs.

There is clearly a lot of room for improvement. Part of my purpose for  
writing the game was to test atscc2js, the compiler for translating into  
JavaScript the C output from ATS source. I myself find ATS+JavaScript  
co-programming to be very interesting.

If you want to play with it:

[http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)

Please help improve it (and have fun!).

Cheers!

–Hongwei

---

<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:** [May 7, 2015, 1:32am UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/2 "2015-05-07T01:32:03Z")

</div>

Emscripten is far more general than necessary for compiling the C code  
generated from ATS source.

If I have an implementation already written in C and want to translate it  
into JS,  
then using Emscripten makes sense. If I want to implement something to run  
in  
browsers, then doing ATS+JS co-programming (with atscc2js) makes more sense.On Wednesday, May 6, 2015 at 4:50:35 PM UTC-4, Yannick Duchêne wrote:

> Le lundi 4 mai 2015 03:31:32 UTC+2, Chad Zawistowski a écrit :
> 
> > I wonder what the differences are between compiling to Javascript  
> > directly, versus compiling to C and then using Emscripten to convert from C  
> > to optimized asm.js? That’s a more complicated toolchain, but it’s also  
> > less compiler code to maintain. I wonder how it would affect performance?  
> > Or ease of interacting with other javascript code?
> 
> My personal theoretical opinion is: the path which goes from ATS to  
> JavaScript, may be safer, as it requires less assumptions and as Emscripten  
> has a lot of dependencies, which to me means more opportunities for an  
> error somewhere.
> 
> Now, I don’t know if this theoretical opinion is confirmed in practice.

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [May 9, 2015, 4:06pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/3 "2015-05-09T16:06:43Z")

</div>

This thread may be the opportunity for a basic question: what’s the  
recommended path to get a working atscc2js?

I installed ATS/Postiats 0.1.11, compiled astcc2js with it, but running  
`patsopt -d test.dats | atscc2js -o test_dats.js` I either get an error  
about a missing (not available for staloading) `STATS/option.sats` if I use  
the libatscc2js from contrib from SourceForge or syntax errors (“the  
syntactic entity [xyz] is needed”) if I use the libatscc2js from contrib  
from GitHub.

I wanted to test if ATS typing can help me with maintenance issues I have  
with some JavaScript.Le dimanche 3 mai 2015 00:39:14 UTC+2, gmhwxi a écrit :

> Here is an implementation of Tetris in ATS+Bacon.js:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> 
> The graphics for the game uses easel.js by createjs.
> 
> There is clearly a lot of room for improvement. Part of my purpose for  
> writing the game was to test atscc2js, the compiler for translating into  
> JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> co-programming to be very interesting.
> 
> If you want to play with it:
> 
> [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> 
> Please help improve it (and have fun!).
> 
> Cheers!
> 
> –Hongwei

---

<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:** [May 4, 2015, 2:05am UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/4 "2015-05-04T02:05:23Z")

</div>

One more thing:

I forgot to mention that atscc2js makes it very convenient to mix ATS code  
with JS code.On Sunday, May 3, 2015 at 10:03:00 PM UTC-4, gmhwxi wrote:

> We tried both:
> 
> 1. ATS → C -(atscc2js)-\> JS
> 2. ATS → C -(emscripten)-\> JS
> 
> Actually, Will Blair first tried (2).
> 
> Right now, (2) is clearly much more powerful as it essentially has the  
> full library support of ATS.
> 
> I use (1) mostly for the teaching purpose. Also, I use (1) because I can  
> gradually build library support  
> not only for atscc2js but also for atscc2py, atscc2php, atscc2pl, etc.  
> Maybe for atscc2erl in the future 🙂
> 
> On Sunday, May 3, 2015 at 9:31:32 PM UTC-4, Chad Zawistowski wrote:
> 
> > I wonder what the differences are between compiling to Javascript  
> > directly, versus compiling to C and then using Emscripten to convert from C  
> > to optimized asm.js? That’s a more complicated toolchain, but it’s also  
> > less compiler code to maintain. I wonder how it would affect performance?  
> > Or ease of interacting with other javascript code?
> > 
> > On Saturday, May 2, 2015 at 3:39:14 PM UTC-7, gmhwxi wrote:
> > 
> > > Here is an implementation of Tetris in ATS+Bacon.js:
> > > 
> > > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > > 
> > > The graphics for the game uses easel.js by createjs.
> > > 
> > > There is clearly a lot of room for improvement. Part of my purpose for  
> > > writing the game was to test atscc2js, the compiler for translating into  
> > > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > > co-programming to be very interesting.
> > > 
> > > If you want to play with it:
> > > 
> > > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > > 
> > > Please help improve it (and have fun!).
> > > 
> > > Cheers!
> > > 
> > > –Hongwei

---

<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:** [June 21, 2015, 7:40pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/5 "2015-06-21T19:40:26Z")

</div>

Here is a version of tetris that has a button for auto-play:

[http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/tetris.html](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/tetris.html)

I wrote it for my cs320-summer-2015 class. Have fun!On Saturday, May 2, 2015 at 6:39:14 PM UTC-4, gmhwxi wrote:

> Here is an implementation of Tetris in ATS+Bacon.js:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> 
> The graphics for the game uses easel.js by createjs.
> 
> There is clearly a lot of room for improvement. Part of my purpose for  
> writing the game was to test atscc2js, the compiler for translating into  
> JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> co-programming to be very interesting.
> 
> If you want to play with it:
> 
> [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> 
> Please help improve it (and have fun!).
> 
> Cheers!
> 
> –Hongwei

---

<div class="post-metadata">

**Author:** ![Chad\_Zawistowski](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@Chad\_Zawistowski](https://discourse.ats-lang.org/u/Chad_Zawistowski)\
**Post date:** [May 4, 2015, 1:31am UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/6 "2015-05-04T01:31:32Z")

</div>

I wonder what the differences are between compiling to Javascript directly,  
versus compiling to C and then using Emscripten to convert from C to  
optimized asm.js? That’s a more complicated toolchain, but it’s also less  
compiler code to maintain. I wonder how it would affect performance? Or  
ease of interacting with other javascript code?On Saturday, May 2, 2015 at 3:39:14 PM UTC-7, gmhwxi wrote:

> Here is an implementation of Tetris in ATS+Bacon.js:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> 
> The graphics for the game uses easel.js by createjs.
> 
> There is clearly a lot of room for improvement. Part of my purpose for  
> writing the game was to test atscc2js, the compiler for translating into  
> JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> co-programming to be very interesting.
> 
> If you want to play with it:
> 
> [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> 
> Please help improve it (and have fun!).
> 
> Cheers!
> 
> –Hongwei

---

<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:** [May 9, 2015, 6:13pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/7 "2015-05-09T18:13:53Z")

</div>

Try ATS2-0.1.12:

> <https://gist.github.com/githwxi/7e31f4fd4df92125b73c>

I tested the script on Cloud 9; it worked fine.On Saturday, May 9, 2015 at 1:53:16 PM UTC-4, Yannick Duchêne wrote:

> Trying to compile the recently introduced Tetris, I got this:
> 
> /home/yannick/apps/ats/lib/ats2-postiats-0.1.11/bin/atscc2js -o  
> tetris\_dats.js -i tetris\_dats.c  
> Hello from atscc2js!  
> ParsingErrors:  
> : 24(line=3, offs=1) – 30(line=3, offs=7): error(parsing): the keyword  
> [EOF] is needed.  
> exit(ATS): uncaught exception at run-time:  
> /home/yannick/Applications/Third\_Parties/ATS/ATSCC2JS/catsparse.sats:FatalErrorExn(1024)  
> make: \*\*\* [tetris\_dats.js] Erreur 1
> 
> The test file is just the Hello-word from the ATS site:  
> [http://www.ats-lang.org/Patsoptaas.html](http://www.ats-lang.org/Patsoptaas.html) . Saved as `test.dats` and  
> running `patsopt -d test.dats | atscc2js -o test_dats.js`, I get this:
> 
> Hello from atscc2js!  
> […]/libatscc/DATS/list.dats: 4029(line=271, offs=5) – 4033(line=271,  
> offs=9): error(parsing): the syntactic entity [p0at] is needed.  
> […]/libatscc/DATS/list.dats: 4025(line=271, offs=1) – 4028(line=271,  
> offs=4): error(parsing): the keyword [in] is needed.  
> […]/libatscc/DATS/list.dats: 4018(line=269, offs=6) – 4021(line=269,  
> offs=9): error(parsing): the syntactic entity [d0exp] is needed.  
> […]/libatscc/DATS/list.dats: 4002(line=267, offs=1) – 4004(line=267,  
> offs=3): error(parsing): the keyword [end] is needed.  
> […]/libatscc/DATS/list.dats: 3959(line=261, offs=13) – 3962(line=261,  
> offs=16): error(parsing): the syntactic entity [d0exp] is needed.  
> […]/libatscc/DATS/list.dats: 3922(line=259, offs=1) – 3931(line=259,  
> offs=10): error(parsing): the token is discarded.  
> exit(ATS): uncaught exception:  
> \_2home\_2hwxi\_2research\_2Postiats\_2git\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> 
> I don’t know what’s wrong with my installation, as it works online.
> 
> Le samedi 9 mai 2015 18:39:09 UTC+2, gmhwxi a écrit :
> 
> > If I could take a look at the file test.dats you used, I may be able to  
> > see what the cause was.
> > 
> > Basically, you need the following two lines to tell the ATS compiler  
> > (patsopt) how to handle  
> > templates for the purpose of generating JS code:
> > 
> > //  
> > #include “share/atspre\_define.hats”  
> > #include “{$LIBATSCC2JS}/staloadall.hats”  
> > //
> > 
> > On Sat, May 9, 2015 at 12:06 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)\> wrote:
> > 
> > > This thread may be the opportunity for a basic question: what’s the  
> > > recommended path to get a working atscc2js?
> > > 
> > > I installed ATS/Postiats 0.1.11, compiled astcc2js with it, but running  
> > > `patsopt -d test.dats | atscc2js -o test_dats.js` I either get an error  
> > > about a missing (not available for staloading) `STATS/option.sats` if I use  
> > > the libatscc2js from contrib from SourceForge or syntax errors (“the  
> > > syntactic entity [xyz] is needed”) if I use the libatscc2js from contrib  
> > > from GitHub.
> > > 
> > > I wanted to test if ATS typing can help me with maintenance issues I  
> > > have with some JavaScript.
> > > 
> > > Le dimanche 3 mai 2015 00:39:14 UTC+2, gmhwxi a écrit :
> > > 
> > > > Here is an implementation of Tetris in ATS+Bacon.js:
> > > > 
> > > > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > > > 
> > > > The graphics for the game uses easel.js by createjs.
> > > > 
> > > > There is clearly a lot of room for improvement. Part of my purpose for  
> > > > writing the game was to test atscc2js, the compiler for translating into  
> > > > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > > > co-programming to be very interesting.
> > > > 
> > > > If you want to play with it:
> > > > 
> > > > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > > > 
> > > > Please help improve it (and have fun!).
> > > > 
> > > > Cheers!
> > > > 
> > > > –Hongwei
> > > 
> > > –  
> > > 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/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%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:** [May 4, 2015, 2:03am UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/8 "2015-05-04T02:03:00Z")

</div>

We tried both:

1. ATS → C -(atscc2js)-\> JS
2. ATS → C -(emscripten)-\> JS

Actually, Will Blair first tried (2).

Right now, (2) is clearly much more powerful as it essentially has the full  
library support of ATS.

I use (1) mostly for the teaching purpose. Also, I use (1) because I can  
gradually build library support  
not only for atscc2js but also for atscc2py, atscc2php, atscc2pl, etc.  
Maybe for atscc2erl in the future :)On Sunday, May 3, 2015 at 9:31:32 PM UTC-4, Chad Zawistowski wrote:

> I wonder what the differences are between compiling to Javascript  
> directly, versus compiling to C and then using Emscripten to convert from C  
> to optimized asm.js? That’s a more complicated toolchain, but it’s also  
> less compiler code to maintain. I wonder how it would affect performance?  
> Or ease of interacting with other javascript code?
> 
> On Saturday, May 2, 2015 at 3:39:14 PM UTC-7, gmhwxi wrote:
> 
> > Here is an implementation of Tetris in ATS+Bacon.js:
> > 
> > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > 
> > The graphics for the game uses easel.js by createjs.
> > 
> > There is clearly a lot of room for improvement. Part of my purpose for  
> > writing the game was to test atscc2js, the compiler for translating into  
> > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > co-programming to be very interesting.
> > 
> > If you want to play with it:
> > 
> > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > 
> > Please help improve it (and have fun!).
> > 
> > Cheers!
> > 
> > –Hongwei

---

<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:** [May 9, 2015, 4:39pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/9 "2015-05-09T16:39:09Z")

</div>

If I could take a look at the file test.dats you used, I may be able to see  
what the cause was.

Basically, you need the following two lines to tell the ATS compiler  
(patsopt) how to handle  
templates for the purpose of generating JS code:

//  
#include “share/atspre\_define.hats”  
#include “{$LIBATSCC2JS}/staloadall.hats”  
//On Sat, May 9, 2015 at 12:06 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com)\> wrote:

> This thread may be the opportunity for a basic question: what’s the  
> recommended path to get a working atscc2js?
> 
> I installed ATS/Postiats 0.1.11, compiled astcc2js with it, but running  
> `patsopt -d test.dats | atscc2js -o test_dats.js` I either get an error  
> about a missing (not available for staloading) `STATS/option.sats` if I use  
> the libatscc2js from contrib from SourceForge or syntax errors (“the  
> syntactic entity [xyz] is needed”) if I use the libatscc2js from contrib  
> from GitHub.
> 
> I wanted to test if ATS typing can help me with maintenance issues I have  
> with some JavaScript.
> 
> Le dimanche 3 mai 2015 00:39:14 UTC+2, gmhwxi a écrit :
> 
> > Here is an implementation of Tetris in ATS+Bacon.js:
> > 
> > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > 
> > The graphics for the game uses easel.js by createjs.
> > 
> > There is clearly a lot of room for improvement. Part of my purpose for  
> > writing the game was to test atscc2js, the compiler for translating into  
> > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > co-programming to be very interesting.
> > 
> > If you want to play with it:
> > 
> > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > 
> > Please help improve it (and have fun!).
> > 
> > Cheers!
> > 
> > –Hongwei
> 
> –  
> 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/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [May 6, 2015, 8:50pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/10 "2015-05-06T20:50:35Z")

</div>

> I wonder what the differences are between compiling to Javascript  
> directly, versus compiling to C and then using Emscripten to convert from C  
> to optimized asm.js? That’s a more complicated toolchain, but it’s also  
> less compiler code to maintain. I wonder how it would affect performance?  
> Or ease of interacting with other javascript code?

My personal theoretical opinion is: the path which goes from ATS to  
JavaScript, may be safer, as it requires less assumptions and as Emscripten  
has a lot of dependencies, which to me means more opportunities for an  
error somewhere.

Now, I don’t know if this theoretical opinion is confirmed in practice.

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [May 9, 2015, 7:12pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/11 "2015-05-09T19:12:09Z")

</div>

I did this, just installed git before (may be added to the script, as it’s  
not installed as a default), added `--prefix=/home/<directory>` as an  
option to configure on line 42, executed the script, executed `make install`, then moved  
`ATS2-contrib/projects/MEDIUM/CATS-parsemit/JavaScript/atscc2js` to  
`<directory>/lib/ats2-postiats-0.1.11/bin`, added a script similar to that  
for `patscc`, but for `atscc2js` in `<directory>/bin`.

Now it’s fine, the test files compiles, as well the Tetris game.

Thanks to you and your students, I may have a Tetris time tonight 😛 .

I will stick to this procedure for future re-install or updates.Le samedi 9 mai 2015 20:13:53 UTC+2, gmhwxi a écrit :

> Try ATS2-0.1.12:
> 
> [A shell script for installing ATS2 + ATS2-contrib · GitHub](https://gist.github.com/githwxi/7e31f4fd4df92125b73c)
> 
> I tested the script on Cloud 9; it worked fine.
> 
> On Saturday, May 9, 2015 at 1:53:16 PM UTC-4, Yannick Duchêne wrote:
> 
> > Trying to compile the recently introduced Tetris, I got this:
> > 
> > /home/yannick/apps/ats/lib/ats2-postiats-0.1.11/bin/atscc2js -o  
> > tetris\_dats.js -i tetris\_dats.c  
> > Hello from atscc2js!  
> > ParsingErrors:  
> > : 24(line=3, offs=1) – 30(line=3, offs=7): error(parsing): the keyword  
> > [EOF] is needed.  
> > exit(ATS): uncaught exception at run-time:  
> > /home/yannick/Applications/Third\_Parties/ATS/ATSCC2JS/catsparse.sats:FatalErrorExn(1024)  
> > make: \*\*\* [tetris\_dats.js] Erreur 1
> > 
> > The test file is just the Hello-word from the ATS site:  
> > [http://www.ats-lang.org/Patsoptaas.html](http://www.ats-lang.org/Patsoptaas.html) . Saved as `test.dats` and  
> > running `patsopt -d test.dats | atscc2js -o test_dats.js`, I get this:
> > 
> > Hello from atscc2js!  
> > […]/libatscc/DATS/list.dats: 4029(line=271, offs=5) – 4033(line=271,  
> > offs=9): error(parsing): the syntactic entity [p0at] is needed.  
> > […]/libatscc/DATS/list.dats: 4025(line=271, offs=1) – 4028(line=271,  
> > offs=4): error(parsing): the keyword [in] is needed.  
> > […]/libatscc/DATS/list.dats: 4018(line=269, offs=6) – 4021(line=269,  
> > offs=9): error(parsing): the syntactic entity [d0exp] is needed.  
> > […]/libatscc/DATS/list.dats: 4002(line=267, offs=1) – 4004(line=267,  
> > offs=3): error(parsing): the keyword [end] is needed.  
> > […]/libatscc/DATS/list.dats: 3959(line=261, offs=13) – 3962(line=261,  
> > offs=16): error(parsing): the syntactic entity [d0exp] is needed.  
> > […]/libatscc/DATS/list.dats: 3922(line=259, offs=1) – 3931(line=259,  
> > offs=10): error(parsing): the token is discarded.  
> > exit(ATS): uncaught exception:  
> > \_2home\_2hwxi\_2research\_2Postiats\_2git\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> > 
> > I don’t know what’s wrong with my installation, as it works online.
> > 
> > Le samedi 9 mai 2015 18:39:09 UTC+2, gmhwxi a écrit :
> > 
> > > If I could take a look at the file test.dats you used, I may be able to  
> > > see what the cause was.
> > > 
> > > Basically, you need the following two lines to tell the ATS compiler  
> > > (patsopt) how to handle  
> > > templates for the purpose of generating JS code:
> > > 
> > > //  
> > > #include “share/atspre\_define.hats”  
> > > #include “{$LIBATSCC2JS}/staloadall.hats”  
> > > //
> > > 
> > > On Sat, May 9, 2015 at 12:06 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)\> wrote:
> > > 
> > > > This thread may be the opportunity for a basic question: what’s the  
> > > > recommended path to get a working atscc2js?
> > > > 
> > > > I installed ATS/Postiats 0.1.11, compiled astcc2js with it, but running  
> > > > `patsopt -d test.dats | atscc2js -o test_dats.js` I either get an error  
> > > > about a missing (not available for staloading) `STATS/option.sats` if I use  
> > > > the libatscc2js from contrib from SourceForge or syntax errors (“the  
> > > > syntactic entity [xyz] is needed”) if I use the libatscc2js from contrib  
> > > > from GitHub.
> > > > 
> > > > I wanted to test if ATS typing can help me with maintenance issues I  
> > > > have with some JavaScript.
> > > > 
> > > > Le dimanche 3 mai 2015 00:39:14 UTC+2, gmhwxi a écrit :
> > > > 
> > > > > Here is an implementation of Tetris in ATS+Bacon.js:
> > > > > 
> > > > > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > > > > 
> > > > > The graphics for the game uses easel.js by createjs.
> > > > > 
> > > > > There is clearly a lot of room for improvement. Part of my purpose for  
> > > > > writing the game was to test atscc2js, the compiler for translating  
> > > > > into  
> > > > > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > > > > co-programming to be very interesting.
> > > > > 
> > > > > If you want to play with it:
> > > > > 
> > > > > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > > > > 
> > > > > Please help improve it (and have fun!).
> > > > > 
> > > > > Cheers!
> > > > > 
> > > > > –Hongwei
> > > > 
> > > > –  
> > > > 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/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [May 9, 2015, 5:53pm UTC](https://discourse.ats-lang.org/t/tetris-ats-bacon-js/618/12 "2015-05-09T17:53:16Z")

</div>

Trying to compile the recently introduced Tetris, I got this:

/home/yannick/apps/ats/lib/ats2-postiats-0.1.11/bin/atscc2js -o  
tetris\_dats.js -i tetris\_dats.c  
Hello from atscc2js!  
ParsingErrors:  
: 24(line=3, offs=1) – 30(line=3, offs=7): error(parsing): the keyword  
[EOF] is needed.  
exit(ATS): uncaught exception at run-time:  
/home/yannick/Applications/Third\_Parties/ATS/ATSCC2JS/catsparse.sats:FatalErrorExn(1024)  
make: \*\*\* [tetris\_dats.js] Erreur 1

The test file is just the Hello-word from the ATS site:  
[http://www.ats-lang.org/Patsoptaas.html](http://www.ats-lang.org/Patsoptaas.html) . Saved as `test.dats` and running  
`patsopt -d test.dats | atscc2js -o test_dats.js`, I get this:

Hello from atscc2js!  
[…]/libatscc/DATS/list.dats: 4029(line=271, offs=5) – 4033(line=271,  
offs=9): error(parsing): the syntactic entity [p0at] is needed.  
[…]/libatscc/DATS/list.dats: 4025(line=271, offs=1) – 4028(line=271,  
offs=4): error(parsing): the keyword [in] is needed.  
[…]/libatscc/DATS/list.dats: 4018(line=269, offs=6) – 4021(line=269,  
offs=9): error(parsing): the syntactic entity [d0exp] is needed.  
[…]/libatscc/DATS/list.dats: 4002(line=267, offs=1) – 4004(line=267,  
offs=3): error(parsing): the keyword [end] is needed.  
[…]/libatscc/DATS/list.dats: 3959(line=261, offs=13) – 3962(line=261,  
offs=16): error(parsing): the syntactic entity [d0exp] is needed.  
[…]/libatscc/DATS/list.dats: 3922(line=259, offs=1) – 3931(line=259,  
offs=10): error(parsing): the token is discarded.  
exit(ATS): uncaught exception:  
\_2home\_2hwxi\_2research\_2Postiats\_2git\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)

I don’t know what’s wrong with my installation, as it works online.Le samedi 9 mai 2015 18:39:09 UTC+2, gmhwxi a écrit :

> If I could take a look at the file test.dats you used, I may be able to  
> see what the cause was.
> 
> Basically, you need the following two lines to tell the ATS compiler  
> (patsopt) how to handle  
> templates for the purpose of generating JS code:
> 
> //  
> #include “share/atspre\_define.hats”  
> #include “{$LIBATSCC2JS}/staloadall.hats”  
> //
> 
> On Sat, May 9, 2015 at 12:06 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com) \<javascript:\>\> wrote:
> 
> > This thread may be the opportunity for a basic question: what’s the  
> > recommended path to get a working atscc2js?
> > 
> > I installed ATS/Postiats 0.1.11, compiled astcc2js with it, but running  
> > `patsopt -d test.dats | atscc2js -o test_dats.js` I either get an error  
> > about a missing (not available for staloading) `STATS/option.sats` if I use  
> > the libatscc2js from contrib from SourceForge or syntax errors (“the  
> > syntactic entity [xyz] is needed”) if I use the libatscc2js from contrib  
> > from GitHub.
> > 
> > I wanted to test if ATS typing can help me with maintenance issues I have  
> > with some JavaScript.
> > 
> > Le dimanche 3 mai 2015 00:39:14 UTC+2, gmhwxi a écrit :
> > 
> > > Here is an implementation of Tetris in ATS+Bacon.js:
> > > 
> > > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmygame/Tetris)
> > > 
> > > The graphics for the game uses easel.js by createjs.
> > > 
> > > There is clearly a lot of room for improvement. Part of my purpose for  
> > > writing the game was to test atscc2js, the compiler for translating into  
> > > JavaScript the C output from ATS source. I myself find ATS+JavaScript  
> > > co-programming to be very interesting.
> > > 
> > > If you want to play with it:
> > > 
> > > [Index of /COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris](http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/)
> > > 
> > > Please help improve it (and have fun!).
> > > 
> > > Cheers!
> > > 
> > > –Hongwei
> > 
> > –  
> > 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/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
