Changeset 2255 for proto


Ignore:
Timestamp:
Jul 11, 2012, 7:25:49 PM (7 years ago)
Author:
cameron
Message:

Support for nested whiles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r2221 r2255  
    449449    #CARRYSET
    450450    carry_arglist = [ast.Num(carry_base), ast.Num(carries)]
    451     new_test = ast.BoolOp(ast.Or(), [ifNode.test, mkCall('carryQ.CarryTest', carry_arglist)])
    452     new_else_part = ifNode.orelse + [mkCallStmt('carryQ.CarryDequeueEnqueue', carry_arglist)]
     451    new_test = ast.BoolOp(ast.Or(), [ifNode.test, mkCall(ast.Attribute(self.carryvar, 'CarryTest', ast.Load()), carry_arglist)])
     452    new_else_part = ifNode.orelse + [mkCallStmt(ast.Attribute(self.carryvar, 'CarryDequeueEnqueue', ast.Load()), carry_arglist)]
    453453    return ast.If(new_test, ifNode.body, new_else_part)
    454454  def visit_While(self, whileNode):
     
    461461    if carries == 0: return whileNode
    462462    carry_arglist = [ast.Num(carry_base), ast.Num(carries)]
    463     local_carryvar = 'subcarryQ'
     463    local_carryvar = 'sub' + self.carryvar.id
    464464    inner_while = CarryIntro(local_carryvar, '', self.carryout).generic_xfrm(copy.deepcopy(whileNode))
    465465    self.generic_visit(whileNode)
    466466    local_carry_decl = mkCallStmt('LocalCarryDeclare', [ast.Name(local_carryvar, ast.Load()), ast.Num(carries)])
    467467    inner_while.body.insert(0, local_carry_decl)
    468     final_combine = mkCallStmt('carryQ.CarryCombine', [ast.Attribute(ast.Name(local_carryvar, ast.Load()), 'cq', ast.Load()),ast.Num(carry_base), ast.Num(carries)])
     468    final_combine = mkCallStmt(ast.Attribute(self.carryvar, 'CarryCombine', ast.Load()), [ast.Attribute(ast.Name(local_carryvar, ast.Load()), 'cq', ast.Load()),ast.Num(carry_base), ast.Num(carries)])
    469469    inner_while.body.append(final_combine)
    470470    #CARRYSET
    471471    if self.carryin == '': new_test = whileNode.test
    472     else: new_test = ast.BoolOp(ast.Or(), [whileNode.test, mkCall('carryQ.CarryTest', carry_arglist)])
    473     else_part = [mkCallStmt('carryQ.CarryDequeueEnqueue', carry_arglist)]   
     472    else: new_test = ast.BoolOp(ast.Or(), [whileNode.test, mkCall(ast.Attribute(self.carryvar, 'CarryTest', ast.Load()), carry_arglist)])
     473    else_part = [mkCallStmt(ast.Attribute(self.carryvar, 'CarryDequeueEnqueue', ast.Load()), carry_arglist)]   
    474474    return ast.If(new_test, whileNode.body + [inner_while], else_part)
    475475
Note: See TracChangeset for help on using the changeset viewer.