From ATS to JavaScript

This is good stuff!

-GregOn Fri, Aug 22, 2014 at 11:58 AM, gmhwxi gmh...@gmail.com wrote:

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I had:

/* ATSextcode_beg() /
// COMMENT_line
// COMMENT_line
// COMMENT_line
var fs = require(‘fs’);
eval(fs.readFileSync(‘./…/prelude/CATS/integer_cats.js’).toString());
/
ATSextcode_end() */
function
fact(arg0)
{
// __patsflab_fact
tmp1 = ats2jspre_gt_int0_int0(arg0, 0)
if (tmp1) {
tmp3 = ats2jspre_sub_int0_int0(arg0, 1)
tmp2 = fact(tmp3)
tmpret0 = ats2jspre_mul_int0_int0(arg0, tmp2)
} else {
tmpret0 = 1
} // endif
return tmpret0
}

/* ATSextcode_beg() /
console.log("fact(10) = ", fact(10))
/
ATSextcode_end() */

For being used as a target language, I have to say that JS is a lot more
accommodating than Python.

Be happy to hear comments and suggestions.

Cheers!


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/b67fead7-b66a-40e0-82fe-2bf6a8279e1a%40googlegroups.com.

Okay, I added a quick fix.

I am in the process of restructuring atscc2js. I will have something more
modular soon.On Wed, May 20, 2015 at 1:38 PM, Hongwei Xi gmh...@gmail.com wrote:

Because it has never been implemented. I will fix it shortly.

On Wed, May 20, 2015 at 12:50 PM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le vendredi 22 août 2014 20:58:09 UTC+2, gmhwxi a écrit :

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I
had:
[…]

Not a big issue, just a bit annoying, atscc2js does not output the file
name with its error messages (or it’s just with me?), just the
“line=”/“offs=”.


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/74394103-20ec-443e-b424-18767c75bb62%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/74394103-20ec-443e-b424-18767c75bb62%40googlegroups.com?utm_medium=email&utm_source=footer
.

Here is a version of Game-of-24 that runs on the JS code generated from ATS
source:

http://www.ats-lang.org/COMPILED/doc/PROJECT/SMALL/GameOf24/JavaScript/inputform.htmlOn Wednesday, August 27, 2014 8:38:44 PM UTC-4, gmhwxi wrote:

Good point. Now the comment reads:

The starting compilation time is …

I will add the finishing time at the end of each generated file.

On Wednesday, August 27, 2014 8:16:07 PM UTC-4, Raoul Duke wrote:

warning: this comment can easily be interpreted to mean the compiler
is slow, taking 19+ hours to compile! pretty please reword it to avoid
fudding ats2js. :slight_smile: (and even possibly do include the actual
compilation time stats.)

/*
**
** The JavaScript code is generated by atscc2js
** The compilation time is: 2014-8-27: 19h:27m
**
*/

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I had:
[…]

What’s the difference between pats_ccomp_instrset.h and pats_ccomp.h?
They both seems to define similar things.

I came to this question trying to understand how ATSCC2JS generate a JS
file. I guess it parse the file, searching for macros it expects to find,
but they are defined at two places.

Also, as the compilation from C source to the final binary target make uses
of macro, why not do the same for C to JS and use the C preprocessor to
generate JS files from the C files, as the C files seems to be made of a
predefined set of macros?

Because it has never been implemented. I will fix it shortly.On Wed, May 20, 2015 at 12:50 PM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le vendredi 22 août 2014 20:58:09 UTC+2, gmhwxi a écrit :

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I had:
[…]

Not a big issue, just a bit annoying, atscc2js does not output the file
name with its error messages (or it’s just with me?), just the
“line=”/“offs=”.


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/74394103-20ec-443e-b424-18767c75bb62%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/74394103-20ec-443e-b424-18767c75bb62%40googlegroups.com?utm_medium=email&utm_source=footer
.

not_null is a template, and it is never implemented.On Thu, May 14, 2015 at 12:12 AM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le vendredi 22 août 2014 20:58:09 UTC+2, gmhwxi a écrit :

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

Something which ATSCC2JS seems to not handle.

First the test ATS source, then the error ATSCC2JS complains about.

The ATS test source:
#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME “js_main_dynload”

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

sortdef reference = int
typedef reference = [r: reference] int(r)
typedef reference(r: reference) = int(r)
abstype element

stacst not_null(r: reference): bool
extern fun {r: reference} not_null(r: reference r): bool(not_null(r))

extern fun element{r: reference | not_null(r)}(r: reference r): element
extern fun reference(k: string): reference

val r: reference = reference(“foo”)
val b: bool = not_null(r)
val () =
if b then
let val e: element = element(r)
in () end

%{$
js_main_dynload();
%}

The error ATSCC2JS complains about:
Hello from atscc2js!
ParsingErrors:
:236:35:
error(parsing): the keyword [)] is needed.
:236:1:
error(parsing): the keyword [}] is needed.

Here is the corresponding line #236 in the C file:
ATSINSmove(statmp1, PMVtmpltcstmat0(
statmp0)) ;

Offset 35 is at the “[” character. It also seems PMVtmpltcstmat is not
defined anywhere.


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/e62a5141-4ab0-406f-a193-99d529d22419%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/e62a5141-4ab0-406f-a193-99d529d22419%40googlegroups.com?utm_medium=email&utm_source=footer
.

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

[…]

For the “main” of an ATS application targeting JavaScript, I would suggest
to use something like this:

%{$
try {
js_main_dynload();
}
catch (e) {
alert(e);
}
%}

Without it, runtime check error, like that of assertloc, occurs silently.

Exciting. If I understand based on your previous assessment, atscc2js
would probably be the best existing template for a atscc2java?

While there are multiple paths to target the JVM, I’m guessing that
having an atscc2java is the most reasonable for the moment, and will
probably still generate fairly performant code.

My medium term plans would be to write atscc2java, then convert
IntelliJATS to it … I hope this might generate more interest for
others in the community as well, but I would say my primary reason is
to just have something to program ATS in, and this seems to be some
potentially nice synergy.On Wed, May 20, 2015 at 2:03 PM, Hongwei Xi gmh...@gmail.com wrote:

Okay, I added a quick fix.

I am in the process of restructuring atscc2js. I will have something more
modular soon.

On Wed, May 20, 2015 at 1:38 PM, Hongwei Xi gmh...@gmail.com wrote:

Because it has never been implemented. I will fix it shortly.

On Wed, May 20, 2015 at 12:50 PM, ‘Yannick Duchêne’ via ats-lang-users ats-lan...@googlegroups.com wrote:

Le vendredi 22 août 2014 20:58:09 UTC+2, gmhwxi a écrit :

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I
had:
[…]

Not a big issue, just a bit annoying, atscc2js does not output the file
name with its error messages (or it’s just with me?), just the
“line=”/“offs=”.


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/74394103-20ec-443e-b424-18767c75bb62%40googlegroups.com.


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/CAPPSPLo053PGnhnv5%3Dw-1BsfaA82DL7Ugk216yAzaTgzBBduaw%40mail.gmail.com.

Brandon Barker
brandon...@gmail.com

This is the first I’ve heard of WebAssembly;
http://www.osnews.com/story/28637/The_web_is_getting_its_bytecode_WebAssembly

Looks like it is quite a ways from even a draft spec for now.On Friday, 22 August 2014 15:42:54 UTC-4, gmhwxi wrote:

Will do it later. It probably just needs some compilation flags.

For now, I’d like to experiment co-programming with ATS and Node.js.

On Friday, August 22, 2014 3:18:21 PM UTC-4, Martin DeMello wrote:

Why not target asm.js rather than javascript proper?

martin

On Fri, Aug 22, 2014 at 11:58 AM, gmhwxi gmh...@gmail.com wrote:

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I
had:

/* ATSextcode_beg() */
// COMMENT_line

// COMMENT_line

// COMMENT_line

var fs = require(‘fs’);
eval(fs.readFileSync(‘./…/prelude/CATS/integer_cats.js’).toString());
/* ATSextcode_end() */
function
fact(arg0)
{
// __patsflab_fact

tmp1 = ats2jspre_gt_int0_int0(arg0, 0)
if (tmp1) {
tmp3 = ats2jspre_sub_int0_int0(arg0, 1)
tmp2 = fact(tmp3)
tmpret0 = ats2jspre_mul_int0_int0(arg0, tmp2)
} else {
tmpret0 = 1
} // endif

return tmpret0
}

/* ATSextcode_beg() /
console.log("fact(10) = ", fact(10))
/
ATSextcode_end() */

For being used as a target language, I have to say that JS is a lot more
accommodating than Python.

Be happy to hear comments and suggestions.

Cheers!


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.
To post to this group, send email to ats-l...@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/b67fead7-b66a-40e0-82fe-2bf6a8279e1a%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/b67fead7-b66a-40e0-82fe-2bf6a8279e1a%40googlegroups.com?utm_medium=email&utm_source=footer
.

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

Something which ATSCC2JS seems to not handle.

First the test ATS source, then the error ATSCC2JS complains about.

The ATS test source:
#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME “js_main_dynload”

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

sortdef reference = int
typedef reference = [r: reference] int(r)
typedef reference(r: reference) = int(r)
abstype element

stacst not_null(r: reference): bool
extern fun {r: reference} not_null(r: reference r): bool(not_null(r))

extern fun element{r: reference | not_null(r)}(r: reference r): element
extern fun reference(k: string): reference

val r: reference = reference(“foo”)
val b: bool = not_null(r)
val () =
if b then
let val e: element = element(r)
in () end

%{$
js_main_dynload();
%}

The error ATSCC2JS complains about:
Hello from atscc2js!
ParsingErrors:
:236:35:
error(parsing): the keyword [)] is needed.
:236:1:
error(parsing): the keyword [}] is needed.

Here is the corresponding line #236 in the C file:
ATSINSmove(statmp1, PMVtmpltcstmat0(
statmp0)) ;

Offset 35 is at the “[” character. It also seems PMVtmpltcstmat is not
defined anywhere.

Good point. Now the comment reads:

The starting compilation time is …

I will add the finishing time at the end of each generated file.On Wednesday, August 27, 2014 8:16:07 PM UTC-4, Raoul Duke wrote:

warning: this comment can easily be interpreted to mean the compiler
is slow, taking 19+ hours to compile! pretty please reword it to avoid
fudding ats2js. :slight_smile: (and even possibly do include the actual
compilation time stats.)

/*
**
** The JavaScript code is generated by atscc2js
** The compilation time is: 2014-8-27: 19h:27m
**
*/

Using C macros to generate JS would encounter many difficulties.

For instance, there are goto’s in C code but JS does not support goto’s.On Tuesday, May 12, 2015 at 6:53:19 AM UTC-4, Yannick Duchêne wrote:

Le vendredi 22 août 2014 20:58:09 UTC+2, gmhwxi a écrit :

Okay, I have got the ball rolling:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/JavaScript

I am currently targeting Node.js. This is the first running example I
had: […]

What’s the difference between pats_ccomp_instrset.h and pats_ccomp.h?
They both seems to define similar things.

I came to this question trying to understand how ATSCC2JS generate a JS
file. I guess it parse the file, searching for macros it expects to find,
but they are defined at two places.

Also, as the compilation from C source to the final binary target make
uses of macro, why not do the same for C to JS and use the C preprocessor
to generate JS files from the C files, as the C files seems to be made of a
predefined set of macros?

Also, as the compilation from C source to the final binary target make
uses of macro, why not do the same for C to JS and use the C preprocessor
to generate JS files from the C files, as the C files seems to be made of a
predefined set of macros?

Just gave it a try, and as there are other includes, this cannot be that
easy. The includes are really made for C.

Can I still use either one of these two include files as a reference or
should I look to other things too?