module Spitewaste
Constants
- FUCKTIONAL
- LIBSPW
- OPERATORS_M2T
- OPERATORS_T2M
- VERSION
Public Class Methods
encode(n)
click to toggle source
# 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
generate_filter_spw(fn, a, b)
click to toggle source
select() and reject() do almost the exact same thing, differing only in whether they drop or keep the match, so this is a bit of deduplication.
# File lib/spitewaste/parsers/fucktional.rb, line 4 def self.generate_filter_spw fn, a, b ops = ['push -10 dup call dec load swap store', 'pop'] yes, no = ops[a], ops[b] <<SPW push -10 dup store #{fn}_loop_%1$s: push 1 sub dup jn #{fn}_restore_%1$s swap dup %2$s jz #{fn}_no_%1$s #{yes} jump #{fn}_loop_%1$s #{fn}_no_%1$s: #{no} jump #{fn}_loop_%1$s #{fn}_restore_%1$s: push 9 sub load #{fn}_restore_loop_%1$s: dup push 10 add jz #{fn}_done_%1$s dup load swap push 1 add jump #{fn}_restore_loop_%1$s #{fn}_done_%1$s: dup load sub SPW end
Public Instance Methods
guess_format(program)
click to toggle source
# File lib/spitewaste.rb, line 17 def guess_format program white = program.count "\s\t\n" black = program.size - white return :whitespace if white > black program[/import|[^-\w\s]/] ? :spitewaste : :assembly end
strpack(s)
click to toggle source
# File lib/spitewaste.rb, line 25 def strpack s s.bytes.zip(0..).sum { |b, e| b * 128 ** e } end