Tetris: ATS+Bacon.js

244 views
Skip to first unread message

gmhwxi

unread,
May 2, 2015, 6:39:14 PM5/2/15
to ats-lan...@googlegroups.com

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

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:

http://ats-lang.sourceforge.net/COMPILED/doc/PROJECT/SMALL/JSmygame/Tetris/

Please help improve it (and have fun!).

Cheers!

--Hongwei

Chad Zawistowski

unread,
May 3, 2015, 9:31:32 PM5/3/15
to ats-lan...@googlegroups.com
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?

gmhwxi

unread,
May 3, 2015, 10:03:00 PM5/3/15
to ats-lan...@googlegroups.com
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 :)

gmhwxi

unread,
May 3, 2015, 10:05:23 PM5/3/15
to ats-lan...@googlegroups.com
One more thing:

I forgot to mention that atscc2js makes it very convenient to mix ATS code with JS code.

Yannick Duchêne

unread,
May 6, 2015, 4:50:35 PM5/6/15
to ats-lan...@googlegroups.com


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.

gmhwxi

unread,
May 6, 2015, 9:32:03 PM5/6/15
to ats-lan...@googlegroups.com

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.

Yannick Duchêne

unread,
May 9, 2015, 12:06:44 PM5/9/15
to ats-lan...@googlegroups.com
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.

Hongwei Xi

unread,
May 9, 2015, 12:39:09 PM5/9/15
to ats-lan...@googlegroups.com
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"
//


--
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/10db92af-cee9-46e9-8d1e-74e79b4ba33d%40googlegroups.com.

Yannick Duchêne

unread,
May 9, 2015, 1:53:16 PM5/9/15
to ats-lan...@googlegroups.com
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 . 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.

gmhwxi

unread,
May 9, 2015, 2:13:53 PM5/9/15
to ats-lan...@googlegroups.com
Try ATS2-0.1.12:

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

I tested the script on Cloud 9; it worked fine.

Yannick Duchêne

unread,
May 9, 2015, 3:12:09 PM5/9/15
to ats-lan...@googlegroups.com
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 :p .

I will stick to this procedure for future re-install or updates.
Message has been deleted

gmhwxi

unread,
Jun 21, 2015, 3:40:26 PM6/21/15
to ats-lan...@googlegroups.com

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

I wrote it for my cs320-summer-2015 class. Have fun!
Reply all
Reply to author
Forward
0 new messages