Skip to content

Commit

Permalink
Finish the extraction that I was supposed to do in dbad7a.
Browse files Browse the repository at this point in the history
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 8f6ee03
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions csharp/BrainmessShort/Main.cs
Expand Up @@ -23,25 +23,26 @@ public static void Main(string[] args)


char Fetch() 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() public void Run()
{ {
while(pc < program.Length) while(pc < program.Length)
{ {
char instruction = Fetch (); char instruction = Fetch();
pc++;
switch(instruction) switch(instruction)
{ {
case '>': case '>':
Expand All @@ -65,13 +66,13 @@ public void Run()
case '[': case '[':
if (tape[tc] == 0) if (tape[tc] == 0)
{ {
pc = JumpForward (); JumpForward();
} }
break; break;
case ']': case ']':
if (tape[tc] != 0) if (tape[tc] != 0)
{ {
pc = JumpBackward (); JumpBackward();
} }
break; break;
} }
Expand Down

0 comments on commit 8f6ee03

Please sign in to comment.