Ats repl

I think it would be nice to have a way to do REPL in ATS, at least for the
ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the work
so there may be some limitations on what can be done for the interpreter
without herculean effort. ATS can already parse code into AST so that part
should be reused to parse the input for the interpreter as well (although
it may be important to generate better error messages for the interpreter).
Parsed ATS expressions can be evaluated if we can correctly dispatch
function calls so we need a loader to find/load/register compiled functions
and a runtime to manage associated symbol table and global data. The trick
here is to ensure type safety even while type information may have been
lost in the compiled native code, so the interpreter will need to access
ATS’s type analysis module to establish type correctness (so we will need
access to the source/header files as well even for pre-compiled code).
Alternatively we may use the compiler working in the background to
establish type-correctness? On the other hand things like defining new data
structures and functions are dependent on the C compilers and are not easy
to support directly in the interpreter. Here I think the typical Prolog
style of separating compilation (consult) and evaluation (query) may be a
useful model. We can organize functions into different modules that get
compiled into DLLs. If a source file is modified the associated DLL will be
recompiled (maybe externally calling make but runtime may need to know the
dependency so it can update type information) and reloaded.

I know these are rather immature thoughts but I hope this is somehow doable
and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

Here is an interesting paper that discussed combining Lua with ML in
writing an optimizing compiler for C–:

They went as far as writing the Lua interpreter themselves in ML in order
to avoid the GC clash problems. I think luajit and ATS would pair together
a lot better for the task.
Following is a quote of the part on advantages of having embedded Lua for
the compiler. In case the significance is lost on anyone they are changing
internal variables/parameters of the compiler using Lua assignments at the
command line.

*There are significant advantages to having this code in Lua.• It is easy
to change the configuration of the optimizer, the compiler, or even the
targetmachine by putting a simple phrase on the command line. For example,
simplywriting qc-- backend=Backend.mips allows us to cross-compile for our
MIPSmachine. Cross-compilation is better than compiling natively because
our MIPS machineis very slow.• The Lua code is invaluable for debugging.
For example, we can turn off a pass ofthe compiler by a command-line
assignment such as backend.expand=nil, and wecan make the compiler emit
“diagnostic assembly language” by using the assignmentbackend.asm=Asm.cmm.•
The “driver” code in Lua runs not only the C-- compiler but also
preprocessors,front ends, the assembler, and the linker. It can therefore
be used to compile a testcase from start to finish, then do another test
without restarting the compiler. Theadvantage is speed. For example, to
test calling conventions, we compile a suite ofseveral hundred test cases.
Using the Lua driver, these cases compile three to fivetimes faster than
using a Perl script in which the compiler is started separately foreach
case.*And later on:

*As shown by highlighting, almost every stage in the Lua record is actually
implemented inthe host language, Objective Caml—but the stages are composed
using Lua. The advantageis that by putting an appropriate Lua assignment on
the compiler’s command line, we canomit or change any stage, including the
assembly-language emitter.*Enjoy,
HaitaoOn Tuesday, March 18, 2014 10:04:37 PM UTC-7, H Zhang wrote:

Then you definitely want to try ZeroBrane if you haven’t used it before.
Very small IDE yet very versatile and powerful. Shows how embedding a good
language makes a powerful editor/IDE a breeze. It has very nice pedagogical
demos (written in Lua) that could be used to demo ATS as well. Luajit is
now ZeroBrane’s default interpreter so you don’t even have to separately
build luajit (which is straightforward to do anyway).

I would be very interested in combining this with the ATS compiler to make
exploring the ATS compiler easier. If you want to start a project on this I
would be happy to contribute.

Haitao

On Tuesday, March 18, 2014 7:17:44 PM UTC-7, gmhwxi wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make
it work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions,
    load the DLL and use the functions dynamically. The luajit C definitions
    can probably be automatically extracted from extern fun … = “mac#”
    statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are
some thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

I installed ZeroBrane today and played with it a bit.

I have to say that zbstudio is probably not something I am looking for
right now.

What I am really interested in is an IDE for ATS that can support various
forms
of meta-programming. Supporting run-time debugging for ATS is a secondary
issue
to me.

Maybe I will give CINT a try next.On Wednesday, March 19, 2014 1:04:37 AM UTC-4, H Zhang wrote:

Then you definitely want to try ZeroBrane if you haven’t used it before.
Very small IDE yet very versatile and powerful. Shows how embedding a good
language makes a powerful editor/IDE a breeze. It has very nice pedagogical
demos (written in Lua) that could be used to demo ATS as well. Luajit is
now ZeroBrane’s default interpreter so you don’t even have to separately
build luajit (which is straightforward to do anyway).

I would be very interested in combining this with the ATS compiler to make
exploring the ATS compiler easier. If you want to start a project on this I
would be happy to contribute.

Haitao

On Tuesday, March 18, 2014 7:17:44 PM UTC-7, gmhwxi wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make
it work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions,
    load the DLL and use the functions dynamically. The luajit C definitions
    can probably be automatically extracted from extern fun … = “mac#”
    statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are
some thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

While CINT is still probably what would be desired for this, I did see a
new (to me) C interpreter today called
PicoC: OSnews - Exploring the Future of Computing

Also a few other fringe C compilers mentioned in the thread.On Thursday, March 20, 2014 at 1:24:52 AM UTC-4, gmhwxi wrote:

I installed ZeroBrane today and played with it a bit.

I have to say that zbstudio is probably not something I am looking for
right now.

What I am really interested in is an IDE for ATS that can support various
forms
of meta-programming. Supporting run-time debugging for ATS is a secondary
issue
to me.

Maybe I will give CINT a try next.

On Wednesday, March 19, 2014 1:04:37 AM UTC-4, H Zhang wrote:

Then you definitely want to try ZeroBrane if you haven’t used it before.
Very small IDE yet very versatile and powerful. Shows how embedding a good
language makes a powerful editor/IDE a breeze. It has very nice pedagogical
demos (written in Lua) that could be used to demo ATS as well. Luajit is
now ZeroBrane’s default interpreter so you don’t even have to separately
build luajit (which is straightforward to do anyway).

I would be very interested in combining this with the ATS compiler to
make exploring the ATS compiler easier. If you want to start a project on
this I would be happy to contribute.

Haitao

On Tuesday, March 18, 2014 7:17:44 PM UTC-7, gmhwxi wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make
it work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions,
    load the DLL and use the functions dynamically. The luajit C definitions
    can probably be automatically extracted from extern fun … = “mac#”
    statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it
make sense to actually support a true subset of ML? So one can write code
in this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are
some thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

Then you definitely want to try ZeroBrane if you haven’t used it before.
Very small IDE yet very versatile and powerful. Shows how embedding a good
language makes a powerful editor/IDE a breeze. It has very nice pedagogical
demos (written in Lua) that could be used to demo ATS as well. Luajit is
now ZeroBrane’s default interpreter so you don’t even have to separately
build luajit (which is straightforward to do anyway).

I would be very interested in combining this with the ATS compiler to make
exploring the ATS compiler easier. If you want to start a project on this I
would be happy to contribute.

HaitaoOn Tuesday, March 18, 2014 7:17:44 PM UTC-7, gmhwxi wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make it
work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

Well, in principle, what is needed for writing an interpreter for ATS is a
C interpreter
instead of a C compiler.

An interpreter has a state that allows top-level values obtained during
evaluation to be
recorded for subsequent use.

With a C compiler like PicoC, you could turn ATS into a scripting language.
Actually, I
did this with TinyCC. It was for fun and probably for fun only.On Tuesday, June 2, 2015 at 8:32:13 AM UTC-4, Brandon Barker wrote:

While CINT is still probably what would be desired for this, I did see a
new (to me) C interpreter today called PicoC:
OSnews - Exploring the Future of Computing

Also a few other fringe C compilers mentioned in the thread.

On Thursday, March 20, 2014 at 1:24:52 AM UTC-4, gmhwxi wrote:

I installed ZeroBrane today and played with it a bit.

I have to say that zbstudio is probably not something I am looking for
right now.

What I am really interested in is an IDE for ATS that can support various
forms
of meta-programming. Supporting run-time debugging for ATS is a secondary
issue
to me.

Maybe I will give CINT a try next.

On Wednesday, March 19, 2014 1:04:37 AM UTC-4, H Zhang wrote:

Then you definitely want to try ZeroBrane if you haven’t used it before.
Very small IDE yet very versatile and powerful. Shows how embedding a good
language makes a powerful editor/IDE a breeze. It has very nice pedagogical
demos (written in Lua) that could be used to demo ATS as well. Luajit is
now ZeroBrane’s default interpreter so you don’t even have to separately
build luajit (which is straightforward to do anyway).

I would be very interested in combining this with the ATS compiler to
make exploring the ATS compiler easier. If you want to start a project on
this I would be happy to contribute.

Haitao

On Tuesday, March 18, 2014 7:17:44 PM UTC-7, gmhwxi wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make
it work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions,
    load the DLL and use the functions dynamically. The luajit C definitions
    can probably be automatically extracted from extern fun … = “mac#”
    statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least
for the ML style subset of ATS. This may even be a good way to show how to
do a project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it
make sense to actually support a true subset of ML? So one can write code
in this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are
some thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make it
work.On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C functions
from ATS and it feels pretty close to a REPL. The process is as follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL. Luajit
has the easiest CFFI I have seen of all dynamic languages. Since it has JIT
it does not depend on the C compiler to generate calling code. Remember it
is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the work
so there may be some limitations on what can be done for the interpreter
without herculean effort. ATS can already parse code into AST so that part
should be reused to parse the input for the interpreter as well (although
it may be important to generate better error messages for the interpreter).
Parsed ATS expressions can be evaluated if we can correctly dispatch
function calls so we need a loader to find/load/register compiled functions
and a runtime to manage associated symbol table and global data. The trick
here is to ensure type safety even while type information may have been
lost in the compiled native code, so the interpreter will need to access
ATS’s type analysis module to establish type correctness (so we will need
access to the source/header files as well even for pre-compiled code).
Alternatively we may use the compiler working in the background to
establish type-correctness? On the other hand things like defining new data
structures and functions are dependent on the C compilers and are not easy
to support directly in the interpreter. Here I think the typical Prolog
style of separating compilation (consult) and evaluation (query) may be a
useful model. We can organize functions into different modules that get
compiled into DLLs. If a source file is modified the associated DLL will be
recompiled (maybe externally calling make but runtime may need to know the
dependency so it can update type information) and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

please god choose a language that at least has /optional/ static
typing. yeah, yeah, lua is great… except for all the ways it is an
embodiment of pure evil! :-}

I am trying to use the teaching opportunity to flush out as many bugs as
possible :slight_smile:

The students are probably more comfortable with Piazza.On Tuesday, March 18, 2014 10:32:38 PM UTC-4, Brandon Barker wrote:

That’s a lot of ATS teaching, in addition to your spring and fall semester
courses.

I’ve wondered, why do more (any) of your students not use/find this forum?

Brandon Barker
brand...@gmail.com <javascript:>

On Tue, Mar 18, 2014 at 10:17 PM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make
it work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions,
    load the DLL and use the functions dynamically. The luajit C definitions
    can probably be automatically extracted from extern fun … = “mac#”
    statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are
some thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao


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 <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/67a942a1-df23-4011-9c85-8fb91c1c3241%40googlegroups.comhttps://groups.google.com/d/msgid/ats-lang-users/67a942a1-df23-4011-9c85-8fb91c1c3241%40googlegroups.com?utm_medium=email&utm_source=footer
.

I use luajit (through the ZeroBrane IDE) to call the generated C functions
from ATS and it feels pretty close to a REPL. The process is as follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include files
    are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL. Luajit
has the easiest CFFI I have seen of all dynamic languages. Since it has JIT
it does not depend on the C compiler to generate calling code. Remember it
is the luajit C FFI extension, not the regular Lua C API.

HaitaoOn Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for the
ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the work
so there may be some limitations on what can be done for the interpreter
without herculean effort. ATS can already parse code into AST so that part
should be reused to parse the input for the interpreter as well (although
it may be important to generate better error messages for the interpreter).
Parsed ATS expressions can be evaluated if we can correctly dispatch
function calls so we need a loader to find/load/register compiled functions
and a runtime to manage associated symbol table and global data. The trick
here is to ensure type safety even while type information may have been
lost in the compiled native code, so the interpreter will need to access
ATS’s type analysis module to establish type correctness (so we will need
access to the source/header files as well even for pre-compiled code).
Alternatively we may use the compiler working in the background to
establish type-correctness? On the other hand things like defining new data
structures and functions are dependent on the C compilers and are not easy
to support directly in the interpreter. Here I think the typical Prolog
style of separating compilation (consult) and evaluation (query) may be a
useful model. We can organize functions into different modules that get
compiled into DLLs. If a source file is modified the associated DLL will be
recompiled (maybe externally calling make but runtime may need to know the
dependency so it can update type information) and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao

That’s a lot of ATS teaching, in addition to your spring and fall semester
courses.

I’ve wondered, why do more (any) of your students not use/find this forum?

Brandon Barker
brandon…@gmail.comOn Tue, Mar 18, 2014 at 10:17 PM, gmhwxi gmh...@gmail.com wrote:

This sounds like a pretty cool idea :slight_smile:

I will teach a class based on ATS this summer. I will see if I can make it
work.

On Tuesday, March 18, 2014 10:05:57 PM UTC-4, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C
functions from ATS and it feels pretty close to a REPL. The process is as
follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL.
Luajit has the easiest CFFI I have seen of all dynamic languages. Since it
has JIT it does not depend on the C compiler to generate calling code.
Remember it is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the
work so there may be some limitations on what can be done for the
interpreter without herculean effort. ATS can already parse code into AST
so that part should be reused to parse the input for the interpreter as
well (although it may be important to generate better error messages for
the interpreter). Parsed ATS expressions can be evaluated if we can
correctly dispatch function calls so we need a loader to find/load/register
compiled functions and a runtime to manage associated symbol table and
global data. The trick here is to ensure type safety even while type
information may have been lost in the compiled native code, so the
interpreter will need to access ATS’s type analysis module to establish
type correctness (so we will need access to the source/header files as well
even for pre-compiled code). Alternatively we may use the compiler working
in the background to establish type-correctness? On the other hand things
like defining new data structures and functions are dependent on the C
compilers and are not easy to support directly in the interpreter. Here I
think the typical Prolog style of separating compilation (consult) and
evaluation (query) may be a useful model. We can organize functions into
different modules that get compiled into DLLs. If a source file is modified
the associated DLL will be recompiled (maybe externally calling make but
runtime may need to know the dependency so it can update type information)
and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao


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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/67a942a1-df23-4011-9c85-8fb91c1c3241%40googlegroups.comhttps://groups.google.com/d/msgid/ats-lang-users/67a942a1-df23-4011-9c85-8fb91c1c3241%40googlegroups.com?utm_medium=email&utm_source=footer
.

Very cool!

I hadn’t heard of luajit before and might be doing some hobby lua work
soon, so that’s also nice to know about.

Brandon Barker
brandon…@gmail.comOn Tue, Mar 18, 2014 at 10:05 PM, H Zhang zht...@gmail.com wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C functions
from ATS and it feels pretty close to a REPL. The process is as follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL. Luajit
has the easiest CFFI I have seen of all dynamic languages. Since it has JIT
it does not depend on the C compiler to generate calling code. Remember it
is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the work
so there may be some limitations on what can be done for the interpreter
without herculean effort. ATS can already parse code into AST so that part
should be reused to parse the input for the interpreter as well (although
it may be important to generate better error messages for the interpreter).
Parsed ATS expressions can be evaluated if we can correctly dispatch
function calls so we need a loader to find/load/register compiled functions
and a runtime to manage associated symbol table and global data. The trick
here is to ensure type safety even while type information may have been
lost in the compiled native code, so the interpreter will need to access
ATS’s type analysis module to establish type correctness (so we will need
access to the source/header files as well even for pre-compiled code).
Alternatively we may use the compiler working in the background to
establish type-correctness? On the other hand things like defining new data
structures and functions are dependent on the C compilers and are not easy
to support directly in the interpreter. Here I think the typical Prolog
style of separating compilation (consult) and evaluation (query) may be a
useful model. We can organize functions into different modules that get
compiled into DLLs. If a source file is modified the associated DLL will be
recompiled (maybe externally calling make but runtime may need to know the
dependency so it can update type information) and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao


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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/6c9f85b4-a1c0-4411-abe4-eea039e30824%40googlegroups.comhttps://groups.google.com/d/msgid/ats-lang-users/6c9f85b4-a1c0-4411-abe4-eea039e30824%40googlegroups.com?utm_medium=email&utm_source=footer
.

Oh I forgot to mention that one should #define ATS_DYNLOADFLAG 0
Since there is no main function for the DLL it appears this is how one can
make the dynload initialization happy (actually turned off), otherwise the
linker would complain about missing dynload functions.

HaitaoOn Tuesday, March 18, 2014 7:05:57 PM UTC-7, H Zhang wrote:

I use luajit (through the ZeroBrane IDE) to call the generated C functions
from ATS and it feels pretty close to a REPL. The process is as follows:

  1. Generate C files using patsopt -o prog.c -d prog.dats
  2. Compile to object files with gcc -fPIC. Make sure that ATS include
    files are in the path and MALLOCFLAG is defined.
  3. Create DLL with gcc -shared
  4. In luajit console or script, write the appropriate C definitions, load
    the DLL and use the functions dynamically. The luajit C definitions can
    probably be automatically extracted from extern fun … = “mac#” statements.

I hope this is helpful to others who find similar needs of an REPL. Luajit
has the easiest CFFI I have seen of all dynamic languages. Since it has JIT
it does not depend on the C compiler to generate calling code. Remember it
is the luajit C FFI extension, not the regular Lua C API.

Haitao

On Saturday, January 11, 2014 9:26:30 PM UTC-8, H Zhang wrote:

I think it would be nice to have a way to do REPL in ATS, at least for
the ML style subset of ATS. This may even be a good way to show how to do a
project in ATS and I will be happy to contribute to such a project.

Now the first question is since ATS has a ML style subset would it make
sense to actually support a true subset of ML? So one can write code in
this intersection of ATS and ML and use the ML interpreter for REPL
development and debugging and use ATS compiler to compile to native code
for performance. Is there a reason why this can not be done? If doable this
seems the low hanging fruit to get.

If we do want/need to do an interpreter for ATS (ML style) here are some
thoughts:

As I understand it ATS depends on the C compilers to do a lot of the work
so there may be some limitations on what can be done for the interpreter
without herculean effort. ATS can already parse code into AST so that part
should be reused to parse the input for the interpreter as well (although
it may be important to generate better error messages for the interpreter).
Parsed ATS expressions can be evaluated if we can correctly dispatch
function calls so we need a loader to find/load/register compiled functions
and a runtime to manage associated symbol table and global data. The trick
here is to ensure type safety even while type information may have been
lost in the compiled native code, so the interpreter will need to access
ATS’s type analysis module to establish type correctness (so we will need
access to the source/header files as well even for pre-compiled code).
Alternatively we may use the compiler working in the background to
establish type-correctness? On the other hand things like defining new data
structures and functions are dependent on the C compilers and are not easy
to support directly in the interpreter. Here I think the typical Prolog
style of separating compilation (consult) and evaluation (query) may be a
useful model. We can organize functions into different modules that get
compiled into DLLs. If a source file is modified the associated DLL will be
recompiled (maybe externally calling make but runtime may need to know the
dependency so it can update type information) and reloaded.

I know these are rather immature thoughts but I hope this is somehow
doable and I think with a good (enough) REPL ATS will be more accessible to
programmers in general.

Thanks,

Haitao