Browse Source

Clean up REPL

master
Dylan Baker 5 years ago
parent
commit
f34112d2c8
3 changed files with 11 additions and 1 deletions
  1. 2
    1
      bin/chervil
  2. 1
    0
      lib/chervil/ast/definition.rb
  3. 8
    0
      lib/chervil/ast/function.rb

+ 2
- 1
bin/chervil View File

@@ -8,5 +8,6 @@ env = Chervil::Env.new
8 8
 while line = Readline.readline("> ", true)
9 9
   lexer = Chervil::Lexer.new(line)
10 10
   tree = Chervil::Parser.new(lexer).parse
11
-  puts Chervil::Interpreter.new(tree, env).interpret
11
+  results = Chervil::Interpreter.new(tree, env).interpret
12
+  results.each { |result| puts result unless result.nil? }
12 13
 end

+ 1
- 0
lib/chervil/ast/definition.rb View File

@@ -14,6 +14,7 @@ module Chervil::AST
14 14
 
15 15
     def evaluate(env)
16 16
       env.set(@name.name, @value)
17
+      nil
17 18
     end
18 19
   end
19 20
 end

+ 8
- 0
lib/chervil/ast/function.rb View File

@@ -12,6 +12,10 @@ module Chervil::AST
12 12
       @params == other.params && @body == other.body
13 13
     end
14 14
 
15
+    def evaluate(env)
16
+      self
17
+    end
18
+
15 19
     def call(args)
16 20
       unless @params.size == args.size
17 21
         raise "Expected #{params.size} arguments but received #{args.size}"
@@ -29,5 +33,9 @@ module Chervil::AST
29 33
 
30 34
       current_expr
31 35
     end
36
+
37
+    def to_s
38
+      "<function>"
39
+    end
32 40
   end
33 41
 end

Loading…
Cancel
Save