mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-19 15:54:18 +00:00
Estimated hours taken: 20 Branches: main Add support for deconstructing by functor number rather than name, for use by write_binary. library/deconstruct.m: runtime/mercury_deconstruct.h: runtime/mercury_deconstruct.c: runtime/mercury_ml_expand_body.h: runtime/mercury_ml_deconstruct_body.h: Add predicates deconstruct.functor_number and deconstruct.deconstruct.du, which returns a functor number suitable for use by construct.construct rather than a functor name. library/construct.m: library/term.m: browser/term_rep.m: extras/quickcheck/qcheck.m: tests/valid/agc_unbound_typevars.m: tests/valid/agc_unbound_typevars2.m: Add a function get_functor_lex, which returns the lexicographic functor number given an ordinal functor number. Add equivalence types to make it clearer which ordering is being used by which functor numbers. Remove a C-ism: num_functors now fails rather than returning -1 for types without functors. NEWS: Document the new predicates and functions. runtime/mercury_type_info.h: runtime/mercury_builtin_types.c: runtime/mercury_mcpp.h: compiler/rtti.m: compiler/rtti_out.m: compiler/type_ctor_info.m: compiler/rtti_to_mlds.m: compiler/opt_debug.m: Add a field to MR_TypeCtorInfo which contains a mapping from an ordinal functor number to a lexicographic functor number which can be passed to construct.construct. Bump MR_RTTI_VERSION. tests/hard_coded/expand.m: tests/hard_coded/expand.exp: tests/hard_coded/expand.exp2: tests/hard_coded/construct_test.m: tests/hard_coded/construct_test.exp: tests/hard_coded/construct_test_exist.m: tests/hard_coded/construct_test_exist.exp: Test cases.
85 lines
3.7 KiB
C
85 lines
3.7 KiB
C
/*
|
|
** vim:ts=4 sw=4 expandtab
|
|
*/
|
|
/*
|
|
** Copyright (C) 2002-2004, 2007 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_deconstruct_macros.h
|
|
**
|
|
** This file defines macros for performing tasks that are useful when
|
|
** deconstructing terms,
|
|
*/
|
|
|
|
#ifndef MERCURY_DECONSTRUCT_MACROS_H
|
|
#define MERCURY_DECONSTRUCT_MACROS_H
|
|
|
|
/*
|
|
** Check for attempts to deconstruct a non-canonical type.
|
|
** Such deconstructions must be cc_multi, which is why we treat
|
|
** violations of this as runtime errors in det deconstruction
|
|
** predicates.
|
|
** (There ought to be cc_multi versions of those predicates.)
|
|
*/
|
|
#define MR_abort_if_type_is_noncanonical(ei, msg) \
|
|
do { \
|
|
if ((ei).non_canonical_type) { \
|
|
MR_fatal_error(msg); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define MR_noncanon_msg(predname) \
|
|
"called " predname " for non-canonical type"
|
|
|
|
#define MR_deconstruct_get_functor(ei, functor_field, var) \
|
|
do { \
|
|
MR_make_aligned_string(var, (ei).functor_field); \
|
|
} while (0)
|
|
|
|
#define MR_deconstruct_get_functor_number(ei, var) \
|
|
do { \
|
|
var = (ei).functor_number; \
|
|
} while (0)
|
|
|
|
#define MR_deconstruct_get_arity(ei, var) \
|
|
do { \
|
|
var = (ei).arity; \
|
|
} while (0)
|
|
|
|
#define MR_deconstruct_get_arg_list(ei, args_field, var) \
|
|
do { \
|
|
int i; \
|
|
\
|
|
var = MR_list_empty_msg(MR_PROC_LABEL); \
|
|
i = (ei).arity; \
|
|
\
|
|
while (--i >= 0) { \
|
|
MR_Word arg; \
|
|
\
|
|
/* Create an argument on the heap */ \
|
|
MR_new_univ_on_hp(arg, \
|
|
(ei).args_field.arg_type_infos[i], \
|
|
(ei).args_field.arg_values[i + \
|
|
(ei).args_field.num_extra_args]); \
|
|
\
|
|
/* Join the argument to the front of the list */ \
|
|
var = MR_univ_list_cons_msg(arg, var, MR_PROC_LABEL); \
|
|
} \
|
|
} while (0)
|
|
|
|
/*
|
|
** Free any arg_type_infos allocated by the MR_expand variant.
|
|
** Should be called after we have used them for the last time.
|
|
*/
|
|
#define MR_deconstruct_free_allocated_arg_type_infos(ei, args_field)\
|
|
do { \
|
|
if ((ei).args_field.can_free_arg_type_infos) { \
|
|
MR_GC_free((ei).args_field.arg_type_infos); \
|
|
} \
|
|
} while (0)
|
|
|
|
#endif /* MERCURY_DECONSTRUCT_MACROS_H */
|