VM: guarda de travamento por tempo; vm_push sem memset de 420 bytes
Com a VM rápida, um render 3D normal passa de 500 mil comandos dentro
da fatia de 12 ms, e o limite de passos por quadro abortava o programa
("limite de passos atingido") em parte das vezes, conforme onde o
quadro cortava. O guarda agora é por tempo: um laço que fica 3 s sem
pausa (corpo de Meus Blocos) é parado; laços comuns pausam a cada volta.
vm_push zerava o TinyBlocks_Flow inteiro (dois textos de erro) a cada
"se" executado; agora só os campos. shape_of só para comandos comuns.
vm_bench: diagnóstico (variáveis e pilhas) quando um render não termina.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4a27f0180
commit
f4313417c0
3 files changed
+99
-52
No files matched your search
@@ -190,7 +190,6 @@ enum { IT_SEL = 0, IT_BRUSH, IT_LINE, IT_RECT, IT_ELLIPSE,
|
||||
#define MAX_FLY 192
|
||||
#define MAX_CATS 24
|
||||
#define MAX_CALL_DEPTH 32
|
||||
#define MAX_STEPS 500000L
|
||||
#define MAX_RUN_BLOCKS 200000
|
||||
#define STAGE_BUF 16384
|
||||
#define LIT_TEXT_CAP 512
|
||||
@@ -871,6 +870,7 @@ typedef struct Ed {
|
||||
CallFrame frames[MAX_CALL_DEPTH];
|
||||
int frame_n;
|
||||
long steps;
|
||||
unsigned vm_t0; /* inicio do quadro da VM (guarda de travamento) */
|
||||
bool abort;
|
||||
char abort_msg[160];
|
||||
TinyBlocks_Block** run_blocks; /* instâncias criadas na última execução */
|
||||
|
||||
@@ -1399,8 +1399,15 @@ static void err_uncaught(Ed* ed, const char* msg) {
|
||||
stage_append(ed, line);
|
||||
}
|
||||
|
||||
/* Guarda contra um laco que nunca devolve o controle (corpo de Meus Blocos
|
||||
roda sem pausas): por tempo, nao por passos, que a VM rapida faz meio
|
||||
milhao de passos num render normal. Laços comuns pausam a cada volta e o
|
||||
quadro ja corta em vm_frame_ms. */
|
||||
#define VM_STALL_MS 3000u
|
||||
static unsigned now_ms(void);
|
||||
static bool step(Ed* ed) {
|
||||
if (++ed->steps > MAX_STEPS) run_abort(ed, "limite de passos atingido (laço infinito?)");
|
||||
if ((++ed->steps & 1023) == 0 && now_ms() - ed->vm_t0 > VM_STALL_MS)
|
||||
run_abort(ed, "o script ficou 3 s sem pausa (laço infinito?)");
|
||||
return !ed->abort;
|
||||
}
|
||||
|
||||
@@ -1438,7 +1445,12 @@ static void vm_push(Ed* ed, VmThread* th, Tab* T, int bi, int kind) {
|
||||
if (th->sp >= VM_STACK) { run_abort(ed, "blocos aninhados demais"); return; }
|
||||
VmFrame* f = &th->st[th->sp++];
|
||||
f->T = T; f->bi = bi; f->kind = kind;
|
||||
memset(&f->flow, 0, sizeof(f->flow));
|
||||
/* sem memset: a struct tem ~420 bytes (textos de erro) e isto roda a
|
||||
cada "se" executado; as strings so precisam comecar vazias */
|
||||
f->flow.step = 0;
|
||||
f->flow.count = 0;
|
||||
f->flow.pending[0] = 0;
|
||||
f->flow.saved[0] = 0;
|
||||
f->flow.rt = ed->rt;
|
||||
f->flow.arg = flow_arg;
|
||||
}
|
||||
@@ -1493,10 +1505,10 @@ static bool vm_step(Ed* ed, VmThread* th, bool sync) {
|
||||
if (!step(ed)) break;
|
||||
TinyBlocks_TypeBlock* t = blk_type(ed, b);
|
||||
if (!t) continue;
|
||||
Shape sh = shape_of(t);
|
||||
if (sh == SH_HAT || shape_is_value(sh)) continue;
|
||||
if (t->flow) { vm_push(ed, th, T, bi, VF_FLOW); continue; }
|
||||
if ((t->pure == TB_PURE_SET_VAR || t->pure == TB_PURE_CHANGE_VAR) && jit_stmt(ed, T, bi, t)) continue;
|
||||
Shape sh = shape_of(t);
|
||||
if (sh == SH_HAT || shape_is_value(sh)) continue;
|
||||
TinyBlocks_Block* r = get_rt(ed, T, bi);
|
||||
if (r) tb_block_eval(r, ed->rt);
|
||||
if (t->flags & TB_TYPE_REDRAW) ed->redraw_req = true; /* caneta: mostra este quadro */
|
||||
@@ -1573,6 +1585,7 @@ static void run_begin(Ed* ed, bool clear) {
|
||||
define_sync(ed); /* "devolva" novo no corpo de um "defina" */
|
||||
run_reset(ed);
|
||||
ed->steps = 0; ed->abort = false; ed->abort_msg[0] = 0; ed->frame_n = 0;
|
||||
ed->vm_t0 = now_ms();
|
||||
ed->live_tab = &CT;
|
||||
ed->vm_var_n = tb_variables_count();
|
||||
if (clear) ed->stage_buf[0] = 0;
|
||||
@@ -1593,7 +1606,8 @@ static void vm_frame(Ed* ed) {
|
||||
cap_begin(ed);
|
||||
unsigned t0 = now_ms();
|
||||
ed->redraw_req = false;
|
||||
ed->steps = 0; /* limite de passos vale por quadro */
|
||||
ed->steps = 0;
|
||||
ed->vm_t0 = t0; /* guarda de travamento (step) */
|
||||
bool alive;
|
||||
do {
|
||||
alive = false;
|
||||
|
||||
Reference in new issue
Block a user