1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

7681 commits

Author SHA1 Message Date
Andy Wingo
6871327742 Micro-optimize char_decimal_value.
* libguile/numbers.c (char_decimal_value): A wee micro-optimization.
2013-08-31 11:15:01 +02:00
Andy Wingo
25752c4d1c Faster scm_from_port_stringn
* libguile/strings.c (scm_from_port_stringn): Always inline to
  scm_from_utf8_string if the byte sequence is valid utf-8.
2013-08-31 10:57:11 +02:00
Andy Wingo
be7ecef05c unread-char: inline conversion from codepoint to bytes
* libguile/ports.c (scm_ungetc_unlocked): Inline the conversion from
  codepoint to bytes for UTF-8 and latin-1 ports.  Speeds up a
  numbers-reading test case by 100% (!).
2013-08-31 10:44:07 +02:00
Andy Wingo
e063995db8 rtl vm: box-set! binds no values
* libguile/vm-engine.c (box-set!): Remove the OP_DST flag.
2013-08-24 15:40:29 +02:00
Mark H Weaver
84cc4127bd RTL: 'return-values' instruction assumes 'reset-frame' has been called.
* libguile/vm-engine.c (return-values): Remove NVALUES operand.
  Don't reset the frame.

* test-suite/tests/rtl.test ("cached-toplevel-set!"): Adapt to the fact
  that 'return-values' has no operand now, and that 'reset-frame' must
  be done first.
2013-08-24 15:27:50 +02:00
Mark H Weaver
adb8d905df RTL VM: Rename 'apply' instruction to 'tail-apply'.
* libguile/vm-engine.c (apply, tail-apply): apply -> tail-apply.
  (RETURN_VALUE_LIST): goto op_apply -> goto op_tail_apply.

* libguile/vm.c (rtl_apply_code): scm_rtl_op_apply ->
  scm_rtl_op_tail_apply.
2013-08-24 15:22:17 +02:00
Mark H Weaver
e79ed6b1d7 RTL VM: fix multiple value returns.
* libguile/vm-engine.c (halt): Fix off-by-one error in retrieving
  multiple values from the frame.
2013-08-24 15:20:56 +02:00
Mark H Weaver
c099201da1 In bytevector->uint-list et al, check that SIZE divides the bv length.
Fixes <http://bugs.gnu.org/15100>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/bytevectors.c (INTEGERS_TO_LIST): Enforce the R6RS
  requirement that SIZE divides the bytevector length.

* test-suite/tests/bytevectors.test: Add test.  Remove tests that
  assumes that this "divides" check is not enforced.
2013-08-16 23:13:54 -04:00
Mark H Weaver
88cff2ef1b Merge remote-tracking branch 'origin/stable-2.0' 2013-08-16 23:05:34 -04:00
Mark H Weaver
088cfb7d76 Improved error checking in bytevector->uint-list and bytevector->sint-list.
Partially fixes <http://bugs.gnu.org/15100>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/bytevectors.c (INTEGERS_TO_LIST): Make sure SIZE isn't 0.
  Allow SIZE to be greater than the bytevector length, for consistency
  with allowing extra bytes at the end when the bytevector length is
  non-zero.  Use scm_from_size_t instead of scm_from_uint.

* test-suite/tests/bytevectors.test: Add tests.  Remove a test that
  checks for an exception when SIZE is greater than the bytevector
  length.
2013-08-16 22:54:39 -04:00
Mark H Weaver
062888f7bb RTL VM: Fix SCM_PACK_RTL_* macros.
* libguile/instructions.h (SCM_PACK_RTL_8_8_8): Fix typo.
  (SCM_PACK_RTL_16_8): Fix erroneous shift offset.
2013-08-12 13:50:19 -04:00
Mark H Weaver
1160e2d94e Merge remote-tracking branch 'origin/stable-2.0' 2013-08-11 22:46:22 -04:00
Andy Wingo
af95414f1d Various RTL VM and calling convention tweaks
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Allow for
  five-word instructions, and for new instruction word types.

* libguile/vm-engine.c (RETURN_ONE_VALUE): Instead of returning the
  value in the fixed part of the call frame, return it in the same place
  multiple-value returns go: from slot 1.
  (BR_ARITHMETIC): Allow arithmetic tests to be negated.
  (rtl_vm_engine): Change calling convention to use the same location
  for single and multiple-value returns.  Renumber all instructions.

  (halt, halt/values): Fold into a single instruction (halt).
  (call): Take the location of the procedure instead of the location of
  the call frame.  Also take the number of args, and reset the sp before
  jumping to the procedure, so as to indicate the number of arguments.
  (call/values): Remove, as the new calling convention has RA == MVRA.
  (tail-call): Require the procedure to be shuffled down already, and
  take "nlocals" as an arg instead of "nargs".
  (receive, receive-values): New instructions, for receiving returned
  values from calls.
  (return-values): Rename from return/values.  Remove "values".
  (alloc-frame): Rename from reserve-locals.
  (reset-frame): New instruction.
  (drop-locals): Remove.
  (br-if-=, br-if-<, br-if-<=): Allow these instructions to be
  negatable.
  (br-if->, br-if->=): Remove.  Probably a bad idea, given NaN.
  (box-ref): Don't bother trying to do a reverse lookup -- the
  toplevel-box, module-box, and resolve instructions should handle
  that.
  (resolve): Add arg to check that the variable is bound.
  (toplevel-box, module-box): New instructions, replacing toplevel-ref,
  toplevel-set, module-ref, and module-set.

* libguile/vm.c (rtl_boot_continuation_code, rtl_values_code): Adapt to
  instruction set changes.

* module/Makefile.am: Make the assembler and disassembler dependent on
  vm-operations.h.

* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm: Adapt to instruction changes and
  new instruction word kinds.

* test-suite/tests/rtl.test: Adapt to instruction set changes.
2013-08-11 16:45:31 +02:00
Mark H Weaver
6f82b8f623 Fix inappropriate uses of scm_syserror in numbers.c.
* libguile/numbers.c (mem2ureal, left_shift_exact_integer,
  floor_right_shift_exact_integer, round_right_shift_exact_integer):
  Use 'assert' instead of 'scm_syserror' to indicate a case that should
  never happen.
2013-08-10 11:53:23 -04:00
Mark H Weaver
b7c1b60c83 dereference-pointer: check for null pointer.
* libguile/foreign.c (scm_dereference_pointer): Check for attempts to
  dereference a null pointer.

* test-suite/tests/foreign.test ("null pointer"): Add test.
2013-08-09 18:26:07 -04:00
Mark H Weaver
fa102e73c3 Fix numerator and denominator handling of signed zeroes and infinities.
* libguile/numbers.c (scm_numerator, scm_denominator): Handle signed
  zeroes and infinities in accordance with the corresponding R6RS flonum
  procedures.

* module/rnrs/arithmetic/flonums.scm (flnumerator, fldenominator):
  Remove special handling of infinities.

* test-suite/tests/numbers.test (numerator, denominator): Add tests.
  Convert existing tests to use 'pass-if-equal'.

* test-suite/tests/r6rs-arithmetic-flonums.test (flnumerator): Fix
  broken test of (flnumerator -0.0).
2013-08-09 06:09:56 -04:00
Mark H Weaver
056e3470c4 Eliminate use of deprecated 'SCM_WTA_DISPATCH_2' in numbers.c.
* libguile/numbers.c (scm_gcd): Use 'scm_wta_dispatch_2' not
  'SCM_WTA_DISPATCH_2'.
2013-08-08 02:19:46 -04:00
Mark H Weaver
789dd40b8b Fix --without-threads and SCM_DEBUG_TYPING_STRICTNESS==2 builds.
* libguile/hashtab.c (scm_hashv_ref, scm_hashv_set_x,
  scm_hashv_remove_x, scm_hash_ref, scm_hash_set_x, scm_hash_remove_x):
* libguile/strports.c (scm_mkstrport):
* libguile/weak-vector.c (weak_vector_ref): Add missing SCM_UNPACK.

* libguile/ports.c (lock_port, unlock_port): Cast MUTEX to the
  expected type.
2013-08-08 01:23:04 -04:00
Mark H Weaver
6dce942c46 String ports use UTF-8; ignore %default-port-encoding.
* libguile/strports.c (scm_mkstrport): Use UTF-8; ignore
  %default-port-encoding.  Rename 'str_len' and 'c_pos' to
  'num_bytes' and 'c_byte_pos'.  Interpret 'pos' argument
  as a character index instead of a byte index.

* module/ice-9/boot-9.scm (%cond-expand-features): Add srfi-6 to the
  list of core features.

* module/srfi/srfi-6.scm (open-input-string, open-output-string): Simply
  re-export these, since the core versions are now compliant.

* doc/ref/api-io.texi (String Ports): Remove text that describes
  non-compliant behavior of string ports with regard to encoding.

* doc/ref/srfi-modules.texi (SRFI-0): Add srfi-6 to the list of
  core features.
  (SRFI-6): Remove text that mentions non-compliant behavior of
  core string ports.

* module/ice-9/format.scm (format):
* module/ice-9/pretty-print.scm (truncated-print):
* module/rnrs/io/ports.scm (open-string-input-port,
  open-string-output-port):
* test-suite/test-suite/lib.scm (format-test-name):
* test-suite/tests/chars.test ("combining accent is pretty-printed",
  "combining X is pretty-printed"):
* test-suite/tests/ecmascript.test (eread, eread/1):
* test-suite/tests/rdelim.test:
* test-suite/tests/reader.test (read-string):
* test-suite/tests/regexp.test:
* test-suite/tests/srfi-105.test (read-string): Don't set
  %default-port-encoding before creating string ports.

* benchmark-suite/benchmarks/ports.bm (%latin1-port): Use
  'set-port-encoding!' to set the string port encoding.
  (%utf8/ascii-port, %utf8/wide-port, "rdelim"): Don't set
  %default-port-encoding before creating string ports.

* test-suite/tests/r6rs-ports.test ("lookahead-u8 non-ASCII"): Don't set
  %default-port-encoding before creating string ports.
  ("put-bytevector with UTF-16 string port", "put-bytevector with
  wrong-encoding string port"): Use 'set-port-encoding!' to set the
  string port encoding.

* test-suite/tests/print.test (tprint): Use 'set-port-encoding!' to set
  the string port encoding.
  ("truncated-print"): Use 'pass-if-equal'.

* test-suite/tests/ports.test ("encoding failure leads to exception",
  "%default-port-encoding is honored", "peek-char [latin-1]", "peek-char
  [utf-8]", "peek-char [utf-16]"): Remove tests.
  ("%default-port-encoding is ignored", "peek-char"): Add tests.
  ("suitable encoding [latin-1]", "suitable encoding [latin-3]",
  "wrong encoding, error", "wrong encoding, substitute",
  "wrong encoding, escape"): Use 'set-port-encoding!' to set the
  string port encoding.
  ("%default-port-encoding, wrong encoding"): Rewrite to use
  a file port instead of a string port.
2013-08-07 01:22:22 -04:00
David Kastrup
b4a099883d Fix display of symbols containing backslashes.
Fixes <http://bugs.gnu.org/15033>.

* libguile/print.c (print_extended_symbol): Double print backslashes.

Signed-off-by: Mark H Weaver <mhw@netris.org>
2013-08-06 18:01:54 -04:00
Mark H Weaver
d8d7c7bf57 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/numbers.c
	libguile/vm-i-scheme.c
2013-08-06 17:37:34 -04:00
Mark H Weaver
e7f64971ed RTL VM: Avoid untagging inums in 'logand' and 'logior'.
* libguile/vm-engine.c (logand, logior): Avoid untagging.
2013-08-06 17:03:56 -04:00
Mark H Weaver
d2295ba571 RTL VM: Avoid signed overflows in 'add1' and 'sub1'.
* libguile/vm-engine.c (INUM_MIN, INUM_MAX): Redefine without making
  assumptions about the representation.
  (INUM_STEP): New macro.
  (add1, sub1): Avoid signed overflows, and use INUM_STEP.
2013-08-06 17:00:23 -04:00
Mark H Weaver
0bd659658b RTL VM: ash: Use SCM_SRS and fix large right shifts in fast path.
* libguile/vm-engine.c (ash): Use SCM_SRS, and handle large right
  shifts properly.
2013-08-06 16:51:41 -04:00
Mark H Weaver
ca7b6f6869 VM: ash: Use SCM_SRS and handle large right shift in fast path.
* libguile/vm-i-scheme.c (ash): Use SCM_SRS.  Handle inum right shift by
  more than SCM_I_FIXNUM_BIT-1 bits in fast path.
2013-08-06 16:38:32 -04:00
Mark H Weaver
19374ad2de Use Gnulib's 'isfinite' in numbers.c.
* libguile/numbers.c (DOUBLE_IS_FINITE, DOUBLE_IS_POSITIVE_INFINITY,
  DOUBLE_IS_NEGATIVE_INFINITY): Remove.
  (scm_odd_p, scm_even_p, scm_finite_p, icmplx2str, scm_rational_p,
  scm_inexact_to_exact): Use 'isfinite' instead of 'DOUBLE_IS_FINITE'.
2013-08-06 16:26:46 -04:00
Mark H Weaver
e1592f8a40 Use Gnulib's 'copysign' in numbers.c.
* libguile/numbers.c (double_is_non_negative_zero): Remove.
  (idbl2str, scm_max, scm_min, scm_angle, log_of_shifted_double,
  scm_log10): Use 'copysign' to check signs of zeroes,
  instead of 'double_is_non_negative_zero'.
2013-08-06 16:21:26 -04:00
Mark H Weaver
48b6f151c7 VM: ASM_ADD and ASM_SUB for x86: clobber _CX not "rcx".
* libguile/vm-i-scheme.c (ASM_ADD, ASM_SUB): Clobber _CX not "rcx".
2013-08-04 19:39:43 -04:00
Mark H Weaver
afa3c37ddc VM: Define ASM_MUL on ARM only if SMULL instruction is supported.
* libguile/vm-i-scheme.c (ASM_MUL): Define only if the target
  architecture is known to implement the SMULL instruction.
2013-08-04 18:06:07 -04:00
Mark H Weaver
f91a1864c3 VM: Implement ASM_ADD, ASM_SUB, and ASM_MUL for ARM processors.
* libguile/vm-i-scheme.c (ASM_ADD, ASM_SUB, ASM_MUL): Implement for ARM.
2013-08-04 04:16:57 -04:00
Mark H Weaver
b2df1682df VM: Avoid untagging inums in 'logand' and 'logior'.
* libguile/vm-i-scheme.c (logand, logior): Avoid untagging.
2013-08-03 15:09:36 -04:00
Mark H Weaver
4fa65b903b VM: Add ASM_MUL for x86.
* libguile/vm-i-scheme.c (ASM_MUL): New macro.
  (mul): Use ASM_MUL if available.
2013-08-03 15:05:59 -04:00
Mark H Weaver
9f6211707b VM: Support 32-bit x86 in ASM_ADD and ASM_SUB.
* libguile/vm-i-scheme.c (_CX): New macro.
  (ASM_ADD, ASM_SUB): Replace references to "rcx" with _CX.
2013-08-03 15:02:41 -04:00
Mark H Weaver
ddf4ff2475 VM: Add "cc" to the clobber list of ASM_ADD and ASM_SUB.
* libguile/vm-i-scheme.c (ASM_ADD, ASM_SUB): Add "cc" to the clobber
  list.  Suggested by Göran Weinholt <goran@weinholt.se>.
2013-08-03 14:59:54 -04:00
Mark H Weaver
4350c15673 VM: Avoid overflow in ASM_ADD when the result is most-positive-fixnum.
* libguile/vm-i-scheme.c (ASM_ADD): Remove the tag from one of the
  operands before adding, to avoid overflow when the result is the most
  positive fixnum.
2013-08-03 14:51:07 -04:00
Mark H Weaver
cb1482e719 VM: Avoid signed overflows in 'add1' and 'sub1'.
* libguile/vm-i-scheme.c (INUM_STEP): New macro.
  (add1, sub1): Avoid signed overflows, and use INUM_STEP.
2013-08-03 14:46:40 -04:00
Mark H Weaver
478fa0d530 VM: Redefine INUM_MIN and INUM_MAX without assumptions.
* libguile/vm-i-scheme.c (INUM_MIN, INUM_MAX): Redefine to avoid
  assumptions about the representation of inums.
2013-08-03 14:32:04 -04:00
Mark H Weaver
00472a22bb Add 'scm_i_from_double' and use it.
* libguile/numbers.c (scm_i_from_double): New static function.
  (scm_from_double): Just call 'scm_i_from_double'.
  (scm_inf, scm_nan, scm_abs, scm_i_inexact_floor_quotient,
  scm_i_inexact_floor_remainder, scm_i_inexact_floor_divide,
  scm_i_inexact_ceiling_quotient, scm_i_inexact_ceiling_remainder,
  scm_i_inexact_ceiling_divide, scm_i_inexact_truncate_quotient,
  scm_i_inexact_truncate_remainder, scm_i_inexact_truncate_divide,
  scm_i_inexact_centered_quotient, scm_i_inexact_centered_remainder,
  scm_i_inexact_centered_divide, scm_i_inexact_round_quotient,
  scm_i_inexact_round_remainder, scm_i_inexact_round_divide,
  scm_max, scm_min, scm_sum, scm_difference, scm_product,
  scm_divide, scm_truncate_number, scm_round_number, scm_floor,
  scm_ceiling, scm_expt, scm_sin, scm_cos, scm_tan, scm_sinh,
  scm_cosh, scm_tanh, scm_asin, scm_acos, scm_atan, scm_sys_asinh,
  scm_sys_acosh, scm_sys_atanh, scm_real_part, scm_imag_part,
  scm_magnitude, scm_angle, scm_exact_to_inexact, log_of_shifted_double,
  log_of_fraction, scm_log10, scm_exp, scm_sqrt, scm_init_numbers):
  Use 'scm_i_from_double' instead of 'scm_from_double'.
2013-08-02 12:04:20 -04:00
Andy Wingo
78ff784784 RTL instructions have no rest args
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE):
* module/system/vm/assembler.scm (assembler):
* module/system/vm/disassembler.scm (disassembler): Remove support for
  RTL instructions with rest args.
2013-07-21 17:12:23 +02:00
Andy Wingo
14d102920f add allocate-struct primitive and rtl opcode
* libguile/struct.h:
* libguile/struct.c (scm_allocate_struct): New interface: allocates a
  struct.

* libguile/vm-engine.c (allocate_struct): Instead of make-struct with a
  rest arg, separate allocation from initialization.
2013-07-21 17:12:22 +02:00
Andy Wingo
b21713128e abort is no longer an op with rest args
* libguile/vm-engine.c (abort): No longer an op with rest args.
2013-07-21 17:12:22 +02:00
Andy Wingo
286a0fb3ae call is no longer a vararg instruction
* libguile/vm-engine.c (push_frame, call): Separate out push_frame from
  call, and expect the caller to arrange the proc and arguments.

* test-suite/tests/rtl.test ("call"): Update tests.
2013-07-21 17:12:22 +02:00
Andy Wingo
7396d21670 RTL: Local 0 is the procedure
* libguile/vm-engine.c: Change the RTL VM to number the procedure as
  local 0, and other locals from 1.  In the future we will want the FP
  to point to local 0 instead of local 1.  In the future also we can
  elide the procedure for well-known closures (closures in which all
  references are known call sites).
  (make_closure, free_set): Instead of taking rest arguments, we add a
  new free-set! op that initializes closures.
  (free_ref): Take the closure as an argument.

* libguile/vm.c (rtl_boot_continuation_code): Remove comments, which
  were out of date.
  (rtl_apply_code, rtl_values_code): Update comments.

* module/system/vm/assembler.scm (intern-constant, emit-init-constants):
  Adapt to locals numbering change.
  (begin-kw-arity): For assert-nargs-ee purposes, nreq includes the
  procedure.

* module/system/vm/disassembler.scm (code-annotation): Adapt annotation
  for assert-nargs-ee/locals.

* test-suite/tests/rtl.test: Adapt tests.
2013-07-21 17:12:22 +02:00
Andy Wingo
2a294c7cd3 rtl: propagate OP_DST to scheme
* libguile/instructions.c (scm_rtl_instruction_list): Add an element to
  the list to indicate that an instruction outputs to its first
  argument.

* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm: Adapt.
2013-07-21 17:12:22 +02:00
Andy Wingo
ee0a2b5135 free variable debugging access procedures for rtl
* libguile/programs.c (scm_program_num_free_variables)
  (scm_program_free_variable_ref, scm_program_free_variable_set_x): Add
  support for RTL programs.
2013-07-21 17:12:22 +02:00
Andy Wingo
081cf91029 fix rtl program arity functions
* libguile/programs.c (parse_arity): Lookup rtl-program-minimum-arity
  from (system vm debug).

* module/system/vm/debug.scm (find-first-arity): Fix the linear search.
  Whoops!
2013-07-21 17:12:21 +02:00
Mark H Weaver
d9e7774fda Fix minor formatting error in 'rationalize'.
* libguile/numbers.c (scm_rationalize): Fix formatting.
2013-07-21 07:20:03 -04:00
Mark H Weaver
620c13e8fc Rewrite 'rationalize' to fix bugs and improve efficiency.
Fixes <http://bugs.gnu.org/14905>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/numbers.c (scm_rationalize): Rewrite.  Previously an
  incorrect algorithm was used which failed in many cases.

* test-suite/tests/numbers.test (rationalize): Add tests.
2013-07-21 06:44:54 -04:00
Mark H Weaver
f82f62944a Merge remote-tracking branch 'origin/stable-2.0' 2013-07-18 15:31:34 -04:00
Mark H Weaver
824b9ad8b7 Modify SCM_UNPACK type check to avoid warnings in clang.
* libguile/tags.h (SCM_UNPACK): Change (*(SCM*)0=(x)) to
  (*(volatile SCM *)0=(x)), to avoid null-dereference warnings
  from clang.  Reported by Shane Celis <shane.celis@gmail.com>.
2013-07-18 14:23:32 -04:00