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>
130 lines
5.5 KiB
C
130 lines
5.5 KiB
C
/*
|
|
* TinyBlocks - tb_defs.h
|
|
* Forward declarations, enums e tipos primitivos compartilhados por todo o runtime.
|
|
*/
|
|
#ifndef TINYBLOCKS_DEFS_H
|
|
#define TINYBLOCKS_DEFS_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/* -- Visibilidade de API --- */
|
|
#ifdef _WIN32
|
|
# define TB_API __declspec(dllexport)
|
|
#else
|
|
# define TB_API __attribute__((visibility("default")))
|
|
#endif
|
|
|
|
/* -- Forward declarations --- */
|
|
typedef struct TinyBlocks TinyBlocks;
|
|
typedef struct TinyBlocks_Block TinyBlocks_Block;
|
|
typedef struct TinyBlocks_TypeBlock TinyBlocks_TypeBlock;
|
|
typedef struct TinyBlocks_LibraryBlock TinyBlocks_LibraryBlock;
|
|
typedef struct TinyBlocks_TextBlock TinyBlocks_TextBlock;
|
|
typedef struct TinyBlocks_IntegerBlock TinyBlocks_IntegerBlock;
|
|
typedef struct TinyBlocks_RealBlock TinyBlocks_RealBlock;
|
|
typedef struct TinyBlocks_VectorBlock TinyBlocks_VectorBlock;
|
|
typedef struct TinyBlocks_VectorData TinyBlocks_VectorData;
|
|
typedef struct TinyBlocks_RenderableBlock TinyBlocks_RenderableBlock;
|
|
typedef struct TinyBlocks_JsonValue TinyBlocks_JsonValue;
|
|
typedef struct TinyBlocks_Image TinyBlocks_Image;
|
|
typedef struct TinyBlocks_Result TinyBlocks_Result;
|
|
|
|
/* -- Kinds de bloco --- */
|
|
typedef enum TinyBlocks_BlockKind {
|
|
TB_KIND_BLOCK = 0, /* bloco genérico / definido pelo usuário */
|
|
TB_KIND_TYPE = 1, /* TinyBlocks_TypeBlock */
|
|
TB_KIND_LIBRARY = 2, /* TinyBlocks_LibraryBlock */
|
|
TB_KIND_TEXT = 3, /* TinyBlocks_TextBlock */
|
|
TB_KIND_INTEGER = 4, /* TinyBlocks_IntegerBlock */
|
|
TB_KIND_REAL = 5, /* TinyBlocks_RealBlock */
|
|
TB_KIND_VECTOR = 6, /* TinyBlocks_VectorBlock */
|
|
} TinyBlocks_BlockKind;
|
|
|
|
/* -- Kinds de valor (para slots) --- */
|
|
typedef enum TinyBlocks_ValueKind {
|
|
TB_VALUE_NONE = 0,
|
|
TB_VALUE_INTEGER = 1,
|
|
TB_VALUE_REAL = 2,
|
|
TB_VALUE_TEXT = 3,
|
|
TB_VALUE_BLOCK = 4, /* referência a qualquer bloco (handle opaco) */
|
|
TB_VALUE_VECTOR = 5, /* dados de vetor 2D (ref-counted) */
|
|
TB_VALUE_JSON = 6, /* valor JSON (ref-counted) */
|
|
TB_VALUE_IMAGE = 7, /* imagem RGBA/cinza (ref-counted) */
|
|
TB_VALUE_RESULT = 8, /* Ok(valor) | Erro(valor) (ref-counted) */
|
|
TB_VALUE_KIND_COUNT /* quantidade de kinds (tabela de classes) */
|
|
} TinyBlocks_ValueKind;
|
|
|
|
/* -- Valor com tag (flui entre slots) --- */
|
|
typedef struct TinyBlocks_Value {
|
|
TinyBlocks_ValueKind kind;
|
|
union {
|
|
int64_t integer;
|
|
double real;
|
|
char* text; /* heap-owned (tb_value_free) */
|
|
TinyBlocks_Block* block; /* ponteiro não-owning */
|
|
TinyBlocks_VectorData* vector; /* ref-counted (retain/release) */
|
|
TinyBlocks_JsonValue* json; /* ref-counted (retain/release) */
|
|
TinyBlocks_Image* image; /* ref-counted (retain/release) */
|
|
TinyBlocks_Result* result; /* ref-counted (retain/release) */
|
|
} as;
|
|
} TinyBlocks_Value;
|
|
|
|
/* ===
|
|
* Dados de vetor 2D (fluxo de comandos de desenho, ref-counted)
|
|
* === */
|
|
typedef enum TinyBlocks_VCmdKind {
|
|
TB_VCMD_BEGIN_PATH = 0, /* nenhum arg */
|
|
TB_VCMD_MOVE_TO, /* args[0]=x, args[1]=y */
|
|
TB_VCMD_LINE_TO, /* args[0]=x, args[1]=y */
|
|
TB_VCMD_CLOSE_PATH, /* nenhum arg */
|
|
TB_VCMD_STROKE, /* args[0..3]=r,g,b,a args[4]=width */
|
|
TB_VCMD_FILL, /* args[0..3]=r,g,b,a */
|
|
TB_VCMD_RECT, /* args[0..3]=x,y,w,h */
|
|
TB_VCMD_CIRCLE, /* args[0..2]=cx,cy,raio */
|
|
} TinyBlocks_VCmdKind;
|
|
|
|
typedef struct { TinyBlocks_VCmdKind kind; float args[5]; } TinyBlocks_VCmd;
|
|
|
|
struct TinyBlocks_VectorData {
|
|
TinyBlocks_VCmd* cmds;
|
|
uint32_t count, capacity;
|
|
int32_t ref;
|
|
};
|
|
|
|
|
|
/* -- Descritor de slot (em TypeBlock - descreve a forma dos inputs/outputs) - */
|
|
/* Tracos de um slot (tb_type_block_set_input_flags / _output_flags) */
|
|
enum {
|
|
TB_SLOT_BOOLEAN = 1u << 0, /* entrada hexagonal / saida booleana */
|
|
TB_SLOT_VARIABLE = 1u << 1, /* campo com o NOME de uma variavel */
|
|
};
|
|
|
|
typedef struct TinyBlocks_SlotDesc {
|
|
const char* name;
|
|
TinyBlocks_ValueKind expected_kind; /* TB_VALUE_NONE = aceita qualquer tipo */
|
|
} TinyBlocks_SlotDesc;
|
|
|
|
/* -- Conexão de entrada (de qual bloco/slot este input lê) --- */
|
|
typedef struct TinyBlocks_Connection {
|
|
TinyBlocks_Block* source; /* bloco de origem (NULL se não conectado) */
|
|
uint32_t output_idx; /* qual output slot da origem */
|
|
TinyBlocks_Value default_value; /* valor quando não há conexão */
|
|
} TinyBlocks_Connection;
|
|
|
|
/* -- Alocador customizável --- */
|
|
typedef void* (*TinyBlocks_AllocFn)(size_t size, void* userdata);
|
|
typedef void (*TinyBlocks_FreeFn) (void* ptr, void* userdata);
|
|
|
|
/* -- Helpers para TinyBlocks_Value --- */
|
|
TB_API TinyBlocks_Value tb_value_none(void);
|
|
TB_API TinyBlocks_Value tb_value_integer(int64_t v);
|
|
TB_API TinyBlocks_Value tb_value_real(double v);
|
|
TB_API TinyBlocks_Value tb_value_text(const char* v); /* copia a string */
|
|
TB_API TinyBlocks_Value tb_value_block(TinyBlocks_Block* v);
|
|
TB_API TinyBlocks_Value tb_value_clone(TinyBlocks_Value v); /* deep copy */
|
|
TB_API void tb_value_free(TinyBlocks_Value* v); /* libera text */
|
|
|
|
#endif /* TINYBLOCKS_DEFS_H */
|