diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-09-13 01:31:49 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-09-13 01:49:22 +0200 |
commit | a9224ebee3b6458dee42d76ec76b1a704e206107 (patch) | |
tree | 5582c794f37cd092a987ce8dc9ae49723d46a1a0 | |
parent | c2057ebf7e2a34eccd615a7d88085e247e5b9e9f (diff) | |
download | sciteco-a9224ebee3b6458dee42d76ec76b1a704e206107.tar.gz |
remaining types of program counters changed to gsize/gssize
* This fixes F< to the beginning of the macro, which was broken in 73d574b71a10d4661ada20275cafde75aff6c1ba.
teco_machine_main_t::macro_pc actually has to be signed as it is sometimes set to -1.
-rw-r--r-- | src/cmdline.c | 2 | ||||
-rw-r--r-- | src/goto-commands.c | 6 | ||||
-rw-r--r-- | src/goto.c | 20 | ||||
-rw-r--r-- | src/goto.h | 8 | ||||
-rw-r--r-- | src/parser.c | 11 | ||||
-rw-r--r-- | src/parser.h | 5 | ||||
-rw-r--r-- | tests/testsuite.at | 4 |
7 files changed, 30 insertions, 26 deletions
diff --git a/src/cmdline.c b/src/cmdline.c index e402124..0d32513 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -87,7 +87,7 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) { const teco_string_t src = {(gchar *)data, len}; teco_string_t old_cmdline = {NULL, 0}; - guint repl_pc = 0; + gsize repl_pc = 0; teco_cmdline.machine.macro_pc = teco_cmdline.pc = teco_cmdline.effective_len; diff --git a/src/goto-commands.c b/src/goto-commands.c index bf80c0b..a8a9689 100644 --- a/src/goto-commands.c +++ b/src/goto-commands.c @@ -61,8 +61,8 @@ teco_state_label_input(teco_machine_main_t *ctx, gunichar chr, GError **error) * on rubout. * Otherwise, the label will be removed (PC == -1). */ - gint existing_pc = teco_goto_table_set(&ctx->goto_table, ctx->goto_label.data, - ctx->goto_label.len, ctx->macro_pc); + gssize existing_pc = teco_goto_table_set(&ctx->goto_table, ctx->goto_label.data, + ctx->goto_label.len, ctx->macro_pc); if (ctx->parent.must_undo) teco_goto_table_undo_set(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len, existing_pc); @@ -119,7 +119,7 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError } if (value == 0) { - gint pc = teco_goto_table_find(&ctx->goto_table, label.data, label.len); + gssize pc = teco_goto_table_find(&ctx->goto_table, label.data, label.len); if (pc >= 0) { ctx->macro_pc = pc; @@ -35,12 +35,12 @@ /** @extends teco_rb3str_head_t */ typedef struct { teco_rb3str_head_t head; - gint pc; + gsize pc; } teco_goto_label_t; /** @private @static @memberof teco_goto_label_t */ static teco_goto_label_t * -teco_goto_label_new(const gchar *name, gsize len, gint pc) +teco_goto_label_new(const gchar *name, gsize len, gsize pc) { teco_goto_label_t *label = g_new0(teco_goto_label_t, 1); teco_string_init(&label->head.name, name, len); @@ -79,10 +79,10 @@ teco_goto_table_dump(teco_goto_table_t *ctx) #endif /** @memberof teco_goto_table_t */ -gint +gssize teco_goto_table_remove(teco_goto_table_t *ctx, const gchar *name, gsize len) { - gint existing_pc = -1; + gssize existing_pc = -1; teco_goto_label_t *label = (teco_goto_label_t *)teco_rb3str_find(&ctx->tree, TRUE, name, len); if (label) { @@ -95,7 +95,7 @@ teco_goto_table_remove(teco_goto_table_t *ctx, const gchar *name, gsize len) } /** @memberof teco_goto_table_t */ -gint +gssize teco_goto_table_find(teco_goto_table_t *ctx, const gchar *name, gsize len) { teco_goto_label_t *label = (teco_goto_label_t *)teco_rb3str_find(&ctx->tree, TRUE, name, len); @@ -103,13 +103,13 @@ teco_goto_table_find(teco_goto_table_t *ctx, const gchar *name, gsize len) } /** @memberof teco_goto_table_t */ -gint -teco_goto_table_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gint pc) +gssize +teco_goto_table_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gssize pc) { if (pc < 0) return teco_goto_table_remove(ctx, name, len); - gint existing_pc = -1; + gssize existing_pc = -1; teco_goto_label_t *label = (teco_goto_label_t *)teco_rb3str_find(&ctx->tree, TRUE, name, len); if (label) { @@ -135,7 +135,7 @@ teco_goto_table_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gint p */ typedef struct { teco_goto_table_t *table; - gint pc; + gssize pc; gsize len; gchar name[]; } teco_goto_table_undo_set_t; @@ -153,7 +153,7 @@ teco_goto_table_undo_set_action(teco_goto_table_undo_set_t *ctx, gboolean run) /** @memberof teco_goto_table_t */ void -teco_goto_table_undo_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gint pc) +teco_goto_table_undo_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gssize pc) { if (!ctx->must_undo) return; @@ -40,12 +40,12 @@ teco_goto_table_init(teco_goto_table_t *ctx, gboolean must_undo) ctx->must_undo = must_undo; } -gint teco_goto_table_remove(teco_goto_table_t *ctx, const gchar *name, gsize len); +gssize teco_goto_table_remove(teco_goto_table_t *ctx, const gchar *name, gsize len); -gint teco_goto_table_find(teco_goto_table_t *ctx, const gchar *name, gsize len); +gssize teco_goto_table_find(teco_goto_table_t *ctx, const gchar *name, gsize len); -gint teco_goto_table_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gint pc); -void teco_goto_table_undo_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gint pc); +gssize teco_goto_table_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gssize pc); +void teco_goto_table_undo_set(teco_goto_table_t *ctx, const gchar *name, gsize len, gssize pc); /** @memberof teco_goto_table_t */ static inline gboolean diff --git a/src/parser.c b/src/parser.c index 3c37f81..45e31cf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -102,12 +102,6 @@ gboolean teco_machine_main_step(teco_machine_main_t *ctx, const gchar *macro, gsize stop_pos, GError **error) { while (ctx->macro_pc < stop_pos) { -#ifdef DEBUG - g_printf("EXEC(%d): input='%c'/%x, state=%p, mode=%d\n", - ctx->macro_pc, macro[ctx->macro_pc], macro[ctx->macro_pc], - ctx->parent.current, ctx->mode); -#endif - if (G_UNLIKELY(teco_interface_is_interrupted())) { teco_error_interrupted_set(error); goto error_attach; @@ -123,6 +117,11 @@ teco_machine_main_step(teco_machine_main_t *ctx, const gchar *macro, gsize stop_ /* UTF-8 sequences are already validated */ gunichar chr = g_utf8_get_char(macro+ctx->macro_pc); +#ifdef DEBUG + g_printf("EXEC(%d): input='%C' (U+%04" G_GINT32_MODIFIER "X), state=%p, mode=%d\n", + ctx->macro_pc, chr, chr, ctx->parent.current, ctx->mode); +#endif + if (!teco_machine_input(&ctx->parent, chr, error)) goto error_attach; diff --git a/src/parser.h b/src/parser.h index 0303bae..7cc286e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -38,7 +38,7 @@ typedef struct { /** how many iterations are left */ teco_int_t counter; /** Program counter of loop start command */ - guint pc : sizeof(guint)*8 - 1; + gsize pc : sizeof(gsize)*8 - 1; /** * Whether the loop represents an argument * barrier or not (it "passes through" @@ -432,7 +432,8 @@ typedef enum { struct teco_machine_main_t { teco_machine_t parent; - gsize macro_pc; + /* signed because it is sometimes set to -1 for flow control */ + gssize macro_pc; /** * Aliases bitfield with an integer. diff --git a/tests/testsuite.at b/tests/testsuite.at index 0c7612a..7474d01 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -167,6 +167,10 @@ AT_CHECK([$SCITECO -e '@EC//'], 1, ignore, ignore) AT_CHECK([$SCITECO -e '@EGa//'], 1, ignore, ignore) AT_CLEANUP +AT_SETUP([Jump to beginning of macro]) +AT_CHECK([$SCITECO -e "%a-2\"< F< ' Qa-2\"N(0/0)'"], 0, ignore, ignore) +AT_CLEANUP + AT_BANNER([Known Bugs]) AT_SETUP([Number stack]) |