[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pkl: Re-implement `strace` instruction
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] pkl: Re-implement `strace` instruction |
Date: |
Wed, 01 Dec 2021 21:58:47 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Yes the shuffling of the stack elemnts is ugly.
> diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
> index 6c3a1690..8c943f14 100644
> --- a/libpoke/pvm.jitter
> +++ b/libpoke/pvm.jitter
> @@ -6087,31 +6087,30 @@ end
> instruction strace (?n)
> non-relocatable
> code
> - pvm_val tmp[1024];
> - int i = 0, j;
> - int num_elems = (int) JITTER_ARGN0;
> -
> - while (((num_elems == 0 || i < num_elems)
> - && (JITTER_HEIGHT_STACK () !=
> - PVM_STATE_BACKING_FIELD (canary))))
> - {
> - assert (i < 1024);
> - pvm_print_val_with_params (PVM_STATE_BACKING_FIELD (vm),
> - JITTER_TOP_STACK (),
> - 0 /* depth */,
> - PVM_PRINT_FLAT,
> - 16 /* base */,
> - 2 /* indent */,
> - 0 /* acutoff */,
> - PVM_PRINT_F_MAPS);
> - pk_puts ("\n");
> - tmp[i++] = JITTER_TOP_STACK ();
> - JITTER_DROP_STACK ();
> - }
> -
> - /* Restore the stack. */
> - for (j = (i - 1); j >= 0; j--)
> - JITTER_PUSH_STACK (tmp[j]);
> + int i = 0;
> + int num_elems_max =
> + PVM_STATE_BACKING_FIELD (canary) == NULL
> + ? 1024
> + : (pvm_val*)JITTER_HEIGHT_STACK () -
> + (pvm_val*)PVM_STATE_BACKING_FIELD (canary);
`canary' is supposed to be always set to a meaningful height when strace
is used. So it would be better to use an assert. No need for a 1024
default.
Instead of `num_elems_max' I would prefer to use a clearer name, like,
num_elems_in_stack.
OK otherwise, for both master and poke-1.
> + int num_elems = (int) JITTER_ARGN0;
> +
> + if (num_elems == 0 || num_elems > num_elems_max)
> + num_elems = num_elems_max;
> +
> + while (i < num_elems)
> + {
> + pvm_print_val_with_params (PVM_STATE_BACKING_FIELD (vm),
> + JITTER_AT_DEPTH_STACK (i),
> + 0 /* depth */,
> + PVM_PRINT_FLAT,
> + 16 /* base */,
> + 2 /* indent */,
> + 0 /* acutoff */,
> + PVM_PRINT_F_MAPS);
> + pk_puts ("\n");
> + i++;
> + }
> end
> end