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:
- Correlate syntax errors back to the source code;
- 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 