Class: Spitewaste::WhitespaceEmitter

Inherits:
Emitter
  • Object
show all
Defined in:
lib/spitewaste/emitters/whitespace.rb

Instance Attribute Summary

Attributes inherited from Emitter

#instructions, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Emitter

#initialize

Constructor Details

This class inherits a constructor from Spitewaste::Emitter

Class Method Details

.encode(n) ⇒ Object



10
11
12
# File 'lib/spitewaste/emitters/whitespace.rb', line 10

def self.encode n
  (n < 0 ? ?\t : ' ') + n.abs.to_s(2).tr('01', " \t") + ?\n
end

Instance Method Details

#emit(io:) ⇒ Object



3
4
5
6
7
8
# File 'lib/spitewaste/emitters/whitespace.rb', line 3

def emit io:
  instructions.each do |op, arg|
    io.write OPERATORS_M2T[op]
    io.write self.class.encode(arg) if arg
  end
end