Adiciona libraries toml/fs, metadados .toml e build por library

- tinyblocks-toml: lexer + parser TOML (include/lexeme.h, include/ast.h,
  src/lexer.c, src/parser.c) e bloco Toml.Get.
- tinyblocks-fs: categoria "Arquivos" com FS.Open/Read/Write/Append/Tell/Close.
- library.toml em cada library com metadados (categoria, cor, descricao) e
  receita de build, sem precisar embutir isso no .so.
- Makefiles proprios por library com build/ local; Makefile raiz delega.
- Palco (tb_stage) movido para o core; pen deixa de depender do editor, o
  que torna os .so arrastaveis.
- Editor linka com -rdynamic para resolver simbolos do core em .so via dlopen.
- Testes: test-toml (parser) e test-plugin (dlopen de .so standalone).
This commit is contained in:
mguinhos committed 2026-10-20 19:38:58 -03:00
1 parent 90d47bf8a0
commit dc23b92d15
48 files changed
+2405 -744

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
/*
* TinyBlocks - tinyblocks-toml
* ast.h: arvore sintatica e leitura de documentos TOML.
*/
#ifndef TB_TOML_AST_H
#define TB_TOML_AST_H
#include <stddef.h>
#include <stdbool.h>
#include "lexeme.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
TOML_STRING,
TOML_INTEGER,
TOML_FLOAT,
TOML_BOOL,
TOML_DATETIME,
TOML_ARRAY,
TOML_TABLE
} TomlValueKind;
typedef struct TomlValue TomlValue;
typedef struct TomlKeyVal TomlKeyVal;
struct TomlKeyVal {
char* key;
TomlValue* value;
TomlKeyVal* next;
};
struct TomlValue {
TomlValueKind kind;
int line, col;
union {
char* string;
long long integer;
double real;
bool boolean;
struct { TomlValue** items; size_t count, cap; } array;
struct { TomlKeyVal* head, *tail; size_t count; } table;
} as;
};
typedef struct {
TomlValue* root; /* tabela raiz */
} TomlDoc;
/* Parser (texto em memoria / arquivo). Em erro preenche err. */
TomlDoc* toml_parse(const char* src, TomlLexError* err);
TomlDoc* toml_parse_file(const char* path, TomlLexError* err);
void toml_free(TomlDoc* doc);
/* Navegacao */
const TomlValue* toml_table_get(const TomlValue* table, const char* key);
const TomlValue* toml_path_get(const TomlValue* root, const char* dotted);
const TomlValue* toml_array_get(const TomlValue* arr, size_t i);
size_t toml_array_count(const TomlValue* arr);
size_t toml_table_count(const TomlValue* table);
const TomlKeyVal* toml_table_head(const TomlValue* table);
/* Conversoes com valor padrao */
const char* toml_as_string(const TomlValue* v, const char* def);
long long toml_as_int(const TomlValue* v, long long def);
double toml_as_float(const TomlValue* v, double def);
bool toml_as_bool(const TomlValue* v, bool def);
/* Escreve a arvore em stdout (debug) */
void toml_dump(const TomlValue* v, int indent);
#ifdef __cplusplus
}
#endif
#endif /* TB_TOML_AST_H */
@@ -0,0 +1,68 @@
/*
* TinyBlocks - tinyblocks-toml
* lexeme.h: tipos de token e lexer de TOML.
*/
#ifndef TB_TOML_LEXEME_H
#define TB_TOML_LEXEME_H
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
TL_EOF = 0,
TL_ERROR,
TL_NEWLINE,
TL_LBRACKET, /* [ */
TL_RBRACKET, /* ] */
TL_LBRACE, /* { */
TL_RBRACE, /* } */
TL_EQUALS, /* = */
TL_COMMA, /* , */
TL_DOT, /* . */
TL_BARE, /* chave simples */
TL_STRING, /* string (basica/literal) */
TL_INTEGER,
TL_FLOAT,
TL_BOOL,
TL_DATETIME
} TomlLexKind;
typedef struct {
TomlLexKind kind;
const char* start; /* inicio no fonte (nao NUL-terminado) */
size_t len; /* tamanho no fonte */
int line, col;
char* text; /* string decodificada (TL_STRING), malloc */
long long ival;
double fval;
bool bval;
} Lexeme;
typedef struct {
Lexeme* items;
size_t count, cap;
} LexemeList;
typedef struct {
bool ok;
char msg[256];
int line, col;
} TomlLexError;
/* Tokeniza o texto inteiro. Em erro retorna false e preenche *err. */
bool toml_lex(const char* src, LexemeList* out, TomlLexError* err);
/* Libera a lista e os textos decodificados */
void toml_lexemes_free(LexemeList* list);
const char* toml_lexeme_kind_name(TomlLexKind kind);
#ifdef __cplusplus
}
#endif
#endif /* TB_TOML_LEXEME_H */
@@ -0,0 +1,27 @@
/*
* TinyBlocks - tb_toml.h
* Library tinyblocks-toml: parser de TOML (lexer + AST) e metadados de
* library. Tambem expoe o bloco Toml.Get para scripts.
*/
#ifndef TINYBLOCKS_TOML_H
#define TINYBLOCKS_TOML_H
#include <tinyblocks/tinyblocks.h>
#include "lexeme.h"
#include "ast.h"
#ifdef __cplusplus
extern "C" {
#endif
TB_API const TinyBlocks_LibraryDescriptor* tb_toml_get_library(void);
/* Le um valor escalar de um arquivo .toml (ex.: "library.category").
* Retorna o valor em 'out' ou o default. Util para metadados de library. */
TB_API const char* tb_toml_file_get(const char* path, const char* dotted, const char* def);
#ifdef __cplusplus
}
#endif
#endif /* TINYBLOCKS_TOML_H */