Compiling ATS to Python?

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
’/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not now.

Cheers!

Neat! Instead of targeting Python, how about the asm.js subset of
JavaScript? For longish running benchmarks, performance should be on
par with the native-compiled version.

http://asmjs.org/spec/latest/

Googling around, it looks like Firefox and Chrome have optimized for
asm.js since versions 22 and 28 respectively. And both browsers have
command-line shells (SpiderMonkey and V8) for easy benchmarking.

-GregOn Wed, Aug 6, 2014 at 7:43 PM, gmhwxi gmh...@gmail.com wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a hand.
Unfortunately,
I myself do not have time to go further along this path. At least, not now.

Cheers!


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/798ce024-b9d2-4f43-add8-d0be6f1a696f%40googlegroups.com.

Now I have added the support for pattern matching.

Here is an implementation of the list-length function in python
that is generated from some ATS source:

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude/CATS’
)
from integer_cats import *

(* ****** ****** *)

def nil(): return None
def cons(x, xs): return (x, xs)

def ATSCKptrisnil(xs): return (xs == None)
def ATSCKptriscons(xs): return (xs != None)

(* ****** ****** *)

extern

fun

listlen

: {a:t@ype} List0 (a) → int = “ext#”

//

(* ****** ****** *)

implement

listlen{a}

(xs) = let

//

prval () = lemma_list_param (xs)

//

fun

loop{i,j:nat} ..

(

xs: list (a, i), res: int(j)

) : int(i+j) = let

in

//

case+ xs of

| list_nil () => res | list_cons (_, xs) => loop (xs, res+1)

//

end // end of [loop]

//

in

loop (xs, 0)

end // end of [intlistlen]

def listlen(arg0):
tmpret0 = None
funlab_py = None
tmplab_py = None
#__patsflab_listlen
tmpret0 = loop_1(arg0, 0)
return tmpret0

def loop_1(arg0, arg1):
apy0 = None
apy1 = None
tmpret1 = None
tmp3 = None
tmp4 = None
funlab_py = None
tmplab_py = None
mbranch_1 = None
def __atstmplab0():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
if (ATSCKptriscons(arg0)): tmplab_py = 4 ; return#__atstmplab3
__atstmplab1()
return
def __atstmplab1():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmpret1 = arg1
return
def __atstmplab2():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
__atstmplab3()
return
def __atstmplab3():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmp3 = arg0[1]
tmp4 = atspre2py_add_int1_int1(arg1, 1)
#tailcal_beg
apy0 = tmp3
apy1 = tmp4
arg0 = apy0
arg1 = apy1
funlab_py = 1 #__patsflab_loop_1
#tailcal_end
return
mbranch_1 = { 1: __atstmplab0, 2: __atstmplab1, 3: __atstmplab2, 4:
__atstmplab3 }
while (1):
funlab_py = 0
#__patsflab_loop_1
#ATScaseof_beg
tmplab_py = 1
while (1):
mbranch_1.get(tmplab_py)()
if (tmplab_py == 0): break
#ATScaseof_end
if (funlab_py == 0): break
return tmpret1

(* ****** ****** *)

xs = cons(1, cons(2, cons(3, nil())))

print(“listlen(”, xs, “) =”, listlen(xs))

(* ****** ****** *)On Wednesday, August 6, 2014 10:43:13 PM UTC-4, gmhwxi wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not now.

Cheers!

if anybody thinks this is cool (i certainly do) then also please
checkout http://shenlanguage.org :slight_smile:

I think we can try all these approaches.

The target language of ATS is very small, and it should be
straightforward to translate it to llvm. Actually, it makes a lot
of sense to write a compiler for translating this target language
into object code since using gcc/clang is clearly an overkill.

This complaint makes some sense, but targeting C is a portability bonus.
Also, on most software store, you can submit C programs not any misc
language you use and even less binaries. And C is the most common
denominator, covering both Apple’s and Windows’s and Ubuntu’s own software
stores (at least Apple and Windows favour C, to get run safety static check
on the application… Ubuntu don’t, but still requires something which can be
compiled within a standard Ubuntu environment).

Hongwei,

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not now.

Some questions:

  1. what’s the difference between ATSINSlab and ATSINSflab, and between
    ATSINSgoto and ATSINSfgoto?
  2. what are pointer operations compiled to?
  3. what is ATSINSmove_boxrec?

Hongwei,

This is very nice!

Is it possible for atsopt to emit #line pragmas (instead of comments) so
that paremit would parse them?

I think that propagating such information is very important for
debugging/tracing purposes.On Sunday, August 17, 2014 5:51:22 AM UTC+6, gmhwxi wrote:

Now I have added the support for pattern matching.

Here is an implementation of the list-length function in python
that is generated from some ATS source:

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude/CATS’
)
from integer_cats import *

(* ****** ****** *)

def nil(): return None
def cons(x, xs): return (x, xs)

def ATSCKptrisnil(xs): return (xs == None)
def ATSCKptriscons(xs): return (xs != None)

(* ****** ****** *)

extern

fun

listlen

: {a:t@ype} List0 (a) → int = “ext#”

//

(* ****** ****** *)

implement

listlen{a}

(xs) = let

//

prval () = lemma_list_param (xs)

//

fun

loop{i,j:nat} ..

(

xs: list (a, i), res: int(j)

) : int(i+j) = let

in

//

case+ xs of

| list_nil () => res | list_cons (_, xs) => loop (xs, res+1)

//

end // end of [loop]

//

in

loop (xs, 0)

end // end of [intlistlen]

def listlen(arg0):
tmpret0 = None
funlab_py = None
tmplab_py = None
#__patsflab_listlen
tmpret0 = loop_1(arg0, 0)
return tmpret0

def loop_1(arg0, arg1):
apy0 = None
apy1 = None
tmpret1 = None
tmp3 = None
tmp4 = None
funlab_py = None
tmplab_py = None
mbranch_1 = None
def __atstmplab0():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
if (ATSCKptriscons(arg0)): tmplab_py = 4 ; return#__atstmplab3
__atstmplab1()
return
def __atstmplab1():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmpret1 = arg1
return
def __atstmplab2():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
__atstmplab3()
return
def __atstmplab3():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmp3 = arg0[1]
tmp4 = atspre2py_add_int1_int1(arg1, 1)
#tailcal_beg
apy0 = tmp3
apy1 = tmp4
arg0 = apy0
arg1 = apy1
funlab_py = 1 #__patsflab_loop_1
#tailcal_end
return
mbranch_1 = { 1: __atstmplab0, 2: __atstmplab1, 3: __atstmplab2, 4:
__atstmplab3 }
while (1):
funlab_py = 0
#__patsflab_loop_1
#ATScaseof_beg
tmplab_py = 1
while (1):
mbranch_1.get(tmplab_py)()
if (tmplab_py == 0): break
#ATScaseof_end
if (funlab_py == 0): break
return tmpret1

(* ****** ****** *)

xs = cons(1, cons(2, cons(3, nil())))

print(“listlen(”, xs, “) =”, listlen(xs))

(* ****** ****** *)

On Wednesday, August 6, 2014 10:43:13 PM UTC-4, gmhwxi wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

</s

There is no documentation right now.

However, the code should be straightforward to follow.

And I will be happy to answer questions.

I myself do not write Python code. I am more interested in
generating Javascript code :)On Wed, Aug 6, 2014 at 10:59 PM, Brandon Barker brandon...@gmail.com wrote:

This is exciting! Is the documentation embedded in the source of
ATS-parse-emit?

Brandon Barker
brandon...@gmail.com

On Wed, Aug 6, 2014 at 10:43 PM, gmhwxi gmh...@gmail.com wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not
now.

Cheers!


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/798ce024-b9d2-4f43-add8-d0be6f1a696f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/798ce024-b9d2-4f43-add8-d0be6f1a696f%40googlegroups.com?utm_medium=email&utm_source=footer
.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAORbNRq_KP%3DQwkU_m_-JvQK-QgNJZ09dY3zsvOjwYpV939Djuw%40mail.gmail.com
https://groups.google.com/d/msgid/ats-lang-users/CAORbNRq_KP%3DQwkU_m_-JvQK-QgNJZ09dY3zsvOjwYpV939Djuw%40mail.gmail.com?utm_medium=email&utm_source=footer
.

This is exciting! Is the documentation embedded in the source of
ATS-parse-emit?

Brandon Barker
brandon…@gmail.comOn Wed, Aug 6, 2014 at 10:43 PM, gmhwxi gmh...@gmail.com wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not now.

Cheers!


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/798ce024-b9d2-4f43-add8-d0be6f1a696f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/798ce024-b9d2-4f43-add8-d0be6f1a696f%40googlegroups.com?utm_medium=email&utm_source=footer
.

ATSINSlab/ATSINSgoto are used for pattern matching compilation.
ATSINSflab/ATSINSfgoto are used to support tail-call optimization.
Because Python does not support jumps, ATSINSgoto and ATSINSfgoto
need to be removed. I will try to do it.

For compiling code to Python, I have no plan to handle pointer operations.
Or one may go the Cython road.

ATSmove_boxrec(tmp, T): create an uninitialized record of the type T, and
assign it to tmp.

ATSmove_boxrec is always followed by a few assignments for field
initialization;
they should probably grouped together and then translated into something
like:

tmp = (v1, v2, …, vn)On Thursday, August 7, 2014 12:03:22 PM UTC-4, Artyom Shalkhakov wrote:

Hongwei,

On Thursday, August 7, 2014 8:43:13 AM UTC+6, gmhwxi wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(
‘/home/hwxi/research/Postiats-contrib/git/projects/MEDIUM/ATS-parse-emit/Python/prelude’
)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

Yes, the above Python code works!

At this point, there is still a lot of work to be done before all of this
can actually be useful.

If someone is interested in making it work, I will be happy to offer a
hand. Unfortunately,
I myself do not have time to go further along this path. At least, not
now.

Some questions:

  1. what’s the difference between ATSINSlab and ATSINSflab, and between
    ATSINSgoto and ATSINSfgoto?
  2. what are pointer operations compiled to?
  3. what is ATSINSmove_boxrec?

Cheers!

hey, please! the web is dead! mobile first! and not that crappy html5
lies lies lies! sheesh. :-}

so i’d almost rather see another layer of abstraction. that’s both a
horrible joke, and a serious thought. (it is also easy for me to say
as somebody who isn’t working on this project.)

i.e.: use llvm bytecode! via Emscripten or whatever else! that way you
can get asm.js, and i can get code for mobile devices for games!

I myself do not write Python code. I am more interested in

  • generating Javascript* code :slight_smile:

The same for me!

Funny this thread comes now, as I was precisely thinking of trying to do
something similar in the future. Will have a look at it very soon,

Yes. But we have already got C covered :slight_smile:

The point here is to venture out, seeing if other popular languages can
be covered as well. Venturing out makes sense because the price is very
low. The heavy lifting has already been taken care of by ATS/Postiats.On Thursday, August 7, 2014 3:06:16 PM UTC-4, Yannick Duchêne wrote:

Le jeudi 7 août 2014 20:27:39 UTC+2, gmhwxi a écrit :

I think we can try all these approaches.

The target language of ATS is very small, and it should be
straightforward to translate it to llvm. Actually, it makes a lot
of sense to write a compiler for translating this target language
into object code since using gcc/clang is clearly an overkill.

This complaint makes some sense, but targeting C is a portability bonus.
Also, on most software store, you can submit C programs not any misc
language you use and even less binaries. And C is the most common
denominator, covering both Apple’s and Windows’s and Ubuntu’s own software
stores (at least Apple and Windows favour C, to get run safety static check
on the application… Ubuntu don’t, but still requires something which can be
compiled within a standard Ubuntu environment).

If you add the flag --gline:

patsopt --gline -o listlen_dats.c -d listlen.dats

then you will get line information on the source code in the output.

I have just added code for parsing line pragmas.

Great! Thanks!

I think we can try all these approaches.

The target language of ATS is very small, and it should be
straightforward to translate it to llvm. Actually, it makes a lot
of sense to write a compiler for translating this target language
into object code since using gcc/clang is clearly an overkill.On Thursday, August 7, 2014 1:48:44 PM UTC-4, Raoul Duke wrote:

hey, please! the web is dead! mobile first! and not that crappy html5
lies lies lies! sheesh. :-}

so i’d almost rather see another layer of abstraction. that’s both a
horrible joke, and a serious thought. (it is also easy for me to say
as somebody who isn’t working on this project.)

i.e.: use llvm bytecode! via Emscripten or whatever else! that way you
can get asm.js, and i can get code for mobile devices for games!

If you add the flag --gline:

patsopt --gline -o listlen_dats.c -d listlen.dats

then you will get line information on the source code in the output.

I have just added code for parsing line pragmas.On Sun, Aug 17, 2014 at 2:37 AM, Artyom Shalkhakov < artyom.s...@gmail.com> wrote:

Hongwei,

This is very nice!

Is it possible for atsopt to emit #line pragmas (instead of comments) so
that paremit would parse them?

I think that propagating such information is very important for
debugging/tracing purposes.

On Sunday, August 17, 2014 5:51:22 AM UTC+6, gmhwxi wrote:

Now I have added the support for pattern matching.

Here is an implementation of the list-length function in python
that is generated from some ATS source:

import sys
sys.path.append(‘/home/hwxi/research/Postiats-contrib/git/
projects/MEDIUM/ATS-parse-emit/Python/prelude/CATS’)
from integer_cats import *

(* ****** ****** *)

def nil(): return None
def cons(x, xs): return (x, xs)

def ATSCKptrisnil(xs): return (xs == None)
def ATSCKptriscons(xs): return (xs != None)

(* ****** ****** *)

extern

fun

listlen

: {a:t@ype} List0 (a) → int = “ext#”

//

(* ****** ****** *)

implement

listlen{a}

(xs) = let

//

prval () = lemma_list_param (xs)

//

fun

loop{i,j:nat} ..

(

xs: list (a, i), res: int(j)

) : int(i+j) = let

in

//

case+ xs of

| list_nil () => res | list_cons (_, xs) => loop (xs, res+1)

//

end // end of [loop]

//

in

loop (xs, 0)

end // end of [intlistlen]

def listlen(arg0):
tmpret0 = None
funlab_py = None
tmplab_py = None
#__patsflab_listlen
tmpret0 = loop_1(arg0, 0)
return tmpret0

def loop_1(arg0, arg1):
apy0 = None
apy1 = None
tmpret1 = None
tmp3 = None
tmp4 = None
funlab_py = None
tmplab_py = None
mbranch_1 = None
def __atstmplab0():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
if (ATSCKptriscons(arg0)): tmplab_py = 4 ; return#__atstmplab3
__atstmplab1()
return
def __atstmplab1():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmpret1 = arg1
return
def __atstmplab2():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
__atstmplab3()
return
def __atstmplab3():
nonlocal arg0, arg1
nonlocal apy0, apy1, tmpret1, tmp3, tmp4
nonlocal funlab_py, tmplab_py
nonlocal mbranch_1
tmplab_py = 0
tmp3 = arg0[1]
tmp4 = atspre2py_add_int1_int1(arg1, 1)
#tailcal_beg
apy0 = tmp3
apy1 = tmp4
arg0 = apy0
arg1 = apy1
funlab_py = 1 #__patsflab_loop_1
#tailcal_end
return
mbranch_1 = { 1: __atstmplab0, 2: __atstmplab1, 3: __atstmplab2, 4:
__atstmplab3 }
while (1):
funlab_py = 0
#__patsflab_loop_1
#ATScaseof_beg
tmplab_py = 1
while (1):
mbranch_1.get(tmplab_py)()
if (tmplab_py == 0): break
#ATScaseof_end
if (funlab_py == 0): break
return tmpret1

(* ****** ****** *)

xs = cons(1, cons(2, cons(3, nil())))

print(“listlen(”, xs, “) =”, listlen(xs))

(* ****** ****** *)

On Wednesday, August 6, 2014 10:43:13 PM UTC-4, gmhwxi wrote:

Hi,

I have been working on documenting the target language of ATS/Postiats.
It is a very small and standard subset of C. I have now got a functioning
parser
for it.

Today, I wrote some code to demonstrate how one might generate Python
code
from ATS source by making use of this parser:

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

As an example, here is some generated Python code

import sys
sys.path.append(‘/home/hwxi/research/Postiats-contrib/git/
projects/MEDIUM/ATS-parse-emit/Python/prelude’)
from integer_cats import *

def fact(arg0):
#__patsflab_fact
tmp1 = ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, 0)
if(tmp1):
tmp7 = atspre_g0int_sub_int(arg0, 1)
tmp6 = fact(tmp7)
tmpret0 = atspre_g0int_mul_int(arg0, tmp6)
else:
tmpret0 = 1
#endif
return(tmpret0)

def ATSLIB_056_prelude__gt_g0int_int__1__1(arg0, arg1):
#__patsflab_gt_g0int_int
tmp3__1 = atspre_g0int2int_int_int(arg1)
tmpret2__1 = atspre_g0int_gt_int(arg0, tmp3__1)
return(tmpret2__1)

print “fact(100) =”, fact(100)

</s


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/cdd1c384-c4fb-418a-8e96-62f73a4b7715%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/cdd1c384-c4fb-418a-8e96-62f73a4b7715%40googlegroups.com?utm_medium=email&utm_source=footer
.

This is great! I think I’ll try to write a compiler to IL bytecode. :slight_smile: