Class: Kaguya::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/kaguya/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
# File 'lib/kaguya/cli.rb', line 13

def initialize(argv)
  @argv = argv.dup
  parser.parse!(@argv)
end

Class Method Details

.start(argv) ⇒ Object



9
10
11
# File 'lib/kaguya/cli.rb', line 9

def self.start(argv)
  new(argv).run
end

Instance Method Details

#runObject



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

def run
  source_file = File.open(@argv[0], 'r')
  parser = Parser.new(source_file)
  ast = parser.parse

  if @debug
    puts '=== AST ==='
    pp ast
  end

  compiler = Compiler.new(ast)
  iseq = compiler.compile

  if @debug
    puts '=== ISEQ ==='
    pp iseq
    puts '=== RUN ==='
  end

  vm = VM.new(iseq)
  vm.run
end