# ATS-par-emit: labels for instructions

**URL:** <https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713>\
**Category:** Google Group\
**Created:** [August 18, 2014, 3:49pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713 "2014-08-18T15:49:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [August 18, 2014, 3:49pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/1 "2014-08-18T15:49:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 19, 2014, 12:20am UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/2 "2014-08-19T00:20:13Z")

</div>

> 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.On Monday, August 18, 2014 2:52:58 PM UTC-4, Raoul Duke wrote:

> > 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.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 19, 2014, 2:53pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/3 "2014-08-19T14:53:04Z")

</div>

> 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))On Tuesday, August 19, 2014 12:11:52 AM UTC-4, Artyom Shalkhakov wrote:

> 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 (  
> [code generation · githwxi/ATS-Postiats Wiki · GitHub](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.
> 
> > On Monday, August 18, 2014 11:49:16 AM UTC-4, Artyom Shalkhakov wrote:
> > 
> > > 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?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 19, 2014, 4:10pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/4 "2014-08-19T16:10:44Z")

</div>

I added a function tmpvar\_is\_arg to atsparemit\_syntax.sats.On Tuesday, August 19, 2014 10:53:04 AM UTC-4, gmhwxi wrote:

> 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))
> 
> On Tuesday, August 19, 2014 12:11:52 AM UTC-4, Artyom Shalkhakov wrote:
> 
> > 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 (  
> > [code generation · githwxi/ATS-Postiats Wiki · GitHub](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.
> > 
> > > On Monday, August 18, 2014 11:49:16 AM UTC-4, Artyom Shalkhakov wrote:
> > > 
> > > > 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?

---

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [August 19, 2014, 4:11am UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/5 "2014-08-19T04:11:52Z")

</div>

> 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  
([code generation · githwxi/ATS-Postiats Wiki · GitHub](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.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 18, 2014, 4:22pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/6 "2014-08-18T16:22:56Z")

</div>

Yes, another pass.

You can introduce another type instr2 for instructions and then translate  
instr to instr2.On Monday, August 18, 2014 11:49:16 AM UTC-4, Artyom Shalkhakov wrote:

> 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?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 18, 2014, 8:09pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/7 "2014-08-18T20:09:22Z")

</div>

> 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](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

---

<div class="post-metadata">

**Author:** ![Raoul\_Duke](https://avatars.discourse-cdn.com/v4/letter/r/bbe5ce/32.png) [@Raoul\_Duke](https://discourse.ats-lang.org/u/Raoul_Duke)\
**Post date:** [August 18, 2014, 5:59pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/8 "2014-08-18T17:59:22Z")

</div>

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](http://www.shenlanguage.org) or even  
[http://www.haxe.org](http://www.haxe.org) which are languages with multiple back-ends,  
sometimes where it is formalized (shen) and less so for others  
(haxe).]

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 18, 2014, 6:33pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/9 "2014-08-18T18:33:46Z")

</div>

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](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.On Monday, August 18, 2014 1:59:43 PM UTC-4, Raoul Duke wrote:

> 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](http://www.shenlanguage.org) or even  
> [http://www.haxe.org](http://www.haxe.org) which are languages with multiple back-ends,  
> sometimes where it is formalized (shen) and less so for others  
> (haxe).]

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [August 19, 2014, 4:15am UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/10 "2014-08-19T04:15:02Z")

</div>

d0exp for dynamic expressions and instr for instructions (statements).On Tue, Aug 19, 2014 at 12:11 AM, Artyom Shalkhakov \< [artyom.s...@gmail.com](mailto:artyom.s...@gmail.com)\> wrote:

> 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 (  
> [code generation · githwxi/ATS-Postiats Wiki · GitHub](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.
> 
> > On Monday, August 18, 2014 11:49:16 AM UTC-4, Artyom Shalkhakov wrote:
> > 
> > > 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?
> > 
> > –  
> > 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](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](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](https://groups.google.com/d/msgid/ats-lang-users/f63c9f39-fd3e-4739-9403-807b708f8091%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/f63c9f39-fd3e-4739-9403-807b708f8091%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/f63c9f39-fd3e-4739-9403-807b708f8091%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .

---

<div class="post-metadata">

**Author:** ![Raoul\_Duke](https://avatars.discourse-cdn.com/v4/letter/r/bbe5ce/32.png) [@Raoul\_Duke](https://discourse.ats-lang.org/u/Raoul_Duke)\
**Post date:** [August 18, 2014, 6:52pm UTC](https://discourse.ats-lang.org/t/ats-par-emit-labels-for-instructions/713/11 "2014-08-18T18:52:37Z")

</div>

> 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.
