Commit Graph

22 Commits

Author SHA1 Message Date
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Zoltan Somogyi
53b573692a Convert C code to use // style comments.
runtime/*.[ch]:
trace/*.[chyl]:
    As above. In some places, improve comments, e.g. by expanding contractions
    such as "we've". Add #ifndef guards against double inclusion around
    the trace/*.h files that did not already have them.

tools/*:
    Make the corresponding changes in shell scripts that generate .[ch] files
    in the runtime.

tests/*:
    Conform to a slight change in the text of a message.
2016-07-14 13:57:35 +02:00
Zoltan Somogyi
67326f16e4 Fix style issues in the runtime.
Move all .h and .c files to four-space indentation without tabs,
if they weren't there already.

Use the same vim line for all .h and .c files.

Align all backslashes at the ends of lines in macro definitions.
Align close comment signs.

In some places, fix inconsistent indentation.

Fix a bunch of comments. Add XXXs to a few of them.
2016-07-09 12:14:00 +02:00
Peter Wang
fcf6c7971e Rename MR_is_inf_func to MR_is_infinite_func as intended.
runtime/mercury_float.c:
	As above.
2014-09-19 17:36:45 +10:00
Julien Fischer
896d35933a Speed up is_finite/1 and is_nan/1 in C grades.
The Mercury runtime procedures MR_is_{inf,nan} are defined as functions, even
on systems (e.g. all those that support the relevant bits of C99), where the
underlying C stdlib uses macros to implement those operations.  Define the
above runtime procedures as macros speeds up an artificial test case (counting
infinities in a list of floats) by ~3.5%.

Change the name of MR_is_inf to MR_is_infinite.

runtime/mercury_float.h:
	Rename MR_is_inf to MR_is_infinite.

	Define MR_is_{infinite,nan} as macros on systems that support C99.
	This avoids some unnecessary function call overhead.

	Rename the function versions of MR_is_infinite and MR_is_nan to
	MR_is_infinite_func and MR_is_nan_func.

runtime/mercury_float.c:
library/float.m:
	Conform to the above changes.
2014-09-17 13:13:31 +10:00
Julien Fischer
4e15777451 Standardise formatting of float special values.
The string representation of float special values is currently dependent on the
target language and, for C grades, the underlying platform.  As a result,
values like NaN and Infinity are being printed or converted into strings in
variety of ways.  (See, for example bug #348 in Mantis.)

This diff changes float->string conversion to detect float special values and
use a consistent string representation for them.

library/string.m:
library/io.m:
runtime/mercury_float.c:
    Check if a float is not-a-number or of infinite magnitude when converting
    floats into strings.  If so, then use a standard representation of the
    value: "nan" for not-a-number values, and "infinity" / "-infinity" for
    values of infinite magnitude.
    For uppercase conversion specifiers in format strings, we output the above
    strings in uppercase (e.g. "NAN", "INFINITY").

library/float.m:
    Add is_infinite/1 and is_nan_or_infinite/1 as synonyms for is_inf/1 and
    is_nan_or_inf/1 respectively.

    Group float classification predicates into their own section.  Upcoming
    change will add more of them.

NEWS:
    Announce the above changes.

tests/general/string_format_special_floats.m:
tests/general/string_format_special_floats.exp:
    Modify this test to check that we actually print float special values as
    above.

tests/hard_coded/write_float_special.exp:
    Conform to the above change.

tests/EXPECT_FAIL_TESTS.all_grades:
    Do not expect the write_float_special test case to fail any more since
    the expected outputs should be the same on every platform.
2014-09-16 14:27:26 +10:00
Julien Fischer
af1a4771ab Fix the printing of float special values with write_float in C grades.
runtime/mercury_float.c:
	When printing floats, do not append ".0" to nan, inf or -inf.

tests/hard_coded/Mmakefile:
tests/hard_coded/write_float_special.{m,exp,exp2}:
	Add a regression test for the above.

NEWS:
	Announce the above.
2014-06-30 16:13:10 +10:00
Julien Fischer
e9d90b2891 Avoid warnings from clang in the runtime and util directories.
runtime/mercury_stack_trace.c:
	In the function MR_dump_stack_from_layout_clique initialise the variable
	lines_dumped_so_far.  (This appears to be an actual bug.)

runtime/mercury_prof.c:
	Only define the static global in_profiling_code if either of call count
	profiling or time profiling is enabled.

runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_profiling.c:
	Only define some local variables in grades that require them.

runtime/mercury_float.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_memory_zones.c:
runtime/mercury_stm.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Delete unused local variables.

util/mdemangle.c:
	Delete an unused static global variable.

	Use fputs in place of fprintf in a couple of places in order
	to avoid warnings about format strings that are not string literals.

	Delete an unused function.

util/mkinit.c:
util/mkinit_erl.c:
	Delete unused local variables.
2014-03-20 17:01:15 +11:00
Julien Fischer
c1f361e2fc Fix a typo.
runtime/mercury_float.c:
	s/_FPCLASS_INF/_FPCLASS_PINF/
2013-05-31 17:45:21 +10:00
Julien Fischer
63c8afdad7 Provide MSVC specific definitions for MS_is_nan and MR_is_inf.
runtime/mercury_float.c:
	As above.
2013-05-31 17:42:36 +10:00
Peter Wang
5c0082083c Work around `isinf' link error on Solaris.
On Solaris, `isinf' is detected by configure but we pass -fno-builtin
for global registers on x86/x86-64, and that causes an undefined
reference to `isinf' when linking.

configure.ac:
runtime/mercury_conf.h.in:
	Check for existence of `finite'.

runtime/mercury_conf_param.h:
	Define MR_SOLARIS if appropriate.

runtime/mercury_float.c:
	Don't use `isinf' or `isinff' on Solaris.

	Add a better `MR_is_inf' fallback using `finite'.
2013-05-29 16:44:01 +10:00
Ian MacLarty
067c703c56 Fix a bug in MR_sprintf_float where it would convert 1.8e-10
runtime/mercury_float.c:
    Fix a bug in MR_sprintf_float where it would convert 1.8e-10
    into "1.80000000000000e-1" instead of "1.8e-10".

    The problem was that it was stripping the zeros off the end of the string
    produced by sprintf without considering the case where the output
    was in scientific notation.

    The fix is to remove the `#' from the sprintf format string and then to
    append ".0" to the string if there is no "." or "e".

tests/general/float_roundtrip.m:
tests/general/float_roundtrip.exp:
    Add regression test.

tests/hard_coded/deep_copy.exp:
tests/hard_coded/expand.exp:
tests/hard_coded/float_reg.exp:
tests/hard_coded/write.exp:
tests/hard_coded/write_binary.exp:
tests/hard_coded/write_reg1.exp:
tests/hard_coded/write_xml.exp:
    Update the expected output of these tests as trailing zeros are now
    also removed from the base part of scientific notation float strings.
2010-07-16 07:19:12 +00:00
Ralph Becket
427c7518ec Improve the readability of float output from the debugger and io.print etc.
Estimated hours taken: 4
Branches: main

Improve the readability of float output from the debugger and io.print etc.
by pruning redundant trailing zeroes.

NEWS:
	Mention the change.

library/string.m:
runtime/mercury_float.c:
	Make string.float_to_string trim redundant trailing zeroes.
	The behaviour of string.format etc. is unchanged.

tests/debugger/ambiguity.exp:
tests/debugger/field_names.exp:
tests/debugger/higher_order.exp:
tests/debugger/print_table.exp:
tests/hard_coded/common_type_cast.exp:
tests/hard_coded/constant_prop_1.exp:
tests/hard_coded/construct_test.exp:
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deep_copy.exp:
tests/hard_coded/deep_copy_exist.exp:
tests/hard_coded/dense_lookup_switch2.exp:
tests/hard_coded/dense_lookup_switch_non.exp:
tests/hard_coded/existential_float.exp:
tests/hard_coded/expand.exp:
tests/hard_coded/final_excp.exp:
tests/hard_coded/float_field.exp:
tests/hard_coded/float_gv.exp:
tests/hard_coded/float_reg.exp:
tests/hard_coded/float_rounding_bug.exp:
tests/hard_coded/init_excp.exp:
tests/hard_coded/mutable_excp.exp:
tests/hard_coded/pragma_import.exp:
tests/hard_coded/prince_frameopt.exp:
tests/hard_coded/string_string.exp:
tests/hard_coded/unused_float_box_test.exp:
tests/hard_coded/write.exp:
tests/hard_coded/write_binary.exp:
tests/hard_coded/write_reg1.exp:
tests/hard_coded/write_xml.exp:
tests/hard_coded/sub-modules/non_word_mutable.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_class.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_1.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_2.exp:
tests/hard_coded/typeclasses/existential_rtti.exp:
tests/hard_coded/typeclasses/func_default_mode_bug.exp:
tests/hard_coded/typeclasses/mode_decl_order_bug.exp:
tests/hard_coded/typeclasses/module_test.exp:
tests/hard_coded/typeclasses/typeclass_exist_method.exp:
tests/invalid/error_in_list.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/purity/purity_type_error.err_exp:
tests/mmc_make/complex_test.exp:
tests/recompilation/add_type_re.exp.1:
tests/recompilation/type_spec_rename_var_r.exp.1:
tests/recompilation/type_spec_rename_var_r.exp.2:
tests/recompilation/type_spec_unname_var_r.exp.1:
tests/recompilation/type_spec_unname_var_r.exp.2:
	Updated expected test case output.
2007-02-15 00:41:59 +00:00
Zoltan Somogyi
c959a1657f Convert all remaining C source files to four-space indentation.
Estimated hours taken: 0.5
Branches: main

runtime/*.c:
	Convert all remaining C source files to four-space indentation.
	Fix some deviations from our style guide.
2006-11-14 00:15:41 +00:00
Simon Taylor
06a3af4bcf Fix a GCC warning: "declaration of `round' shadows global declaration".
Estimated hours taken: 0.1
Branches: main

runtime/mercury_float.c:
	Fix a GCC warning: "declaration of `round' shadows global declaration".
2002-12-02 08:39:46 +00:00
Peter Ross
ed71812550 Move implementation of is_nan and is_inf into the runtime.
Estimated hours taken: 0.5
Branches: main

Move implementation of is_nan and is_inf into the runtime.
This avoids problems with warnings about implicit declarations of
functions isnan and isinf when compiling with --ansi.

library/float.m:
runtime/mercury_float.c:
runtime/mercury_float.h:
	Move the bodies of is_nan and is_inf into the runtime.
2002-11-29 13:50:59 +00:00
Peter Ross
4e9e65503b Fix a bug where we weren't outputting floats to enough precision when
Estimated hours taken: 1
Branches: main

Fix a bug where we weren't outputting floats to enough precision when
deconstructing them.

runtime/mercury_ml_expand_body.h:
	Use MR_sprintf_float to determine the representation of the
	deconstructed float.

library/string.m:
library/io.m:
runtime/mercury_float.c:
runtime/mercury_float.h:
	Move ML_sprintf_float to mercury_float.h.

tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
	Adapt the test case to test floats which require 17 digits of
	precision.
2002-11-29 13:26:01 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +00:00
Tyson Dowd
db64a3588d Add MR_ prefixes to the types used when generating C code.
Estimated hours taken: 4

Add MR_ prefixes to the types used when generating C code.
This means types such as Word, String, Bool, Float become MR_Word,
MR_String, MR_Bool, MR_Float.  Also define MR_Box for both the LLDS and
MLDS backends so we can use it uniformly.

This is very important in environments where String or Bool have already
been used as system types (for example, managed C++).  And besides, we
should do it anyway as part of the grand namespace cleanup.

I have fixed all of the uses of the non-prefixed types in the runtime
and trace directories.  I haven't done it for the library and compiler
directories yet (no promises that I will do it in future either).  But
if you see a non-prefixed type in code from now on, please consider it a
bug and fix it.

mercury_bootstrap.h contains #defines to map the non-prefixed types into
the prefixed ones.  Like many of the other namespace cleaning backwards
compatibility macros, this can be turned off with
MR_NO_BACKWARDS_COMPAT.

This shouldn't break any code, but this kind of change affects so many
things that of course there could be problems lurking in there somewhere.

If you start getting errors from the C compiler after this change is
installed, you will want to make sure you at least have the runtime
system updated so that you are getting the backwards compatibility
definitions in mercury_bootstrap.h.  Then if you continue to have
problems you can bug me about it.

compiler/export.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
	Use MR_Word, MR_Float, MR_Bool, etc when generating C.

doc/reference_manual.texi:
	Update the reference manual to talk about MR_Word, MR_String,
	MR_Char, etc.

runtime/mercury_bootstrap.h:
	Add bootstrapping typedefs.

runtime/*:
trace/*:
	Change Word, Float, Bool, Code, String, etc to
	MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.
2000-08-03 06:19:31 +00:00
Tyson Dowd
bd19208eb9 Remove old .h files.
Estimated hours taken: 1

runtime/*.h:
runtime/*.c:
runtime/mercury_conf.h.in:
	Remove old .h files.
	Update #includes to refer to mercury_*.h
	Update #ifdef MODULE_H to be #ifdef MERCURY_MODULE_H
1997-11-23 07:21:53 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
David Overton
4bf71fa904 Add new predicate `float__hash' to the standard library for computing a
Estimated hours taken: 4

Add new predicate `float__hash' to the standard library for computing a
non-negative integer hash value for a float.

Add a C function to the runtime to do the actual hashing.  This
function is in the runtime so that it can be called from both
the library and from C code generated for `pragma fact_table'
indexing.

library/float.m
        Add a new predicate `float__hash' that calls the runtime
	function `hash_float()'.

runtime/mercury_float.h
	Add a declaration for `hash_float()'.

runtime/mercury_float.c
	Add new file mercury_float.c for runtime code related to
	floats.
	Add a new function `hash_float()' for hashing floats.
1997-02-28 05:25:52 +00:00