Module: FAM

Defined in:
lib/fam.rb,
lib/fam.rb

Defined Under Namespace

Modules: Machine, Syntax

Constant Summary collapse

VERSIONS =
{ :major => 0, :minor => 1, :tiny => 3 }

Class Method Summary collapse

Class Method Details

.run(string, allocate: '200B', clock: 6, verbose: false, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fam.rb', line 21

def self.run string, allocate: '200B', clock: 6, verbose: false, &block
  $VERBOSE = verbose
  $CLOCK = clock

  lexed = Syntax::Lexer.lex string
  puts lexed if $VERBOSE
  puts if $VERBOSE
  parsed = Syntax::Parser.parse lexed.tokens
  tree = parsed.ast
  pp tree if $VERBOSE
  ram = Machine::RAM.new allocate
  cpu = Machine::CPU.new ram
  puts if $VERBOSE
  cpu.run tree do |pc|
    puts "Program counter: #{pc}" if $VERBOSE
    yield cpu.ram, pc, cpu.registers if block_given?
  end
  cpu
end

.version(*args) ⇒ Object



12
13
14
# File 'lib/fam.rb', line 12

def self.version *args
  VERSIONS.values.join '.'
end