Result como tagged union e classes de valor (polimorfismo dos valores)
- TinyBlocks_Result (tb_result.h): Ok | Erro com tag (enum) e payload,
ref-counted, que flui como TB_VALUE_RESULT. A library de erros passa a
produzir/consumir Result em vez de objetos JSON {"ok"/"erro"}.
- TinyBlocks_ValueClass (tb_value_class.h): cada kind de valor tem uma
"interface" (copy, release, to_text, to_number, truthy, equals,
type_name) numa tabela; tb_value_clone/free e as operacoes genericas
(tb_value_to_text, tb_value_to_number, tb_value_truthy, tb_value_equals,
tb_value_type_name) despacham por ela. Sem libm no core.
- Editor e as conversoes "texto de" / "número de" usam o despacho.
- make test-value: classes de valor e Result.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f6a1a0eb0
commit
351e85bb14
13 files changed
+650
-290
No files matched your search
@@ -29,6 +29,7 @@ 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 {
|
||||
@@ -51,6 +52,8 @@ typedef enum TinyBlocks_ValueKind {
|
||||
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) --- */
|
||||
@@ -64,6 +67,7 @@ typedef struct TinyBlocks_Value {
|
||||
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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user