summaryrefslogtreecommitdiff
path: root/module/srfi/srfi-9.scm
AgeCommit message (Collapse)AuthorFilesLines
2019-10-23SRFI-9 uses make-record-typeAndy Wingo1-12/+7
* 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-22Allow records to be subtypedAndy Wingo1-1/+4
* 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.
2018-01-21Introduce make-struct/simpleAndy Wingo1-27/+24
* 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.
2014-04-05Match and srfi-9 expose their bailouts to the CSE passAndy Wingo1-6/+6
* 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.
2013-11-10Effects analysis sees match-error, throw-bad-structs as bailoutsAndy Wingo1-0/+1
* 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-09-13Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-1/+4
Conflicts: module/srfi/srfi-9.scm module/web/server.scm
2013-09-12Adapt srfi-9.test to error reporting improvements; update copyright dates.Mark H Weaver1-1/+2
* 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-12Improve error reporting of procedures defined by define-inlinable.Mark H Weaver1-0/+2
* 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-07-21Use allocate-struct in define-record-type implementationsAndy Wingo1-28/+34
* 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.
2012-11-10Improve error for set-fields paths leading to different types.Mark H Weaver1-7/+14
* 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-09Improve error messages for invalid record definitions.Mark H Weaver1-7/+37
* 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-08Implement functional record setters.Mark H Weaver1-81/+171
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-04-10SRFI-9: Set the `record-constructor' slot of the RTD.Ludovic Courtès1-4/+8
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.
2011-08-17srfi-9 record compatibility with boot-9 recordsAndy Wingo1-10/+22
* 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-04-27Keep a 2.0.0-compatible `define-inlinable' macro in (srfi srfi-9).Ludovic Courtès1-0/+31
Partially reverts 165b10ddfaaa8ecc72d45a9be7d29e7537dc2379 and 531c9f1dc51c4801c4d031ee80a31f15285a6b85. * module/srfi/srfi-9.scm (define-inlinable): New macro.
2011-04-07Move `define-inlinable' into the default namespaceAndreas Rottmann1-32/+0
* 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-03-11Fix `define-inlinable' in SRFI-9 so that arguments are evaluated only once.Ludovic Courtès1-3/+6
* 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-09Don't mix definitions and expressions in SRFI-9Andreas Rottmann1-3/+5
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>
2010-06-19Fix SRFI-9 for records without fieldsAndreas Rottmann1-0/+4
* module/srfi/srfi-9.scm (define-record-type): Deal with fieldless records. * test-suite/tests/srfi-9.test: Add a fieldless record definition.
2010-02-01Inline SRFI-9 constructors too.Ludovic Courtès1-2/+2
* 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-01SRFI-9: Fix `define-inlinable'.Ludovic Courtès1-0/+1
* module/srfi/srfi-9.scm (define-inlinable): Fix the catch-all case of the generated macro.
2009-12-11SRFI-9: Make accessors inlinable.Ludovic Courtès1-3/+29
* module/srfi/srfi-9.scm (define-inlinable): New macro. (define-record-type): Use it.
2009-12-11SRFI-9: Reimplement in terms of structs, using `syntax-case'.Ludovic Courtès1-26/+98
* module/srfi/srfi-9.scm (define-record-type): Rewrite to use raw structs instead of records. Use `syntax-case' instead of `define-macro'.
2009-06-17Complete changing license to LGPLv3+Neil Jerram1-1/+1
(Still guile-readline to do, but that will all be GPLv3+.)
2008-11-01move scm srfi files to module/srfi, and compile them.Andy Wingo1-0/+91
* .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.