示例#1
0
文件: rewrites.py 项目: WuCPMark/TFJ
 def _Bind(self, stmt):
     var = stmt.binder()
     varNames = [x.id for x in flatten(var)]
     operation = S.substituted_expression(stmt.value(), self.env)
     for name in varNames:
         if self.freeze:
             if name in self.env:
                 rename = self.env[name]
             elif name not in self.exceptions:
                 rename = markGenerated('%s_%s' % (name, SingleAssignmentRewrite.serial.next()))
             else:
                 rename = name
         elif name not in self.exceptions:
             rename = markGenerated('%s_%s' % (name, SingleAssignmentRewrite.serial.next()))
         else:
             rename = name
        
         self.env[name] = S.Name(rename)
     result = S.Bind(S.substituted_expression(var, self.env), operation)
     return result
示例#2
0
def _indices(bind, typings, write_out):
    app = bind.value()
    if write_out:
        new_dest_id = C.markGenerated(bind.binder().id + '_'  + \
                                      intrinsic_name_supply.next())
        typings[new_dest_id] = T.Monotype("index_sequence")
        source = app.parameters[1]
        declaration = S.Bind(S.Name(new_dest_id),
                             S.Apply(S.Name("index_sequence"),
                                     [B.CMember(source, S.Apply(S.Name("size"),
                                                                []))]))
        declaration.no_return_convert = True
        copy = S.Apply(S.Name('copy'),
                       [bind.binder(),
                       S.Name(new_dest_id),
                       C.globalIndex])
        return declaration, copy
    
    typings[bind.binder().id] = T.Monotype("index_sequence")
    source = app.parameters[1]
    bind.parameters[0] = S.Apply(S.Name("index_sequence"),
                                 [B.CMember(source, S.Apply(S.Name("size"), []))])
    return bind