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,7 +16,9 @@ class AST::ForLoop
16 16
     @iterable.execute(env).each do |i|
17 17
       _env = Environment.new
18 18
       _env.set(@iterator.name, i)
19
-      @block.execute(_env)
19
+      @block.statements.each do |statement|
20
+        statement.execute(_env)
21
+      end
20 22
     end
21 23
   end
22 24
 end

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

@@ -10,10 +10,14 @@ RSpec.describe AST::ForLoop do
10 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 23
       ).execute(Environment.new)

Loading…
Cancel
Save