~tim/scheme-vm

ref: c5110102ce2df2d78a0c87f293edf20f5a3984e7 scheme-vm/bin/scheme -rwxr-xr-x 940 bytes
c5110102Tim Morgan Add more char functions 2 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
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby

require 'optparse'
require_relative '../program'

options = { debug: 0 }
opt_parser = OptionParser.new do |opts|
  opts.banner = "Usage: scheme [options] path [arguments]\n" \
                "       scheme [options] -e '(import (scheme write)) (write \"hello world\")' [arguments]"

  opts.on('-e SCRIPT', 'Execute script passed as argument') do |script|
    options[:script] = script
  end

  opts.on('-d', '--debug', 'Output debugging info (repeat to show more)') do
    options[:debug] += 1
  end

  opts.on('-h', '--help', 'Print this help') do
    puts opts
    exit
  end
end
opt_parser.parse!

program = if options[:script]
            Program.new(options[:script], args: ARGV)
          elsif ARGV.any?
            filename = ARGV.shift
            Program.new(File.read(filename), filename: filename, args: ARGV)
          end

if program
  exit program.run(debug: options[:debug])
else
  puts opt_parser
end