mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 04:43:53 +00:00
Estimated hours taken: 30 (including debugging) Add MR_TYPECTOR_REP_* to the type_ctor_info to describe the representation of this type. We want to do this because it allows us to check quickly to see what kind of data representation is being used. Previously this information was spread throughout the type_ctor_layout and type_ctor_functors data structures. It was complex to interpret and contained a lot of unnecessary duplication. We can now omit data structures such as the type_ctor_layout in many cases (it is only necessary for discriminated unions). Because we rule out some of the possible alternatives, the encodings used in the type_ctor_layout can be simplified. Also, the functors indicator in type_ctor_functors can be removed, as it subsumed by this data structure. Use this representation in code that uses RTTI. compiler/base_type_info.m: Add a missing alternative to the type_ctor_rep (this was a bug). library/array.m: library/builtin.m: library/private_builtin.m: runtime/mercury_bootstrap.c: Use MR_TYPECTOR_REP_* in the type_ctor_infos for builtin types. library/std_util.m: runtime/mercury_deep_copy_body.h: runtime/mercury_tabling.c: Use MR_TYPECTOR_REP_* and MR_DISCUNION_TAG_* to dispatch on data representations. Also, fix a bug in deep_copy when copying floating point values. I'm not sure when this stopped working, or if this is exactly the right fix, but it is more correct than the previous code. runtime/mercury_type_info.c: runtime/mercury_type_info.h: Update code to use MR_TYPECTOR_REP_*. Use a struct for type_ctor_info. tests/hard_coded/Mmakefile: tests/hard_coded/deep_copy.m: tests/hard_coded/deep_copy.exp: Add a test case for deep_copy.
109 lines
3.6 KiB
C
109 lines
3.6 KiB
C
/*
|
|
** Copyright (C) 1998-1999 The University of Melbourne.
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
/*
|
|
** mercury_bootstrap.c -
|
|
** Defintions that may be used for bootstrapping purposes.
|
|
**
|
|
** Because the runtime is linked as a library, symbols can be
|
|
** safely defined here -- if there is a duplicate symbol
|
|
** generated by the compiler, it will not link this module into
|
|
** the executable. If the symbol is not generated by the compiler,
|
|
** it will link with the definition in this file.
|
|
**
|
|
** Most of the time this file will be empty.
|
|
** It should not be used for more than one bootstrapping problem
|
|
** at a time.
|
|
*/
|
|
|
|
#include "mercury_imp.h"
|
|
|
|
MR_MODULE_STATIC_OR_EXTERN
|
|
const struct mercury_data_builtin__type_ctor_layout_c_pointer_0_struct_bootstrap {
|
|
TYPE_LAYOUT_FIELDS
|
|
} mercury_data_builtin__type_ctor_layout_c_pointer_0_bootstrap = {
|
|
make_typelayout_for_all_tags(TYPE_CTOR_LAYOUT_CONST_TAG,
|
|
mkbody(MR_TYPE_CTOR_LAYOUT_C_POINTER_VALUE))
|
|
};
|
|
|
|
MR_MODULE_STATIC_OR_EXTERN
|
|
const struct mercury_data_builtin__type_ctor_functors_c_pointer_0_struct_bootstrap {
|
|
Integer f1;
|
|
} mercury_data_builtin__type_ctor_functors_c_pointer_0_bootstrap = {
|
|
MR_TYPE_CTOR_FUNCTORS_SPECIAL
|
|
};
|
|
|
|
Declare_entry(mercury____Unify___builtin__c_pointer_0_0_bootstrap);
|
|
Declare_entry(mercury____Index___builtin__c_pointer_0_0_bootstrap);
|
|
Declare_entry(mercury____Compare___builtin__c_pointer_0_0_bootstrap);
|
|
|
|
const struct mercury_data_builtin__type_ctor_info_c_pointer_0_struct {
|
|
Integer f1;
|
|
Code * f2;
|
|
Code * f3;
|
|
Code * f4;
|
|
Integer f5;
|
|
Word * f6;
|
|
Word * f7;
|
|
Word * f8;
|
|
Word * f9;
|
|
} mercury_data_builtin__type_ctor_info_c_pointer_0 = {
|
|
(Integer) 0,
|
|
ENTRY(mercury____Unify___builtin__c_pointer_0_0_bootstrap),
|
|
ENTRY(mercury____Index___builtin__c_pointer_0_0_bootstrap),
|
|
ENTRY(mercury____Compare___builtin__c_pointer_0_0_bootstrap),
|
|
MR_TYPECTOR_REP_C_POINTER,
|
|
(Word *) &mercury_data_builtin__type_ctor_functors_c_pointer_0_bootstrap,
|
|
(Word *) &mercury_data_builtin__type_ctor_layout_c_pointer_0_bootstrap,
|
|
string_const("builtin", 7),
|
|
string_const("c_pointer", 9)
|
|
};
|
|
|
|
Define_extern_entry(mercury____Unify___builtin__c_pointer_0_0_bootstrap);
|
|
Define_extern_entry(mercury____Index___builtin__c_pointer_0_0_bootstrap);
|
|
Define_extern_entry(mercury____Compare___builtin__c_pointer_0_0_bootstrap);
|
|
|
|
BEGIN_MODULE(unify_c_pointer_module_bootstrap)
|
|
init_entry(mercury____Unify___builtin__c_pointer_0_0_bootstrap);
|
|
init_entry(mercury____Index___builtin__c_pointer_0_0_bootstrap);
|
|
init_entry(mercury____Compare___builtin__c_pointer_0_0_bootstrap);
|
|
|
|
BEGIN_CODE
|
|
Define_entry(mercury____Unify___builtin__c_pointer_0_0_bootstrap);
|
|
/*
|
|
** For c_pointer, we assume that equality and comparison
|
|
** can be based on object identity (i.e. using address comparisons).
|
|
** This is correct for types like io__stream, and necessary since
|
|
** the io__state contains a map(io__stream, filename).
|
|
** However, it might not be correct in general...
|
|
*/
|
|
r1 = (r1 == r2);
|
|
proceed();
|
|
|
|
Define_entry(mercury____Index___builtin__c_pointer_0_0_bootstrap);
|
|
r1 = -1;
|
|
proceed();
|
|
|
|
Define_entry(mercury____Compare___builtin__c_pointer_0_0_bootstrap);
|
|
r1 = (r1 == r2 ? COMPARE_EQUAL :
|
|
r1 < r2 ? COMPARE_LESS :
|
|
COMPARE_GREATER);
|
|
proceed();
|
|
|
|
END_MODULE
|
|
|
|
/* Ensure that the initialization code for the above module gets run. */
|
|
/*
|
|
INIT sys_init_unify_c_pointer_module_bootstrap
|
|
*/
|
|
|
|
extern ModuleFunc unify_c_pointer_module_bootstrap;
|
|
void sys_init_unify_c_pointer_module_bootstrap(void);
|
|
/* duplicate declaration to suppress gcc -Wmissing-decl warning */
|
|
void sys_init_unify_c_pointer_module_bootstrap(void) {
|
|
unify_c_pointer_module_bootstrap();
|
|
}
|