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

3358 commits

Author SHA1 Message Date
Andy Wingo
bed7bdc19c Fix use of port-encoding
* module/ice-9/ports.scm (clear-stream-start-for-bom-read): Fix to use
  %port-encoding, which works in symbols.
2016-05-05 23:03:04 +02:00
Andy Wingo
0b4b4db9fa Speed up peek-char
* module/ice-9/ports.scm (peek-char-and-len): Only inline fast path for
  UTF-8.
2016-05-05 22:57:33 +02:00
Andy Wingo
6d15a71e8f Port to Scheme of new BOM handling
* libguile/ports.c (scm_specialize_port_encoding_x)
  (scm_port_clear_stream_start_for_bom_read): New functions exported
  to (ice-9 ports).
* module/ice-9/ports.scm (clear-stream-start-for-bom-read):
  (fill-input, peek-char-and-len): Rework to handle BOM in fill-input
  instead of once per peek-char.
2016-05-05 22:54:58 +02:00
Andy Wingo
d7a111b0ec Spead tweaks to Scheme peek-char
* module/ice-9/ports.scm: Speed tweaks to %peek-char.  Ultimately
  somewhat fruitless; I can get 1.4s instead of 1.5s by only
  half-inlining the UTF-8 case though.
2016-05-04 12:40:27 +02:00
Andy Wingo
f5b9a53bd0 Add integer->char and char->integer opcodes
* libguile/vm-engine.c (integer_to_char, char_to_integer): New opcodes.
* libguile/vm.c (vm_error_not_a_char): New error case.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm:
* module/language/tree-il/compile-cps.scm (convert):
* doc/ref/vm.texi (Inlined Scheme Instructions):
* module/system/vm/assembler.scm: Add support for new opcodes.
2016-05-04 12:36:41 +02:00
Andy Wingo
2ba638092f Initial peek-char implementation in Scheme
* module/ice-9/ports.scm (EILSEQ, decoding-error, peek-char-and-len/utf8):
  (peek-char-and-len/iso-8859-1, peek-char-and-len/iconv):
  (peek-char-and-len, %peek-char): New definitions.  Missing iconv1 for
  peek-char, but enough to benchmark.
2016-05-04 11:48:05 +02:00
Andy Wingo
36e32138f8 Port refactors to help Scheme peek-char
* libguile/ports.h (scm_sys_port_encoding, scm_sys_set_port_encoding):
  New functions, to expose port encodings as symbols directly to (ice-9
  ports).
  (scm_port_maybe_consume_initial_byte_order_mark): New function.
* libguile/ports.c (scm_port_encoding): Dispatch to %port-encoding.
  (scm_set_port_encoding_x): Dispatch to %set-port-encoding!.
  (port_maybe_consume_initial_byte_order_mark): New helper, factored out
  of peek_codepoint.
  (scm_port_maybe_consume_initial_byte_order_mark, peek_codepoint): Call
  port_maybe_consume_initial_byte_order_mark.
* module/ice-9/ports.scm (port-encoding): Implement in Scheme.
2016-05-04 11:47:42 +02:00
Andy Wingo
422f65fe09 Minor tweak to Scheme peek-byte.
* module/ice-9/ports.scm (peek-byte): Use second return from
  fill-input.
2016-05-01 22:00:37 +02:00
Andy Wingo
4ba59e94f9 Changes to Scheme fill-input corresponding to C
* module/ice-9/ports.scm (fill-input): Rewrite to make changes like the
  ones made to the C scm_fill_input: allow callers to specify a minimum
  amount of buffering.
2016-05-01 21:57:32 +02:00
Andy Wingo
6a752bcf2a peek-byte in Scheme
* libguile/ports.c (trampoline_to_c_read, trampoline_to_c_write): Since
  C might assume that the indices are within bounds of the bytevector,
  verify them more here.
  (scm_port_random_access_p, scm_port_read_buffering)
  (scm_set_port_read_buffer, scm_port_read, scm_port_write): New helpers
  exposed to (ice-9 ports).
  (scm_port_read_buffer, scm_port_write_buffer): Don't flush or validate
  port mode; we do that in Scheme.
* module/ice-9/ports.scm: Implement enough of port machinery to
  implement peek-byte in Scheme.  Not yet exported.
2016-04-30 14:46:45 +02:00
Andy Wingo
555c934726 Refactor way the-eof-object is defined
* libguile/ports.c (scm_init_ice_9_ports): Define the-eof-object here.
  Update a comment.
* module/ice-9/ports.scm: Use the-eof-object definition from C.
2016-04-30 14:44:20 +02:00
Andy Wingo
44b3342c4d Load port bindings in separate (ice-9 ports) module
* module/ice-9/ports.scm: New file.
* am/bootstrap.am (SOURCES): Add ice-9/ports.scm.
* libguile/fports.c (scm_init_ice_9_fports): New function.
  (scm_init_fports): Arrange for scm_init_ice_9_fports to be called via
  load-extension, and load snarfed things there.  Move open-file
  definition early, to allow ports to bootstrap.
* libguile/ioext.c (scm_init_ice_9_ioext): New function.
  (scm_init_ioext): Similarly, register scm_init_ice_9_ioext as an
  extension.
* libguile/ports.c (scm_set_current_input_port)
  (scm_set_current_output_port, scm_set_current_error_port): Don't
  define Scheme bindings; do that in Scheme.
* libguile/ports.c (scm_i_set_default_port_encoding):
  (scm_i_default_port_encoding, scm_i_default_port_conversion_handler):
  (scm_i_set_default_port_conversion_handler): Since we now init
  encoding early, remove the "init" flags on these encoding/strategy
  vars.
  (scm_init_ice_9_ports): New function.
  (scm_init_ports): Register scm_init_ice_9_ports extension, and define
  some bindings needed by the bootstrap.
* module/Makefile.am (SOURCES): Add ice-9/ports.scm.
* module/ice-9/boot-9.scm: Remove code that's not on the boot path,
  moving it to ice-9/ports.scm.  At the end, load (ice-9 ports).
* module/ice-9/psyntax.scm (include): Use close-port instead of
  close-input-port.
* module/ice-9/psyntax-pp.scm (include): Regenerate.
2016-04-15 14:07:02 +02:00
Andy Wingo
5e470ea48f Fix R6RS imports of interfaces that use interfaces
* module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface): In Guile, a
  module's public interface is just another module, and that means that
  it can import other modules as well.  Allow for R6RS modules that
  import module whose interfaces import other modules to access all
  visible bindings.
* test-suite/tests/rnrs-libraries.test ("import features"): Update
  test.
2016-04-14 12:35:55 +02:00
Andy Wingo
110695c82e Fix error in exception printer when bootstrapping
* module/ice-9/boot-9.scm (exception-printers): Fix error in which, for
  a pure bootstrap with no compiled files, the exception printer would
  use false-with-exception before it has been defined, which doesn't
  work for macros.  We wouldn't see this problem normally because,
  oddly, the macro is indeed defined normally because of boot reasons.
2016-04-13 11:12:24 +02:00
Andy Wingo
55fb8f4e7e make-chunked-output-port buffering fix
* module/web/http.scm (make-chunked-output-port): Add #:buffering
  argument, defaulting to 1200 (some random value under the MTU).  This
  will force a flush every so often, and not every character as would
  otherwise be the case after this port rewrite.
2016-04-11 22:23:47 +02:00
Andy Wingo
59a18451b8 Use symbols instead of _IONBF values as args to setvbuf
* libguile/ports.c (scm_setvbuf): Use the symbols `none', `line', and
  `block' instead of the values `_IONBF', `_IOLBF', and `_IOFBF'.
* NEWS: Update.
* doc/ref/posix.texi (Ports and File Descriptors): Update setvbuf
documentation.
* module/ice-9/deprecated.scm (define-deprecated): New helper.
(_IONBF, _IOLBF, _IOFBF): Define deprecated values.
* benchmark-suite/benchmarks/read.bm ("read"):
* benchmark-suite/benchmarks/uniform-vector-read.bm
("uniform-vector-read!"):
* libguile/r6rs-ports.c (cbip_fill_input):
* module/system/base/types.scm (%ffi-memory-backend):
* module/web/client.scm (open-socket-for-uri):
* module/web/server/http.scm (http-read):
* test-suite/tests/ports.test ("pipe, fdopen, and line buffering"):
("setvbuf"):
* test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports"): Update to use
non-deprecated interfaces.
2016-04-04 16:30:56 +02:00
Andy Wingo
737e62f4b5 Fix frame->stack-vector when no stack is active
* module/system/repl/debug.scm (frame->stack-vector): Handle the case
  where there is no active stack.
2016-04-04 16:30:52 +02:00
Andy Wingo
43a038f6e1 Fix lower-bound saturation in type inference
* module/language/cps/types.scm (type-entry-saturating-union): Fix range
  saturation in the negative direction.  Previously we were artificially
  truncating negative range ends to zero.
2016-03-14 11:17:08 +01:00
Andy Wingo
486b322fd5 Fix frame-call-representation for change to <binding>.
* module/system/vm/frame.scm (frame-call-representation): Fix for change
  to <binding>.
2016-02-02 11:09:00 +01:00
Andy Wingo
8998f1539f Update statprof documentation; deprecate `with-statprof'
* module/statprof.scm: Remove most of the commentary, as it was
  duplicated in the manual and was getting out of date.
  (stats): Remove self-secs-per-call and cum-secs-per-call fields as
  they can be computed from the other fields.
  (statprof-call-data->stats): Adapt.
  (statprof-stats-self-secs-per-call):
  (statprof-stats-cum-secs-per-call): New functions.
  (statprof-display/flat): Don't print the seconds-per-call fields, as
  we are no longer stopping the clock around call counters.  Anyway
  these times were quite misleading.
  (with-statprof): Deprecate.  It took its keyword arguments at the
  beginning; very complicated!  Better to use the `statprof' function.
  (`statprof' was introduced after `with-statprof' and then
  `with-statprof' was adapted to use it.)

* doc/ref/statprof.texi (Statprof): Port this documentation away from
  the automatically generated text and update it for the new interfaces
  like #:display-style.

* module/system/base/syntax.scm (record-case): Remove comment that
  referenced with-statprof.  Add comment indicating that record-case
  should be replaced.

* doc/ref/scheme-using.texi (Profile Commands): Update to mention
  keyword arguments and to link to the statprof documentation.
2016-02-01 15:12:36 +01:00
Andy Wingo
4066ee3192 Better call-counting profiles in statprof
* module/statprof.scm: Update commentary.
  (count-call): Don't bother stopping and starting the timer.  The
  overhead of call counting perturbs timing too much already, and
  somewhat paradoxically stopping and starting the timer takes too much
  time.
  (skip-count-call): New function.
  (stack-samples->procedure-data, stack-samples->callee-lists): If we
  are counting calls, skip any part of the stack that is inside
  count-call.
2016-02-01 11:27:14 +01:00
Andy Wingo
cd0b61a04e Frame <binding> objects capture frame, can ref value directly
* module/system/repl/debug.scm (print-locals): Adapt to
  frame-binding-ref change.

* module/system/vm/frame.scm (<binding>): Add `frame' field.
  (available-bindings): Capture the frame.
  (binding-ref, binding-set!): New functions, accessing a local variable
  value directly from a frame.
  (frame-binding-ref, frame-binding-set!): Remove.  As these are very
  low-level debugging interfaces introduced in 2.0, never documented,
  and quite tied to the VM, we feel comfortable making this change.
  (frame-call-representation): Adapt to available-bindings change.
  (frame-environment, frame-object-binding): Adapt to binding-ref
  interface change.

* doc/ref/vm.texi (Stack Layout): Mention that slots can be re-used.
  Update disassembly in example.

* doc/ref/api-debug.texi (Frames): Remove documentation for
  frame-local-ref, frame-local-set!, and frame-num-locals.  Replace with
  documentation for frame-bindings, binding accessors, and binding-ref /
  binding-set!.
2016-01-31 11:15:58 +01:00
Andy Wingo
67e8aa85e8 Remove frame-local-ref, frame-local-set!
* libguile/frames.h (scm_frame_num_locals, scm_frame_local_ref)
  (scm_frame_local_set_x): Remove.  As long as we are changing the
  interface in a backward-incompatible way, we might as well remove
  these.
* libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref)
  (scm_frame_local_set_x, scm_init_frames_builtins, scm_init_frames):
  Arrange to make frame-local-ref et al private to frames.scm.

* module/system/vm/frame.scm: Load scm_init_frames_builtins extensions.
  (frame-instruction-pointer-or-primitive-procedure-name): New public
  function.
  (frame-binding-ref, frame-binding-set!): Allow binding objects as
  vars.

* module/system/repl/debug.scm (print-locals): Pass binding directly to
  frame-binding-ref.

* module/statprof.scm (sample-stack-procs, count-call): Use new
  frame-instruction-pointer-or-primitive-procedure-name function.
2016-01-31 10:45:02 +01:00
Andy Wingo
9eb841c2d8 Fix uniform vector compilation to foreign byte orders.
* module/system/vm/assembler.scm (define-byte-order-swapper): New
  helper.
  (byte-swap/2!, byte-swap/4!, byte-swap/8!): New functions.
  (link-data): Swap bytes in uniform vectors on foreign byte orders.
2016-01-29 10:24:40 +01:00
Andy Wingo
e4be4aea34 Fix cross-compilation of immediates to targets with different word sizes
* module/system/vm/assembler.scm (immediate-bits): Rename from
  immediate?, and return the bits.  Take asm argument so that we measure
  what's an immediate not on the host but for the target.  Adapt all
  callers.
  (write-immediate): Take bits instead of SCM object.  Adapt callers.
  (write-placeholder): New helper, to write bits for #f.  Adapt callers
  that wrote #f to use write-placeholder.
2016-01-29 09:50:32 +01:00
Andy Wingo
f61870979c Fix type inference of integer division
* module/language/cps/types.scm (define-binary-result!): Fix inference
  of integer division.
2016-01-17 16:58:36 +01:00
Andy Wingo
ee85113f4a statprof: Better tree-format profiles
* module/statprof.scm (statprof-fetch-call-tree): Add #:precise? keyword
  argument, defaulting to false.  Search for cycles after computing
  printable source locations instead of doing so over addresses -- it
  could be that two addresses map to the same source location, and from
  the user's perspective they are then indistinguishable in the
  printout.
2016-01-11 21:56:48 +01:00
Andy Wingo
cf2fadf603 statprof: Add tree #:display-style.
* module/statprof.scm (statprof-display/flat): Rename from
  statprof-display.  Use real format; we have it.
  (statprof-display-anomalies): Likewise use real format.
  (procedure=?): Remove unused function.
  (collect-cycles): New helper.
  (statprof-fetch-call-tree): Fix to root the trees correctly -- it was
  interpreting them in the wrong order.  Detect cycles so that it's not
  so terrible.  Use precise locations for source locations.  Probably
  need to add an option to go back to the per-function behavior.
  (statprof-display/tree): New helper, uses statprof-fetch-call-tree to
  display a profile in a nested tree.
  (statprof-display): Add #:style argument, which can be `flat',
  `anomalies', or `tree'.
  (statprof): Add #:display-style argument, proxying to #:style,
  defaulting to 'flat.
2016-01-11 21:56:48 +01:00
Andy Wingo
6d7c09c8a9 web: Be less strict when parsing entity tags.
* module/web/http.scm (parse-entity-tag): Be less strict, accepting
  unquoted strings as well.

* test-suite/tests/web-http.test ("response headers"): Add a test for
  etag parsing.
2016-01-07 10:53:57 +01:00
Andy Wingo
4137c224e2 Remove unused function in simplify.scm
* module/language/cps/simplify.scm (intset-add*): Remove unused
  function.
2016-01-04 23:33:24 +01:00
Andy Wingo
f56f580a4a Inline some helpers in intset.scm.
* module/language/cps/intset.scm (round-down): Inline.
  (clone-branch-and-set): Inline, and inline the vector-move-left!.
2016-01-04 22:48:30 +01:00
Andy Wingo
9091454c2e Include missing #:simplify? option in (language cps optimize).
* module/language/cps/optimize.scm (cps-default-optimization-options):
  Add missing #:simplify? option.  Otherwise the simplification pass was
  running even at -O0.
2016-01-04 22:43:30 +01:00
Andy Wingo
fb2f7b4e5f Better CPS conversion for tests in tests
* module/language/tree-il/compile-cps.scm (convert): Tests in tests have
  their consequents and alternates also converted in test context.
2016-01-03 18:18:51 +01:00
Andy Wingo
166703c5ce Better partial evaluation of tests in tests
* module/language/tree-il/peval.scm (peval): In test context,
  fold (let ((x EXP)) (if x x ALT)) to (if EXP #t ALT).  This reduces
  the number of boolean literals that the compiler has to reify, by
  causing EXP to evaluate in test context instead of value context.
  Also, rotate `let' out of the test part of conditionals, for the same
  reason.
2016-01-03 18:15:20 +01:00
Andy Wingo
52965e03ec Better folding of branches on $values
* module/language/cps/type-fold.scm (local-type-fold): Fold branches on
  $values, if we can.
2016-01-03 16:17:53 +01:00
Andy Wingo
39002f251e Eta-reduce branches
* module/language/cps/simplify.scm (compute-eta-reductions): Eta-reduce
  branches as well, so that passing a constant to a branch will fold to
  the true or false branch, provided that the test variable was just
  used in the branch.
2016-01-03 16:16:54 +01:00
Andy Wingo
5d171d998c Fix module for reification of srfi-4 primitives
* module/language/cps/reify-primitives.scm (primitive-module): Add cases
  for SRFI-4 primitives.  These primitives are only treated as such for
  the purposes of Tree-IL primitive expansion; perhaps the right fix is
  elsewhere, but it's here for now.
2015-12-30 17:14:22 +01:00
Andy Wingo
a9c2606451 Type inference copes better with unsorted graphs
* module/language/cps/types.scm (&min/0, &min/s64, &max/s64, &max/size)
  (&max/u64, &max/vector): New clamped variable range accessors.  Use
  them in type inferrers.
2015-12-26 22:12:09 +01:00
Andy Wingo
620b640a4e Fix bug in intmap-map
* module/language/cps/utils.scm (intmap-map): Use transient intmap-add!
  on an empty intmap to build the result instead of intmap-replace! on
  the argument.  Avoids spooky action-at-a-distance mutation of the
  argument if it happens to be a transient -- although the intmap-fold
  will correctly traverse a snapshot of the argument and the result will
  be correct, the argument value would be modified in place, causing
  strange results to calling code that passes in a transient.
2015-12-26 22:12:09 +01:00
Andy Wingo
8a39162160 Assembler O(n) in instruction encodings, not instruction count
* module/system/vm/assembler.scm: Change define encoders for all of the
  kinds of instructions and have the emit-foo procedures call the common
  encoders.  No change to public interface.  This decreases the amount
  of generated code in the assembler.
2015-12-26 22:12:09 +01:00
Andy Wingo
362907810b Fix emit-receive* for many locals
* module/system/vm/assembler.scm (emit-receive*): Fix to use FP-relative
  move instead of SP-relative move.
2015-12-26 22:12:09 +01:00
Andy Wingo
9e1c07bda6 Assembler works on byte offsets, not u32 offsets
* module/system/vm/assembler.scm (u32-ref, u32-set!, s32-ref, s32-set!):
  Remove these helpers.
* module/system/vm/assembler.scm (<asm>): Track offsets in bytes, not
  u32 units.
  (emit, assembler, process-relocs, process-labels, link-text-object)
  (link-frame-maps, link-symtab, write-arities, link-docstrs)
  (link-procprops, link-debug): Adapt.

* module/system/vm/linker.scm (process-reloc): Add addend before
  dividing by 4 for rel32/4 symbols.
2015-12-26 22:12:09 +01:00
Andy Wingo
3c271457f1 Fix build when threads are disabled
* module/language/cps/intmap.scm: Remove srfi-18 import.  We just need
  current-thread which is actually defined in (guile), and
  importing (srfi srfi-18) raises an error if Guile is compiled without
  threads support.
2015-12-16 09:48:37 +00:00
Andy Wingo
a1471e0244 Add another simplification pass to make rotate-loops work better
* module/language/cps/optimize.scm (optimize-first-order-cps): Toss in
  another simplification pass.
2015-12-03 09:12:25 +00:00
Andy Wingo
1d4b4ec39c Add support for comparing u64 values with SCM values
* libguile/vm-engine.c (BR_U64_SCM_COMPARISON): New helper.
  (br-if-u64-<=-scm, br-if-u64-<-scm, br-if-u64-=-scm)
  (br-if-u64->-scm, br-if-u64->=-scm): New instructions, to compare an
  untagged u64 with a tagged SCM.  Avoids many u64->scm operations.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/type-fold.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation, compute-labels):
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
  support for new opcodes.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Specialize u64 comparisons.
* module/language/cps/types.scm (true-comparison-restrictions): New helper.
  (define-comparison-inferrer): Use the new helper.  Add support for
  u64-<-scm et al.
2015-12-03 09:01:24 +01:00
Andy Wingo
7a43a3a181 Refactor range checking in assembler instruction packers
* module/system/vm/assembler.scm (check-urange, check-srange): New
  helpers.
  (pack-u8-u24, pack-u8-s24, pack-u1-u7-u24, pack-u8-u12-u12):
  (pack-u8-u8-u16, pack-u8-u8-u8-u8): Use the new helpers.  Not only
  makes the code nicer but also reduces register pressure.
2015-12-02 22:12:30 +01:00
Andy Wingo
9514dc7b95 Add ursh/immediate and ulsh/immediate ops
* libguile/vm-engine.c (ursh/immediate, ulsh/immediate): New ops.
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations)
  (compute-needs-slot):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm:
* module/language/cps/types.scm: Add support for new ops, and specialize
  ursh and ulsh.
2015-12-02 22:11:19 +01:00
Andy Wingo
246887171c Assembler has a single growable vector
* module/system/vm/assembler.scm (<asm>): Instead of writing words into
  a list of fixed-size buffers, use a growable vector.
  (expand, emit): Instead of assuming that there is enough space for
  only one word, check that there is space for the entire instruction at
  the beginning.
2015-12-02 08:45:30 +01:00
Andy Wingo
dbd9265cc0 More efficient assembler instructions
* module/system/vm/assembler.scm (pack-u8-u24, pack-u8-s24):
  (pack-u1-u7-u24, pack-u8-u12-u12, pack-u8-u8-u16): Tweak to expose
  more possibilities for untagging u64 values.
2015-12-02 08:45:30 +01:00
Andy Wingo
73065c7131 Specialize u64 bit operations
* module/language/cps/specialize-numbers.scm (specialize-u64-binop):
  (specialize-operations): Specialize u64 bit operations.
2015-12-02 08:45:30 +01:00