Browse Source

Fix for loops

master
Dylan Baker 5 years ago
parent
commit
749c1d5350
2 changed files with 10 additions and 4 deletions
  1. 3
    1
      lib/ahem/ast/for_loop.rb
  2. 7
    3
      spec/ast/for_loop_spec.rb

+ 3
- 1
lib/ahem/ast/for_loop.rb View File

16
     @iterable.execute(env).each do |i|
16
     @iterable.execute(env).each do |i|
17
       _env = Environment.new
17
       _env = Environment.new
18
       _env.set(@iterator.name, i)
18
       _env.set(@iterator.name, i)
19
-      @block.execute(_env)
19
+      @block.statements.each do |statement|
20
+        statement.execute(_env)
21
+      end
20
     end
22
     end
21
   end
23
   end
22
 end
24
 end

+ 7
- 3
spec/ast/for_loop_spec.rb View File

10
             AST::Number.new(3.0),
10
             AST::Number.new(3.0),
11
           ]
11
           ]
12
         ),
12
         ),
13
-        AST::FunctionCall.new(
14
-          AST::Identifier.new('print'),
13
+        AST::Block.new(
15
           [
14
           [
16
-            AST::Identifier.new('x')
15
+            AST::FunctionCall.new(
16
+              AST::Identifier.new('print'),
17
+              [
18
+                AST::Identifier.new('x')
19
+              ]
20
+            )
17
           ]
21
           ]
18
         )
22
         )
19
       ).execute(Environment.new)
23
       ).execute(Environment.new)

Loading…
Cancel
Save