<br><div class="gmail_quote">On Sat, Apr 21, 2012 at 3:03 AM, Michael Haupt <span dir="ltr">&lt;<a href="mailto:mhaupt@gmail.com" target="_blank">mhaupt@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div bgcolor="#FFFFFF"><div>Hi Ricardo,<br></div></div></blockquote><div><br></div><div>Hi Michael,</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF">

<div><blockquote type="cite"><div><div><ol><li>We added a new programming mode that lets you compile your scripts and have them running inside the robot, in contrast to running them in the computer and communicate with the robot via bluetooth or usb. We believe this opens a lot of new posibilities for the Physical Etoys users.</li>


</ol></div></div></blockquote></div><div>Can you give some details? I figure you&#39;d have to compile the programs somehow to let them run in isolation. How do you do that for Arduino, and how for the NXT?</div><div>
<div><br></div></div></div></blockquote><div><br></div><div>Yes, we&#39;re using the same mechanism for both Arduino and Lego Nxt. We made a very simple Smalltalk to C translator, which takes a Smalltalk class and generates a valid C/C++ program (C++ for Arduino and NXC for Lego Nxt, actually). Then we talk to the compiler libraries for each platform (avr-gcc/avrdude for Arduino and NBC for Lego Nxt) and let them compile and program the robot.</div>

<div><br></div><div>The process is actually a little bit more complicated than that because to translate the Etoys scripts, which can be represented by several different Player subclasses, first we need to merge them in one class. This is a restriction enforced by the translator which requires as input only one class with one entry point (even though it will then generate code for all the referred classes). Also, this one class representing the Etoys program must simulate the script&#39;s ticking, for which I simply create an eternal loop that constantly goes through the list of scripts and executes them if they have to run at that time.</div>

<div><br></div><div>All in all, the C code generation is actually very simple, but it took us quite some time to implement it. At first I started using Squeak&#39;s parser but then Serge Stinckwich was kind enough to point me to the Refactoring Browser&#39;s parser, which has a much simpler hierarchy of parse nodes IMHO. That, combined with the visitor pattern, is all we needed to translate the code.</div>

<div><br></div><div>Currently, the translator only supports a very small subset of Smalltalk, easily identifiable by the hierarchy of CObject and its subclasses. It&#39;s so basic that it doesn&#39;t even support blocks (except as arguments of primitive methods), polymorphism or dynamic typing (we use pragmas to specify the variable types). So it&#39;s not actually very fun to write code for it (it&#39;s more like C code disguised as smalltalk) but it&#39;s good enough for Etoys scripts and it has seemed to work fine... at least on our lab, let&#39;s see how it goes in the real world :)</div>

<div><br></div><div>When we started doing this for Lego Nxt we looked briefly at NXTalk but we decided against it because we had as a requirement to be compatible with the Lego standard firmware so that the kid could use both Physical Etoys and the Lego software to program his robot. We think we made the right choice, specially because the same code for the Lego Nxt was then used for Arduino without too many changes.</div>

<div><br></div><div>If you want to have a look, all the code is available at the following squeaksource repositories: CTranslator, Arduino and SqueakNxt. Look for the packages that end with &quot;Compiler&quot; in the last two. Don&#39;t expect it to be fully documented, though :)</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF"><div>
<div></div><blockquote type="cite"><div><div>

<div>And also, I would like to announce that Physical Etoys 2.0 is going to be installed by default on all the laptops of the &quot;Conectar igualdad&quot; program, which is kind of like the argentinian version of OLPC (but for older students). So we are *really* excited about this!</div>


</div></div></blockquote><div><br></div></div><div>Congratulations! That is a great achievement.</div></div></blockquote><div><br></div><div>Thanks, we believe that too and we&#39;re very happy about it.</div><div> </div>

<div>Cheers,</div><div>Richo</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF"><br><blockquote type="cite"><div><div>

</div></div></blockquote><div>Best,</div><div><br></div><div>Michael</div></div><br><br>
<br></blockquote></div><br>