List of all members.
Detailed Description
Definition at line 97 of file py2un.py.
Constructor & Destructor Documentation
| def py2un::Py2Un::__init__ |
( |
|
self | ) |
|
Definition at line 98 of file py2un.py.
00099 :
00100 self.ind = 0
00101 self.opnum = 0
00102 self.pretty = False
00103 self.tokens = []
00104 self.globalStack = []
self.overrideMode = None
Member Function Documentation
| def py2un::Py2Un::addGlobal |
( |
|
self, |
|
|
|
name |
|
) |
| |
Definition at line 154 of file py2un.py.
00155 :
00156 if len(self.globalStack) > 0:
00157 if not name in self.globalStack[-1]:
self.globalStack[-1].append(name)
| def py2un::Py2Un::buildNameList |
( |
|
self, |
|
|
|
node, |
|
|
|
lst |
|
) |
| |
Definition at line 557 of file py2un.py.
00558 :
00559 if type(node).__name__ == 'Tuple' or type(node).__name__ == 'List':
00560 for n in node.elts:
00561 self.buildNameList(n, lst)
00562 elif type(node).__name__ == 'Name':
00563 lst.append(node.id)
00564 else:
self.comment('Unhandled type in buildNameList: ' + type(node).__name__)
| def py2un::Py2Un::comment |
( |
|
self, |
|
|
|
text |
|
) |
| |
Definition at line 119 of file py2un.py.
00120 :
00121 if self.pretty:
self.tokens.append( '#' + text )
| def py2un::Py2Un::dedent |
( |
|
self, |
|
|
|
amt = 4 |
|
) |
| |
| def py2un::Py2Un::generic_visit |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 140 of file py2un.py.
00141 :
00142 self.output('Undef: ' + str(type(node)))
00143 self.indent()
00144 self.output('Fields: ' + str(node._fields))
00145 ast.NodeVisitor.generic_visit(self, node)
00146 self.dedent()
| def py2un::Py2Un::getTab |
( |
|
self, |
|
|
|
off = 0 |
|
) |
| |
Definition at line 134 of file py2un.py.
00135 :
return (self.ind + off) * ' '
| def py2un::Py2Un::indent |
( |
|
self, |
|
|
|
amt = 4 |
|
) |
| |
| def py2un::Py2Un::isGlobal |
( |
|
self, |
|
|
|
name |
|
) |
| |
Definition at line 158 of file py2un.py.
00159 :
00160 for l in self.globalStack:
00161 if name in l:
00162 return True
00163 return False
| def py2un::Py2Un::output |
( |
|
self, |
|
|
|
text |
|
) |
| |
Definition at line 122 of file py2un.py.
00123 :
00124 if self.pretty:
00125 self.tokens.append( self.getTab() + text )
00126 else:
00127 self.tokens.append( text )
self.opnum += 1
| def py2un::Py2Un::popGlobalScope |
( |
|
self | ) |
|
Definition at line 150 of file py2un.py.
00151 :
00152 if len(self.globalStack) > 0:
00153 self.comment('EndScope,' + str(len(self.globalStack)))
del self.globalStack[-1]
| def py2un::Py2Un::pushGlobalScope |
( |
|
self | ) |
|
Definition at line 147 of file py2un.py.
00148 :
00149 self.globalStack.append([])
self.comment('StartScope,' + str(len(self.globalStack)))
| def py2un::Py2Un::update |
( |
|
self, |
|
|
|
tokInd, |
|
|
|
txt |
|
) |
| |
Definition at line 128 of file py2un.py.
00129 :
00130 if tokInd < len(self.tokens) and tokInd >= 0:
00131 if self.pretty:
00132 self.tokens[tokInd] = self.getTab() + txt
00133 else:
self.tokens[tokInd] = txt
| def py2un::Py2Un::visit_Assign |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 206 of file py2un.py.
00207 :
00208 self.comment('Assign')
00209 self.indent()
00210 ast.NodeVisitor.visit(self,node.value)
00211 for n in node.targets:
00212 ast.NodeVisitor.visit(self,n)
00213 self.dedent()
| def py2un::Py2Un::visit_Attribute |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 452 of file py2un.py.
00453 :
00454 self.comment('Attribute')
00455 name = self.overrideMode or type(node.ctx).__name__
00456 self.comment(name)
00457 self.indent()
00458
00459
00460 ast.NodeVisitor.visit(self,node.value)
00461
00462 if name == 'Store':
00463 self.output('SETATTR,' + node.attr)
00464 elif name == 'Load':
00465 self.output('GETATTR,' + node.attr)
00466 elif name == 'Del':
00467 self.output('DELATTR,' + node.attr)
00468
00469 self.dedent()
| def py2un::Py2Un::visit_AugAssign |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 214 of file py2un.py.
00215 :
00216 self.comment('AugAssign')
00217 self.indent()
00218 prevOverride = self.overrideMode
00219 self.overrideMode = 'Load'
00220 ast.NodeVisitor.visit(self,node.target)
00221 self.overrideMode = prevOverride
00222 ast.NodeVisitor.visit(self,node.value)
00223 self.output('CMP,' + transOp(type(node.op).__name__))
00224 ast.NodeVisitor.visit(self,node.target)
00225 self.dedent()
| def py2un::Py2Un::visit_BinOp |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 361 of file py2un.py.
00362 :
00363 self.comment('BinOp')
00364 self.indent()
00365 ast.NodeVisitor.visit(self,node.left)
00366 ast.NodeVisitor.visit(self,node.right)
00367 self.output('CMP,' + transOp(type(node.op).__name__))
00368 self.dedent()
| def py2un::Py2Un::visit_BoolOp |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 335 of file py2un.py.
00336 :
00337 self.comment('BoolOp')
00338 self.indent()
00339
00340 op = transOp(type(node.op).__name__)
00341 if len(node.values) != 2:
00342 self.comment('BoolOp_with_' + str(len(node.values)) + '_values_not_anticipated')
00343 self.dedent()
00344 return
00345
00346 ast.NodeVisitor.visit(self,node.values[0])
00347
00348 self.output('')
00349
00350 plcHolder = len(self.tokens) - 1
00351 plcIndex = self.opnum
00352
00353 ast.NodeVisitor.visit(self,node.values[1])
00354
00355 if op == '&&':
00356 self.update(plcHolder, 'JMPF_OR_POP,' + str(self.opnum - plcIndex + 1))
00357 elif op == '||':
00358 self.update(plcHolder, 'JMPT_OR_POP,' + str(self.opnum - plcIndex + 1))
00359
00360 self.dedent()
| def py2un::Py2Un::visit_Call |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 420 of file py2un.py.
00421 :
00422 self.comment('Call')
00423 self.indent()
00424
00425 if type(node.func) is ast.Name:
00426 if node.func.id in builtins:
00427 self.output('FUNC,' + node.func.id)
00428 else:
00429 ast.NodeVisitor.visit(self,node.func)
00430 else:
00431 ast.NodeVisitor.visit(self,node.func)
00432 for n in node.args:
00433 ast.NodeVisitor.visit(self,n)
00434 self.output('CALL,' + str(len(node.args)))
00435 self.dedent()
| def py2un::Py2Un::visit_Compare |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 388 of file py2un.py.
00389 :
00390 self.comment('Compare')
00391 self.indent()
00392
00393 ast.NodeVisitor.visit(self,node.left)
00394
00395 replacements = []
00396 doComplex = len(node.ops) > 1
00397 if len(node.ops) > 0:
00398 for i in range(len(node.ops)):
00399 if i < len(node.comparators):
00400 if i > 0:
00401 self.output('')
00402 replacements.append((len(self.tokens) - 1, self.opnum ))
00403 ast.NodeVisitor.visit(self,node.comparators[i])
00404
00405 if doComplex and i + 1 < len(node.ops):
00406 self.output('DUP')
00407 self.output('ROT_3')
00408 self.output('CMP,' + transOp(type(node.ops[i]).__name__))
00409
00410 if doComplex and i + 1 == len(node.ops):
00411 self.output('JMP_REL,3')
00412 else:
00413 self.comment('More_ops_than_comparators!')
00414 for r in replacements:
00415 self.update(r[0], 'JMPF_OR_POP,' + str(self.opnum - r[1] + 1))
00416 if doComplex:
00417 self.output('ROT_2')
00418 self.output('POP')
00419 self.dedent()
| def py2un::Py2Un::visit_Delete |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 199 of file py2un.py.
00200 :
00201 self.comment('Delete')
00202 self.indent()
00203 for n in node.targets:
00204 ast.NodeVisitor.visit(self,n)
00205 self.dedent()
| def py2un::Py2Un::visit_Dict |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 376 of file py2un.py.
00377 :
00378 self.comment('Dict')
00379 self.indent()
00380 for n in node.keys:
00381 ast.NodeVisitor.visit(self,n)
00382 self.output('BUILDLIST,' + str(len(node.keys)))
00383 for n in node.values:
00384 ast.NodeVisitor.visit(self,n)
00385 self.output('BUILDLIST,' + str(len(node.values)))
00386 self.output('BUILDDICT,' + str(len(node.keys)))
00387 self.dedent()
| def py2un::Py2Un::visit_ExceptHandler |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 588 of file py2un.py.
00589 :
00590 self.comment('ExceptHandler')
00591 self.indent()
00592 opArgs = ''
00593 if node.type:
00594 if type(node.type).__name__ == 'Tuple':
00595 for e in node.type.elts:
00596 if type(e).__name__ == 'Name':
00597 opArgs += ',' + e.id
00598 else:
00599 self.comment('Unhandled exception type in tuple: ' + type(node.type).__name__)
00600 elif type(node.type).__name__ == 'Name':
00601 opArgs += ',' + node.type.id
00602 else:
00603 self.comment('Unhandled exception type: ' + type(node.type).__name__)
00604 self.output('')
00605
00606 plcHolder = len(self.tokens) - 1
00607 plcIndex = self.opnum
00608
00609 if node.name:
00610 self.output('GETEXC')
00611 if type(node.name).__name__ == 'Name':
00612 self.output('SETLOC,' + node.name.id)
00613 else:
00614 self.comment('Unhandled exception var name type: ' + type(node.name).__name__)
00615
00616 for n in node.body:
00617 ast.NodeVisitor.visit(self,n)
00618
00619 self.update(plcHolder, 'EXCEPT' + opArgs + ',' + str(self.opnum - plcIndex + 1))
00620 self.dedent()
| def py2un::Py2Un::visit_Expr |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 324 of file py2un.py.
00325 :
00326 self.comment('Expr')
00327 self.indent()
00328 ast.NodeVisitor.visit(self,node.value)
00329 self.output('POP')
00330 self.dedent()
| def py2un::Py2Un::visit_For |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 234 of file py2un.py.
00235 :
00236 self.comment('For')
00237 self.indent()
00238 ast.NodeVisitor.visit(self,node.iter)
00239 self.output('GET_ITER')
00240 self.output('WHILE')
00241 self.output('')
00242 plcHolder = len(self.tokens) - 1
00243 plcIndex = self.opnum
00244 ast.NodeVisitor.visit(self,node.target)
00245 self.indent()
00246 for n in node.body:
00247 ast.NodeVisitor.visit(self,n)
00248 self.dedent()
00249 self.output('END')
00250 self.update(plcHolder, 'FOR_ITER,' + str(self.opnum - plcIndex + 1))
00251 for n in node.orelse:
00252 ast.NodeVisitor.visit(self,n)
00253 self.dedent()
| def py2un::Py2Un::visit_FunctionDef |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 171 of file py2un.py.
00172 :
00173 self.comment('FunctionDef')
00174 self.indent()
00175
00176 for n in node.args.args:
00177 ast.NodeVisitor.visit(self,n)
00178 self.output('BUILDLIST,' + str(len(node.args.args)))
00179
00180 for n in node.args.defaults:
00181 ast.NodeVisitor.visit(self,n)
00182 self.output('BUILDLIST,' + str(len(node.args.defaults)))
00183 self.pushGlobalScope()
00184 self.output('DEFCODE,' + node.name)
00185 for n in node.body:
00186 ast.NodeVisitor.visit(self,n)
00187 self.output('BUILDCODE,' + node.name)
00188 self.popGlobalScope()
00189 self.output('SETLOC,' + node.name)
00190 self.dedent()
| def py2un::Py2Un::visit_Global |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 317 of file py2un.py.
00318 :
00319 self.comment('Global')
00320 self.indent()
00321 for n in node.names:
00322 self.addGlobal(n)
00323 self.dedent()
| def py2un::Py2Un::visit_If |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 269 of file py2un.py.
00270 :
00271 self.comment('If')
00272 self.indent()
00273 self.output('IF')
00274 ast.NodeVisitor.visit(self,node.test)
00275 self.output('TEST')
00276 for n in node.body:
00277 ast.NodeVisitor.visit(self,n)
00278 if node.orelse:
00279 self.output('ELSE')
00280 for n in node.orelse:
00281 ast.NodeVisitor.visit(self,n)
00282 self.output('END')
00283 self.dedent()
| def py2un::Py2Un::visit_Index |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 582 of file py2un.py.
00583 :
00584 self.comment('Index')
00585 self.indent()
00586 ast.NodeVisitor.visit(self,node.value)
00587 self.dedent()
| def py2un::Py2Un::visit_List |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 526 of file py2un.py.
00527 :
00528 self.comment('List')
00529 name = self.overrideMode or type(node.ctx).__name__
00530 self.indent()
00531 if name == 'Store':
00532 lst = []
00533 for n in node.elts:
00534 self.buildNameList(n, lst)
00535 self.output('SETLOC,' + ','.join(lst))
00536 else:
00537 for n in node.elts:
00538 ast.NodeVisitor.visit(self,n)
00539 self.output('BUILDLIST,' + str(len(node.elts)))
00540 self.dedent()
| def py2un::Py2Un::visit_Module |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 165 of file py2un.py.
00166 :
00167 self.pushGlobalScope()
00168 ast.NodeVisitor.generic_visit(self, node)
00169 self.popGlobalScope()
| def py2un::Py2Un::visit_Name |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 491 of file py2un.py.
00492 :
00493 self.comment('Name')
00494 name = self.overrideMode or type(node.ctx).__name__
00495 self.indent()
00496 glb = self.isGlobal(node.id)
00497 if name == 'Store':
00498 if glb:
00499 self.output('SETGLB,' + node.id)
00500 else:
00501 self.output('SETLOC,' + node.id)
00502 elif name == 'Load':
00503
00504 if node.id == 'True':
00505 self.output('PUSHB,True')
00506 elif node.id == 'False':
00507 self.output('PUSHB,False')
00508 elif node.id == 'None':
00509 self.output('PUSHN')
00510
00511 else:
00512 if glb:
00513 self.output('GETGLB,' + node.id)
00514 else:
00515 self.output('GETLOC,' + node.id)
00516 elif name == 'Del':
00517 if glb:
00518 self.output('DELGLB,' + node.id)
00519 else:
00520 self.output('DELLOC,' + node.id)
00521 elif name == 'Param':
00522 self.output('PUSHS,' + node.id)
00523 else:
00524 self.output('????,' + node.id)
00525 self.dedent()
| def py2un::Py2Un::visit_Num |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 436 of file py2un.py.
00437 :
00438 self.comment('Num')
00439 self.indent()
00440 if (type(node.n) == types.IntType):
00441 self.output('PUSHI,' + str(node.n))
00442 elif (type(node.n) == types.FloatType):
00443 self.output('PUSHF,' + str(node.n))
00444 self.dedent()
| def py2un::Py2Un::visit_Pass |
( |
|
self, |
|
|
|
none |
|
) |
| |
Definition at line 331 of file py2un.py.
00332 :
00333 self.comment('Pass')
| def py2un::Py2Un::visit_Print |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 226 of file py2un.py.
00227 :
00228 self.comment('Print')
00229 self.indent()
00230 for n in node.values:
00231 ast.NodeVisitor.visit(self,n)
00232 self.output('PRINT,' + str(len(node.values)))
00233 self.dedent()
| def py2un::Py2Un::visit_Return |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 191 of file py2un.py.
00192 :
00193 self.comment('Return')
00194 self.indent()
00195 if node.value:
00196 ast.NodeVisitor.visit(self,node.value)
00197 self.output('RETURN')
00198 self.dedent()
| def py2un::Py2Un::visit_Slice |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 566 of file py2un.py.
00567 :
00568 self.comment('Slice')
00569 self.indent()
00570 x = 0
00571 if node.lower:
00572 x |= 1
00573 ast.NodeVisitor.visit(self,node.lower)
00574 if node.upper:
00575 x |= 2
00576 ast.NodeVisitor.visit(self,node.upper)
00577 if node.step:
00578 x |= 4
00579 ast.NodeVisitor.visit(self,node.step)
00580 self.output('BUILDSLICE,' + str(x))
00581 self.dedent()
| def py2un::Py2Un::visit_Str |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 445 of file py2un.py.
00446 :
00447 self.comment('Str')
00448 self.indent()
00449 rep = node.s.replace(' ','\\_').replace(',','\\.')
00450 self.output('PUSHS,' + rep)
00451 self.dedent()
| def py2un::Py2Un::visit_Subscript |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 470 of file py2un.py.
00471 :
00472 self.comment('Subscript')
00473
00474 name = self.overrideMode or type(node.ctx).__name__
00475
00476 self.indent()
00477
00478 ast.NodeVisitor.visit(self,node.value)
00479 ast.NodeVisitor.visit(self,node.slice)
00480
00481 if name == 'Store':
00482 self.output('SETIND')
00483 elif name == 'Load':
00484 self.output('GETIND')
00485 elif name == 'Del':
00486 self.output('DELIND')
00487 else:
00488 self.output('????')
00489
00490 self.dedent()
| def py2un::Py2Un::visit_TryExcept |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 284 of file py2un.py.
00285 :
00286 self.comment('TryExcept')
00287 self.indent()
00288 self.output('TRY')
00289 plcHolder = len(self.tokens) - 1
00290 plcIndex = self.opnum
00291 for n in node.body:
00292 ast.NodeVisitor.visit(self,n)
00293 for n in node.handlers:
00294 ast.NodeVisitor.visit(self,n)
00295 if node.orelse:
00296 self.output('ELSE')
00297 for n in node.orelse:
00298 ast.NodeVisitor.visit(self,n)
00299 self.output('END')
00300 self.update(plcHolder, 'TRY,' + str(self.opnum - plcIndex + 1))
00301 self.dedent()
| def py2un::Py2Un::visit_TryFinally |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 302 of file py2un.py.
00303 :
00304 self.comment('TryFinally')
00305 self.indent()
00306 self.output('')
00307 plcHolder = len(self.tokens) - 1
00308 plcIndex = self.opnum
00309 for n in node.body:
00310 ast.NodeVisitor.visit(self,n)
00311 self.output('FINALLY')
00312 for n in node.finalbody:
00313 ast.NodeVisitor.visit(self,n)
00314 self.output('END')
00315 self.update(plcHolder, 'TRY,' + str(self.opnum - plcIndex + 1))
00316 self.dedent()
| def py2un::Py2Un::visit_Tuple |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 541 of file py2un.py.
00542 :
00543 self.comment('Tuple')
00544 name = self.overrideMode or type(node.ctx).__name__
00545 self.indent()
00546 if name == 'Store':
00547 lst = []
00548 for n in node.elts:
00549 self.buildNameList(n, lst)
00550 self.output('SETLOC,' + ','.join(lst))
00551
00552 else:
00553 for n in node.elts:
00554 ast.NodeVisitor.visit(self,n)
00555 self.output('BUILDTUPLE,' + str(len(node.elts)))
00556 self.dedent()
| def py2un::Py2Un::visit_UnaryOp |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 369 of file py2un.py.
00370 :
00371 self.comment('UnaryOp')
00372 self.indent()
00373 ast.NodeVisitor.visit(self,node.operand)
00374 self.output('UNARY,' + transOp(type(node.op).__name__))
00375 self.dedent()
| def py2un::Py2Un::visit_While |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 254 of file py2un.py.
00255 :
00256 self.comment('While')
00257 self.indent()
00258 self.output('WHILE')
00259 ast.NodeVisitor.visit(self.test)
00260 self.output('TEST')
00261 self.indent()
00262 for n in node.body:
00263 ast.NodeVisitor.visit(self,n)
00264 self.dedent()
00265 self.output('END')
00266 for n in node.orelse:
00267 ast.NodeVisitor.visit(self,n)
00268 self.dedent()
| def py2un::Py2Un::walk_tree |
( |
|
self, |
|
|
|
node, |
|
|
|
pretty |
|
) |
| |
Definition at line 105 of file py2un.py.
00106 :
00107 self.ind = 0
00108 self.opnum = 0
00109 self.pretty = pretty
00110 self.overrideMode = None
00111 self.visit(node)
00112 i = 0
00113 for t in self.tokens:
00114 if self.pretty:
00115 print str(i) + ' ' + t
00116 else:
00117 print t,
00118 i += 1
return ' '.join(self.tokens)
Member Data Documentation
The documentation for this class was generated from the following file: