[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED 1/2] poked: Introduce a new channel (OUT_CMD)
From: |
Mohammad-Reza Nabipoor |
Subject: |
[COMMITTED 1/2] poked: Introduce a new channel (OUT_CMD) |
Date: |
Fri, 11 Mar 2022 00:44:07 +0330 |
The output of `pk_print_val` after `pk_compile_statement` will be
put in separate channel (OUT_CMD) instead of the OUT_OUT channel.
2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* poked/poked.c (termout_chan): Renamed from `out_chan`.
(termout_kind): Renamed from `out_kind`.
(termout_restore): New function to restore to terminal output to
OUT_OUT channel (normal text mode).
(termout_vu_append): New function to change the terminal output to
OUT_VU channel (append mode).
(termout_cmd): New function to change the terminal output to OUT_CMD
channel (normal text mode).
(iteration_send): New function to send iteration number to both
OUT_OUT and OUT_CMD channels.
(iteration_begin): New function to send iteration-begin command.
(iteration_end): New function to end iteration-end command.
(main): Send output of `pk_print_val` to OUT_CMD channel.
* poked/usock.h (USOCK_CHAN_OUT_CMD): New macro.
---
ChangeLog | 17 +++++++++
poked/poked.c | 96 ++++++++++++++++++++++++++++++++++-----------------
poked/usock.h | 1 +
3 files changed, 82 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 883f4201..12260363 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * poked/poked.c (termout_chan): Renamed from `out_chan`.
+ (termout_kind): Renamed from `out_kind`.
+ (termout_restore): New function to restore to terminal output to
+ OUT_OUT channel (normal text mode).
+ (termout_vu_append): New function to change the terminal output to
+ OUT_VU channel (append mode).
+ (termout_cmd): New function to change the terminal output to OUT_CMD
+ channel (normal text mode).
+ (iteration_send): New function to send iteration number to both
+ OUT_OUT and OUT_CMD channels.
+ (iteration_begin): New function to send iteration-begin command.
+ (iteration_end): New function to end iteration-end command.
+ (main): Send output of `pk_print_val` to OUT_CMD channel.
+ * poked/usock.h (USOCK_CHAN_OUT_CMD): New macro.
+
2022-03-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* poked/poked.c (OUTKIND_ID): Remove macro.
diff --git a/poked/poked.c b/poked/poked.c
index 43eb0ac0..fd2e40af 100644
--- a/poked/poked.c
+++ b/poked/poked.c
@@ -37,7 +37,6 @@ struct usock *srv;
#define NOK 1
static int poked_init (void);
-
static void poked_free (void);
#define OUTKIND_ITER_BEGIN 1
@@ -47,6 +46,30 @@ static void poked_free (void);
#define VUKIND_CLEAR 1
#define VUKIND_APPEND 2
+static uint8_t termout_chan = USOCK_CHAN_OUT_OUT;
+static uint32_t termout_kind = OUTKIND_TXT;
+
+static void
+termout_restore(void)
+{
+ termout_chan = USOCK_CHAN_OUT_OUT;
+ termout_kind = OUTKIND_TXT;
+}
+
+static void
+termout_vu_append(void)
+{
+ termout_chan = USOCK_CHAN_OUT_VU;
+ termout_kind = VUKIND_APPEND;
+}
+
+static void
+termout_cmd(void)
+{
+ termout_chan = USOCK_CHAN_OUT_CMD;
+ /* termout_kind = OUTKIND_TXT; // redundant */
+}
+
static void *
srvthread (void *data)
{
@@ -56,9 +79,6 @@ srvthread (void *data)
return NULL;
}
-static uint8_t out_chan = USOCK_CHAN_OUT_OUT;
-static uint32_t out_kind = OUTKIND_TXT;
-
static void
poked_buf_send (void)
{
@@ -85,6 +105,35 @@ poked_buf_send (void)
(void)pk_call (pkc, pk_decl_val (pkc, "__chan_send_reset"), NULL, NULL, 0);
}
+static void
+iteration_send (struct usock* srv, uint64_t n_iteration, int begin_p)
+{
+ uint8_t buf[8] = {
+#define b(i) (uint8_t) (n_iteration >> (i))
+ b (0), b (8), b (16), b (24), b (32), b (40), b (48), b (56),
+#undef b
+ };
+
+ usock_out (srv, begin_p ? OUTKIND_ITER_BEGIN : OUTKIND_ITER_END,
+ USOCK_CHAN_OUT_OUT, buf, sizeof (buf));
+ usock_out (srv, begin_p ? OUTKIND_ITER_BEGIN : OUTKIND_ITER_END,
+ USOCK_CHAN_OUT_CMD, buf, sizeof (buf));
+}
+
+static void
+iteration_begin (struct usock* srv, uint64_t n_iteration)
+{
+ return iteration_send (srv, n_iteration, 1);
+}
+
+static void
+iteration_end (struct usock* srv, uint64_t n_iteration)
+{
+ return iteration_send (srv, n_iteration, 0);
+}
+
+#define iteration_send private_
+
int
main ()
{
@@ -135,16 +184,7 @@ poked_restart:
printf ("< '%.*s'\n", (int)srclen, src);
n_iteration++;
- {
- uint8_t buf[8] = {
-#define b(i) (uint8_t) (n_iteration >> (i))
- b (0), b (8), b (16), b (24), b (32), b (40), b (48), b (56),
-#undef b
- };
-
- usock_out (srv, OUTKIND_ITER_BEGIN, USOCK_CHAN_OUT_OUT, buf,
- sizeof (buf));
- }
+ iteration_begin (srv, n_iteration);
ok = 0;
switch (usock_buf_tag (inbuf) & 0x7f)
@@ -173,7 +213,9 @@ poked_restart:
else if (val != PK_NULL)
{
ok = 1;
+ termout_cmd();
pk_print_val (pkc, val, &exc);
+ termout_restore();
}
}
}
@@ -202,26 +244,16 @@ poked_restart:
if (pk_int_value (pk_decl_val (pkc, "__vu_do_p")))
{
usock_out (srv, VUKIND_CLEAR, USOCK_CHAN_OUT_VU, "", 1);
- out_chan = USOCK_CHAN_OUT_VU;
- out_kind = VUKIND_APPEND;
- (void)pk_call (pkc, pk_decl_val (pkc, "__vu_dump"), NULL, NULL,
0);
- out_chan = USOCK_CHAN_OUT_OUT;
- out_kind = OUTKIND_TXT;
+ termout_vu_append ();
+ (void)pk_call (pkc, pk_decl_val (pkc, "__vu_dump"), NULL, NULL,
+ 0);
+ termout_restore ();
}
if (pk_int_value (pk_decl_val (pkc, "__chan_send_p")))
poked_buf_send ();
eol:
- {
- uint8_t buf[8] = {
-#define b(i) (uint8_t) (n_iteration >> (i))
- b (0), b (8), b (16), b (24), b (32), b (40), b (48), b (56),
-#undef b
- };
-
- usock_out (srv, OUTKIND_ITER_END, USOCK_CHAN_OUT_OUT, buf,
- sizeof (buf));
- }
+ iteration_end (srv, n_iteration);
}
}
poked_free ();
@@ -268,7 +300,7 @@ static void
tif_puts (const char *s)
{
printf (">(p) '%s'\n", s);
- usock_out (srv, out_kind, out_chan, s, strlen (s) + 1);
+ usock_out (srv, termout_kind, termout_chan, s, strlen (s) + 1);
}
static void
tif_printf (const char *fmt, ...)
@@ -284,7 +316,7 @@ tif_printf (const char *fmt, ...)
assert (n >= 0);
printf (">(P) '%.*s'\n", n, data);
- usock_out (srv, out_kind, out_chan, data, n + 1);
+ usock_out (srv, termout_kind, termout_chan, data, n + 1);
free (data);
}
static void
@@ -297,7 +329,7 @@ tif_indent (unsigned int level, unsigned int step)
assert (data);
data[0] = '\n';
memset (data + 1, ' ', len - 1);
- usock_out (srv, out_kind, out_chan, data, len);
+ usock_out (srv, termout_kind, termout_chan, data, len);
free (data);
}
static void
diff --git a/poked/usock.h b/poked/usock.h
index d7597062..1dc99510 100644
--- a/poked/usock.h
+++ b/poked/usock.h
@@ -30,6 +30,7 @@
#define USOCK_CHAN_OUT_VU 0x02
#define USOCK_CHAN_OUT_DISASM 0x03
#define USOCK_CHAN_OUT_TREEVU 0x04
+#define USOCK_CHAN_OUT_CMD 0x05
struct usock;
--
2.35.1
- [COMMITTED 1/2] poked: Introduce a new channel (OUT_CMD),
Mohammad-Reza Nabipoor <=