+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.
+
2023-02-07 Tom Tromey <tom@tromey.com>
* doc/chew.c (pcu) <l>: Now intptr_t.
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. */
} dict_type;
int internal_wanted;
-intptr_t internal_mode;
+intptr_t *internal_mode;
int warning;
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)
{
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);
}
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;
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)
{
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');
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
;
catstr
copy_past_newline
catstr
- "" swap 0 internalmode maybecatstr
+ "" swap 0 internalmode ! maybecatstr
;
: ENUMEQX ENUMEQ catstr ;
: ENUMDOC
"\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
;