282 elif isinstance(child, ast.Import): |
282 elif isinstance(child, ast.Import): |
283 importName = child.names[0][0] |
283 importName = child.names[0][0] |
284 if importName == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter |
284 if importName == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter |
285 pass |
285 pass |
286 elif importName.endswith('.js'): |
286 elif importName.endswith('.js'): |
287 self.imported_js.add(importName) |
287 self.imported_js.add(importName) |
288 else: |
288 else: |
289 self.add_imported_module(strip_py(importName)) |
289 self.add_imported_module(strip_py(importName)) |
290 elif isinstance(child, ast.From): |
290 elif isinstance(child, ast.From): |
291 if child.modname == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter |
291 if child.modname == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter |
292 pass |
292 pass |
293 else: |
293 else: |
294 self.add_imported_module(child.modname) |
294 self.add_imported_module(child.modname) |
308 elif isinstance(child, ast.Subscript): |
308 elif isinstance(child, ast.Subscript): |
309 self._subscript_stmt(child, None) |
309 self._subscript_stmt(child, None) |
310 elif isinstance(child, ast.Global): |
310 elif isinstance(child, ast.Global): |
311 self._global(child, None) |
311 self._global(child, None) |
312 elif isinstance(child, ast.Printnl): |
312 elif isinstance(child, ast.Printnl): |
313 self._print(child, None) |
313 self._print(child, None) |
314 elif isinstance(child, ast.Print): |
314 elif isinstance(child, ast.Print): |
315 self._print(child, None) |
315 self._print(child, None) |
316 elif isinstance(child, ast.TryExcept): |
316 elif isinstance(child, ast.TryExcept): |
317 self._tryExcept(child, None) |
317 self._tryExcept(child, None) |
318 elif isinstance(child, ast.Raise): |
318 elif isinstance(child, ast.Raise): |
319 self._raise(child, None) |
319 self._raise(child, None) |
320 elif isinstance(child, ast.Stmt): |
320 elif isinstance(child, ast.Stmt): |
995 elif isinstance(node, ast.Pass): |
995 elif isinstance(node, ast.Pass): |
996 pass |
996 pass |
997 elif isinstance(node, ast.Function): |
997 elif isinstance(node, ast.Function): |
998 self._function(node, True) |
998 self._function(node, True) |
999 elif isinstance(node, ast.Printnl): |
999 elif isinstance(node, ast.Printnl): |
1000 self._print(node, current_klass) |
1000 self._print(node, current_klass) |
1001 elif isinstance(node, ast.Print): |
1001 elif isinstance(node, ast.Print): |
1002 self._print(node, current_klass) |
1002 self._print(node, current_klass) |
1003 elif isinstance(node, ast.TryExcept): |
1003 elif isinstance(node, ast.TryExcept): |
1004 self._tryExcept(node, current_klass) |
1004 self._tryExcept(node, current_klass) |
1005 elif isinstance(node, ast.Raise): |
1005 elif isinstance(node, ast.Raise): |
1006 self._raise(node, current_klass) |
1006 self._raise(node, current_klass) |
1007 else: |
1007 else: |
1064 if len(node.nodes) != 1: |
1064 if len(node.nodes) != 1: |
1065 tempvar = '__temp'+str(node.lineno) |
1065 tempvar = '__temp'+str(node.lineno) |
1066 tnode = ast.Assign([ast.AssName(tempvar, "OP_ASSIGN", node.lineno)], node.expr, node.lineno) |
1066 tnode = ast.Assign([ast.AssName(tempvar, "OP_ASSIGN", node.lineno)], node.expr, node.lineno) |
1067 self._assign(tnode, current_klass, top_level) |
1067 self._assign(tnode, current_klass, top_level) |
1068 for v in node.nodes: |
1068 for v in node.nodes: |
1069 tnode2 = ast.Assign([v], ast.Name(tempvar, node.lineno), node.lineno) |
1069 tnode2 = ast.Assign([v], ast.Name(tempvar, node.lineno), node.lineno) |
1070 self._assign(tnode2, current_klass, top_level) |
1070 self._assign(tnode2, current_klass, top_level) |
1071 return |
1071 return |
1072 |
1072 |
1073 local_var_names = None |
1073 local_var_names = None |
1074 if len(self.local_arg_stack) > 0: |
1074 if len(self.local_arg_stack) > 0: |
1075 local_var_names = self.local_arg_stack[-1] |
1075 local_var_names = self.local_arg_stack[-1] |
1175 |
1175 |
1176 if isinstance(node.expr, ast.CallFunc): |
1176 if isinstance(node.expr, ast.CallFunc): |
1177 debugStmt = self.debug and not self._isNativeFunc(node) |
1177 debugStmt = self.debug and not self._isNativeFunc(node) |
1178 if debugStmt and isinstance(node.expr.node, ast.Name) and \ |
1178 if debugStmt and isinstance(node.expr.node, ast.Name) and \ |
1179 node.expr.node.name == 'import_wait': |
1179 node.expr.node.name == 'import_wait': |
1180 debugStmt = False |
1180 debugStmt = False |
1181 if debugStmt: |
1181 if debugStmt: |
1182 st = self.get_line_trace(node) |
1182 st = self.get_line_trace(node) |
1183 print >>self.output, "sys.addstack('%s');\n" % st |
1183 print >>self.output, "sys.addstack('%s');\n" % st |
1184 if isinstance(node.expr.node, ast.Name) and node.expr.node.name == NATIVE_JS_FUNC_NAME: |
1184 if isinstance(node.expr.node, ast.Name) and node.expr.node.name == NATIVE_JS_FUNC_NAME: |
1185 if len(node.expr.args) != 1: |
1185 if len(node.expr.args) != 1: |
1381 def _mul(self, node, current_klass): |
1381 def _mul(self, node, current_klass): |
1382 return self.expr(node.left, current_klass) + " * " + self.expr(node.right, current_klass) |
1382 return self.expr(node.left, current_klass) + " * " + self.expr(node.right, current_klass) |
1383 |
1383 |
1384 def _mod(self, node, current_klass): |
1384 def _mod(self, node, current_klass): |
1385 if isinstance(node.left, ast.Const) and isinstance(node.left.value, StringType): |
1385 if isinstance(node.left, ast.Const) and isinstance(node.left.value, StringType): |
1386 self.imported_js.add("sprintf.js") # Include the sprintf functionality if it is used |
1386 self.imported_js.add("sprintf.js") # Include the sprintf functionality if it is used |
1387 return "sprintf("+self.expr(node.left, current_klass) + ", " + self.expr(node.right, current_klass)+")" |
1387 return "sprintf("+self.expr(node.left, current_klass) + ", " + self.expr(node.right, current_klass)+")" |
1388 return self.expr(node.left, current_klass) + " % " + self.expr(node.right, current_klass) |
1388 return self.expr(node.left, current_klass) + " % " + self.expr(node.right, current_klass) |
1389 |
1389 |
1390 def _invert(self, node, current_klass): |
1390 def _invert(self, node, current_klass): |
1391 return "~" + self.expr(node.expr, current_klass) |
1391 return "~" + self.expr(node.expr, current_klass) |
1392 |
1392 |
1736 print >> lib_code, '\n//\n// END LIB '+library+'\n//\n' |
1736 print >> lib_code, '\n//\n// END LIB '+library+'\n//\n' |
1737 if module_name: |
1737 if module_name: |
1738 print >> app_code, self._translate( |
1738 print >> app_code, self._translate( |
1739 module_name, is_app, debug=debug, imported_js=imported_js) |
1739 module_name, is_app, debug=debug, imported_js=imported_js) |
1740 for js in imported_js: |
1740 for js in imported_js: |
1741 path = self.findFile(js) |
1741 path = self.findFile(js) |
1742 if os.path.isfile(path): |
1742 if os.path.isfile(path): |
1743 if self.verbose: |
1743 if self.verbose: |
1744 print 'Including JS', js |
1744 print 'Including JS', js |
1745 print >> lib_code, '\n//\n// BEGIN JS '+js+'\n//\n' |
1745 print >> lib_code, '\n//\n// BEGIN JS '+js+'\n//\n' |
1746 print >> lib_code, file(path).read() |
1746 print >> lib_code, file(path).read() |
1747 print >> lib_code, '\n//\n// END JS '+js+'\n//\n' |
1747 print >> lib_code, '\n//\n// END JS '+js+'\n//\n' |
1748 else: |
1748 else: |
1749 print >>sys.stderr, 'Warning: Unable to find imported javascript:', js |
1749 print >>sys.stderr, 'Warning: Unable to find imported javascript:', js |
1750 return lib_code.getvalue(), app_code.getvalue() |
1750 return lib_code.getvalue(), app_code.getvalue() |
1751 |
1751 |
1752 |
1752 |
1753 usage = """ |
1753 usage = """ |
1754 usage: %s file_name [module_name] |
1754 usage: %s file_name [module_name] |