Comportamento dos blocos no próprio tipo e executor único (fluxo como interface)

Core:
- TinyBlocks_FlowClass (tb_flow.h): um bloco C diz como roda (bocas,
  rótulos das faixas, tampa, next/error). next escolhe a boca, sai ou pede
  pausa (TB_FLOW_YIELD); error trata um erro que subiu de dentro.
- TypeBlock: shape (chapéu...), flags (TB_TYPE_HIDDEN, TB_TYPE_REDRAW),
  flow, event (TB_EVENT_FLAG) e traços por campo (TB_SLOT_BOOLEAN,
  TB_SLOT_VARIABLE) via tb_type_block_set_input/output_flags.

Libraries declaram o próprio comportamento:
- control: repita / repita até que / sempre / se / se-senão como fluxos;
  errors: tente / se der erro / finalmente como fluxos.
- events: chapéu da bandeira; operators: booleanos e campos hexagonais,
  literais numéricos ocultos; variables: campo de nome de variável;
  pen: redesenha o palco; graphics/editor: tipos de infraestrutura ocultos.

Editor:
- Forma, bocas, rótulos, tampa, campos booleanos/de variável, ocultos e
  "redesenhe" vêm dos traços (sem strcmp em nomes de outras libraries).
- run_chain e vm_step viraram um executor só, que segue a classe de fluxo
  de cada bloco C; o corpo de Meus Blocos roda nele sem pausas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-22 18:56:21 -03:00
1 parent 351e85bb14
commit a5e36b3eed
15 files changed
+456 -251

No files matched your search

@@ -682,16 +682,12 @@ typedef struct {
/* Execucao em "threads" (estilo Scratch 3): cada script da bandeira tem uma
pilha explicita e pausa no fim de cada volta de laco; o editor avanca as
threads a cada quadro (ver vm_frame em tb_editor.c). */
enum { VF_CHAIN, VF_REPEAT, VF_UNTIL, VF_FOREVER, VF_TRY };
enum { VF_CHAIN, VF_FLOW };
typedef struct {
Tab* T;
int bi; /* CHAIN: proximo bloco; laco: o bloco do laco */
int kind; /* VF_* */
long long n; /* REPEAT: voltas que faltam */
bool in_iter; /* laco: uma volta esta em andamento */
int phase; /* TRY: 0 tente, 1 se der erro, 2 finalmente */
char pend[200]; /* TRY: erro a relancar depois do finalmente */
char saved[200]; /* TRY: "erro capturado" de fora (restaura) */
Tab* T;
int bi; /* CHAIN: proximo bloco; FLOW: o bloco C */
int kind; /* VF_* */
TinyBlocks_Flow flow; /* FLOW: estado do bloco C (a classe dele manda) */
} VmFrame;
#define VM_STACK 64
#define VM_THREADS 32
+115 -206
View File
@@ -23,6 +23,7 @@
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -166,25 +167,22 @@ static int input_count(const TinyBlocks_TypeBlock* t) {
return t->input_desc_count < MAX_INPUTS ? (int)t->input_desc_count : MAX_INPUTS;
}
/* A forma vem do tipo (a library declara): bloco C = classe de fluxo,
chapeu/booleano = shape ou saida TB_SLOT_BOOLEAN */
static Shape shape_of(const TinyBlocks_TypeBlock* t) {
if (!t || !t->type_name) return SH_STACK;
const char* n = t->type_name;
if (strncmp(n, "Events.", 7) == 0 ||
strcmp(n, "Port.Define") == 0) return SH_HAT;
if (strcmp(n, "Control.If") == 0 || strcmp(n, "Control.Repeat") == 0 ||
strcmp(n, "Control.RepeatUntil") == 0 ||
strcmp(n, "Control.Forever") == 0) return SH_C1;
if (strcmp(n, "Control.IfElse") == 0 ||
strcmp(n, "Errors.TryCatch") == 0) return SH_C2;
if (strcmp(n, "Errors.Try") == 0) return SH_C3;
if (strcmp(n, "Operators.Lt") == 0 || strcmp(n, "Operators.Eq") == 0 ||
strcmp(n, "Operators.Gt") == 0 || strcmp(n, "Operators.And") == 0 ||
strcmp(n, "Operators.Or") == 0 || strcmp(n, "Operators.Not") == 0)
return SH_BOOL;
/* Convencao para as libraries: uma unica saida cujo nome termina em '?'
(ex.: "é pasta?") e um bloco booleano. */
if (t->output_desc_count == 1 && t->output_descs && t->output_descs[0].name) {
const char* on = t->output_descs[0].name;
if (!t) return SH_STACK;
if (t->flow) return t->flow->mouths >= 3 ? SH_C3 : t->flow->mouths == 2 ? SH_C2 : SH_C1;
switch (t->shape) {
case TB_SHAPE_HAT: return SH_HAT;
case TB_SHAPE_STACK: return SH_STACK;
case TB_SHAPE_REPORTER: return SH_REPORTER;
case TB_SHAPE_BOOLEAN: return SH_BOOL;
default: break;
}
if (t->output_desc_count == 1) {
if (tb_type_block_output_flags(t, 0) & TB_SLOT_BOOLEAN) return SH_BOOL;
/* convencao antiga das libraries: saida cujo nome termina em '?' */
const char* on = t->output_descs && t->output_descs[0].name ? t->output_descs[0].name : "";
size_t ol = strlen(on);
if (ol > 0 && on[ol - 1] == '?') return SH_BOOL;
}
@@ -198,14 +196,13 @@ static int shape_mouths(Shape s) { return s == SH_C1 ? 1 : s == SH_C2 ? 2 : s ==
/* Texto da faixa entre a boca k e a k+1 ("senão", "se der erro"...) */
static const char* mouth_label(const TinyBlocks_TypeBlock* t, int k) {
const char* n = t && t->type_name ? t->type_name : "";
if (!strncmp(n, "Errors.Try", 10)) return k == 0 ? "se der erro" : "finalmente";
return "senão";
if (!t || !t->flow || k < 0 || k >= TB_FLOW_MAX_MOUTHS - 1) return "";
return t->flow->labels[k] ? t->flow->labels[k] : "";
}
/* Bloco "tampa" (como o "sempre" do Scratch): nada encaixa embaixo dele */
static bool is_cap(const TinyBlocks_TypeBlock* t) {
return t && t->type_name && strcmp(t->type_name, "Control.Forever") == 0;
return t && t->flow && t->flow->cap;
}
static UserBlockDef* user_def_find(Ed* ed, const char* name);
@@ -222,18 +219,9 @@ static const UserParam* user_param_at(const UserBlockDef* def, int idx) {
return NULL;
}
/* Campo hexagonal (recebe booleano): traco do campo, declarado no tipo */
static bool slot_is_bool(const TinyBlocks_TypeBlock* t, int i) {
if (!t || !t->type_name) return false;
const char* n = t->type_name;
if (strncmp(n, "User.", 5) == 0) {
UserBlockDef* def = g_active_ed ? user_def_find(g_active_ed, n + 5) : NULL;
const UserParam* p = user_param_at(def, i);
return p && p->kind == PARAM_BOOL;
}
if (i == 0 && (strcmp(n,"Control.If") == 0 || strcmp(n,"Control.IfElse") == 0 ||
strcmp(n,"Control.RepeatUntil") == 0)) return true;
return strcmp(n,"Operators.And") == 0 || strcmp(n,"Operators.Or") == 0 ||
strcmp(n,"Operators.Not") == 0;
return i >= 0 && (tb_type_block_input_flags(t, (uint32_t)i) & TB_SLOT_BOOLEAN);
}
static bool is_lit_text(const TinyBlocks_TypeBlock* t) {
@@ -776,17 +764,10 @@ static int hit_slot(Tab* T, int bi, float x, float y) {
/* ===
* Renderização de blocos
* === */
/* Campo de nome de variavel (slot 0 de Variables.Get/Set/Change):
* desenhado laranja (cor da categoria), como no Scratch. */
/* Campo com o nome de uma variavel (traco TB_SLOT_VARIABLE): desenhado
* laranja (cor da categoria), como no Scratch. */
static bool slot_is_var_name(const TinyBlocks_TypeBlock* t, int s) {
if (!t || !t->type_name || s != 0) return false;
const char* n = t->type_name;
return strcmp(n, "Variables.Get") == 0 ||
strcmp(n, "Variables.Set") == 0 ||
strcmp(n, "Variables.Change") == 0 ||
strcmp(n, "Variables.DeclareLocal") == 0 ||
strcmp(n, "Variables.DeclareGlobal") == 0 ||
strcmp(n, "Variables.Delete") == 0;
return s >= 0 && (tb_type_block_input_flags(t, (uint32_t)s) & TB_SLOT_VARIABLE);
}
static void draw_slot(TinyBlocks_RenderableBlock* rb, const EdBlock* b, int s,
@@ -1083,156 +1064,77 @@ static bool step(Ed* ed) {
return !ed->abort;
}
/* Roda uma pilha de uma vez (corpo de Meus Blocos). Um erro para a pilha e
fica pendente para quem chamou (o "tente" mais proximo trata). */
static void run_chain(Ed* ed, Tab* T, int head) {
for (int bi = head; bi >= 0 && !err_pending(ed) && step(ed); bi = T->ws[bi].next) {
EdBlock* b = &T->ws[bi];
TinyBlocks_TypeBlock* t = blk_type(ed, b);
if (!t) continue;
const char* tn = t->type_name;
Shape sh = shape_of(t);
if (sh == SH_HAT || shape_is_value(sh)) continue;
if (strcmp(tn, "Control.Repeat") == 0) {
TinyBlocks_Value v = eval_arg(ed, T, bi, 0);
long long n = tb_value_as_integer(v, 0);
tb_value_free(&v);
for (long long k = 0; k < n && !err_pending(ed) && step(ed); k++) run_chain(ed, T, b->sub[0]);
} else if (strcmp(tn, "Control.RepeatUntil") == 0) {
for (;;) {
TinyBlocks_Value v = eval_arg(ed, T, bi, 0);
bool done = tb_value_truthy(v);
tb_value_free(&v);
if (done || err_pending(ed) || !step(ed)) break;
run_chain(ed, T, b->sub[0]);
}
} else if (strcmp(tn, "Control.Forever") == 0) {
/* dentro de Meus Blocos roda sem pausar: so o limite de passos para */
while (!err_pending(ed) && step(ed)) run_chain(ed, T, b->sub[0]);
} else if (strcmp(tn, "Control.If") == 0 || strcmp(tn, "Control.IfElse") == 0) {
TinyBlocks_Value v = eval_arg(ed, T, bi, 0);
bool cond = tb_value_truthy(v);
tb_value_free(&v);
if (err_pending(ed)) return;
if (cond) run_chain(ed, T, b->sub[0]);
else if (sh == SH_C2) run_chain(ed, T, b->sub[1]);
} else if (strcmp(tn, "Errors.TryCatch") == 0 || strcmp(tn, "Errors.Try") == 0) {
run_chain(ed, T, b->sub[0]);
if (ed->abort) return;
if (err_pending(ed)) { /* se der erro */
char msg[200], saved[200];
err_take(ed, msg, sizeof(msg));
snprintf(saved, sizeof(saved), "%s", tinyblocks_caught_error(ed->rt));
tinyblocks_set_caught_error(ed->rt, msg);
run_chain(ed, T, b->sub[1]);
tinyblocks_set_caught_error(ed->rt, saved);
}
if (sh == SH_C3 && !ed->abort) { /* finalmente: sempre */
char pend[200] = "";
if (err_pending(ed)) err_take(ed, pend, sizeof(pend));
run_chain(ed, T, b->sub[2]);
if (pend[0] && !err_pending(ed)) tinyblocks_set_error(ed->rt, "%s", pend);
}
} else {
TinyBlocks_Block* r = get_rt(ed, T, bi);
if (r) tb_block_eval(r, ed->rt);
}
}
}
/* == Threads (scripts rodando quadro a quadro, estilo Scratch 3) ===
* Cada script e uma pilha explicita de VmFrame. Um laco pausa no fim de
* cada volta; vm_frame avanca as threads varias vezes no mesmo quadro ate
* todas pausarem/terminarem, um bloco do palco pedir redesenho ou acabar o
* tempo do quadro. Assim contas terminam na hora e desenhos animam. */
/* == Executor (scripts quadro a quadro, estilo Scratch 3) ===
* Cada script e uma pilha explicita de VmFrame. Um bloco C nao e conhecido
* pelo nome: a classe de fluxo dele (TinyBlocks_FlowClass) escolhe a boca a
* rodar, pede pausa (lacos) ou trata um erro que subiu ("tente"). vm_frame
* avanca as threads varias vezes no mesmo quadro ate todas pausarem ou
* terminarem. O corpo de Meus Blocos roda no mesmo executor, sem pausas. */
#define VM_FRAME_MS 12u
static unsigned now_ms(void);
static void vm_push(Ed* ed, VmThread* th, Tab* T, int bi, int kind, long long n) {
static const TinyBlocks_FlowClass* frame_flow(Ed* ed, VmFrame* f) {
EdBlock* B = &f->T->ws[f->bi];
TinyBlocks_TypeBlock* t = B->used ? blk_type(ed, B) : NULL;
return t ? t->flow : NULL;
}
/* TinyBlocks_Flow.arg: avalia uma entrada do bloco C deste frame */
static TinyBlocks_Value flow_arg(TinyBlocks_Flow* fl, uint32_t slot) {
VmFrame* f = (VmFrame*)((char*)fl - offsetof(VmFrame, flow));
return g_active_ed ? eval_arg(g_active_ed, f->T, f->bi, (int)slot) : tb_value_none();
}
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; f->n = n; f->in_iter = false;
f->phase = 0; f->pend[0] = f->saved[0] = 0;
f->T = T; f->bi = bi; f->kind = kind;
memset(&f->flow, 0, sizeof(f->flow));
f->flow.rt = ed->rt;
f->flow.arg = flow_arg;
}
static void vm_start(Ed* ed, Tab* T, int head) {
if (ed->vm_n >= VM_THREADS) return;
VmThread* th = &ed->vm[ed->vm_n++];
th->sp = 0;
th->scope = tb_vars_scope_new(NULL); /* variaveis locais deste script */
vm_push(ed, th, T, head, VF_CHAIN, 0);
ed->vm_running = true;
}
/* Um erro na thread: desempilha ate o "tente" mais proximo e entra no
"se der erro" (ou no "finalmente", guardando o erro para depois).
false = ninguem tratou (a thread acaba). */
static bool vm_throw(Ed* ed, VmThread* th) {
char msg[200];
err_take(ed, msg, sizeof(msg));
/* Um erro na thread: desempilha ate um bloco C cuja classe trate o erro e
entra na boca que ela escolher. false = ninguem tratou (msg = o erro). */
static bool vm_throw(Ed* ed, VmThread* th, char* msg, size_t cap) {
err_take(ed, msg, cap);
while (th->sp > 0) {
VmFrame* f = &th->st[th->sp - 1];
if (f->kind != VF_TRY) { th->sp--; continue; }
EdBlock* B = &f->T->ws[f->bi];
bool has_finally = shape_of(B->type) == SH_C3;
if (f->phase == 0) { /* no tente: vai para o se der erro */
f->phase = 1;
snprintf(f->saved, sizeof(f->saved), "%s", tinyblocks_caught_error(ed->rt));
tinyblocks_set_caught_error(ed->rt, msg);
vm_push(ed, th, f->T, B->sub[1], VF_CHAIN, 0);
return true;
if (f->kind == VF_FLOW) {
const TinyBlocks_FlowClass* fc = frame_flow(ed, f);
int m = fc && fc->error ? fc->error(&f->flow, msg) : TB_FLOW_DONE;
if (m >= 0 && m < fc->mouths) {
vm_push(ed, th, f->T, f->T->ws[f->bi].sub[m], VF_CHAIN);
return true;
}
}
if (f->phase == 1) tinyblocks_set_caught_error(ed->rt, f->saved);
if (f->phase == 1 && has_finally) { /* erro no se der erro: finalmente e relanca */
f->phase = 2;
snprintf(f->pend, sizeof(f->pend), "%s", msg);
vm_push(ed, th, f->T, B->sub[2], VF_CHAIN, 0);
return true;
}
th->sp--; /* erro no finalmente: sobe */
th->sp--;
}
err_uncaught(ed, msg);
return false;
}
/* Executa a thread ate a proxima pausa (true) ou ate terminar (false) */
static bool vm_step(Ed* ed, VmThread* th) {
/* Avanca a thread ate a proxima pausa (true) ou ate terminar (false).
sync: roda de uma vez (ignora pausas) e deixa um erro sem tratamento
pendente para quem chamou. */
static bool vm_step(Ed* ed, VmThread* th, bool sync) {
while (th->sp > 0 && !ed->abort) {
if (err_pending(ed) && !vm_throw(ed, th)) break;
if (th->sp <= 0) break;
if (err_pending(ed)) {
char msg[200];
if (vm_throw(ed, th, msg, sizeof(msg))) continue;
if (sync) tinyblocks_set_error(ed->rt, "%s", msg); /* sobe para quem chamou */
else err_uncaught(ed, msg);
break;
}
VmFrame* f = &th->st[th->sp - 1];
Tab* T = f->T;
if (f->kind == VF_TRY) { /* uma parte do tente acabou bem */
EdBlock* B = &T->ws[f->bi];
bool has_finally = B->used && shape_of(B->type) == SH_C3;
if (f->phase == 1) tinyblocks_set_caught_error(ed->rt, f->saved);
if (f->phase < 2 && has_finally) {
f->phase = 2;
vm_push(ed, th, T, B->sub[2], VF_CHAIN, 0);
continue;
}
char pend[200];
snprintf(pend, sizeof(pend), "%s", f->pend);
th->sp--;
if (pend[0]) tinyblocks_set_error(ed->rt, "%s", pend); /* relanca */
continue;
}
if (f->kind != VF_CHAIN) {
EdBlock* L = &T->ws[f->bi];
if (!L->used) { th->sp--; continue; } /* laco apagado com o programa rodando */
if (f->in_iter) { f->in_iter = false; return true; } /* fim de uma volta: pausa */
if (f->kind == VF_REPEAT) {
if (f->n <= 0) { th->sp--; continue; }
f->n--;
} else if (f->kind == VF_UNTIL) {
TinyBlocks_Value v = eval_arg(ed, T, f->bi, 0);
bool done = tb_value_truthy(v);
tb_value_free(&v);
if (done) { th->sp--; continue; }
}
f->in_iter = true;
vm_push(ed, th, T, L->sub[0], VF_CHAIN, 0);
if (f->kind == VF_FLOW) { /* bloco C: a classe escolhe */
const TinyBlocks_FlowClass* fc = frame_flow(ed, f);
if (!fc) { th->sp--; continue; } /* apagado com o programa rodando */
if (!step(ed)) break;
int m = fc->next(&f->flow);
if (m == TB_FLOW_YIELD) { if (sync) continue; return true; }
if (m < 0 || m >= fc->mouths) { th->sp--; continue; }
vm_push(ed, th, T, T->ws[f->bi].sub[m], VF_CHAIN);
continue;
}
if (f->bi < 0 || !T->ws[f->bi].used) { th->sp--; continue; }
@@ -1242,38 +1144,37 @@ static bool vm_step(Ed* ed, VmThread* th) {
if (!step(ed)) break;
TinyBlocks_TypeBlock* t = blk_type(ed, b);
if (!t) continue;
const char* tn = t->type_name;
Shape sh = shape_of(t);
if (sh == SH_HAT || shape_is_value(sh)) continue;
if (strcmp(tn, "Control.Repeat") == 0) {
TinyBlocks_Value v = eval_arg(ed, T, bi, 0);
long long n = tb_value_as_integer(v, 0);
tb_value_free(&v);
if (n > 0) vm_push(ed, th, T, bi, VF_REPEAT, n);
} else if (strcmp(tn, "Control.RepeatUntil") == 0) {
vm_push(ed, th, T, bi, VF_UNTIL, 0);
} else if (strcmp(tn, "Control.Forever") == 0) {
vm_push(ed, th, T, bi, VF_FOREVER, 0);
} else if (strcmp(tn, "Control.If") == 0 || strcmp(tn, "Control.IfElse") == 0) {
TinyBlocks_Value v = eval_arg(ed, T, bi, 0);
bool cond = tb_value_truthy(v);
tb_value_free(&v);
if (err_pending(ed)) continue;
if (cond) vm_push(ed, th, T, b->sub[0], VF_CHAIN, 0);
else if (sh == SH_C2) vm_push(ed, th, T, b->sub[1], VF_CHAIN, 0);
} else if (strcmp(tn, "Errors.TryCatch") == 0 || strcmp(tn, "Errors.Try") == 0) {
vm_push(ed, th, T, bi, VF_TRY, 0);
vm_push(ed, th, T, b->sub[0], VF_CHAIN, 0);
} else {
TinyBlocks_Block* r = get_rt(ed, T, bi);
if (r) tb_block_eval(r, ed->rt);
if (strncmp(tn, "Stage.", 6) == 0) ed->redraw_req = true; /* caneta: mostra este quadro */
}
if (t->flow) { vm_push(ed, th, T, bi, VF_FLOW); 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 */
}
th->sp = 0;
return false;
}
/* Roda uma pilha de uma vez (corpo de Meus Blocos), no mesmo executor */
static void run_chain(Ed* ed, Tab* T, int head) {
VmThread* th = malloc(sizeof(*th));
if (!th) { run_abort(ed, "sem memória para rodar o bloco"); return; }
th->sp = 0;
th->scope = NULL;
vm_push(ed, th, T, head, VF_CHAIN);
vm_step(ed, th, true);
free(th);
}
static void vm_start(Ed* ed, Tab* T, int head) {
if (ed->vm_n >= VM_THREADS) return;
VmThread* th = &ed->vm[ed->vm_n++];
th->sp = 0;
th->scope = tb_vars_scope_new(NULL); /* variaveis locais deste script */
vm_push(ed, th, T, head, VF_CHAIN);
ed->vm_running = true;
}
/* Captura o stdout (blocos "escreva") enquanto os blocos rodam */
static void cap_begin(Ed* ed) {
fflush(stdout);
@@ -1350,7 +1251,7 @@ static void vm_frame(Ed* ed) {
VmThread* th = &ed->vm[i];
if (th->sp <= 0) continue;
tb_vars_scope_set(th->scope);
if (vm_step(ed, th)) alive = true;
if (vm_step(ed, th, false)) alive = true;
else { tb_vars_scope_set(NULL); tb_vars_scope_free(th->scope); th->scope = NULL; }
tb_vars_scope_set(NULL);
}
@@ -1384,7 +1285,8 @@ static void run_flag(Ed* ed) {
int started = 0;
for (int i = 0; i < n; i++) {
EdBlock* b = &CT.ws[heads[i]];
if (blk_type(ed, b) && strcmp(b->type->type_name, "Events.WhenRun") == 0) {
TinyBlocks_TypeBlock* t = blk_type(ed, b);
if (t && t->event && strcmp(t->event, TB_EVENT_FLAG) == 0) { /* chapeus da bandeira */
vm_start(ed, &CT, heads[i]);
started++;
}
@@ -1744,9 +1646,7 @@ static void retype_all(Ed* ed) {
static bool type_hidden(Ed* ed, const TinyBlocks_TypeBlock* t) {
const char* n = t->type_name;
if (!n || n[0] == '_' || strstr(n, "._")) return true;
if (strncmp(n, "Editor.", 7) == 0 || strncmp(n, "Graphics.", 9) == 0) return true;
if (strcmp(n, "Literal.Integer") == 0 || strcmp(n, "Literal.Real") == 0) return true;
if (strcmp(n, "Port.Define") == 0) return true; /* nasce pelo "Criar um Bloco" */
if (t->flags & TB_TYPE_HIDDEN) return true; /* infraestrutura / "defina" */
if (strncmp(n, "Port.", 5) == 0) return !CT.is_composite && !tab_has_define(&CT);
return false;
}
@@ -2512,6 +2412,10 @@ static void comp_make_type(Ed* ed, UserBlockDef* def) {
def->input_count ? in_s : NULL, (uint32_t)def->input_count,
def->output_count ? out_s : NULL, (uint32_t)def->output_count,
eval_composite);
for (int i = 0; def->reg_type && i < def->input_count; i++) {
const UserParam* p = user_param_at(def, i);
if (p && p->kind == PARAM_BOOL) tb_type_block_set_input_flags(def->reg_type, (uint32_t)i, TB_SLOT_BOOLEAN);
}
retype_all(ed);
}
@@ -6781,6 +6685,9 @@ static bool editor_lib_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
static const TinyBlocks_SlotDesc port_out_in[] = {{"nome", TB_VALUE_TEXT}, {"valor", TB_VALUE_NONE}};
static const TinyBlocks_SlotDesc any_out[] = {{"valor", TB_VALUE_NONE}};
reg(rt, lib, "Port.Define", port_label, 1, NULL, 0, eval_port_define);
TinyBlocks_TypeBlock* tdef = tb_type_block_find(rt, "Port.Define");
tb_type_block_set_shape(tdef, TB_SHAPE_HAT);
tb_type_block_set_flags(tdef, TB_TYPE_HIDDEN); /* nasce pelo "Criar um Bloco" */
reg(rt, lib, "Port.In", port_label, 1, any_out, 1, eval_port_in);
reg(rt, lib, "Port.Out", port_out_in, 2, NULL, 0, eval_port_out);
@@ -6793,6 +6700,7 @@ static bool editor_lib_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
scene_in, 1, NULL, 0, editor_eval);
if (!t) return false;
tb_type_block_set_instance_hooks(t, sizeof(Ed*), editor_instance_init, editor_instance_deinit);
tb_type_block_set_flags(t, TB_TYPE_HIDDEN);
t->on_draw = editor_on_draw;
tb_library_add(lib, &t->base);
@@ -6801,6 +6709,7 @@ static bool editor_lib_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
scene_in, 1, NULL, 0, area_eval);
if (!ta) return false;
tb_type_block_set_instance_hooks(ta, sizeof(AreaScene), area_instance_init, area_instance_deinit);
tb_type_block_set_flags(ta, TB_TYPE_HIDDEN);
ta->on_draw = area_on_draw;
tb_library_add(lib, &ta->base);
return true;
@@ -46,6 +46,7 @@ bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, "Editor.Stage", stage_in, 1, NULL, 0, eval_stage);
if (!t) return false;
tb_type_block_set_instance_hooks(t, 1, stage_instance_init, stage_instance_deinit);
tb_type_block_set_flags(t, TB_TYPE_HIDDEN);
t->on_draw = stage_on_draw;
return tb_library_add(lib, &t->base);
}