From 9425ad37ec95a40dc039169031259161c92cc217 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 31 Aug 2025 02:24:11 +0300 Subject: support <:O>: if a label is not found, continue execution after the go-to statement * this is a SciTECO extension - it's not in TECO-11 * Allows for select-case-like constructs with default-clauses as in :Os.^EQa$ !* default *! !s.foo! !* ... *! !s.bar! !* ... *! * Consistent with nOlabel0,label1,...$ if is out of range. Unfortunately this form of computed goto is not applicable when "selecting" by strings or non-consecutive integers. * In order to continue after the <:O> statement, we must keep the program counter along with the label we were looking for. At the end of the macro, the PC is restored instead of throwing an error. * Since that would be very inefficient in loops - where potentially all iterations would result in rescanning till the end of the macro - we now store a completed-flag in the goto table. If it is set while trying to :O to an unknown label, we can just continue execution. --- src/goto.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/goto.h') diff --git a/src/goto.h b/src/goto.h index eda823f..05c7598 100644 --- a/src/goto.h +++ b/src/goto.h @@ -26,10 +26,14 @@ typedef struct { teco_rb3str_tree_t tree; + /** Whether to generate undo tokens (unnecessary in macro invocations) */ + guint must_undo : 1; + /** - * Whether to generate undo tokens (unnecessary in macro invocations) + * Whether the table is guaranteed to be complete because the entire + * macro has already been parsed. */ - gboolean must_undo; + guint complete : 1; } teco_goto_table_t; /** @memberof teco_goto_table_t */ @@ -38,6 +42,7 @@ teco_goto_table_init(teco_goto_table_t *ctx, gboolean must_undo) { rb3_reset_tree(&ctx->tree); ctx->must_undo = must_undo; + ctx->complete = FALSE; } gboolean teco_goto_table_remove(teco_goto_table_t *ctx, const gchar *name, gsize len); -- cgit v1.2.3