Class: Spitewaste::WhitespaceEmitter
- Inherits:
-
Emitter
- Object
- Emitter
- Spitewaste::WhitespaceEmitter
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
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
|