<div style="white-space:pre-wrap">Thanks Phil I was already informed about CCodeGenerator , it definitely helps but your PDF helps even more , I see now why Esteban recommended Slang. It looks like there is a lot I can use from both for my compiler. I am studying them and will be back with questions. Is this the right place to ask questions about Slang and CCodeGenerator ? I really like the idea of Slang of two modes one interpreter mode for pure smalltalk code and one for generating the c code. This was the direction I was going too. Prototype in Pharo and worry about generating the C++ code only when your code reaches production state. <br></div><div class="gmail_quote"><div dir="ltr">On Tue, 8 Mar 2016 at 15:25, <a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a> &lt;<a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr">Kilon,<div><br></div><div>Check <a href="http://www.smalltalkhub.com/#!/~PavelKrivanek/CCodeGenerator" target="_blank">http://www.smalltalkhub.com/#!/~PavelKrivanek/CCodeGenerator</a> as this is a standalone part for Slang support.</div><div><br></div><div>I did some changes in the past but I think Pavel integrated them back.</div><div><br></div><div><a href="http://www.smalltalkhub.com/#!/~philippeback/HOExtras/packages/CCodeGenerator-Core" target="_blank">http://www.smalltalkhub.com/#!/~philippeback/HOExtras/packages/CCodeGenerator-Core</a><br></div><div><br></div><div>Basically this thing allows you to write Slang, emit C code.</div><div><br></div><div>There is sample class to demonstrate:</div><div><br></div><div>* C code generation from Slang</div><div>* Using OSProcess to invoke C compiler to make a shared lib</div><div>* Loading it using NativeBoost</div><div><br></div><div>Here is the doc comment:</div><div><br></div><div><div>Generate the C code into generated.c</div><div><br></div><div>| cg |</div><div>cg := CCodeGenerator new initialize.</div><div>cg vmClass: CCGExample.</div><div>cg addClass: CCGExample.</div><div>CCGExample exportHeaders.</div><div>cg storeCodeOnFile: &#39;generated.c&#39; doInlining: false.  </div><div><br></div><div>Compile it</div><div><br></div><div>gcc -c -m32 generated.c</div><div>gcc -shared -m32 -o generated.dll generated.o</div><div><br></div><div>| c | </div><div>c := PipeableOSProcess command: &#39;gcc -c -m32 generated.c&#39;.</div><div>(c output; succeeded)</div><div><span style="white-space:pre-wrap">                </span>ifFalse: [ self error: &#39;Compilation error: &#39;, c errorPipelineContents printString].</div><div>c := PipeableOSProcess command: &#39;gcc -shared -m32 -o generated.dll generated.o&#39;.</div><div>(c output; succeeded)</div><div><span style="white-space:pre-wrap">                </span>ifFalse: [ self error: &#39;Compilation error&#39;, c errorPipelineContents printString].<span style="white-space:pre-wrap">                </span></div><div><span style="white-space:pre-wrap">                                </span></div><div>Try it</div><div><br></div><div>NativeBoost clearNativeCode.</div><div><br></div><div>CCGExample new nbFib4: 30.</div><div>CCGExample new nbFactorial: 5.</div></div><div><br></div><div><br></div><div>Slang code looking like this:</div><div><br></div><div><div>factorial: anArgument</div><div><br></div><div><span style="white-space:pre-wrap">        </span>&quot;&lt;var: #anArgument type: #&#39;double&#39;&gt;&quot;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>| count factorial |</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>self export: true.</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>count := anArgument.</div><div><span style="white-space:pre-wrap">        </span>factorial := 1.</div><div><span style="white-space:pre-wrap">        </span>[ count &gt; 0 ] whileTrue: </div><div><span style="white-space:pre-wrap">                </span>[ factorial := factorial * count.</div><div><span style="white-space:pre-wrap">                </span>count := count - 1 ].</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>^ factorial</div></div><div><br></div><div>Here is the PDF going into how to extend the VM with plugins and there is some Slang in there too.</div><div>Sure Spur may have changed things and this may require adjustments.</div><div><br></div><div>HTH</div></div><div dir="ltr"><div>Phil</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 8, 2016 at 11:15 AM, kilon.alios <span dir="ltr">&lt;<a href="mailto:kilon.alios@gmail.com" target="_blank">kilon.alios@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"><br>
Sorry for the late reply, I have been down with the flu lately.<br>
<br>
My goal is mostly curiosity , I am itching to try messing with programming<br>
languages but I also like keeping close with smalltalk syntax.<br>
<br>
The why is that I am aiming for readable C++ code that is easy to mix with<br>
existing C++ code. In my particular case is using and extending the Unreal<br>
Engine.<br>
<br>
I cannot do it via shared libraries because Unreal Engine is not made to be<br>
used as a library , it actually messes with a lot of things as you can<br>
imagine it has it own event loop, threading, GC and even adds reflection to<br>
C++. Also I need something that compiles statically for the iOS platform<br>
where shared libraries are not allowed, and I am not sure if Android has<br>
similar restrictions.<br>
<br>
So even though its great to use pharo unlimited as a scripting language, I<br>
think there is also usefuleness in limiting pharo usage (static types,<br>
memory managment etc) when you want to generate code in another programming<br>
language in my case C++.<br>
<br>
My crazy dream would be that pharo would be able to be used in any project<br>
inside a team, without any other team mates having to learn pharo. The<br>
advantage would be you will be able to use pharo not just for prototyping<br>
but even generate the source in another language and know would be able to<br>
guess you wrote the code in Pharo. Of course this idea is not really new or<br>
unique.<br>
<br>
However that dream is crazy , my more realistic dream is to build an<br>
enviroment of a collection of tools that allow to annotate pharo code<br>
without changing it, for example you can annotate what type a variable is or<br>
what variable is actually a pointer what kind of pointer (raw or smart)<br>
which method would use C++ templates etc. Then a compiler will take the<br>
pharo code plus the annotations and convert it to C++ code that is readable<br>
as much as possible. That means of course there will be some sever<br>
limitations of how one codes in Pharo in order to translate with ease to<br>
C++.<br>
<br>
<br>
I have been pointed here because you guys are doing something similar with<br>
Slang though I am not sure whether Slang produces readable C code since it<br>
looks like it does not impose any sever limitations to Smalltalk usage but<br>
then I can be wrong.<br>
<br>
In any case I am open to advice and suggestions.<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://forum.world.st/Fwd-Pharo-users-Understanding-Slang-for-building-a-compiler-to-C-tp4882613p4883161.html" rel="noreferrer" target="_blank">http://forum.world.st/Fwd-Pharo-users-Understanding-Slang-for-building-a-compiler-to-C-tp4882613p4883161.html</a><br>
Sent from the Squeak VM mailing list archive at Nabble.com.<br>
<br>
</blockquote></div><br></div>
</blockquote></div>