Commit Graph

52 Commits

Author SHA1 Message Date
Julien Fischer
ef5d797371 Use fixed size integer literals in the library and compiler.
configure.ac:
    Check that the bootstrap compiler supports fixed size
    integer types.

library/int16.m:
library/int32.m:
library/int8.m:
library/integer.m:
library/uint16.m:
library/uint32.m:
library/uint8.m:
compiler/lookup_switch.m:
     Use fixed size integer literals instead of casting from ints.
2017-08-30 20:51:45 +10:00
Julien Fischer
e6dbebaf95 Fix integer->(u)int8 conversion of zero.
library/integer.m:
    Handle the zero case in integer->(u)int8 conversion correctly.
2017-08-21 20:54:40 +10:00
Julien Fischer
3f28b096ef Add builtin 8, 16 and 32 bit integer types -- Part 2.
Enable support for literals of the new types.

Begin implementing library support for 8, 16, and 32 bit types.

Update the compiler to represent values of their own constants.

library/int8.m:
library/int16.m:
library/int32.m:
library/uint8.m:
library/uint16.m:
library/uint32.m:
    Begin filling these modules out.

library/uint.m:
    Unrelated change: add the predicates plus/2, minus/2 and
    times/2 for uints.

library/integer.m:
    Add predicates for converting integer/0 values into values
    of the new types.

    Add functions for converting values of the new types into
    integer/0 values.

library/string.m:
    Add functions for converting values of the new types to strings.

library/private_builtin.m:
    Replace the placeholder definitions for the builtin unify and compare
    predicates for the new types with their actual definitions.

library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
    Replace placeholder definitions for the new types with their
    actual definitions.

library/io.m:
    Add predicates for writing values of the new types to file streams.

library/stream.string_writer.m:
    Implement generic write and print for values of the new types.

library/string.to_string.m:
    Likewise for string/1.

library/term.m:
library/term_conversion.m:
    Add predicates and functions for converting the new types to
    and from terms.

compiler/builtin_ops.m:
compiler/elds.m:
compiler/hlds_data.m:
compiler/llds.m:
compiler/mlds.m:
compiler/prog_data.m:
    Replace placeholders for the new types with the new types.

compiler/superhomogeneous.m:
    Enable literals of the new types.

compiler/mlds_to_cs.m:
    Avoid a warning from the C# compiler for bitwise-or operators
    with sbyte operands.

compiler/c_util.m:
compiler/elds_to_erlang.m:
compiler/hlds_out_util.m:
compiler/llds_out_data.m:
compiler/lookup_switch.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_to_term.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_util.m:
    Replace placeholder code for the new types with code that uses the new
    types.

tests/invalid/invalid_int.m:
tests/invalid/invalid_int.err_exp2:
    Extend this test case to cover the fixed size integer types.
2017-08-21 09:50:16 +10:00
Julien Fischer
6a09347cc9 Use uint literals in library and compiler.
configure.ac:
     Require that the bootstrap compiler support uint literals.

library/integer.m:
library/uint.m:
compiler/const_prop.m:
compiler/ml_lookup_switch.m:
compiler/simplify_goal_call.m:
compiler/uint_emu.m:
     Use uint literals rather than casting from ints.

     Delete imports of the uint module where we can now do so.
2017-06-12 00:20:22 +10:00
Zoltan Somogyi
5e87e2b8c2 Fix more warnings from --warn-inconsistent-pred-order-clauses. 2017-05-05 01:28:29 +10:00
Julien Fischer
de9eb1c37d Remove a workaround in the integer module.
library/integer.m:
    Fix an XXX UINT: use unchecked_right_shift/2 from the uint module rather
    than defining our own local version.

    Use an unchecked shift in the definition of the chop/4 operation for
    ints as well.
2017-04-25 22:03:01 +10:00
Julien Fischer
8f583d15fa Implement integer-to-uint and uint-to-integer conversion.
library/integer.m:
     As above -- I have upcoming changes that require this.
     (There's a bunch places marked XXX UINT that will need
     to revisited once more uint support is available.)

tests/Mmakefile:
tests/hard_coded/integer_uint_conv.{m,exp,exp2}:
      Add test for the conversions.
2017-04-17 00:54:01 +10:00
Zoltan Somogyi
c3e089c401 Wrap overlong lines. 2017-01-12 04:32:30 +11:00
Julien Fischer
61c4ef7e50 Allow optional underscores in numeric literals.
Allow the optional use of underscores in numeric literals for the purpose of
improving their readability (e.g. by grouping digits etc).  We allow any number
of underscores between digits and also between the radix prefix (if present) and
the initial digit.  (When integer type suffixes are supported we will also
allow them to be preceded by any number of underscores.)  The following are
*not* allowed:

   1. Leading underscores.
   2. Trailing underscores.
   3. Underscores inside the components of a radix prefix (e.g.
      0_xffff or 0__b101010.)
   4. Underscores immediately adjacent to the decimal point in a float
      literal (e.g. 123_._123.)
   5. Underscores immediately adjacent to the exponent ('e' or 'E) in
      a float literal (e.g. 123_e12 or 123E_12.)
   6. Underscores immediately adjacent to the optional sign of an exponent
      in a float literal (e.g. 123_+e12 or 123-_E12.)
   7. Underscores between the optional sign of an exponent and the exponent
      indicator (e.g. 123+_e12.)

library/lexer.m:
    Modify the scanner to account of underscores in numeric literals according
    to the scheme above.

library/string.m:
library/integer.m:
    Export undocumented functions for converting strings containing underscores
    into ints or integers respectively.

tests/hard_coded/parse_number_from_io.{m,exp}:
     Test parsing of valid numeric literals from file streams.

tests/hard_coed/parse_number_from_string.{m,exp}:
     Test parsing of valid and invalid numeric literal from string.

tests/invalid/invalid_binary_literal.{m,err_exp}:
tests/invalid/invalid_decimal_literal.{m,err_exp}:
tests/invalid/invalid_octal_literal.{m,err_exp}:
tests/invalid/invalid_hex_literal.{m,err_exp}:
tests/invalid/invalid_float_literal.{m,err_exp}:
      Test parsing of invalid numeric literals from file streams.

tests/hard_coded/parse_number_from_{io,string}.m:
tests/hard_coded/parse_number_from_{io,string}.exp:
     Test parsing of valid numeric literals.

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
     Add the new test cases.
2017-01-12 01:10:31 +11:00
Julien Fischer
46bfc2e549 Do not module qualify clause heads in library modules.
library/*.m:
    As above.

library/tree234.m:
    Fix spelling.

    Use spaces instead of tabs in some spots.
2016-08-10 11:55:55 +10:00
Zoltan Somogyi
ba53e90cab Delete some unused predicates. 2016-01-02 01:39:02 +11:00
Zoltan Somogyi
bbbbfde36c Convert (C->T;E) to (if C then T else E).
Also, eliminate the use of DCGs, turn semidet functions into predicates,
and improve documentation.
2015-10-21 11:04:05 +11:00
Julien Fischer
17c6a63117 Additions to the integer module.
library/integer.m:
	Add some more functions that return constants: negative_one/0 and ten/0.

	Export (and rename) the predicate that is used to test whether an integer
	is equal to zero.

NEWS:
	Announce the above (and also two/0, which was added recently).
2015-04-23 15:49:28 +10:00
Matthias Güdemann
48b1f0d860 Speed-up integer power function.
library/integer.m:
        Replace old big_pow function with simple square and multiply
        that uses multiplication directly. This speeds-up the power
        function, as the multiplication function is faster now.
2015-04-20 16:56:03 +02:00
Peter Wang
c89017a096 Add integer.to_base_string.
library/integer.m:
	Add to_base_string/2.

tests/general/base_string_to_integer.exp:
tests/general/base_string_to_integer.m:
	Extend test case.

NEWS:
	Announce addition.
2015-02-17 12:14:16 +11:00
Peter Wang
3e872aeba9 Some `integer' module improvements.
library/integer.m:
	Add basic documentation for interface predicates and functions.

	Throw math.domain_error exceptions where the analogous
	predicates and functions in the `int' module would do so.

	Throw exceptions with unexpected/3 where that would indicate an
	implementation error.

	Fix looseness in the strings that from_base_string accepted,
	e.g. "+" and "--1".

	Minor style changes.
2015-02-17 12:14:16 +11:00
Peter Wang
8593d8201a Improve `integer' module interface.
library/integer.m:
	Add to_int/2 which fails instead of throwing an exception if the
	value cannot be represented as an `int'.

	Deprecate function int/1.
	Add a function with a more explicit name det_to_int/1.

	Deprecate semidet function from_string/1.
	Add a replacement predicate from_string/2.

	Deprecate semidet function from_base_string/2.
	Add a replacement predicate from_base_string/3.

library/string.format.m:
	Conform to changes.

NEWS:
	Announce changes.
2015-02-17 12:14:16 +11: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
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
696829e6c1 Fix problems with the char module.
(1) The behaviour of digit_to_int/2 was inconsistent with that of is_digit/2.
The former succeeds for all of 0-9, a-z and A-Z while the latter succeeds only
for 0-9 (i.e. it was possible for digit_to_int/2 to succeed for non-decimal
characters, which is not what was intended in many of it uses).

(2) Predicates involving hexadecimal digits were inconsistently named, they
were "hex digits" in one predicate name, "hex chars" in another.

This change ensures that the following operations are supported for binary,
octal, decimal and hexadecimal digits and that we use a consistent naming
scheme for the predicates that implement them:
    - testing if a character is a digit of the given base
    - conversion to an int
    - conversion from an int

In addition, we also add predicates for supporting these operations for user
defined bases, ranging from 2-36.

library/char.m:
    Add the predicate is_decimal_digit/1, which is a synonym for is_digit/1.

    Add the predicate is_base_digit/2.

    Add the predicates int_to_{binary,octal,decimal,hex}_digit/2 and
    base_int_to_digit/3.

    Add the predicates {binary,octal,decimal,hex}_digit_to_int/2 and
    base_digit_to_int/3.

    Add det function versions of the above.

    Delete the function det_digit_to_int/1 that I added the other day.

    Mark the following as obsolete:
        - is_hex_digit/2
        - int_to_hex_char/2
        - int_to_digit/2
        - det_int_to_digit/1
        - det_int_to_digit/2

    Avoid redundant module qualification in the implementation.

    Mark some C foreign_procs as not modifying the trail.

    Re-order some declarations according to how the coding standard says they
    should be ordered.

library/bitmap.m:
library/integer.m:
library/parsing_utils.m:
library/string.m:
compiler/prog_rep_tables.m:
    Replace calls to obsolete predicates or functions.

NEWS:
    Announce the above changes.

    Add note advising users of digit_to_int/2 to check their code for the
    problem described above.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_char_digits.m:
tests/hard_coded/test_char_digits.exp:
    Add a systematic test for the above predicates.
2014-09-12 01:16:00 +10:00
Matthias Güdemann
7488c9f003 Add integer multiplication based on Karatsuba's algorithm
library/integer.m:
    Adds Karatsuba based fast integer algorithm in the function
    `pos_mul_karatsuba' which replaces the call to `pos_mul_list' in `pos_mul'.

    It is a divide and conquer algorithm which uses O(n^1.585) basic
    operations instead of O(n^2). The function expects two positive
    integer variables, the first one must have at most as many digits as
    the second one. It falls back to quadratic multiplication if the
    larger factor has less than `karatsuba_threshold' digits.

    If compiled in a parallel grade, the function uses parallelism for the
    divide and conquer part for numbers with more than
    `karatsuba_parallel_threshold' digits.

    The current values for `karatsuba_threshold' is 35,
    `karatsuba_parallel_threshold' is 10 times this value.
2014-02-23 12:20:09 +01:00
Zoltan Somogyi
b3786ea0ac Fix white space.
Estimated hours taken: 0.1
Branches: main

library/integer.m:
	Fix white space.
2012-03-26 04:25:37 +00:00
Peter Wang
b1af59cb29 Deprecate string.substring, string.foldl_substring, etc. in favour of
Branches: main

Deprecate string.substring, string.foldl_substring, etc. in favour of
new procedures named string.between, string.foldl_between, etc.
The "between" procedures take a pair of [Start, End) endpoints instead
of Start, Count arguments.  The reasons for this change are:

- the "between" procedures are more convenient

- "between" should be unambiguous.  You can guess that it takes an End
  argument instead of a Count argument without looking up the manual.

- Count arguments necessarily counted code units, but when working with
  non-ASCII strings, almost the only way that the values would be arrived at
  is by substracting one end point from another.

- it paves the way for a potential change to replace string offsets with an
  abstract type.  We cannot do that if users regularly have to perform a
  subtraction between two offsets.

library/string.m:
	Add string.foldl_between, string.foldl2_between,
	string.foldr_between, string.between.

	Deprecate the old substring names.

	Replace string.substring_by_codepoint by string.between_codepoints.

compiler/elds_to_erlang.m:
compiler/error_util.m:
compiler/rbmm.live_variable_analysis.m:
compiler/timestamp.m:
extras/posix/samples/mdprof_cgid.m:
library/bitmap.m:
library/integer.m:
library/lexer.m:
library/parsing_utils.m:
mdbcomp/trace_counts.m:
profiler/demangle.m:
	Conform to changes.

tests/general/Mercury.options:
tests/general/string_foldl_substring.exp:
tests/general/string_foldl_substring.m:
tests/general/string_foldr_substring.exp:
tests/general/string_foldr_substring.m:
tests/hard_coded/Mercury.options:
tests/hard_coded/string_substring.m:
	Test both between and substring procedures.

tests/hard_coded/string_codepoint.exp:
tests/hard_coded/string_codepoint.exp2:
tests/hard_coded/string_codepoint.m:
	Update names in test outputs.

NEWS:
	Announce the change.
2011-06-15 01:05:34 +00:00
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Julien Fischer
c2e2d69a5c Add the functions integer.from_base_string/2 and
Estimated hours taken: 1.5
Branches: main

library/integer.m:
	Add the functions integer.from_base_string/2 and
	integer.det_from_base_string/2.

NEWS:
	Announce the addition.

tests/general/Mmakefile:
tests/general/.cvsignore:
tests/general/base_string_to_integer.{m,exp}:
	Test the new functions.
2007-05-10 05:55:38 +00:00
Julien Fischer
9cd94b5c72 Various minor cleanups and syntax updates for the standard library.
Estimated hours taken: 1
Branches: main

Various minor cleanups and syntax updates for the standard library.
There are no changes to any algorithms.

library/injection.m:
library/set.m:
library/sparse_bitset.m:
	Use promise_equivalent_clauses where appropriate.

library/set_ordlist.m:
library/set_unordlist.m:
	Convert these module to 4-space indentation:
		Convert these module to 4-space indentation

library/*.m:
	Convert some if-then-elses into switches.

	Remove unnecessary module qualification - this is related
	mainly to the breakup of std_util and the fact that on
	the 0.13 branche we had two versions of the all-solutions
	predicates.

	Various other style cleanups.

vim/syntax/mercury.vim:
	Highlight promise_equivalent_clauses appropriately.
2006-10-23 00:33:04 +00:00
Julien Fischer
42ded6d070 Delete library predicates that were marked as obsolete prior to the 0.12
Estimated hours taken: 0.1
Branches: main

Delete library predicates that were marked as obsolete prior to the 0.12
release.

library/int.m:
library/integer.m:
library/rational.m:
library/rbtree.m:
	Delete some obsolete predicates.
2006-09-27 07:39:52 +00:00
Peter Ross
84ffc0924d Fix --warn-unused-imports warnings in some of the modules.
Estimated hours taken: 4
Branches: main

library/*.m:
compiler/*.m:
	Fix --warn-unused-imports warnings in some of the modules.
2006-09-27 06:17:09 +00:00
Julien Fischer
e0f5ac47db Make it easier for vi to jump past the initial comments
Estimated hours taken: 0.1
Branches: main

library/*.m:
	Make it easier for vi to jump past the initial comments
	at the head of a module.
2006-04-19 05:18:00 +00:00
Julien Fischer
5e92224eec Improve the library reference manual by formatting the beginning of
Estimated hours taken: 0.2
Branches: main, release

library/*.m:
	Improve the library reference manual by formatting the beginning of
	library modules consistently.

library/integer.m:
	Fix some bad indentation.
2006-04-13 06:08:05 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
b293bd999d Replace __ with . as the module qualifier everywhere.
Estimated hours taken: 1
Branches: main

library/*.m:
	Replace __ with . as the module qualifier everywhere.

tests/hard_coded/test_injection.exp:
	Replace __ with . as the module qualifier in expected exceptions.
2006-03-07 22:23:58 +00:00
Peter Ross
6890ff0884 Make the big_quot_rem predicate visible using
Estimated hours taken: 0.1
Branches: main, release

library/integer.m:
	Make the big_quot_rem predicate visible using
	divide_with_rem, so as to avoid making two calls
	to // and rem.
2005-11-13 09:37:45 +00:00
Zoltan Somogyi
57b8f436eb Convert to four-space indentation most of the library modules that
Estimated hours taken: 4
Branches: main

library/*.m:
	Convert to four-space indentation most of the library modules that
	weren't already indented that way. Use predmode syntax where possible.
	In some modules, shorten long lines by deleting module name prefixes.
	Fix departures from our coding standards.

	In some modules, simplify code, mostly using field names and/or state
	variables.

	There are no changes in algorithms, except for neg_list in integer.m.
2005-10-17 11:35:22 +00:00
Zoltan Somogyi
88c7539230 Import only one module per line, as we already do in the compiler
Estimated hours taken: 0.3
Branches: main

library/*.m:
	Import only one module per line, as we already do in the compiler
	directory.
2005-06-16 04:08:07 +00:00
Julien Fischer
0ff60718d1 Allow strings of digits prefixed by a single '+' to be converted
Estimated hours taken: 0.5
Branches: main

Allow strings of digits prefixed by a single '+' to be converted
to arbitrary precision integers.

library/integer.m:
	Modify integer.from_string/1 and integer.det_from_string/1
	so that they accept strings that match the regexp [+-]?[0-9]+.
	Previously they would fail to correctly convert a string of
	digits if it was prefixed by a single '+'.

	This now corresponds to the behaviour of string.to_int/1
	and string.det_to_int/1.

tests/hard_coded/integer_test.m:
	Check that strings of digits prefixed with '+' are converted
	correctly.
2004-11-11 06:41:52 +00:00
Julien Fischer
794f363490 Add a new function to the integer module and deprecate an
Estimated hours taken: 1
Branches: main

Add a new function to the integer module and deprecate an
existing predicate.

library/integer.m:
	Add a function integer.det_from_string/1 that is similar
	to integer.from_string/1 except that it throws an
 	exception instead of failing if the string cannot be
	converted to an integer.

	Deprecate the predicate version of integer.pow.  We don't
	gain anything from having both a predicate and function
	version.

library/string.m:
	Replace a call to the predicate version of integer.pow with
	a call to the function version.

tests/hard_coded/integer_test.m:
	Test integer.det_from_string.
	Replace instances of `:' as the module qualifier.
	Include integer.one/0 and integer.zero/0 in some
	of the tests.

NEWS:
	Mention these changes.
2004-11-10 07:12:38 +00:00
Zoltan Somogyi
6909674f14 Bring these modules up to date with our current style guidelines.
Estimated hours taken: 8
Branches: main

library/*.m:
	Bring these modules up to date with our current style guidelines.
	Use predmode declarations where appropriate. Use state variable syntax
	where appropriate. Reorder arguments where this makes it possible to
	to use state variable syntax. Standardize format of predicate
	description comments. Standardize indentation.
2004-03-15 23:49:36 +00:00
Zoltan Somogyi
ee2218ae46 Bring these modules up to date with our current style guidelines.
Estimated hours taken: 10
Branches: main

library/*.m:
	Bring these modules up to date with our current style guidelines.
	Use predmode declarations where appropriate. Use state variable syntax
	where appropriate. Reorder arguments where this makes it possible to
	to use state variable syntax.

library/io.m:
	Export some predicates that are duplicated in term_io.m and/or
	parser.m, and give them more expressive names.

library/parser.m:
library/term_io.m:
	Delete the now unnecessary copies of those predicates in these modules.
2004-03-15 06:50:18 +00:00
Julien Fischer
db4217666a Fix a typo in a comment in integer.m.
library/integer.m:
	s/mode/mod/.
2004-01-20 01:01:56 +00:00
Julien Fischer
0b2aee5bd1 More code cleanups for the integer module.
Estimated hours taken: 1
Branches: main

More code cleanups for the integer module.  This does not change
any algorithms.

library/integer.m:
	Use distinct variable names. e.g X and Y rather than X1 and X2

	Fix indentation so it adheres more closely to what is specified
	in the coding standards.

	While converting a list of digits to string call error/1 if something
	goes wrong rather than appending "Woops" to the string.

	Replace calls to int__to_float/2 with calls to float__float/1.

	Fix an incorrect reference in an error message.
2004-01-05 12:40:25 +00:00
Julien Fischer
90d2b4f1d2 Add some functions to the integer and rational modules.
Estimated hours taken: 1.5
Branches: main

Add some functions to the integer and rational modules.

Clean up the code in these modules so it adheres more closely to
our current coding standards.

NEWS:
	Mention these changes.

library/integer.m:
	Shift the constant functions integer.zero/0 and integer.one/0
	back into the interface.  According to the log they were deleted
	because they were not sufficiently useful.  In my view they
	the symbolic names are preferable to writing them as integer(1)
	and integer(0).

	Add a function version of integer.pow/3.

	Shift a large comment that concerns implementation details and
	possible improvements to the module from the interface into the
	implementation.
	(This avoids it being included in the library reference manual).

	Various code cleanups, in particular fix spacing and
	indentation throughout.

library/rational.m:
	Add function rational/1 that converts an int to a rational and
	function from_integer/1 that does the same with an integer.

	For consistency with the above add a function from_integers/2 and
	deprecate the version rational_from_integers/2.

	Remove the functions izero and ione from the implementation and
	just call integer.zero/0 and integer.one/0 now that they are
	exported from the integer module again.

	Various code cleanups.
2003-12-18 07:48:19 +00:00
Fergus Henderson
78a61c514c Delete some unused procedures warned about by --warn-dead-procs.
Estimated hours taken: 1.75
Branches: main

Delete some unused procedures warned about by --warn-dead-procs.

library/eqvclass.m:
library/integer.m:
library/io.m:
library/list.m:
library/relation.m:
library/string.m:
library/term.m:
	Delete the following procedures:
		eqvclass.find_partition/3
		integer.int_max/0
		io.buffer_to_string/3
		list.qsort/3
		list.partition/4
		relation.tsort_2/6
		relation.tsort_3/6
		string.to_int_list/2,
		string.int_list_to_char_list/2,
		string.char_list_to_int_list
		term.require_equal/2
		term.contains_functor/3
		term.subterm/2

library/exception.m:
library/set_bbbtree.m:
library/tree234.m:
	Comment out unused modes of
		exception.wrap_success_or_failure/2
		exception.call_goal/2
		exception.call_handler/2
	Comment out unused di/uo modes of
		set_bbbtree.build_node/4
		set_bbbtree.{single,double}_rot_{l,r}/4
		tree234.insert2/4
		tree234.insert3/4
2003-08-17 13:30:13 +00:00
Simon Taylor
d325ed1f4c These modules were unintentionally licensed under the
Estimated hours taken: 0.2
Branches: main, release

library/mer_std.m:
library/rational.m:
library/integer.m:
	These modules were unintentionally licensed under the
	GPL rather than the LGPL.
2002-08-29 10:09:07 +00:00
Simon Taylor
b96ff7a174 Remove functions int:^/2' and integer:^/2', since
Estimated hours taken: 0.1

library/int.m:
library/integer.m:
	Remove functions `int:^/2' and `integer:^/2', since
	the operator `^' is now used for record syntax.

compiler/code_util.m:
	Remove `int:^/2' from the list of builtins.

NEWS:
	Document record syntax and the removal of the above functions.
2000-01-16 04:34:37 +00:00
Simon Taylor
3b00a6e94c Replace integer:^/2' with integer__xor/2' because
Estimated hours taken: 0.1

NEWS:
library/integer.m:
	Replace `integer:^/2' with `integer__xor/2' because
	`^' will be used for record syntax.
1999-12-01 02:54:06 +00:00
Mark Brown
f59b67cdf9 Use `int__xor' instead of the now obsolete '^'.
Estimated hours taken: 0.1

library/integer.m:
	Use `int__xor' instead of the now obsolete '^'.
1999-11-04 04:41:07 +00:00
Fergus Henderson
1b8834f807 Incorporate Dan Hazel's rewrite of library/integer.m into the standard
Estimated hours taken: 2
	(+ unknown time from Dan Hazel)

Incorporate Dan Hazel's rewrite of library/integer.m into the standard
library, with the following changes:
	- I added determinism declarations for a couple of functions,
	  so that it compiles with `--no-infer-all'.
	- I deleted the functions `integer__zero', `integer__one', ...,
	  `integer__ten' and `integer__intmax' from the interface,
	  since I don't think they are sufficiently useful.
	- I changed the messages in the calls to error/1 to be
	  a bit more consistent

The log message below is Dan Hazel's original description of his
changes revised a little by me.

library/integer.m:
	integer.m was a bit sleepy to be of effective use so I've butchered
	it.  Sincere apologies to author aet (I'm not sure who you are.)
	I've followed some of the suggested "Possible improvements:" in the
	preface and rewritten all of the code using a different data
	structure.

	i)   Previously stored as a "sign" and list of integers of base 10000
	     ordered least significant to most.
	     My problems with this are:
		It doesn't sort into an intuitive order using mercury's compare
		(for solutions output for example).
		It makes div/mod too slow.
		The benefits -- simpler algorithms for `+' `*' -- are not cost
		benefits (which I think should be the priority in a library)
		as aet is walking the full list to normalise anyway.
	     ** Now stored as a "sign" which also stores the list length and
		a list of all +ve or all -ve digits of base 2^14 ordered most
		significant to least.
		The conversion to base 10 string is more complex of course.
		It's no longer quite arbitrary precision - something like
		    (2^14)^maxint

	ii)  Normalisation was being done as a separate pass and too often.
	     This was the most expensive part if I remember.
	     ** Almost all normalisation is now done on the fly (you're down
		there anyway).

	iii) The new data structure reduces comparison to mercury term
	     comparison which seems much faster.

	iv)  I've added
		 /\ \/ << >> ^ \

	v)   I've added:
	       :- func integer__float(integer) = float.
	     which will clumsily overflow I imagine (fix if you care); and
	       :- func integer__int(integer) = int.
	     which checks for overflow and calls error/1 in that case.

	vi)  Normalising can now be done using machine arithmetic.

	vii) There's a new pow algorithm which works by shifting the exponent.

	viii)
	     The procedure/function names should be recognisable but
	     much of the code is completely rewritten.  Sorry if it's
	     clumsy and ugly.
1999-11-04 02:39:17 +00:00
Fergus Henderson
ce403ce9d5 Fix a bug in the definition of `big_plus': it wasn't handling the
Estimated hours taken: 0.5

library/integer.m:
	Fix a bug in the definition of `big_plus': it wasn't handling the
	cases where the sign was zero correctly.   I added some additional
	code to handle those cases.

	Also a few cosmetic changes to make the layout more consistent.
1999-09-02 17:08:20 +00:00
Fergus Henderson
65782f9925 Add functions for the single output det predicates in a number
Estimated hours taken: 5

[This change was by Ralph Becket.
I'm just the person who reviewed it and committed it.  -fjh.]

Add functions for the single output det predicates in a number
of modules in the standard library.  Basically, for each

	:- pred f(in, ..., in, out) is det.

I have added the declaration

	:- func f(in, ..., in) = out.

and definition

	f(X1, ..., Xn) = Y :-
		f(X1, ..., Xn, Y).

library/char.m:
library/dir.m:
library/map.m:
library/string.m:
library/list.m:
library/set.m:
	Make the changes described above.

library/array.m:
	As above, except array input modes are all array_ui or
	array_di as appropriate and array output modes are array_uo.

library/int.m:
	Added forward versions of +/2, */2 and -/2 as plus/2, times/2
	and minus/2 respectively, to make it easier to pass these
	as arguments to higher-order predicates.
	Also added func constants for max_int, min_int and bits_per_int.

library/integer.m:
	Replaced local functions for list head, tail and length with
	calls to equivalent functions now defined in list.m.

library/io.m:
	Added func for error_message/2.

library/list.m:
	Add functions det_head/1 and det_tail/1 which abort on null lists.

library/set.m:
	Add functions map/2, filter_map/2 and fold/3.

library/std_util.m:
	Added utility function to construct a pair object from its
	arguments and general purpose higher order functions for
	partial functions and for function composition, exponentiation
	and exchanging the arguments of a binary function.
1999-07-07 15:19:42 +00:00