1.1 --- a/TO_DO.txt Mon Mar 21 01:27:27 2011 +0100
1.2 +++ b/TO_DO.txt Wed Mar 23 00:58:57 2011 +0100
1.3 @@ -99,6 +99,8 @@
1.4 Other
1.5 =====
1.6
1.7 +Support tuple as a function returning any input tuple uncopied.
1.8 +
1.9 Check context_value initialisation (avoiding or handling None effectively).
1.10
1.11 __getitem__ could be written in Python, using a native method only to access fragments.
2.1 --- a/lib/builtins.py Mon Mar 21 01:27:27 2011 +0100
2.2 +++ b/lib/builtins.py Wed Mar 23 00:58:57 2011 +0100
2.3 @@ -4,7 +4,7 @@
2.4 Simple built-in classes and functions. Objects which provide code that shall
2.5 always be compiled should provide docstrings.
2.6
2.7 -Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -279,6 +279,9 @@
2.13 pass
2.14
2.15 class tuple(object):
2.16 +
2.17 + #"Implementation of tuple."
2.18 +
2.19 def __init__(self, args): pass
2.20
2.21 def __getitem__(self, index):
2.22 @@ -291,7 +294,7 @@
2.23
2.24 "Return a slice starting from 'start', with the optional 'end'."
2.25
2.26 - return tuple(_getslice(self, start, end))
2.27 + return _tuple(_getslice(self, start, end))
2.28
2.29 def __len__(self): pass
2.30 def __add__(self, other): pass
2.31 @@ -612,6 +615,7 @@
2.32 def _isinstance(obj, cls): pass
2.33 def _print(dest, *args): pass
2.34 def _printnl(dest, *args): pass
2.35 +def _tuple(l): pass
2.36
2.37 # Reference some names to ensure their existence. This should be everything
2.38 # mentioned in a get_builtin or load_builtin call. Instances from this module
3.1 --- a/micropython/ast.py Mon Mar 21 01:27:27 2011 +0100
3.2 +++ b/micropython/ast.py Wed Mar 23 00:58:57 2011 +0100
3.3 @@ -171,6 +171,8 @@
3.4
3.5 "Return the code for the given class 'cls'."
3.6
3.7 + # Obtain the function object to be populated.
3.8 +
3.9 self.unit = cls.get_instantiator()
3.10 self.reset()
3.11
4.1 --- a/micropython/trans.py Mon Mar 21 01:27:27 2011 +0100
4.2 +++ b/micropython/trans.py Wed Mar 23 00:58:57 2011 +0100
4.3 @@ -1117,13 +1117,6 @@
4.4
4.5 self.set_block(fn.body_block)
4.6
4.7 - extend = ExtendFrame()
4.8 - self.new_op(extend)
4.9 -
4.10 - # Perform tuple assignment for any tuple parameters.
4.11 -
4.12 - self._visitFunctionTupleParameters(fn, node)
4.13 -
4.14 # For functions with star parameters, make a special list for the
4.15 # extra arguments and re-map the parameter.
4.16
4.17 @@ -1135,6 +1128,15 @@
4.18 self.new_op(CheckExtra(nparams))
4.19 self.new_op(StoreTemp(nparams))
4.20
4.21 + # Extend the frame for local usage.
4.22 +
4.23 + extend = ExtendFrame()
4.24 + self.new_op(extend)
4.25 +
4.26 + # Perform tuple assignment for any tuple parameters.
4.27 +
4.28 + self._visitFunctionTupleParameters(fn, node)
4.29 +
4.30 # Add any attribute usage guards.
4.31
4.32 self._generateGuards(node)
5.1 --- a/rsvplib.py Mon Mar 21 01:27:27 2011 +0100
5.2 +++ b/rsvplib.py Wed Mar 23 00:58:57 2011 +0100
5.3 @@ -30,6 +30,7 @@
5.4
5.5 instance_template_size = instance_data_offset = 1
5.6 instance_size = instance_template_size + 1
5.7 + fragment_data_offset = 1
5.8
5.9 def __init__(self, machine, constants):
5.10
5.11 @@ -60,6 +61,7 @@
5.12 self.str_instance = cls.instance_template_location
5.13
5.14 self.tuple_class = self.machine.tuple_class
5.15 + self.tuple_instance = self.machine.tuple_instance
5.16 self.type_error_instance = self.machine.type_error_instance
5.17
5.18 self.frame_stack = self.machine.frame_stack
5.19 @@ -262,7 +264,7 @@
5.20 # Make a new sequence.
5.21 # NOTE: Using an arbitrary size.
5.22
5.23 - new_fragment = self.machine._MakeFragment(1, 5) # include the header
5.24 + new_fragment = self.machine._MakeFragment(self.fragment_data_offset, 5) # include the header
5.25
5.26 # Complete the list instance by saving the fragment reference.
5.27 # NOTE: This requires an attribute in the list structure.
5.28 @@ -288,7 +290,7 @@
5.29 # Get the fragment header.
5.30
5.31 header = self.machine.load(fragment.ref)
5.32 - nelements = header.occupied_size - 1
5.33 + nelements = header.occupied_size - self.fragment_data_offset
5.34
5.35 # Get the item position.
5.36
5.37 @@ -300,7 +302,7 @@
5.38
5.39 # Get the item itself.
5.40
5.41 - self.machine.result = self.machine.load(fragment.ref + 1 + item_pos)
5.42 + self.machine.result = self.machine.load(fragment.ref + self.fragment_data_offset + item_pos)
5.43
5.44 def builtins_list_len(self):
5.45 frame = self.local_sp_stack[-1]
5.46 @@ -316,7 +318,7 @@
5.47 # Get the fragment header.
5.48
5.49 header = self.machine.load(fragment.ref)
5.50 - nelements = header.occupied_size - 1
5.51 + nelements = header.occupied_size - self.fragment_data_offset
5.52
5.53 # Make a new object.
5.54
5.55 @@ -365,7 +367,7 @@
5.56
5.57 # Copy existing elements.
5.58
5.59 - for i in range(1, header.occupied_size):
5.60 + for i in range(self.fragment_data_offset, header.occupied_size):
5.61 self.machine.save(new_fragment + i, self.machine.load(fragment.ref + i))
5.62
5.63 self.machine.save(new_fragment + header.occupied_size, arg_value)
5.64 @@ -375,6 +377,40 @@
5.65
5.66 self.machine.save(obj_value.ref + self.instance_data_offset, DataValue(None, new_fragment))
5.67
5.68 + def builtins_tuple(self):
5.69 + frame = self.local_sp_stack[-1]
5.70 +
5.71 + # Get the list address.
5.72 +
5.73 + obj_value = self.frame_stack[frame]
5.74 +
5.75 + if not self.machine._CheckInstance(obj_value.ref, self.list_class):
5.76 + self.machine.exception = self.machine._MakeObject(self.instance_size, self.type_error_instance)
5.77 + return self.machine.RaiseException()
5.78 +
5.79 + # Get the fragment address.
5.80 +
5.81 + fragment = self.machine.load(obj_value.ref + self.instance_data_offset)
5.82 +
5.83 + # Get the fragment header.
5.84 +
5.85 + header = self.machine.load(fragment.ref)
5.86 +
5.87 + # Make a new object.
5.88 +
5.89 + addr = self.machine._MakeObject(self.instance_data_offset + header.occupied_size - self.fragment_data_offset, self.tuple_instance)
5.90 +
5.91 + # Copy the fragment contents into the tuple.
5.92 + # NOTE: This might be done by repurposing the fragment in some situations.
5.93 +
5.94 + for i in range(self.fragment_data_offset, header.occupied_size):
5.95 + self.machine.save(addr + self.instance_data_offset + i - self.fragment_data_offset, self.machine.load(fragment.ref + i))
5.96 +
5.97 + # Return the new object.
5.98 + # Introduce object as context for the new object.
5.99 +
5.100 + self.machine.result = DataValue(addr, addr)
5.101 +
5.102 def builtins_tuple_len(self):
5.103 frame = self.local_sp_stack[-1]
5.104
5.105 @@ -501,6 +537,7 @@
5.106 "__builtins__._isinstance" : builtins_isinstance,
5.107 "__builtins__._print" : builtins_print,
5.108 "__builtins__._printnl" : builtins_printnl,
5.109 + "__builtins__._tuple" : builtins_tuple,
5.110 }
5.111
5.112 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/call_func_extra_known_with_locals.py Wed Mar 23 00:58:57 2011 +0100
6.3 @@ -0,0 +1,17 @@
6.4 +#!/usr/bin/env python
6.5 +
6.6 +def f(a, b, *c):
6.7 + d = 123 # introduce locals in the frame
6.8 + return c
6.9 +
6.10 +r1 = f(1, 2, 3)
6.11 +r2 = f(1, b=2)
6.12 +r3 = f(1, 2, 3, 4)
6.13 +
6.14 +result_0 = len(r2)
6.15 +result_1 = len(r1)
6.16 +result_2 = len(r3)
6.17 +result_3 = r1[0]
6.18 +result_4 = r3[1]
6.19 +
6.20 +# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tests/call_func_extra_unknown_with_locals.py Wed Mar 23 00:58:57 2011 +0100
7.3 @@ -0,0 +1,26 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +def f(a, b, *c):
7.7 + d = 123 # introduce locals in the frame
7.8 + return c
7.9 +
7.10 +g = f
7.11 +
7.12 +r4 = g(1, 2, 3)
7.13 +r5 = g(1, b=2)
7.14 +r6 = g(1, 2, 3, 4)
7.15 +
7.16 +def g(a, c, *b):
7.17 + d = 123 # introduce locals in the frame
7.18 + return b
7.19 +
7.20 +r7 = g(1, c=2)
7.21 +r8 = g(1, 2, 3, 4)
7.22 +
7.23 +result_0 = len(r5)
7.24 +result_1 = len(r4)
7.25 +result_2 = len(r6)
7.26 +result2_0 = len(r7)
7.27 +result2_2 = len(r8)
7.28 +
7.29 +# vim: tabstop=4 expandtab shiftwidth=4
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/tests/tuple_call.py Wed Mar 23 00:58:57 2011 +0100
8.3 @@ -0,0 +1,15 @@
8.4 +#!/usr/bin/env python
8.5 +
8.6 +a1 = tuple((1, 2, 3))
8.7 +a2 = tuple((1, 2, 3))
8.8 +b1 = tuple((1, tuple((2, 3)), 4, 5))
8.9 +
8.10 +result_1 = a1[0]
8.11 +result_2 = a2[1]
8.12 +result_3 = b1[1][1]
8.13 +result_4 = b1[2]
8.14 +resultL_2 = len(b1[1])
8.15 +resultL_3 = len(a1)
8.16 +resultL_4 = len(b1)
8.17 +
8.18 +# vim: tabstop=4 expandtab shiftwidth=4