atscc2js examples

79 views
Skip to first unread message

gmhwxi

unread,
Nov 6, 2014, 2:14:39 AM11/6/14
to ats-lan...@googlegroups.com
In the past, I used animation to teach recursion
and various sorting algorithms. The animation in my code
was GTK-based. I rewrote a portion of the code I used so
that the animation can now be done in Javascript:

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

The source of these examples is at:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/JSmydraw

Some of these examples can be tested using Patsoptaas (Patsopt-as-a-Service):

http://www.ats-lang.org/Examples.html

Cheers!

Yannick Duchêne

unread,
May 10, 2015, 11:18:20 AM5/10/15
to ats-lan...@googlegroups.com
Just wanted to mention Closure which may be worth used on ATS generated JavaScript, for two reasons:

  * It support inlining, which is welcome for function wrapping JavaScript expressions (ex from `bool.sats` and others);
  * It can be invoked so that it checks for missing references, which is welcome as there is otherwise no compilation phase as with the C target, to be sure to be hinted about undefined references.

I checked it has this behaviour using these options:

--compilation_level ADVANCED --language_in ECMASCRIPT5_STRICT -language_out ECMASCRIPT5_STRICT --warning_level VERBOSE

If I understand correctly, using `--compilation_level ADVANCED` not only ends into inlining when applicable, but also make Closure report more errors (I still have undefined reference in mind).

Also, an option which I believe is nice too, is the ability to preserve a comment, using a JSDoc block comment starting with `@preserver`. I will use this one, at the top of each files to tell people it's JavaScript generated from ATS:

/**
* @preserve JavaScript generated
* from [ATS (Applied Type system)](http://www.ats-lang.org) source
* then minified using [Closure](http://developers.google.com/closure/).
*/



Yannick Duchêne

unread,
May 10, 2015, 11:30:22 AM5/10/15
to ats-lan...@googlegroups.com


Le dimanche 10 mai 2015 17:18:20 UTC+2, Yannick Duchêne a écrit :
Just wanted to mention Closure which may be worth used on ATS generated JavaScript, for two reasons:

  * It support inlining, which is welcome for function wrapping JavaScript expressions (ex from `bool.sats` and others);
  * It can be invoked so that it checks for missing references, which is welcome as there is otherwise no compilation phase as with the C target, to be sure to be hinted about undefined references.


I also just checked to get the best of inlining, ES5 getters/setters should not be used, as Closure does a far better job at inlining classical function definition (like getXYZ()/setXYZ(xyz)) than setters and getters, which seems to not be inlined at all.

I'm dropping this note without knowing if there are people who really use getters/setters for ATS to JavaScript, still good to know it may not give the best with regard to minification and inlining.

gmhwxi

unread,
May 10, 2015, 12:07:42 PM5/10/15
to ats-lan...@googlegroups.com
Thanks.

I also did a bit investigation on Closure last night.
Here is a simple procedure that formed in my mind:

Say I have a project called myproject. I do ATS+JS co-programming.
At the end I produce a single file myproject.js. Then I will use Closure
to compile myproject.js+libatscc2js_all.js together to generate another file
myproject_final.js, which is the final output of myproject.

Yannick Duchêne

unread,
May 10, 2015, 12:38:28 PM5/10/15
to ats-lan...@googlegroups.com


Le dimanche 10 mai 2015 18:07:42 UTC+2, gmhwxi a écrit :
Thanks.

I also did a bit investigation on Closure last night.
Here is a simple procedure that formed in my mind:

Say I have a project called myproject. I do ATS+JS co-programming.
At the end I produce a single file myproject.js. Then I will use Closure
to compile myproject.js+libatscc2js_all.js together to generate another file
myproject_final.js, which is the final output of myproject.

The same for me.

I get libatscc2js_all.js from https://gist.github.com/githwxi/c754d1fbea087ffb9e93 , as this was part of my installation (don't know if I once again something wrong).

I had to remove the BaconJS part and add `var tmplab_js` and `var tmplab` at some places, otherwise there was undefined reference errors (nice it works and really make it fail).

There remains just some warnings, but it works and the result it a working JavaScript file, with really just what's necessary, and nothing more.

Except the dirty had-oc fixes in libatscc2js_all.js, it's all nice.

This minifier is a must-have for ATS+JavaScript.

Yannick Duchêne

unread,
May 10, 2015, 12:39:29 PM5/10/15
to ats-lan...@googlegroups.com

I get libatscc2js_all.js from https://gist.github.com/githwxi/c754d1fbea087ffb9e93 , as this was part of my installation (don't know if I once again something wrong).


Oops, typo. I wanted to say “as this was *not* part of […]” 

gmhwxi

unread,
May 10, 2015, 12:55:54 PM5/10/15
to ats-lan...@googlegroups.com
Bacon.js will be removed for libatscc2js_all.js soon.

I added it mainly as a quick way to allow people taking my class to gain
some experience with functional reactive programming (FRP).

I will look into the issue of tmplab ad tmplab_js. Maybe you could show me
a file where you had to manually add things like 'var tmplab' and 'var tmplab_js'.

Yannick Duchêne

unread,
May 10, 2015, 2:43:19 PM5/10/15
to ats-lan...@googlegroups.com


Le dimanche 10 mai 2015 18:55:54 UTC+2, gmhwxi a écrit :

I will look into the issue of tmplab ad tmplab_js. Maybe you could show me
a file where you had to manually add things like 'var tmplab' and 'var tmplab_js'.


I get the error with something as simple as this:

#include "share/atspre_define.hats"
#include "{$LIBATSCC2JS}/staloadall.hats"

#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME "js_main_dynload"

%{$
  js_main_dynload
()
%}


The errors are:

./libatscc2js_all.js:1400: ERROR - variable tmplab_js is undeclared
  tmplab_js
= 1;
 
^
./libatscc2js_all.js:1402: ERROR - variable tmplab is undeclared
    tmplab
= tmplab_js; tmplab_js = 0;
   
^
2 error(s), 0 warning(s)
*** Exited with status 2 ***

It's in `function ats2jspre_list_make_intrange_3(arg0, arg1, arg2)` , but also forward, as it displays a missing definition error only once per identifier.


gmhwxi

unread,
May 10, 2015, 4:02:43 PM5/10/15
to ats-lan...@googlegroups.com
Thanks!

I think I have fixed this issue. New libatscc2js_all.js has been uploaded.

Yannick Duchêne

unread,
May 10, 2015, 4:15:40 PM5/10/15
to ats-lan...@googlegroups.com


Le dimanche 10 mai 2015 22:02:43 UTC+2, gmhwxi a écrit :
Thanks!


 Thanks to you too!

If I may have one more question… I can't get a comment to stay in the generated file. If I add this at the top of `some_file.dats`:

%{^
/**
* @preserve JavaScript generated
* from [ATS (Applied Type System)](http://www.ats-lang.org) source

* then minified using [Closure](http://developers.google.com/closure/).
*/

%}


it does not appear in the generated JavaScript file. The `%{^` and `%}` is to insert a literal block before all the others, if I'm not wrong, but it seems to not be working with comments, which get replaced with this:

// COMMENT_line



gmhwxi

unread,
May 10, 2015, 5:16:59 PM5/10/15
to ats-lan...@googlegroups.com

I have just uploaded some changes to fix this issue.

gmhwxi

unread,
May 10, 2015, 8:39:46 PM5/10/15
to ats-lan...@googlegroups.com

I have taken out the Bacon.js wrapper for atscc2js, which can now be found here:

https://gist.githubusercontent.com/githwxi/c036945d0cae84cf9fc5/raw/libatscc2js_baconjs_cats.js
Reply all
Reply to author
Forward
0 new messages