# From ATS to PHP

**URL:** <https://discourse.ats-lang.org/t/from-ats-to-php/318>\
**Category:** Google Group\
**Created:** [August 29, 2014, 3:39am UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318 "2014-08-29T03:39:57Z")\
**Posts on this page:** 7\
**Page:** 1

<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 29, 2014, 3:39am UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/1 "2014-08-29T03:39:57Z")

</div>

I also wrote a code generator from ATS to PHP:

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP)

Compared to the code generators for Python and JavaScript, the one for PHP  
is much simpler. If you  
are interested in writing a code generator from ATS to some language X, I  
recommend that you study  
this one first.

Here is some generated code:

\<?php /\* \*\* The PHP code is generated by atscc2php \*\* The starting compilation time is: 2014-8-28: 23h:35m \*/ function fibats($arg0) { /\* // $tmpret0 \*/ \_\_patsflab\_fibats: $tmpret0 = loop\_1($arg0, 0, 1); return $tmpret0; } // end-of-function function loop\_1($arg0, $arg1, $arg2) { /\* // $apy0 // $apy1 // $apy2 // $tmpret1 // $tmp2 // $tmp3 // $tmp4 \*/ \_\_patsflab\_loop\_1: $tmp2 = ats2phppre\_gt\_int1\_int1($arg0, 0); if($tmp2) { $tmp3 = ats2phppre\_sub\_int1\_int1($arg0, 1); $tmp4 = ats2phppre\_add\_int1\_int1($arg1, $arg2); // ATStailcalseq\_beg $apy0 = $tmp3; $apy1 = $arg2; $apy2 = $tmp4; $arg0 = $apy0; $arg1 = $apy1; $arg2 = $apy2; goto \_\_patsflab\_loop\_1; // ATStailcalseq\_end } else { $tmpret1 = $arg1; } // endif return $tmpret1; } // end-of-function /\* \*\*\*\*\*\* \*\*\*\*\*\* \*/ /\* end-of-compilation-unit \*/ ?\>

More examples can be found at

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST)

---

<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:** [September 28, 2014, 3:03pm UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/2 "2014-09-28T15:03:21Z")

</div>

ATS is first compiled into a simple subset of C. Then it is just a matter  
of interpreting this subset in PHP.  
By the way, not all of ATS can be compiled this way. So far, what is  
supported includes the functional core  
(datatypes + higher-order functions) plus templates.On Sat, Sep 27, 2014 at 10:24 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com)\> wrote:

> Le vendredi 29 août 2014 05:39:57 UTC+2, gmhwxi a écrit :
> 
> > I also wrote a code generator from ATS to PHP:
> > 
> > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP)
> > 
> > Compared to the code generators for Python and JavaScript, the one for  
> > PHP is much simpler. If you  
> > are interested in writing a code generator from ATS to some language X, I  
> > recommend that you study  
> > this one first.
> 
> Please, how do code generation take care of the target language semantic?  
> Is this based on reasonably safe and predictable subset or average  
> assumptions? (I mean in the general case, not specifically PHP).
> 
> –  
> 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/e2e02e43-85de-4f20-a9bb-64a781e16e2a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/e2e02e43-85de-4f20-a9bb-64a781e16e2a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/e2e02e43-85de-4f20-a9bb-64a781e16e2a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/e2e02e43-85de-4f20-a9bb-64a781e16e2a%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:** [September 29, 2014, 6:21am UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/3 "2014-09-29T06:21:19Z")

</div>

> ATS is first compiled into a simple subset of C. Then it is just a matter of  
> interpreting this subset in PHP. By the way, not all of ATS can be compiled this way.

So, there are also other “kernels” that could be targeted, to give  
more/other portability to ATS.

E.g. Shen ; [http://shenlanguage.org](http://shenlanguage.org) ;  
[https://thestrangeloop.com/sessions/shen-a-sufficiently-advanced-lisp](https://thestrangeloop.com/sessions/shen-a-sufficiently-advanced-lisp)

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [September 28, 2014, 2:24am UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/4 "2014-09-28T02:24:13Z")

</div>

> I also wrote a code generator from ATS to PHP:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP)
> 
> Compared to the code generators for Python and JavaScript, the one for PHP  
> is much simpler. If you  
> are interested in writing a code generator from ATS to some language X, I  
> recommend that you study  
> this one first.

Please, how do code generation take care of the target language semantic?  
Is this based on reasonably safe and predictable subset or average  
assumptions? (I mean in the general case, not specifically PHP).

---

<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:** [September 2, 2014, 11:55pm UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/5 "2014-09-02T23:55:07Z")

</div>

PHP is a very wild language!

After bitten unexpectedly and repeatedly, I have finally managed to support  
lists and arrays  
for atscc2php. Here is an implementation of Game-of-24:

[http://www.ats-lang.org/COMPILED/doc/PROJECT/SMALL/GameOf24/PHP/inputform.html](http://www.ats-lang.org/COMPILED/doc/PROJECT/SMALL/GameOf24/PHP/inputform.html)

The ATS source can be found at:

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/GameOf24/PHPOn](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/GameOf24/PHPOn) Friday, August 29, 2014 5:53:50 PM UTC-4, gmhwxi wrote:

> Here is an example that makes use of some PHP code generated from ATS  
> source:
> 
> [http://www.ats-lang.org/COMPILED/doc/PROJECT/MEDIUM/ATS-parse-emit/PHP/orderform.html](http://www.ats-lang.org/COMPILED/doc/PROJECT/MEDIUM/ATS-parse-emit/PHP/orderform.html)
> 
> On Thursday, August 28, 2014 11:39:57 PM UTC-4, gmhwxi wrote:
> 
> > I also wrote a code generator from ATS to PHP:
> > 
> > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP)
> > 
> > Compared to the code generators for Python and JavaScript, the one for  
> > PHP is much simpler. If you  
> > are interested in writing a code generator from ATS to some language X, I  
> > recommend that you study  
> > this one first.
> > 
> > Here is some generated code:
> > 
> > \<?php /\* \*\* \*\* The PHP code is generated by atscc2php \*\* The starting compilation time is: 2014-8-28: 23h:35m \*\* \*/ function fibats($arg0) { /\* // $tmpret0 \*/ \_\_patsflab\_fibats: $tmpret0 = loop\_1($arg0, 0, 1); return $tmpret0; } // end-of-function function loop\_1($arg0, $arg1, $arg2) { /\* // $apy0 // $apy1 // $apy2 // $tmpret1 // $tmp2 // $tmp3 // $tmp4 \*/ \_\_patsflab\_loop\_1: $tmp2 = ats2phppre\_gt\_int1\_int1($arg0, 0); if($tmp2) { $tmp3 = ats2phppre\_sub\_int1\_int1($arg0, 1); $tmp4 = ats2phppre\_add\_int1\_int1($arg1, $arg2); // ATStailcalseq\_beg $apy0 = $tmp3; $apy1 = $arg2; $apy2 = $tmp4; $arg0 = $apy0; $arg1 = $apy1; $arg2 = $apy2; goto \_\_patsflab\_loop\_1; // ATStailcalseq\_end } else { $tmpret1 = $arg1; } // endif return $tmpret1; } // end-of-function /\* \*\*\*\*\*\* \*\*\*\*\*\* \*/ /\* end-of-compilation-unit \*/ ?\>
> > 
> > More examples can be found at
> > 
> > [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST)

---

<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 29, 2014, 9:53pm UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/6 "2014-08-29T21:53:50Z")

</div>

Here is an example that makes use of some PHP code generated from ATS  
source:

[http://www.ats-lang.org/COMPILED/doc/PROJECT/MEDIUM/ATS-parse-emit/PHP/orderform.htmlOn](http://www.ats-lang.org/COMPILED/doc/PROJECT/MEDIUM/ATS-parse-emit/PHP/orderform.htmlOn) Thursday, August 28, 2014 11:39:57 PM UTC-4, gmhwxi wrote:

> I also wrote a code generator from ATS to PHP:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP)
> 
> Compared to the code generators for Python and JavaScript, the one for PHP  
> is much simpler. If you  
> are interested in writing a code generator from ATS to some language X, I  
> recommend that you study  
> this one first.
> 
> Here is some generated code:
> 
> \<?php /\* \*\* \*\* The PHP code is generated by atscc2php \*\* The starting compilation time is: 2014-8-28: 23h:35m \*\* \*/ function fibats($arg0) { /\* // $tmpret0 \*/ \_\_patsflab\_fibats: $tmpret0 = loop\_1($arg0, 0, 1); return $tmpret0; } // end-of-function function loop\_1($arg0, $arg1, $arg2) { /\* // $apy0 // $apy1 // $apy2 // $tmpret1 // $tmp2 // $tmp3 // $tmp4 \*/ \_\_patsflab\_loop\_1: $tmp2 = ats2phppre\_gt\_int1\_int1($arg0, 0); if($tmp2) { $tmp3 = ats2phppre\_sub\_int1\_int1($arg0, 1); $tmp4 = ats2phppre\_add\_int1\_int1($arg1, $arg2); // ATStailcalseq\_beg $apy0 = $tmp3; $apy1 = $arg2; $apy2 = $tmp4; $arg0 = $apy0; $arg1 = $apy1; $arg2 = $apy2; goto \_\_patsflab\_loop\_1; // ATStailcalseq\_end } else { $tmpret1 = $arg1; } // endif return $tmpret1; } // end-of-function /\* \*\*\*\*\*\* \*\*\*\*\*\* \*/ /\* end-of-compilation-unit \*/ ?\>
> 
> More examples can be found at
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/ATS-parse-emit/PHP/TEST)

---

<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:** [September 29, 2014, 5:21pm UTC](https://discourse.ats-lang.org/t/from-ats-to-php/318/7 "2014-09-29T17:21:17Z")

</div>

Indeed. However, this should probably be done by someone who wants to use  
such a code generator.

I did atscc2js and atscc2php because I wanted to use them to add some  
dynamic  
content to the ATS webpage.On Mon, Sep 29, 2014 at 2:21 AM, Raoul Duke [rao...@gmail.com](mailto:rao...@gmail.com) wrote:

> > ATS is first compiled into a simple subset of C. Then it is just a  
> > matter of  
> > interpreting this subset in PHP. By the way, not all of ATS can be  
> > compiled this way.
> 
> So, there are also other “kernels” that could be targeted, to give  
> more/other portability to ATS.
> 
> E.g. Shen ; [http://shenlanguage.org](http://shenlanguage.org) ;  
> [https://thestrangeloop.com/sessions/shen-a-sufficiently-advanced-lisp](https://thestrangeloop.com/sessions/shen-a-sufficiently-advanced-lisp)
> 
> –  
> 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/CAJ7XQb6YOPLo19%2B4HToA0fPYUw9ZYJQ%2BCcD\_tkFRuWjXW2BXAA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb6YOPLo19%2B4HToA0fPYUw9ZYJQ%2BCcD_tkFRuWjXW2BXAA%40mail.gmail.com)  
> .
