<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RedBrain @ $HOME : ~ $ &#187; compiler</title>
	<atom:link href="http://redbrain.co.uk/index.php/tag/compiler/feed/" rel="self" type="application/rss+xml" />
	<link>http://redbrain.co.uk</link>
	<description>Frustrated Software Developer</description>
	<lastBuildDate>Wed, 16 Nov 2011 17:36:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Gccpy &#8211; Call for help!</title>
		<link>http://redbrain.co.uk/index.php/update/gccpy-call-for-help/</link>
		<comments>http://redbrain.co.uk/index.php/update/gccpy-call-for-help/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 02:38:01 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[gccpy]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=614</guid>
		<description><![CDATA[<p>Hey guys, so its been a while I&#8217;ve got a lot of stuff done and many core things working in Gccpy now more links on how to get up and running with it soon.</p>
<p>I am asking for help from you or from your friend.. anyone, all you need is:</p>
<p class="wp-caption-text">all minezz</p>

 5 minutes
text editor
basic knowledge [...]]]></description>
			<content:encoded><![CDATA[<p>Hey guys, so its been a while I&#8217;ve got a lot of stuff done and many core things working in Gccpy now more links on how to get up and running with it soon.</p>
<p>I am asking for help from you or from your friend.. anyone, all you need is:</p>
<div class="wp-caption alignright" style="width: 284px"><a href="http://icanhascheezburger.files.wordpress.com/2010/08/10f9d781-d2d8-4854-a036-83a0b14fdc88.jpg"><img title="all minezz" src="http://icanhascheezburger.files.wordpress.com/2010/08/10f9d781-d2d8-4854-a036-83a0b14fdc88.jpg" alt="all minezz" width="274" height="205" /></a><p class="wp-caption-text">all minezz</p></div>
<ul>
<li> 5 minutes</li>
<li>text editor</li>
<li>basic knowledge in python</li>
</ul>
<p>I am trying to build up a test suite for this compiler and i would love to have it all built from scratch for this project rather than taking something from <a href="http://www.python.org/">CPython</a> where i think licenses will clash and i want to avoid anything like that. So what does this all mean?</p>
<p>I need people to write up their favourite python snippets, but there are requirements: what you can do is use <span style="text-decoration: underline;">anything EXCEPT any imports</span>. Imports are something which will be handled soon, and isn&#8217;t that important  yet for the core language implementation.</p>
<p>So I have set-up this mailing list and i would love it if as many of you would <a href="http://crules.org/cgi-bin/mailman/listinfo/gccpy">join</a>: <a href="http://crules.org/cgi-bin/mailman/listinfo/gccpy">http://crules.org/cgi-bin/mailman/listinfo/gccpy</a></p>
<p>So join the mailing list or simply post a message if you prefer and we will try to remember to cc you with in. One thing i would ask is only submit a small test case if you are ok with this being pretty much un-licensed because GNU projects require copy approval for you to submit code, but we can negate this by going though me just submit this to me under a <a href="http://sam.zoy.org/wtfpl/">http://sam.zoy.org/wtfpl/</a> (Whatever you want to do license) . This just saves any pain of licensing, you will of course still be attributed! Leave your name and an email within the test-case file, since really that&#8217;s all we care about as hackers anyway we don&#8217;t care about licensing so long as we have some attribution. To give you a flavour of how simple these test cases can be lets look at one i made earlier:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1"># DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># &nbsp;Version 2, December 2004</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># Copyright (C) 2004 Sam Hocevar</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">#</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># Everyone is permitted to copy and distribute verbatim or modified</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># copies of this license document, and changing it is allowed as long</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># as the name is changed.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1"># DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># 0. You just DO WHAT THE FUCK YOU WANT TO.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># @Author redbrain &#8211; redbrain@gcc.gnu.org</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># @Date 13/8/10</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># @Expected Result: &lt;5&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># &nbsp; -Tested against Python Version &lt;2.6.5&gt;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> foo <span class="br0">&#40;</span> x , y <span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> x+y</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">print</span> foo<span class="br0">&#40;</span> <span class="nu0">2</span>,<span class="nu0">3</span> <span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>Things for testing the expression syntax handling or calling functions, parameter passing like keywords parameters and positional parameters, class&#8217;s anything! Even if it is as small as one expression and a print for the result it is more than enough for a test case! The reason I want as many people involved is so i can see what features/trends matter most important to python users and then I can focus on making them extra awesome. And if it only takes you 5 minutes to write a small piece of python code and send an email while you get your name within the Gcc sources the more the better:).</p>
<p>When you create a test case simply send an email to the mailing list with the subject &#8220;Test Case &lt;name&gt;&#8221;. You can submit as many as you like the more the better  and the funnier the better&#8230;. <strong>* looks at <a href="http://identi.ca/jezra">Jezra</a> <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong>! <a href="http://identi.ca/yamatt">@yamatt </a>i am reusing that python while loop you sent me ages ago to freak out my processor! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Thanks so much every one, watch this space in the next week for links on how to use and see your test case running in Gccpy, so you can compile your python code to an executable!</p>
<p>So remember the mailing list is over <a href="http://crules.org/cgi-bin/mailman/listinfo/gccpy">here</a>. <a href="http://crules.org/cgi-bin/mailman/listinfo/gccpy">http://crules.org/cgi-bin/mailman/listinfo/gccpy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/update/gccpy-call-for-help/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crules and Intermediate Representation</title>
		<link>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/</link>
		<comments>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:47:00 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Crules]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=491</guid>
		<description><![CDATA[<p>If you follow my blog you may have noticed i have been quiet and thats because i&#8217;ve been working on http://crules.org Its the new homepage for my project Crules, its got some good content on it but nothing really on the language yet. Though today i spend a very long time on the HACKING article [...]]]></description>
			<content:encoded><![CDATA[<p>If you follow my blog you may have noticed i have been quiet and thats because i&#8217;ve been working on <a href="http://crules.org">http://crules.org</a> Its the new homepage for my project Crules, its got some good content on it but nothing really on the language yet. Though today i spend a very long time on the<a href="http://crules.org/doku.php?id=hacking"> HACKING</a> article And i explain a lot on how Intermediate Representation&#8217;s work and <a href="http://en.wikipedia.org/wiki/Three_address_code">3-address code</a>.</p>
<p>So lets just take an extract since i am lazy: So in compilers or interpreters how do we represent:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span><span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> -- <span class="br0">&#40;</span> <span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> * <span class="br0">&#40;</span> x -- y <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> + <span class="br0">&#40;</span> <span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> * <span class="br0">&#40;</span> x -- y <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>Lets see it in a diagram first then in IR code:</p>
<div class="wp-caption alignleft" style="width: 281px"><a href="http://farm3.static.flickr.com/2718/4153843445_7f33be00d2.jpg"><img title="Expression DAG" src="http://farm3.static.flickr.com/2718/4153843445_7f33be00d2.jpg" alt="Expression" width="271" height="202" /></a><p class="wp-caption-text">Expression</p></div>
<p>So what is this? Well early on when i was getting into compiler construction when doing semantic analysis you will need to find a way of representing these semantics for your language, and you will find generally that there are 3 things you need to know: <strong>DESTINATION OPERAND A and OPERAND B</strong>. This is what&#8217;s called <a title="http://en.wikipedia.org/wiki/Three_address_code" rel="nofollow" href="http://en.wikipedia.org/wiki/Three_address_code">3-address code</a>. This is what sets compilers apart and can make or break them! Its what gives implementations flexibility and the ability to &#8216;<strong>control the flow</strong>&#8216; of execution! Any good compiler book will give you more detailed discussion on this topic its my main interest in compilers since this is what gives an implementation its logic. So lets give it a syntax we can write down to illustrate how mine works: it just so happens a <a title="http://en.wikipedia.org /wiki/Lisp_%28programming_language%29" rel="nofollow" href="http://en.wikipedia.org%20/wiki/Lisp_%28programming_language%29">LISP</a> &#8216;ish syntax can show this very well!</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span> <span class="br0">&#40;</span> IDENTIFIER <span class="br0">&#40;</span> TYPE <span class="br0">&#41;</span> <span class="br0">&#41;</span> =&gt; <span class="br0">&#40;</span> OPERAND A <span class="br0">&#41;</span> =&gt; <span class="br0">&#40;</span> OPERAND B <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="co1">;</span></div>
</li>
</ol>
</div>
<p>Since the parser is precedence aware it will construct the tree as shown in a symbol language which looks like this if it was output ( outputting the IR like this is a future TODO ); It may look a little like <a title="http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html" rel="nofollow" href="http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html">GIMPLE</a> but this IR I have as I will demonstrate more examples can encompass much much more..  ( this is a 3-address code by the way )</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span> <span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_MULTIPLY <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_MULTIPLY <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span><span class="co1">;</span></div>
</li>
</ol>
</div>
<div class="wp-caption alignright" style="width: 280px"><a href="http://icanhascheezburger.files.wordpress.com/2009/11/funny-pictures-cat-will-unroll-all-toilet-paper.jpg"><img title="Busy catz" src="http://icanhascheezburger.files.wordpress.com/2009/11/funny-pictures-cat-will-unroll-all-toilet-paper.jpg" alt="busy!" width="270" height="201" /></a><p class="wp-caption-text">busy!</p></div>
<p>Though one big note its is ok for me to leave the representation like this since in my interpreter i just evaluate this at run time but how does this affect things like code-generators like proper Compilers? Well its quite simple in a sane compiler like GCC ( although most compilers will follow this idiom i am sure) introduce another layer for IR called RTL ( <a href="http://en.wikipedia.org/wiki/Register_transfer_language">Register Transfer Language</a> ). The wikipedia article lacks and most compiler books overlook this section very much since, most books are written by the academics and generally stay away from the <a href="http://en.wikipedia.org/wiki/Compiler#Back_end">back-end of compilers</a> since that is the actual hard part since a code-gen is very specific to the instruction set your targeting and register allocation algorithms are very difficult and is a huge research project.  Its said in computer science the most difficult things to build software wise is a good JIT or any Code-Generator for that matter.  Anyways back to the problem lets take a smaller expression for sleep&#8217;s sake the expression:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">unsigned</span> <span class="kw4">int</span> retval = <span class="br0">&#40;</span> x * <span class="nu0">2</span> <span class="br0">&#41;</span> / <span class="br0">&#40;</span> <span class="nu0">7</span> + y <span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Will generate something like:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">t1 = x * <span class="nu0">2</span>;</div>
</li>
<li class="li1">
<div class="de1">t2 = <span class="nu0">7</span> + y;</div>
</li>
<li class="li1">
<div class="de1">t3 = t1 / t2;</div>
</li>
<li class="li2">
<div class="de2">retval = t3;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Anyways you&#8217;ll notice in my the IR keywords such as SYMBOL_ACCESS or SYMBOL_ITEM or OP_ADD etc, these are what&#8217;s called OP_Codes and are generally represented by some symbolic hex values since its cheap to check against for the implementation to figure out what to do with symbol &#8216;x&#8217;; So ok thats a quick and dirty intro to Intermediate Representation&#8217;s!</p>
<p>I think this lolcat will sum up your feelings at the end of reading this blog post:</p>
<p>And i started getting out my old grunge cd&#8217;s which include my <a href="http://www.last.fm/music/Silverchair">Silverchair</a> collection and this is on of my favourite bands of all time and this is a pretty good song!</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="425" height="373"><param name="movie" value="http://www.youtube.com/v/fTM5cDIESrY&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=1&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/fTM5cDIESrY&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=1&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="373" ></embed><param name="wmode" value="transparent" /></object></span></p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

