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

27 commits

Author SHA1 Message Date
Andy Wingo
7fef214f6e Remove vestigial code from srfi-9
* module/srfi/srfi-9.scm (%define-record-type): No need to define
record-layout.
2024-03-17 21:40:58 +01:00
Andy Wingo
19c7969fff define-inlinable marks residualized procedure as maybe-unused
* module/ice-9/boot-9.scm (define-inlinable):
* module/srfi/srfi-9.scm (define-tagged-inlinable): Add maybe-unused
declaration.  Also require at least one body expr, otherwise the
metadata declaration could escape as the proc body.
2023-08-24 11:43:31 +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
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
5084fa4858 Introduce make-struct/simple
* libguile/struct.h:
* libguile/struct.c (scm_make_struct_simple): New function.
* module/ice-9/boot-9.scm (make-record-type): Recast in terms of
  make-struct/simple.
* module/ice-9/eval.scm (primitive-eval): Remove allocate-struct case.
* module/srfi/srfi-9.scm (%%set-fields, %define-record-type): Use
  make-struct/simple.
2018-01-21 21:03:35 +01:00
Andy Wingo
3625351955 Match and srfi-9 expose their bailouts to the CSE pass
* module/ice-9/match.upstream.scm (match-next): Inline a call to
  "error", so the new CSE pass will see this case as a bailout.

* module/srfi/srfi-9.scm (throw-bad-struct): Reimplement as a syntax
  rule, so that the CSE pass sees the "throw" call.
2014-04-05 11:56:44 +02:00
Andy Wingo
a2972c195d Effects analysis sees match-error, throw-bad-structs as bailouts
* module/language/tree-il/effects.scm (make-effects-analyzer): Allow
  module-ref calls to be treated as bailouts, if the procedure has the
  "definite-bailout?" property.  Perhaps this should be renamed.

* module/ice-9/match.upstream.scm (match-error):
* module/srfi/srfi-9.scm (throw-bad-struct): Give these procedures the
  definite-bailout? property.
2013-11-10 10:17:44 +01:00
Mark H Weaver
c04bf4337b Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	module/srfi/srfi-9.scm
	module/web/server.scm
2013-09-13 00:24:04 -04:00
Mark H Weaver
361553b49d Adapt srfi-9.test to error reporting improvements; update copyright dates.
* module/srfi/srfi-9.scm: Add 2013 copyright date.

* test-suite/tests/srfi-9.test: Adapt to recent error reporting
  improvements to procedures defined by 'define-tagged-inlinable'.
2013-09-12 18:14:54 -04:00
Mark H Weaver
89ffbb1c2e Improve error reporting of procedures defined by define-inlinable.
* module/ice-9/boot-9.scm (define-inlinable): Improve error reporting
  when procedures defined using 'define-inlinable' are applied to the
  wrong number of arguments.

* module/srfi/srfi-9.scm (define-tagged-inlinable): Improve error
  reporting when procedures defined using 'define-tagged-inlinable' are
  applied to the wrong number of arguments.
2013-09-12 18:04:08 -04:00
Andy Wingo
746065c92e Use allocate-struct in define-record-type implementations
* module/ice-9/boot-9.scm (iota): Move up.
  (make-record-type, define-record-type): Use allocate-struct and
  struct-set!.

* module/srfi/srfi-9.scm (%%set-fields, %define-record-type): Use
  allocate-struct and struct-set!.

Note that this makes the stack VM slower, but it will make RTL
compilation faster.
2013-07-21 17:12:22 +02:00
Mark H Weaver
92fac8c056 Improve error for set-fields paths leading to different types.
* module/system/base/ck.scm: New module.

* module/srfi/srfi-9.scm: Import (system base ck).

  (getter-type, getter-index, getter-copier): Convert incoming argument
  convention to CK form.

  (define-tagged-inlinable): Convert return value convention for key
  lookup to CK form.

* module/srfi/srfi-9/gnu.scm: Import (system base ck).
  Rename '%set-fields-unknown-getter' to 'unknown-getter'.

  (c-list, c-same-type-check): New macros.

  (%set-fields): Using the CK abstract machine, arrange to check (at
  macro expansion time) that all of the getters in head position
  correspond to the same record type.

* test-suite/tests/srfi-9.test: Add test.
2012-11-10 01:37:20 -05:00
Mark H Weaver
f31a076232 Improve error messages for invalid record definitions.
* module/srfi/srfi-9.scm (%define-record-type): Accept additional 'form'
  parameter which contains the original form of 'define-record-type' or
  'define-immutable-record-type'.  Add elaborate pattern guard which
  raises descriptive syntax errors for specific errors, and a fallback
  pattern to catch anything else.
  (define-record-type): Pass 'form' parameter to %define-record-type.

* module/srfi/srfi-9/gnu.scm (define-immutable-record-type): Pass 'form'
  parameter to %define-record-type.

* test-suite/tests/srfi-9.test: Add tests.
2012-11-09 23:05:42 -05:00
Mark H Weaver
d9e368979b Implement functional record setters.
Written in collaboration with Ludovic Courtès <ludo@gnu.org>

* module/srfi/srfi-9.scm: Internally, rename 'accessor' to 'getter'
  and 'modifier' to 'setter'.

  (define-tagged-inlinable, getter-type, getter-index, getter-copier,
  %%on-error, %%set-fields): New macros.

  (%define-record-type): New macro for creating both mutable and
  immutable records, and containing a substantially rewritten version of
  the code formerly in 'define-record-type'.

  (define-record-type): Now just a wrapper for '%define-record-type'.

  (throw-bad-struct, make-copier-id): New procedures.

* module/srfi/srfi-9/gnu.scm (define-immutable-record-type, set-field,
  and set-fields): New exported macros.

  (collate-set-field-specs): New procedure.

  (%set-fields-unknown-getter, %set-fields): New macros.

* test-suite/tests/srfi-9.test: Add tests.  Rename getters and setters
  in existing tests to make the functional setters look better.
2012-11-08 19:20:28 -05:00
Ludovic Courtès
5ef102cc93 SRFI-9: Set the `record-constructor' slot of the RTD.
Fixed <http://bugs.gnu.org/11196>.
Reported by Klaus Stehle <klaus.stehle@uni-tuebingen.de>.

* module/srfi/srfi-9.scm (define-record-type): Define the contructor
  before TYPE-NAME.  Set RTD's constructor field.

* test-suite/tests/srfi-9.test ("record compatibility"): New test
  prefix.
2012-04-10 00:17:39 +02:00
Andy Wingo
8761623524 srfi-9 record compatibility with boot-9 records
* module/srfi/srfi-9.scm (define-record-type): Instead of defining the
  RTD using make-vtable, use make-struct with the record-type-vtable,
  and record the type name and fields names in the vtable.  This way
  SRFI-9 records are compatible with boot-9 records.  Also we use a
  generic printer, instead of generating one anew.
2011-08-17 10:47:04 +02:00
Ludovic Courtès
756b1dfa6e Keep a 2.0.0-compatible `define-inlinable' macro in (srfi srfi-9).
Partially reverts 165b10ddfa and
531c9f1dc5.

* module/srfi/srfi-9.scm (define-inlinable): New macro.
2011-04-27 22:26:05 +02:00
Andreas Rottmann
165b10ddfa Move `define-inlinable' into the default namespace
* module/ice-9/boot-9.scm (define-inlineable): Moved here from SRFI-9.
* module/srfi/srfi-9 (define-inlinable): Removed here.

* doc/ref/api-procedures.texi (Inlinable Procedures): Add subsection
  about `define-inlinable'.
2011-04-07 01:12:26 +02:00
Ludovic Courtès
b075a6d766 Fix `define-inlinable' in SRFI-9 so that arguments are evaluated only once.
* module/srfi/srfi-9.scm (define-inlinable): When inlining, evaluate the
  arguments only once.  Reported by Andreas Rottmann; thanks to Andy
  Wingo for the elegant solution.

* test-suite/tests/srfi-9.test ("side-effecting arguments"): New test
  prefix.
2011-03-11 21:02:30 +01:00
Andreas Rottmann
531c9f1dc5 Don't mix definitions and expressions in SRFI-9
The expansion of `define-inlinable' contained an expression, which made
SRFI-9's `define-record-type' fail in non-toplevel contexts ("definition
used in expression context").

* module/srfi/srfi-9.scm (define-inlinable): Get rid of apparently
  useless expression in the expansion, so the expansion yields only
  definitions.  At the same time, use a space in the generated names to
  lessen the chances of name conflicts, also avoiding -Wunused-toplevel
  warnings.
* test-suite/tests/srfi-9.test (non-toplevel): New test verifying that
  `define-record-type' works in non-toplevel context as well.
* doc/ref/srfi-modules.texi (SRFI-9 - define-record-type): Add
  subsubsection noting that Guile does not enforce top-levelness.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-03-09 21:36:54 +01:00
Andreas Rottmann
c4a8200fa0 Fix SRFI-9 for records without fields
* module/srfi/srfi-9.scm (define-record-type): Deal with fieldless records.
* test-suite/tests/srfi-9.test: Add a fieldless record definition.
2010-06-19 14:52:56 +02:00
Ludovic Courtès
30a700c8c1 Inline SRFI-9 constructors too.
* module/srfi/srfi-9.scm (define-record-type)[constructor]: Use
  `define-inlinable' instead of `define'.

* test-suite/lib.scm (exception:syntax-pattern-unmatched): New variable.

* test-suite/tests/srfi-9.test ("constructor")["foo 0 args (inline)",
  "foo 2 args (inline)"]: New tests.
  ["foo 0 args", "foo 2 args"]: Adjust to constructor inlining.

* testsuite/t-records.scm: Remove wrong-arg-count case.
2010-02-01 00:25:51 +01:00
Ludovic Courtès
61cbfff509 SRFI-9: Fix `define-inlinable'.
* module/srfi/srfi-9.scm (define-inlinable): Fix the catch-all case of
  the generated macro.
2010-02-01 00:25:51 +01:00
Ludovic Courtès
fe258c43a1 SRFI-9: Make accessors inlinable.
* module/srfi/srfi-9.scm (define-inlinable): New macro.
  (define-record-type): Use it.
2009-12-11 13:03:46 +01:00
Ludovic Courtès
09a8dc97db SRFI-9: Reimplement in terms of structs, using `syntax-case'.
* module/srfi/srfi-9.scm (define-record-type): Rewrite to use raw
  structs instead of records.  Use `syntax-case' instead of
  `define-macro'.
2009-12-11 13:03:46 +01:00
Neil Jerram
83ba2d3750 Complete changing license to LGPLv3+
(Still guile-readline to do, but that will all be GPLv3+.)
2009-06-17 22:30:26 +01:00
Andy Wingo
ea93465de7 move scm srfi files to module/srfi, and compile them.
* .gitignore: Add gdb-pre-inst-guile.

* configure.in: Add module/srfi/Makefile.

* module/Makefile.am: Add srfi/.

* module/srfi/: SRFI scheme files moved here, and compiled.

* srfi/Makefile.am: Remove the bits about the scheme files.
2008-11-01 13:49:23 +01:00
Renamed from srfi/srfi-9.scm (Browse further)