1.1 --- a/lib/__builtins__/tuple.py Sat Mar 25 17:24:11 2017 +0100
1.2 +++ b/lib/__builtins__/tuple.py Sat Mar 25 17:58:39 2017 +0100
1.3 @@ -21,8 +21,8 @@
1.4
1.5 from __builtins__.iteration.iterator import itemiterator
1.6 from __builtins__.sequence import hashable, sequence
1.7 -from native import list_element, list_init, list_len, list_setsize, \
1.8 - list_setelement
1.9 +from native import tuple_init, \
1.10 + list_element, list_len, list_setsize, list_setelement
1.11
1.12 class tuple(sequence, hashable):
1.13
1.14 @@ -35,16 +35,19 @@
1.15 # Reserve an attribute for a fragment reference along with some space
1.16 # for elements.
1.17
1.18 - size = args is not None and len(args) or 0
1.19 - self.__data__ = list_init(size)
1.20 - list_setsize(self.__data__, size)
1.21 + self.__data__ = tuple_init(size)
1.22
1.23 - # Populate the tuple.
1.24 + if args is None:
1.25 + size = 0
1.26 + else:
1.27 + size = args.__len__()
1.28 + list_setsize(self.__data__, size)
1.29
1.30 - if args is not None:
1.31 + # Populate the tuple.
1.32 +
1.33 i = 0
1.34 - for arg in args:
1.35 - list_setelement(self.__data__, i, arg)
1.36 + while i < size:
1.37 + list_setelement(self.__data__, i, args[i])
1.38 i += 1
1.39
1.40 def __hash__(self):
2.1 --- a/lib/native/__init__.py Sat Mar 25 17:24:11 2017 +0100
2.2 +++ b/lib/native/__init__.py Sat Mar 25 17:58:39 2017 +0100
2.3 @@ -48,6 +48,8 @@
2.4
2.5 from native.system import exit, get_argv, get_path
2.6
2.7 +from native.tuple import tuple_init
2.8 +
2.9 from native.unicode import unicode_len, unicode_ord, unicode_substr, unicode_unichr
2.10
2.11 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/lib/native/tuple.py Sat Mar 25 17:58:39 2017 +0100
3.3 @@ -0,0 +1,29 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +Native library functions for tuples.
3.8 +
3.9 +None of these are actually defined here. Instead, native implementations are
3.10 +substituted when each program is built. It is, however, important to declare
3.11 +non-core exceptions used by the native functions because they need to be
3.12 +identified as being needed by the program.
3.13 +
3.14 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
3.15 +
3.16 +This program is free software; you can redistribute it and/or modify it under
3.17 +the terms of the GNU General Public License as published by the Free Software
3.18 +Foundation; either version 3 of the License, or (at your option) any later
3.19 +version.
3.20 +
3.21 +This program is distributed in the hope that it will be useful, but WITHOUT
3.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
3.24 +details.
3.25 +
3.26 +You should have received a copy of the GNU General Public License along with
3.27 +this program. If not, see <http://www.gnu.org/licenses/>.
3.28 +"""
3.29 +
3.30 +def tuple_init(size): pass
3.31 +
3.32 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/templates/native/tuple.c Sat Mar 25 17:58:39 2017 +0100
4.3 @@ -0,0 +1,46 @@
4.4 +/* Native functions for tuple operations.
4.5 +
4.6 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
4.7 +
4.8 +This program is free software; you can redistribute it and/or modify it under
4.9 +the terms of the GNU General Public License as published by the Free Software
4.10 +Foundation; either version 3 of the License, or (at your option) any later
4.11 +version.
4.12 +
4.13 +This program is distributed in the hope that it will be useful, but WITHOUT
4.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
4.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
4.16 +details.
4.17 +
4.18 +You should have received a copy of the GNU General Public License along with
4.19 +this program. If not, see <http://www.gnu.org/licenses/>.
4.20 +*/
4.21 +
4.22 +#include "native/common.h"
4.23 +#include "types.h"
4.24 +#include "exceptions.h"
4.25 +#include "ops.h"
4.26 +#include "progconsts.h"
4.27 +#include "progops.h"
4.28 +#include "progtypes.h"
4.29 +#include "main.h"
4.30 +
4.31 +/* Tuple operations. */
4.32 +
4.33 +static __fragment __empty_fragment = {.size=0, .capacity=0};
4.34 +
4.35 +__attr __fn_native_tuple_tuple_init(__attr __self, __attr size)
4.36 +{
4.37 + /* size interpreted as int */
4.38 + unsigned int n = __TOINT(size);
4.39 +
4.40 + /* Return the __data__ attribute. */
4.41 + if (n) return (__attr) {.seqvalue=__new_fragment(n)};
4.42 + else return (__attr) {.seqvalue=&__empty_fragment};
4.43 +}
4.44 +
4.45 +/* Module initialisation. */
4.46 +
4.47 +void __main_native_tuple()
4.48 +{
4.49 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/templates/native/tuple.h Sat Mar 25 17:58:39 2017 +0100
5.3 @@ -0,0 +1,32 @@
5.4 +/* Native functions for tuple operations.
5.5 +
5.6 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
5.7 +
5.8 +This program is free software; you can redistribute it and/or modify it under
5.9 +the terms of the GNU General Public License as published by the Free Software
5.10 +Foundation; either version 3 of the License, or (at your option) any later
5.11 +version.
5.12 +
5.13 +This program is distributed in the hope that it will be useful, but WITHOUT
5.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
5.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
5.16 +details.
5.17 +
5.18 +You should have received a copy of the GNU General Public License along with
5.19 +this program. If not, see <http://www.gnu.org/licenses/>.
5.20 +*/
5.21 +
5.22 +#ifndef __NATIVE_TUPLE_H__
5.23 +#define __NATIVE_TUPLE_H__
5.24 +
5.25 +#include "types.h"
5.26 +
5.27 +/* List operations. */
5.28 +
5.29 +__attr __fn_native_tuple_tuple_init(__attr __self, __attr size);
5.30 +
5.31 +/* Module initialisation. */
5.32 +
5.33 +void __main_native_tuple();
5.34 +
5.35 +#endif /* __NATIVE_TUPLE_H__ */