# HG changeset patch # User Paul Boddie # Date 1341939273 -7200 # Node ID 32adc6af1dc43c42e364932ceaa2d57d3a831a0d # Parent 82f8c2ada78ed2c9badfa0025d793594963c65b2 Changed true/false value usage, employing boolean values instead of numbers. diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/__init__.py --- a/micropython/__init__.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/__init__.py Tue Jul 10 18:54:33 2012 +0200 @@ -446,9 +446,9 @@ # Status information. - self.completed = 0 - self.vacuumed = 0 - self.finalised = 0 + self.completed = False + self.vacuumed = False + self.finalised = False def get_modules(self): @@ -472,7 +472,7 @@ self.get_module("__builtins__").complete() self.get_module("__main__").complete() - self.completed = 1 + self.completed = True # General maintenance. @@ -493,7 +493,7 @@ else: del self.modules[name] - self.vacuumed = 1 + self.vacuumed = True def finalise(self, objtable): @@ -512,7 +512,7 @@ for module in self.get_modules(): module.finalise(objtable) - self.finalised = 1 + self.finalised = True # Name accounting. @@ -1054,7 +1054,7 @@ if self.verbose: print >>sys.stderr, "Loaded", name self.loading.remove(module) - module.loaded = 1 + module.loaded = True # Record each module as imported by any importer. diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/ast.py --- a/micropython/ast.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/ast.py Tue Jul 10 18:54:33 2012 +0200 @@ -67,8 +67,8 @@ # Status flags. - self.in_exception_handler = 0 - self.in_assignment = 0 # for slicing and subscript + self.in_exception_handler = False + self.in_assignment = False # for slicing and subscript # Reset the assembler. @@ -512,12 +512,12 @@ self.record_value(self.has_immediate_usage(node.nodes)) - self.in_assignment = 1 + self.in_assignment = True for n in node.nodes: self.dispatch(n) - self.in_assignment = 0 + self.in_assignment = False self.discard_value() def visitAssAttr(self, node): @@ -729,7 +729,7 @@ self._endFor(node, temp_iterator, next_block, exit_block, else_block, node.else_) def visitIf(self, node): - first = 1 + first = True next_block = None exit_block = self.new_block() @@ -756,7 +756,7 @@ self.new_op(JumpIfFalse(next_block, working="status")) self.dispatch(body) - first = 0 + first = False if next_block is not None: self.set_block(next_block) @@ -863,9 +863,9 @@ # Produce the handler code, then jump to the exit. - self.in_exception_handler = 1 + self.in_exception_handler = True self.dispatch(handler) - self.in_exception_handler = 0 + self.in_exception_handler = False self.new_op(Jump(exit_block)) diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/code.py --- a/micropython/code.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/code.py Tue Jul 10 18:54:33 2012 +0200 @@ -248,8 +248,8 @@ for n in nodes: if not self.is_immediate_user(n): - return 0 - return 1 + return False + return True # Temporary storage administration. @@ -361,23 +361,23 @@ """ if not self.check_op(op): - return 0 + return False # Add the operation to the current block. self.optimiser.set_new("working", op) self.blocks[-1].append(op) - return 1 + return True def insert_op(self, i, op): "Insert at index 'i' in the current block the instruction 'op'." if not self.check_op(op): - return 0 + return False self.blocks[-1].insert(i, op) - return 1 + return True def check_op(self, op): @@ -387,14 +387,14 @@ # still available and was not recorded. if isinstance(op, LoadTemp) and op.attr is None: - return 0 + return False # Optimise load operations employed by this instruction. if self.optimiser.optimise_away_no_operations(op) or self.optimiser.optimise_unused_handlers(op): - return 0 + return False - return 1 + return True def remove_op(self): diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/data.py --- a/micropython/data.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/data.py Tue Jul 10 18:54:33 2012 +0200 @@ -73,7 +73,7 @@ self.namespace = {} self.globals = set() self.lambdas = {} # only really useful for functions - self.finalised = 0 + self.finalised = False # Attributes accessed on objects, potentially narrowing their types. # Specific namespaces should define known names during initialisation. @@ -138,9 +138,9 @@ def vacuum_item(self, name): if self.has_key(name): del self[name] - return 1 + return True else: - return 0 + return False def add_lambda(self, obj): attr = Attr(None, self, obj.name) @@ -319,9 +319,9 @@ if not self.namespace.has_key(name): self.globals.add(name) self.define_scope(name, "global") - return 1 + return True else: - return 0 + return False # Attribute positioning. @@ -347,13 +347,13 @@ for i, attr in enumerate(self.values()): attr.position = i - self.finalised = 1 + self.finalised = True def unfinalise_attributes(self): "Open attribute definitions to editing and subsequent finalisation." - self.finalised = 0 + self.finalised = False # Attribute usage methods. @@ -984,7 +984,7 @@ "A class providing dictionaries which retain no information." def has_key(self, name): - return 0 + return False def __setitem__(self, name, value): pass @@ -1143,14 +1143,14 @@ "Return whether this attribute defines more than one class." if self.assignments > 1: - have_class = 0 + have_class = False for obj in self.get_values(): if isinstance(obj, Class): if have_class: - return 1 - have_class = 1 - - return 0 + return True + have_class = True + + return False def defined_within_hierarchy(self): @@ -1174,14 +1174,14 @@ context.has_subclass(self.parent) or self.parent.has_subclass(context)) ): - return 0 - - return 1 + return False + + return True # Instance attributes are not defined within a hierarchy. else: - return 0 + return False def defined_outside_hierarchy(self): @@ -1205,14 +1205,14 @@ context.has_subclass(self.parent) or self.parent.has_subclass(context)) ): - return 0 - - return 1 + return False + + return True # Instance attributes are not defined within a hierarchy. else: - return 0 + return False def __repr__(self): if self.position is not None: @@ -1356,11 +1356,11 @@ # NOTE: Hack to prevent damage to exceptions. if name == "_pc": - return 0 + return False if not NamespaceDict.vacuum_item(self, name): self.instattr.remove(name) - return 1 + return True def finalise_attributes(self): @@ -1371,14 +1371,14 @@ self.finalise_class_attributes() self.finalise_instance_attributes() - self.finalised = 1 + self.finalised = True def unfinalise_attributes(self): "Open attribute definitions to editing and subsequent finalisation." self.reset_caches() - self.finalised = 0 + self.finalised = False # Convenience methods for accessing functions and methods. @@ -1685,10 +1685,10 @@ if name is None: self.name = "lambda#%d" % new_lambda() - self._is_lambda = 1 + self._is_lambda = True else: self.name = name - self._is_lambda = 0 + self._is_lambda = False self.parent = parent self.argnames = argnames @@ -1804,11 +1804,11 @@ if self.dynamic is None: for attr in self.default_attrs: if not attr.is_strict_constant() and self.dynamic_def: - self.dynamic = 1 + self.dynamic = True self._make_dynamic() break else: - self.dynamic = 0 + self.dynamic = False return self.dynamic @@ -1831,9 +1831,9 @@ if name not in self.argnames and not self.has_key(name): self.globals.add(name) - return 1 + return True else: - return 0 + return False def parameters(self): @@ -1899,8 +1899,8 @@ for cls in self.parent.descendants: if name in cls.relocated: - return 1 - return 0 + return True + return False # Administrative methods. @@ -1909,7 +1909,7 @@ def vacuum_item(self, name): del self.lambdas[name] - return 1 + return True def finalise_attributes(self): @@ -1949,7 +1949,7 @@ self.local_usage = nothers self.all_local_usage = nparams + nothers - self.finalised = 1 + self.finalised = True def _finalise_parameters(self): if not self.argnames: @@ -2174,22 +2174,22 @@ self.count = count def __eq__(self, other): - return 0 + return False __lt__ = __le__ = __eq__ def __ne__(self, other): - return 1 + return True def __gt__(self, other): if isinstance(other, AtLeast): - return 0 + return False else: return self.count > other def __ge__(self, other): if isinstance(other, AtLeast): - return 0 + return False else: return self.count >= other diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/graph.py --- a/micropython/graph.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/graph.py Tue Jul 10 18:54:33 2012 +0200 @@ -88,11 +88,11 @@ attr = objtable.access(objname, attrname) except TableError: #print >>sys.stderr, "%s.%s not found!" % (objname, attrname) - return 0 + return False for value in attr.get_values(): if isinstance(value, allowed_types): - return 1 - return 0 + return True + return False # vim: tabstop=4 expandtab shiftwidth=4 diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/inspect.py --- a/micropython/inspect.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/inspect.py Tue Jul 10 18:54:33 2012 +0200 @@ -111,19 +111,19 @@ self.optimisations = self.importer.optimisations self.builtins = self.importer.modules.get("__builtins__") - self.loaded = 0 - self.completed = 0 + self.loaded = False + self.completed = False # Current expression state. self.expr = None - self.in_assignment = 0 # For slice and subscript handling. + self.in_assignment = False # For slice and subscript handling. # Namespace state. - self.in_method = 0 # Find instance attributes in all methods. - self.in_function = 0 # Note function presence, affecting definitions. - self.in_loop = 0 # Note loop "membership", affecting assignments. + self.in_method = False # Find instance attributes in all methods. + self.in_function = False # Note function presence, affecting definitions. + self.in_loop = False # Note loop "membership", affecting assignments. self.namespaces = [] self.functions = [] @@ -139,7 +139,7 @@ def complete(self): if not self.completed: - self.completed = 1 + self.completed = True self.process() if self.importer.verbose: print >>sys.stderr, "Completed import of", self.full_name() @@ -794,19 +794,19 @@ # Previous namespace is the class. if self.in_class(namespaces): - self.in_method = 1 + self.in_method = True in_function = self.in_function in_loop = self.in_loop - self.in_function = 1 - self.in_loop = 0 + self.in_function = True + self.in_loop = False self.namespaces = namespaces self.dispatch(node.code) self.in_loop = in_loop self.in_function = in_function - self.in_method = 0 + self.in_method = False # Specific handler methods. @@ -818,10 +818,10 @@ def visitAssign(self, node): self.expr = self.dispatch(node.expr) - self.in_assignment = 1 + self.in_assignment = True for n in node.nodes: self.dispatch(n) - self.in_assignment = 0 + self.in_assignment = False def visitAssAttr(self, node): expr = self.dispatch(node.expr) @@ -1061,7 +1061,7 @@ self.use_name("StopIteration") in_loop = self.in_loop - self.in_loop = 1 + self.in_loop = True self.dispatch(node.list) # NOTE: Could generate AST nodes for the actual operations instead of @@ -1249,7 +1249,7 @@ self.use_name("next") in_loop = self.in_loop - self.in_loop = 1 + self.in_loop = True self.dispatch(node.list) # NOTE: Could generate AST nodes for the actual operations instead of @@ -1409,7 +1409,7 @@ # Propagate attribute usage to branches. in_loop = self.in_loop - self.in_loop = 1 + self.in_loop = True # The test is evaluated initially and again in the loop. diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/objectset.py --- a/micropython/objectset.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/objectset.py Tue Jul 10 18:54:33 2012 +0200 @@ -42,12 +42,12 @@ def __repr__(self): out = ["{"] - first = 1 + first = True for key, value in self.items(): if not first: out.append(", ") else: - first = 0 + first = False out.append(repr(key)) if value: out.append(" : ") diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/opt.py --- a/micropython/opt.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/opt.py Tue Jul 10 18:54:33 2012 +0200 @@ -365,7 +365,7 @@ """ if not (isinstance(unit, Function) and unit.is_method()): - return 0 + return False expr = self.get_active_value("working") return expr and isinstance(expr, LoadName) and expr.attr.name == "self" @@ -378,9 +378,9 @@ parent = unit.parent if parent is context or parent.has_subclass(context) or context.has_subclass(parent): - return 1 + return True - return 0 + return False def have_empty_handler(self, instruction): @@ -531,8 +531,8 @@ if self.should_optimise_unused_handlers() and self.have_empty_handler(instruction): self.translation.remove_op() - return 1 + return True else: - return 0 + return False # vim: tabstop=4 expandtab shiftwidth=4 diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/report.py --- a/micropython/report.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/report.py Tue Jul 10 18:54:33 2012 +0200 @@ -335,12 +335,12 @@ names.sort() self._names_list_start(label, classes) - first = 1 + first = True for name in names: if not first: self.stream.write("
") self.stream.write(name) - first = 0 + first = False self._names_list_end() def _attrcombined(self, name, node): @@ -350,7 +350,7 @@ if attrnames: break else: - return 0 + return False self._name_start() self.stream.write(name) @@ -359,7 +359,7 @@ self._attrnames(attrnames) self._popup_end() self._name_end() - return 1 + return True def _attrnames(self, attrnames): self._names_list(attrnames, "attributes", "attrnames") @@ -686,14 +686,14 @@ if bases and not (len(bases) == 1 and bases[0].name == "object"): self.stream.write("(") - first = 1 + first = True for base in bases: if not first: self.stream.write(", ") self._object_name_ref(base.module, base) - first = 0 + first = False self.stream.write(")") self.stream.write(":\n") @@ -755,7 +755,7 @@ self._keyword("from") self._module_link(node.modname) self._keyword("import", 1) - first = 1 + first = True for name, alias in node.names: if not first: self.stream.write(", ") @@ -763,7 +763,7 @@ if alias: self._keyword("as", 1) self._name(alias) - first = 0 + first = False self.stream.write("\n") def visitFunction(self, node): @@ -799,17 +799,17 @@ def visitGlobal(self, node): self.stream.write("
\n") self._keyword("global") - first = 1 + first = True for name in node.names: if not first: self.stream.write(", ") self.stream.write(name) - first = 0 + first = False self.stream.write("
\n") def visitIf(self, node): self.stream.write("
\n") - first = 1 + first = True for compare, stmt in node.tests: self.stream.write("
\n") if first: @@ -822,7 +822,7 @@ self.stream.write("
\n") self.dispatch(stmt) self.stream.write("
\n") - first = 0 + first = False if node.else_ is not None: self.stream.write("
\n") self._keyword("else", trailing=0) @@ -836,7 +836,7 @@ def visitImport(self, node): self.stream.write("
\n") self._keyword("import") - first = 1 + first = True for name, alias in node.names: if not first: self.stream.write(",\n") @@ -844,7 +844,7 @@ if alias: self._keyword("as", 1) self._name(alias) - first = 0 + first = False self.stream.write("
\n") def visitPass(self, node): @@ -870,14 +870,14 @@ if node.dest is not None: self.stream.write(">>\n") self.dispatch(node.dest) - first = 0 + first = False else: - first = 1 + first = True for n in node.nodes: if not first: self.stream.write(",\n") self.dispatch(n) - first = 0 + first = False self.stream.write("
\n") def visitRaise(self, node): @@ -985,12 +985,12 @@ def _visitBitBinary(self, node, symbol): name = operator_functions[node.__class__.__name__] self._span_start(name) - first = 1 + first = True for node in node.nodes: if not first: self._op(symbol, name, 1) self.dispatch(node) - first = 0 + first = False self._span_end() def _visitBinary(self, node, symbol): @@ -1015,12 +1015,12 @@ def visitAnd(self, node): self._span_start("and") - first = 1 + first = True for n in node.nodes: if not first: self._keyword("and", 1) self.dispatch(n) - first = 0 + first = False self._span_end() def visitAssAttr(self, node): @@ -1075,22 +1075,22 @@ self.dispatch(node.node) self._span_start("call") self.stream.write("(") - first = 1 + first = True for arg in node.args: if not first: self.stream.write(", ") self.dispatch(arg) - first = 0 + first = False if node.star_args is not None: if not first: self.stream.write(", *") self.dispatch(node.star_args) - first = 0 + first = False if node.dstar_args is not None: if not first: self.stream.write(", **") self.dispatch(node.dstar_args) - first = 0 + first = False self.stream.write(")") self._span_end() self._span_end() @@ -1277,12 +1277,12 @@ def visitOr(self, node): self._span_start("or") - first = 1 + first = True for n in node.nodes: if not first: self._keyword("or", 1) self.dispatch(n) - first = 0 + first = False self._span_end() def visitPower(self, node): @@ -1306,7 +1306,7 @@ def visitSliceobj(self, node): self._span_start("sliceobj") - first = 1 + first = True for n in node.nodes: if not first: self.stream.write(":") @@ -1320,12 +1320,12 @@ self._span_start("subscript") self.dispatch(node.expr) self.stream.write("[") - first = 1 + first = True for sub in node.subs: if not first: self.stream.write(", ") self.dispatch(sub) - first = 0 + first = False self.stream.write("]") self._span_end() @@ -1340,29 +1340,29 @@ # Output preparation methods. def _sequence(self, node): - first = 1 + first = True for n in node.nodes: if not first: self.stream.write(", ") self.dispatch(n) - first = 0 + first = False def _mapping(self, node): - first = 1 + first = True for k, v in node.items: if not first: self.stream.write(", ") self.dispatch(k) self.stream.write(" : ") self.dispatch(v) - first = 0 + first = False def _parameters(self, fn, node): nparams = len(fn.positional_names) ndefaults = len(fn.defaults) first_with_default = nparams - ndefaults - first = 1 + first = True for n, param in enumerate(fn.positional_names): if not first: self.stream.write(", ") @@ -1377,7 +1377,7 @@ n_default = n - first_with_default if n_default >= 0: self._default(fn.defaults[n_default]) - first = 0 + first = False if fn.has_star: if not first: @@ -1392,7 +1392,7 @@ def _tuple_parameter(self, parameters, node): self.stream.write("(") - first = 1 + first = True for param in parameters: if not first: self.stream.write(", ") @@ -1404,7 +1404,7 @@ else: self._assname(param, node) - first = 0 + first = False self.stream.write(")") diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/table.py --- a/micropython/table.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/table.py Tue Jul 10 18:54:33 2012 +0200 @@ -124,8 +124,8 @@ break element = self.displaced[i + offset] if attr is not None and element is not None: - return 0 - return 1 + return False + return True def _add_row(self, offset, attributes, len_displaced): @@ -312,10 +312,10 @@ possible = [] for objname, attributes in self.table.items(): - found = 1 + found = True for name in names: if not attributes.has_key(name): - found = 0 + found = False break if found: possible.append(objname) @@ -332,10 +332,10 @@ possible = [] for objname, attributes in self.table.items(): - found = 0 + found = False for name in names: if attributes.has_key(name): - found = 1 + found = True break if found: possible.append(objname) @@ -398,8 +398,8 @@ for objname in fn(names): attributes = self.table[objname] - is_static = 0 - is_instance = 0 + is_static = False + is_instance = False for name in names: if not attributes.has_key(name): @@ -409,14 +409,14 @@ if isinstance(attr, (Class, Module)): pass elif attr.is_static_attribute(): - is_static = 1 + is_static = True else: - is_instance = 1 + is_instance = True if is_static and not is_instance: - is_static = 1 + is_static = True else: - is_static = 0 + is_static = False possible.append((objname, is_static)) diff -r 82f8c2ada78e -r 32adc6af1dc4 micropython/trans.py --- a/micropython/trans.py Tue Jul 10 01:36:34 2012 +0200 +++ b/micropython/trans.py Tue Jul 10 18:54:33 2012 +0200 @@ -443,13 +443,13 @@ # Find keyword arguments in advance in order to help resolve targets. - have_keywords = 0 + have_keywords = False for arg in args: if isinstance(arg, compiler.ast.Keyword): employed_keywords.add(arg.name) keyword_args.append(arg) - have_keywords = 1 + have_keywords = True elif not have_keywords: positional_args.append(arg) @@ -461,7 +461,7 @@ if target is None or isinstance(context, Instance): ncontext = 1 - expect_testable_self = 0 + expect_testable_self = False # Handle calls to classes by obtaining the instantiator function. # A context is reserved for the new instance, but this is not provided @@ -470,25 +470,25 @@ elif isinstance(target, Class): ncontext = 1 - expect_testable_self = 0 + expect_testable_self = False target = target.get_instantiator() # Method calls via classes. elif isinstance(context, Class): ncontext = 0 - expect_testable_self = 1 + expect_testable_self = True # Function calls. else: ncontext = 0 - expect_testable_self = 0 + expect_testable_self = False # Traverse the positional arguments adding them using the incrementing # frame position. - first = 1 + first = True frame_pos = ncontext temp_first_argument = None @@ -511,7 +511,7 @@ temp_first_argument = self.optimiser.optimise_temp_storage() - first = 0 + first = False frame_pos += 1 # Adjust the invocation frame for unknown invocations.