Commit Graph

124 Commits

Author SHA1 Message Date
Julien Fischer
a83ba5ee79 Modernise the header comment in the float module.
library/float.m:
     Remove out-of-date references to ANSI C, POSIX, C9X (C99), and
     platform-specific behaviour on Linux, Digital Unix and Solaris.

     All current Mercury backends use (and are _required_ to use) IEEE floating
     point; delete conditional language about this.

     Do not specify halting with runtime error as a resolution for NaNs or
     signed zeros; instead just say we should throw an exception.

     Generalise the discussion of excess precision.
     (XXX ideally we could get rid of this by telling C compilers not to
     use extended-precision FP registers on those system that provide
     them; most of them do that by default anyway, but I'm not sure if
     all of them do.)
2026-03-14 17:09:55 +11:00
Julien Fischer
0b92543c5e Fix more library documentation errors.
library/*.m:
   As above.
2026-01-23 19:53:58 +11:00
Zoltan Somogyi
3f72528869 Update module stability levels. 2025-08-11 22:32:52 +02:00
Zoltan Somogyi
34e64a623b Replace "iff" with "if-and-only-if" in the library. 2025-06-08 10:33:56 +10:00
Peter Wang
d7099e830a Remove MR_INT_LEAST64_LENGTH_MODIFIER.
We had configure choose the format string length modifier for
MR_int_least64_t based on whether the type is an alias for "int",
"long", "long long" or "__int64". That does not work for some versions
of MinGW-w64, which warn about the "ll" length modifier even though
MR_int_least64_t is an alias for "long long". The reason is that
we would be calling the MSVC runtime *printf functions,
which require the "I64" length modifier instead of "ll".

The only place MR_INT_LEAST64_LENGTH_MODIFIER is used in the Mercury
system is in the hidden function float64_bits_string (which is also
no longer used by the Mercury compiler after the removal of the hl
grades). We can replace that use with PRIdLEAST64 from inttypes.h.

Users are unlikely to be using MR_INT_LEAST64_LENGTH_MODIFIER,
so it should be safe to remove it.

configure.ac:
runtime/mercury_conf.h.in:
    Don't define MR_INT_LEAST64_LENGTH_MODIFIER.

library/float.m:
    Replace use of MR_INT_LEAST64_LENGTH_MODIFIER with PRIdLEAST64
    in float64_bits_string.

    Mark all float32_bits_string and float64_bits_string foreign procs
    as 'may_not_export_body'. There is no need to opt-export procedures
    that will rarely be used, if ever.

runtime/mercury_types.h:
    Update comment.
2023-12-20 15:32:02 +11:00
Zoltan Somogyi
5cbcfaa0ed Move X_to_doc functions to pretty_printer.m.
library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/list.m:
library/one_or_more.m:
library/string.m:
library/tree234.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
library/version_array.m:
    Mark the X_to_doc function in each of these modules as obsolete,
    and make it a forwarding function to the actual implementation
    in pretty_printer.m. The intention is that when these forwarding
    functions are eventually removed, this will also remove the dependency
    of these modules on pretty_printer.m. This should help at least some
    of these modules escape the giant SCC in the library's dependency graph.
    (It does not make sense that a library module that adds code to increment
    an int thereby becomes dependent on pretty_printer.m through int.m.)

library/pretty_printer.m:
    Move all the X_to_doc functions from the above modules here.

    Fix the one_or_more_to_doc function, which was

    - missing the comma between the two arguments of the one_or_more
      function symbol, and

    - would print "..., ...]" instead of just "...]" at the end of the
      tail list when that list exceeded the limits of the specified pp_params.

    Rename one of the moved types along with its function symbols,
    to reduce ambiguity.

    Put arrays before their indexes in the argument lists of some of
    the moved functions.

    Some of the moved X_to_doc functions for compound types returned
    a doc that had an indent wrapper. These indents differed between the
    various X_to_doc functions without any visible reason, but they are
    also redundant. The callers can trivially add such wrappers if they
    want to, but taking them off, if they want them off, is harder.
    Eliminate the problem by deleting all such indent wrappers.

    Add formatters for the intN, uintN and one_or_more types to the
    default formatter map. Their previous absence was an oversight.

    Add a function, get_formatter_map_entry_types, that returns the ids
    of the types in the formatter_map given to the function. It is intended
    for tests/hard_coded/test_pretty_printer_defaults.m, but is exported
    for anyone to use.

tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
    Use get_formatter_map_entry_types to print the default formatter map
    in a format that is much more easily readable.

NEWS:
    Announce all the user-visible changes above.
2022-12-27 18:27:52 +11:00
Julien Fischer
c5fc6144ba Delete an old workaround for MSVC.
library/float.m:
    We no longer require an MSVC specific workaround because Microsoft's
    sprintf() implementation does not support the lld conversion specifier.
    (It has been supported since 2013.)

README.MS-VisualC:
    Document that the oldest version of MSVC that can be used to build Mercury
    is MSVC 12 (2013).
2022-10-18 01:54:36 +11:00
Peter Wang
a4d9a6faa1 Fix compilation warning with 32-bit MinGW.
I got this warning when cross-compiling for Windows/x86 with
i686-w64-mingw32-gcc version 11.1.0:

    format '%d' expects argument of type 'int', but argument 3 has type 'MR_int_least64_t'

library/float.m:
    Use MR_INT_LEAST64_LENGTH_MODIFIER in float64_bits_string
    except when compiling with MSVC.
2022-10-06 16:53:59 +11:00
Julien Fischer
e7d28ff90f Update copyright notices in stdlib.
library/*.m:
    As above.
2022-06-07 21:51:03 +10:00
Zoltan Somogyi
51ba7f936f Use consistent attributes on C#/Java foreign_procs. 2022-03-17 13:53:26 +11:00
Zoltan Somogyi
06f81f1cf0 Add end_module declarations ...
.. to modules which did not yet have them.
2022-01-09 10:36:15 +11:00
Zoltan Somogyi
0d7c8a7654 Specify pred or func for all pragmas.
*/*.m:
    As above.

configure.ac:
    Require the installed compiler to support this capability.
2021-06-16 15:23:58 +10:00
Julien Fischer
c9fd469059 Avoid a warning from recent Java compilers.
library/float.m
    The constructor Double(double) is deprecated; use valueOf()
    instead.
2021-05-23 13:46:08 +10:00
Peter Wang
0d3fcbaae3 Delete Erlang code from library/mdbcomp/browser directories.
library/*.m:
    Delete Erlang foreign code and foreign types.

    Delete documentation specific to Erlang targets.

library/deconstruct.m:
    Add pragma no_determinism_warning to allow functor_number_cc/3
    to compile for now.

library/Mercury.options:
    Delete workaround only needed when targetting Erlang.

browser/listing.m:
mdbcomp/rtti_access.m:
    Delete Erlang foreign code and foreign types.
2020-10-28 14:10:56 +11:00
Zoltan Somogyi
85f20002c5 Move the domain_error type to exception.m.
library/math.m:
library/exception.m:
    Move the domain_error type from math.m to exception.m.

NEWS:
    Announce the change as a potentially breaking change.

deep_profiler/query.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/integer.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
    Replace all references to math.domain_error with just domain_error.
    Delete imports of math.m where this was the only reason for the import.
2020-05-01 18:57:43 +10:00
Julien Fischer
d33647299a Rationalise hash functions across the standard library.
Currently, the hash functions for (some of) the primitive types are defined in
three places:

   1. The hash_table module.
   2. The version_hash_table module (duplicates of the above).
   3. Some (but not all) of the library modules for the primitive types.

This change makes the library module for a primitive type provide the hash
function for that type and deprecates the versions in the hash table modules.

Additionally, deprecate the "generic" has functions in the hash table modules.

library/hash_table.m:
library/version_hash_table.m:
    As above.

library/char.m:
library/int.m:
library/uint.m:
    Add hash/1 and hash/2.

library/float.m:
    Add hash/2.

library/robdd.m:
    Replace a call to the deprecated function.

NEWS:
    Announce the above additions and deprecations.

tests/hard_coded/hash_table_delete.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/version_hash_table_delete.m:
tests/hard_coded/version_hash_table_test.m:
    Conform to the above change.
2020-02-11 14:22:42 +11:00
Peter Wang
864a23ee91 Use conventional formatting.
library/float.m:
library/math.m:
    As above.
2020-01-08 17:01:46 +11:00
AlaskanEmily
fcdaa69680 Use function-like macros for the float/double verisons of the math.h functions
library/float.m:
library/math.m:
    As above.
2020-01-08 17:00:53 +11:00
AlaskanEmily
bf7aaef2b2 Use float versions of math.h functions when MR_USE_SINGLE_PREC_FLOAT is defined
library/float.m:
library/math.m:
    As above.
2020-01-08 17:00:53 +11:00
Mark Brown
5da7a4a70a Address some of Julien's review comments. 2019-08-28 00:52:17 +10:00
Mark Brown
1d0bde74f4 Some RNGs for the standard library, plus typeclass interfaces.
library/rng.m:
    Top-level module containing typeclasses and generic routines,
    as well as overall documentation.

library/rng.binfile.m:
    A generator that reads from a file.

library/rng.marsaglia.m:
    Fast, simple generator. Diehard results for default seed:
        PASSED: 109
        WEAK:   2
        FAILED: 3

library/rng.tausworthe.m:
    Combined Tausworthe generators. Diehard results for default seed:

    generator T3
        PASSED: 113
        WEAK:   1
        FAILED: 0

    generator T4
        PASSED: 112
        WEAK:   2
        FAILED: 0

library/library.m:
library/MODULES_DOC:
    Add the new modules to the public interface.

library/float.m:
    Add functions to convert from (u)int32/64 to float.

library/uint32.m:
    Add function to convert from uint64 to uint32.

tests/hard_coded/Mmakefile:
tests/hard_coded/rng1.{m,exp}:
tests/hard_coded/rng2.{m,exp}:
    Test the generators. The expected outputs are derived from
    the output of the C reference implementations.
2019-08-28 00:52:17 +10:00
Julien Fischer
8fe2751758 Conversion of 8- and 16-bit integers to floats.
Add functions for performing conversion of 8- and 16-bit integers to floats.
Since the ranges of all these integer types lie within the what can be exactly
represented by both single- and double-precision floating-point values, these
conversions always succeed.

Add a note about the float/1 function.

library/float.m:
     Add the new conversion functions.

     Note that the behaviour of float/1 is currently undefined if the
     argument is outside the range that the floating-point type can exactly
     represent integers.

     Fix section headings.

tests/hard_coded/Mmakfile:;
tests/hard_coded/float_conv.{m,exp}
    A test of int->float conversion; currently for 8- and 16-bit integers.
2018-10-09 04:42:31 +00:00
Julien Fischer
4ae5a8f928 Fix section headings in float module.
library/float.m:
    As above.
2018-10-09 02:30:59 +00:00
Julien Fischer
32cb78a060 Minor cleanups for the float module.
library/float.m:
   In particular, avoid excessive module qualification.
2018-08-08 09:54:02 +10:00
Zoltan Somogyi
a12692a0de Replace /* */ comments with // in the library.
Keep the old style comments where they do not go to the end of the line,
or where it is important that the comment line not have a // on it.
2018-06-21 18:55:08 +02:00
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
95ff02b1bf Add options to check the ordering of module contents.
One option, --warn-non-contiguous-decls, generates warnings if the
mode declarations of a predicate or function aren't in a contiguous block
immediately following the pred or func declaration. Since this is a rare
kind of "style error", this option is enabled by default.

Two options, --warn-inconsistent-pred-order-clauses and
--warn-inconsistent-pred-order-foreign-procs, warn about inconsistencies
between (a) the order in which predicates (and functions) are declared,
and (b) the order in which they are defined. The two options differ in
their scope. The latter applies to all predicates and functions defined
in the module, while the former applies only to those whose definitions
include Mercury clauses.

Since an exported predicate or function may need nonexported auxiliary
predicates and/or functions, imposing a single order the declarations and
definitions of *all* the predicates and functions in a module is not a good
idea. Instead, both options divide the predicates and functions defined
in a module two groups, the exported and the nonexported, and expect
a consistent order only within each group.

The result is output that looks like this:

    time.m:021: Warning: the order of the declarations and definitions of the
    time.m:021:   exported predicates is inconsistent, as shown by this diff:
    time.m:021:
    time.m:021:   --- declaration order
    time.m:021:   +++ definition order
    time.m:021:   @@ -1,7 +1,7 @@
    time.m:021:    predicate `clock'/3
    time.m:021:   -predicate `time'/3
    time.m:021:    predicate `times'/4
    time.m:021:    function `clk_tck'/0
    time.m:021:   +predicate `time'/3
    time.m:021:    function `difftime'/2
    time.m:021:    predicate `localtime'/4
    time.m:021:    function `localtime'/1

compiler/options.m:
doc/user_guide.texi:
    Add the new options.

compiler/style_checks.m:
    A new module that generates the new warnings if warranted.

compiler/check_hlds.m:
compiler/notes/compiler_design.html:
    Include and document the new module.

compiler/mercury_compile_front_end.m:
    Invoke the new module if any of the three new options is set.

compiler/hlds_pred.m:
    Record the item number of every predicate, function, and mode declaration
    in the module being compiled. We need this for information for the
    new warnings.

compiler/hlds_module.m:
    Record the context of the module declaration. We use this context
    for warnings about inconsistent order, since there isn't a better one.

compiler/hlds_clauses.m:
    Add a mechanism to retrieve the item numbers of a set of clauses
    even if they are contiguous.

    Document some old data types.

compiler/error_util.m:
    Add a new phase for style checks.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/from_ground_term_util.m:
compiler/lambda.m:
compiler/make_hlds.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/par_loop_control.m:
compiler/polymorphism.m:
compiler/stm_expand.m:
compiler/table_gen.m:
compiler/unify_proc.m:
    Conform the changes to the HLDS above.

compiler/typecheck_errors.m:
    Fix style of error messages.

library/array2d.m:
library/assoc_list.m:
library/benchmarking.m:
library/bit_buffer.write.m:
library/bool.m:
library/builtin.m:
library/construct.m:
library/cord.m:
library/counter.m:
library/float.m:
library/injection.m:
library/lazy.m:
library/lexer.m:
library/ops.m:
library/private_builtin.m:
library/profiling_builtin.m:
library/prolog.m:
library/queue.m:
library/rational.m:
library/require.m:
library/stack.m:
library/std_util.m:
library/store.m:
library/thread.semaphore.m:
library/tree234.m:
library/univ.m:
library/version_store.m:
    Move declarations or definitions around to avoid some of the warnings
    that we can now generate. (There are many more left.)

    Make some minor style improvements in the process.

tests/warnings/inconsistent_pred_order.{m,exp}:
tests/warnings/non_contiguous_decls.{m,exp}:
    New test cases to test the new options. They are both copies of
    tests/benchmarks/queens.m, with intentionally-screwed-up style.

tests/warnings/Mmakefile:
    Enable the new test cases.

tests/warnings/Mercury.options:
    Specify the options being tested for the new test cases.

tests/benchmarks/queens.m:
    Bring the style of this module up to date (before copying it).

tests/invalid/mode_decl_in_wrong_section.err_exp:
    Expect the warnings we now generate.
2016-10-15 17:26:32 +11:00
Zoltan Somogyi
44f9f1f405 Convert (C->T;E) to (if C then T else E). 2015-12-01 07:58:07 +11:00
Julien Fischer
59e6180eb9 Fix a portability issue with 64-bit Cygwin.
library/float.m:
    MR_in_least64_t is a long on 64-bit Cygwin systems.

runtime/mercury_conf_param.h:
    Define macros that allow us to distinguish between 32-
    and 64-bit Cygwin.
2015-10-13 15:39:22 +11:00
Julien Fischer
3dd02876a5 Delete the MLDS->IL backend.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_managed.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/ilds.m:
    Delete the modules making up the MLDS->IL code generator.

compiler/globals.m:
compiler/prog_data.m:
    Delete IL as a target and foreign language.

compiler/prog_io_pragma.m:
    Delete the max_stack_size/1 foreign proc attribute.  This was only
    ever required by the IL backend.

compiler/options.m
    Delete options used for the IL backend.

compiler/write_deps_file.m:
    Don't generate mmake targets for .il files etc.

compiler/*.m:
    Conform to the above changes.

compiler/notes/compiler_design.html
compiler/notes/work_in_progress.html
    Conform to the above changes.

library/*.m:
    Delete IL foreign_proc and foreign_export pragmas.

README.DotNet:
    Delete this file.

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
    Conform the above changes.

configure.ac:
    Don't check that IL is a supported foreign language when performing the
    up-to-date check.

    Delete the '--enable-dotnet-grades' option.

scripts/Mmake.vars.in:
    Delete variables used for the IL backend (and in on case by the Aditi
    backend).

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.rules:
scripts/canonical_grade.sh-subr:
tools/bootcheck:
    Delete stuff related to the 'il' and 'ilc' grades.

doc/reference_manual.texi:
     Delete the documentation of the 'max_stack_size' option.

doc/user_guide.texi:
     Delete stuff related to the IL backend.

tests/hard_coded/csharp_test.{m,exp}:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/valid/csharp_hello.m:
	Delete these tests: they are no longer relevant.

tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/intermod_foreign_type2.m:
tests/hard_coded/lp.m:
tests/hard_coded/user_compare.m:
tests/invalid/foreign_type_2.m:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/invalid/foreign_type_visibility.m:
tests/invalid/illtyped_compare.{m,err_exp}:
tests/submodules/external_unification_pred.m
tests/valid/big_foreign_type.m
tests/valid/solver_type_bug.m
tests/valid_seq/foreign_type_spec.m
tests/valid_seq/intermod_impure2.m
    Delete IL foreign_procs where necessary.

tests/hard_coded/Mmakefile
tests/invalid/Mercury.options
tests/invalid/Mmakefile
tests/submodules/Mmakefile
tests/valid/Mercury.options
tests/valid/Mmake.valid.common
tests/valid/Mmakefile
tests/valid_seq/Mmakefile
tests/valid_seq/Mercury.options
    Conform to the above changes.
2015-09-21 11:34:46 +10:00
Zoltan Somogyi
7f9791aa26 Standardize divider line lengths in the library.
library/*.m:
    As above.

tool/stdlines:
    A new shell script to do the job.
2014-11-23 22:05:34 +11:00
Zoltan Somogyi
15abab79de Wrap some too-long lines in the library. 2014-11-03 21:03:26 +11:00
Julien Fischer
bed96b93ff Avoid module qualification in library interfaces where possible.
NOTE: this change does not affect the io module -- I've left that for a
separate change.

library/*.m:
	As per the recent change to the coding standard, avoid module
	qualification in library interfaces where possible.

	Reformat declarations and descriptive comments to better utilise
	any space freed up by the above.
2014-10-10 15:08:24 +11:00
Julien Fischer
86e28feb52 Add float.infinity/0 to the standard library.
Add a constant function to the float module that returns positive infinity.
This is implemented for the C, Java, and C# backends.
The Erlang backend currently does not support it

library/float.m:
	Add the new function.

	Address review comments from Paul about my previous change.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_infinity.{m,exp}:
	Test various operations involving infinity.

NEWS:
	Announce the addition.
2014-09-18 09:27:49 +10:00
Julien Fischer
b262a2b0a7 Add new float classification predicates.
Add the predicates is_finite/1 and is_zero/1 to the float module.
In C grades the implementation of the former maps down to the isfinite macro
(with C99).

configure.ac:
runtime/mercury_confg.h.in:
	Check if the C99 macro isfinite is available.

runtime/mercury_float.h:
	Add the macro MR_is_finite for testing if a floating point
	number is finite.  If the C stdlib provides this operation
	directly we use that, otherwise we define it in terms of
	MR_is_infinite and MR_is_nan.

library/float.m:
	Add the predicates is_finite/2 and is_zero/2.

	Expand tabs in this file.

	Fix capitalization in documentation.

library/int.m:
	Fix inconsistent capitalization in a spot.

library/string.m:
	Use is_finite/1 in place of negating is_nan_or_infinite/1.
2014-09-17 14:43:25 +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
7b5c98a725 Fix a typo in the library documentation.
library/float.m:
	s/float point/floating point/ in a spot.
2014-07-30 23:27:26 +10:00
Julien Fischer
cb3cb3691e More fixes for float.float64_bits_string/1.
The implementation of float64_bits_string/1 does not work correctly on
platforms where sizeof(long) == 4.  This is the case for the i386 version of
NetBSD.  Also, make the code in the float module consistent with the fact the
runtime allows there to be no 64-bit integer type defined at all.

configure.ac:
runtime/mercury_conf.h.in:
	Define a new macro that expands to the integer length modifier for
	the MR_int_least64_t type.

library/float.m:
	Use the new macro to avoid a spot that was assuming that a long is
	a 64-bit quantity.  (TODO: we can probably now simplify some of the
	Windows specific code here, but I don't want to do that until I have
	tested it.)

	Have float64_bits_string/1 call MR_fatal_error() if MR_INT_LEAST64_TYPE
	is not defined.
2013-05-23 13:36:41 +10:00
Julien Fischer
3c894311a6 Fix problem with float64_bits_string/1 on Windows.
library/float.m:
     Some of the C compilers on Windows (MSVC and some versions of 32-bit
     MinGW GCC) do not support the "ll" size prefix in conversion
     specifiers.  In this case, use an extension to the Microsoft
     C library that provides equivalent functionality.
     (Annoyingly, only the Cygwin GCC raised a warning about this,
     everything else just silently did the wrong thing!)
2013-05-01 15:59:17 +10:00
Julien Fischer
73bbbdc0ab Fix a problem on Cygwin.
library/float.m:
    The 64-bit integer type on Cygwin is "long long int".
2013-05-01 03:05:52 +10:00
Julien Fischer
b8aed192cd Fix float.float64_bits_string/1 on MinGW64.
library/float.m:
     Use the appropriate conversion specifier for
     MR_int_least64_t on MinGW64 in a spot.

runtime/mercury_conf_param.h:
     Define MR_MINGW64 on MinGW64 systems.
2013-03-25 14:05:03 +11:00
Julien Fischer
42d3464298 Fix a comment.
Branches: main, 11.07

library/prolog.m:
	Fix a comment.

library/flaot.m:
	Prevent some hidden functions from showing up in the library reference.
2012-02-08 12:19:43 +00:00
Peter Wang
573e6f2f00 Support unboxed float fields in high-level C grades.
Branches: main

Support unboxed float fields in high-level C grades.

When the representation of `float' is no wider than a machine word, d.u.
functor arguments of type `float' (or equivalent) will be stored directly
within cells constructed for that functor, instead of a pointer to the box
containing the value.  This was already so for low-level C grades.

compiler/mlds.m:
	Add an option to mlds_type, equivalent to
	`mlds_array_type(mlds_generic_type)' except that some elements are
	known to be floats.

	Update some comments.

compiler/ml_global_data.m:
	Remember the `--unboxed-float' option in `ml_global_data'.

	Special case generic arrays in `ml_gen_static_scalar_const_addr' and
	`ml_gen_static_scalar_const_value'.  Float literals cannot be used to
	initialize an element of a generic array in C.  If any appear, replace
	the generic array type by an instance of
	`mlds_mostly_generic_array_type' with float fields in the positions
	which have float initializers.

compiler/ml_code_util.m:
	Make `ml_must_box_field_type' and `ml_gen_box_const_rval' depend on the
	`--unboxed-float' option.

	Delete some now-misleading comments.

	Delete an unused predicate.

compiler/mlds_to_c.m:
	Update code that writes out scalar static data to handle
	`mlds_mostly_generic_array_type'.

	In one case, for `--high-level-data' only, output float constants by
	their integer representation, so that they may be cast to pointer
	types.

compiler/ml_unify_gen.m:
	Rename some predicates for clarity.

compiler/ml_accurate_gc.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Conform to changes.

library/float.m:
	Add hidden functions to return the integer representation of the bit
	layout of floating point values.

library/exception.m:
	Delete mention of MR_AVOID_MACROS.

runtime/mercury.c:
runtime/mercury.h:
	Make MR_box_float/MR_unbox_float act like "casts" when MR_BOXED_FLOAT
	is undefined, and only define them in high-level grades.  I think they
	should be replaced by MR_float_to_word/MR_word_to_float (which have
	less confusing names when there is no boxing) but that would require
	some header file reshuffling which I don't want to undertake yet.

	Delete references to MR_AVOID_MACROS.  Apparently it existed to support
	the defunct gcc back-end but I cannot see it ever being defined.

runtime/mercury_conf_param.h:
	MR_HIGHLEVEL_CODE no longer implies MR_BOXED_FLOAT.

	Delete mention of MR_AVOID_MACROS.

runtime/mercury_float.h:
	Fix a comment.

tests/hard_coded/Mmakefile:
tests/hard_coded/float_ground_term.exp:
tests/hard_coded/float_ground_term.m:
	Add a test case.
2011-08-22 07:56:10 +00:00
Peter Wang
57f9013259 Start a C# backend, adapted from mlds_to_java.m.
Branches: main

Start a C# backend, adapted from mlds_to_java.m.

Some `pragma foreign_*' declarations are commented out in this change because
no bootstrap compiler will yet accept "C#" in the language specification.

The compiler already supported C# foreign_procs for the IL backend, but the IL
backend and this new backend do not agree on naming and calling conventions so
the changes to the existing C# foreign_procs will further break the IL backend.
Nobody cares.

Only tested so far with Mono on Linux.

compiler/mlds_to_cs.m:
        New module.  In the CVS Attic there exists an obsolete file named
        mlds_to_csharp.m (replaced by mlds_to_managed.m) which we don't want to
        conflict with.

        For C# we need to know if a `pragma foreign_type' is a value or
        reference type.  Currently this is done by accepting a fake keyword
        `valuetype' before the type name, like for IL.

compiler/ml_backend.m:
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
        Hook up the C# backend.

compiler/globals.m:
        Add `target_csharp' as a target language.

compiler/options.m:
        Add `--csharp' and `--csharp-only' options and their synonyms.

compiler/handle_options.m:
        Handle `target_csharp' like `target_java', except for features which
        are still to be implemented.

compiler/add_pragma.m:
        Allow C# as a `pragma foreign_export' language.

        Allow C# for `pragma foreign_export_enum'.

        Conform to changes.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
        Accept C# as a language for `pragma foreign_type'.

        Accept `csharp' as the name of a grade in trace parameters.

compiler/make_hlds_passes.m:
        Reuse most of the code for implementing mutables on Java for C#.

compiler/mlds.m:
        Add a new MLDS target language, `ml_target_csharp'.

        Conform to changes.

compiler/ml_foreign_proc_gen.m:
        Generate foreign_procs for C#.

compiler/foreign.m:
        Update predicates to support C# targets.

compiler/c_util.m:
        Make `quote_string' use hexadecimal escapes in C# string literals.

compiler/parse_tree.m:
compiler/java_names.m:
        Add C# equivalents for predicates in this module.  `java_names' is a
        misleading module name, but the predicates for C# and Java share some
        code and may possibly be combined in the future.

compiler/rtti.m:
        Add predicates to return the names of RTTI structures in C#.

compiler/simplify.m:
        Handle the trace parameter `grade(csharp)'.

compiler/compile_target_code.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
        Add some support for building of executables and libraries with
        `--target csharp'.

compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/granularity.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modules.m:
compiler/pragma_c_gen.m:
compiler/prog_foreign.m:
compiler/special_pred.m:
compiler/write_deps_file.m:
        Conform to changes.

library/builtin.m:
library/rtti_implementation.m:
library/type_desc.m:
        Implement RTTI procedures for the new backend, which uses a high-level
        data representation (like the Java backend).  The existing C# code was
        designed for the IL backend, which used a low-level representation of
        the RTTI data structures.

        Most (if not all) of the the "new" code is exactly the same as the Java
        versions, with only syntactic changes.

        Rename the C# class `void_0' to `Void_0' to match the naming convention
        used by mlds_to_cs.m.

library/array.m:
        Update the existing C# code to work with the new backend.

        Use `object[]' as the type of all array of non-primitive types.
        The problem is one we encountered on the Java backend: when creating a
        new array based on the type of a single element, we don't know whether
        the new array should contain elements of the class or superclass.

library/bool.m:
        Export `bool' constants to C#.

library/exception.m:
        Update the existing C# code to work with the new backend.

        Move the `mercury.runtime.Exception' C# class to mercury_dotnet.cs.

library/float.m:
        Add C# implementations of `is_nan' and `is_inf'.

library/list.m:
        Add methods for manipulating lists from hand-written C# code.

library/string.m:
        Add C# implementations of string procedures which were missing.

library/dir.m:
library/io.m:
library/library.m:
        Update the existing C# code to work with the new backend.

library/private_builtin.m:
        Update the existing C# code to work with the new backend.

        Delete the static constants which are duplicated in mercury_dotnet.cs.
        The mlds_to_cs.m will emit references to the constants in the latter
        only.

library/backjump.m:
library/bitmap.m:
library/mutvar.m:
library/par_builtin.m:
library/region_builtin.m:
library/store.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/univ.m:
        Make these modules compile with the C# backend.

runtime/mercury_dotnet.cs.in:
        Add RTTI classes to the `mercury.runtime' namespace, equivalent to
        those on the Java backend.

        Use enumerations `MR_TYPECTOR_REP_*' and `MR_SECTAG_*' constants so we
        can switch on them.

        Add the `UnreachableDefault' exception class.

        Hide old classes which are unused with the new backend behind
        #ifdef !MR_HIGHLEVEL_DATA.
2010-09-16 00:39:12 +00:00
Ian MacLarty
5cc168f863 Document that floats are double precision by default.
library/float.m:
    Document that floats are double precision by default.
2010-09-08 04:24:58 +00:00
Peter Wang
c053f90088 Allow inlining of Java foreign_procs.
Branches: main, 10.04

Allow inlining of Java foreign_procs.

This revealed a problem with directly using the `succeeded' flag directly as
the success indicator in Java foreign_procs.  When the code of the foreign_proc
becomes a nested function, and after nested functions are eliminated, there may
not be a variable called `succeeded' in that context; it is moved into
environment struct, and the transformation is not able to update handwritten
code to reflect that.  The solution is to declare a local variable for the
foreign_proc, let the handwritten code assign that, then assign its final
value to the `succeeded' flag with an MLDS statement.

We take the opportunity to name the local variable `SUCCESS_INDICATOR', in
line with other backends.

compiler/inlining.m:
        Allow inlining of Java foreign_procs.

compiler/ml_foreign_proc_gen.m:
        In the code generated for semidet Java foreign_procs, declare a local
        `SUCCESS_INDICATOR' variable and assign its value to the `succeeded'
        flag afterwards.

        Add braces to give the foreign_proc variables a limited scope.

compiler/make_hlds_warn.m:
        Conform to renaming.

doc/reference_manual.texi:
        Update documentation for the renaming of the `succeeded' variable.

library/array.m:
library/bitmap.m:
library/builtin.m:
library/char.m:
library/construct.m:
library/dir.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/string.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/version_array.m:
        Conform to renaming.

        Fix problems with Java foreign_procs that may now be copied into other
        modules when intermodule optimisation is enabled, some by disallowing
        the procedures from being duplicated, some by making referenced
        classes/fields `public'.

        [Some of the `may_not_duplicate' attributes may not indicate actual
        problems, just that it seems not worthwhile inlining calls to the
        procedure.]

extras/solver_types/library/any_array.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/java_test.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/user_compare.m:
tests/valid/exported_foreign_type2.m:
tests/warnings/warn_succ_ind.m:
tests/warnings/warn_succ_ind.exp3:
        Conform to renaming.
2010-05-07 03:12:27 +00:00
Zoltan Somogyi
599e1c2fdb Implement the proc command of the deep profiler using the report mechanism.
Estimated hours taken: 16
Branches: main

Implement the proc command of the deep profiler using the report mechanism.

Some of the detailed changes also address Paul's post-commit review of my
previous diff.

deep_profiler/report.m:
	Define the representation of the proc report.

	Change some names to be more consistent.

deep_profiler/profile.m:
	Add a type for use in report.m.

	Document the fields of an existing type.

deep_profiler/create_report.m:
	Add code to create proc reports.

	Change some names to be more consistent.

	Fix a bug: avoid divide by zero exceptions in some rare cases.

deep_profiler/measurement units.m:
	Fix a bug: avoid divide by zero exceptions in some rare cases.

deep_profiler/display_report.m:
	Add the code for converting proc reports to displays. This required
	rewriting almost everthing in this module to remove the assumption,
	which was previously embedded in many places, that the code is part
	of the implementation of the top_procs command. The new code is
	separated into two parts; the command-specific parts, and the parts
	that should be usable for all commands. (The reusable part is much
	bigger.)

deep_profiler/display.m:
	Expand the display representation to allow the specification of

	- plain text as distinguished from headings
	- paragraph breaks
	- pseudo-links, i.e. text fragments that are formatted like links
	- table separator rows
	- table cells that span more than one column

	which are used in the new version of display_report.m.

	Simplify the mechanism for setting up table header groups.

deep_profiler/html_format.m:
	Handle the changes in display.m.

	Fix some anomalies in the formatting of lists and tables.

	Group related code together.

deep_profiler/query.m:
	Provide a switch for selecting which of the two mechanisms,
	the old direct generation of HTML or the new indirect generation
	through the report and display structures, should generate the HTML
	page for a command that both mechanisms can implement. The default
	is the new mechanism, but it can be overridden by implementors
	by creating a file called "/tmp/old_deep_profiler".

	Switch the default handling of the proc command over to the new
	mechanism.

	Rename some types and function symbols to make them more consistent
	and expressive.

	Generate more informative error messages for domain error exceptions.

deep_profiler/mdprof_cgi.m:
	Add a mechanism for decoding the links in the generated pages.
	The mechanism takes the form of three new options: --decode,
	--decode-cmd, and --decode-prefs. When one or more of these are given,
	mdprof_cgi will not do its usual stuff, instead of just loops waiting
	for lines whose contents it will then try to decode as queries,
	as commands and/or as preferences.

deep_profiler/Mercury.options:
	Try to postpone thrashing in the deep compiler when compiled in
	debug grades, by compiling their contents with shallow tracing.

deep_profiler/array_util.m:
	Make shallow tracing effective by moving the deep recursions
	into non-exported predicates.

deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/startup.m:
	Convert the debugging code to use trace goals.

deep_profiler/cliques.m:
deep_profiler/read_profile.m:
	Convert the debugging code to use trace goals.

	Use more expressive names for lots of variables.

	In read_profile.m, avoid an unnecessary repackaging of data.

deep_profiler/util.m:
	Fix some grammar errors in a comment, and comment some code to use
	state variables.

deep_profiler/interface.m:
	Fix some grammar errors in a comment.

deep_profiler/mdprof_feedback.m:
	Change some variable names to be consistent with the other modules.

library/float.m:
library/int.m:
	Make the messages in the domain errors we throw more expressive.

library/io.m:
	Minor style changes.
2008-08-18 02:14:59 +00:00
Peter Wang
19405c1dd8 Set float.max to a sensible value for Erlang.
Estimated hours taken: 0.2
Branches: main

library/float.m:
	Set float.max to a sensible value for Erlang.

library/string.m:
	Bump up the precision of the Erlang implementation of
	string.lowlevel_float_to_string to match the maximum on the C
	backends.
2007-08-31 03:05:05 +00:00
Ralph Becket
67ec243a51 Define pretty_printer formatters for some common standard library types.
Estimated hours taken: 4
Branches: main

Define pretty_printer formatters for some common standard library types.
Include these formatters in the default pretty_printer formatter_map.
Add a useful function to the pretty_printer interface.

library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/list.m:
library/string.m:
library/tree234.m:
	Add <type>_to_doc functions.

library/pretty_printer.m:
	Added function format_arg/1.
	Initialise the default formatter_map to use the <type>_to_doc
	functions.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_pretty_printer_defaults.exp:
tests/hard_coded/test_pretty_printer_defaults.m:
	Test case.
2007-08-14 04:21:09 +00:00