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
|