From: Tom Tromey <tom@tromey.com>
To: binutils@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 6/8] Change internalmode to be an intrinsic variable
Date: Wed, 8 Feb 2023 00:17:23 -0700 [thread overview]
Message-ID: <20230208071725.3668898-7-tom@tromey.com> (raw)
In-Reply-To: <20230208071725.3668898-1-tom@tromey.com>
Currently, internalmode is a special word to set an internal state
variable. Because this series adds variables anyway, change this to
be a variable instead.
I saw some commits in the history that made sure that chew did not
leak memory, so I put some extra effort into trying to handle this for
variables as well.
2023-02-07 Tom Tromey <tom@tromey.com>
* doc/proto.str (external, internal, ifinternal, ENUMEQ, ENUMDOC):
Update.
* doc/chew.c (internalmode): Remove.
(add_intrinsic_variable): New function.
(main): Add internalmode as intrinsic.
(internal_mode): Remove global.
(maybecatstr): Update.
(free_words): Free variables.
---
bfd/ChangeLog | 11 +++++++++++
bfd/doc/chew.c | 46 +++++++++++++++++++++++++++++++++-------------
bfd/doc/proto.str | 12 ++++++------
3 files changed, 50 insertions(+), 19 deletions(-)
diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c
index 510a8e968c5..b17b20a183f 100644
--- a/bfd/doc/chew.c
+++ b/bfd/doc/chew.c
@@ -70,12 +70,13 @@
translatecomments - turn {* and *} into comment delimiters
kill_bogus_lines - get rid of extra newlines
indent
- internalmode - pop from integer stack, set `internalmode' to that value
print_stack_level - print current stack depth to stderr
strip_trailing_newlines - go ahead, guess...
[quoted string] - push string onto string stack
[word starting with digit] - push atol(str) onto integer stack
+ internalmode - the internalmode variable (evaluates to address)
+
A command must be all upper-case, and alone on a line.
Foo. */
@@ -119,7 +120,7 @@ typedef struct dict_struct
} dict_type;
int internal_wanted;
-intptr_t internal_mode;
+intptr_t *internal_mode;
int warning;
@@ -376,6 +377,14 @@ push_number (void)
pc++;
}
+/* This is a wrapper for push_number just so we can correctly free the
+ variable at the end. */
+static void
+push_variable (void)
+{
+ push_number ();
+}
+
static void
push_text (void)
{
@@ -993,19 +1002,10 @@ skip_past_newline (void)
pc++;
}
-static void
-internalmode (void)
-{
- internal_mode = *(isp);
- isp--;
- icheck_range ();
- pc++;
-}
-
static void
maybecatstr (void)
{
- if (internal_wanted == internal_mode)
+ if (internal_wanted == *internal_mode)
{
catstr (tos - 1, tos);
}
@@ -1138,6 +1138,11 @@ free_words (void)
free (ptr->code[i + 1].s - 1);
++i;
}
+ else if (ptr->code[i].f == push_variable)
+ {
+ free ((void *) ptr->code[i + 1].l);
+ ++i;
+ }
free (ptr->code);
}
next = ptr->next;
@@ -1217,6 +1222,18 @@ add_intrinsic (char *name, void (*func) (void))
add_to_definition (new_d, p);
}
+static void
+add_intrinsic_variable (char *name, intptr_t *loc)
+{
+ dict_type *new_d = newentry (xstrdup (name));
+ pcu p = { push_variable };
+ add_to_definition (new_d, p);
+ p.l = (intptr_t) loc;
+ add_to_definition (new_d, p);
+ p.f = 0;
+ add_to_definition (new_d, p);
+}
+
void
compile (char *string)
{
@@ -1430,10 +1447,13 @@ main (int ac, char *av[])
add_intrinsic ("translatecomments", translatecomments);
add_intrinsic ("kill_bogus_lines", kill_bogus_lines);
add_intrinsic ("indent", indent);
- add_intrinsic ("internalmode", internalmode);
add_intrinsic ("print_stack_level", print_stack_level);
add_intrinsic ("strip_trailing_newlines", strip_trailing_newlines);
+ internal_mode = xmalloc (sizeof (intptr_t));
+ *internal_mode = 0;
+ add_intrinsic_variable ("internalmode", internal_mode);
+
/* Put a nl at the start. */
catchar (&buffer, '\n');
diff --git a/bfd/doc/proto.str b/bfd/doc/proto.str
index 7bebbc26f8f..5206f7f3877 100644
--- a/bfd/doc/proto.str
+++ b/bfd/doc/proto.str
@@ -34,16 +34,16 @@
ignore ;
: external
- 0 internalmode ignore ;
+ 0 internalmode ! ignore ;
: internal
- 1 internalmode ignore ;
+ 1 internalmode ! ignore ;
- input stack { a b } output b if internal, a if external
: ifinternal
- "" swap 1 internalmode maybecatstr
+ "" swap 1 internalmode ! maybecatstr
swap
- "" swap 0 internalmode maybecatstr
+ "" swap 0 internalmode ! maybecatstr
catstr
;
@@ -123,7 +123,7 @@
catstr
copy_past_newline
catstr
- "" swap 0 internalmode maybecatstr
+ "" swap 0 internalmode ! maybecatstr
;
: ENUMEQX ENUMEQ catstr ;
: ENUMDOC
@@ -133,7 +133,7 @@
"\n{* " swap catstr " *}\n" catstr
translatecomments
- discard it if we're doing internal mode
- "" swap 0 internalmode maybecatstr
+ "" swap 0 internalmode ! maybecatstr
swap
catstr catstr
;
--
2.39.1
next prev parent reply other threads:[~2023-02-08 7:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 7:17 [PATCH 0/8] Make the BFD info manual a bit prettier Tom Tromey
2023-02-08 7:17 ` [PATCH 1/8] Remove H_CFLAGS from doc/local.mk Tom Tromey
2023-02-08 7:17 ` [PATCH 2/8] Simplify @node use in BFD documentation Tom Tromey
2023-03-03 8:20 ` Jan Beulich
2023-03-03 23:08 ` Tom Tromey
2023-03-06 7:07 ` Jan Beulich
2023-02-08 7:17 ` [PATCH 3/8] Add copyright headers to the .str files Tom Tromey
2023-02-08 7:17 ` [PATCH 4/8] Remove the paramstuff word Tom Tromey
2023-02-08 7:17 ` [PATCH 5/8] Use intptr_t rather than long in chew Tom Tromey
2023-02-08 7:17 ` Tom Tromey [this message]
2023-02-08 7:17 ` [PATCH 7/8] Use @deftypefn in chew output Tom Tromey
2023-02-15 17:55 ` Simon Marchi
2023-02-15 23:11 ` Tom Tromey
2023-02-16 1:29 ` Simon Marchi
2023-02-19 3:46 ` Alan Modra
2023-02-08 7:17 ` [PATCH 8/8] Remove RETURNS from BFD chew comments Tom Tromey
2023-02-15 9:54 ` [PATCH 0/8] Make the BFD info manual a bit prettier Nick Clifton
2023-02-15 21:51 ` Tom Tromey
2023-02-16 9:40 ` Nick Clifton
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230208071725.3668898-7-tom@tromey.com \
--to=tom@tromey.com \
--cc=binutils@sourceware.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.
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).