~tim/scheme-vm

ref: d947890410d3f5830161c11c89fdcb49aca9c10c scheme-vm/program.rb -rw-r--r-- 476 bytes
d9478904Tim Morgan Fix ruby-version file 6 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require_relative 'parser'
require_relative 'compiler'

class Program
  def initialize(code, args: [], stdout: $stdout)
    @sexps = Parser.new(code).parse
    @instr = compiler.compile
    @args = args
    @stdout = stdout
  end

  def run(debug: 0)
    compiler.pretty_print(@instr) if debug >= 2
    vm.execute(nil, debug: debug)
  end

  def compiler
    @compiler ||= Compiler.new(@sexps)
  end

  def vm
    @vm ||= VM.new(@instr, stdout: @stdout, args: @args)
  end
end