# HG changeset patch # User Paul Boddie # Date 1481042979 -3600 # Node ID fd3bcbdacf1855a76fc34e66bc65135a4b4c90b9 # Parent e31fddc66a6c4bd8e3dddec91760acd633ffd854 Removed instantiator definitions, employing the concrete symbols in the templates, adding an IOError-raising function and guarding it with a test for the presence of IOError in the generated program. diff -r e31fddc66a6c -r fd3bcbdacf18 generator.py --- a/generator.py Tue Dec 06 15:12:04 2016 +0100 +++ b/generator.py Tue Dec 06 17:49:39 2016 +0100 @@ -56,11 +56,7 @@ # NOTE: These must be synchronised with the library. function_type = "__builtins__.core.function" - memory_error_type = "__builtins__.core.MemoryError" - overflow_error_type = "__builtins__.core.OverflowError" - type_error_type = "__builtins__.core.TypeError" type_type = "__builtins__.core.type" - zero_division_error_type = "__builtins__.core.ZeroDivisionError" predefined_constant_members = ( ("__builtins__.boolean", "False"), @@ -360,10 +356,6 @@ #define __FUNCTION_TYPE %s #define __FUNCTION_INSTANCE_SIZE %s -#define __MEMORY_ERROR_INSTANTIATOR %s -#define __OVERFLOW_ERROR_INSTANTIATOR %s -#define __TYPE_ERROR_INSTANTIATOR %s -#define __ZERO_DIVISION_ERROR_INSTANTIATOR %s #define __TYPE_CLASS_TYPE %s #define __TYPE_CLASS_POS %s #define __TYPE_CLASS_CODE %s @@ -371,10 +363,6 @@ #endif /* __PROGTYPES_H__ */""" % ( encode_path(self.function_type), encode_size("", self.function_type), - encode_instantiator_pointer(self.memory_error_type), - encode_instantiator_pointer(self.overflow_error_type), - encode_instantiator_pointer(self.type_error_type), - encode_instantiator_pointer(self.zero_division_error_type), encode_path(self.type_type), encode_symbol("pos", encode_type_attribute(self.type_type)), encode_symbol("code", encode_type_attribute(self.type_type)), diff -r e31fddc66a6c -r fd3bcbdacf18 templates/progops.c --- a/templates/progops.c Tue Dec 06 15:12:04 2016 +0100 +++ b/templates/progops.c Tue Dec 06 17:49:39 2016 +0100 @@ -58,7 +58,6 @@ } #ifdef __HAVE___builtins___dict_dict - void __newdata_mapping(__attr args[], unsigned int number) { __attr dict = args[0]; @@ -76,36 +75,44 @@ __fn___builtins___dict_dict___init__(callargs); args[0] = dict; } - #endif /* __HAVE___builtins___dict_dict */ /* Helpers for raising errors within common operations. */ +#ifdef __HAVE___builtins___exception_io_IOError +void __raise_io_error() +{ + __attr args[1]; + __attr exc = __new___builtins___exception_io_IOError(args); + __Raise(exc); +} +#endif /* __HAVE___builtins___exception_io_IOError */ + void __raise_memory_error() { __attr args[1]; - __attr exc = __MEMORY_ERROR_INSTANTIATOR(args); + __attr exc = __new___builtins___core_MemoryError(args); __Raise(exc); } void __raise_overflow_error() { __attr args[1]; - __attr exc = __OVERFLOW_ERROR_INSTANTIATOR(args); + __attr exc = __new___builtins___core_OverflowError(args); __Raise(exc); } void __raise_type_error() { __attr args[1]; - __attr exc = __TYPE_ERROR_INSTANTIATOR(args); + __attr exc = __new___builtins___core_TypeError(args); __Raise(exc); } void __raise_zero_division_error() { __attr args[1]; - __attr exc = __ZERO_DIVISION_ERROR_INSTANTIATOR(args); + __attr exc = __new___builtins___core_ZeroDivisionError(args); __Raise(exc); } diff -r e31fddc66a6c -r fd3bcbdacf18 templates/progops.h --- a/templates/progops.h Tue Dec 06 15:12:04 2016 +0100 +++ b/templates/progops.h Tue Dec 06 17:49:39 2016 +0100 @@ -11,10 +11,16 @@ void __newdata_sequence(__attr args[], unsigned int number); +#ifdef __HAVE___builtins___dict_dict void __newdata_mapping(__attr args[], unsigned int number); +#endif /* __HAVE___builtins___dict_dict */ /* Exception raising. */ +#ifdef __HAVE___builtins___exception_io_IOError +void __raise_io_error(); +#endif /* __HAVE___builtins___exception_io_IOError */ + void __raise_memory_error(); void __raise_overflow_error(); void __raise_zero_division_error();