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)
--
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.
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.
I myself do not write Python code. I am more interested ingenerating Javascript code :)
Cheers!
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.
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} .<i>.
# (
# 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))
# (* ****** ****** *)
...
</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.
If you add the flag --gline:then you will get line information on the source code in the output.
patsopt --gline -o listlen_dats.c -d listlen.datsI have just added code for parsing line pragmas.