Libatsopt

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

For a bit of fun, here is a short program for building a compiler for ATS2
based on libatsopt:

Will Blair has already succeeded in build a JS version of libatsopt. This
means we
can have a compiler for ATS2 that runs entirely in the browser. I actually
tried such
a compiler built by him yesterday :slight_smile:

Web worker sounds like the right way to go

Just found out that the picture is less rosy.

Chromium uses a very limited call stack for each worker. Right now,
compiling a program
insider a worker can often (but not always) cause the call stack being
exhausted. Firefox
seems to fare a lot better in this regard. Anyway, I think what I have got
so far is sufficient
for building some teaching stuff for ATS. Here is a webworker-based version:

http://ats-lang.github.io/EXPERIMENT/test_libatsopt/wktest_libatsopt.htmlOn Monday, October 26, 2015 at 1:56:11 PM UTC-4, H Zhang wrote:

So emscripten_force_exit didnā€™t work? Or restart it was the problem? Web
worker sounds like the right way to go. Another possibility is to use
dlmallocā€™s mspace (arena allocator). You can create_mspace a block of
memory, call mspace_malloc, mspace_free etc with the additional mspace
pointer, and destroy_mspace at the end to release all the memory at once.
From http://gee.cs.oswego.edu/pub/misc/malloc.h

/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
/
typedef void
mspace;

/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

On Sunday, October 25, 2015 at 7:41:08 PM UTC-7, gmhwxi wrote:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a large
number
of times (e.g., 100 times), one may have to reload the page to start
again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™
in Emscripten
generated JS code and then restart it. I gave up at the end. Now I will
try to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation
finishes. This is essentially
what Will Blair did. Hopefully, this approach will work out.

On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way to
fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE features
to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at GitHub - leanprover/tutorial: Lean Tutorials
Looks like they use the Ace editor. They use Aceā€™s setAnnotation to do
flycheck style highlighting. They also use a pre-generated dictionary for
autocompletion. These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I
shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler
for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

Here is a very primitive version:

https://ats-lang.github.io/EXPERIMENT/test_libatsopt/test_libatsopt.html

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a flycheck
style syntax error highlighter either directly in the browser or in an
Electron app. I had very good impression of Lean Proverā€™s online tutorial.
The source repo is at GitHub - leanprover/tutorial: Lean Tutorials Looks like
they use the Ace editor. They use Aceā€™s setAnnotation to do flycheck style
highlighting. They also use a pre-generated dictionary for autocompletion.
These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for
ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a large
number
of times (e.g., 100 times), one may have to reload the page to start again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™ in
Emscripten
generated JS code and then restart it. I gave up at the end. Now I will try
to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation finishes.
This is essentially
what Will Blair did. Hopefully, this approach will work out.On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way to
fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE features
to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at GitHub - leanprover/tutorial: Lean Tutorials
Looks like they use the Ace editor. They use Aceā€™s setAnnotation to do
flycheck style highlighting. They also use a pre-generated dictionary for
autocompletion. These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall
be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for
ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

Cheers!On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt. This
means we
can have a compiler for ATS2 that runs entirely in the browser. I actually
tried such
a compiler built by him yesterday :slight_smile:

emscripten_force_exit works. After exiting from ā€˜mainā€™, calling ā€˜mainā€™
again causes
many timing-related issues. I did make it work after modifying
Emscripten-generated
code, but I did not feel I should continue that way. It is not like my life
being dependent
on it :)On Monday, October 26, 2015 at 1:56:11 PM UTC-4, H Zhang wrote:

So emscripten_force_exit didnā€™t work? Or restart it was the problem? Web
worker sounds like the right way to go. Another possibility is to use
dlmallocā€™s mspace (arena allocator). You can create_mspace a block of
memory, call mspace_malloc, mspace_free etc with the additional mspace
pointer, and destroy_mspace at the end to release all the memory at once.
From http://gee.cs.oswego.edu/pub/misc/malloc.h

/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
/
typedef void
mspace;

/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

On Sunday, October 25, 2015 at 7:41:08 PM UTC-7, gmhwxi wrote:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a large
number
of times (e.g., 100 times), one may have to reload the page to start
again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™
in Emscripten
generated JS code and then restart it. I gave up at the end. Now I will
try to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation
finishes. This is essentially
what Will Blair did. Hopefully, this approach will work out.

On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way to
fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE features
to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at GitHub - leanprover/tutorial: Lean Tutorials
Looks like they use the Ace editor. They use Aceā€™s setAnnotation to do
flycheck style highlighting. They also use a pre-generated dictionary for
autocompletion. These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I
shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler
for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

I just noticed that running 2 pieces of Emscripten generated JS code could
cause a
conflict between them. In my case, I wanted to run Patsopt and Atscc2js,
but my attempt
failed for reasons unclear to me. Reality is always more fascinating than
oneā€™s plan :slight_smile:

Running Atscc2js inside a webworker is fine, though.On Thursday, October 29, 2015 at 10:42:44 PM UTC-4, H Zhang wrote:

Well in that case the arena based allocator might be an easy alternative.
Since you only need a single arena to reclaim the memory, you could just
use a global variable for the arena pointer to be initialized at the top of
the main and destroyed at the end. The malloc and free can be replaced with
the macros that call mspace_malloc and mspace_free instead with the global
mspace pointer threaded in. You donā€™t have to change any existing code. I
think Emscripten by default uses dlmalloc so hopefully compatibility isnā€™t
a problem.
https://github.com/kripken/emscripten/blob/master/system/lib/dlmalloc.c

On Tuesday, October 27, 2015 at 11:38:42 AM UTC-7, gmhwxi wrote:

Web worker sounds like the right way to go

Just found out that the picture is less rosy.

Chromium uses a very limited call stack for each worker. Right now,
compiling a program
insider a worker can often (but not always) cause the call stack being
exhausted. Firefox
seems to fare a lot better in this regard. Anyway, I think what I have
got so far is sufficient
for building some teaching stuff for ATS. Here is a webworker-based
version:

wktest_libatsopt

On Monday, October 26, 2015 at 1:56:11 PM UTC-4, H Zhang wrote:

So emscripten_force_exit didnā€™t work? Or restart it was the problem? Web
worker sounds like the right way to go. Another possibility is to use
dlmallocā€™s mspace (arena allocator). You can create_mspace a block of
memory, call mspace_malloc, mspace_free etc with the additional mspace
pointer, and destroy_mspace at the end to release all the memory at once.
From http://gee.cs.oswego.edu/pub/misc/malloc.h

/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
/
typedef void
mspace;

/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

On Sunday, October 25, 2015 at 7:41:08 PM UTC-7, gmhwxi wrote:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a
large number
of times (e.g., 100 times), one may have to reload the page to start
again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™
in Emscripten
generated JS code and then restart it. I gave up at the end. Now I will
try to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation
finishes. This is essentially
what Will Blair did. Hopefully, this approach will work out.

On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way
to fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE
features to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at
GitHub - leanprover/tutorial: Lean Tutorials Looks like they use the Ace
editor. They use Aceā€™s setAnnotation to do flycheck style highlighting.
They also use a pre-generated dictionary for autocompletion. These all seem
pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using
node.js
to execute the JS version of patsopt. In the very near future, I
shall be
able to generate another version that can be invoked inside a
browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler
for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of
libatsopt. This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

So one will soon be able to write ATS and compile to JS and run it all in
the browser? I think that is potentially really big for expanding ATSā€™
audience. Compiling to a GCā€™ed VM means at a minimum one can start using
ATS like a flavored ML. While there are many languages transpiling to js
ATS may be able to really stand out on code efficiency? As I understand it
ATS is able to compile recursive calls to loops. I think transpilers like
Elm and SMLtoJs still donā€™t have TCO yet.

HaitaoOn Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt. This
means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

So emscripten_force_exit didnā€™t work? Or restart it was the problem? Web
worker sounds like the right way to go. Another possibility is to use
dlmallocā€™s mspace (arena allocator). You can create_mspace a block of
memory, call mspace_malloc, mspace_free etc with the additional mspace
pointer, and destroy_mspace at the end to release all the memory at once.
From http://gee.cs.oswego.edu/pub/misc/malloc.h

/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
/
typedef void
mspace;

/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);On Sunday, October 25, 2015 at 7:41:08 PM UTC-7, gmhwxi wrote:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a large
number
of times (e.g., 100 times), one may have to reload the page to start again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™ in
Emscripten
generated JS code and then restart it. I gave up at the end. Now I will
try to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation
finishes. This is essentially
what Will Blair did. Hopefully, this approach will work out.

On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way to
fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE features
to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at GitHub - leanprover/tutorial: Lean Tutorials
Looks like they use the Ace editor. They use Aceā€™s setAnnotation to do
flycheck style highlighting. They also use a pre-generated dictionary for
autocompletion. These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall
be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for
ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

Well in that case the arena based allocator might be an easy alternative.
Since you only need a single arena to reclaim the memory, you could just
use a global variable for the arena pointer to be initialized at the top of
the main and destroyed at the end. The malloc and free can be replaced with
the macros that call mspace_malloc and mspace_free instead with the global
mspace pointer threaded in. You donā€™t have to change any existing code. I
think Emscripten by default uses dlmalloc so hopefully compatibility isnā€™t
a problem.
https://github.com/kripken/emscripten/blob/master/system/lib/dlmalloc.cOn Tuesday, October 27, 2015 at 11:38:42 AM UTC-7, gmhwxi wrote:

Web worker sounds like the right way to go

Just found out that the picture is less rosy.

Chromium uses a very limited call stack for each worker. Right now,
compiling a program
insider a worker can often (but not always) cause the call stack being
exhausted. Firefox
seems to fare a lot better in this regard. Anyway, I think what I have got
so far is sufficient
for building some teaching stuff for ATS. Here is a webworker-based
version:

wktest_libatsopt

On Monday, October 26, 2015 at 1:56:11 PM UTC-4, H Zhang wrote:

So emscripten_force_exit didnā€™t work? Or restart it was the problem? Web
worker sounds like the right way to go. Another possibility is to use
dlmallocā€™s mspace (arena allocator). You can create_mspace a block of
memory, call mspace_malloc, mspace_free etc with the additional mspace
pointer, and destroy_mspace at the end to release all the memory at once.
From http://gee.cs.oswego.edu/pub/misc/malloc.h

/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
/
typedef void
mspace;

/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

On Sunday, October 25, 2015 at 7:41:08 PM UTC-7, gmhwxi wrote:

I have yet to address the memory issue. For now, each call to patsopt
leaks a few million bytes of memory. If one wants to call patsopt a
large number
of times (e.g., 100 times), one may have to reload the page to start
again.

I spent two days trying to figure out how to quit from a call to ā€˜mainā€™
in Emscripten
generated JS code and then restart it. I gave up at the end. Now I will
try to use a WebWorker
to run patsopt and then terminate the WebWorker after compilation
finishes. This is essentially
what Will Blair did. Hopefully, this approach will work out.

On Sunday, October 25, 2015 at 8:07:34 PM UTC-4, H Zhang wrote:

This is really cool! It runs very snappy. I was thinking that one way
to fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE
features to aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.

On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at
GitHub - leanprover/tutorial: Lean Tutorials Looks like they use the Ace
editor. They use Aceā€™s setAnnotation to do flycheck style highlighting.
They also use a pre-generated dictionary for autocompletion. These all seem
pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I
shall be
able to generate another version that can be invoked inside a
browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler
for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of
libatsopt. This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

It seems to me that an immediate application of this is to have a flycheck
style syntax error highlighter either directly in the browser or in an
Electron app. I had very good impression of Lean Proverā€™s online tutorial.
The source repo is at GitHub - leanprover/tutorial: Lean Tutorials Looks like
they use the Ace editor. They use Aceā€™s setAnnotation to do flycheck style
highlighting. They also use a pre-generated dictionary for autocompletion.
These all seem pretty readily achievable for ATS as well.On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt. This
means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

Note that Emscripten itself is not yet compiled to JS.

To do ā€œeverythingā€ in the browser, one can take the following route:

Use patsopt(JS) to compile ATS source into C and then use atscc2js(JS)
to compile the generated C code into JS, where patsopt(JS) and atscc2js(JS)
are Emscripten-generated JS.

By the way, it should not be so hard to compile ATS to languages like Elm
and SML :)On Wednesday, October 21, 2015 at 1:32:53 AM UTC-4, H Zhang wrote:

So one will soon be able to write ATS and compile to JS and run it all in
the browser? I think that is potentially really big for expanding ATSā€™
audience. Compiling to a GCā€™ed VM means at a minimum one can start using
ATS like a flavored ML. While there are many languages transpiling to js
ATS may be able to really stand out on code efficiency? As I understand it
ATS is able to compile recursive calls to loops. I think transpilers like
Elm and SMLtoJs still donā€™t have TCO yet.

Haitao

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for
ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile:

This is really cool! It runs very snappy. I was thinking that one way to
fix the memory leak is to just reclaim all allocations after a run since
the compiler runs in batch mode. Looks like you have solved the memory
problem.

This looks like it could be used to create some interesting IDE features to
aid the learning of ATS:

  1. Correlate syntax errors back to the source code;
  2. Correlate source code to highlight corresponding generated C code

Just off the top of my head.On Saturday, October 24, 2015 at 7:20:37 PM UTC-7, gmhwxi wrote:

Here is a very primitive version:

test_libatsopt

I hope someone would be willing to step up to the challenge of using
libatsopt(JS) to
build something interesting.

On Wednesday, October 21, 2015 at 4:30:46 PM UTC-4, H Zhang wrote:

It seems to me that an immediate application of this is to have a
flycheck style syntax error highlighter either directly in the browser or
in an Electron app. I had very good impression of Lean Proverā€™s online
tutorial. The source repo is at GitHub - leanprover/tutorial: Lean Tutorials
Looks like they use the Ace editor. They use Aceā€™s setAnnotation to do
flycheck style highlighting. They also use a pre-generated dictionary for
autocompletion. These all seem pretty readily achievable for ATS as well.

On Tuesday, October 20, 2015 at 11:57:54 AM UTC-7, gmhwxi wrote:

Following an example by Will Blair, I managed to use Emscripten
to compile libatsopt; I then generated a JS version of patsopt that
can be used to compile ATS2/prelude. So far I have been using node.js
to execute the JS version of patsopt. In the very near future, I shall be
able to generate another version that can be invoked inside a browser.

See:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt/JS

Cheers!

On Friday, October 2, 2015 at 10:49:48 PM UTC-4, gmhwxi wrote:

Please find some instructions on building libatsopt, that is, the
library version of patsopt:

https://github.com/githwxi/ATS-Postiats/tree/master/utils/libatsopt

For a bit of fun, here is a short program for building a compiler for
ATS2
based on libatsopt:

https://github.com/githwxi/ATS-Postiats/blob/master/utils/libatsopt/TEST/patsopt.dats

Will Blair has already succeeded in build a JS version of libatsopt.
This means we
can have a compiler for ATS2 that runs entirely in the browser. I
actually tried such
a compiler built by him yesterday :slight_smile: