Skip to content

Commit

Permalink
Make ReadWriteAnalysis great again
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Dec 10, 2016
1 parent c3f90c8 commit f20557c
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ class ReadWriteAnalysis implements BrainfuckAnalyzer {
cell.data(this, ReadWriteData).writeCount += times;
maxMemory = Math.max(maxMemory, runner.memory.memoryIndex)
}
if (cmd instanceof SyntaxTree || cmd instanceof PrintSyntax) {
// TODO: I don't think this handles END_WHILE at the moment
cell.data(this, ReadWriteData).readCount++
maxMemory = Math.max(maxMemory, runner.memory.memoryIndex)
if (cmd instanceof PrintSyntax) {
markCellRead(cell, runner);
}
}

@Override
void beforeEndWhile(MemoryCell cell, BrainfuckRunner runner) {
markCellRead(cell, runner);
}

@Override
void beforeWhile(MemoryCell cell, BrainfuckRunner runner) {
markCellRead(cell, runner);
}

private void markCellRead(MemoryCell cell, BrainfuckRunner runner) {
cell.data(this, ReadWriteData).readCount++
maxMemory = Math.max(maxMemory, runner.memory.memoryIndex)
}

@Override
void print() {
println "Total memory used = $cellsUsed"
Expand Down

0 comments on commit f20557c

Please sign in to comment.