ATS-par-emit: labels for instructions

39 views
Skip to first unread message

Artyom Shalkhakov

unread,
Aug 18, 2014, 11:49:16 AM8/18/14
to ats-lan...@googlegroups.com
I'm trying to emit CIL from ATS2. Conditionals need to be translated into conditional jumps.

Not every instruction in instrlst is labeled with ATSINSflab/ATSINSlab, so it seems that a pass is needed to insert missing labels or some such.

What's the easiest way to proceed?

gmhwxi

unread,
Aug 18, 2014, 12:22:56 PM8/18/14
to ats-lan...@googlegroups.com
Yes, another pass.

You can introduce another type instr2 for instructions and then translate
instr to instr2.

Raoul Duke

unread,
Aug 18, 2014, 1:59:43 PM8/18/14
to ats-lang-users
seems like there are now multiple people trying to target ATS at other
back-ends. it would be great if your efforts were somehow aligned and
documented so that this could be sort of a standard way for ATS to
grow.

[cf. things such as http://www.shenlanguage.org or even
http://www.haxe.org which are languages with multiple back-ends,
sometimes where it is formalized (shen) and less so for others
(haxe).]

gmhwxi

unread,
Aug 18, 2014, 2:33:46 PM8/18/14
to ats-lan...@googlegroups.com

At this stage, I am mostly experimenting.

Originally, I planned to target Javascript, but I am targeting Python
instead. I think Python is a bit harder to handle because it does not
support *directly* switch statements. All of my code is on-line:

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

I still plan to target Javascript later. I learned that Will Blair
would like to target Javascript as well.

Alignment and documentation will come later if they do come. It is in
general very difficult to get a good software product during the first try.
Iterations are often needed.

Raoul Duke

unread,
Aug 18, 2014, 2:52:58 PM8/18/14
to ats-lang-users
> Alignment and documentation will come later if they do come. It is in
> general very difficult to get a good software product during the first try.
> Iterations are often needed.

of course, hear hear. too much early 'standardization' slows down the
experimenting too much.



still, having looked and and used some other languages that have
multiple back-ends $0.02:

so one of the ways in which Shen does a better job than I think Haxe
is that Shen tries to have a quite small kernel language. then the
full language sits on top of it, and target languages sit underneath.
it has benefits and drawbacks, of course.

that is the kind of thing that I think would be interesting for ATS
people to talk about. I see the way Haxe has gone and frankly when I
use it, I see that it is a big fat lie in so many ways e.g. the Java
back end is (historically maybe less so now) drastically and rather
dishonestly incomplete.

i'd hope that ATS could (some day) take a minute to gather stock and
see if there could be some unifying strategies here.

gmhwxi

unread,
Aug 18, 2014, 4:09:22 PM8/18/14
to ats-lan...@googlegroups.com
that is the kind of thing that I think would be interesting for ATS
people to talk about. I see the way Haxe has gone and frankly when I
use it, I see that it is a big fat lie in so many ways e.g. the Java
back end is (historically maybe less so now) drastically and rather
dishonestly incomplete.

What I wanted and want is a style of co-programming with ATS and Python.

I have been advocating refinement-based programming for quite some time.
See: http://www.ats-lang.org/EXAMPLE/EFFECTIVATS/mergesort/main.html

When programming in a language like Python, one does not really do program
design explicitly; one just writes code and then tests. A great advantage of ATS
lies in its strong support for specification. For instance, the above link contains a
so-called specification-like implementation of mergesort in ATS; it is *not* a running
implementation; it is just some sort of a skeleton. However, I can typecheck the skeleton
in ATS to gain confidence in its correctness.

With a code generator from ATS to Python, I can now combine the skeleton with the rest of code
written in Python directly (instead of having to translate the skeleton to Python manually).
In this way, I can even advocated refinement-based programming to Python programmers
(who are willing to use ATS to do top-level specification-like implementation). To me, this is
a promising way to get (formal) specification into mainstream programming.



i'd hope that ATS could (some day) take a minute to gather stock and
see if there could be some unifying strategies here.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

gmhwxi

unread,
Aug 18, 2014, 8:20:13 PM8/18/14
to ats-lan...@googlegroups.com
i'd hope that ATS could (some day) take a minute to gather stock and
see if there could be some unifying strategies here.

Certainly!

The current target language for ATS.Postiats makes essential use of
goto statements. It makes sense to first translate the target language into
another one that does not involve ny goto statements. In this way, targeting
languages that do not support goto statements can be made a lot easier.

Python makes things a bit harder because it does not even support switch
statements directly.
 

Artyom Shalkhakov

unread,
Aug 19, 2014, 12:11:52 AM8/19/14
to ats-lan...@googlegroups.com
On Monday, August 18, 2014 10:22:56 PM UTC+6, gmhwxi wrote:
Yes, another pass.

You can introduce another type instr2 for instructions and then translate
instr to instr2.

OK. One more question: what's the difference between d0exp (dynamic expressions?) and instr? Why are the two separated? For instance, d0exp contains function application primitive, whereas instr does not. I made some wiki edits (https://github.com/githwxi/ATS-Postiats/wiki/code-generation), but then got confused.

And another question: I'd like to separate arguments from local variables (for IL has different instructions for handling those); currently the code will check the symbol string (if it starts with "arg", then it's an argument). Guess this would be solved with instr2 (or d0exp2). Function calls need to be annotated with types of the functions being called, too. Again, this is work for another pass.

I'd like people who are knowledgeable about JVM to chime in. Perhaps IL instruction set isn't much different from that of JVM? Some code could be shared between two backends, then.
 

Hongwei Xi

unread,
Aug 19, 2014, 12:15:03 AM8/19/14
to ats-lan...@googlegroups.com
d0exp for dynamic expressions and instr for instructions (statements).



--
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/f63c9f39-fd3e-4739-9403-807b708f8091%40googlegroups.com.

gmhwxi

unread,
Aug 19, 2014, 10:53:04 AM8/19/14
to ats-lan...@googlegroups.com
And another question: I'd like to separate arguments from local variables (for IL has different instructions for handling those); currently the code will check the symbol string (if it starts with "arg", then it's an argument).

Forgot to answer this one.

Yes, checking if the name begins with 'arg' is the right way to do it.

staload STRING = "libc/SATS/string.sats"

fun symbol_is_arg
(x: symbol): bool =
 
$STRING.strncmp (symbol_get_name(x), "arg", i2sz(3))

gmhwxi

unread,
Aug 19, 2014, 12:10:44 PM8/19/14
to ats-lan...@googlegroups.com
I added a function tmpvar_is_arg to atsparemit_syntax.sats.
Reply all
Reply to author
Forward
0 new messages