Permalink
Browse files

Finish the extraction that I was supposed to do in dbad7a.

Previous commit left the pc variable being used in Run method.
This commit fixes that so that I have a commit to point to for blog.
  • Loading branch information...
michaelgwelch committed Mar 22, 2012
1 parent dbad7a8 commit 8f6ee036182c9584d639f58456476aefb62b8701
Showing with 10 additions and 9 deletions.
  1. +10 −9 csharp/BrainmessShort/Main.cs
@@ -23,25 +23,26 @@ public static void Main(string[] args)
char Fetch()
{
return program[pc];
var instruction = program[pc];
pc++;
return instruction;
}
int JumpForward()
void JumpForward()
{
return program.FindMatch(pc - 1) + 1;
pc = program.FindMatch(pc - 1) + 1;
}
int JumpBackward()
void JumpBackward()
{
return program.FindMatch(pc - 1);
pc = program.FindMatch(pc - 1);
}
public void Run()
{
while(pc < program.Length)
{
char instruction = Fetch ();
pc++;
char instruction = Fetch();
switch(instruction)
{
case '>':
@@ -65,13 +66,13 @@ public void Run()
case '[':
if (tape[tc] == 0)
{
pc = JumpForward ();
JumpForward();
}
break;
case ']':
if (tape[tc] != 0)
{
pc = JumpBackward ();
JumpBackward();
}
break;
}

0 comments on commit 8f6ee03

Please sign in to comment.