mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 02:43:40 +00:00
Estimated hours taken: 32
Branches: main
Another step towards RTTI in Mercury.
This step redefines the representation of type_ctor_infos inside the compiler
to be identical to the representation we will need for efficient interpretation
of RTTI data structures in Mercury, following on from an earlier step which
did the same for (pseudo)typeinfos.
Instead of the type_ctor_info being broken down into its components in
type_ctor_info.m, the breakdown process is now performed in rtti_out.m (for the
LLDS backend) and rtti_to_mlds.m (for the MLDS backend). Eventually, the IL and
Java backends will stop using rtti_to_mlds.m for this purpose, and will instead
write out the type_ctor_data structures as static data to be interpreted
directly.
We now predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20 for the LLDS C backend as well as for the
MLDS C backend. The LLDS backend can define them for higher arities
on demand; the MLDS backend (for now) still cannot.
runtime/mercury_type_info.h:
To be able to represent all the kinds of types we now support
- add a data structure for converting values of reserved_addr types
from their printable representation to their internal representation
(it was previously missing), and
- add a type_ctor_rep to represent foreign types.
Add missing MR_ prefixes on some field names.
Add typedefs for all the types that the rtti_names can refer to.
There were already such typedefs in runtime/mercury.h for the MLDS
grades, we now have them for the LLDS grades too.
Predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20. There were already such typedefs in
runtime/mercury.h for the MLDS grades, we now have them for the
LLDS grades too.
runtime/mercury.h:
Delete the typedefs that are now in mercury_type_info.h.
runtime/mercury.h:
Delete the definitions of the C types representing type_info and
pseudo_type_infos, since these are now in mercury_type_info.h.
#include mercury_type_info.h.
compiler/rtti.m:
Add new, purely Mercury data structures for representing
type_ctor_infos and their components, designed both for efficient
interpretation and as a source for the generation of static data
structures in C.
This entailed deleting most of the alternatives of the rtti_data type
while preserving their rtti_name equivalents; the deleted alternatives
represent tables are no longer created in type_ctor_info.m but which
are created dynamically in rtti_out.m and rtti_to_mlds.m (which need
a way for one table to refer to another).
Centralize the correspondence between rtti_names and the C and Java
types of the corresponding structures (the C and Java names differ in
prefixes only). Among other things, this remove the double maintenance
problem we have previously with the LLDS and MLDS backends maintaining
their own maps of the correspondence.
Add utility predicates on the new data structures for use by both
rtti_out.m and rtti_to_mlds.m.
compiler/hlds_module.m:
Always store the ids of unification and comparison procedures in
type_ctor_gen_infos, to simplify their handling.
compiler/type_ctor_info.m:
Generate the new data structures for representing type_ctor_infos.
Conform to the changed data structures for type_ctor_gen_infos.
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Rewrite substantial parts of these modules to convert the new data
structures for representing type_ctor_infos to sets of discrete
structures dynamically.
Most of the dynamically created structures are unique by construction,
but this is not true for typeinfos and pseudo-typeinfos. Therefore
add mechanisms to ensure that we don't generate redundant structures
representing typeinfos and pseudo-typeinfos.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
Use the standard mechanisms for creating C and Java type names.
compiler/mlds_to_gcc.m:
Conform to the changed data structures in rtti.m and
mercury_type_info.h.
compiler/opt_debug.m:
Conform to the changed data structures in rtti.m.
compiler/dead_proc_elim.m:
Conform to the changed data structures for type_ctor_gen_infos.
compiler/pseudo_type_info.m:
Add a predicate to construct a representation of a type that may or may
not be ground.
compiler/mlds_to_gcc.m:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
library/rtti_implemenation.m:
runtime/mercury_mcpp.{cpp,h}:
Add the type_ctor_rep for foreign types to the lists of type_ctor_reps.
library/construct.m:
library/deconstruct.m:
Add missing MR_ prefixes on field names.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
Handle the type_ctor_rep for foreign types.
Add missing MR_ prefixes on field names.
library/list.m:
Add two utility predicates, is_empty and is_not_empty, for use with
higher order code.
NEWS:
Mention the new predicates in list.m. Delete a duplicate entry.
174 lines
4.9 KiB
C++
174 lines
4.9 KiB
C++
//
|
|
// Copyright (C) 2000-2002 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_mcpp.cpp - This file defines the system runtime types and
|
|
// methods that are used when generating code for the .NET backend.
|
|
// It is written using Microsoft's Managed Extensions for C++ (usually
|
|
// called Managed C++ or MC++).
|
|
|
|
// vi: ts=4 sw=4 et tw=0 wm=0
|
|
|
|
#using <mscorlib.dll>
|
|
#using "mercury_il.dll"
|
|
|
|
// This line (somehow) stops the compiler from
|
|
// linking in the C library (and it will then complain about main being
|
|
// missing)
|
|
extern "C" int _fltused=0;
|
|
|
|
#include "mercury_mcpp.h"
|
|
|
|
namespace mercury {
|
|
|
|
namespace runtime {
|
|
|
|
__gc public class SystemException : public System::Exception
|
|
{
|
|
public:
|
|
SystemException(MR_String Msg) : System::Exception(Msg)
|
|
{
|
|
// the parent constructor sets the error message that
|
|
// will be printed.
|
|
}
|
|
};
|
|
|
|
|
|
__gc public class LowLevelData
|
|
{
|
|
|
|
public:
|
|
// Make a Mercury enumeration with the given integer value.
|
|
static MR_Word make_enum(int enum_value) {
|
|
|
|
MR_Word e;
|
|
MR_newenum(e, enum_value);
|
|
return e;
|
|
|
|
}
|
|
|
|
// Make an MR_Word with the given tag and arity.
|
|
static MR_Word make_MR_Word(int tag, int arity) {
|
|
MR_Word e;
|
|
MR_newobj(e, tag, arity);
|
|
return e;
|
|
|
|
}
|
|
// Set a field of an MR_Word with a given value.
|
|
// The first field is at index 1.
|
|
static void set_MR_Word_field(MR_Word w, int index, System::Object *value) {
|
|
MR_objset(w, index, value);
|
|
}
|
|
// Get the value from an MR_Word.
|
|
// The first field is at index 1.
|
|
static System::Object * get_MR_Word_field(MR_Word w, int index) {
|
|
return w[index];
|
|
}
|
|
|
|
static bool list_is_cons(MR_Word w) {
|
|
return (System::Convert::ToInt32(w[0]) != 0);
|
|
}
|
|
|
|
static MR_Box list_get_head(MR_Word w) {
|
|
return w[1];
|
|
}
|
|
|
|
static MR_Word list_get_tail(MR_Word w) {
|
|
return dynamic_cast<MR_Word>(w[2]);
|
|
}
|
|
|
|
};
|
|
|
|
__gc public class Errors {
|
|
public:
|
|
static void SORRY(MR_String s)
|
|
{
|
|
MR_String msg;
|
|
msg = System::String::Concat("Sorry, unimplemented: ", s);
|
|
throw new mercury::runtime::SystemException(msg);
|
|
}
|
|
|
|
static void fatal_error(MR_String s)
|
|
{
|
|
MR_String msg;
|
|
msg = System::String::Concat("Fatal error: ", s);
|
|
throw new mercury::runtime::SystemException(msg);
|
|
}
|
|
};
|
|
|
|
|
|
__gc public class Constants {
|
|
public:
|
|
|
|
// These constants are duplicated in library/private_builtin.m.
|
|
// They must be kept sychronized.
|
|
|
|
// XXX it would be nice if these could be const or an enum. But
|
|
// there are some problems with accessing the values from IL if we do
|
|
// that because neither alternatives seem to define field names we
|
|
// can reference from IL.
|
|
|
|
static int MR_TYPECTOR_REP_ENUM = MR_TYPECTOR_REP_ENUM_val;
|
|
static int MR_TYPECTOR_REP_ENUM_USEREQ = MR_TYPECTOR_REP_ENUM_USEREQ_val;
|
|
static int MR_TYPECTOR_REP_DU = MR_TYPECTOR_REP_DU_val;
|
|
static int MR_TYPECTOR_REP_DU_USEREQ = 3;
|
|
static int MR_TYPECTOR_REP_NOTAG = 4;
|
|
static int MR_TYPECTOR_REP_NOTAG_USEREQ = 5;
|
|
static int MR_TYPECTOR_REP_EQUIV = 6;
|
|
static int MR_TYPECTOR_REP_FUNC = 7;
|
|
static int MR_TYPECTOR_REP_INT = 8;
|
|
static int MR_TYPECTOR_REP_CHAR = 9;
|
|
static int MR_TYPECTOR_REP_FLOAT =10;
|
|
static int MR_TYPECTOR_REP_STRING =11;
|
|
static int MR_TYPECTOR_REP_PRED =12;
|
|
// MR_TYPECTOR_REP_UNIV is unused - it is retained
|
|
// only for backwards compatability.
|
|
static int MR_TYPECTOR_REP_UNIV =13;
|
|
static int MR_TYPECTOR_REP_VOID =14;
|
|
static int MR_TYPECTOR_REP_C_POINTER =15;
|
|
static int MR_TYPECTOR_REP_TYPEINFO =16;
|
|
static int MR_TYPECTOR_REP_TYPECLASSINFO =17;
|
|
static int MR_TYPECTOR_REP_ARRAY =18;
|
|
static int MR_TYPECTOR_REP_SUCCIP =19;
|
|
static int MR_TYPECTOR_REP_HP =20;
|
|
static int MR_TYPECTOR_REP_CURFR =21;
|
|
static int MR_TYPECTOR_REP_MAXFR =22;
|
|
static int MR_TYPECTOR_REP_REDOFR =23;
|
|
static int MR_TYPECTOR_REP_REDOIP =24;
|
|
static int MR_TYPECTOR_REP_TRAIL_PTR =25;
|
|
static int MR_TYPECTOR_REP_TICKET =26;
|
|
static int MR_TYPECTOR_REP_NOTAG_GROUND =27;
|
|
static int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ =28;
|
|
static int MR_TYPECTOR_REP_EQUIV_GROUND =29;
|
|
static int MR_TYPECTOR_REP_TUPLE =30;
|
|
static int MR_TYPECTOR_REP_RESERVED_ADDR =31;
|
|
static int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ =32;
|
|
static int MR_TYPECTOR_REP_TYPECTORINFO =33;
|
|
static int MR_TYPECTOR_REP_BASETYPECLASSINFO =34;
|
|
static int MR_TYPECTOR_REP_TYPEDESC =35;
|
|
static int MR_TYPECTOR_REP_TYPECTORDESC =36;
|
|
static int MR_TYPECTOR_REP_FOREIGN =37;
|
|
static int MR_TYPECTOR_REP_UNKNOWN =38;
|
|
|
|
static int MR_SECTAG_NONE = 0;
|
|
static int MR_SECTAG_LOCAL = 1;
|
|
static int MR_SECTAG_REMOTE = 2;
|
|
};
|
|
|
|
__gc public class Environment
|
|
{
|
|
public:
|
|
};
|
|
|
|
__gc public class Commit : public System::Exception
|
|
{
|
|
public:
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|