Skip to content

Elements of Computing Systems Chapter 6

Tom Stuart edited this page Mar 5, 2015 · 6 revisions

Preamble

After the hard-won success of last meeting, we recapped the progress we'd made with our finished Computer and briefly mentioned a pull request to extract a Decoder chip before cracking on with Chapter 6. As there were some frustrations last meeting, we discussed whether splitting into smaller teams would avoid some of the tension in the group. As there were only around seven of us, we decided to try the problems together but be mindful of past issues. We particularly stressed the importance of each agreeing whether to write the simplest possible thing to make progress (deferring refactoring to the end) or to refactor as we go. We opted for the former approach and ploughed on with Chapter 6.

Exercises

Tom walked us through his hack-assembler project and we decided to use it to test drive our solution to the exercises. With Leo at the keyboard, we worked our way through Tom's test cases, trying to be as conservative as possible in our approach and avoid getting side-tracked with refactoring:

  1. Initial Parser#has_more_commands? implementation
  2. Initial Parser#advance implementation
  3. Enhancements to Parser#advance and Parser#has_more_commands? to support interleaved comments
  4. Parser#command_type implementation
  5. Parser#symbol implementation
  6. Parser#dest implementation
  7. Parser#comp implementation (as a particularly nifty one-liner that drew groans from some members of the group)
  8. Parser#jump implementation
  9. Code implementation
  10. bin/assembler implementation
  11. SymbolTable implementation
  12. Full two-pass assembler implementation

During the exercises, there was an interesting aside: we added a private attr_reader to the Parser like so:

class Parser
  private
 
  attr_reader :lines
end

Tom mentioned that this actually raises a warning when running Ruby with warnings enabled (warning: private attribute?). As a workaround, you actually have to use private like so:

class Parser
  attr_reader :lines
  private :lines
end

We managed to complete all the exercises and only ran over by a few minutes. For comparison, Tom then ran through his different solutions to the exercises and the varying performance of each. He has since posted more information about the different approaches to the mailing list but curiously the fastest implementation remains the one we wrote together.

We agreed to meet again in three weeks to discuss Chapter 7 with Leo and Geckoboard graciously offering to host once more.

Thanks

Thanks to Geckoboard for hosting the meeting, Leo for driving and Tom for the hack-assembler project.

Clone this wiki locally