<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Vincent Geddes &#187; Smalltalk</title>
	<atom:link href="http://blogs.gnome.org/vgeddes/tag/smalltalk/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.gnome.org/vgeddes</link>
	<description>Blogging is Serious Business!</description>
	<lastBuildDate>Sat, 13 Sep 2008 18:37:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license>		<item>
		<title>3 + 4</title>
		<link>http://blogs.gnome.org/vgeddes/2008/04/14/3-4/</link>
		<comments>http://blogs.gnome.org/vgeddes/2008/04/14/3-4/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 23:00:10 +0000</pubDate>
		<dc:creator>vgeddes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/vgeddes/2008/04/14/3-4/</guid>
		<description><![CDATA[As some of you might have noticed, I have become somewhat of a Smalltalk weenie recently. This was a long time coming, but basically a reaction to many years of tedious hacking in C. Now don&#8217;t get me wrong, C is a great language, I still love it, but I have been using it in [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you might have noticed, I have become somewhat of a Smalltalk <a href="http://c2.com/cgi/wiki?SmugSmalltalkWeenie">weenie</a> recently. This was a long time coming, but basically a reaction to many years of tedious hacking in C. Now don&#8217;t get me wrong, C is a great language, I still love it, but I have been using it in entirely inappropriate places.</p>
<p>After reading up on Smalltalk a few months ago, I was entranced, and quickly decided that I just had to build my own Smalltalk system. Since I didn&#8217;t want it to be tied to any sort of platform (i.e. Java), I chose to write it in C (C99 to be specific).</p>
<p>I started out with the compiler. In order to learn more about compiler theory, I wrote a Smalltalk source-to-bytecode compiler from the ground up. The compiler translates source code into a compact bytecode representation consisting of about 30 different bytecodes. Currently, all Smalltalk-80 syntax is supported (except for message cascades). Of course, the compiler needs to manipulate on Smalltalk objects, so I also designed an object memory model (basically how objects are stored in physical memory). All objects have the same header, consisting of book-keeping, hash, and class fields. I intend to reduce the number of header fields to two though, since the hash field is often unnecessary. For example, instances of <em>String</em> will have a custom hash function, and will never need to access the hash field.</p>
<p>As with most Smalltalk VMs (and possibly Python/Ruby), integers are represented using tagged pointers. This kind of pointer has a 1-bit tag in the low-order position. If the bit is 1, then the rest of the pointer contains a 31-bit integer, otherwise, the pointer simply points to a heap-allocated object. This arrangement increases performance greatly, as having to heap-allocate integer objects would absolutely kill performance. We can get away with this, since on most architectures, pointers are aligned on 4 byte boundaries, thus leaving the low-order 2 bits of each pointer unused.</p>
<p>Just this evening, the VM passed a critical milestone, that of being able to evaluate the expression &#8220;3 + 4&#8243;. This sounds trivial, but a whole of lot nuts-and-bolts have to be in place to make this work. A few hours after the &#8220;3+4&#8243; test, the VM was capable of executing unary methods, as well as handling local variables and activation records.</p>
<p>Below is some sample Smalltalk code which shows what the VM can do currently, basically some arithmetic, local variable manipulation, and a method call to &#8220;increment&#8221;. Note that the method <em>doIt</em> belongs to the <em>UndefinedObject</em> class, and <em>increment</em> to <em>SmallInteger.</em></p>
<p><img src="http://blogs.gnome.org/vgeddes/files/2008/04/smalltalk.png" alt="smalltalk.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/vgeddes/2008/04/14/3-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
