mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 18:33:58 +00:00
Estimated hours taken: 250 Add support for tabling. This change allows for model_det, model_semidet and model_non memoing, minimal model and loop detection tabling. compiler/base_type_layout.m: Update comments to reflect new runtime naming standard. compiler/det_analysis.m: Allow tabling to change the result of det analysis. This is necessary in the case of minimal model tabling which can turn a det procedure into a semidet one. compiler/det_report.m: compiler/hlds_data.m: Add code to report error messages for various non compatible tabling methods and determinism. compiler/hlds_out.m: compiler/modules.m: Remove reference to the old memo marker. compiler/hlds_pred.m: Create new type (eval_method) to define which of the available evaluation methods should be used each procedure. Add new field to the proc_info structure. Add several new predicates relating to the new eval_method type. compiler/inlining.m: compiler/intermod.m: Make sure only procedures with normal evaluation are inlined. compiler/make_hlds.m: Add code to process new tabling pragmas. compiler/mercury_compile.m: Call the tabling transformation code. compiler/modes.m: Make sure that all procedures with non normal evaluation have no unique/partially instantiated modes. Produce error messages if they do. Support for partially instantiated modes is currently missing as it represents a large amount of work for a case that is currently not used. compiler/module_qual.m: compile/prog_data.m: compiler/prog_io_pragma.m: Add three new pragma types: `memo' `loop_check' `minimal_model' and code to support them. compiler/simplify.m: Don't report infinite recursion warning if a procedure has minimal model evaluation. compiler/stratify.m: Change the stratification analyser so that it reports cases of definite non-stratification. Rather than reporting warnings for any code that is not definitely stratified. Remove reference to the old memo marker. compiler/switch_detection.m: Fix a small bug where goal were being placed in reverse order. Call list__reverse on the list of goals. compiler/table_gen.m: New module to do the actual tabling transformation. compiler/notes/compiler_design.html: Document addition of new tabling pass to the compiler. doc/reference_manual.texi: Fix mistake in example. library/mercury_builtin.m: Add many new predicates for support of tabling. library/std_util.m: library/store.m: Move the functions : ML_compare_type_info ML_collapse_equivalences ML_create_type_info to the runtime. runtime/mercury_deep_copy.c: runtime/mercury_type_info.h: runtime/mercury_type_info.c: Move the make_type_info function into the mercury_type_info module and make it public. runtime/Mmakefile: runtime/mercury_imp.h: Add references to new files added for tabling support. runtime/mercury_string.h: Change hash macro so it does not cause a name clash with any variable called "hash". runtime/mercury_type_info.c: runtime/mercury_type_info.h: Add three new functions taken from the library : MR_compare_type_info MR_collapse_equivalences MR_create_type_info. runtime/mercury_table_any.c: runtime/mercury_table_any.h: runtime/mercury_table_enum.c: runtime/mercury_table_enum.h: runtime/mercury_table_int_float_string.c: runtime/mercury_table_int_float_string.h: runtime/mercury_table_type_info.c: runtime/mercury_table_type_info.h: runtime/mercury_tabling.h: New modules for the support of tabling.
145 lines
4.5 KiB
C
145 lines
4.5 KiB
C
/*
|
|
** Copyright (C) 1995-1998 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_string.h - string handling */
|
|
|
|
#ifndef MERCURY_STRING_H
|
|
#define MERCURY_STRING_H
|
|
|
|
#include <string.h> /* for strcmp() etc. */
|
|
|
|
#include "mercury_heap.h" /* for incr_hp_atomic */
|
|
|
|
/*
|
|
** Mercury characters are given type `Char', which is a typedef for `char'.
|
|
** But BEWARE: when stored in an Integer, the value must be
|
|
** first cast to `UnsignedChar'.
|
|
** Mercury strings are stored as pointers to '\0'-terminated arrays of Char.
|
|
**
|
|
** We may eventually move to using wchar_t for Mercury characters and strings,
|
|
** so it is important to use these typedefs.
|
|
**
|
|
** The actual typedefs are in mercury_types.h to avoid problems with
|
|
** circular #includes.
|
|
**
|
|
** typedef char Char;
|
|
** typedef unsigned char UnsignedChar;
|
|
**
|
|
** typedef Char *String;
|
|
** typedef const Char *ConstString;
|
|
*/
|
|
|
|
/*
|
|
** string_const("...", len):
|
|
** Given a C string literal and its length, returns a Mercury string.
|
|
*/
|
|
#define string_const(string, len) ((Word)string)
|
|
|
|
/*
|
|
** bool string_equal(ConstString s1, ConstString s2):
|
|
** Return true iff the two Mercury strings s1 and s2 are equal.
|
|
*/
|
|
#define string_equal(s1,s2) (strcmp((char*)(s1),(char*)(s2))==0)
|
|
|
|
/*
|
|
** void make_aligned_string(ConstString & ptr, const char * string):
|
|
** Given a C string `string', set `ptr' to be a Mercury string
|
|
** with the same contents. (`ptr' must be an lvalue.)
|
|
** If the resulting Mercury string is to be used by Mercury code,
|
|
** then the string pointed to by `string' should have been either
|
|
** statically allocated or allocated on the Mercury heap.
|
|
**
|
|
** BEWARE: this may modify `hp', so it must only be called from
|
|
** places where `hp' is valid. If calling it from inside a C function,
|
|
** rather than inside Mercury code, you may need to call
|
|
** save/restore_transient_regs().
|
|
**
|
|
** Algorithm: if the string is aligned, just set ptr equal to it.
|
|
** Otherwise, allocate space on the heap and copy the C string to
|
|
** the Mercury string.
|
|
*/
|
|
#define make_aligned_string(ptr, string) \
|
|
do { \
|
|
if (tag((Word) (string)) != 0) { \
|
|
make_aligned_string_copy((ptr), (string)); \
|
|
} else { \
|
|
(ptr) = (string); \
|
|
} \
|
|
} while(0)
|
|
|
|
/* void make_aligned_string_copy(ConstString &ptr, const char * string);
|
|
** Same as make_aligned_string(ptr, string), except that the string
|
|
** is guaranteed to be copied. This is useful for copying C strings
|
|
** onto the Mercury heap.
|
|
**
|
|
** BEWARE: this may modify `hp', so it must only be called from
|
|
** places where `hp' is valid. If calling it from inside a C function,
|
|
** rather than inside Mercury code, you may need to call
|
|
** save/restore_transient_regs().
|
|
*/
|
|
#define make_aligned_string_copy(ptr, string) \
|
|
do { \
|
|
Word make_aligned_string_tmp; \
|
|
char * make_aligned_string_ptr; \
|
|
\
|
|
incr_hp_atomic(make_aligned_string_tmp, \
|
|
(strlen(string) + sizeof(Word)) / sizeof(Word)); \
|
|
make_aligned_string_ptr = \
|
|
(char *) make_aligned_string_tmp; \
|
|
strcpy(make_aligned_string_ptr, (string)); \
|
|
(ptr) = make_aligned_string_ptr; \
|
|
} while(0)
|
|
|
|
/*
|
|
** do_hash_string(int & hash, Word string):
|
|
** Given a Mercury string `string', set `hash' to the hash value
|
|
** for that string. (`hash' must be an lvalue.)
|
|
**
|
|
** This is an implementation detail used to implement hash_string().
|
|
** It should not be used directly. Use hash_string() instead.
|
|
**
|
|
** Note that hash_string is also defined in library/string.m.
|
|
** The definition here and the definition in string.m
|
|
** must be kept equivalent.
|
|
*/
|
|
#define do_hash_string(hash, s) \
|
|
{ \
|
|
int len = 0; \
|
|
hash = 0; \
|
|
while(((const Char *)(s))[len]) { \
|
|
hash ^= (hash << 5); \
|
|
hash ^= ((const Char *)(s))[len]; \
|
|
len++; \
|
|
} \
|
|
hash ^= len; \
|
|
}
|
|
|
|
/*
|
|
** hash_string(s):
|
|
** Given a Mercury string `s', return a hash value for that string.
|
|
*/
|
|
int hash_string(Word);
|
|
|
|
#ifdef __GNUC__
|
|
#define hash_string(s) \
|
|
({ int hash_string_result; \
|
|
do_hash_string(hash_string_result, s); \
|
|
hash_string_result; \
|
|
})
|
|
#endif
|
|
|
|
/*
|
|
** If we're not using gcc, the actual definition of hash_string is in misc.c;
|
|
** it uses the macro HASH_STRING_FUNC_BODY below.
|
|
*/
|
|
|
|
#define HASH_STRING_FUNC_BODY \
|
|
int hash_string_result; \
|
|
do_hash_string(hash_string_result, s); \
|
|
return hash_string_result;
|
|
|
|
#endif /* not MERCURY_STRING_H */
|