<?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; Programming</title>
	<atom:link href="http://redbrain.co.uk/index.php/tag/programming/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>Parsing the Doom Wad File</title>
		<link>http://redbrain.co.uk/index.php/random/parsing-the-doom-wad-file/</link>
		<comments>http://redbrain.co.uk/index.php/random/parsing-the-doom-wad-file/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 01:12:31 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[Crules]]></category>
		<category><![CDATA[doom]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=528</guid>
		<description><![CDATA[<p>So it was a fine Christmas, I was at home with family armed only with 2 seasons of xFiles and my laptop added to the factI didn&#8217;t upload my ssh key to my laptop so hacking on Crules was out the window. So it got me thinking on the main goals for my Crules Scripting [...]]]></description>
			<content:encoded><![CDATA[<p>So it was a fine Christmas, I was at home with family armed only with 2 seasons of xFiles and my laptop added to the factI didn&#8217;t upload my ssh key to my laptop so hacking on Crules was out the window. So it got me thinking on the main goals for my Crules Scripting Language, one of which ( the main one ) is that it should be embeddable into existing C/C++ applications like Lua or Python or even C# (mono) if your using its recently added reflection api!</p>
<p>So why not make a game engine using my language with crules as a scripting language so I can see what the API _SHOULD_ look like for the client. So i choose doom since i am terrible with graphics, i can use the doom.wad and concentrate on programming; So in the past i have written two separate 2D game engines one was a Java 2D <a href="http://en.wikipedia.org/wiki/Monkey_Island_%28series%29">Monkey Island</a> clone i done for university and it was terrible since Java is a terrible platform in my opinion, then my 2nd was a port  of it over to <a href="http://www.libsdl.org/">C++/SDL</a> and the code was terrible <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  so don&#8217;t bother asking me about it.</p>
<p>Anyway&#8217;s so the long and short i am writing doom engine from scratch, my original idea was to work with an existing game engine like <a href="http://www.crystalspace3d.org/main/Main_Page">Crystal Space</a> or <a href="http://dengine.net/">Doomsday Engine</a> though, Crystal Space i was put off since it already uses Python and i don&#8217;t really feel like trawling though lots of code and forking it essentially would be really more work than its worth. Doomsday Engine is the cream of the crop of Doom Ports at the moment, all others are practically the same in essence using the same ancient code and hacks from throughout the 90&#8242;s. And really the technology has changed somewhat since then. Though Doomsday Engine is pretty amazing and works well, it seems to need a massive cleanup and i don&#8217;t mean to be nasty on the developers or anything they have done a fantastic job!  And they have really made the code much cleaner than any other port about! Plus the lead developer has been really nice to me <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Anyway&#8217;s Games have always been a great passion to me and really doom can&#8217;t be that hard to re-implement from scratch and really it isn&#8217;t i already have a basic game engine working using OpenGL and <a href="http://www.libsdl.org/">SDL{ _ttf, _mixer }</a>. With audio, and fps counter and input bla bla. But i am just concentrating on differentiating the wad sprite formats etc while revising for exams and working on crules and many other bits and pieces. So in the end  i&#8217;ll just stick in an extract of the log of my game engine when it starts parsing the doom.wad and explain a little on how to parse the wad!</p>
<blockquote><p>debug: main.c:28 -&gt; Trying to start crldoom wad: data/doom.wad!<br />
debug: doom.c:147 -&gt; parsing wad file &lt;data/doom.wad&gt;!<br />
debug: doom.c:80 -&gt; is a wad file :: &lt;IWAD&gt;!<br />
log: doom.c:155 -&gt; wad file data/doom.wad has length 12408292!<br />
debug: doom.c:27 -&gt; debug seeking&#8230;<br />
debug: doom.c:30 -&gt; reading&#8230;.<br />
debug: doom.c:34 -&gt; parsing&#8230;<br />
log: doom.c:49 -&gt; header:: ident -&gt; 1145132873, n_lumps -&gt; 2306, infotableofs -&gt; 12371396!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 12, size -&gt; 10752, name -&gt; 1497451600, ident -&gt; PLAYPAL!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 10764, size -&gt; 8704, name -&gt; 1330401091, ident -&gt; COLORMAP!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 19468, size -&gt; 4000, name -&gt; 1329876549, ident -&gt; ENDOOM!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 23468, size -&gt; 6854, name -&gt; 1330464068, ident -&gt; DEMO1!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 30324, size -&gt; 9402, name -&gt; 1330464068, ident -&gt; DEMO2!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 39728, size -&gt; 15466, name -&gt; 1330464068, ident -&gt; DEMO3!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 55196, size -&gt; 3286, name -&gt; 1330464068, ident -&gt; DEMO4!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 58484, size -&gt; 0, name -&gt; 827142469, ident -&gt; E1M1!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 58484, size -&gt; 1430, name -&gt; 1313425492, ident -&gt; THINGS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 59916, size -&gt; 6804, name -&gt; 1162758476, ident -&gt; LINEDEFS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 66720, size -&gt; 19980, name -&gt; 1162103123, ident -&gt; SIDEDEFS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 86700, size -&gt; 1880, name -&gt; 1414677846, ident -&gt; VERTEXES!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 88580, size -&gt; 8964, name -&gt; 1397179731, ident -&gt; SEGS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 97544, size -&gt; 956, name -&gt; 1128616787, ident -&gt; SSECTORS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 98500, size -&gt; 6664, name -&gt; 1162104654, ident -&gt; NODES!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 105164, size -&gt; 2288, name -&gt; 1413694803, ident -&gt; SECTORS!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 107452, size -&gt; 968, name -&gt; 1162495314, ident -&gt; REJECT!<br />
log: doom.c:62 -&gt; directory:: filepos -&gt; 108420, size -&gt; 6948, name -&gt; 1129270338, ident -&gt; BLOCKMAP!</p></blockquote>
<p>So this is just some of the output of the code i had written it parses out whats called the &#8216;directories&#8217; in the file and then i also have functions to parse out whats called the &#8216;lumps&#8217; from these directories the lumps are the actual data. I&#8217;ll explain more detail when i talk about how to parse this. And how to convert the music lumps to proper midi so you can play it in SDL_mixer or even in Totem if in in gnome.</p>
<p>So what do we need, if you have yourself a Doom.wad file lying about i am sure if you go through your old boxes you&#8217;ll find yourself a copy of doom, or if you cant find it you can find it on torrent sites but you didn&#8217;t read that here <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Thing is I have bought the game like 3/4 times I am sure hehe. Lets get started.</p>
<p>In the Doom wad there is whats called the &#8216;HEADER&#8217; which is of length 12 bytes which contains 3 * 4-byte integers which contain the data we care about, so lets do that lets make some code (i just wrote this code in like 10 min to illustrate the idea its ok does the job!):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;stdio.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;stdlib.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;string.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co2">#define WAD_HEADER_LENGTH &nbsp; &nbsp; 12</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define WAD_DIRECTORY_LENGTH &nbsp;16</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">unsigned</span> <span class="kw4">long</span> parse_int<span class="br0">&#40;</span> <span class="kw4">unsigned</span> <span class="kw4">char</span> *p <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="kw4">unsigned</span> <span class="kw4">long</span><span class="br0">&#41;</span> &nbsp; p<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| <span class="br0">&#40;</span><span class="kw4">unsigned</span> <span class="kw4">long</span><span class="br0">&#41;</span> p<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> &lt;&lt; <span class="nu0">8</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| <span class="br0">&#40;</span><span class="kw4">unsigned</span> <span class="kw4">long</span><span class="br0">&#41;</span> p<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> &lt;&lt; <span class="nu0">16</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| <span class="br0">&#40;</span><span class="kw4">unsigned</span> <span class="kw4">long</span><span class="br0">&#41;</span> p<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> &lt;&lt; <span class="nu0">24</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#41;</span> ;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span> <span class="kw4">int</span> argc, <span class="kw4">char</span> *argv<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">const</span> <span class="kw4">char</span>* wad_file= <span class="st0">&quot;/home/redbrain/workspace/doom-dev/crldoom/data/doom.wad&quot;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; FILE* wad_fd;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> !<span class="br0">&#40;</span>wad_fd= fopen<span class="br0">&#40;</span>wad_file, <span class="st0">&quot;rb&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; fprintf<span class="br0">&#40;</span>stderr, <span class="st0">&quot;error opening &lt;%s&gt;!<span class="es0">\n</span>&quot;</span>, wad_file<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EXIT_FAILURE;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">unsigned</span> <span class="kw4">char</span> header_buffer<span class="br0">&#91;</span> WAD_HEADER_LENGTH <span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fread<span class="br0">&#40;</span> header_buffer, WAD_HEADER_LENGTH, <span class="nu0">1</span>, wad_fd <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw4">char</span>* wad_ident= <span class="br0">&#40;</span><span class="kw4">char</span>*<span class="br0">&#41;</span> header_buffer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; wad_ident<span class="br0">&#91;</span> <span class="nu0">4</span> <span class="br0">&#93;</span>= <span class="st0">&#8216;<span class="es0">\0</span>&#8216;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> strncmp<span class="br0">&#40;</span> wad_ident, <span class="st0">&quot;IWAD&quot;</span>, <span class="nu0">4</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; fprintf<span class="br0">&#40;</span>stderr, <span class="st0">&quot;invalid wad header type &lt;%s&gt;!<span class="es0">\n</span>&quot;</span>, wad_ident <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EXIT_FAILURE;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;doom wad is a &lt;%s&gt;!<span class="es0">\n</span>&quot;</span>, wad_ident <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> wad_length= <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fseek<span class="br0">&#40;</span> wad_fd, <span class="nu0">0</span>, SEEK_END <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; wad_length= ftell<span class="br0">&#40;</span> wad_fd <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> directory_offset= parse_int<span class="br0">&#40;</span> header_buffer<span class="nu0">+8</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> number_lumps= parse_int<span class="br0">&#40;</span> header_buffer<span class="nu0">+4</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;wad directory offset &lt;%lu&gt; with &lt;%lu&gt; lumps!<span class="es0">\n</span>&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;directory_offset, number_lumps <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> t_ofs= directory_offset; <span class="kw4">unsigned</span> <span class="kw4">long</span> lump_count= <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">while</span><span class="br0">&#40;</span> t_ofs &lt;= <span class="br0">&#40;</span> wad_length -- WAD_DIRECTORY_LENGTH <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; fseek<span class="br0">&#40;</span> wad_fd, t_ofs, SEEK_SET <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw4">unsigned</span> <span class="kw4">char</span> *directory_buffer= <span class="br0">&#40;</span><span class="kw4">unsigned</span> <span class="kw4">char</span>*<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; malloc<span class="br0">&#40;</span> <span class="kw4">sizeof</span><span class="br0">&#40;</span><span class="kw4">char</span><span class="br0">&#41;</span> * WAD_DIRECTORY_LENGTH <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; fread<span class="br0">&#40;</span> directory_buffer, WAD_DIRECTORY_LENGTH, <span class="nu0">1</span>, wad_fd <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> filepos= parse_int<span class="br0">&#40;</span> directory_buffer <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw4">unsigned</span> <span class="kw4">long</span> size= parse_int<span class="br0">&#40;</span> directory_buffer<span class="nu0">+4</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw4">char</span> *directory_ident= strdup<span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="kw4">char</span>*<span class="br0">&#41;</span> directory_buffer<span class="nu0">+8</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; directory_ident<span class="br0">&#91;</span> strlen<span class="br0">&#40;</span>directory_ident<span class="br0">&#41;</span> <span class="br0">&#93;</span>= <span class="st0">&#8216;<span class="es0">\0</span>&#8216;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;directory name &lt;%s&gt; at offset &lt;%lu&gt; with size &lt;%lu&gt;!<span class="es0">\n</span>&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;directory_ident, filepos, size <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; free<span class="br0">&#40;</span> directory_ident <span class="br0">&#41;</span>; free<span class="br0">&#40;</span> directory_buffer <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; t_ofs += WAD_DIRECTORY_LENGTH; lump_count++;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&quot;directorys parsed &lt;%lu&gt; total lumps &lt;%lu&gt;!<span class="es0">\n</span>&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;lump_count, number_lumps <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fclose<span class="br0">&#40;</span> wad_fd <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>So lets compile and test this code &lt;remember to change the path to your doom wad&gt;:</p>
<blockquote><p>gcc doom_wad_test.c</p>
<p>./a.out</p></blockquote>
<p>So right what does any of this code mean i just chucked it up there, i wrote it up very quickly from scratch. So as i stated earlier there is a wad header which is a 12 bytes in length which i refer to as &#8216;WAD_HEADER_LENGTH&#8217; which contains 3 * 4-byte integers. So from the code we have fopen&#8217;d the wad_file and i use fread to read in the 12 bytes in a 12 byte &#8216;unsigned char[]&#8216; buffer. So to read out the integers in a neutral endian way i found a nice parse_int function in some of the wad documentation i found and in old doom source code which was GPL so it was like&#8230;. yoink&#8230; but its pretty easy to understand if you know your representations well enough but i wont go into detail.</p>
<p>The first integer is the IWAD or PWAD string, IWAD is what you will find mostly its the deployment version of the wad, the PWAD is a patch wad and very few of them are still around and i think it has similar structure. Anyways, you parse out the first integer like this</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">char</span>* wad_ident= <span class="br0">&#40;</span><span class="kw4">char</span>*<span class="br0">&#41;</span> header_buffer;</div>
</li>
<li class="li1">
<div class="de1">wad_ident<span class="br0">&#91;</span> <span class="nu0">4</span> <span class="br0">&#93;</span>= <span class="st0">&#8216;<span class="es0">\0</span>&#8216;</span>;</div>
</li>
</ol>
</div>
<p>Remember to add null string &#8216;\0&#8242;, so we don&#8217;t get buffer overflow! This string is always a length of 4 so no need to mess about! And then the next integer is the number of lumps in the wad the lumps are the actual binary data like music and graphics. Third int is the &#8216;directory offset&#8217; which contains pointers to where the lumps are their idents and the size of the lumps which have lengths of 16 &#8216;WAD_DIRECTORY_LENGTH&#8217; until the end of the wad file! so note i find the length of the file and do:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">while</span><span class="br0">&#40;</span> t_ofs &lt;= <span class="br0">&#40;</span> wad_length -- WAD_DIRECTORY_LENGTH <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>So how do we parse out these directories?  We move to the directory offset and then read the 16 bytes into a buffer, which is 4 integers this time. But still contains only 3 things means the ident strings can be longer or can be with some padding between each directory lump.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">unsigned</span> <span class="kw4">long</span> filepos= parse_int<span class="br0">&#40;</span> directory_buffer <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">unsigned</span> <span class="kw4">long</span> size= parse_int<span class="br0">&#40;</span> directory_buffer<span class="nu0">+4</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">char</span> *directory_ident= strdup<span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="kw4">char</span>*<span class="br0">&#41;</span> directory_buffer<span class="nu0">+8</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">directory_ident<span class="br0">&#91;</span> strlen<span class="br0">&#40;</span>directory_ident<span class="br0">&#41;</span> <span class="br0">&#93;</span>= <span class="st0">&#8216;<span class="es0">\0</span>&#8216;</span>;</div>
</li>
</ol>
</div>
<p>Now we know the file offset of the lump the size of the lump and the ident of the lump and we make sure to add the null terminator again to avoid buffer overflow. And then we can parse out the lumps simply just fseek and fread <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Done its so simple and seems like there would be more to it, yet when you think of it is very much common sense there really isn&#8217;t that many ways to pack data into a file like this! If your interested i&#8217;ll be talking about it soon&#8230; on how to convert the D_E1M* lumps which are music lumps to compatible midi tracks. And finally on how <a href="http://en.wikipedia.org/wiki/Binary_space_partitioning">BSP</a> works for the levels and maybe how to draw them in C/SDL/OpenGL&#8230; if you ask i prefer C over C++, yeah when it comes to building this game engine there have been times i though woo having an object would be really nice here but then i realise well no because that&#8217;s what the scripting engine is going to do&#8230; <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Mainly due to the fact i dont like C++ syntax it feels messy to me and C is just nice and simple <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Finally I just want to wrap up with saying <a href="http://en.wikipedia.org/wiki/John_D._Carmack">John Carmack</a> has to be one of my biggest Hero&#8217;s in Computer Science along with <a href="http://tirania.org/blog/">Migel De Icaza</a>, <a href="http://en.wikipedia.org/wiki/Linus_Torvalds">Linus Torvalds</a>, Various GCC hackers&#8230; like Ian Lance Taylor But John Carmack in particular since he made Doom! But also he attended the <a title="University of Missouri–Kansas City" href="http://en.wikipedia.org/wiki/University_of_Missouri%E2%80%93Kansas_City">University of Missouri–Kansas City</a> for two semesters before withdrawing to work as a freelance programmer. Which i think that is brilliant! Since University does not teach students to be serious programmers or technology well very few do anyway and i think its great he had the balls to do that and so did Migel De Icaza and they have both done some of the most amazing things in computer science!</p>
<p>Anyways if your interested in Crules or CrlDoom see: <a href="http://crules.org">http://crules.org</a> code for crldoom is over @ <a href="http://code.redbrain.co.uk/cgit.cgi/crldoom">http://code.redbrain.co.uk/cgit.cgi/crldoom</a></p>
<p>This is a project i love <a href="http://www.moddb.com/mods/classic-doom-3">Classic Doom 3</a> it was Doom re-implemented ontop of the Doom3 Engine what more do you want!!!</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="425" height="373"><param name="movie" value="http://www.youtube.com/v/woBAUk5hMD8&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/woBAUk5hMD8&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/random/parsing-the-doom-wad-file/feed/</wfw:commentRss>
		<slash:comments>3</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>
		<item>
		<title>Intel C++ Complilers Linux</title>
		<link>http://redbrain.co.uk/index.php/quick-tips/intel-c-complilers-linux/</link>
		<comments>http://redbrain.co.uk/index.php/quick-tips/intel-c-complilers-linux/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 16:15:27 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=485</guid>
		<description><![CDATA[<p>So if you know me you&#8217;ll know i think compilers are cool&#8230; yeah i know i am weird lol. So any-way&#8217;s this is something i never really got around to until last night. Which was setting up the Intel C/C++ compilers in my Computer which is running Debian. If  you ever look at using compilers [...]]]></description>
			<content:encoded><![CDATA[<p>So if you know me you&#8217;ll know i think compilers are cool&#8230; yeah i know i am weird lol. So any-way&#8217;s this is something i never really got around to until last night. Which was setting up the Intel C/C++ compilers in my Computer which is running Debian. If  you ever look at using compilers other than GCC such as like Sun Studio and Intel C++ you may find its very messy feeling. What i mean is they have like a nasty install.sh, and to be quite honest they fail lol. Since they generally only cared about creating RPM&#8217;s and hoping your running Red Hat since most customers who would buy these compilers would be running a Red Hat server farm. So if your project is using Autoconf and Automake you dont have to worry about a thing, once the compilers are installed it will be one quick minor change to your configure.ac. And your all set!</p>
<p>First off go and download the 750mb tarball of the Intel C compilers over at: <a href="http://software.intel.com/en-us/intel-compilers/">http://software.intel.com/en-us/intel-compilers/</a></p>
<blockquote><p>% tar zxvf l_cproc_p_11.1.059_ia32.tgz</p>
<p>% cd l_cproc_p_11.1.059_ia32</p>
<p>% ./install.sh</p>
<p># follow all the instructions it complained i didn&#8217;t have java installed but you don&#8217;t need it. Once your finished it should all be installed to /opt/intel/Compiler</p>
<p>% PATH=$PATH:/opt/intel/Compiler/11.0/069/bin/ia32</p>
<p>% LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/Compiler/11.1/059/lib/ia32/:/usr/lib/</p></blockquote>
<p>You should be able to run &#8216;icc&#8217; but you will probably get the error: &#8221; /opt/intel/Compiler/11.1/059/bin/ia32/mcpcom: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory</p>
<p>compilation aborted for test.c (code 127)&#8221;</p>
<p>So you need to install an older libstdc++ on debian it is:</p>
<blockquote><p>% aptitude install libstdc++5</p></blockquote>
<p>That should be it lets give it a test:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; ;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<blockquote><p>% icc test.c</p></blockquote>
<p>Should work now! If your project uses a Configure.ac lets make a quick change:</p>
<blockquote><p>Change your AC_PROG_CC to:<br />
AC_PROG_CC([icc gcc cc cl])</p></blockquote>
<p>This is the order in which the configure should search for each compiler. Since you need GCC installed to use Intel C++ you need to put ICC at the top of the list! Hope this helps someone!</p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/quick-tips/intel-c-complilers-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python, GCC and Crules :-)</title>
		<link>http://redbrain.co.uk/index.php/about-me/python-gcc-and-crules/</link>
		<comments>http://redbrain.co.uk/index.php/about-me/python-gcc-and-crules/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 17:28:33 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[About Me]]></category>
		<category><![CDATA[Crules]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=446</guid>
		<description><![CDATA[<p style="text-align: left;">Hey guys, I&#8217;ve been pretty quiet this summer i guess so as it may seem, but I&#8217;ve been working frigging hard. I&#8217;m starting to get things coming together! So what am i doing? I&#8217;ve been doing a little freelance server work, I&#8217;ve been working on CRULES which is coming along nicely a lot [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Hey guys, I&#8217;ve been pretty quiet this summer i guess so as it may seem, but I&#8217;ve been working frigging hard. I&#8217;m starting to get things coming together! So what am i doing? I&#8217;ve been doing a little freelance server work, I&#8217;ve been working on CRULES which is coming along nicely a lot of the back-end is working pretty nice now and i just need to keep working at it, but i am also trying to start a new front-end into GCC. So what does that mean, so in <a href="http://gcc.gnu.org/">GCC </a>the gnu compiler collection its a collection of compilers i am writing a small paper on the architecture of GCC and how to build a new front-end but more on that later, but what i mean is each language in GCC be it ADA, Fortran, C, C++, Java they are all front-ends to GCC, that is the part which does the semantic analysis and parsing of the pain text source code into the GIMPLE tree for middle end optimization from there code-generation.</p>
<p style="text-align: left;">So i am making a Python compiler(front-end), well starting too its going quite slow because i am in the middle of finishing up some <a href="http://www.gnu.org/software/automake/">automake</a> work, and crules definitions. And GCC is quite complex in its development but its quite amazing and the most amazing project i have ever seen. I mean its development consists of many little files in different languages that aren&#8217;t even front-ends in GCC. For example a .md machine description is written in LISP that describes the architecture of an OS or Processor this makes it easier to port GCC to new systems, <a href="http://gcc.gnu.org/wiki/GIMPLE">GIMPLE the IR</a> was a language called SIMPLE but its GNU/Simple = GIMPLE, this gives the IR a better formalization, lang.opt files for command line options so you dont have to do any command line parsing in your front-end thats up to the gcc driver program( I&#8217;ll explain this some other time), Make-lang.in GNU/Make on how your code should be compiled, config-lang.in its in bash but does all the configuration on how the front-end is build with respect to Stage-x as in the boot-strap if it requires libraries to be built like JAVA needs libjava or if its an optional language.</p>
<div class="wp-caption alignright" style="width: 310px"><a href="http://ihasahotdog.files.wordpress.com/2009/08/funny-dog-pictures-uses-force.jpg?w=500&amp;h=332"><img title="o_O" src="http://ihasahotdog.files.wordpress.com/2009/08/funny-dog-pictures-uses-force.jpg?w=500&amp;h=332" alt="The force!" width="300" height="199" /></a><p class="wp-caption-text">The force!</p></div>
<p style="text-align: left;">Thats a lot of stuff people probably don&#8217;t care about! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But its interesting what other project uses a cool a setup as that! I mean <a href="http://en.wikipedia.org/wiki/Lisp_(programming_language)">LISP</a>, there isn&#8217;t even a lisp compiler in there but there its a bit of a one in the backend. There are some exciting things coming from GCC at the moment, <a href="http://gcc.gnu.org/wiki/LinkTimeOptimization">LTO </a>or <a href="http://gcc.gnu.org/wiki/Graphite">graphite</a> springs to mind, they aren&#8217;t ready yet, but LTO mean Link time optimization, so when you compile your program with gcc in whatever language, you compile each file to object code individually but you use gcc to link each object code and library together instead of using LD explicitly because it works nicer, so on Link time optimization when your linking all the code together another pass of the optimizations goes over a huge IR of all the object code to re-structure of remove dead code etc all the usual optimizations. And with OPEN/MP becoming pretty popular graphite you can pass flags like -fparallelize-all to extract loops even dependence loops to push in open/mp pragmas to make fully parallelized code without having to lift a finger. I&#8217;m working quite slowly to write 3 papers in total, a long thesis on Crules you can check it in my git-repos over at <a href="http://code.redbrain.co.uk">http://code.redbrain.co.uk</a> and i am working on a thesis on the python-front-end as-well as a little paper on the gcc architecture. There is a tagged branch for a front-end-skeleton here on my git-repos: <a href="http://code.redbrain.co.uk/cgit.cgi/gcc-python/">http://code.redbrain.co.uk/cgit.cgi/gcc-python/</a></p>
<p style="text-align: left;">So there is a lot of work there. And i chose to do a python front-end due to the fact everyone can say python is an awesome language no-one can deny that, it has been very well designed; language design is something a lot of people can over-look or take too far and python was a good mix in my opinion. What i mean is if you spend too long on language design your language will become very messy and hard for users to become comfortable with, something that has happened Haskell in my opinion although the way non-determinism is very clever in how Haskell has implemented it. On the other hand if you don&#8217;t spend enough time designing your language its going to be very messy and not much re-use of syntax. One thing to remember in design there is always a reason for the smallest of things be it the reason of using an identifier to using a &#8216;.&#8217; for access or &#8216;- &gt;;&#8217; for pointer access, keywords have to make sense etc.</p>
<p style="text-align: left;">I was invited to join the graphite project i posted a quick patch to fix a part of their build-system, but i am not sure what i can really contribute because i would need to work full-time on it because its been going for some time now. Some of the work is pretty exciting. I am going to see later if i can maby merge the actual python parser from python into my GCC front-end because this would make a very nice setup to mirror the language features of python to an extend but there will be differences an GNU&#8217;isms because the mere fact that this will be compiled handling things like IO will rely on linking against libraries and the python pre-processor functions like import and from etc will be fiddly to work but i should be  able to take alot of work from the gnuJava front-end as there are similarities in how certain things work.</p>
<p style="text-align: left;">
<div class="wp-caption alignleft" style="width: 310px"><a href="http://icanhascheezburger.files.wordpress.com/2009/08/funny-pictures-kitten-wonders-where-gravity-went.jpg"><img title="Distracting" src="http://icanhascheezburger.files.wordpress.com/2009/08/funny-pictures-kitten-wonders-where-gravity-went.jpg" alt="Something to Distract you! :)" width="300" height="200" /></a><p class="wp-caption-text">Something to Distract you! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></div>
<p style="text-align: left;">
<p style="text-align: left;">Anyways from my goggling i haven&#8217;t been able to find an implementation of python that is compiled properly i mean natively compiled, some people mix the up the fact that python does create byte-code like java think its compiled code and it really isn&#8217;t. I remember at university a lecturer told us that compiling JAVA code you were creating Machine code to run natively on a computer. And he got the pipeline so wrong in creating a binary. They always made it seem that a compiler was a piece of magic that made a binary and java is NOT a compiled language unless you use GCJ. I personally find <a href="http://en.wikipedia.org/wiki/Linker">linkers</a> are a piece of magic these days a lot of the know-how in how linkers are build is quite complicated in some ways. Although what you are essentially doing is taking the object code output from an assembler and creating an <a href="http://en.wikipedia.org/wiki/Executable_and_Linkable_Format">ELF</a> format file with the object code in the correct segments and data in the top segment etc. And on windows its a <a href="http://en.wikipedia.org/wiki/COFF">COFF</a> format i think, but even at that what are you doing and what does object code look-like is it literally the binary format of instructions in order from the corresponding assembly code?!</p>
<p style="text-align: left;">I would love to understand more on how that all works, but i mean an object code file is a not a plain text binary file so yeah i even posted to comp.compilers a thread on manging the jit you can look for it in the archives but its something that is still quite hidden, and only a few people who implemented it understand, i see how it all partly works because of the libjit project. like the defintions of an a.out and ELF were quite understandable i guess. But with a<a href="http://en.wikipedia.org/wiki/Just-in-time_compilation"> jit</a> if your able to for example jit a function like:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">int</span> multiply<span class="br0">&#40;</span> <span class="kw4">int</span> x, <span class="kw4">int</span> y <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> x*y;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p style="text-align: left;">If you are able to make target assembly code for this, and you assemble it and link it properly you have a binary how do you actually execute it in a useful way for an interpreter?! I mean do you keep adding new functions into this image and use dlopen functions and treat the symbols like a dynamic library and execute them that way through <a href="http://en.wikipedia.org/wiki/Dynamic_loading">dlopen</a>? I mean this is what the <a href="http://llvm.org/">LLVM</a> project hides from the users very well but anyways enough of that. <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: left;">Anyways thats what I&#8217;ve been doing for a summer what have you been up to?! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  You can follow some of my stuff on several mailing lists like bison,<a href="http://www.gnu.org/software/autoconf/">autoconf</a>, automake, gcc-help, gcc,comp.compilers. I helped a guy a while back on his bison parser, bison is a very useful tool, but for doing more free-form grammars is a pain I&#8217;ve found and i like to think i know <a href="http://en.wikipedia.org/wiki/Yacc">YACC</a> pretty well now from using it for about a year.</p>
<p style="text-align: left;">By the way I&#8217;ll be posting a <a href="http://wiki.redbrain.co.uk">wiki</a> links on crules soon for example on how the language works etc and why but i would really like it if people read my thesis when its finished because i designed this language from a very specific set of reasons in the beginning for a specific application, but its become a fully multi-paradigm language in its design now, and this is what my thesis on it describes.</p>
<p style="text-align: left;">Anyways i&#8217;m going back to get some work done and i have <a href="http://www.belfastlinux.org/wiki/Main_Page">BLUG</a> tomorrow! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Oh hey i found a new favourite band bought their album as soon as i heard this, its a polish metal band they are probably the a new <a href="http://www.nightwish.com/">Nightwish</a> i guess! They are very good!</p>
<p style="text-align: left;"><!-- Smart Youtube --><span class="youtube"><object width="425" height="373"><param name="movie" value="http://www.youtube.com/v/LapknbGS7Os&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/LapknbGS7Os&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>
<p style="text-align: left;">I think thats enough for now i have some photos to upload but i&#8217;ll do that next time <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/about-me/python-gcc-and-crules/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

