瀏覽代碼

Fix for loops

master
Dylan Baker 5 年之前
父節點
當前提交
749c1d5350
共有 2 個文件被更改,包括 10 次插入4 次删除
  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 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存