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

4114 commits

Author SHA1 Message Date
Andy Wingo
cf08dbdc18 Associate #:replace info with modules, not variables
* doc/ref/api-modules.texi (Creating Guile Modules): Document
  #:re-export-and-replace.
* module/ice-9/boot-9.scm (module-replacements): New module field.
  (make-module, make-autoload-interface): Initialize replacements to an
  empty hash table.
  (resolve-interface): Propagate replacement info when making custom
  interfaces.
  (define-module): Parse a #:re-export-and-replace keyword arg.
  (define-module*): Handle #:re-export-and-replace.
  (module-export!, module-re-export!): Add a keyword arg to indicate
  whether to replace or not.
  (module-replace!): Call module-export! with #:replace? #t.
  (duplicate-handlers): Update replace duplicate handler to look for
  replacement info on the interfaces.
* module/srfi/srfi-18.scm (srfi):
* module/srfi/srfi-34.scm (srfi): Update to #:re-export-and-replace
  raise-continuable as raise.
2019-11-29 11:51:29 +01:00
Andy Wingo
8304b15807 Fix range inference on division in unreachable code
* module/language/cps/types.scm (div-result-range): It is possible for a
  max value to be less than a minimum.  In this bug from zig:

    (define (benchmark x)
      (let loop ((count 0)
                 (sum 0))
        (if (= count 10)
            (exact->inexact (/ sum 10)))
        (loop (+ count 1) x)))

  Here the first iteration gets peeled, and thus the first "if" can't be
  true, because "count" is zero.  However on the true branch of the if,
  range inference produces bogus ranges -- notably, the variable bound
  to 10 is inferred to have a min of 10 and a max of 0.  This is fine,
  because it's unreachable; but that then infects the division, because
  the same variable bound to 10 is used there, resulting in division by
  zero.
2019-11-27 16:03:59 +01:00
Andy Wingo
7190905109 Fix frame-call-representation for callees without closures
* module/system/vm/assembler.scm (<arity>): Add new "has-closure?"
  flag.
  (begin-kw-arity, pack-arity-flags, write-arities): Write
  "elided-closure?" flag into binary.  A negative flag for compat
  reasons.
* module/system/vm/debug.scm (elided-closure?, arity-has-closure?): Add
  arity-has-closure? accessor.
* module/system/vm/frame.scm (frame-call-representation): Count from 0
  for callees with elided closures.
2019-11-27 15:04:55 +01:00
Andy Wingo
08bd2f0dcb Fix range inference for right-shifts
* module/language/cps/types.scm (compute-ash-range): Fix rsh range
  inference, broken during refactoring.  Fixes
  https://bugs.gnu.org/38369.
2019-11-26 11:03:24 +01:00
Andy Wingo
1907e59c09 Install exception converters and printers from boot-9
* doc/ref/intro.texi (Guile and Scheme): Fix a date.
* module/ice-9/boot-9.scm: Load (ice-9 exceptions).
2019-11-21 16:48:35 +01:00
Andy Wingo
b634071dd4 Add R7RS documentation and --r7rs command-line option
* doc/ref/Makefile.am: Add r7rs.texi.
* doc/ref/guile-invoke.texi (Command-line Options): Document --r7rs.
* doc/ref/guile.texi (Guile Modules): Link to R7RS.
* doc/ref/intro.texi (Guile and Scheme): Update for R7RS support.
* doc/ref/r7rs.texi: New file.
* doc/ref/scheme-intro.texi (Guile Scheme): Update for R7RS.
* module/ice-9/command-line.scm (*usage*, compile-shell-switches): Add
  --r7rs option.
2019-11-17 15:30:59 +01:00
Andy Wingo
614f0ab75f Add install-r7rs!, like install-r6rs!
* module/ice-9/boot-9.scm (install-r7rs!): New function.
2019-11-16 21:09:51 +01:00
Andy Wingo
d914652c0a Add initial implementation of R7RS modules
* module/Makefile.am (SOURCES): Add new files.
* module/scheme/base.scm:
* module/scheme/case-lambda.scm:
* module/scheme/char.scm:
* module/scheme/complex.scm:
* module/scheme/cxr.scm:
* module/scheme/eval.scm:
* module/scheme/file.scm:
* module/scheme/inexact.scm:
* module/scheme/lazy.scm:
* module/scheme/load.scm:
* module/scheme/process-context.scm:
* module/scheme/r5rs.scm:
* module/scheme/read.scm:
* module/scheme/repl.scm:
* module/scheme/time.scm:
* module/scheme/write.scm: New files.  Thanks to Göran Weinholt for
  akku-scm and OKUMURA Yuki for yuni, off of which some of these files
  were based.
2019-11-16 21:09:46 +01:00
Andy Wingo
95efe14e44 SRFI-18 uses core exceptions
* module/ice-9/boot-9.scm (exception-kind, exception-args): Export.
* module/ice-9/exceptions.scm (exception-kind, exception-args):
  Re-export.
* module/srfi/srfi-18.scm: Rewrite exception support in terms of core
  exceptions, not SRFI-34/35.
* test-suite/tests/srfi-18.test: Since Guile doesn't expose the current
  exception handler as such, SRFI-18 captures it using delimited
  continuations.  This means that we can't compare the result
  of (current-exception-handler) with the installed handler using eq?,
  even though the procedures are indeed equivalent.  So, instead test
  handler behavior.
2019-11-14 16:33:10 +01:00
Andy Wingo
f4ca107f7f Rebase throw/catch on top of raise-exception/with-exception-handler
* libguile/exceptions.c:
* libguile/exceptions.h: New files.
* libguile.h: Add exceptions.h.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Add exceptions.c and
  exceptions.h.
* libguile/init.c (scm_i_init_guile): Initialize exceptions.
* libguile/threads.c (scm_spawn_thread): Use new names for
  scm_i_make_catch_handler and scm_c_make_thunk.
* libguile/throw.c: Rewrite to be implemented in terms of
  with-exception-handler / raise-exception.
* libguile/throw.h: Use data types from exceptions.h.  Move
  scm_report_stack_overflow and scm_report_out_of_memory to
  exceptions.[ch].
* module/ice-9/boot-9.scm (&error, &programming-error)
  (&non-continuable, make-exception-from-throw, raise-exception)
  (with-exception-handler): New top-level definitions.
  (throw, catch, with-throw-handler): Rewrite in terms of
  with-exception-handler and raise-exception.
: New top-level definitions.
* module/ice-9/exceptions.scm: Adapt to re-export &error,
  &programming-error, &non-continuable, raise-exception, and
  with-exception-handler from boot-9.
  (make-quit-exception, guile-quit-exception-converter): New exception
  converters.
  (make-exception-from-throw): Override core binding.
* test-suite/tests/eval.test ("inner trim with prompt tag"): Adapt to
  "with-exception-handler" being the procedure on the stack.
  ("outer trim with prompt tag"): Likewise.
* test-suite/tests/exceptions.test (throw-test): Use pass-if-equal.
* module/srfi/srfi-34.scm: Reimplement in terms of core exceptions, and
  make "guard" actually re-raise continuations with the original "raise"
  continuation.
2019-11-13 22:24:19 +01:00
Andy Wingo
3c73d77e2a Move exceptions with key and args to core
* module/ice-9/boot-9.scm (&exception-with-key-and-args)
  (&quit-exception): New definitions.
* module/ice-9/exceptions.scm (make-guile-exception):
  (guile-exception?, guile-exception-key, guile-exception-args): Update
  definitions.
2019-11-07 16:43:23 +01:00
Andy Wingo
92d767bae2 Move the core of exception objects into core
* module/ice-9/boot-9.scm (&exception, &compound-exception)
  (simple-exceptions, make-exception, exception?, exception-type?)
  (make-exception-type, exception-predicate, exception-accessor): Move
  these definitions into core, from (ice-9 exceptions).
* module/ice-9/exceptions.scm: Re-export definitions from core.
2019-11-07 15:55:23 +01:00
Andy Wingo
fc7a0a854f Move exception-handling routines after records in boot-9
* module/ice-9/boot-9.scm: Move down definitions of catch, throw, and so
  on until they are after records.
2019-11-07 15:50:20 +01:00
Andy Wingo
f9b594c482 Move false-if-exception down in boot-9
* module/ice-9/boot-9.scm (false-if-exception): Move down.
2019-11-07 15:07:14 +01:00
Andy Wingo
9835ed1809 Move adapter between "throw" and "raise" exceptions into core
* module/ice-9/exceptions.scm (&guile):
  (default-guile-exception-converter):
  (guile-common-exceptions):
  (convert-guile-exception):
  (&raise-object-wrapper):
  (make-raise-object-wrapper):
  (raise-object-wrapper?):
  (raise-object-wrapper-obj):
  (raise-object-wrapper-continuation):
  (raise-exception):
  (raise-continuable):
  (with-exception-handler):
  (exception-printer):
  (format-exception):
  (format-simple-exception):
  (%exception):
  (guile-syntax-error-converter):
  (guile-lexical-error-converter):
  (guile-assertion-failure-converter):
  (guile-undefined-variable-error-converter):
  (guile-implementation-restriction-converter):
  (guile-external-error-converter):
  (guile-system-error-converter):
  (guile-exception-converters):
  (set-guile-exception-converter!): Move here, from (rnrs exceptions).
* module/rnrs/exceptions.scm: Re-export bindings from (ice-9
  exceptions).
2019-11-05 09:36:36 +01:00
Andy Wingo
86bc3da9e0 Rebase SRFI-35 on top of (ice-9 exceptions)
* module/ice-9/exceptions.scm (exception-type?): New export.
* module/srfi/srfi-35.scm: Rewrite in terms of (ice-9 exceptions).
2019-11-04 15:18:57 +01:00
Andy Wingo
54ab2175f9 Add (ice-9 exceptions) module
* module/ice-9/exceptions.scm: New file, derived from (rnrs
  conditions).  Perhaps unadvisedly, in this file I've renamed a number
  of the identifiers.  I have never found that the R6RS identifiers made
  sense to me.  For now this is an internal module that R6RS and SRFI-35
  will be based on.
* module/Makefile.am (SOURCES): Add the new file.
* module/rnrs/conditions.scm (rnrs): Export renamed identifiers
  from (ice-9 exceptions).
2019-11-03 21:37:02 +01:00
Andy Wingo
90d52a9e1d Add `record-type-has-parent?'.
* module/ice-9/boot-9.scm (record-type-has-parent?): New function.
* module/srfi/srfi-35.scm (condition-type?): Use it.
2019-11-03 21:36:39 +01:00
Andy Wingo
9f1a671734 Remove circularity in r6rs by rebasing conditions on core records
* module/rnrs/conditions.scm: Use core record facilities to define the
  base condition types, define-condition-type, and the standard
  condition hierarchy.
  (simple-condition?): Rename from condition-internal?.
* module/rnrs/exceptions.scm: Move `raise' definition here, out from the
  procedural records layer.
  (format-simple-condition): Reimplement in a simpler way, hopefully
  producing the same output.
* module/rnrs/records/procedural.scm:
* module/rnrs/records/inspection.scm: Import the exceptions and
  conditions modules, and use the normal raise function.
2019-10-30 15:53:38 +01:00
Andy Wingo
73d0a3bccb Rebase R6RS records on top of core records
* module/ice-9/boot-9.scm (record-type-uid): New accessor.
  (make-record-type): Record UID in record type properties.
* module/rnrs/conditions.scm (define-condition-type): Fix invalid
  invocation of make-record-type.
* module/rnrs/records/inspection.scm: Rewrite to use core record
  inspection facilities.
* module/rnrs/records/procedural.scm: Rewrite to use core
  make-record-type.  Incidentally the result is that instances of
  derived R6RS record types are now flat instead of nested.
* test-suite/tests/r6rs-records-procedural.test
  ("make-record-type-descriptor"): Relax a couple condition type checks,
  while we redo the exception system.
2019-10-29 11:35:16 +01:00
Andy Wingo
1ae0f8d490 Add record-type-parent definition.
* module/ice-9/boot-9.scm (record-type-parent): New definition.
2019-10-29 10:34:35 +01:00
Andy Wingo
315fabdfe7 Add support for immutable fields in core records
* module/ice-9/boot-9.scm (make-record-type): Allow (mutable NAME)
  or (immutable NAME) as a field name, and record field mutability in a
  bitfield.
  (record-modifier): Throw an error if the field isn't mutable.
* test-suite/tests/records.test ("records"): Add tests.
* doc/ref/api-data.texi (Records): Update.
2019-10-28 16:59:58 +01:00
Andy Wingo
f963bdf02d Rename final? record type flag; add support for opaque?
* module/ice-9/boot-9.scm (record-type-extensible?): Rename from
  record-type-final?, with the opposite sense.
  (record-type-opaque?): New accessor.
  (make-record-type): Change #:final? to #:extensible?, with the
  opposite meaning.  Add #:opaque? arg.
* test-suite/tests/records.test ("records"): Add opaque tests; update
  extensible tests.
* doc/ref/api-data.texi (Records): Update.
* module/srfi/srfi-35.scm (&condition, make-condition-type): Update for
  make-record-type API change.
2019-10-27 21:31:18 +01:00
Andy Wingo
7a8e314d31 Guile `make-record-type' supports non-generative definition
* module/ice-9/boot-9.scm (prefab-record-types): New definition.
  (make-record-type): Add #:uid keyword.
* test-suite/tests/records.test ("records"): Add tests.
* doc/ref/api-data.texi (Records): Document #:uid
2019-10-27 20:55:01 +01:00
Andy Wingo
958aa8b313 Change record type "flags" field to "properties"
* module/ice-9/boot-9.scm (record-type-properties): Rename from
  record-type-flags.
  (record-type-final?): New accessor.
  (make-record-type):
  (define-record-type):
* test-suite/tests/records.test ("records"): Adapt.
2019-10-27 20:03:51 +01:00
Andy Wingo
99a95383cf Rebase srfi-35 conditions on top of make-record-type
* module/srfi/srfi-35.scm: Import (ice-9 match), and remove now-unused
  srfi-1 import.
  (print-condition): Print more like records, as appears to be the
  intention.
  (&condition): Define using make-record-type.  Adapt all callers.
  Also, compound conditions are now a disjoint type, handled specially
  by condition-ref, condition?, and so on.
* test-suite/tests/srfi-35.test (v3): Fix an error in which a
  subcondition was initialized without initializers for all of its
  fields.
2019-10-23 14:42:35 +02:00
Andy Wingo
f116bd1009 make-record-type does more validation on the fields
* module/ice-9/boot-9.scm (make-record-type): Validate that the fields
  are a unique list of symbols.  Deprecate passing a string as a type
  name.
* module/system/base/syntax.scm (define-record): Update to pass a symbol
  as a type name.
* test-suite/tests/records.test (rtd-foo, rtd-fŏŏ, "records"): Adapt to
  make record types with symbol names.
2019-10-23 14:42:29 +02:00
Andy Wingo
bebc46be14 SRFI-9 uses make-record-type
* module/srfi/srfi-9.scm (%define-record-type): Use make-record-type,
  instead of rolling our own vtable.  Shouldn't have any perf impact.
2019-10-23 12:04:58 +02:00
Andy Wingo
f060f1a4e6 Record accessors respect subtyping
* module/ice-9/boot-9.scm (make-record-type): Don't allow subtyping of
  final types.
  (%record-type-error): Remove helper.
  (record-accessor, record-modifier): Use computed record type
  predicate, to allow for subtyping.
  (define-record-type): Adapt to %record-type-error going away; these
  types are final so no accessor adaptation is needed.
* test-suite/tests/records.test: Add tests.
* doc/ref/api-data.texi (Records): Update.
2019-10-22 16:22:48 +02:00
Andy Wingo
4bec125e63 Allow records to be subtyped
* module/ice-9/boot-9.scm (record-type-vtable): Add slots for "flags"
  and a parent vector.
  (record-type-name, record-type-fields): Move up in the file.
  (record-type-constructor, record-type-flags, record-type-parents): New
  accessors.
  (make-record-type): Take #:final? and #:parent keyword arguments.
  (record-constructor): Delegate to record-type-constructor.
  (record-predicate): For non-final types --types that can be extended
  by subtyping -- implement an O(1) type predicate.
  (define-record-type): Initialize the new fields.
* module/srfi/srfi-9.scm (%define-record-type): Initialize flags and
  parent fields.
2019-10-22 14:50:14 +02:00
Andy Wingo
f7b4055b16 Deprecate two-arg `record-constructor'
* module/ice-9/boot-9.scm (record-constructor): Deprecate the two-arg
  form.
2019-10-22 13:59:33 +02:00
Andy Wingo
0c8d20d2d0 Re-implement (ice-9 gap-buffer) records in terms of srfi-9
* module/ice-9/gap-buffer.scm (gap-buffer): Use srfi-9.
2019-10-22 13:47:02 +02:00
Andy Wingo
40395c0dff Remove (ice-9 channel)
* module/ice-9/channel.scm: Remove.  This file has had a bug since
  2.0 or so that prevented loading the module; I can only conclude that
  it hasn't worked for years.
* module/Makefile.am (SOURCES): Remove ice-9/channel.scm.
2019-10-21 17:34:50 +02:00
Andy Wingo
f152d7cd96 Refactor PEG records
* module/ice-9/peg/using-parsers.scm (prec): Use SRFI-9 to define PEG
  record types.
  (peg:start, peg:end, peg:string, peg:tree, peg:substring): Implement
  in a more efficient way.
2019-10-21 17:21:47 +02:00
Andy Wingo
2cca09126e Extend `import' to allow R7RS-style srfi references
* module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface): Allow for
  srfis to be accessed via (srfi 42 foo) in addition to (srfi :42 foo).
2019-09-27 22:57:38 +02:00
Andy Wingo
3e02bf7259 (ice-9 safe-r5rs) fixes for bound aux syntax
* module/ice-9/safe-r5rs.scm: Define local versions of `case' and `cond'
  that assume aux syntax is unbound.  If this doesn't work, we can
  switch to exporting aux syntax.
* module/ice-9/top-repl.scm (top-repl): Don't add (ice-9 r5rs) to the
  REPL environment.
2019-09-27 22:57:38 +02:00
Andy Wingo
2e335635cc (ice-9 null) also exports aux syntax, syntax-rules
* module/ice-9/null.scm: Add more syntactic exports.
2019-09-27 22:57:38 +02:00
Andy Wingo
cc7d394490 Deprecate passing a non-zero size to make-module
* module/ice-9/boot-9.scm (make-module): Issue a deprecation warning if
  users pass a non-zero size.
  (nested-define-module!, make-modules-in, beautify-user-module!)
  (resolve-interface, make-autoload-interface, %cond-expand-table):
* module/ice-9/popen.scm (port/pid-table):
* module/ice-9/session.scm (make-fold-modules):
* module/language/ecmascript/function.scm (*program-wrappers*):
* module/scripts/api-diff.scm (read-api-alist-file):
* module/srfi/srfi-10.scm (reader-ctors): Update callers.  Also remove
  some make-hash-table sizes.
2019-09-27 22:57:38 +02:00
Andy Wingo
f62e19bd10 (ice-9 null) also re-exports core aux syntax
* module/ice-9/null.scm: Re-export _, else, =>, and the ellipsis.
2019-09-27 22:57:38 +02:00
Andy Wingo
3be16199ab Avoid mutating arguments to resolve-interface
* module/ice-9/boot-9.scm (resolve-interface): This function used to
  mutate the #:hide argument, which results in terrorism if the value is
  a literal.
2019-09-27 22:57:38 +02:00
Andy Wingo
714d0b9d9f Better R6RS compatibility
* module/ice-9/boot-9.scm (install-r6rs!): Also enable
  `hungry-eol-escapes'.
* doc/ref/r6rs.texi (R6RS Incompatibilities): Document lack of unicode
  escapes in symbols.
2019-09-27 14:08:02 +02:00
Andy Wingo
afcc22f639 Add --r6rs command-line option
* doc/ref/guile-invoke.texi (Command-line Options): Document --r6rs.
* doc/ref/r6rs.texi (R6RS Incompatibilities): Mention that --r6rs calls
  install-r6rs!.
* module/ice-9/command-line.scm (*usage*, compile-shell-switches):
  Implement --r6rs.
2019-09-25 22:08:12 +02:00
Andy Wingo
0bb980f120 New function: install-r6rs!
* doc/ref/r6rs.texi (R6RS Incompatibilities): Document install-r6rs!.
* module/ice-9/boot-9.scm (install-r6rs!): New function.
2019-09-25 22:06:38 +02:00
Andy Wingo
374c1e5807 Define top-level bindings for aux syntax: else, =>, _, ...
* module/ice-9/boot-9.scm (else, =>, ..., _): New definitions.  These
  are specified by the r6rs and the r7rs.
* module/ice-9/sandbox.scm (core-bindings): Include the aux syntax
  definitions.
* module/rnrs/base.scm:
* module/rnrs.scm: Re-export aux syntax.
2019-09-12 21:50:51 +02:00
Andy Wingo
4e89d0c061 Use "G_" as the conventional alias for gettext
Since the change in 2.2 noted in the NEWS as "Fix literal matching for
module-bound literals", defining `_' makes `syntax-rules' and `match'
fail to recognize `_' as the catch-all literal.  This change adapts the
recommendations to current practice in 2.2, as users have had to adapt
to this change.

* doc/ref/api-i18n.texi (Gettext Support): Update documentation.
* module/language/tree-il/analyze.scm (proc-ref?, gettext?): G_ is the
  conventional abbreviation, not _.
* test-suite/tests/tree-il.test: Adapt.
* module/ice-9/command-line.scm: Use G_ instead of _.
2019-09-12 21:50:35 +02:00
Andy Wingo
d1cf892880 Optimize fixnum or s64 -> f64 conversions
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add "inexact"
  intrinsic.
* libguile/jit.c (compile_s64_to_f64): New compiler.
* libguile/vm-engine.c (s64->f64): New instruction.
* module/language/cps/effects-analysis.scm (heap-numbers-equal?):
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-numbers.scm (fixnum->f64):
  (specialize-operations):
* module/language/cps/type-fold.scm (scm->f64, inexact):
* module/language/cps/types.scm (inexact, s64->f64):
* module/language/tree-il/cps-primitives.scm (exact->inexact):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*):
* module/system/vm/assembler.scm: Recognize exact->inexact as a
  primitive, and optimize it.  Add compiler support for new "inexact"
  and "s64->f64" primcalls.
2019-09-01 20:46:04 +02:00
Daniel Llorens
74f14562a6 Have disassemble-file accept an optional output port
* module/system/vm/disassembler.scm (disassemble-file): As stated.
2019-08-29 14:31:19 +02:00
Andy Wingo
887aac28d2 At optimization level -O3, seal declarative module-private bindings
* module/language/tree-il/letrectify.scm (compute-private-toplevels):
  New function; computes the subset of declarative bindings that are
  private to a module.  If the module exports a macro, all bindings are
  public, as we have no way to know what binding might be exported.
 (letrectify): Add #:seal-private-bindings? keyword arg.  If true, avoid
  making boxes for private definitions.
* module/language/tree-il/optimize.scm (optimize): Add
  -Oseal-private-bindings, enabled at -O3.
2019-08-28 10:44:44 +02:00
Andy Wingo
607d427f81 Emit warning when using "load" in declarative modules
* module/ice-9/boot-9.scm (load): Emit a warning at compile-time when
  using "load" from a declarative module.
2019-08-28 10:44:44 +02:00
Andy Wingo
a2f5f9eda4 Fix bug in CSE auxiliary definitions
* module/language/cps/cse.scm (compute-equivalent-subexpressions): When
  CSE sees a definition like `(cons a b)', it will also record an
  "auxiliary definition" for `(car x)', where x is the variable defined
  by the cons, whereby calling `(car x)' can reduce to `a' if there is
  no intervening effect that clobbers the definitions.  However, when
  the successor of the cons is a control-flow join, then any variables
  defined there have multiple definitions.  It's incorrect to add the
  aux definition in that case.
* test-suite/tests/compiler.test ("cse auxiliary definitions"): New
  test.
2019-08-28 10:44:44 +02:00