Atscc2js examples

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:

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

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

Cheers!

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.

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) source
  • then minified using Closure.
    */Le jeudi 6 novembre 2014 08:14:39 UTC+1, gmhwxi a écrit :

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:

Index of /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!

Thanks!

I think I have fixed this issue. New libatscc2js_all.js has been uploaded.On Sunday, May 10, 2015 at 2:43:19 PM UTC-4, Yannick Duchêne wrote:

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.

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.

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:

%{^
/**

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

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
Library for JS code generated from ATS source · GitHub , 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.

I have just uploaded some changes to fix this issue.On Sunday, May 10, 2015 at 4:15:40 PM UTC-4, Yannick Duchêne wrote:

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:

%{^
/**

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

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.jsOn Sunday, May 10, 2015 at 12:55:54 PM UTC-4, gmhwxi wrote:

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’.

On Sunday, May 10, 2015 at 12:38:28 PM UTC-4, Yannick Duchêne wrote:

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
Library for JS code generated from ATS source · GitHub , 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.

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’.On Sunday, May 10, 2015 at 12:38:28 PM UTC-4, Yannick Duchêne wrote:

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
Library for JS code generated from ATS source · GitHub , 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.

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.On Sunday, May 10, 2015 at 11:18:20 AM UTC-4, Yannick Duchêne wrote:

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:

/**

Le jeudi 6 novembre 2014 08:14:39 UTC+1, gmhwxi a écrit :

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:

Index of /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!

I get libatscc2js_all.js from
Library for JS code generated from ATS source · GitHub , 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 […]”