Skip to content
Permalink
Browse files

Fixed a bug with for loops over a send with a block

  • Loading branch information
Alex Gaynor
Alex Gaynor committed May 11, 2013
1 parent 3757697 commit b3cd7aeb3ee7eb3032da06d4ac479295dacc8456
Showing with 30 additions and 0 deletions.
  1. +20 −0 tests/test_compiler.py
  2. +10 −0 topaz/parser.py
@@ -277,6 +277,26 @@ def test_for_loop(self, space):
RETURN
""")

def test_for_loop_over_send_block(self, space):
self.assert_compiles(space, """
for k in f { 1 }
2
end
""", """
LOAD_SELF
LOAD_CONST 0
LOAD_CLOSURE 0
BUILD_BLOCK 1
SEND_BLOCK 1 1
LOAD_CONST 2
LOAD_CLOSURE 0
BUILD_BLOCK 1
SEND_BLOCK 3 1
RETURN
""")

def test_until(self, space):
self.assert_compiles(space, "until false do 5 end", """
SETUP_LOOP 20
@@ -12,6 +12,7 @@
class Parser(object):
def __init__(self, lexer):
self.lexer = lexer
self._hidden_scopes = []

def parse(self):
l = LexerWrapper(self.lexer.tokenize())
@@ -35,6 +36,13 @@ def save_and_pop_scope(self, node):
child_symtable.parent_symtable.add_subscope(node, child_symtable)
self.lexer.symtable = child_symtable.parent_symtable

def hide_scope(self):
self._hidden_scopes.append(self.lexer.symtable)
self.lexer.symtable = self.lexer.symtable.parent_symtable

def unhide_scope(self):
self.lexer.symtable = self._hidden_scopes.pop()

def new_token(self, orig, name, value):
return Token(name, value, orig.getsourcepos())

@@ -1677,10 +1685,12 @@ def for_prod(self, p):
@pg.production("post_for_in : ")
def post_for_in(self, p):
self.lexer.condition_state.begin()
self.hide_scope()

@pg.production("post_for_do : ")
def post_for_do(self, p):
self.lexer.condition_state.end()
self.unhide_scope()

@pg.production("primary : CLASS cpath superclass push_local_scope bodystmt END")
def primary_class(self, p):

0 comments on commit b3cd7ae

Please sign in to comment.