Skip to content

Commit

Permalink
Remove current-instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
fraya committed May 13, 2024
1 parent 802bf55 commit cb68f6d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
10 changes: 2 additions & 8 deletions sources/brainfuck.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ define sealed class <bf> (<object>)
required-init-keyword: program:;
constant slot bf-memory :: <memory> = make(<memory>, fill: 0),
init-keyword: memory:;
constant virtual slot current-instruction :: <instruction>;
end;

define inline method current-instruction
(bf :: <bf>) => (instruction :: <instruction>)
bf.bf-program[bf.bf-pp]
end;

define inline method instruction-at
Expand Down Expand Up @@ -72,7 +66,7 @@ end;
define method run
(bf :: <bf>) => (bf :: <bf>)
while (program-not-finished?(bf))
execute(bf.current-instruction, bf);
execute(bf.bf-program[bf.bf-pp], bf);
bf.bf-pp := bf.bf-pp + 1
end;
bf
Expand Down Expand Up @@ -178,7 +172,7 @@ define method print-object
print-object(bf.bf-memory, s);
format(s," PP:%03d '%='",
bf.bf-pp,
bf.current-instruction);
bf.bf-program[bf.bf-pp]);
end;

////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions sources/jump-instruction.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define sealed method execute
method find-address(bf)
block (address)
let level = 1;
let jump = bf.current-instruction;
let jump = bf.bf-program[bf.bf-pp];
for (index from bf.bf-pp + 1 below bf.bf-program.size)
select (object-class(instruction-at(bf, index)))
<jump-forward> => level := level + 1;
Expand All @@ -57,7 +57,7 @@ define sealed method execute
method find-address(bf)
block (address)
let level = 1;
let jump = bf.current-instruction;
let jump = bf.bf-program[bf.bf-pp];
for (index from bf.bf-pp - 1 to 0 by -1)
select (object-class(instruction-at(bf, index)))
<jump-forward> => level := level - 1;
Expand Down
1 change: 0 additions & 1 deletion sources/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ define module brainfuck-impl
// Program exports

export
current-instruction,
instruction-at,
program-not-finished?;

Expand Down

0 comments on commit cb68f6d

Please sign in to comment.