Variáveis locais e globais: crie local, crie global e apague a variável

- Blocos novos em Variáveis: "crie variável local [] com valor ()",
  "crie variável global [] com valor ()" e "apague a variável []".
- O armazenamento das variáveis foi para o core (tinyblocks/tb_vars.h),
  com escopos: uma cópia só, mesmo com a library carregada como .so.
- Editor: cada script tem as suas locais (somem quando ele termina) e cada
  chamada de "Meus Blocos" também (vê as globais, não as de quem chamou).
  mude/adicione alteram onde a variável existir; se não existir, criam global.
- A API tb_variables_* (monitores, salvar projeto) olha as globais.
- make test-vars: escopos e os blocos novos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-22 18:13:07 -03:00
1 parent d9449a568e
commit 0c73e81c1a
8 files changed
+428 -79

No files matched your search

@@ -20,6 +20,7 @@
#include <tb_graphics.h>
#include <tinyblocks/tb_stage.h>
#include <tinyblocks/tb_input.h>
#include <tinyblocks/tb_vars.h>
#include <tb_variables.h>
#include <tb_blueprint.h>
#include <tb_api.h>
@@ -318,6 +319,9 @@ static const BlockSpec s_specs[] = {
{"Variables.Set", "mude %1 para %2", "x|0"},
{"Variables.Change", "adicione %2 a %1", "x|1"},
{"Variables.Get", "%1", "x"},
{"Variables.DeclareLocal", "crie variável local %1 com valor %2", "contador|0"},
{"Variables.DeclareGlobal", "crie variável global %1 com valor %2", "placar|0"},
{"Variables.Delete", "apague a variável %1", "contador"},
{"IO.Print", "escreva %1 %2", "Olá!|"},
{"IO.PrintInt", "escreva o número %1", NULL},
{"Port.In", "parâmetro %1", "x"},
@@ -648,8 +652,9 @@ typedef struct {
#define VM_STACK 64
#define VM_THREADS 32
typedef struct {
VmFrame st[VM_STACK];
int sp;
VmFrame st[VM_STACK];
int sp;
TbVarScope* scope; /* variaveis locais deste script */
} VmThread;
/* Cache das arvores do runtime por (aba, bloco, profundidade de chamada):