Commits

Anonymous committed b2e3bd0

Issue 8: use Stmts nodes for for-loops. isop44++

Comments (0)

Files changed (2)

Grammar/Actions.nqp

 
     # XXX implement complex for syntax
 
-    # XXX right now this uses a Block rather than Stmts so that $iter's scope
-    # XXX is confined to this 'for'. Better to use Stmts and make $iter an anonymous register.
-    #my $past := PAST::Stmts.new( :node($/) );
-    my $past := PAST::Block.new( :blocktype('immediate'), :node($/) );
+    my $past := PAST::Stmts.new( :node($/) );
 
     # create iterator
     my $list := $( $<expression_list> );
-    my $iter := PAST::Var.new(     :name('iter'), :scope('register'), :node($/) );
-    my $iterdecl := PAST::Var.new( :name('iter'), :scope('register'), :node($/), :isdecl(1) );
-    $past.push( $iterdecl );
+    my $iter := PAST::Var.new( :scope('register'), :node($/) );
     $past.push( PAST::Op.new( $iter, $list,
                               :inline('    %0 = new "Iterator", %1'),
                               :node($/) ) );

Lib/test/parrot/control-flow.py

     i = 2
 if i == 2: print('failure: nested scopes')
 else: print('success: nested scopes')
+
+print('test: for var exists after loop')
+i = 0
+for i in [7,1,3]:
+    pass
+if i == 3: print('success: for var exists after loop')
+else: print('failure: for var exists after loop')