From: "Ludovic Courtès" <ludo@gnu.org>
To: 40077@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#40077] [PATCH 1/4] repl: Allow clients to send their protocol version.
Date: Sun, 15 Mar 2020 18:15:04 +0100 [thread overview]
Message-ID: <20200315171507.22910-1-ludo@gnu.org> (raw)
In-Reply-To: <20200315170019.22544-1-ludo@gnu.org>
* guix/repl.scm (send-repl-response): Add #:version.
(machine-repl): Make 'loop' an internal define with a
'version' parameter. Pass VERSION to 'send-repl-response'.
Send (0 1) as the protocol version.
If the first element read from INPUT matches (() repl-version _ ...),
interpret it as the client's protocol version.
---
guix/repl.scm | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/guix/repl.scm b/guix/repl.scm
index 0f75f9cd0b..a141003812 100644
--- a/guix/repl.scm
+++ b/guix/repl.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -39,9 +39,10 @@
(one-of symbol? string? keyword? pair? null? array?
number? boolean? char?)))
-(define (send-repl-response exp output)
+(define* (send-repl-response exp output
+ #:key (version '(0 0)))
"Write the response corresponding to the evaluation of EXP to PORT, an
-output port."
+output port. VERSION is the client's protocol version we are targeting."
(define (value->sexp value)
(if (self-quoting? value)
`(value ,value)
@@ -72,13 +73,26 @@ The protocol of this REPL is meant to be machine-readable and provides proper
support to represent multiple-value returns, exceptions, objects that lack a
read syntax, and so on. As such it is more convenient and robust than parsing
Guile's REPL prompt."
- (write `(repl-version 0 0) output)
- (newline output)
- (force-output output)
-
- (let loop ()
- (match (read input)
+ (define (loop exp version)
+ (match exp
((? eof-object?) #t)
(exp
- (send-repl-response exp output)
- (loop)))))
+ (send-repl-response exp output
+ #:version version)
+ (loop (read input) version))))
+
+ (write `(repl-version 0 1) output)
+ (newline output)
+ (force-output output)
+
+ ;; In protocol version (0 0), clients would not send their supported
+ ;; protocol version. Thus, the code below checks for two case: (1) a (0 0)
+ ;; client that directly sends an expression to evaluate, and (2) a more
+ ;; recent client that sends (() repl-version ...). This form is chosen to
+ ;; be unambiguously distinguishable from a regular Scheme expression.
+
+ (match (read input)
+ ((() 'repl-version version ...)
+ (loop (read input) version))
+ (exp
+ (loop exp '(0 0)))))
--
2.25.1
next prev parent reply other threads:[~2020-03-15 17:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-15 17:00 [bug#40077] [PATCH 0/4] Inferior provide stack traces along with exceptions Ludovic Courtès
2020-03-15 17:15 ` Ludovic Courtès [this message]
2020-03-15 17:15 ` [bug#40077] [PATCH 2/4] inferior: Adjust to protocol (0 1) Ludovic Courtès
2020-03-15 17:15 ` [bug#40077] [PATCH 3/4] repl: Return stack traces along with exceptions Ludovic Courtès
2020-03-15 17:15 ` [bug#40077] [PATCH 4/4] inferior: '&inferior-exception' includes a stack trace Ludovic Courtès
2020-03-19 14:15 ` bug#40077: [PATCH 0/4] Inferior provide stack traces along with exceptions Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200315171507.22910-1-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=40077@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).