# HG changeset patch # User Paul Boddie # Date 1276727737 -7200 # Node ID 3d45965e06d03d386312b86c89ac33a8a46308c1 # Parent d44c000714fa8f3b6e61566829a567b2f9d5d003 Removed object usage in the builtins and permitted the absence of generated structures for various objects (especially those referenced and used by methods defined in the runtime library) in the generated program, all in order to minimise the amount of generated program code and data where various features are not actually used in a program. diff -r d44c000714fa -r 3d45965e06d0 lib/builtins.py --- a/lib/builtins.py Wed Jun 16 01:08:18 2010 +0200 +++ b/lib/builtins.py Thu Jun 17 00:35:37 2010 +0200 @@ -26,7 +26,11 @@ class basestring(object): def __init__(self, x=None): pass - def __getitem__(self, index): pass + + def __getitem__(self, index): + # Note usage. + IndexError + def __getslice__(self, start, end=None): pass def __iadd__(self, other): pass def __add__(self, other): pass @@ -61,7 +65,10 @@ class dict(object): def __init__(self, *args): pass def __setitem__(self, key, value): pass - def __getitem__(self, key): pass + + def __getitem__(self, key): + # Note usage. + KeyError class file(object): def write(self, s): pass @@ -160,7 +167,10 @@ # Reserve space for a fragment reference. self._elements = None - def __getitem__(self, index): pass + def __getitem__(self, index): + # Note usage. + IndexError + def __setitem__(self, index, value): pass def __getslice__(self, start, end=None): pass def __setslice__(self, start, end, slice): pass @@ -243,7 +253,11 @@ class tuple(object): def __init__(self, args): pass - def __getitem__(self, index): pass + + def __getitem__(self, index): + # Note usage. + IndexError + def __getslice__(self, start, end=None): pass def __len__(self): pass def __add__(self, other): pass @@ -474,9 +488,9 @@ AttributeError #StopIteration TypeError -IndexError +#IndexError -list +#list tuple #xrange #ellipsis diff -r d44c000714fa -r 3d45965e06d0 micropython/inspect.py --- a/micropython/inspect.py Wed Jun 16 01:08:18 2010 +0200 +++ b/micropython/inspect.py Thu Jun 17 00:35:37 2010 +0200 @@ -863,7 +863,9 @@ visitLeftShift = _visitBinary - visitList = OP + def visitList(self, node): + self.use_attribute("__builtins__", "list") + self.OP(node) def visitListComp(self, node): for qual in node.quals: @@ -932,7 +934,7 @@ visitRightShift = _visitBinary def visitSlice(self, node): - self.use_name("slice", node) + self.use_attribute("__builtins__", "slice") self.use_name("__getitem__", node) self.OP(node) diff -r d44c000714fa -r 3d45965e06d0 rsvp.py --- a/rsvp.py Wed Jun 16 01:08:18 2010 +0200 +++ b/rsvp.py Thu Jun 17 00:35:37 2010 +0200 @@ -141,7 +141,11 @@ self.breakpoints = set() def _get_class(self, module, name): - return self._objlist.access(module, name).get_value() + attr = self._objlist.access(module, name) + if attr is not None: + return attr.get_value() + else: + return None # Debugging methods. diff -r d44c000714fa -r 3d45965e06d0 rsvplib.py --- a/rsvplib.py Wed Jun 16 01:08:18 2010 +0200 +++ b/rsvplib.py Thu Jun 17 00:35:37 2010 +0200 @@ -43,14 +43,17 @@ self.int_class = cls.location self.int_instance = cls.instance_template_location cls = self.machine._get_class("__builtins__", "list") - self.list_class = cls.location - self.list_instance = cls.instance_template_location + if cls is not None: + self.list_class = cls.location + self.list_instance = cls.instance_template_location cls = self.machine._get_class("__builtins__", "IndexError") - self.index_error = cls.location - self.index_error_instance = cls.instance_template_location + if cls is not None: + self.index_error = cls.location + self.index_error_instance = cls.instance_template_location cls = self.machine._get_class("__builtins__", "basestring") - self.str_class = cls.location - self.str_instance = cls.instance_template_location + if cls is not None: + self.str_class = cls.location + self.str_instance = cls.instance_template_location self.tuple_class = self.machine.tuple_class self.type_error_instance = self.machine.type_error_instance