module Braingasm

Constants

VERSION

Public Class Methods

compile(code) click to toggle source
# File lib/braingasm.rb, line 23
def self.compile(code)
  tokenizer = Tokenizer.new(code)
  compiler = Compiler.new
  parser = Parser.new(tokenizer, compiler)

  parser.parse_program
end
handle_options(**command_line_options) click to toggle source
# File lib/braingasm/options.rb, line 31
def self.handle_options(**command_line_options)
  Options[:eof] = 0 if command_line_options[:zero]
  Options[:eof] = -1 if command_line_options[:negative]
  Options[:eof] = nil if command_line_options[:as_is]

  Options[:wrap_cells] = true if command_line_options[:bound]

  if command_line_options[:cell_size_given]
    cell_size = command_line_options[:cell_size]
    Options[:cell_limit] = 2**cell_size
    Options[:wrap_cells] = true
  end
end
initialize_machine(code) click to toggle source
# File lib/braingasm.rb, line 14
def self.initialize_machine(code)
  machine = Machine.new

  machine.program = compile(code)
  machine.input = InputBuffer.new($<)
  machine.output = $>
  machine
end
run(code) click to toggle source
# File lib/braingasm.rb, line 9
def self.run(code)
  machine = self.initialize_machine(code)
  machine.run()
end