Skip to content

Commit

Permalink
Merge write statements in MindFreak to_c
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Oct 17, 2024
1 parent d9bdebb commit a1817e0
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions MindFreak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ def to_c(program, tape = TAPE_DEFAULT_SIZE, eof = 0, type = 'unsigned int')
when INCREMENT # Tape
code << "#{indent}*(pointer#{"+#{offset}" if offset}) #{'+' unless assign}= #{arg};"
when WRITE # Write
c = "putchar(*(pointer#{"+#{offset}" if offset}));"
code << "#{indent}#{arg > 1 ? "for(unsigned int i = #{arg}; i--;) #{c}" : c}"
code << "#{indent}#{"for(unsigned int i = #{arg}; i--;) " if arg > 1}putchar(*(pointer#{"+#{offset}" if offset}));"
when READ # Read
code << "#{indent}for(unsigned int i = #{arg-1}; i--;) getchar();" if arg > 1
case eof
Expand Down

0 comments on commit a1817e0

Please sign in to comment.