Module: Braingasm

Defined in:
lib/braingasm.rb,
lib/braingasm/io.rb,
lib/braingasm/errors.rb,
lib/braingasm/parser.rb,
lib/braingasm/machine.rb,
lib/braingasm/options.rb,
lib/braingasm/version.rb,
lib/braingasm/compiler.rb,
lib/braingasm/prefixes.rb,
lib/braingasm/tokenizer.rb

Defined Under Namespace

Modules: Options Classes: BraingasmError, Compiler, ExitSignal, InputBuffer, JumpSignal, Machine, Parser, ParsingError, PrefixStack, Tokenizer, VMError

Constant Summary collapse

VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.compile(code) ⇒ Object



23
24
25
26
27
28
29
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



14
15
16
17
18
19
20
21
# 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) ⇒ Object



9
10
11
12
# File 'lib/braingasm.rb', line 9

def self.run(code)
  machine = self.initialize_machine(code)
  machine.run()
end