1.1 --- a/generator.py Thu Nov 24 22:43:29 2016 +0100
1.2 +++ b/generator.py Thu Nov 24 23:42:19 2016 +0100
1.3 @@ -52,6 +52,7 @@
1.4 "A code generator."
1.5
1.6 function_type = "__builtins__.core.function"
1.7 + type_error_type = "__builtins__.core.TypeError"
1.8
1.9 # NOTE: These must be synchronised with the library.
1.10
1.11 @@ -348,10 +349,12 @@
1.12
1.13 #define __FUNCTION_TYPE %s
1.14 #define __FUNCTION_INSTANCE_SIZE %s
1.15 +#define __TYPE_ERROR_INSTANTIATOR %s
1.16
1.17 #endif /* __PROGTYPES_H__ */""" % (
1.18 encode_path(self.function_type),
1.19 - encode_size("<instance>", self.function_type)
1.20 + encode_size("<instance>", self.function_type),
1.21 + encode_instantiator_pointer(self.type_error_type)
1.22 )
1.23
1.24 print >>f_signatures, """\
2.1 --- a/lib/__builtins__/__init__.py Thu Nov 24 22:43:29 2016 +0100
2.2 +++ b/lib/__builtins__/__init__.py Thu Nov 24 23:42:19 2016 +0100
2.3 @@ -20,7 +20,8 @@
2.4 """
2.5
2.6 from __builtins__.core import function, get_using, object, type, \
2.7 - BaseException, Exception, Warning
2.8 + BaseException, Exception, TypeError, \
2.9 + UnboundMethodInvocation, Warning
2.10
2.11 # Exceptions.
2.12
2.13 @@ -58,7 +59,6 @@
2.14 SystemError,
2.15 SystemExit,
2.16 TabError,
2.17 - TypeError,
2.18 UnboundLocalError,
2.19 UnicodeDecodeError,
2.20 UnicodeEncodeError,
3.1 --- a/lib/__builtins__/core.py Thu Nov 24 22:43:29 2016 +0100
3.2 +++ b/lib/__builtins__/core.py Thu Nov 24 23:42:19 2016 +0100
3.3 @@ -87,8 +87,14 @@
3.4
3.5 __repr__ = __str__
3.6
3.7 -class BaseException(object): pass
3.8 +class BaseException:
3.9 +
3.10 + "The root of all exception types."
3.11 +
3.12 + pass
3.13 +
3.14 class Exception(BaseException): pass
3.15 +class TypeError(Exception): pass
3.16 class UnboundMethodInvocation(Exception): pass
3.17 class Warning(object): pass
3.18
4.1 --- a/lib/__builtins__/exception/__init__.py Thu Nov 24 22:43:29 2016 +0100
4.2 +++ b/lib/__builtins__/exception/__init__.py Thu Nov 24 23:42:19 2016 +0100
4.3 @@ -32,7 +32,6 @@
4.4 ReferenceError,
4.5 StandardError,
4.6 StopIteration,
4.7 - TypeError,
4.8 ValueError
4.9 )
4.10
5.1 --- a/lib/__builtins__/exception/base.py Thu Nov 24 22:43:29 2016 +0100
5.2 +++ b/lib/__builtins__/exception/base.py Thu Nov 24 23:42:19 2016 +0100
5.3 @@ -3,7 +3,7 @@
5.4 """
5.5 Base exception objects.
5.6
5.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
5.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
5.9
5.10 This program is free software; you can redistribute it and/or modify it under
5.11 the terms of the GNU General Public License as published by the Free Software
5.12 @@ -27,7 +27,6 @@
5.13 class ReferenceError(Exception): pass
5.14 class StandardError(Exception): pass
5.15 class StopIteration(Exception): pass
5.16 -class TypeError(Exception): pass
5.17 class ValueError(Exception): pass
5.18
5.19 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/templates/ops.c Thu Nov 24 22:43:29 2016 +0100
6.2 +++ b/templates/ops.c Thu Nov 24 23:42:19 2016 +0100
6.3 @@ -82,6 +82,14 @@
6.4
6.5 /* Attribute testing and retrieval operations. */
6.6
6.7 +static __attr __check_and_load_via_object_null(__ref obj, int pos, int code)
6.8 +{
6.9 + if (__HASATTR(obj, pos, code))
6.10 + return __load_via_object(obj, pos);
6.11 + else
6.12 + return __NULL;
6.13 +}
6.14 +
6.15 __attr __check_and_load_via_class(__ref obj, int pos, int code)
6.16 {
6.17 return __check_and_load_via_object(__get_class(obj), pos, code);
6.18 @@ -89,12 +97,16 @@
6.19
6.20 __attr __check_and_load_via_object(__ref obj, int pos, int code)
6.21 {
6.22 - return __HASATTR(obj, pos, code) ? __load_via_object(obj, pos) : __NULL;
6.23 + if (__HASATTR(obj, pos, code))
6.24 + return __load_via_object(obj, pos);
6.25 +
6.26 + __raise_type_error();
6.27 + return __NULL;
6.28 }
6.29
6.30 __attr __check_and_load_via_any(__ref obj, int pos, int code)
6.31 {
6.32 - __attr out = __check_and_load_via_object(obj, pos, code);
6.33 + __attr out = __check_and_load_via_object_null(obj, pos, code);
6.34 if (out.value == 0)
6.35 out = __check_and_load_via_class(obj, pos, code);
6.36 return out;
6.37 @@ -132,8 +144,7 @@
6.38 if (!__is_instance(context) && __test_common_type(context, __TYPEPOS(attr.context), __TYPECODE(attr.context)))
6.39 return __update_context(context, attr);
6.40
6.41 - /* NOTE: An error may be more appropriate. */
6.42 -
6.43 + __raise_type_error();
6.44 return __NULL;
6.45 }
6.46
7.1 --- a/templates/progops.c Thu Nov 24 22:43:29 2016 +0100
7.2 +++ b/templates/progops.c Thu Nov 24 23:42:19 2016 +0100
7.3 @@ -42,6 +42,15 @@
7.4 return attr;
7.5 }
7.6
7.7 +/* A helper for raising type errors within common operations. */
7.8 +
7.9 +void __raise_type_error()
7.10 +{
7.11 + __attr args[1];
7.12 + __attr exc = __TYPE_ERROR_INSTANTIATOR(args);
7.13 + __Raise(exc);
7.14 +}
7.15 +
7.16 /* Generic invocation operations. */
7.17
7.18 /* Invoke the given callable, supplying keyword argument details in the given