forked from vito/atomy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quanto
executable file
·61 lines (48 loc) · 1.14 KB
/
quanto
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
#!/usr/bin/env rbx
base = File.expand_path "../../lib/atomo/", __FILE__
kernel = File.expand_path "../../kernel/", __FILE__
require 'readline'
require base + "/macros"
require base + "/method"
require base + "/util"
require base + "/compiler/compiler"
require base + "/compiler/stages"
require base + "/parser"
require base + "/patterns"
require base + "/code_loader"
bnd = TOPLEVEL_BINDING
def require_quanto(*as)
Atomo::CodeLoader.load_file *as
end
a = Time.now
puts "loading kernel"
require_quanto(kernel + "/boot.atomo")
puts Time.now - a
if ARGV[0]
require_quanto(ARGV[0])
exit(0)
end
HISTORY_FILE = File.expand_path("~/.quanto_history")
if File.exists?(HISTORY_FILE)
File.open(HISTORY_FILE, "r") do |f|
f.readlines.each do |l|
Readline::HISTORY << l.strip
end
end
end
SANE_HISTORY = []
while str = Readline.readline("> ")
next if str.empty?
SANE_HISTORY << str
begin
res = Atomo::Compiler.evaluate str, bnd
puts "=> #{res.pretty.render}"
rescue StandardError => e
puts "ERROR!"
puts "#{e}:\n #{e.message}"
puts e.backtrace
end
end
File.open(HISTORY_FILE, "a") do |f|
f.puts(*SANE_HISTORY)
end