From 1cfe37610253c20a4fcb0d937c29e70894ecc4f5 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 22 Nov 2024 16:59:07 +0300 Subject: the search mode and current radix are mapped to __local__ Q-Registers ^X and ^R now (refs #17) * This way the search mode and radix are local to the current macro frame, unless the macro was invoked with :Mq. If colon-modified, you can reproduce the same effect by calling [.^X 0^X ... ].^X * The radix register is cached in the Q-Reg table as an optimization. This could be done with the other "special" registers as well, but at the cost of larger stack frames. * In order to allow constructs like [.^X typed with upcarets, the Q-Register specification syntax has been extended: ^c is the corresponding control code instead of the register "^". --- src/expressions.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/expressions.c') diff --git a/src/expressions.c b/src/expressions.c index ee6b4dc..25213e9 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -23,6 +23,7 @@ #include "sciteco.h" #include "error.h" #include "undo.h" +#include "qreg.h" #include "expressions.h" /* @@ -57,7 +58,6 @@ teco_expressions_precedence(teco_operator_t op) } gint teco_num_sign = 1; -gint teco_radix = 10; void teco_expressions_push_int(teco_int_t number) @@ -114,12 +114,20 @@ teco_expressions_pop_num_calc(teco_int_t *ret, teco_int_t imply, GError **error) } void -teco_expressions_add_digit(gunichar digit) +teco_expressions_add_digit(gunichar digit, teco_qreg_t *qreg) { + /* + * FIXME: We could just access qreg->integer here since + * we can assume that "^R" is a plain register. + */ + assert(qreg != NULL); + teco_int_t radix = 10; + qreg->vtable->get_integer(qreg, &radix, NULL); + teco_int_t n = teco_expressions_args() > 0 ? teco_expressions_pop_num(0) : 0; /* use g_unichar_digit_value()? */ - teco_expressions_push(n*teco_radix + (n < 0 ? -1 : 1)*((gint)digit - '0')); + teco_expressions_push(n*radix + (n < 0 ? -1 : 1)*((gint)digit - '0')); } void @@ -378,21 +386,26 @@ teco_expressions_clear(void) * @param buffer The output buffer of at least TECO_EXPRESSIONS_FORMAT_LEN characters. * The output string will be null-terminated. * @param number The number to format. + * @param table The local Q-Register table that contains the appropriate radix register (^R). * @return A pointer into buffer to the beginning of the formatted number. */ gchar * -teco_expressions_format(gchar *buffer, teco_int_t number) +teco_expressions_format(gchar *buffer, teco_int_t number, teco_qreg_t *qreg) { + assert(qreg != NULL); + teco_int_t radix = 10; + qreg->vtable->get_integer(qreg, &radix, NULL); + gchar *p = buffer + TECO_EXPRESSIONS_FORMAT_LEN; teco_int_t v = ABS(number); *--p = '\0'; do { - *--p = '0' + (v % teco_radix); + *--p = '0' + (v % radix); if (*p > '9') *p += 'A' - '9' - 1; - } while ((v /= teco_radix)); + } while ((v /= radix)); if (number < 0) *--p = '-'; -- cgit v1.2.3