/
atomy
executable file
·110 lines (88 loc) · 2.04 KB
/
atomy
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env rbx
# vim: ft=ruby
unless Rubinius.ruby19?
puts("Atomy must be run in 1.9 mode.")
exit(1)
end
base = File.expand_path "../../lib/", __FILE__
kernel = File.expand_path "../../kernel/", __FILE__
$LOAD_PATH.unshift kernel
require 'readline'
require 'optparse'
require 'profiler'
require base + "/atomy"
options = {}
unless ARGV.empty? || ARGV[0][0] != ?-
OptionParser.new do |o|
o.banner = "usage: atomy [options]"
o.on("-B", "--print-bytecode", "print out compiled bytecode") do |v|
options[:debug] = v
end
o.on("-e", "--evaluate EXPR", "evaluate EXPR and print the result") do |v|
options[:evaluate] = v
end
o.on("-s", "--before-start EXPR", "evaluate EXPR beforehand") do |v|
options[:start] = v
end
o.on("-l", "--load FILE", "load FILENAME and start the REPL") do |v|
options[:load] = v
end
o.on("-x", "--skip-kernel", "don't load the kernel") do
options[:skip_kernel] = true
end
o.on("-p", "--profile", "perform profiling") do
options[:profile] = true
end
o.on_tail("-h", "--help", "show this message") do
puts o
exit
end
end.parse!
end
unless options[:skip_kernel]
require("boot")
end
if options[:profile]
profiler = Rubinius::Profiler::Instrumenter.new
profiler.start
end
def run_atomy(options)
if str = options[:evaluate] || options[:start]
$0 = "(eval)"
res = Atomy::Compiler.eval(
str,
TOPLEVEL_BINDING,
"(eval)",
1,
options[:debug]
)
if options[:evaluate]
if res.respond_to?(:write)
res.write
else
p(res)
end
return
end
end
if file = options[:load] || ARGV[0]
$0 = file
run = ARGV.shift
Atomy.load(file, run ? :run : :load, options[:debug])
return if run
end
require("repl").repl(
File.expand_path("~/.atomy_history"),
TOPLEVEL_BINDING,
options[:debug]
)
end
begin
run_atomy(options)
ensure
if options[:profile]
profiler.stop
#data = profiler.info
profiler.show
end
end