The myatscc utility

276 views
Skip to first unread message

gmhwxi

unread,
Apr 25, 2017, 8:24:19 PM4/25/17
to ats-lang-users

Often a file of ATS source code has to be compiled with the use of a Makefile.
This can be quite inconvenient in practice.

When teaching, I have to answer countless questions regarding the need of certain
flags for compiling ATS code through the use of patscc/patsopt directly.

I recently wrote a command 'myatscc' (which should be available to you if you build
the latest version of ATS (that is, ATS2-0.3.5). The simple idea behind of 'myatscc' is
like this:

Given a file, say, foo.dats, one should be able to compile it by issuing the following
command:

myatscc foo.dats

Whatever needed for compiling foo.dats should be written as some form of comment
inside foo.dats. For instance, the following comment is assumed to be the default (if
nothing is given explicitly):

(*
##myatsccdef=\
patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -o $fname($1) $1
*)

$1: the first non-flag argument passed to myatscc
$fname: a built-in function for myatscc that returns the proper part of a filename

If you just want to see what myatscc generates (but not to execute what is generated),
please do:

myatscc --dryrun foo.dats

I am pretty sure that 'myatscc' will save a great deal of my own time :)

Cheers!

Artyom Shalkhakov

unread,
Apr 27, 2017, 12:23:30 AM4/27/17
to ats-lang-users
Hi Hongwei,
This is awesome!

Can it compile multi-module programs too? I currently have a very clumsy Makefile setup here:


(see specifically the Makefile)

The way I see it, it should be possible for the compiler (or some other tool) to infer module dependencies automatically?

Incidentally, we discussed the ways of automating programmer's workflow here:


I'm going to try to adapt the existing xmake project to tailor it to the needs of ATS programming. I don't have much time for this, at the moment, though.
 
Cheers!

gmhwxi

unread,
Apr 27, 2017, 1:56:01 AM4/27/17
to ats-lang-users
Thanks!

These days I have been thinking about (and working on) a tutorial system
for ATS. And myatscc is an attempt to provide an option that avoids the need
to make directly use of patscc/patsopt.

Yes, you can use myatscc to compile multiple files. I will be happy to show
it to you.

First, I suggest that you make an npm-package for ats3d, which, by the way,
is beautifully written.

If you are not familiar with the process of npm-packaging, I will be happy to do it.
It does not take much time at all. Afterwards, let use myatscc to compile all the
test files inside ats3d/TEST.


>>The way I see it, it should be possible for the compiler (or some other tool) to infer module dependencies automatically?

I have not thought about it carefully.


Incidentally, we discussed the ways of automating programmer's workflow here:
I'm going to try to adapt the existing xmake project to tailor it to the needs of ATS programming. I don't have much time for this, at the moment, though.

Sounds great! I will talk to Ryan.
 

gmhwxi

unread,
May 7, 2017, 11:12:38 PM5/7/17
to ats-lang-users
FYI.

In case one wants to use ATS as a scripting language,
please include the following comment in the file containing
scripting code written in ATS:

(*
##myatsccdef=\
patsopt --constraint-ignore --dynamic $1 | \
tcc -run -DATS_MEMALLOC_LIBC -I${PATSHOME} -I${PATSHOME}/ccomp/runtime - $arglst(2)
*)

'tcc' is for Tiny C Compiler, which can compile about 1M lines of C per second.

gmhwxi

unread,
May 23, 2017, 8:23:18 AM5/23/17
to ats-lang-users
FYI.

Here is another MYATSCCDEF that allows you to
compile and run a single-file ATS program without
installing patscc/patsopt (but you do need ATS2-include
for all the necessary header files):

(*
##myatsccdef=\
curl --data-urlencode mycode@$1 \
http://bucs320-tutoriats.rhcloud.com/\
SERVICE/assets/patsopt_ccats_eval_code_0_.php | \
php -R 'if (\$argn != \"\") echo(json_decode(urldecode(\$argn))[1].\"\\n\");' | \
tcc -run -std=c99 -D_XOPEN_SOURCE -I\${PATSHOME} -I\${PATSHOME}/ccomp/runtime -L\${PATSHOME}/ccomp/atslib/lib -o $fname($1) -x c -
*)

Please visit the link:

http://www.ats-lang.org/Downloads.html#Install_of_ATS2_include

for information on installing ATS2-include.

If you don't have 'tcc', you can try 'gcc' or 'clang'.

Cheers!

Julian Fondren

unread,
Feb 9, 2018, 10:53:19 PM2/9/18
to ats-lang-users
Scripts are typically invoked directly, as "tool" where tool is in your PATH, or "./tool"

In Unix, the kernel itself finds the scripting binary to run an executable file beginning with #!
So languages intended for scripting use typically accept #! or # as a line comment.

ATS doesn't accept it as a comment, but you can make do with some overhead:

$ cat hello.dats 
//usr/bin/env myatscc "$0"; exit
(*
##myatsccdef=\
patsopt --constraint-ignore --dynamic $1 | \
tcc -run -DATS_MEMALLOC_LIBC -I${PATSHOME} -I${PATSHOME}/ccomp/runtime - $arglst(2)
*)

implement main0() = println!("Hello, world!")
$ ./hello.dats 
Hello, world!

The next step would be to cache the compilation entirely, as with https://github.com/mjambon/ocamlscript

gmhwxi

unread,
Feb 10, 2018, 9:45:42 AM2/10/18
to ats-lang-users
Very interesting. I didn't know this.

What do you mean by caching compilation?

Julian Fondren

unread,
Feb 10, 2018, 7:28:20 PM2/10/18
to ats-lang-users
By 'caching compilation' I mean that the machine code is saved and not regenerated until there are updates to the source code. With this normal optimizations and normal error-checking can be performed. You can do this by having a deterministic location for the produced executable ("script.exe", say) and then on startup testing the file modification time of the source and the generated executable when that exists: if the executable exists and is newer than the source, just exec it; otherwise, rebuild it and then exec it.

Marcello Presulli

unread,
Apr 11, 2018, 3:13:58 AM4/11/18
to ats-lang-users
Hi community,

i don't know if it's useful, but if someone wants to build and execute a "myatscc" code definiton in-situ via .dats file itself, here it is:

$ cat hello.dats
exec <$0 ; read ; cat > $0.dats ; exec myatscc $0.dats $@

(*
##myatsccdef=patscc -cleanaft -o $fname($fname($1)) $1 -DATS_MEMALLOC_LIBC -I${PATSHOME} $arglst(2) ; rm $1 ; ./$fname($fname($1))
*)

implement main0() = println!("Hello, world!")


Cheers,
Marcello
Message has been deleted

richard

unread,
May 19, 2018, 8:18:03 AM5/19/18
to ats-lang-users
(*
##myatsccdef=\
curl --data-urlencode mycode@$1 \

http://bucs320-tutoriats.rhcloud.com/\
SERVICE/assets/patsopt_ccats_eval_code_0_.php | \
php -R 'if (\$argn != \"\") echo(json_decode(urldecode(\$argn))[1].\"\\n\");' | \
tcc -run -std=c99 -D_XOPEN_SOURCE -I\${PATSHOME} -I\${PATSHOME}/ccomp/runtime -L\${PATSHOME}/ccomp/atslib/lib -o $fname($1) -x c -
*)
 
Pure Wizardry.

Here is a slightly different example,
//usr/bin/env myatscc "$0" && ./$(echo "$0" | sed 's/\.dats/_dats/g') ; exit

extern
fun system
:(string) -> int = "mac#system"

implement
main0
() = () where
{
  val _
= system("patsopt")
}

(* end of [hello.dats] *)
 
Run via,
$ sh hello.dats
 
Hello from ATS2(ATS/Postiats)!



Reply all
Reply to author
Forward
0 new messages