<?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>Baroquebobcat</title>
	<atom:link href="http://blog.baroquebobcat.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.baroquebobcat.com</link>
	<description>Ruby, Computer Science, Japan and Stuff</description>
	<lastBuildDate>Thu, 19 Jan 2012 02:05:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mirah Office Hours: Digging In</title>
		<link>http://blog.baroquebobcat.com/2012/01/18/mirah-office-hours-digging-in/</link>
		<comments>http://blog.baroquebobcat.com/2012/01/18/mirah-office-hours-digging-in/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 02:05:47 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=738</guid>
		<description><![CDATA[This week I wanted to deal with one embarrassing bug, and some that looked fun. After looking through everything last week, I felt like I got a better sense about the current issues. So, I picked a few issues to work on that I thought I could dig into and get something working in an [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/baroquebobcat/6723138865/" title="Mirah -v Frankly embarrassing by baroquebobcat, on Flickr"><img src="http://farm8.staticflickr.com/7143/6723138865_a4c3f3a128_o.png" width="421" height="96" alt="Mirah -v Frankly embarrassing"></a></p>
<p>This week I wanted to deal with one embarrassing bug, and some that looked fun. After looking through everything last week, I felt like I got a better sense about the current issues. So, I picked a few issues to work on that I thought I could dig into and get something working in an afternoon. I think I was a little ambitious.</p>
<p>First I wanted to fix <a href="https://github.com/mirah/mirah/issues/161">#161</a> <tt>mirah -v</tt> causing an error because, frankly it&#8217;s embarrassing. I also thought it&#8217;d be pretty easy. <a href="https://github.com/mirah/mirah/commit/1a3da9f25fd9abea76c2aaf880e586d8834d5b09" title="fix 161">It was</a>, but the fix wasn&#8217;t as clean as I&#8217;d like.</p>
<p>Next time I&#8217;m in the option handling code, I&#8217;m going to do some house cleaning&#8211;it&#8217;s getting a bit ugly. For instance, parser should not take a list of commandline args and have to worry about &#8216;-e&#8217; etc. How to reorganize it I haven&#8217;t decided. Maybe using <a href="http://ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html">optparse</a>, though that has its own idiosyncrasies.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/13">#13</a> booleans don&#8217;t have an == method.</strong></p>
<p>I fixed this by <a href="https://github.com/mirah/mirah/commit/d680a3355cd98c7bb1a43cfda9cae21bad799960">adding an intrinsic</a> to the jvm backend code. It&#8217;s not especially pretty. The intrinsics code is tied up in a few files and some of them feel like balls of mud. It&#8217;s not readily apparent where to find things and what they do.</p>
<p>I&#8217;ve been thinking about how to make intrinsics nicer and more consistent. It might be nice to have some common types with a common set of expected method definitions that the various (hypothetical) backends should implement. That way you&#8217;d have some consistency across different Mirah backends.</p>
<p>I&#8217;d also like to reorganize the intrinsics and make their internal APIs easier to grok. Things I&#8217;d like to do with them, like allowing easy method aliasing are hard right now, because the API has a lot of sharp edge cases.</p>
<p><strong>Test cleanup</strong></p>
<p>After fixing #13, I renamed all the test files. I was getting frustrated w/ having them all be prefixed with <tt>test_</tt>. That made tabbing into the right test file take a couple more keystrokes. It added just enough friction that I wanted to change it. So I did.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/30">#30</a> Const Assign</strong></p>
<p>This one is definitely not a single Sunday afternoon project. And, honestly I didn&#8217;t expect it to be. I spent about an hour trying to figure out what would need to change to support creating constants. It looks kind of annoying.</p>
<p>First, you need to transform the mmeta AST nodes into a Mirah AST node for the Const Assign, which could be as simple as creating a static FieldAssign. Then you need to change the code generation to deal with that. Unfortunately, FieldAssign&#8217;s don&#8217;t currently know about access levels (public, private, protected) which means you&#8217;d either have to add access levels to field assign, or create a new AST class that would have to be dealt with in the code generation phase.</p>
<p>Thinking about it a little, it might be nicer to do the second thing. Then, different (hypothetical) backends could handle access levels for constants their own way. That might be handy, particularly if constants are special in different ways in different languages.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/41">#41</a> i++</strong></p>
<p>The other thing I looked at briefly was adding ++ to the grammar. This turned out to be rather hard looking because the parser&#8217;s master branch is tied to mirah&#8217;s newast branch, which has a lot of new things in it and doesn&#8217;t work with the current release yet. </p>
<p>I&#8217;m debating creating a new branch on the parser at a point before it started using the new AST. On the other hand, it might make sense to spend more time trying to update the newast branch so that it is up to date with master. Then I could get it closer to merging back in.</p>
<p>That&#8217;s all for this week.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2012/01/18/mirah-office-hours-digging-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mirah Office Hours: Back After the Holidays</title>
		<link>http://blog.baroquebobcat.com/2012/01/10/mirah-office-hours-back-after-the-holidays/</link>
		<comments>http://blog.baroquebobcat.com/2012/01/10/mirah-office-hours-back-after-the-holidays/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 16:29:25 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=718</guid>
		<description><![CDATA[This week I decided to go and read all of Mirah&#8217;s open issues starting with the earliest submitted ones. I&#8217;d been spending so much time just looking at the top of the list. I didn&#8217;t have a good sense for which ones were duplicates, which were pretty undefined and which were easy. Thankfully, Mirah doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>This week I decided to go and read all of Mirah&#8217;s open issues starting with the earliest submitted ones. I&#8217;d been spending so much time just looking at the top of the list. I didn&#8217;t have a good sense for which ones were duplicates, which were pretty undefined and which were easy. Thankfully, Mirah doesn&#8217;t have that many issues, so attempting to read through them all wasn&#8217;t a ridiculous undertaking. There were only 64, and I had filed about a half dozen of them myself.</p>
<p>In the end, I was able to close 7, and get a good sense of where a number of the other ones stood in terms of how much work it&#8217;ll take to fix them. Of course there were a few that made me confused, where I don&#8217;t have any idea where to start digging to fix them. </p>
<p>After going through the stack of issues, I have a better sense of what I want to try to tackle next week. Here&#8217;s a few that I think look fun.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/41">#41</a> &#8211; adding ++ to the language.</strong></p>
<p>++ isn&#8217;t in the grammar yet, so this would require learning more about the parser. And, I&#8217;d get to play around with the grammar, which is always fun, and something I haven&#8217;t done much of since graduating.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/127">#127</a> &#038; <a href="https://github.com/mirah/mirah/issues/42">#42</a> &#8211; working out the semantics of equality.</strong></p>
<p>Currently Mirah uses Java&#8217;s ==, which checks identity not equality. We&#8217;d like to use Java&#8217;s equals as our ==, but I&#8217;ve had a little trouble getting it working properly. Still, this is a fun one to hack on.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/45">#45</a> &#8211; an issue with how field assignments check typing<br />
</strong><br />
Namely, they don&#8217;t really. It isn&#8217;t completely straight forward but I think I&#8217;ve nailed down where to make the changes.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/57">#57</a> &#8211; who is self in a block</strong></p>
<p>This looks fun. I&#8217;m not quite sure how to make it work. The problem is that you want blocks to work like they do in Ruby, where self is the owner of the outer scope. Currently, Mirah&#8217;s bindings don&#8217;t do that, so self is the instance of the closure. Looking at this got me thinking about non local return(NLR). There was an interesting discussion about it on Twitter today with <a href="http://twitter.com/evanphx">@evanphx</a> saying</p>
<p><a href="http://www.flickr.com/photos/baroquebobcat/6670884691/" title="NLR in closure comment by @evanphx by baroquebobcat, on Flickr"><img src="http://farm8.staticflickr.com/7001/6670884691_673e1f3f78.jpg" width="500" height="225" alt="NLR in closure comment by @evanphx"></a></p>
<p>I think it&#8217;d be really interesting to try to add NLR to Mirah&#8217;s blocks. It might be crazy, but it could also be awesome.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/69">#69</a> &#8211; Mirah doesn&#8217;t check blocks signature against the signature of the method they&#8217;re supposed to be implementing.<br />
</strong><br />
Madness, but madness I think I can fix.</p>
<p><strong><a href="https://github.com/mirah/mirah/issues/74">#74</a> Constants!</strong></p>
<p>Mirah doesn&#8217;t let you create constants, other than classes and interfaces. I&#8217;d like to change that. And, the error tells you what&#8217;s missing. Now, all I&#8217;ve got to do is figure out how to implement it.</p>
<p><strong>Tune in next week&#8230;</strong></p>
<p>And that&#8217;s what I&#8217;m looking at doing next Sunday. Or some of it anyway. There&#8217;s a bunch of trickiness out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2012/01/10/mirah-office-hours-back-after-the-holidays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading from Rails 2.3.8 to 2.3.14: find_or_create_by on associations changed</title>
		<link>http://blog.baroquebobcat.com/2012/01/09/upgrading-from-rails-2-3-8-to-2-3-14-find_or_create_by-on-associations-change/</link>
		<comments>http://blog.baroquebobcat.com/2012/01/09/upgrading-from-rails-2-3-8-to-2-3-14-find_or_create_by-on-associations-change/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 03:52:08 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[rails 2.3]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=729</guid>
		<description><![CDATA[Update: I&#8217;m not the first one to run into this: lighthouse ticket find_or_create-via-has_many-fails-for-hash-parameters and rails/rails#207. Between 2.3.8 and 2.3.9 a change was added to ActiveRecord::Associations::AssociationCollection#method_missing that caused find_or_create_by_* to no longer accept hashes as arguments. An app I was upgrading from 2.3.8 ran into this as it passed hashes to a find_or_create_by_* call. The symptom [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> I&#8217;m not the first one to run into this: <a href="https://rails.lighthouseapp.com/projects/8994/tickets/6147-find_or_create-via-has_many-fails-for-hash-parameters">lighthouse ticket find_or_create-via-has_many-fails-for-hash-parameters</a> and <a href="https://github.com/rails/rails/pull/207">rails/rails#207</a>.<br />
Between 2.3.8 and 2.3.9 a change was added to <tt>ActiveRecord::Associations::AssociationCollection#method_missing</tt> that caused <tt>find_or_create_by_*</tt> to no longer accept hashes as arguments. An app I was upgrading from 2.3.8 ran into this as it passed hashes to a <tt>find_or_create_by_*</tt> call.</p>
<p>The symptom was that <tt>foobar</tt> in <tt>find_or_create_by_foobar</tt> became a serialized hash when saved to the database, instead of the string I was expecting.</p>
<p><script src="https://gist.github.com/1586708.js?file=db_col"></script></p>
<p>The reason it was changed was to ensure that the caches on the collection were updated properly (<a href="https://rails.lighthouseapp.com/projects/8994/tickets/1108">lighthouse 1108</a>) &#038; (<a href="https://github.com/rails/rails/commit/fad166c15277c72b370c90e890d509d0f6c9af63">commit fad166c1</a>), which is pretty important, but the fix didn&#8217;t take into account dealing w/ two of the cases that <tt>find_or_create_by_*</tt> accepts when called on an ActiveRecord class:</p>
<ul>
<li><tt>post.comments.find_or_create_by_body :body => 'bar', :type => 'baz'</tt></li>
<li><tt>post.comments.find_or_create_by_body 'bar', :type => 'baz'</tt></li>
</ul>
<p>The new behavior looked like this:</p>
<p><script src="https://gist.github.com/1586708.js?file=test.rb"></script></p>
<p>I wrote a patch for it (<a href="https://github.com/rails/rails/pull/4331">github.com/rails/rails/pull/4331</a>). Then I found out that 2.3 is only accepting security patches, so I closed it.</p>
<p>If you run into this and you want to use my patch, refer to gist <a href="https://gist.github.com/1586708">1586708</a> which has a monkey patchified version of it. If you want to work around the bug, you can use the optional block to set the attributes you were passing in the hash.</p>
<p><script src="https://gist.github.com/1586708.js?file=workaround.rb"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2012/01/09/upgrading-from-rails-2-3-8-to-2-3-14-find_or_create_by-on-associations-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test ActiveRecord with Reset Transactions Without Rails</title>
		<link>http://blog.baroquebobcat.com/2012/01/09/test-activerecord-with-reset-transactions-without-rails/</link>
		<comments>http://blog.baroquebobcat.com/2012/01/09/test-activerecord-with-reset-transactions-without-rails/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 03:23:58 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=725</guid>
		<description><![CDATA[I found myself wanting to use Rails&#8217; test transaction functionality in a Rails-less environment, and couldn&#8217;t find a tutorial about it. So I dug into the Rails source to figure out how it worked&#8211;just enough to pull it out into a gist. So, if you add this to your test_helper.rb or equivalent, you too can [...]]]></description>
			<content:encoded><![CDATA[<p>I found myself wanting to use Rails&#8217; test transaction functionality in a Rails-less environment, and couldn&#8217;t find a tutorial about it. So I dug into the Rails source to figure out how it worked&#8211;just enough to pull it out into a gist. So, if you add this to your <tt>test_helper.rb</tt> or equivalent, you too can have your ActiveRecord tests wrapped in transactions that rollback after each case. It also lets you use fixtures, but who does that?</p>
<p><script src="https://gist.github.com/1571808.js?file=test_transactions_without_rails.rb"></script><br />
<noscript><br />
<code># Snippet to wrap tests with ActiveRecord db transactions outside Rails.<br />
#<br />
# references:<br />
#   https://github.com/rails/rails/blob/master/railties/lib/rails/test_help.rb#L27<br />
#   https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L704<br />
#<br />
# TestFixtures checks whether configurations is blank<br />
# to determine whether to use transactions/fixtures or not.<br />
# which is why we need to set it to something.<br />
ActiveRecord::Base.configurations= {test: {<br />
    database: 'something_test',<br />
    adapter: 'mysql',<br />
    # ...<br />
}}<br />
ActiveRecord::Base.establish_connection ActiveRecord::Base.configurations[:test]<br />
class ActiveSupport::TestCase < ::Test::Unit::TestCase<br />
  include ActiveRecord::TestFixtures<br />
  setup do<br />
    ActiveRecord::IdentityMap.clear<br />
  end<br />
# if you want to use fixtures you can set the fixture path, and it'll load them like rails does.<br />
# self.fixture_path = "my_fixtures"<br />
end</code><br />
</noscript></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2012/01/09/test-activerecord-with-reset-transactions-without-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>American Censorship Day</title>
		<link>http://blog.baroquebobcat.com/2011/11/15/american-censorship-day/</link>
		<comments>http://blog.baroquebobcat.com/2011/11/15/american-censorship-day/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 06:59:34 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=713</guid>
		<description><![CDATA[SOPA is getting hearings today (Nov 16th). So I added the censorship banner for the day. http://americancensorship.org/]]></description>
			<content:encoded><![CDATA[<p>SOPA is getting hearings today (Nov 16th). So I added the censorship banner for the day.</p>
<p><a href="http://americancensorship.org/">http://americancensorship.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/11/15/american-censorship-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mirah Office Hours</title>
		<link>http://blog.baroquebobcat.com/2011/11/08/mirah-office-hours-6/</link>
		<comments>http://blog.baroquebobcat.com/2011/11/08/mirah-office-hours-6/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 16:45:22 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=708</guid>
		<description><![CDATA[This week I looked at doing views in Shatner again. I had thought of a new approach to get around def_edb&#8216;s issues with unquotes. That quickly devolved into an exploration of a part of the inference engine I hadn&#8217;t played with yet. I&#8217;d been looking for a good way to share state between views and [...]]]></description>
			<content:encoded><![CDATA[<p>This week I looked at doing views in Shatner again. I had thought of a new approach to get around <em>def_edb</em>&#8216;s issues with unquotes. That quickly devolved into an exploration of a part of the inference engine I hadn&#8217;t played with yet.</p>
<p>I&#8217;d been looking for a good way to share state between views and the ShatnerApp. Initially, my plan was to just have the view be a method on the Shatner app, just like how Dubious currently does it. But, that&#8217;s pretty pedestrian and totally wouldn&#8217;t cause things to blow up. Blowing things up in Mirah is one of the reasons I work on Shatner.</p>
<p>I thought maybe I could build view objects as closures. That way they&#8217;d have references to all the variables defined in the outer scope, but they could still be separate classes and have separate methods ala Rails&#8217; view helpers.</p>
<p>And maybe it&#8217;d be easier to build a macro that just modifies the code in place to implement something like (<a href="https://gist.github.com/1346820#file_shatner_view.mirah">gist</a>):</p>
<p><script src="https://gist.github.com/1346820.js?file=shatner_view.mirah"></script></p>
<p>so that it becomes (<a href="https://gist.github.com/1346820#file_shatner_view_unwound.mirah">gist</a>):</p>
<p><script src="https://gist.github.com/1346820.js?file=shatner_view_unwound.mirah"></script></p>
<p>Of course, that didn&#8217;t work.</p>
<p>What I discovered was that Mirah currently doesn&#8217;t support closures being defined in closures (issue <a href="https://github.com/mirah/mirah/issues/155">#155</a>). They don&#8217;t work because they can&#8217;t figure out what the outer scope is.</p>
<p>When a closure is created in Mirah, it begins life as a Mirah::AST::Block. However, it doesn&#8217;t stay just a block for long. After the parse phase is over, it is transformed.</p>
<p>The typer figures out what method is being called with the block, and figures out what the block&#8217;s interface is. It generates AST nodes for a class that implements that interface and dumps the class into the tree of the outer class. It then adds AST nodes at the call site for creating a new instance of that freshly minted closure class and carries on typing.</p>
<p>The problem is that the AST nodes inside the block still think their parent is the block. This is only a problem when you have another block inside a block because a Mirah::AST::Block doesn&#8217;t have a class associated with it, so the closure generated inside the closure doesn&#8217;t know what contains it.</p>
<p>I still haven&#8217;t quite figured out how to resolve this. I feel like there&#8217;s probably some AST munging needed to get it to work properly, but I&#8217;m not sure what operations need to be taken.</p>
<p>It&#8217;s a very interesting problem though.</p>
<p>The other thing I looked at was getting == to use equals. Earlier, I&#8217;d tried copying <a href="https://github.com/mirah/mirah/blob/e5a60b205af188c332328f663e0c2fd8014c6427/lib/mirah/jvm/types/intrinsics.rb#L306">String#+</a> doing something like (<a href="https://gist.github.com/1346820#file_intrinsics_equal.rb">gist</a>):</p>
<p><script src="https://gist.github.com/1346820.js?file=intrinsics_equal.rb"></script></p>
<p>Which worked for ==, but not for !=, because I couldn&#8217;t figure out how to negate the call.</p>
<p>So, I tried the method used by kind_of?, which creates some AST nodes and shoves them back into the tree. That worked for the Java source generator, but not the Bytecode generator. Which was kind of odd.</p>
<p>Clearly I don&#8217;t know enough about how the bytecode generator works. Maybe I&#8217;ll look into that some next week.</p>
<p>&#8216;Til next week everybody.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/11/08/mirah-office-hours-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mirah Office Hours</title>
		<link>http://blog.baroquebobcat.com/2011/10/25/mirah-office-hours-5/</link>
		<comments>http://blog.baroquebobcat.com/2011/10/25/mirah-office-hours-5/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 15:50:37 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=699</guid>
		<description><![CDATA[This week I decided to focus just on bugs. I picked a few that looked interesting and set about investigating. I decided to look at #108, #150, #151, #68 and #52. 108 I realized, I hadn&#8217;t thought enough about. It&#8217;s really a design thing. Do you want to require that your closures match signatures with [...]]]></description>
			<content:encoded><![CDATA[<p>This week I decided to focus just on bugs. I picked a few that looked interesting and set about investigating.</p>
<p>I decided to look at #108, #150, #151, #68 and #52.</p>
<p>108 I realized, I hadn&#8217;t thought enough about. It&#8217;s really a design thing. Do you want to require that your closures match signatures with the methods the implement? What if you don&#8217;t care about the arguments because everything you want to do has to do with the closed scope and not with what you&#8217;re passed? I could see it both ways. On the one hand, requiring a matching signature ensures all the types and whatnot are correct. On the other hand, if you aren&#8217;t using the passed arguments, they are just boilerplate code.</p>
<p>I think we should allow closures to have no arguments where the method they are implementing has them for niceness. But it should be an all or nothing thing. Either no parameters, or parameters matching the signature of the method you expect to be implementing.</p>
<p><strong>#52</strong></p>
<p>I spent most of my time on this one. It seemed straight forward at first, but had a number of tricky bits that took some working out. The problem was that if you had a begin rescue end block, and treated it as an expression if the result types of the block itself and the rescue clauses differed, Mirah wouldn&#8217;t raise an exception, but the JVM would. For example (<a href="https://gist.github.com/1312734#file_bad_rescue.mirah">gist</a>):</p>
<p><script src="https://gist.github.com/1312734.js?file=bad_rescue.mirah"></script></p>
<p><em>foo</em> either is an int or a String, which would be fine in Ruby&#8211;but not in Mirah because Mirah has static typing.</p>
<p>So, I set about fixing it. The first thing was to define the valid behavior. What I came up with was this:</p>
<ul>
<li>if a begin rescue block is treated as an expression, check the compatibility of its result types</li>
<li>if it&#8217;s not an expression, don&#8217;t check the result types</li>
</ul>
<p>The second one is nicer because it lets you not care when you don&#8217;t want to care. For example (<a href="https://gist.github.com/1312734#file_statement_rescue.mirah">gist</a>):</p>
<p><script src="https://gist.github.com/1312734.js?file=statement_rescue.mirah"></script></p>
<p>If we checked result types in both expressions and statements, the above would fail to compile, which would suck.</p>
<p>I started by writing a <a href="https://github.com/mirah/mirah/blob/5690e6ff3b8f65a9dd2ca727ffaca70972ef95fb/test/core/test_typer.rb#L224:L237">couple tests</a> of the expected behavior. I wanted to get an inference error when I used the rescue as an expression, but not as a statement.</p>
<p>Then I went looking for other, similar pieces of functionality that I could use for a guide. I found that <em>if else</em>s <a href="https://github.com/mirah/mirah/blob/5690e6ff3b8f65a9dd2ca727ffaca70972ef95fb/test/core/test_typer.rb#L177-179">also</a> follow this pattern, so I wanted to look at how <em>If</em> AST nodes were inferred, trying to get a handle on how I would change <em>rescue</em>s. I grepped through <em>lib/</em> for If&#8217;s infer method and found it in <a href="https://github.com/mirah/mirah/blob/5690e6ff3b8f65a9dd2ca727ffaca70972ef95fb/lib/mirah/ast/flow.rb#L53-93">lib/mirah/ast/flow.rb</a>. What it does is get the if body&#8217;s result type, and the else&#8217;s result type and check to see if they are compatible (<a href="https://gist.github.com/1312734#file_if_infer_snip.rb">gist</a>).</p>
<p><script src="https://gist.github.com/1312734.js?file=if_infer_snip.rb"></script></p>
<p>Rescue inference was a little more complicated than If because rescue&#8217;s have a lot more pieces. First, you have the body between the <em>begin</em> and the first <em>rescue</em>. Then, there can be multiple <em>rescue</em> clauses, each handling a different set of exceptions. Finally, if there&#8217;s an <em>else</em>, it runs after the body if there is no exception. There&#8217;s also <em>ensure</em> which is run after, but doesn&#8217;t return anything, so it shouldn&#8217;t affect result type comparisons (need to write a test for that &#8230;).</p>
<p>So, the types that need to be compatible are the that of the body if there isn&#8217;t an else or the else&#8217;s and all the rescue clauses. Kind of complicated. But pretty doable. I <a href="https://github.com/mirah/mirah/blob/677e4aa29dcd5c112a5ef2c04587b39ac5ba5269/lib/mirah/ast/flow.rb#L325-362">modified</a> the Rescue node&#8217;s infer method to test compatibility of the body or the else and all the clauses, which worked for the tests I wrote but broke other tests.</p>
<p>It broke other tests because of how deferred inference works. When inference is <a href="https://github.com/mirah/mirah/blob/master/lib/mirah/typer/simple.rb#L313">reattempted</a>, the typer assumes that the deferred node was evaluated as an expression, which breaks when it is a Rescue because its inference depends on how it was used.</p>
<p>So as a work around, I added an ivar to the Rescue node to cache how it was initially inferred (<a href="https://github.com/mirah/mirah/blob/677e4aa29dcd5c112a5ef2c04587b39ac5ba5269/lib/mirah/ast/flow.rb#L325">lib/mirah/flow.rb</a>).</p>
<p><script src="https://gist.github.com/1312734.js?file=flow.rb"></script></p>
<p>It&#8217;s a hack, but it resolved the issue. I&#8217;d like to look into how to change things to make expression vs statementness be something defined in the AST instead of decided at inference time, or make it more explicit that the expression-ness is determined by the parent node during inference.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/10/25/mirah-office-hours-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another BugMash This Saturday</title>
		<link>http://blog.baroquebobcat.com/2011/10/24/another-bugmash-this-saturday/</link>
		<comments>http://blog.baroquebobcat.com/2011/10/24/another-bugmash-this-saturday/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 01:16:06 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Boulder]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=684</guid>
		<description><![CDATA[It&#8217;s halloween weekend and I&#8217;m going to mashing some bugs. Rails has got 557 issues open and we&#8217;re going to take a crack at &#8216;em. If you&#8217;ve never contributed to Rails before, or you have a couple commits that have been accepted, we&#8217;d love to have you. If you want to join me, please RSVP [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s halloween weekend and I&#8217;m going to mashing some bugs. Rails has got <a href="https://github.com/rails/rails/issues">557</a> issues open and we&#8217;re going to take a crack at &#8216;em.</p>
<p>If you&#8217;ve never contributed to Rails before, or you have a couple commits that have been accepted, we&#8217;d love to have you.</p>
<p> If you want to join me, please RSVP at <a href="http://plancast.com/p/86c6/rails-bugmash-halloween-special-edition">http://plancast.com/p/86c6/rails-bugmash-halloween-special-edition</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/10/24/another-bugmash-this-saturday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mirah Office Hours: Shatner Revisited, Fix a Few Bugs</title>
		<link>http://blog.baroquebobcat.com/2011/10/18/mirah-office-hours-4/</link>
		<comments>http://blog.baroquebobcat.com/2011/10/18/mirah-office-hours-4/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 15:38:23 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=686</guid>
		<description><![CDATA[This week I wanted to get back to my pet Sinatra clone&#8211;Shatner. Last time I tried working on it, I was trying to figure out how to get views working like they do in Ruby. I want to end up with a dsl like this(gist): Where you can call edb :view_name just like you call [...]]]></description>
			<content:encoded><![CDATA[<p>This week I wanted to get back to my pet Sinatra clone&#8211;Shatner. Last time I tried working on it, I was trying to figure out how to get views working like they do in Ruby. I want to end up with a dsl like this(<a href="https://gist.github.com/1294421#file_hello_view.mirah">gist</a>):</p>
<p><script src="https://gist.github.com/1294421.js?file=hello_view.mirah"></script></p>
<p>Where you can call <em>edb :view_name</em> just like you call <em>erb :view_name</em> in Sinatra, and it figures out what you want.</p>
<p>I tried to do this by injecting a call to the <em>def_edb</em> macro into the class&#8217;s AST node. That didn&#8217;t work. Because <em>def_edb</em> was getting expanded before the outer macro, instead of passing it a proper AST node representing a method name, I was passing it an Unquote, which it didn&#8217;t know what to do with.</p>
<p>This looked like a rather difficult thing to untangle, so I gave up on it for now and file a bug (<a href="https://github.com/mirah/mirah/issues/152">#152</a>).</p>
<p>I moved on to fixing some bugs.</p>
<p>I made a quick list of four boogs that looked promising</p>
<ul>
<li><a href="https://github.com/mirah/mirah/issues/110">#110</a> ICE with an empty block</li>
<li><a href="https://github.com/mirah/mirah/issues/108">#108</a> closure generation</li>
<li><a href="https://github.com/mirah/mirah/issues/109">#109</a> incorrectly attaching macros to the wrong node type</li>
<li><a href="https://github.com/mirah/mirah/issues/123">#123</a> ICE from methods that have same name as previously defined macro</li>
</ul>
<p><strong>#110 ICE with empty block</strong></p>
<p><script src="https://gist.github.com/1294421.js?file=110_stacktrace_V"></script></p>
<p>Somewhere the AST node for the body of the block was being set to <em>nil</em>. This caused some later code to blow up when it attempted to iterate over the block&#8217;s children. I fixed it by ensuring that the body of a block is always <a href="https://github.com/mirah/mirah/commit/0a826dde5d96f4d9320f309572ab0afcd83e50cb#diff-0">set to some value</a>.</p>
<p>I looked at some pretty interesting bits of the compiler while fixing this. Did you know that Mirah&#8217;s block support works in two ways? You can use it like you would in JRuby, and pass a block in place of an interface implementation, which is cool. And, you can also pass it a block that contains the definitions of the methods you want to implement. For example (<a href="https://gist.github.com/1294421#file_blocks.mirah">gist</a>)</p>
<p><script src="https://gist.github.com/1294421.js?file=blocks.mirah"></script></p>
<p><strong>#108 closure generation</strong></p>
<p>I was able to reproduce this, and figure out roughly what&#8217;s going on, but haven&#8217;t fixed it yet. The problem is that we&#8217;re not generating the signature of the method a block passed as an interface correctly all the time. When the block has no arguments, but the method it&#8217;s supposed to implement does, Mirah generates a method with the same name but no arguments. Problem.</p>
<p><strong>#109  incorrectly attaching macros to the wrong node type</strong></p>
<p>I reproduced this but didn&#8217;t look into it. It&#8217;s interesting it only happens when the macro is used somewhere else in the code.</p>
<p><strong>#123  ICE from methods that have same name as previously defined macro</strong></p>
<p>The problem here was that a macro&#8217;s return type is InlineCode, and the MethodDefinition node didn&#8217;t know how to validate it&#8217;s own signature against a macro with the same name. I <a href="https://github.com/mirah/mirah/commit/7a933f353fa4cd11f3a813ce67a02aa68787b31b">put in a condition</a> that will cause inference to fail with an error that says the method has the same name as a macro. It&#8217;s not particularly elegant, but I don&#8217;t think it&#8217;s a bad thing for the compiler to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/10/18/mirah-office-hours-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mirah Office Hours</title>
		<link>http://blog.baroquebobcat.com/2011/10/11/mirah-office-hours-3/</link>
		<comments>http://blog.baroquebobcat.com/2011/10/11/mirah-office-hours-3/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 15:40:30 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Mirah]]></category>

		<guid isPermaLink="false">http://blog.baroquebobcat.com/?p=676</guid>
		<description><![CDATA[This week ended up mostly being researchy. I had a bunch of plans. I wanted to look at some of the work I&#8217;d done with implicit main methods&#8211;with an eye for changing from creating them at code generation time to modifying the AST and putting them in the right class. I also wanted to dig [...]]]></description>
			<content:encoded><![CDATA[<p>This week ended up mostly being researchy. I had a bunch of plans. I wanted to look at some of the work I&#8217;d done with implicit main methods&#8211;with an eye for changing from creating them at code generation time to modifying the AST and putting them in the right class. I also wanted to dig into making <em>==</em> use Java&#8217;s <em>equals()</em> instead of Java&#8217;s <em>==</em>&#8211;which compares identity for objects.</p>
<p><strong>Plans</strong></p>
<ul>
<li>use AST modification for main method generation</li>
<li>== &#8211;> .equals()</li>
<li>eql? &#8211;> ==</li>
<li>refactor intrinsic files</li>
<li>research ivar inference(related <a href="https://github.com/mirah/mirah/issues/151">#151</a>)</li>
<li>&#8230;</li>
<li>boogs</li>
</ul>
<p>I didn&#8217;t get to everything, but I touched a lot of it.</p>
<p><strong>Main method</strong></p>
<p>I had some old code that did this from the last time played around with it, so I tried starting there. It modified the JVM compiler&#8217;s define_main method to pull elements out of the AST and inject them into the main method of the class with the same name as the file. It worked as long as a class with a matching name was in the file and failed miserably when there wasn&#8217;t.</p>
<p>I tried different things to generate AST nodes for the &#8216;Script&#8217; class that Mirah generates when there is no class of the same name as the file, but couldn&#8217;t get it to work. After taking a break and looking again I also realized that I was doing my editing in the wrong place.</p>
<p>The compiler is actually where the code generation happens and not where the AST is generated or transformed. It gets the AST after it has been transformed, as necessary, and after all the types have been inferred. Which makes it a bad place to try to extend Mirah&#8217;s behavior.</p>
<p>I think next time I&#8217;ll try to inject the main method AST transform as a plugin that adds functionality to the transformer.</p>
<p><strong>equals</strong></p>
<p>I poked around making == use Java&#8217;s equals method instead of using ==, which for objects compares their references to see if they point at the same thing. Getting == to work was actually pretty straight forward, I just replaced the code generation that does the java style == with a method call to equals. I didn&#8217;t push it yet because I haven&#8217;t added !=, which requires a little more knowledge about bytecode.</p>
<p><strong>ivars</strong></p>
<p>I wanted to see if I could figure out how to get public/protected instance variables from superclasses to be accessible from subclasses. I thought it would have something to do with look up mechanism, but I didn&#8217;t know where to start.</p>
<p>After looking around the various Java type lookup mechanisms I&#8217;m still a bit confused about how everything works. I think I&#8217;ll do a deeper look into it next week, focusing on this file (<a href="https://github.com/mirah/mirah/blob/master/lib/mirah/jvm/method_lookup.rb">/lib/mirah/jvm/method_lookup.rb</a>), which looks to be where most of the interesting type stuff happens.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.baroquebobcat.com/2011/10/11/mirah-office-hours-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

