summaryrefslogtreecommitdiffstats
path: root/arith.c
Commit message (Collapse)AuthorAgeFilesLines
* First cut at signal handling support.Kaz Kylheku2013-12-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.
* * arith.c, hash.c, lib.c, rand.c, stream.c, syslog.c: RemovingKaz Kylheku2013-12-111-1/+0
| | | | | include <assert.h> since none of these modules uses the standard C assert macro.
* Bumping copyrights to 2014 and expressing them as year ranges.Kaz Kylheku2013-12-101-3/+1
| | | | Fixing some errors in copyright comments.
* syslog support; bitwise logior and logand functions become variadic.Kaz Kylheku2013-12-101-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | * Makefile: Use -iquote to restrict our #include search paths from being processed for #include <...>. Add syslog.o to OBJS-y if have_syslog is y. * configure (have_syslog): New variable, set by detecting syslog API. * eval.c (eval_init): logand and logior registrations changed to go to variadic versions. New syslog variables and functions registered. * lib.c (logandv, logiorv): New functions. * lib.h (logandv, logiorv): Declared. * txr.c (main): Call syslog_init. * syslog.c: New file. * syslog.h: New file. * txr.1: Updated. * txr.vim: Regenerated.
* * arith.c (bignum_from_long): New function.Kaz Kylheku2012-10-011-0/+11
| | | | | | | | | * arith.h (bignum_from_long): Declared. * lib.c (int_str): Streamlined. Only use mp_read_radix in the case when wcstol fails, because now we have bignum_from_long to handle all values of long. Ensure that the bignum is normalized, in case it falls in the fixnum range (does not happen on our usual platforms).
* * arith.c (logand): Fix incorrect return value.Kaz Kylheku2012-09-241-1/+1
|
* * arith.c (logtest): New function.Kaz Kylheku2012-09-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Registered logtest. Registered s-ifmt, s-iflnk, s-ifreg, s-ifblk, s-ifdir, s-ifchr, s-ififo, s-isuid, s-isgid, s-isvtx, s-irwxu, s-irusr, s-iwusr, s-ixusr, s-irwxg, s-irgrp, s-iwgrp, s-ixgrp, s-irwxo, s-iroth, s-iwoth, s-ixoth variables. * lib.h (logtest): Declared. * stream.c (s_ifmt, s_ifsock, s_iflnk, s_ifreg, s_ifblk, s_ifdir, s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu, s_irusr, s_iwusr, s_ixusr, s_irwxg, s_irgrp, s_iwgrp, s_ixgrp, s_irwxo, s_iroth, s_iwoth, s_ixoth): New global variables. * stream.h (s_ifmt, s_ifsock, s_iflnk, s_ifreg, s_ifblk, s_ifdir, s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu, s_irusr, s_iwusr, s_ixusr, s_irwxg, s_irgrp, s_iwgrp, s_ixgrp, s_irwxo, s_iroth, s_iwoth, s_ixoth): Declared. * txr.1: Documented logtest and s-* variables for stat, as well as open-file and open-directory.
* * arith.c (comp_trunc, logcomp): logcomp renamed to lognot,Kaz Kylheku2012-09-171-6/+6
| | | | | | | | consistent with Common Lisp. * eval.c (eval_init): logcomp to lognot. * lib.h (logcomp): Declaration updated.
* * arith.c (highest_significant_bit): New static function.Kaz Kylheku2012-09-171-4/+116
| | | | | | | | | | | | | | | | (comp_clamp): Bugfix: avoid shifting left into sign bit. Function renamed to comp_trunc. (logtrunc, ash): New functions. * eval.c (eval_init): Registered logtrunc and ash intrinsics. * lib.h (logtrunc, ash): Declared. * mpi-patches/add-bitops (s_highest_bit_mp): Forward declaration for added. (mp_clamp_comp): Bugfix in handling remainder bits. Function renamed to mp_trunc_comp. (mp_trunc, mp_shift): New functions.
* * arith.c (logand, logior, logxor): Bugfix: result needs to beKaz Kylheku2012-09-161-4/+47
| | | | | | | | | | | | | | normalized, otherwise we end up with fixnum-range bignums. (comp_clamp): New function. (logcomp): Changed to two argument form. If second argument is present (not nil) then call comp_clamp. * eval.c (eval_init): Change registration of logcomp to allow optional argument. * lib.h (logcomp): Declaration updated. * mpi-patches/add-bitops: New mp_clamp_comp function implemented.
* Adding complementing function.Kaz Kylheku2012-09-161-0/+20
| | | | | | | | | | * arith.c (logcomp): New function. * eval.c (eval_init): logcomp registered as intrinsic. * lib.h (logcomp) declared. * mpi-patches/add-bitops: Fixed bugs in mp_xor. Implemented mp_comp.
* Starting work on adding bit operations. The semantics is thatKaz Kylheku2012-09-161-0/+123
| | | | | | | | | | | | | | negative integers behave as an "infinite bit two's complement". * arith.c (logand, logor, logxor): New functions. * eval.c (eval_init): New intrinsic functions logand, logior, logxor. * lib.h (logand, logor, logxor): Declared. * mpi-patches/series: New patch, add-bitops. * mpi-patches/add-bitops: New file.
* * arith.c (plus): Fixed broken (+ fixnum char) case.Kaz Kylheku2012-04-241-2/+2
|
* * arith.c (INT_PTR_MAX_MP): New static variable.Kaz Kylheku2012-04-101-1/+8
| | | | | | | | | | | | | | | (in_int_ptr_range): New function. (arith_init): Initialize INT_PTR_MAX_MP. * arith.h (in_int_ptr_range): Declared. * lib.c (c_num): Allow bignums to be converted to a cnum, if they are in range, rather than allowing only fixnums. * rand.c (make_random_state): Now that we have such a function, initialize random seed using time value from time_sec_usec rather than from time and clock. clock is bad for random seeding because it measures virtual time since the start of the process.
* NetBSD port.Kaz Kylheku2012-04-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | * arith.c (bignum_dbl_ipt): Added missing #if HAVE_DOUBLE_INTPTR_T around function * configure: NetBSD's shell is too pathetic to expand "$@" properly when there are no positional arguments, so I applied the ${@+"$@"} trick. (make): New variable. GNU make might be known only as gmake, so we now detect the command for our own use within the configure script and also for giving the user advice on what command to use for building. Put in a fix so that the attempt to run $make --version does not bail the script under "set -e" if that command terminates unsuccessfully. The check for clashing names has been moved earlier, so that the renaming #define's appear early in config.h (so config.h itself can rely on the renames). The identifier longlong_t has been added to the potential clash list. NetBSD exposes this identifier in spite of -D_POSIX_SOURCE=2, and it clashes with our longlong_t. The tests for integers wider than long long has been modified to actually compile a multiplication of two long-long-s into the wider precision. On the NetBSD system, with gcc 4.1.3, I found that the __int128 type is there, but doesn't actually work; compilation of arith.c bails with an internal compiler error. We now get this internal error at configure time and avoid using the type.
* * arith.c (bignum): Previously static function now exposed as external.Kaz Kylheku2012-04-081-1/+1
| | | | | | | | | | | | | | | | | | | | * arith.h (bignum): Declared. * configure: Added check for tm_gmtoff and tm_tmzone fields being present in struct tm. * eval.c (eval_init): New intrinsic functions: time, time-usec. * lib.c (num): If the cnum is outside of the fixnum range, then construct a bignum. (time_sec, time_sec_usec): New functions. * lib.h (mut): Slight change to macro to eliminate compiler warning. (time_sec, time_sec_usec): Declared. * txr.1: Stub section for time and time-usec. * txr.vim: Highlighting for time and time-usec.
* * arith.c (numeq): Fix misplaced parenthesis.Kaz Kylheku2012-03-291-1/+1
|
* * arith.c (numeq): New function.Kaz Kylheku2012-03-291-2/+41
| | | | | | | | | | | | | | | | | (exptmod): Bugfix: was no normalizing the bignum, ouch. Also was reporting "non-integral operands" for other errors. * eval.c (eval_init): Registered = intrinsic function. * lib.c (numeqv): New function. * lib.h (numeq, numeqv): Declared. * txr.1: Documented expt, sqrt, isqrt, exptmod, fixnump, bignump, integerp, floatp, numberp, zerop, evenp, oddp, >, <, >=, <= and =. * txr.vim: Highlight =
* * arith.c (gcd): Allow zeros. Don't issue "non-integral"Kaz Kylheku2012-03-291-1/+26
| | | | | | | | | | | | | | | exception if MPI fails. (floorf, ceili): Map integer argument to itself. (tang, asine, acosi): New functions. * eval.c (eval_init): New intrinsics: tan, asin, acos. * lib.h (tang, asine, acosi): Declared. * txr.1: Documented gcd, abs, floor, ceil, sin, cos, tan asin, acos, atan, log, and exp. * txr.vim: Highlighting for tang, asine, acosi.
* * arith.c (dmod): New static function.Kaz Kylheku2012-03-291-3/+14
| | | | | | | | (mod): Use dmod instead of fmod directly, to calculate the correct semantics for combinations of negative operands in the floating point domain also. * txr.1: Documented /, trunc and mod.
* * arith.c (to_float): Fix unterminated argument list in throwf.Kaz Kylheku2012-03-261-1/+1
| | | | * lib.c (funcall): Likewise.
* * arith.c (expo): New function.Kaz Kylheku2012-03-221-0/+5
| | | | | | | | | | * eval.c (eval_init): expo registered as intrinsic exp. * lib.h (expo): Declared. * txr.1: Added to stub heading. * txr.vim: Highlighting for exp.
* Fix sqrt confusion. There must be a separate isqrtKaz Kylheku2012-03-221-12/+10
| | | | | | | | | | | | | | | | | for the integer square root. * arith.c (sqroot_fixnum): Renamed back to isqrt_fixnum. (sqroot): Rewritten to handle only floating-point square root. (isqrt): New function, based on previous sqroot, handles only integers. * eval.c (eval_init): New intrinsic, isqrt. * lib.h (isqrt): New declaration. * txr.1: Doc stubs. * txr.vim: Highlighting for isqrt.
* * arith.c (floorf, ceili, sine, cosi, atang, loga): New functions.Kaz Kylheku2012-03-221-0/+30
| | | | | | | | | | | * eval.c (eval_init): New intrinsic functions registered: floor, ceil, sin, cons, atan, log. * lib.h (floorf, ceili, sine, cosi, atang, loga): Declared. * txr.1: Doc stub section for new functions. * txr.vim: Highighting added.
* * arith.c (int_flo): If sprintf produces somethingKaz Kylheku2012-03-221-0/+6
| | | | | | | | that doesn't begin with a digit, it's most likely NaN or Inf. We can turn that into an exception. * stream.c (vformat): If sprintf produces a non-number, turn it into the printed representation #<bad-float>.
* * arith.c (to_float): New static function.Kaz Kylheku2012-03-221-135/+181
| | | | | | | | | | | | | (divi): Uses to_float. (zerop, gt, lt, ge, le, expt): Floating support. (isqrt_fixnum): Static function renamed to sqroot_fixnum. (isqrt): Renamed to sqroot. Floating support. (evenp, oddp, exptmod, gcd): Work with integers, not floats. * eval.c (eval_init): intrinsic registration of sqrt follows rename of isqrt to sqroot. * lib.h (isqrt): Declaration replaced.
* * arith.c (divi): New function.Kaz Kylheku2012-03-211-0/+38
| | | | | | | | | | * eval.c (eval_init): divi registered as / intrinsic. * lib.h (divi): Declared. * txr.1: divi added to stub heading. * txr.vim: / operator highlighted.
* * arith.c (mod): Floating support.Kaz Kylheku2012-03-211-82/+103
|
* * arith.c (trunc): Floating support.Kaz Kylheku2012-03-211-34/+73
|
* * arith.c (plus, minus, mul): Removing unnecessary type checks,Kaz Kylheku2012-03-211-7/+0
| | | | which are already implied by the switch case.
* * Makefile: link in -lm, which is needed now on some systems.Kaz Kylheku2012-03-211-56/+89
| | | | | * arith.c (plus, minus): Eliminated some unnecessary (double) casts. (abso, mul): Floating support.
* * arith.c (neg): Floating-point support.Kaz Kylheku2012-03-211-7/+13
| | | | | | | | | | | | | * parser.l: FLO and FLODOT cases had to be reordered because the lex trailing context counts as part of the match length, causing 3.0 to be matched as three characters with 0 as the trailing context. The cases are split up to eliminate a flex warning. * stream.c (vformat): Support bignum in floating point conversion. Bugfixes: floating point conversion was accessing obj->fl.n instead of using n. Changed some if/else ladders to switches.
* * arith.c (plus): Minor code simplification.Kaz Kylheku2012-03-211-56/+73
| | | | | | | | (minus): Floating point support. * mpi-patches/mpi-to-double (mp_to_double): Re-apply lost bugfix: index incremented instead of decremented. Didn't refresh patch last time, then did a make distclean.
* * arith.c (plus): Completed implementation of bignum-floatKaz Kylheku2012-03-201-6/+6
| | | | and float-bignum cases.
* * arith.c (flo_int): New function.Kaz Kylheku2012-03-201-0/+15
| | | | | | | | | | | * eval.c (eval_init): flo-int registered as intrinsic. * lib.h (flo_int): Declared. * mpi-patches/series: Added mpi-to-double to patch stack. (mp_to_double): New MPI function. * mpi-patches/mpi-to-double: New file.
* * arith.c (plus): Optimization: use num_fast whenKaz Kylheku2012-03-201-46/+135
| | | | | | | | | | | | | | | | result is in the fixnum range. Implemented FLNUM cases, except for adding a FLNUM to BGNUM. (minus, mul): Use num_fast when the cnum value is in the fixnum range. (int_flo): New function. * eval.c (eval_init): Register int-flo intrinsic. * lib.c (c_flo): New function. * lib.h (TYPE_SHIFT, TYPE_PAIR): New macros, carried over from the lazy strings branch. (c_flo, int_flo): Declared.
* * arith.c (plus): Showstopper bug: plus(bignum, fixnum)Kaz Kylheku2012-03-041-1/+1
| | | | broken for fixnum <= 0. Bad pointer passed to MPI.
* * arith.c: Updated copyright year.Kaz Kylheku2012-02-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * arith.h: Likewise. * debug.c: Added copyright header. * debug.h: Updated copyright year. * eval.c: Likewise. * eval.h: Likewise. * filter.c: Likewise. * filter.h: Likewise. * gc.c: Likewise. * gc.h: Likewise. * hash.c: Likewise. * hash.h: Likewise. * lib.c: Likewise. * lib.h: Likewise. * match.c: Likewise. * match.h: Likewise. * parser.h: Likewise. * regex.c: Likewise. * regex.h: Likewise. * stream.c: Likewise. * stream.h: Likewise. * txr.c: Likewise, and e-mail address. * txr.h: Updated copyright year. * unwind.c: Likewise. * unwind.h: Likewise.
* * arith.c (plus, minus): Better wording in error messages.Kaz Kylheku2012-01-261-2/+2
| | | | | | | | | | | | | | | | | | * eval.c (dwim_loc): Assignments to string indices and ranges supported. New arguments for this purpose. (op_modplace): Use new dwim_loc interface for returned value. (op_dwim): Support assignment to string ranges. (eval_init): replace_str registered. * lib.c (string_extend): If the argument is a number, let it specify the amount by which to extend the string. (replace_str): New function. * lib.h (replace_str): Declared. * txr.1: Updated. * txr.vim: Updated.
* * arith.c (zerop): Misspelling in error message.Kaz Kylheku2012-01-251-1/+1
| | | | | | | * lib.c (sub_list, replace_list, sub_vec, replace_vec): Allow the value t to specify one element past the end, so that t t refers to zero-length sequence just past the end of the array or list. Also, fixed out of bounds memmoves in replace_vec.
* * arith.c (highest_bit): Changing to external linkage.Kaz Kylheku2011-12-231-1/+1
| | | | | | | | * arith.h (highest_bit): Declared. * rand.c (random): Rewrote using different algorithm which ensures even distribution, and avoids doing a bignum mod operation.
* Bug #35136 and cleanup.Kaz Kylheku2011-12-221-32/+28
| | | | | | | | | | | * arith.c (plus, minus, mul, gt, ge, lt, le, exptmod, gcd): Remove trailing abort; we already marked uw_throwf as noreturn. This hack should not be needed in functions where the last statement is a throw. (trunc, expt): Repeated error case handled in one place. Temp variable used to avoid two calls to mp_clear. Call to abort removed. (mod): Repeated error handed in one place. Plugged memory leak by moving throw past mp_clear calls. Call to abort removed. (isqrt): Repeated error case handed in one place.
* * arith.c (normalize): Linkage changed to extern.Kaz Kylheku2011-12-211-1/+1
| | | | | | | | * arith.h (normalize): Declared. * rand.c (random): Bugfix: normalize the bignum before returning it. * txr.1: Doc stubs for PRNG functionality.
* * arith.c (abso): broken for fixnums.Kaz Kylheku2011-12-141-1/+1
|
* * arith.c (minus): Allow difference between characters.Kaz Kylheku2011-12-141-0/+1
|
* * arith.c (plus, minus, gt, lt, ge, le): Handle character operands.Kaz Kylheku2011-12-141-0/+56
| | | | | | | | | | * eval.c (eval_init): New functions interned. * lib.c (num_chr, chr_num): New functions. * lib.h (num_chr, chr_num): Declared. * txr.1: Documentation stubs.
* * arith.c (exptmod, gcd): New functions.Kaz Kylheku2011-12-131-0/+53
| | | | | | | | * eval.c (eval_init): New functions registered as intrisics. * lib.h (exptmod, gcd): Declared. * txr.1: Documentation stubs added.
* * arith.c (evenp, oddp): New functions.Kaz Kylheku2011-12-131-0/+30
| | | | | | | | * eval.c (eval_init): New functions registered as intrinsics. * lib.h (evenp, oddp): Declared. * txr.1: Documentation stub updated.
* * arith.c (highest_bit): Linkage changed to static.Kaz Kylheku2011-12-131-1/+43
| | | | | | | | | | | | | | | | | (abso, isqrt): New functions. (isqrt_fixnum): New static function. * eval.c (eval_init): Registered abs, sqrt and numberp instrinsics. * lib.c (numberp): New function. * lib.h (numberp, abso, isqrt): Declared. * mpi-patches/series: New patch added. * mpi-patches/faster-square-root: New patch added. * txr.1: Documentation stubs for new functions.
* * arith.c (expt): Fix broken bignum x fixnum combination.Kaz Kylheku2011-12-131-1/+1
|