|
@@ -4,6 +4,25 @@ module Chervil
|
4
|
4
|
@env = Env.new
|
5
|
5
|
end
|
6
|
6
|
|
|
7
|
+ def display(obj)
|
|
8
|
+ case obj
|
|
9
|
+ when true
|
|
10
|
+ '#t'
|
|
11
|
+ when false
|
|
12
|
+ '#f'
|
|
13
|
+ when AST::Function
|
|
14
|
+ "<function: #{obj.name.name}(#{obj.params.map(&:name).join(' ')})>"
|
|
15
|
+ when Float
|
|
16
|
+ if obj.floor.to_f == obj
|
|
17
|
+ obj.to_i
|
|
18
|
+ else
|
|
19
|
+ obj
|
|
20
|
+ end
|
|
21
|
+ else
|
|
22
|
+ obj
|
|
23
|
+ end
|
|
24
|
+ end
|
|
25
|
+
|
7
|
26
|
def run
|
8
|
27
|
begin
|
9
|
28
|
while line = Readline.readline("> ", true)
|
|
@@ -17,7 +36,7 @@ module Chervil
|
17
|
36
|
end
|
18
|
37
|
|
19
|
38
|
results = Interpreter.new(tree, @env).interpret
|
20
|
|
- results.each { |result| puts result unless result.nil? }
|
|
39
|
+ results.each { |result| puts display(result) unless result.nil? }
|
21
|
40
|
end
|
22
|
41
|
rescue Interrupt
|
23
|
42
|
puts
|