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

21330 commits

Author SHA1 Message Date
Mikael Djurfeldt
f057e02d9a Correctly pass on keyword arguments actually present in args list
* module/oop/goops.scm (compute-keyword-formal-ids): Renamed from
  ->keyword-formal-ids; modified to do work both on the list of formals
  and the list of formal ids in the next-method call.
  (compute-make-procedure): Use compute-keyword-formal-ids.
2024-11-25 21:47:53 +01:00
Mikael Djurfeldt
2d18afe5ac Distinguish between lambda and lambda* in generated procedures
* module/oop/goops (compute-procedure, compute-make-procedure): Emit
  lambda or lambda* as appropriate. This doesn't matter now since all
  will boil down to lambda-case, but to be future-proof...
  Also add some clarifying comments.
2024-11-25 21:47:53 +01:00
Mikael Djurfeldt
05de7e3e61 Remove method slot keyword-formals? introduced in 765f1d49
* module/oop/goops.scm (method-keyword-formals?): Remov method slot
      keyword-formals? as well as exported procedure method-keyword-formals?
      introduced in 765f1d49 by partially reverting that commit.
2024-11-25 21:47:53 +01:00
Mikael Djurfeldt
d619da8c35 GOOPS: Introduce new forms method* and define-method*
* module/oop/goops.scm: Export method* and define-method*.
  (define-method): Extract definitions of helper procedures and place
  them in an eval-when at top level.
  (define-method*): Renamed from last commits define-method and modified
  to invoke method*.
  (define-method): New syntax.
  (parse-keyword-formals): Renamed from parse-formals and modified to
  give keyword methods a specialzers list with tail <top>.
  (parse-formals): Re-introduce the code of previous parse-args.
  (%compute-applicable-methods): Revert change of previous
  commit. Giving keyword methods a specializer tail <top> naturally
  makes original %compute-applicable-methods work also with keyword
  methods (which kind of shows that we have made the correct choices).
  (method*): Renamed from last commit's "method".
  (method): New syntax.
2024-11-25 21:47:53 +01:00
Mikael Djurfeldt
be2f965f85 GOOPS: Add support for keyword arguments in methods
* module/oop/goops.scm (keyword-formals?): New slot in <method>.
  (method-keyword-formals?): New exported <method> getter.
  (%compute-applicable-methods): Treat method as applicable if having
  matched all specializers, still have further arguments and have
  keyword-formals.
  (%compute-applicable-methods): Remove unused local variable n.
  (define-syntax method): Rename parse-args to parse-formals.
  (parse-formals): Return formals, specializers and keyword-formals.
  (compute-procedure): Make a lambda* with possibly keyword formals.
  (->formal-ids): Renamed from ->proper and now returns formal-ids.
  (->keyword-formal-ids): New procedure. Filter out formal ids from
  a keyword formal specification.
  (compute-make-procedure): Adapted for keyword formals. Needs
  ->formal-ids and ->keyword-formal-ids to compute the
  real-next-method call.
  (compute-procedures): Pass on keyword-formals.
  (syntax method): Adapted for keyword formals.
2024-11-25 21:47:53 +01:00
Andy Wingo
c51fcfffb6 psyntax: simplify free-id=?
* module/ice-9/psyntax.scm (free-id=?): Simplify.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-25 11:46:58 +01:00
Andy Wingo
2f175f3453 psyntax: Cosmetic change to overriden globals
* module/ice-9/psyntax.scm (define/override, define*/override): Use
instead of set! on globals.
($sc-dispatch): Renest.  Will compile to the same thing as before.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-20 15:55:44 +01:00
Andy Wingo
2395f3b74c psyntax: Reorder global-extend
* module/ice-9/psyntax.scm (global-extend): Put at the beginning.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19 14:40:25 +01:00
Andy Wingo
81645a25d3 psyntax: Typo fix
* module/ice-9/psyntax.scm: Fix comment typo.
2024-11-19 14:37:32 +01:00
Andy Wingo
6788bb4564 psyntax: Cosmetic change
* module/ice-9/psyntax.scm (build-simple-lambda): Reflow.
2024-11-19 14:36:07 +01:00
Andy Wingo
a14948be2f psyntax: Clean up sourcev/src namings
* module/ice-9/psyntax.scm: Look forward to the all-sourcev world by
just naming things "src".
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19 14:30:49 +01:00
Andy Wingo
2f684989e1 psyntax: Simplify output constructors.
* module/ice-9/psyntax.scm: Eta-reduce build-void, build-call, et al.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19 14:23:47 +01:00
Andy Wingo
7379049d30 psyntax: Factor module-variable use to helpers
* module/ice-9/psyntax.scm (resolve-module*, resolve-variable): New
helpers.
(free-id=?, resolve-identifier): Use new helpers.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19 11:58:23 +01:00
Andy Wingo
5ddb366375 psyntax: Remove stale analyze-variable case
* module/ice-9/psyntax.scm (analyze-variable): Remove "bare" case, long
gone.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19 09:59:15 +01:00
Andy Wingo
cdf8473b19 psyntax: Separate core expanders from their installation
* module/ice-9/psyntax.scm (expand-let, expand-letrec, ...): Name these
expanders, then install them.  Allows for better code evolution and
decreases the indent.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 16:53:41 +01:00
Andy Wingo
6c4f9a58c9 psyntax: Remove pre-3.0 hack about syntax transformer bindings.
* module/ice-9/psyntax.scm (resolve-identifier): Remove "transformer is
a pair" case.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 16:00:23 +01:00
Andy Wingo
527b4498a8 psyntax: Simplify to first-order bindings. NFC
* module/ice-9/psyntax.scm (no-source, make-empty-ribcage): Make normal
bindings, not macros.
2024-11-18 15:59:06 +01:00
Andy Wingo
522b0b4510 psyntax: Match when rebuilding macro output
* module/ice-9/psyntax.scm (expand-macro): Use match.
(eval-local-transformer): Use unless for side effect.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 15:08:18 +01:00
Andy Wingo
b4aebbd7a5 psyntax: Cleanups; ensure order of top-level expansion
* module/ice-9/psyntax.scm (build-lexical-reference): No "type"
parameter.  Adapt callers.
(valid-bound-ids?, distinct-bound-ids?, bound-id-member?): Use match.
(expand-sequence, expand-top-sequence): Use match.  For
expand-top-sequence, ensure that both phases of expansion are run in
order; was the case before, but by accident.  Don't accumulate results
in reverse.
(parse-when-list): Use match.
2024-11-18 11:15:15 +01:00
Andy Wingo
12afcc74fb psyntax: Simplify locally-bound-identifiers
* module/ice-9/psyntax.scm (locally-bound-identifiers): Simplify to use
match and scope.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 10:21:41 +01:00
Andy Wingo
54c8901adc psyntax: Simplify id-var-name
* module/ice-9/psyntax.scm (id-var-name): No need for `search` to return
the marks.  Simplify to use scope instead of repeating, and use match.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 10:11:53 +01:00
Andy Wingo
14414655d3 psyntax: Fix bug introduced in 0295409483
* module/ice-9/psyntax.scm (analyze-variable): Fix erroneous pattern
matching.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18 10:07:50 +01:00
Andy Wingo
2daea40200 psyntax: Use new `match' instead of cdadring
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm: Use `match' more.  Also use more first-order
definitions.  NFC.
2024-11-15 15:35:10 +01:00
Andy Wingo
0295409483 psyntax: Use new `match' instead of cdadring
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm: Use `match' more.  NFC.
2024-11-15 14:27:27 +01:00
Andy Wingo
d94292724b psyntax: Add simple pattern matcher
* module/ice-9/psyntax.scm (simple-match1, simple-match-pat,
simple-match-patv, match): Add simple pattern matcher.
* module/ice-9/psyntax-pp.scm: Regenerate.  Just different renumbering
of temps.
2024-11-15 14:16:20 +01:00
Andy Wingo
d30b39e4ea psyntax: Avoid lambda in procedure definitions
* module/ice-9/psyntax.scm: Instead of e.g. (define foo (lambda (x)
  ...)), do (define (foo x) ...).  No functional change.
2024-11-15 14:06:32 +01:00
Andy Wingo
4f05d1709b psyntax: Remove a useless level of let
* module/ice-9/psyntax.scm: Remove let around the body.
2024-11-15 13:57:57 +01:00
Andy Wingo
3b230745fe psyntax: Inline the single use of define-structure
* module/ice-9/psyntax.scm (define-structure): Remove, inline into use.
No predicate needed.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-15 13:56:04 +01:00
Andy Wingo
8c78234e80 psyntax: Functional annotation of function names
* module/ice-9/psyntax.scm (maybe-name-value): Return a fresh lambda
instead of mutating the given lambda.
(define-expansion-accessors): No need to define setters.
2024-11-14 16:54:25 +01:00
Andy Wingo
f376e6445d psyntax: Clean up use of fx+, etc
* module/ice-9/psyntax.scm (fx+, fx-, fx=): Remove.  Replace uses with
1+, 1-, =.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14 16:11:51 +01:00
Andy Wingo
dd18780fb8 psyntax: Rename top-level-eval, local-eval
* module/ice-9/psyntax.scm (top-level-eval, local-eval): Rename from
top-level-eval-hook, local-eval-hook.  Adapt callers.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14 16:02:20 +01:00
Andy Wingo
d60aeb3ced psyntax: Use vectors instead of gensyms for labels, marks
* module/ice-9/psyntax.scm (gen-unique): Instead of making a string with
an embedded hex counter, make a vector.  A little less work than making
a string, and slightly smaller binaries.
(gen-label, gen-mark): Use gen-unique.
(resolve-identifier): Adapt case that recognizes labels denoting
lexicals to be less strict.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14 16:00:18 +01:00
Andy Wingo
70e2616975 psyntax: Remove useless gen-label invocations
* module/ice-9/psyntax.scm (expand-top-sequence): Remove needless
gen-label uses, and replace one use with gen-lexical (which is what is
needed).
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14 15:46:05 +01:00
Andy Wingo
ebbb10c92d psyntax: Clean up lexical gensym creation
* module/ice-9/psyntax.scm (gen-lexical): Add a nice comment.  Rename
from build-lexical-var, and remove unused src argument.
(gen-var, generate-temporaries): Use gen-lexical.
* module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14 15:34:15 +01:00
Natanael Copa
bb7154fb80
Fix build failure with GCC 14 and musl on 32-bit systems.
Fixes <https://bugs.gnu.org/73835>.

This fixes this error when compiling with GCC 14 and musl libc on 32-bit
Alpine Linux:

  filesys.c: In function 'scm_sendfile':
  filesys.c:1405:16: error: assignment to 'off_t *' {aka 'long long int *'} from incompatible pointer type 'scm_t_off *' {aka 'long int *'} [-Wincompatible-pointer-types]
   1405 |     offset_ptr = SCM_UNBNDP (offset) ? NULL : &c_offset;
	|                ^

* libguile/filesys.c (scm_sendfile): Change type of ‘c_offset’.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:45:12 +02:00
Tomas Volf
1c093d8bc4
doc: Recommend alist-copy instead of list-copy.
The current recommendation of `list-copy' is not right and does not lead
to preserving the original list:

    scheme@(guile-user)> (define x (list (cons 'a 1) (cons 'b 2)))
    scheme@(guile-user)> (define y (list-copy x))
    scheme@(guile-user)> (assq-set! y 'b 3)
    $1 = ((a . 1) (b . 3))
    scheme@(guile-user)> x
    $2 = ((a . 1) (b . 3))

Correct approach seems to be use `alist-copy' from SRFI-1 leading to the
expected behavior of:

    scheme@(guile-user)> ,use (srfi srfi-1)
    scheme@(guile-user)> (define x (list (cons 'a 1) (cons 'b 2)))
    scheme@(guile-user)> (define y (alist-copy x))
    scheme@(guile-user)> (assq-set! y 'b 3)
    $1 = ((a . 1) (b . 3))
    scheme@(guile-user)> x
    $2 = ((a . 1) (b . 2))

* doc/ref/api-data.texi (Adding or Setting Alist Entries): Recommend
`alist-copy'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:45:11 +02:00
Nikolaos Chatzikonstantinou
a0368a6120
doc: Fix typo in FFI documentation.
The incorrect procedure is mentioned; see the example that immediately
follows.

* doc/ref/api-foreign.texi (Foreign Functions): fix typo to
pointer->procedure.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:45:03 +02:00
Juliana Sims
8d45f63c85
doc: Document the peek and pk procedures.
* doc/ref/api-debug.texi: Document the peek and pk procedures.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:44:41 +02:00
Tomas Volf
bfff7e1d6d
doc: Fix implication of omitting optional arguments.
According to the previous wording, omitting all optional arguments led
to empty interface.  That however was not the case and was only a
documentation bug (as confirmed by wingo on IRC).  So let us fix that.

* doc/ref/api-modules.texi (Using Guile Modules): Fix implication of
omitting optional arguments.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:44:40 +02:00
Tomas Volf
130fdb0c8d
doc: Document #:hide.
* doc/ref/api-modules.texi (Using Guile Modules): Document #:hide.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:44:40 +02:00
Tomas Volf
1a5e35f0eb
srfi-64: Accept symbols as test group names.
The specification mandates a string, but with rationale suggesting symbols
would be a more natural fit.

> In some ways using symbols would be preferable. However, we want
> human-readable names, and standard Scheme does not provide a way to include
> spaces or mixed-case text in literal symbols.

Add support for symbols as an implementation extension and for backwards
compatibility with the reference implementation.

* module/srfi/srfi-64.scm (%cmp-group-name): New procedure.
(test-end): Use it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Reported-by: Daniel Llorens <lloda@sarc.name>
2024-10-26 19:44:40 +02:00
Taylan Kammer
242e8698c2 Better REPL behavior on syntax errors in meta commands.
Fixes <https://bugs.gnu.org/30600>.

* module/system/repl/command.scm (define-meta-command): Flush all
remaining input after handling a read error.
* module/system/repl/common.scm (flush-all-input): New public procedure.
* module/system/repl/repl.scm: Remove local flush-all-input definition.
2024-10-25 13:35:31 +02:00
Daniel Llorens
818b879b2e doc: Fix use of literals in alist example
Fixes https://bugs.gnu.org/32841.

* doc/ref/srfi-modules.texi (alist-copy): Add anchor.
* doc/ref/api-data.texi (Alist Example): Fix use of literals.
2024-10-22 11:42:20 +02:00
Ludovic Courtès
faa8ab8a88
Update NEWS. 2024-10-20 21:22:55 +02:00
Tomas Volf
0175343deb
posix.c: Set errno when pipe2 is not available and flags provided.
If pipe2 is not available (e.g. on MacOS) and flags are set,
SCM_SYSERROR was correctly signaled, however errno was not set, so it
reported as:

    Undefined error: 0

That sucks both in tests (the test is not skipped) and in actual
usage (user has no idea what went wrong).

So set errno to ENOSYS as well.

* libguile/posix.c (scm_pipe2) [!HAVE_PIPE2] <c_flags>: Set errno to
ENOSYS.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
ff256c356b
Do not depend on tmpnam in posix.test.
`tmpnam' is a deprecated procedure that can be excluded during a
configure (`--disable-tmpnam').  There currently was a single test
relying on it, and therefore failing is such configuration.  This commit
switches to mkstemp instead.

* test-suite/tests/posix.test ("system*"): Use mkstemp instead of
tmpnam.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
58a722d883
tests: Fix spawn if file not found with Gnulib.
On Darwin posix_spawnp is not considered secured and therefore we
fallback to Gnulib's version.  That one however does not return ENOENT
when the file does not exist, but PID of the child process.  This seems
to be allowed by the standard.

* test-suite/tests/posix.test (skip-on-darwin): New procedure.
("spawn")["file not file"]: Skip on Darwin.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
1746dbbe4d
tests: Fix spawn with #:environment on MacOS.
MacOS adds __CF_USER_TEXT_ENCODING to every program, in similar way GNU
Hurd prepends LD_ORIGIN_PATH (based on the comment).  So extend the
logic to do similar stripping on MacOS.

* test-suite/tests/posix.test ("spawn")
["env with #:environment and #:output"]: Strip trailing
__CF_USER_TEXT_ENCODING environment variable when on Darwin.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
8579b73aba
tests: Skip mkdtemp test for invalid template on Darwin.
Darwin accepts any template, as demonstrated here:

    #include <stdio.h>
    #include <unistd.h>

    int
    main(void)
    {
    	char template[] = {'T', '-', 'A', 'A', 'A', 'A', 'A', 'A', '\0'};
    	char *res = mkdtemp(template);
    	puts(res ? res : "(null)");
    	perror("mkdtemp");
    }

Outputs:

    T-AAAAAA
    mkdtemp: Undefined error: 0

This does not match prescribed POSIX behavior, but it is what it is.

* test-suite/tests/filesys.test (skip-on-darwin): New procedure.
("mkdtemp")["invalid template"]: Skip on Darwin.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
0ceb0036c3
filesys.c: Fix readlink for ports on Darwin.
When passed a port, `readlink' relies on the Linux specific behavior of
empty c_path meaning "the fd itself".  That does not work on Darwin.
Since there is no branch that would yield both fd and c_path, fallback
to freadlink when __APPLE__ is defined.

* libguile/filesys.c (do_readlink): Call freadlink for !__APPLE__.
* configure.ac (AC_CHECK_FUNCS): Add freadlink.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00