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:
1 parent
90d47bf8a0
commit
dc23b92d15
48 files changed
+2405
-744
No files matched your search
@@ -1,9 +1,13 @@
|
||||
# Artefatos de build
|
||||
/build/
|
||||
libraries/*/build/
|
||||
build.tar.xz
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Header gerado (xxd) da library MCP
|
||||
libraries/tinyblocks-mcp/src/tb_mcp_py.h
|
||||
|
||||
# Configuração local do Claude Code
|
||||
.claude/settings.local.json
|
||||
@@ -8,9 +8,33 @@ BUILD := build
|
||||
LIB_A := $(BUILD)/libtinyblocks.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks.so
|
||||
EXAMPLE := $(BUILD)/hello
|
||||
GFX_INC := libraries/tinyblocks-graphics/include
|
||||
|
||||
# Diretórios das libraries (cada uma com Makefile e build/ próprios)
|
||||
LIBDIR := libraries
|
||||
EV_DIR := $(LIBDIR)/tinyblocks-events
|
||||
CT_DIR := $(LIBDIR)/tinyblocks-control
|
||||
OP_DIR := $(LIBDIR)/tinyblocks-operators
|
||||
VR_DIR := $(LIBDIR)/tinyblocks-variables
|
||||
AP_DIR := $(LIBDIR)/tinyblocks-appearance
|
||||
PN_DIR := $(LIBDIR)/tinyblocks-pen
|
||||
FS_DIR := $(LIBDIR)/tinyblocks-fs
|
||||
TOML_DIR := $(LIBDIR)/tinyblocks-toml
|
||||
ED_DIR := $(LIBDIR)/tinyblocks-editor
|
||||
GX_DIR := $(LIBDIR)/tinyblocks-graphics
|
||||
SD_DIR := $(LIBDIR)/tinyblocks-sdl2
|
||||
PY_DIR := $(LIBDIR)/tinyblocks-python
|
||||
MC_DIR := $(LIBDIR)/tinyblocks-mcp
|
||||
|
||||
GFX_INC := $(GX_DIR)/include
|
||||
GFX_HDR := $(GFX_INC)/tb_graphics.h
|
||||
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
SDL2TTF_CFLAGS:= $(shell pkg-config --cflags SDL2_ttf 2>/dev/null)
|
||||
SDL2TTF_LIBS := $(shell pkg-config --libs SDL2_ttf 2>/dev/null)
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
SRCS := src/tinyblocks.c \
|
||||
src/tb_value.c \
|
||||
src/tb_block.c \
|
||||
@@ -21,13 +45,29 @@ SRCS := src/tinyblocks.c \
|
||||
src/tb_real_block.c \
|
||||
src/tb_vector_block.c \
|
||||
src/tb_renderable_block.c \
|
||||
src/tb_stage.c \
|
||||
src/tb_json_block.c
|
||||
|
||||
OBJS := $(patsubst src/%.c,$(BUILD)/%.o,$(SRCS))
|
||||
OBJS_DBG := $(patsubst src/%.c,$(BUILD)/%-dbg.o,$(SRCS))
|
||||
|
||||
CAT_LIBS := events control operators variables appearance pen fs
|
||||
CAT_A := $(foreach l,$(CAT_LIBS),$(LIBDIR)/tinyblocks-$(l)/build/libtinyblocks-$(l).a)
|
||||
CAT_LDFLAGS := $(foreach l,$(CAT_LIBS),-ltinyblocks-$(l))
|
||||
CAT_INCS := $(foreach l,$(CAT_LIBS),-I$(LIBDIR)/tinyblocks-$(l)/include)
|
||||
ED_A := $(ED_DIR)/build/libtinyblocks-editor.a
|
||||
GX_A := $(GX_DIR)/build/libtinyblocks-graphics.a
|
||||
SD_A := $(SD_DIR)/build/libtinyblocks-sdl2.a
|
||||
TOML_A := $(TOML_DIR)/build/libtinyblocks-toml.a
|
||||
LIB_LDFLAGS := -L$(ED_DIR)/build -L$(GX_DIR)/build -L$(SD_DIR)/build \
|
||||
$(foreach l,$(CAT_LIBS),-L$(LIBDIR)/tinyblocks-$(l)/build) -L$(BUILD)
|
||||
|
||||
.PHONY: all help debug release static shared example sdl2 clean run python-lib mcp-lib json \
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor \
|
||||
test-toml test-plugin \
|
||||
category-libs category-sos libs \
|
||||
lib-events lib-control lib-operators lib-variables lib-appearance lib-pen lib-fs \
|
||||
lib-editor lib-graphics lib-sdl2 lib-python lib-mcp lib-toml
|
||||
|
||||
all: static example ## Compila a biblioteca estática e o exemplo hello (padrão)
|
||||
|
||||
@@ -38,7 +78,7 @@ help: ## Lista os alvos disponíveis
|
||||
@echo
|
||||
@echo "Exemplo: make run-editor (libraries extras: ./build/editor build/mylib.so)"
|
||||
|
||||
# -- Biblioteca ---
|
||||
# -- Biblioteca principal (runtime) ---
|
||||
static: $(LIB_A) ## Compila build/libtinyblocks.a
|
||||
shared: $(LIB_SO) ## Compila build/libtinyblocks.so
|
||||
|
||||
@@ -77,106 +117,75 @@ $(BUILD)/hello-dbg: examples/hello/main.c $(BUILD)/libtinyblocks-dbg.a
|
||||
debug: $(BUILD)/hello-dbg ## Compila e roda o hello com ASan/UBSan
|
||||
./$(BUILD)/hello-dbg
|
||||
|
||||
# -- Library SDL2 ---
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
# ── Libraries (cada uma tem Makefile + build/ próprios) ──────────────────
|
||||
define CAT_LIB_TARGET
|
||||
lib-$(1):
|
||||
$(MAKE) -C $(LIBDIR)/tinyblocks-$(1)
|
||||
endef
|
||||
$(foreach l,$(CAT_LIBS),$(eval $(call CAT_LIB_TARGET,$(l))))
|
||||
|
||||
$(BUILD)/sdl2-example: examples/sdl2/main.c $(LIB_A) $(BUILD)/libtinyblocks-sdl2.a
|
||||
lib-editor:
|
||||
$(MAKE) -C $(ED_DIR)
|
||||
|
||||
lib-toml:
|
||||
$(MAKE) -C $(TOML_DIR)
|
||||
|
||||
lib-graphics:
|
||||
$(MAKE) -C $(GX_DIR)
|
||||
|
||||
lib-sdl2:
|
||||
$(MAKE) -C $(SD_DIR)
|
||||
|
||||
lib-python:
|
||||
$(MAKE) -C $(PY_DIR)
|
||||
|
||||
lib-mcp:
|
||||
$(MAKE) -C $(MC_DIR)
|
||||
|
||||
libs: static lib-events lib-control lib-operators lib-variables \
|
||||
lib-appearance lib-pen lib-fs lib-graphics lib-sdl2 lib-toml lib-editor
|
||||
@echo "Libraries OK: category + graphics + sdl2 + toml + editor"
|
||||
|
||||
category-libs: static $(foreach l,$(CAT_LIBS),lib-$(l)) ## Compila as libraries de categoria (.a/.so)
|
||||
@echo "Build category libs OK"
|
||||
|
||||
category-sos: category-libs ## Alias: as libraries de categoria tambem geram .so
|
||||
|
||||
# -- Library SDL2 (backend) ---
|
||||
$(BUILD)/sdl2-example: examples/sdl2/main.c static lib-sdl2
|
||||
$(CC) $(CFLAGS_REL) $(SDL2_CFLAGS) $(SDL2TTF_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-sdl2/include \
|
||||
-I$(SD_DIR)/include \
|
||||
$< -o $@ \
|
||||
-L$(BUILD) -ltinyblocks-sdl2 -ltinyblocks $(SDL2_LIBS) $(SDL2TTF_LIBS) -lm
|
||||
-L$(SD_DIR)/build -L$(BUILD) -ltinyblocks-sdl2 -ltinyblocks \
|
||||
$(SDL2_LIBS) $(SDL2TTF_LIBS) -lm
|
||||
|
||||
sdl2: static $(BUILD)/libtinyblocks-sdl2.a $(BUILD)/sdl2-example ## Compila a library SDL2 e seu exemplo
|
||||
sdl2: static lib-sdl2 $(BUILD)/sdl2-example ## Compila a library SDL2 e seu exemplo
|
||||
@echo "Build SDL2 OK: $(BUILD)/sdl2-example"
|
||||
|
||||
$(BUILD)/libtinyblocks-sdl2.a: $(BUILD)/tb_sdl2.o
|
||||
ar rcs $@ $^
|
||||
|
||||
$(BUILD)/tb_sdl2.o: libraries/tinyblocks-sdl2/src/tb_sdl2.c $(GFX_HDR) $(HDRS)
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_REL) $(SDL2_CFLAGS) $(SDL2TTF_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-sdl2/include -I$(GFX_INC) -Iinclude -fPIC -c $< -o $@
|
||||
|
||||
# Backend SDL2 como .so, para trocar em tempo de execução (--backend)
|
||||
$(BUILD)/libtinyblocks-sdl2.so: libraries/tinyblocks-sdl2/src/tb_sdl2.c $(GFX_HDR) $(LIB_A)
|
||||
$(CC) $(CFLAGS_REL) $(SDL2_CFLAGS) $(SDL2TTF_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-sdl2/include -I$(GFX_INC) -Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(BUILD) -ltinyblocks $(SDL2_LIBS) $(SDL2TTF_LIBS) -lm
|
||||
|
||||
sdl2-backend: static $(BUILD)/libtinyblocks-sdl2.so ## Backend SDL2 como .so (./build/editor --backend build/libtinyblocks-sdl2.so)
|
||||
@echo "Build backend OK: $(BUILD)/libtinyblocks-sdl2.so"
|
||||
|
||||
# -- Library Graphics (interface; backend padrão: SDL2) ---
|
||||
$(BUILD)/tb_graphics.o: libraries/tinyblocks-graphics/src/tb_graphics.c $(GFX_HDR) $(HDRS)
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_REL) -DTB_GRAPHICS_DEFAULT_SDL2 \
|
||||
-I$(GFX_INC) -Ilibraries/tinyblocks-sdl2/include -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/libtinyblocks-graphics.a: $(BUILD)/tb_graphics.o
|
||||
ar rcs $@ $^
|
||||
|
||||
graphics: static $(BUILD)/libtinyblocks-graphics.a $(BUILD)/libtinyblocks-sdl2.a ## Interface gráfica (com backend SDL2)
|
||||
@echo "Build graphics OK: $(BUILD)/libtinyblocks-graphics.a"
|
||||
sdl2-backend: static lib-sdl2 ## Backend SDL2 como .so (./build/editor --backend libraries/tinyblocks-sdl2/build/libtinyblocks-sdl2.so)
|
||||
@echo "Build backend OK: $(SD_DIR)/build/libtinyblocks-sdl2.so"
|
||||
|
||||
run-sdl2: sdl2 ## Compila e roda o exemplo SDL2
|
||||
LD_LIBRARY_PATH=$(BUILD) ./$(BUILD)/sdl2-example
|
||||
LD_LIBRARY_PATH=$(SD_DIR)/build:$(BUILD) ./$(BUILD)/sdl2-example
|
||||
|
||||
# -- Libraries de categoria (uma por seção da paleta) --
|
||||
CAT_LIBS := events control operators variables appearance pen
|
||||
CAT_A := $(patsubst %,$(BUILD)/libtinyblocks-%.a,$(CAT_LIBS))
|
||||
CAT_SO := $(patsubst %,$(BUILD)/tinyblocks-%.so,$(CAT_LIBS))
|
||||
CAT_LDFLAGS := $(patsubst %,-ltinyblocks-%,$(CAT_LIBS))
|
||||
|
||||
define CAT_LIB_RULE
|
||||
$(BUILD)/tb_$(1).o: libraries/tinyblocks-$(1)/src/tb_$(1).c libraries/tinyblocks-$(1)/include/tb_$(1).h $(HDRS)
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_REL) -Ilibraries/tinyblocks-$(1)/include -Ilibraries/tinyblocks-editor/src -fPIC -c $$< -o $$@
|
||||
|
||||
$(BUILD)/libtinyblocks-$(1).a: $(BUILD)/tb_$(1).o
|
||||
ar rcs $$@ $$^
|
||||
|
||||
$(BUILD)/tinyblocks-$(1).so: libraries/tinyblocks-$(1)/src/tb_$(1).c libraries/tinyblocks-$(1)/include/tb_$(1).h $(LIB_A)
|
||||
$(CC) $(CFLAGS_REL) -Ilibraries/tinyblocks-$(1)/include -Ilibraries/tinyblocks-editor/src -fPIC -shared $$< -o $$@ -L$(BUILD) -ltinyblocks '-Wl,-rpath,$$$$ORIGIN'
|
||||
endef
|
||||
|
||||
$(foreach l,$(CAT_LIBS),$(eval $(call CAT_LIB_RULE,$(l))))
|
||||
|
||||
category-libs: static $(CAT_A) ## Compila as libraries de categoria (.a)
|
||||
@echo "Build category libs OK: $(CAT_A)"
|
||||
|
||||
category-sos: static $(CAT_SO) ## Compila as libraries de categoria (.so, hot reload)
|
||||
@echo "Build category .so OK: $(CAT_SO)"
|
||||
# -- Library Graphics (interface; backend padrão: SDL2) ---
|
||||
graphics: static lib-sdl2 lib-graphics ## Interface gráfica (com backend SDL2)
|
||||
@echo "Build graphics OK: $(GX_DIR)/build/libtinyblocks-graphics.a"
|
||||
|
||||
# -- Library Editor ---
|
||||
SDL2TTF_CFLAGS := $(shell pkg-config --cflags SDL2_ttf 2>/dev/null)
|
||||
SDL2TTF_LIBS := $(shell pkg-config --libs SDL2_ttf 2>/dev/null)
|
||||
EDITOR_SRC := $(ED_DIR)/src
|
||||
EDITOR_HDRS := $(EDITOR_SRC)/tb_stage_widget.h $(ED_DIR)/include/tb_editor.h $(GFX_HDR) $(HDRS)
|
||||
|
||||
EDITOR_SRC := libraries/tinyblocks-editor/src
|
||||
EDITOR_HDRS := $(EDITOR_SRC)/tb_stage.h libraries/tinyblocks-editor/include/tb_editor.h $(GFX_HDR) $(HDRS)
|
||||
|
||||
$(BUILD)/tb_editor.o: $(EDITOR_SRC)/tb_editor.c $(EDITOR_HDRS)
|
||||
$(CC) $(CFLAGS_REL) -Ilibraries/tinyblocks-editor/include -I$(GFX_INC) \
|
||||
$(patsubst %,-Ilibraries/tinyblocks-%/include,$(CAT_LIBS)) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/tb_stage.o: $(EDITOR_SRC)/tb_stage.c $(EDITOR_HDRS)
|
||||
$(CC) $(CFLAGS_REL) -I$(GFX_INC) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/libtinyblocks-editor.a: $(BUILD)/tb_editor.o $(BUILD)/tb_stage.o
|
||||
ar rcs $@ $^
|
||||
|
||||
$(BUILD)/editor: examples/editor/main.c $(LIB_A) $(BUILD)/libtinyblocks-editor.a \
|
||||
$(BUILD)/libtinyblocks-graphics.a $(BUILD)/libtinyblocks-sdl2.a $(CAT_A)
|
||||
$(BUILD)/editor: examples/editor/main.c static libs
|
||||
$(CC) $(CFLAGS_REL) \
|
||||
-Ilibraries/tinyblocks-editor/include -I$(GFX_INC) \
|
||||
$(patsubst %,-Ilibraries/tinyblocks-%/include,$(CAT_LIBS)) \
|
||||
-I$(ED_DIR)/include -I$(GFX_INC) $(CAT_INCS) \
|
||||
-I$(FS_DIR)/include -I$(TOML_DIR)/include \
|
||||
$< -o $@ \
|
||||
-L$(BUILD) -Wl,--start-group -ltinyblocks-editor -ltinyblocks-graphics \
|
||||
-ltinyblocks-sdl2 $(CAT_LDFLAGS) -ltinyblocks -Wl,--end-group \
|
||||
$(SDL2_LIBS) $(SDL2TTF_LIBS) -ldl -lm \
|
||||
-Wl,--start-group $(ED_A) $(GX_A) $(SD_A) $(TOML_A) $(CAT_A) $(LIB_A) -Wl,--end-group \
|
||||
$(SDL2_LIBS) $(SDL2TTF_LIBS) -ldl -lm -rdynamic \
|
||||
'-Wl,-rpath,$$ORIGIN'
|
||||
|
||||
editor: static graphics $(BUILD)/libtinyblocks-editor.a $(CAT_A) $(BUILD)/editor ## Compila o editor visual (estilo Scratch)
|
||||
editor: static libs $(BUILD)/editor ## Compila o editor visual (estilo Scratch)
|
||||
@echo "Build editor OK: $(BUILD)/editor"
|
||||
|
||||
run-editor: editor ## Compila e abre o editor visual
|
||||
@@ -215,78 +224,69 @@ customappearance: static $(BUILD)/customappearance.so ## Library de demo do on_
|
||||
@echo "Build customappearance OK: $(BUILD)/customappearance.so"
|
||||
|
||||
# -- Library Python (embedding CPython) ---
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
$(BUILD)/tb_python_lib.o: libraries/tinyblocks-python/src/tb_python.c
|
||||
@mkdir -p $(BUILD)
|
||||
$(BUILD)/python.so: examples/python/python.c static lib-python
|
||||
$(CC) $(CFLAGS_REL) $(PYTHON_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-python/include -fPIC -c $< -o $@
|
||||
-I$(PY_DIR)/include -Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(PY_DIR)/build -L$(BUILD) -ltinyblocks-python -ltinyblocks \
|
||||
'-Wl,-rpath,$$ORIGIN' '-Wl,-rpath,$(abspath $(PY_DIR)/build)'
|
||||
|
||||
# Shared lib - garante um único interpretador Python no processo
|
||||
$(BUILD)/libtinyblocks-python.so: $(BUILD)/tb_python_lib.o
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-python.so -o $@ $^ $(PYTHON_LIBS)
|
||||
|
||||
$(BUILD)/python.so: examples/python/python.c $(LIB_A) $(BUILD)/libtinyblocks-python.so
|
||||
$(CC) $(CFLAGS_REL) $(PYTHON_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-python/include -Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(BUILD) -ltinyblocks -ltinyblocks-python \
|
||||
'-Wl,-rpath,$$ORIGIN'
|
||||
|
||||
python-lib: static $(BUILD)/libtinyblocks-python.so $(BUILD)/python.so ## Library Python (CPython embutido) -> build/python.so
|
||||
python-lib: static lib-python $(BUILD)/python.so ## Library Python (CPython embutido) -> build/python.so
|
||||
@echo "Build python OK: $(BUILD)/python.so"
|
||||
|
||||
# -- Library MCP (usa tinyblocks-python) ---
|
||||
# Gera header com o código Python embutido (unsigned char tb_mcp_py[])
|
||||
libraries/tinyblocks-mcp/src/tb_mcp_py.h: libraries/tinyblocks-mcp/src/tb_mcp.py
|
||||
xxd -i -n tb_mcp_py $< $@
|
||||
|
||||
$(BUILD)/tb_mcp_lib.o: libraries/tinyblocks-mcp/src/tb_mcp.c \
|
||||
libraries/tinyblocks-mcp/src/tb_mcp_py.h \
|
||||
libraries/tinyblocks-python/include/tinyblocks-python/tb_python.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_REL) $(PYTHON_CFLAGS) \
|
||||
-Ilibraries/tinyblocks-mcp/include \
|
||||
-Ilibraries/tinyblocks-python/include \
|
||||
-Ilibraries/tinyblocks-mcp/src \
|
||||
-fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/libtinyblocks-mcp.so: $(BUILD)/tb_mcp_lib.o $(BUILD)/libtinyblocks-python.so
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-mcp.so -o $@ $(BUILD)/tb_mcp_lib.o \
|
||||
-L$(BUILD) -ltinyblocks-python $(PYTHON_LIBS) \
|
||||
'-Wl,-rpath,$$ORIGIN'
|
||||
|
||||
$(BUILD)/mcp.so: examples/mcp/mcp.c $(LIB_A) \
|
||||
$(BUILD)/libtinyblocks-mcp.so $(BUILD)/libtinyblocks-python.so
|
||||
$(BUILD)/mcp.so: examples/mcp/mcp.c static lib-mcp
|
||||
$(CC) $(CFLAGS_REL) \
|
||||
-Ilibraries/tinyblocks-mcp/include \
|
||||
-Ilibraries/tinyblocks-python/include \
|
||||
-Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(BUILD) -ltinyblocks -ltinyblocks-mcp -ltinyblocks-python \
|
||||
'-Wl,-rpath,$$ORIGIN'
|
||||
-I$(MC_DIR)/include -I$(PY_DIR)/include -Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(MC_DIR)/build -L$(PY_DIR)/build -L$(BUILD) \
|
||||
-ltinyblocks-mcp -ltinyblocks-python -ltinyblocks \
|
||||
'-Wl,-rpath,$$ORIGIN' '-Wl,-rpath,$(abspath $(MC_DIR)/build)' \
|
||||
'-Wl,-rpath,$(abspath $(PY_DIR)/build)'
|
||||
|
||||
mcp-lib: static $(BUILD)/libtinyblocks-python.so $(BUILD)/libtinyblocks-mcp.so $(BUILD)/mcp.so ## Library cliente MCP -> build/mcp.so
|
||||
mcp-lib: static lib-mcp $(BUILD)/mcp.so ## Library cliente MCP -> build/mcp.so
|
||||
@echo "Build mcp OK: $(BUILD)/mcp.so"
|
||||
|
||||
# -- Limpeza ---
|
||||
# -- Testes (harness headless com ASan/UBSan) ---
|
||||
# ── Testes (harness headless com ASan/UBSan) ─────────────────────────────
|
||||
$(BUILD)/editor_harness: tests/editor_harness.c $(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage.c \
|
||||
libraries/tinyblocks-graphics/src/tb_graphics.c
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage_widget.c \
|
||||
$(GX_DIR)/src/tb_graphics.c
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) \
|
||||
-Ilibraries/tinyblocks-editor/include -Ilibraries/tinyblocks-editor/src \
|
||||
-I$(GFX_INC) \
|
||||
$(patsubst %,-Ilibraries/tinyblocks-%/include,$(CAT_LIBS)) \
|
||||
-I$(ED_DIR)/include -I$(EDITOR_SRC) -I$(GFX_INC) $(CAT_INCS) \
|
||||
$(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage.c \
|
||||
libraries/tinyblocks-graphics/src/tb_graphics.c \
|
||||
$(foreach l,$(CAT_LIBS),libraries/tinyblocks-$(l)/src/tb_$(l).c) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage_widget.c \
|
||||
$(GX_DIR)/src/tb_graphics.c \
|
||||
$(foreach l,$(CAT_LIBS),$(LIBDIR)/tinyblocks-$(l)/src/tb_$(l).c) \
|
||||
tests/editor_harness.c -o $@ -ldl -lm
|
||||
|
||||
test-editor: $(BUILD)/editor_harness ## Roda o harness headless do editor (ASan/UBSan)
|
||||
./$(BUILD)/editor_harness
|
||||
|
||||
clean: ## Remove o diretório build/
|
||||
# -- Teste do parser TOML ---
|
||||
TOML_LIB_SRCS := $(TOML_DIR)/src/lexer.c $(TOML_DIR)/src/parser.c
|
||||
|
||||
$(BUILD)/toml_test: tests/toml_test.c $(TOML_LIB_SRCS) $(TOML_DIR)/include/ast.h $(TOML_DIR)/include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) -I$(TOML_DIR)/include $(TOML_LIB_SRCS) tests/toml_test.c -o $@
|
||||
|
||||
test-toml: $(BUILD)/toml_test ## Roda o teste do parser TOML (ASan/UBSan)
|
||||
./$(BUILD)/toml_test
|
||||
|
||||
# -- Teste de plugin .so standalone ---
|
||||
FS_SO := $(FS_DIR)/build/libtinyblocks-fs.so
|
||||
|
||||
$(BUILD)/plugin_test: tests/plugin_test.c static $(FS_SO)
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) -Iinclude tests/plugin_test.c -o $@ \
|
||||
-Wl,--start-group $(LIB_A) -Wl,--end-group -ldl -rdynamic
|
||||
|
||||
test-plugin: $(BUILD)/plugin_test ## Carrega library-fs .so via dlopen e testa
|
||||
./$(BUILD)/plugin_test $(FS_SO)
|
||||
|
||||
# ── Limpeza ──────────────────────────────────────────────────────────────
|
||||
clean: ## Remove os diretórios build/ (raiz e libraries)
|
||||
$(RM) -r $(BUILD)
|
||||
$(MAKE) -C libraries/tinyblocks-sdl2 clean 2>/dev/null || true
|
||||
@for d in $(EV_DIR) $(CT_DIR) $(OP_DIR) $(VR_DIR) $(AP_DIR) $(PN_DIR) $(FS_DIR) \
|
||||
$(TOML_DIR) $(ED_DIR) $(GX_DIR) $(SD_DIR) $(PY_DIR) $(MC_DIR); do \
|
||||
$(MAKE) -C $$d clean >/dev/null 2>&1 || true; \
|
||||
done
|
||||
$(RM) $(MC_DIR)/src/tb_mcp_py.h
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <tb_variables.h>
|
||||
#include <tb_appearance.h>
|
||||
#include <tb_pen.h>
|
||||
#include <tb_fs.h>
|
||||
#include <tb_toml.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
TinyBlocks* rt = NULL;
|
||||
@@ -45,6 +47,8 @@ int main(int argc, char** argv) {
|
||||
tb_library_register(rt, tb_variables_get_library());
|
||||
tb_library_register(rt, tb_appearance_get_library());
|
||||
tb_library_register(rt, tb_pen_get_library());
|
||||
tb_library_register(rt, tb_fs_get_library());
|
||||
tb_library_register(rt, tb_toml_get_library());
|
||||
|
||||
/* Interface gráfica: o editor mede texto e cria o palco ao nascer */
|
||||
tb_library_register(rt, tb_graphics_get_library());
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.h
|
||||
* Palco logico (canvas retido) do runtime. Blocos de desenho, como os da
|
||||
* library Caneta, usam esta API; a UI (o editor) chama tb_stage_render para
|
||||
* exibir. Assim a library Caneta nao depende do editor.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_STAGE_H
|
||||
#define TINYBLOCKS_STAGE_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
|
||||
/* Comandos de desenho (coordenadas do palco: 480x360, origem no centro, y p/ cima) */
|
||||
TB_API void tb_stage_clear(void);
|
||||
TB_API void tb_stage_set_background(float r, float g, float b); /* canais 0..255 */
|
||||
TB_API void tb_stage_set_pen(float r, float g, float b); /* canais 0..255 */
|
||||
TB_API void tb_stage_set_pen_size(float size);
|
||||
TB_API void tb_stage_line(float x1, float y1, float x2, float y2);
|
||||
TB_API void tb_stage_rect(float x, float y, float w, float h);
|
||||
TB_API void tb_stage_circle(float x, float y, float radius);
|
||||
TB_API void tb_stage_text(const char* text, float x, float y);
|
||||
|
||||
/* Vista: tamanho da area onde o palco sera desenhado (letterbox 4:3) */
|
||||
TB_API void tb_stage_set_view(float w, float h);
|
||||
|
||||
/* Emite os desenhos num RenderableBlock ja adquirido */
|
||||
TB_API bool tb_stage_render(TinyBlocks_RenderableBlock* rb);
|
||||
|
||||
/* Libera o estado do palco (chamado quando a UI que o exibe e destruida) */
|
||||
TB_API void tb_stage_reset(void);
|
||||
|
||||
#endif /* TINYBLOCKS_STAGE_H */
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library appearance (categoria "Aparência")
|
||||
# Constroi build/libtinyblocks-appearance.a e build/libtinyblocks-appearance.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_appearance.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-appearance.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-appearance.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_appearance.c include/tb_appearance.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library appearance. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-appearance"
|
||||
version = "1.0.0"
|
||||
category = "Aparencia"
|
||||
description = "Saida visivel (escreva)"
|
||||
color = [153, 102, 255, 255]
|
||||
dark = [119, 77, 203, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_appearance.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-appearance.so"
|
||||
static = "build/libtinyblocks-appearance.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library control (categoria "Controle")
|
||||
# Constroi build/libtinyblocks-control.a e build/libtinyblocks-control.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_control.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-control.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-control.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_control.c include/tb_control.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library control. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-control"
|
||||
version = "1.0.0"
|
||||
category = "Controle"
|
||||
description = "Repita, se, se-senao, repita ate que"
|
||||
color = [255, 171, 25, 255]
|
||||
dark = [207, 139, 23, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_control.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-control.so"
|
||||
static = "build/libtinyblocks-control.a"
|
||||
depends = []
|
||||
@@ -1,35 +1,33 @@
|
||||
# Makefile da library editor (editor visual estilo Scratch)
|
||||
# Constroi build/libtinyblocks-editor.a e build/libtinyblocks-editor.so
|
||||
# Inclui o widget Editor.Stage (tb_stage.c).
|
||||
CC := gcc
|
||||
BUILD := ../../build
|
||||
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
SDL2TTF_CFLAGS:= $(shell pkg-config --cflags SDL2_ttf 2>/dev/null)
|
||||
SDL2TTF_LIBS := $(shell pkg-config --libs SDL2_ttf 2>/dev/null)
|
||||
|
||||
ifeq ($(SDL2TTF_LIBS),)
|
||||
$(error SDL2_ttf não encontrado. Instale: sudo apt install libsdl2-ttf-dev)
|
||||
endif
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L \
|
||||
-I../../include \
|
||||
-Iinclude \
|
||||
$(SDL2_CFLAGS) $(SDL2TTF_CFLAGS)
|
||||
-D_POSIX_C_SOURCE=200809L \
|
||||
-I../../include -Iinclude -Isrc \
|
||||
-I../tinyblocks-graphics/include \
|
||||
-I../tinyblocks-variables/include
|
||||
|
||||
LDFLAGS := $(SDL2_LIBS) $(SDL2TTF_LIBS) -lm
|
||||
|
||||
OBJ := $(BUILD)/tb_editor.o
|
||||
OBJ := $(BUILD)/tb_editor.o $(BUILD)/tb_stage_widget.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-editor.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-editor.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
|
||||
all: static shared
|
||||
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_editor.c include/tb_editor.h
|
||||
$(BUILD)/tb_editor.o: src/tb_editor.c include/tb_editor.h src/tb_stage_widget.h \
|
||||
../tinyblocks-graphics/include/tb_graphics.h \
|
||||
../tinyblocks-variables/include/tb_variables.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/tb_stage_widget.o: src/tb_stage_widget.c src/tb_stage_widget.h \
|
||||
../tinyblocks-graphics/include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
@@ -37,7 +35,7 @@ $(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) -shared -o $@ $^ -ldl
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(LIB_A) $(LIB_SO)
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library editor. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-editor"
|
||||
version = "1.0.0"
|
||||
category = "Meus Blocos"
|
||||
description = "Editor visual e blocos compostos"
|
||||
color = [255, 102, 128, 255]
|
||||
dark = [255, 51, 85, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_editor.c", "src/tb_stage_widget.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-editor.so"
|
||||
static = "build/libtinyblocks-editor.a"
|
||||
depends = []
|
||||
@@ -35,8 +35,9 @@
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_graphics.h>
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include <tb_variables.h>
|
||||
#include "tb_stage.h"
|
||||
#include "tb_stage_widget.h"
|
||||
#include "../include/tb_editor.h"
|
||||
|
||||
|
||||
@@ -2555,7 +2556,7 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_text_c(rb, bx + (bw - tw(msg, FS_UI))*0.5f, by + ph*0.5f, msg, COL_TEXT_DIM, FS_UI);
|
||||
} else {
|
||||
TinyBlocks_RenderableBlock* sub = NULL;
|
||||
tb_stage_set_view(ed->stage, bw-2, ph-2);
|
||||
tb_stage_set_view(bw-2, ph-2);
|
||||
clip_set(ed, rb, bx+1, by+1, bw-2, ph-2);
|
||||
if (ed->stage->type->on_draw(ed->stage, ed->rt, &sub) && sub) {
|
||||
tb_draw_merge_offset(rb, sub, bx+1, by+1);
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.c
|
||||
* O Palco do editor: uma tela lógica de 480x360 (origem no centro, y para
|
||||
* cima, como no Scratch) onde os blocos Stage.* desenham. É um componente de
|
||||
* UI: o editor o embute no painel direito (chamando seu on_draw) ou o entrega
|
||||
* como cena de um Graphics.Window próprio ("destacar palco").
|
||||
*
|
||||
* Os desenhos ficam numa lista retida e são re-emitidos a cada on_draw,
|
||||
* escalados para o tamanho da área (letterbox mantendo 4:3).
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <tb_graphics.h>
|
||||
#include "tb_stage.h"
|
||||
|
||||
#define STAGE_W 480.f
|
||||
#define STAGE_H 360.f
|
||||
#define STAGE_MAX_CMDS 4000
|
||||
#define STAGE_TEXT_FS 14.f
|
||||
|
||||
typedef enum { SC_RECT, SC_CIRCLE, SC_LINE, SC_TEXT } StageCmdKind;
|
||||
|
||||
typedef struct {
|
||||
StageCmdKind kind;
|
||||
float a, b, c, d; /* geometria em coordenadas do palco */
|
||||
float size; /* espessura da caneta */
|
||||
float col[3];
|
||||
char text[96];
|
||||
} StageCmd;
|
||||
|
||||
typedef struct {
|
||||
StageCmd* cmds;
|
||||
int n, cap;
|
||||
float bg[3];
|
||||
float pen[3];
|
||||
float pen_size;
|
||||
float view_w, view_h;
|
||||
bool full_warned;
|
||||
} Stage;
|
||||
|
||||
static TinyBlocks_Block* s_current = NULL;
|
||||
static TinyBlocks* s_rt = NULL; /* para mensagens de erro */
|
||||
|
||||
static Stage* stage_of(TinyBlocks_Block* b) { return b ? *(Stage**)b->userdata : NULL; }
|
||||
|
||||
TinyBlocks_Block* tb_stage_current(void) { return s_current; }
|
||||
|
||||
void tb_stage_set_view(TinyBlocks_Block* stage, float w, float h) {
|
||||
Stage* s = stage_of(stage);
|
||||
if (s && w > 0 && h > 0) { s->view_w = w; s->view_h = h; }
|
||||
}
|
||||
|
||||
/* ===
|
||||
* Editor.Stage
|
||||
* === */
|
||||
static bool stage_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)rt;
|
||||
Stage* s = (Stage*)calloc(1, sizeof(Stage));
|
||||
if (!s) return false;
|
||||
s->bg[0] = s->bg[1] = s->bg[2] = 1.f;
|
||||
s->pen[0] = 76/255.f; s->pen[1] = 151/255.f; s->pen[2] = 1.f;
|
||||
s->pen_size = 2.f;
|
||||
s->view_w = STAGE_W; s->view_h = STAGE_H;
|
||||
*(Stage**)self->userdata = s;
|
||||
s_current = self;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void stage_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)rt;
|
||||
Stage* s = stage_of(self);
|
||||
if (s) { free(s->cmds); free(s); }
|
||||
*(Stage**)self->userdata = NULL;
|
||||
if (s_current == self) s_current = NULL;
|
||||
}
|
||||
|
||||
/* input 0 (opcional): Graphics.Input da janela que mostra o palco - dá o tamanho da vista */
|
||||
static void eval_stage(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Block* in = v.kind == TB_VALUE_BLOCK ? v.as.block : NULL;
|
||||
if (!in || in->output_count < GFX_IN_COUNT) return;
|
||||
TinyBlocks_Value w = in->outputs[GFX_IN_WIN_W], h = in->outputs[GFX_IN_WIN_H];
|
||||
if (w.kind == TB_VALUE_INTEGER && h.kind == TB_VALUE_INTEGER)
|
||||
tb_stage_set_view(self, (float)w.as.integer, (float)h.as.integer);
|
||||
}
|
||||
|
||||
static bool stage_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_RenderableBlock** dst) {
|
||||
(void)rt;
|
||||
Stage* s = stage_of(self);
|
||||
if (!s) return false;
|
||||
TinyBlocks_RenderableBlock* rb = tb_renderable_acquire();
|
||||
if (!rb) return false;
|
||||
|
||||
float sc = s->view_w / STAGE_W < s->view_h / STAGE_H ? s->view_w / STAGE_W : s->view_h / STAGE_H;
|
||||
float ox = (s->view_w - STAGE_W*sc) * 0.5f, oy = (s->view_h - STAGE_H*sc) * 0.5f;
|
||||
#define SX(x) (ox + ((x) + STAGE_W*0.5f) * sc)
|
||||
#define SY(y) (oy + (STAGE_H*0.5f - (y)) * sc)
|
||||
|
||||
if (ox > 0.5f || oy > 0.5f) tb_draw_fill_rect(rb, 0, 0, s->view_w, s->view_h, 0.12f, 0.12f, 0.14f, 1.f);
|
||||
tb_draw_fill_rect(rb, ox, oy, STAGE_W*sc, STAGE_H*sc, s->bg[0], s->bg[1], s->bg[2], 1.f);
|
||||
tb_draw_set_clip(rb, ox, oy, STAGE_W*sc, STAGE_H*sc);
|
||||
|
||||
for (int i = 0; i < s->n && rb->count < TB_DRAW_CMD_CAP - 2; i++) {
|
||||
const StageCmd* c = &s->cmds[i];
|
||||
float r = c->col[0], g = c->col[1], b = c->col[2];
|
||||
switch (c->kind) {
|
||||
case SC_RECT:
|
||||
tb_draw_fill_rect(rb, SX(c->a - c->c*0.5f), SY(c->b + c->d*0.5f), c->c*sc, c->d*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_CIRCLE:
|
||||
tb_draw_fill_circle(rb, SX(c->a), SY(c->b), c->c*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_LINE:
|
||||
tb_draw_stroke_line(rb, SX(c->a), SY(c->b), SX(c->c), SY(c->d), c->size*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_TEXT: {
|
||||
float fs = STAGE_TEXT_FS * sc;
|
||||
tb_draw_text(rb, SX(c->a), SY(c->b) + fs*0.36f, c->text, fs, r, g, b, 1.f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tb_draw_clear_clip(rb);
|
||||
#undef SX
|
||||
#undef SY
|
||||
*dst = rb;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ===
|
||||
* API de desenho - usada pela library tinyblocks-pen (categoria "Caneta")
|
||||
* === */
|
||||
static float chan(float v) { return v < 0 ? 0.f : v > 255 ? 1.f : v / 255.f; }
|
||||
|
||||
static StageCmd* push(TinyBlocks* rt, StageCmdKind kind) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (!s) { tinyblocks_set_error(rt, "nenhum palco (Editor.Stage) criado"); return NULL; }
|
||||
if (s->n >= STAGE_MAX_CMDS) {
|
||||
if (!s->full_warned) tinyblocks_set_error(rt, "palco cheio (%d desenhos) = use \"apague tudo\"", STAGE_MAX_CMDS);
|
||||
s->full_warned = true;
|
||||
return NULL;
|
||||
}
|
||||
if (s->n >= s->cap) {
|
||||
int nc = s->cap ? s->cap * 2 : 64;
|
||||
StageCmd* p = (StageCmd*)realloc(s->cmds, (size_t)nc * sizeof(StageCmd));
|
||||
if (!p) return NULL;
|
||||
s->cmds = p; s->cap = nc;
|
||||
}
|
||||
StageCmd* c = &s->cmds[s->n++];
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->kind = kind;
|
||||
memcpy(c->col, s->pen, sizeof(c->col));
|
||||
c->size = s->pen_size;
|
||||
return c;
|
||||
}
|
||||
|
||||
void tb_stage_clear(void) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->n = 0; s->full_warned = false; }
|
||||
}
|
||||
|
||||
void tb_stage_set_background(float r, float g, float b) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->bg[0] = chan(r); s->bg[1] = chan(g); s->bg[2] = chan(b); }
|
||||
}
|
||||
|
||||
void tb_stage_set_pen(float r, float g, float b) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->pen[0] = chan(r); s->pen[1] = chan(g); s->pen[2] = chan(b); }
|
||||
}
|
||||
|
||||
void tb_stage_set_pen_size(float size) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) s->pen_size = size < 1.f ? 1.f : size;
|
||||
}
|
||||
|
||||
void tb_stage_line(float x1, float y1, float x2, float y2) {
|
||||
StageCmd* c = push(s_rt, SC_LINE);
|
||||
if (c) { c->a = x1; c->b = y1; c->c = x2; c->d = y2; }
|
||||
}
|
||||
|
||||
void tb_stage_rect(float x, float y, float w, float h) {
|
||||
StageCmd* c = push(s_rt, SC_RECT);
|
||||
if (c) { c->a = x; c->b = y; c->c = w; c->d = h; }
|
||||
}
|
||||
|
||||
void tb_stage_circle(float x, float y, float radius) {
|
||||
StageCmd* c = push(s_rt, SC_CIRCLE);
|
||||
if (c) { c->a = x; c->b = y; c->c = radius; }
|
||||
}
|
||||
|
||||
void tb_stage_text(const char* text, float x, float y) {
|
||||
StageCmd* c = push(s_rt, SC_TEXT);
|
||||
if (c) {
|
||||
snprintf(c->text, sizeof(c->text), "%s", text ? text : "");
|
||||
c->a = x; c->b = y;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===
|
||||
* Registro do widget Editor.Stage
|
||||
* === */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
s_rt = rt;
|
||||
static const TinyBlocks_SlotDesc stage_in[] = {{"entrada", TB_VALUE_BLOCK}};
|
||||
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, sizeof(Stage*), stage_instance_init, stage_instance_deinit);
|
||||
t->on_draw = stage_on_draw;
|
||||
return tb_library_add(lib, &t->base);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.h
|
||||
* Palco do editor (Editor.Stage) e API de desenho usada pela library Caneta.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_EDITOR_STAGE_H
|
||||
#define TINYBLOCKS_EDITOR_STAGE_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
/* Registra apenas o widget Editor.Stage na library do editor */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib);
|
||||
|
||||
/* Tamanho da área onde o palco será desenhado (on_draw usa 0..w - 0..h) */
|
||||
void tb_stage_set_view(TinyBlocks_Block* stage, float w, float h);
|
||||
|
||||
/* Palco onde o desenho acontece (o último Editor.Stage criado) */
|
||||
TinyBlocks_Block* tb_stage_current(void);
|
||||
|
||||
/* == API de desenho (usada pela library tinyblocks-pen) === */
|
||||
void tb_stage_clear(void);
|
||||
void tb_stage_set_background(float r, float g, float b); /* canais 0..255 */
|
||||
void tb_stage_set_pen(float r, float g, float b); /* canais 0..255 */
|
||||
void tb_stage_set_pen_size(float size);
|
||||
void tb_stage_line(float x1, float y1, float x2, float y2);
|
||||
void tb_stage_rect(float x, float y, float w, float h);
|
||||
void tb_stage_circle(float x, float y, float radius);
|
||||
void tb_stage_text(const char* text, float x, float y);
|
||||
|
||||
#endif /* TINYBLOCKS_EDITOR_STAGE_H */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage_widget.c (editor)
|
||||
* Editor.Stage: widget que renderiza o palco logico do runtime. Toda a
|
||||
* logica de desenho/estado fica no core (tb_stage.h); aqui so adaptamos ao
|
||||
* loop de UI do editor.
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_graphics.h>
|
||||
#include "tb_stage_widget.h"
|
||||
|
||||
/* input 0 (opcional): Graphics.Input da janela que mostra o palco - da o tamanho da vista */
|
||||
static void eval_stage(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Block* in = v.kind == TB_VALUE_BLOCK ? v.as.block : NULL;
|
||||
if (!in || in->output_count < GFX_IN_COUNT) return;
|
||||
TinyBlocks_Value w = in->outputs[GFX_IN_WIN_W], h = in->outputs[GFX_IN_WIN_H];
|
||||
if (w.kind == TB_VALUE_INTEGER && h.kind == TB_VALUE_INTEGER)
|
||||
tb_stage_set_view((float)w.as.integer, (float)h.as.integer);
|
||||
}
|
||||
|
||||
static bool stage_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_RenderableBlock** dst) {
|
||||
(void)self; (void)rt;
|
||||
TinyBlocks_RenderableBlock* rb = tb_renderable_acquire();
|
||||
if (!rb) return false;
|
||||
tb_stage_render(rb);
|
||||
*dst = rb;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool stage_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)self; (void)rt;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void stage_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)self; (void)rt;
|
||||
tb_stage_reset();
|
||||
}
|
||||
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_SlotDesc stage_in[] = {{"entrada", TB_VALUE_BLOCK}};
|
||||
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);
|
||||
t->on_draw = stage_on_draw;
|
||||
return tb_library_add(lib, &t->base);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage_widget.h (editor)
|
||||
* Widget Editor.Stage: exibe o palco logico do runtime (tb_stage.h).
|
||||
*/
|
||||
#ifndef TINYBLOCKS_EDITOR_STAGE_WIDGET_H
|
||||
#define TINYBLOCKS_EDITOR_STAGE_WIDGET_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
/* Registra o TypeBlock Editor.Stage na library do editor */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib);
|
||||
|
||||
#endif /* TINYBLOCKS_EDITOR_STAGE_WIDGET_H */
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library events (categoria "Eventos")
|
||||
# Constroi build/libtinyblocks-events.a e build/libtinyblocks-events.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_events.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-events.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-events.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_events.c include/tb_events.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library events. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-events"
|
||||
version = "1.0.0"
|
||||
category = "Eventos"
|
||||
description = "Blocos que iniciam scripts"
|
||||
color = [255, 191, 0, 255]
|
||||
dark = [204, 153, 0, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_events.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-events.so"
|
||||
static = "build/libtinyblocks-events.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,29 @@
|
||||
# Makefile da library fs (categoria "Arquivos")
|
||||
# Constroi build/libtinyblocks-fs.a e build/libtinyblocks-fs.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_fs.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-fs.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-fs.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_fs.c include/tb_fs.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* TinyBlocks - tb_fs.h
|
||||
* Library tinyblocks-fs: blocos de arquivo (abrir, ler, escrever, anexar,
|
||||
* posicao). Independente do editor; registra a categoria "Arquivos".
|
||||
*/
|
||||
#ifndef TINYBLOCKS_FS_H
|
||||
#define TINYBLOCKS_FS_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_fs_get_library(void);
|
||||
|
||||
#endif /* TINYBLOCKS_FS_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library fs. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-fs"
|
||||
version = "1.0.0"
|
||||
category = "Arquivos"
|
||||
description = "Abra, leia, escreva, anexe e posicao de arquivo"
|
||||
color = [0, 188, 212, 255]
|
||||
dark = [0, 151, 167, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_fs.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-fs.so"
|
||||
static = "build/libtinyblocks-fs.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* TinyBlocks - tb_fs.c
|
||||
* Categoria "Arquivos": abra / leia / escreva / anexe / posicao.
|
||||
* Mantem uma pequena tabela de arquivos abertos (handle inteiro >= 1).
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_fs.h"
|
||||
|
||||
#define FS_MAX_FILES 64
|
||||
|
||||
static FILE* s_files[FS_MAX_FILES];
|
||||
|
||||
static int fs_slot(void) {
|
||||
for (int i = 0; i < FS_MAX_FILES; i++) if (!s_files[i]) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static FILE* fs_get(int64_t handle) {
|
||||
int i = (int)handle - 1;
|
||||
if (i < 0 || i >= FS_MAX_FILES) return NULL;
|
||||
return s_files[i];
|
||||
}
|
||||
|
||||
static void fs_close_slot(int i) {
|
||||
if (i >= 0 && i < FS_MAX_FILES && s_files[i]) { fclose(s_files[i]); s_files[i] = NULL; }
|
||||
}
|
||||
|
||||
static const char* in_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
|
||||
}
|
||||
static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_INTEGER) return v.as.integer;
|
||||
if (v.kind == TB_VALUE_REAL) return (int64_t)v.as.real;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void eval_open(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = in_text(self, rt, 0);
|
||||
int slot = fs_slot();
|
||||
int64_t handle = 0;
|
||||
if (slot >= 0 && path[0]) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (f) { s_files[slot] = f; handle = slot + 1; }
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_integer(handle));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_read(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
int64_t want = in_int(self, rt, 1);
|
||||
char* buf = NULL; size_t n = 0;
|
||||
if (f) {
|
||||
long start = ftell(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
long end = ftell(f);
|
||||
fseek(f, start, SEEK_SET);
|
||||
size_t avail = (end > start) ? (size_t)(end - start) : 0;
|
||||
if (want > 0 && (size_t)want < avail) avail = (size_t)want;
|
||||
buf = (char*)malloc(avail + 1);
|
||||
if (buf) {
|
||||
n = fread(buf, 1, avail, f);
|
||||
buf[n] = 0;
|
||||
}
|
||||
}
|
||||
TinyBlocks_Value v = tb_value_text(buf ? buf : "");
|
||||
free(buf);
|
||||
tb_block_set_output(self, 0, v);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_write(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
const char* text = in_text(self, rt, 1);
|
||||
if (f) fwrite(text, 1, strlen(text), f);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_append(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = in_text(self, rt, 0);
|
||||
const char* text = in_text(self, rt, 1);
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(path, "ab");
|
||||
if (f) { fwrite(text, 1, strlen(text), f); fclose(f); }
|
||||
}
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_tell(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
long pos = f ? ftell(f) : -1;
|
||||
tb_block_set_output(self, 0, tb_value_integer(pos));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_close(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
int64_t h = in_int(self, rt, 0);
|
||||
fs_close_slot((int)h - 1);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
/* -- Registro ------------------------------------------------------------ */
|
||||
|
||||
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
|
||||
const TinyBlocks_SlotDesc* in, uint32_t ni,
|
||||
const TinyBlocks_SlotDesc* out, uint32_t no,
|
||||
void (*fn)(TinyBlocks_Block*, TinyBlocks*)) {
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, name, in, ni, out, no, fn);
|
||||
return t && tb_library_add(lib, &t->base);
|
||||
}
|
||||
|
||||
static bool fs_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_Category cat = {
|
||||
"Arquivos",
|
||||
{ 0/255.f, 188/255.f, 212/255.f, 1.f},
|
||||
{ 0/255.f, 151/255.f, 167/255.f, 1.f},
|
||||
};
|
||||
tb_library_set_category(lib, &cat);
|
||||
|
||||
static const TinyBlocks_SlotDesc open_in[] = {{"nome", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc read_in[] = {{"arquivo", TB_VALUE_INTEGER}, {"bytes", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc write_in[] = {{"arquivo", TB_VALUE_INTEGER}, {"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc append_in[] = {{"nome", TB_VALUE_TEXT}, {"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc tell_in[] = {{"arquivo", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc close_in[] = {{"arquivo", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc handle_out[]= {{"handle", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc text_out[] = {{"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc pos_out[] = {{"posicao",TB_VALUE_INTEGER}};
|
||||
|
||||
return reg(rt, lib, "FS.Open", open_in, 1, handle_out, 1, eval_open)
|
||||
&& reg(rt, lib, "FS.Read", read_in, 2, text_out, 1, eval_read)
|
||||
&& reg(rt, lib, "FS.Write", write_in, 2, NULL, 0, eval_write)
|
||||
&& reg(rt, lib, "FS.Append", append_in, 2, NULL, 0, eval_append)
|
||||
&& reg(rt, lib, "FS.Tell", tell_in, 1, pos_out, 1, eval_tell)
|
||||
&& reg(rt, lib, "FS.Close", close_in, 1, NULL, 0, eval_close);
|
||||
}
|
||||
|
||||
static void fs_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
(void)rt; (void)lib;
|
||||
for (int i = 0; i < FS_MAX_FILES; i++) fs_close_slot(i);
|
||||
}
|
||||
|
||||
TINYBLOCKS_DEFINE_LIBRARY(fs,
|
||||
"tinyblocks-fs",
|
||||
"1.0.0",
|
||||
fs_init,
|
||||
fs_deinit)
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* tb_fs_get_library(void) {
|
||||
return &_tb_lib_desc_fs;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# Makefile da library graphics (interface grafica; backend padrao SDL2)
|
||||
# Constroi build/libtinyblocks-graphics.a e build/libtinyblocks-graphics.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -DTB_GRAPHICS_DEFAULT_SDL2 \
|
||||
-I../../include -Iinclude -I../tinyblocks-sdl2/include
|
||||
|
||||
OBJ := $(BUILD)/tb_graphics.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-graphics.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-graphics.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_graphics.c include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ -ldl
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library graphics. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-graphics"
|
||||
version = "1.0.0"
|
||||
category = "Graficos"
|
||||
description = "Interface grafica (janelas, entrada)"
|
||||
color = [0, 150, 136, 255]
|
||||
dark = [0, 121, 107, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_graphics.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-graphics.so"
|
||||
static = "build/libtinyblocks-graphics.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,35 @@
|
||||
# Makefile da library mcp (cliente MCP; reusa tinyblocks-python)
|
||||
# Constroi build/libtinyblocks-mcp.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
PYDIR := ../tinyblocks-python
|
||||
PYBUILD:= $(PYDIR)/build
|
||||
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -Iinclude -Isrc -I$(PYDIR)/include $(PYTHON_CFLAGS)
|
||||
|
||||
OBJ := $(BUILD)/tb_mcp_lib.o
|
||||
LIB_SO := $(BUILD)/libtinyblocks-mcp.so
|
||||
PY_HDR := src/tb_mcp_py.h
|
||||
|
||||
.PHONY: all shared clean
|
||||
all: shared
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(PY_HDR): src/tb_mcp.py
|
||||
xxd -i -n tb_mcp_py $< $@
|
||||
|
||||
$(OBJ): src/tb_mcp.c $(PY_HDR) $(PYDIR)/include/tinyblocks-python/tb_python.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ) $(PYBUILD)/libtinyblocks-python.so
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-mcp.so -o $@ $(OBJ) \
|
||||
-L$(PYBUILD) -ltinyblocks-python $(PYTHON_LIBS) \
|
||||
'-Wl,-rpath,$$ORIGIN/../../tinyblocks-python/build'
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD) $(PY_HDR)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library mcp. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-mcp"
|
||||
version = "1.0.0"
|
||||
category = "MCP"
|
||||
description = "Cliente MCP (usa tinyblocks-python)"
|
||||
color = [233, 30, 99, 255]
|
||||
dark = [194, 24, 91, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_mcp.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-mcp.so"
|
||||
static = "build/libtinyblocks-mcp.a"
|
||||
depends = ["tinyblocks-python"]
|
||||
@@ -1,314 +0,0 @@
|
||||
unsigned char tb_mcp_py[] = {
|
||||
0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x0a,
|
||||
0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x6a,
|
||||
0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6d, 0x70,
|
||||
0x6f, 0x72, 0x74, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e, 0x72,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2c, 0x20, 0x75, 0x72, 0x6c, 0x6c,
|
||||
0x69, 0x62, 0x2e, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3d, 0x20, 0x6a,
|
||||
0x73, 0x6f, 0x6e, 0x2e, 0x64, 0x75, 0x6d, 0x70, 0x73, 0x28, 0x7b, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6a, 0x73, 0x6f,
|
||||
0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x20, 0x22, 0x32, 0x2e, 0x30, 0x22,
|
||||
0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69,
|
||||
0x64, 0x22, 0x3a, 0x20, 0x31, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x3a,
|
||||
0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x22, 0x3a, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x7d, 0x29, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x28,
|
||||
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x71, 0x20, 0x3d, 0x20,
|
||||
0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x28, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x75, 0x72, 0x6c, 0x2c,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x61, 0x74,
|
||||
0x61, 0x3d, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65,
|
||||
0x72, 0x73, 0x3d, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
|
||||
0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x61, 0x70,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74,
|
||||
0x22, 0x3a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x61, 0x70,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69,
|
||||
0x62, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x75, 0x72,
|
||||
0x6c, 0x6f, 0x70, 0x65, 0x6e, 0x28, 0x72, 0x65, 0x71, 0x2c, 0x20, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x3d, 0x31, 0x35, 0x29, 0x20, 0x61,
|
||||
0x73, 0x20, 0x72, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20,
|
||||
0x72, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x28, 0x29, 0x2e, 0x64, 0x65, 0x63,
|
||||
0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78,
|
||||
0x63, 0x65, 0x70, 0x74, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x45, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x20, 0x61, 0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
||||
0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b,
|
||||
0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x20, 0x65, 0x2e, 0x63, 0x6f,
|
||||
0x64, 0x65, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x65, 0x2e, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x7d,
|
||||
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74,
|
||||
0x20, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x2d, 0x31, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x3a, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29,
|
||||
0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
|
||||
0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x73, 0x28, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x45, 0x78, 0x63, 0x65, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20,
|
||||
0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x20, 0x2d, 0x32, 0x2c,
|
||||
0x20, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3a, 0x20,
|
||||
0x22, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x4a, 0x53, 0x4f,
|
||||
0x4e, 0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65,
|
||||
0x29, 0x7d, 0x7d, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x73, 0x74,
|
||||
0x64, 0x69, 0x6f, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28,
|
||||
0x63, 0x6d, 0x64, 0x2c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c,
|
||||
0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x73, 0x75, 0x62,
|
||||
0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x63, 0x6d, 0x64, 0x2e, 0x73,
|
||||
0x70, 0x6c, 0x69, 0x74, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74,
|
||||
0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x70, 0x72, 0x6f, 0x63, 0x20, 0x3d, 0x20, 0x73, 0x75, 0x62, 0x70, 0x72,
|
||||
0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e, 0x50, 0x6f, 0x70, 0x65, 0x6e, 0x28,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x69, 0x6e,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x50, 0x49, 0x50, 0x45, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x74,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x50, 0x49, 0x50, 0x45, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x44, 0x45, 0x56, 0x4e, 0x55, 0x4c, 0x4c, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78,
|
||||
0x63, 0x65, 0x70, 0x74, 0x20, 0x46, 0x69, 0x6c, 0x65, 0x4e, 0x6f, 0x74,
|
||||
0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x2d, 0x31, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x3a, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29,
|
||||
0x7d, 0x7d, 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20,
|
||||
0x73, 0x65, 0x6e, 0x64, 0x28, 0x6f, 0x62, 0x6a, 0x29, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20,
|
||||
0x3d, 0x20, 0x28, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64, 0x75, 0x6d, 0x70,
|
||||
0x73, 0x28, 0x6f, 0x62, 0x6a, 0x29, 0x20, 0x2b, 0x20, 0x22, 0x5c, 0x6e,
|
||||
0x22, 0x29, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63,
|
||||
0x2e, 0x73, 0x74, 0x64, 0x69, 0x6e, 0x2e, 0x77, 0x72, 0x69, 0x74, 0x65,
|
||||
0x28, 0x6c, 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x73, 0x74, 0x64, 0x69,
|
||||
0x6e, 0x2e, 0x66, 0x6c, 0x75, 0x73, 0x68, 0x28, 0x29, 0x0a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20, 0x72, 0x65, 0x63, 0x76, 0x28,
|
||||
0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c,
|
||||
0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x73,
|
||||
0x74, 0x64, 0x6f, 0x75, 0x74, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x6c, 0x69,
|
||||
0x6e, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65,
|
||||
0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x7d, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
|
||||
0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x73, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2e, 0x64, 0x65, 0x63, 0x6f, 0x64,
|
||||
0x65, 0x28, 0x29, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x70, 0x28, 0x29, 0x29,
|
||||
0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28,
|
||||
0x7b, 0x22, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22,
|
||||
0x32, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x31, 0x2c,
|
||||
0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x3a, 0x22, 0x69, 0x6e,
|
||||
0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x22, 0x2c, 0x22, 0x70,
|
||||
0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x3a, 0x7b, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x22, 0x3a, 0x22, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x31, 0x31, 0x2d,
|
||||
0x30, 0x35, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69,
|
||||
0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x7d, 0x2c, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x22, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x22,
|
||||
0x3a, 0x7b, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x74, 0x69,
|
||||
0x6e, 0x79, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x2d, 0x6d, 0x63, 0x70,
|
||||
0x22, 0x2c, 0x22, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
|
||||
0x22, 0x31, 0x2e, 0x30, 0x22, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x7d, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x72, 0x65, 0x63, 0x76, 0x28, 0x29, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28, 0x7b,
|
||||
0x22, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22, 0x32,
|
||||
0x2e, 0x30, 0x22, 0x2c, 0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22,
|
||||
0x3a, 0x22, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x2f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69,
|
||||
0x7a, 0x65, 0x64, 0x22, 0x2c, 0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x22, 0x3a, 0x7b, 0x7d, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28, 0x7b, 0x22, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22, 0x32, 0x2e, 0x30, 0x22,
|
||||
0x2c, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x22, 0x3a, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c,
|
||||
0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x3a, 0x70, 0x61, 0x72,
|
||||
0x61, 0x6d, 0x73, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x63,
|
||||
0x76, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x70, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x45,
|
||||
0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20,
|
||||
0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f,
|
||||
0x72, 0x22, 0x3a, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x2d,
|
||||
0x31, 0x2c, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3a,
|
||||
0x73, 0x74, 0x72, 0x28, 0x65, 0x29, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x6c, 0x79, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x74,
|
||||
0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x28, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e,
|
||||
0x77, 0x61, 0x69, 0x74, 0x28, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74,
|
||||
0x3d, 0x33, 0x29, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x64, 0x69,
|
||||
0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x73, 0x77, 0x69,
|
||||
0x74, 0x68, 0x28, 0x22, 0x73, 0x74, 0x64, 0x69, 0x6f, 0x3a, 0x2f, 0x2f,
|
||||
0x22, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x73, 0x74, 0x64, 0x69,
|
||||
0x6f, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28, 0x75, 0x72,
|
||||
0x6c, 0x5b, 0x6c, 0x65, 0x6e, 0x28, 0x22, 0x73, 0x74, 0x64, 0x69, 0x6f,
|
||||
0x3a, 0x2f, 0x2f, 0x22, 0x29, 0x3a, 0x5d, 0x2c, 0x20, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x6a, 0x73, 0x6f, 0x6e,
|
||||
0x72, 0x70, 0x63, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29,
|
||||
0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x6d, 0x63, 0x70, 0x5f, 0x70, 0x69,
|
||||
0x6e, 0x67, 0x28, 0x75, 0x72, 0x6c, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69, 0x73,
|
||||
0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22,
|
||||
0x70, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x20, 0x7b, 0x7d, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72,
|
||||
0x22, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x70, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x3a, 0x20, 0x22, 0x20, 0x2b,
|
||||
0x20, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72,
|
||||
0x22, 0x5d, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x2c, 0x20, 0x73, 0x74, 0x72, 0x28, 0x72, 0x65,
|
||||
0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x29,
|
||||
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
||||
0x20, 0x22, 0x6f, 0x6b, 0x22, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x6d,
|
||||
0x63, 0x70, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x74, 0x6f, 0x6f, 0x6c,
|
||||
0x73, 0x28, 0x75, 0x72, 0x6c, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69, 0x73, 0x70,
|
||||
0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x2c, 0x20,
|
||||
0x7b, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x22,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65,
|
||||
0x73, 0x70, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f,
|
||||
0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2c, 0x20, 0x73,
|
||||
0x74, 0x72, 0x28, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72,
|
||||
0x6f, 0x72, 0x22, 0x5d, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x70,
|
||||
0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
|
||||
0x22, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x70, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73,
|
||||
0x75, 0x6c, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x74, 0x6f, 0x6f,
|
||||
0x6c, 0x73, 0x22, 0x2c, 0x20, 0x5b, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5b, 0x5d, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x73, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x67,
|
||||
0x65, 0x74, 0x28, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x22, 0x3f,
|
||||
0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64,
|
||||
0x65, 0x73, 0x63, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64,
|
||||
0x28, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2b, 0x20, 0x22, 0x3a, 0x20, 0x22,
|
||||
0x20, 0x2b, 0x20, 0x64, 0x65, 0x73, 0x63, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x5c, 0x6e, 0x22,
|
||||
0x2e, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x6f, 0x75, 0x74, 0x29, 0x20, 0x69,
|
||||
0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x22,
|
||||
0x28, 0x6e, 0x65, 0x6e, 0x68, 0x75, 0x6d, 0x61, 0x20, 0x66, 0x65, 0x72,
|
||||
0x72, 0x61, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x29, 0x22, 0x0a, 0x0a, 0x64,
|
||||
0x65, 0x66, 0x20, 0x6d, 0x63, 0x70, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f,
|
||||
0x74, 0x6f, 0x6f, 0x6c, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x74, 0x6f,
|
||||
0x6f, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x72, 0x67,
|
||||
0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x6f,
|
||||
0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x28, 0x61, 0x72, 0x67, 0x73,
|
||||
0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x29, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72,
|
||||
0x67, 0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20,
|
||||
0x61, 0x72, 0x67, 0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x73, 0x74,
|
||||
0x72, 0x69, 0x70, 0x28, 0x29, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x7b,
|
||||
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74,
|
||||
0x20, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72, 0x72,
|
||||
0x6f, 0x3a, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x4a, 0x53, 0x4f, 0x4e,
|
||||
0x20, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x6f, 0x3a, 0x20, 0x22,
|
||||
0x20, 0x2b, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69,
|
||||
0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x22, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x22,
|
||||
0x2c, 0x20, 0x7b, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x20, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x61,
|
||||
0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 0x20, 0x61,
|
||||
0x72, 0x67, 0x73, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66,
|
||||
0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x20, 0x69, 0x6e, 0x20,
|
||||
0x72, 0x65, 0x73, 0x70, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x72, 0x65, 0x73, 0x70,
|
||||
0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x2e, 0x67, 0x65,
|
||||
0x74, 0x28, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2c,
|
||||
0x20, 0x73, 0x74, 0x72, 0x28, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65,
|
||||
0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65,
|
||||
0x73, 0x70, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x72, 0x65, 0x73, 0x75,
|
||||
0x6c, 0x74, 0x22, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x70, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x3d,
|
||||
0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x2c, 0x20, 0x72,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69,
|
||||
0x66, 0x20, 0x69, 0x73, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
|
||||
0x28, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2c, 0x20, 0x6c, 0x69,
|
||||
0x73, 0x74, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x70, 0x61, 0x72, 0x74, 0x73, 0x20, 0x3d, 0x20, 0x5b, 0x5d, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x69, 0x74, 0x65, 0x6d, 0x20, 0x69, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x74, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, 0x69, 0x6e,
|
||||
0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x2c,
|
||||
0x20, 0x64, 0x69, 0x63, 0x74, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x70, 0x61, 0x72, 0x74, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64,
|
||||
0x28, 0x69, 0x74, 0x65, 0x6d, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x74,
|
||||
0x65, 0x78, 0x74, 0x22, 0x2c, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64,
|
||||
0x75, 0x6d, 0x70, 0x73, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x29, 0x29, 0x29,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x65, 0x6c, 0x73, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70,
|
||||
0x61, 0x72, 0x74, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28,
|
||||
0x73, 0x74, 0x72, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x29, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x2e, 0x6a, 0x6f, 0x69, 0x6e, 0x28,
|
||||
0x70, 0x61, 0x72, 0x74, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64,
|
||||
0x75, 0x6d, 0x70, 0x73, 0x28, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
|
||||
0x2c, 0x20, 0x65, 0x6e, 0x73, 0x75, 0x72, 0x65, 0x5f, 0x61, 0x73, 0x63,
|
||||
0x69, 0x69, 0x3d, 0x46, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x20, 0x69, 0x6e,
|
||||
0x64, 0x65, 0x6e, 0x74, 0x3d, 0x32, 0x29, 0x0a
|
||||
};
|
||||
unsigned int tb_mcp_py_len = 3728;
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library operators (categoria "Operadores")
|
||||
# Constroi build/libtinyblocks-operators.a e build/libtinyblocks-operators.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_operators.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-operators.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-operators.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_operators.c include/tb_operators.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library operators. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-operators"
|
||||
version = "1.0.0"
|
||||
category = "Operadores"
|
||||
description = "Logica, comparacao, matematica, texto e literais"
|
||||
color = [89, 192, 89, 255]
|
||||
dark = [56, 148, 56, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_operators.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-operators.so"
|
||||
static = "build/libtinyblocks-operators.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library pen (categoria "Caneta")
|
||||
# Constroi build/libtinyblocks-pen.a e build/libtinyblocks-pen.so
|
||||
# Depende do palco do editor (tb_stage.h); o .so resolve tb_stage_* no host.
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_pen.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-pen.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-pen.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_pen.c include/tb_pen.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library pen. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-pen"
|
||||
version = "1.0.0"
|
||||
category = "Caneta"
|
||||
description = "Desenhe no palco"
|
||||
color = [15, 189, 140, 255]
|
||||
dark = [11, 142, 105, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_pen.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-pen.so"
|
||||
static = "build/libtinyblocks-pen.a"
|
||||
depends = ["tinyblocks-editor"]
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_stage.h"
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include "tb_pen.h"
|
||||
|
||||
static float num(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Makefile da library python (embedding CPython)
|
||||
# Constroi build/libtinyblocks-python.so (soname unico p/ um so interpretador)
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -Iinclude $(PYTHON_CFLAGS)
|
||||
|
||||
OBJ := $(BUILD)/tb_python_lib.o
|
||||
LIB_SO := $(BUILD)/libtinyblocks-python.so
|
||||
|
||||
.PHONY: all shared clean
|
||||
all: shared
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_python.c include/tinyblocks-python/tb_python.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-python.so -o $@ $^ $(PYTHON_LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library python. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-python"
|
||||
version = "1.0.0"
|
||||
category = "Python"
|
||||
description = "Embedding de CPython"
|
||||
color = [255, 215, 0, 255]
|
||||
dark = [255, 193, 7, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_python.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-python.so"
|
||||
static = "build/libtinyblocks-python.a"
|
||||
depends = []
|
||||
@@ -1,30 +1,34 @@
|
||||
CC := gcc
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include \
|
||||
$(shell sdl2-config --cflags)
|
||||
LDFLAGS := $(shell sdl2-config --libs)
|
||||
# Makefile da library sdl2 (backend grafico SDL2)
|
||||
# Constroi build/libtinyblocks-sdl2.a e build/libtinyblocks-sdl2.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
BUILD := ../../build
|
||||
LIB_SO := $(BUILD)/libtinyblocks-sdl2.so
|
||||
LIB_A := $(BUILD)/libtinyblocks-sdl2.a
|
||||
OBJ := $(BUILD)/tb_sdl2.o
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
|
||||
.PHONY: all clean shared static
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -I../tinyblocks-graphics/include -Iinclude \
|
||||
$(SDL2_CFLAGS)
|
||||
LDFLAGS := $(SDL2_LIBS) -lm
|
||||
|
||||
all: shared static
|
||||
OBJ := $(BUILD)/tb_sdl2.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-sdl2.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-sdl2.so
|
||||
|
||||
shared: $(LIB_SO)
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_sdl2.c include/tb_sdl2.h
|
||||
$(OBJ): src/tb_sdl2.c include/tb_sdl2.h ../tinyblocks-graphics/include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c src/tb_sdl2.c -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(LIB_SO) $(LIB_A)
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library sdl2. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-sdl2"
|
||||
version = "1.0.0"
|
||||
category = "SDL2"
|
||||
description = "Backend grafico SDL2"
|
||||
color = [96, 125, 139, 255]
|
||||
dark = [69, 90, 100, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_sdl2.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-sdl2.so"
|
||||
static = "build/libtinyblocks-sdl2.a"
|
||||
depends = ["tinyblocks-graphics"]
|
||||
@@ -0,0 +1,37 @@
|
||||
# Makefile da library toml (parser de TOML + metadados)
|
||||
# Constroi build/libtinyblocks-toml.a e build/libtinyblocks-toml.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJS := $(BUILD)/lexer.o $(BUILD)/parser.o $(BUILD)/tb_toml.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-toml.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-toml.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(BUILD)/lexer.o: src/lexer.c include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/parser.o: src/parser.c include/ast.h include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/tb_toml.o: src/tb_toml.c include/tb_toml.h include/ast.h include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJS)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJS)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -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 */
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library toml. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-toml"
|
||||
version = "1.0.0"
|
||||
category = "TOML"
|
||||
description = "Parser de TOML e metadados de library"
|
||||
color = [158, 112, 219, 255]
|
||||
dark = [125, 51, 178, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/lexer.c", "src/parser.c", "src/tb_toml.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-toml.so"
|
||||
static = "build/libtinyblocks-toml.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* lexer.c: tokenizacao de TOML (subset: chaves, strings, numeros, datas,
|
||||
* arrays, tabelas e tabelas inline).
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "lexeme.h"
|
||||
|
||||
typedef struct {
|
||||
const char* p;
|
||||
int line, col;
|
||||
LexemeList* out;
|
||||
TomlLexError* err;
|
||||
} Lexer;
|
||||
|
||||
static bool is_bare_char(int c) {
|
||||
return isalnum((unsigned char)c) || c == '_' || c == '-';
|
||||
}
|
||||
|
||||
static void adv(Lexer* L) {
|
||||
if (*L->p == '\n') { L->line++; L->col = 1; }
|
||||
else L->col++;
|
||||
L->p++;
|
||||
}
|
||||
|
||||
static bool push(Lexer* L, TomlLexKind kind, const char* start, size_t len) {
|
||||
if (L->out->count >= L->out->cap) {
|
||||
size_t nc = L->out->cap ? L->out->cap * 2 : 64;
|
||||
Lexeme* p = (Lexeme*)realloc(L->out->items, nc * sizeof(Lexeme));
|
||||
if (!p) return false;
|
||||
L->out->items = p; L->out->cap = nc;
|
||||
}
|
||||
Lexeme* t = &L->out->items[L->out->count++];
|
||||
memset(t, 0, sizeof(*t));
|
||||
t->kind = kind;
|
||||
t->start = start;
|
||||
t->len = len;
|
||||
t->line = L->line;
|
||||
t->col = L->col;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fail(Lexer* L, const char* msg) {
|
||||
if (L->err) {
|
||||
L->err->ok = false;
|
||||
snprintf(L->err->msg, sizeof(L->err->msg), "%s", msg);
|
||||
L->err->line = L->line;
|
||||
L->err->col = L->col;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* buffer de texto decodificado */
|
||||
typedef struct { char* p; size_t n, cap; } Buf;
|
||||
|
||||
static bool buf_put(Buf* b, char c) {
|
||||
if (b->n + 1 >= b->cap) {
|
||||
size_t nc = b->cap ? b->cap * 2 : 32;
|
||||
char* p = (char*)realloc(b->p, nc);
|
||||
if (!p) return false;
|
||||
b->p = p; b->cap = nc;
|
||||
}
|
||||
b->p[b->n++] = c;
|
||||
b->p[b->n] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int hexval(int c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool utf8_put(Buf* b, unsigned cp) {
|
||||
if (cp <= 0x7F) return buf_put(b, (char)cp);
|
||||
if (cp <= 0x7FF) {
|
||||
return buf_put(b, (char)(0xC0 | (cp >> 6))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
if (cp <= 0xFFFF) {
|
||||
return buf_put(b, (char)(0xE0 | (cp >> 12))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 6) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
return buf_put(b, (char)(0xF0 | (cp >> 18))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 12) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 6) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
|
||||
/* Le a string basica/literal (single ou multiline). Assume p no delimitador. */
|
||||
static bool lex_string(Lexer* L) {
|
||||
const char* start = L->p;
|
||||
char q = *L->p;
|
||||
bool multi = (L->p[1] == q && L->p[2] == q);
|
||||
Buf b = {0};
|
||||
|
||||
adv(L);
|
||||
if (multi) { adv(L); adv(L); }
|
||||
if (multi && (*L->p == '\r' || *L->p == '\n')) {
|
||||
if (*L->p == '\r' && L->p[1] == '\n') adv(L);
|
||||
adv(L);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
char c = *L->p;
|
||||
if (!c) { free(b.p); return fail(L, "string nao terminada"); }
|
||||
if (multi) {
|
||||
if (c == q && L->p[1] == q && L->p[2] == q) { adv(L); adv(L); adv(L); break; }
|
||||
} else {
|
||||
if (c == q) { adv(L); break; }
|
||||
if (c == '\n') { free(b.p); return fail(L, "quebra de linha em string"); }
|
||||
}
|
||||
if (q == '\'' ) { /* literal: sem escapes */
|
||||
buf_put(&b, c); adv(L); continue;
|
||||
}
|
||||
if (c == '\\') {
|
||||
adv(L);
|
||||
char e = *L->p;
|
||||
if (!multi && (e == '\n' || e == 0)) { free(b.p); return fail(L, "escape invalido"); }
|
||||
switch (e) {
|
||||
case 'b': buf_put(&b, '\b'); adv(L); break;
|
||||
case 't': buf_put(&b, '\t'); adv(L); break;
|
||||
case 'n': buf_put(&b, '\n'); adv(L); break;
|
||||
case 'f': buf_put(&b, '\f'); adv(L); break;
|
||||
case 'r': buf_put(&b, '\r'); adv(L); break;
|
||||
case '"': buf_put(&b, '"'); adv(L); break;
|
||||
case '\\': buf_put(&b, '\\'); adv(L); break;
|
||||
case 'u': case 'U': {
|
||||
int n = (e == 'u') ? 4 : 8;
|
||||
adv(L);
|
||||
unsigned cp = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int h = hexval((unsigned char)*L->p);
|
||||
if (h < 0) { free(b.p); return fail(L, "escape unicode invalido"); }
|
||||
cp = cp * 16 + (unsigned)h; adv(L);
|
||||
}
|
||||
utf8_put(&b, cp);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (multi && (e == '\n' || e == '\r' || e == ' ' || e == '\t')) {
|
||||
/* continua a linha: come a barra e espacos em branco */
|
||||
while (*L->p == ' ' || *L->p == '\t' || *L->p == '\r') adv(L);
|
||||
if (*L->p == '\n') adv(L);
|
||||
while (*L->p == ' ' || *L->p == '\t' || *L->p == '\r' || *L->p == '\n') adv(L);
|
||||
break;
|
||||
}
|
||||
free(b.p); return fail(L, "escape invalido");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
buf_put(&b, c); adv(L);
|
||||
}
|
||||
|
||||
if (!push(L, TL_STRING, start, (size_t)(L->p - start))) { free(b.p); return false; }
|
||||
L->out->items[L->out->count - 1].text = b.p ? b.p : (char*)calloc(1, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tenta casar uma data/hora a partir de p; retorna o tamanho casado. */
|
||||
static size_t scan_datetime(const char* p) {
|
||||
const char* s = p;
|
||||
int digits = 0;
|
||||
while (isdigit((unsigned char)*s)) { s++; digits++; }
|
||||
if (digits == 4 && *s == '-') {
|
||||
const char* d = s + 1; int m = 0;
|
||||
while (isdigit((unsigned char)*d)) { d++; m++; }
|
||||
if (m != 2 || *d != '-') return 0;
|
||||
d++; int dd = 0;
|
||||
while (isdigit((unsigned char)*d)) { d++; dd++; }
|
||||
if (dd != 2) return 0;
|
||||
s = d;
|
||||
if (*s == 'T' || *s == 't' || *s == ' ') {
|
||||
const char* t = s + 1;
|
||||
int h = 0; while (isdigit((unsigned char)*t)) { t++; h++; }
|
||||
if (h == 2 && *t == ':') {
|
||||
t++; int mi = 0; while (isdigit((unsigned char)*t)) { t++; mi++; }
|
||||
if (mi == 2 && *t == ':') {
|
||||
t++; int se = 0; while (isdigit((unsigned char)*t)) { t++; se++; }
|
||||
if (se == 2) {
|
||||
if (*t == '.') { t++; while (isdigit((unsigned char)*t)) t++; }
|
||||
if (*t == 'Z' || *t == 'z') t++;
|
||||
else if ((*t == '+' || *t == '-')) {
|
||||
t++; int hh = 0; while (isdigit((unsigned char)*t)) { t++; hh++; }
|
||||
if (hh == 2 && *t == ':') { t++; int mm = 0; while (isdigit((unsigned char)*t)) { t++; mm++; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
s = t;
|
||||
}
|
||||
return (size_t)(s - p);
|
||||
}
|
||||
if (digits == 2) {
|
||||
const char* t = s;
|
||||
if (*t == ':') {
|
||||
t++; int mi = 0; while (isdigit((unsigned char)*t)) { t++; mi++; }
|
||||
if (mi == 2 && *t == ':') {
|
||||
t++; int se = 0; while (isdigit((unsigned char)*t)) { t++; se++; }
|
||||
if (se == 2) {
|
||||
if (*t == '.') { t++; while (isdigit((unsigned char)*t)) t++; }
|
||||
return (size_t)(t - p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool lex_number(Lexer* L) {
|
||||
const char* start = L->p;
|
||||
size_t dt = scan_datetime(L->p);
|
||||
if (dt) {
|
||||
while ((size_t)(L->p - start) < dt) adv(L);
|
||||
return push(L, TL_DATETIME, start, dt);
|
||||
}
|
||||
|
||||
if (*L->p == '+' || *L->p == '-') adv(L);
|
||||
/* inf / nan */
|
||||
if (strncmp(L->p, "inf", 3) == 0 || strncmp(L->p, "nan", 3) == 0) {
|
||||
adv(L); adv(L); adv(L);
|
||||
Lexeme tok; bool ok = push(L, TL_FLOAT, start, (size_t)(L->p - start));
|
||||
if (!ok) return false;
|
||||
tok = L->out->items[L->out->count - 1];
|
||||
tok.fval = (start[0] == '-') ? -0.0 : 0.0; /* inf/nan: valor 0 */
|
||||
L->out->items[L->out->count - 1] = tok;
|
||||
return true;
|
||||
}
|
||||
bool ishex = (L->p[0] == '0' && (L->p[1] == 'x' || L->p[1] == 'o' || L->p[1] == 'b'));
|
||||
bool isfloat = false;
|
||||
if (ishex) {
|
||||
int base = L->p[1] == 'x' ? 16 : (L->p[1] == 'o' ? 8 : 2);
|
||||
adv(L); adv(L);
|
||||
while (is_bare_char((unsigned char)*L->p) && *L->p != '-') adv(L);
|
||||
char buf[128]; size_t n = (size_t)(L->p - start);
|
||||
if (n >= sizeof(buf)) n = sizeof(buf) - 1;
|
||||
memcpy(buf, start, n); buf[n] = 0;
|
||||
/* remove underscores e prefixo */
|
||||
char clean[128]; size_t cn = 0;
|
||||
for (size_t i = 0; buf[i] && cn < sizeof(clean) - 1; i++)
|
||||
if (buf[i] != '_') clean[cn++] = buf[i];
|
||||
clean[cn] = 0;
|
||||
if (!push(L, TL_INTEGER, start, (size_t)(L->p - start))) return false;
|
||||
L->out->items[L->out->count - 1].ival = strtoll(clean, NULL, base);
|
||||
return true;
|
||||
}
|
||||
while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L);
|
||||
if (*L->p == '.') { isfloat = true; adv(L); while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L); }
|
||||
if (*L->p == 'e' || *L->p == 'E') {
|
||||
isfloat = true; adv(L);
|
||||
if (*L->p == '+' || *L->p == '-') adv(L);
|
||||
while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L);
|
||||
}
|
||||
char buf[128]; size_t n = (size_t)(L->p - start);
|
||||
if (n >= sizeof(buf)) n = sizeof(buf) - 1;
|
||||
memcpy(buf, start, n); buf[n] = 0;
|
||||
char clean[128]; size_t cn = 0;
|
||||
for (size_t i = 0; buf[i] && cn < sizeof(clean) - 1; i++)
|
||||
if (buf[i] != '_') clean[cn++] = buf[i];
|
||||
clean[cn] = 0;
|
||||
if (!push(L, isfloat ? TL_FLOAT : TL_INTEGER, start, (size_t)(L->p - start))) return false;
|
||||
Lexeme* t = &L->out->items[L->out->count - 1];
|
||||
if (isfloat) t->fval = strtod(clean, NULL);
|
||||
else t->ival = strtoll(clean, NULL, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool toml_lex(const char* src, LexemeList* out, TomlLexError* err) {
|
||||
Lexer L = { src, 1, 1, out, err };
|
||||
if (err) { err->ok = true; err->msg[0] = 0; err->line = err->col = 0; }
|
||||
|
||||
for (;;) {
|
||||
char c = *L.p;
|
||||
if (c == 0) { if (!push(&L, TL_EOF, L.p, 0)) return false; break; }
|
||||
if (c == ' ' || c == '\t') { adv(&L); continue; }
|
||||
if (c == '\r') { adv(&L); if (*L.p == '\n') adv(&L); if (!push(&L, TL_NEWLINE, L.p, 0)) return false; continue; }
|
||||
if (c == '\n') { adv(&L); if (!push(&L, TL_NEWLINE, L.p, 0)) return false; continue; }
|
||||
if (c == '#') { while (*L.p && *L.p != '\n') adv(&L); continue; }
|
||||
if (c == '"' || c == '\'') { if (!lex_string(&L)) return false; continue; }
|
||||
switch (c) {
|
||||
case '[': adv(&L); if (!push(&L, TL_LBRACKET, L.p - 1, 1)) return false; continue;
|
||||
case ']': adv(&L); if (!push(&L, TL_RBRACKET, L.p - 1, 1)) return false; continue;
|
||||
case '{': adv(&L); if (!push(&L, TL_LBRACE, L.p - 1, 1)) return false; continue;
|
||||
case '}': adv(&L); if (!push(&L, TL_RBRACE, L.p - 1, 1)) return false; continue;
|
||||
case '=': adv(&L); if (!push(&L, TL_EQUALS, L.p - 1, 1)) return false; continue;
|
||||
case ',': adv(&L); if (!push(&L, TL_COMMA, L.p - 1, 1)) return false; continue;
|
||||
case '.': adv(&L); if (!push(&L, TL_DOT, L.p - 1, 1)) return false; continue;
|
||||
default: break;
|
||||
}
|
||||
if (c == '+' || c == '-' || isdigit((unsigned char)c)) { if (!lex_number(&L)) return false; continue; }
|
||||
if (is_bare_char((unsigned char)c)) {
|
||||
const char* start = L.p;
|
||||
while (is_bare_char((unsigned char)*L.p)) adv(&L);
|
||||
size_t n = (size_t)(L.p - start);
|
||||
TomlLexKind k = TL_BARE;
|
||||
if (n == 4 && strncmp(start, "true", 4) == 0) k = TL_BOOL;
|
||||
else if (n == 5 && strncmp(start, "false", 5) == 0) k = TL_BOOL;
|
||||
else if ((n == 3 && (strncmp(start, "inf", 3) == 0 || strncmp(start, "nan", 3) == 0))) k = TL_FLOAT;
|
||||
if (!push(&L, k, start, n)) return false;
|
||||
Lexeme* t = &L.out->items[L.out->count - 1];
|
||||
if (k == TL_BOOL) t->bval = (start[0] == 't');
|
||||
if (k == TL_FLOAT) t->fval = 0.0;
|
||||
continue;
|
||||
}
|
||||
return fail(&L, "caractere inesperado");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void toml_lexemes_free(LexemeList* list) {
|
||||
if (!list) return;
|
||||
for (size_t i = 0; i < list->count; i++) free(list->items[i].text);
|
||||
free(list->items);
|
||||
list->items = NULL; list->count = list->cap = 0;
|
||||
}
|
||||
|
||||
const char* toml_lexeme_kind_name(TomlLexKind kind) {
|
||||
switch (kind) {
|
||||
case TL_EOF: return "EOF";
|
||||
case TL_ERROR: return "ERROR";
|
||||
case TL_NEWLINE: return "NEWLINE";
|
||||
case TL_LBRACKET: return "[";
|
||||
case TL_RBRACKET: return "]";
|
||||
case TL_LBRACE: return "{";
|
||||
case TL_RBRACE: return "}";
|
||||
case TL_EQUALS: return "=";
|
||||
case TL_COMMA: return ",";
|
||||
case TL_DOT: return ".";
|
||||
case TL_BARE: return "BARE";
|
||||
case TL_STRING: return "STRING";
|
||||
case TL_INTEGER: return "INTEGER";
|
||||
case TL_FLOAT: return "FLOAT";
|
||||
case TL_BOOL: return "BOOL";
|
||||
case TL_DATETIME: return "DATETIME";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* parser.c: parser descendente recursivo de TOML sobre a lista de lexemas.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "ast.h"
|
||||
|
||||
typedef struct {
|
||||
const Lexeme* toks;
|
||||
size_t n, i;
|
||||
TomlValue* root;
|
||||
TomlValue* cur; /* tabela corrente (headers) */
|
||||
TomlLexError* err;
|
||||
} Parser;
|
||||
|
||||
static const Lexeme* peek(Parser* P) { return &P->toks[P->i]; }
|
||||
static const Lexeme* advance(Parser* P) {
|
||||
const Lexeme* t = &P->toks[P->i];
|
||||
if (P->i + 1 < P->n) P->i++;
|
||||
return t;
|
||||
}
|
||||
static bool at(Parser* P, TomlLexKind k) { return peek(P)->kind == k; }
|
||||
static bool accept(Parser* P, TomlLexKind k) {
|
||||
if (!at(P, k)) return false;
|
||||
advance(P);
|
||||
return true;
|
||||
}
|
||||
|
||||
static TomlValue* vnew(TomlValueKind k, int line, int col) {
|
||||
TomlValue* v = (TomlValue*)calloc(1, sizeof(TomlValue));
|
||||
if (!v) return NULL;
|
||||
v->kind = k; v->line = line; v->col = col;
|
||||
return v;
|
||||
}
|
||||
|
||||
static TomlValue* vtable(int line, int col) { return vnew(TOML_TABLE, line, col); }
|
||||
|
||||
static char* dup_range(const char* s, size_t n) {
|
||||
char* p = (char*)malloc(n + 1);
|
||||
if (!p) return NULL;
|
||||
memcpy(p, s, n); p[n] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* chave de um token (bare/string/numero/bool/data) */
|
||||
static char* token_key(const Lexeme* t) {
|
||||
if (t->kind == TL_STRING && t->text) return dup_range(t->text, strlen(t->text));
|
||||
return dup_range(t->start, t->len);
|
||||
}
|
||||
|
||||
static void value_free(TomlValue* v) {
|
||||
if (!v) return;
|
||||
switch (v->kind) {
|
||||
case TOML_STRING: free(v->as.string); break;
|
||||
case TOML_DATETIME: free(v->as.string); break;
|
||||
case TOML_ARRAY:
|
||||
for (size_t i = 0; i < v->as.array.count; i++) value_free(v->as.array.items[i]);
|
||||
free(v->as.array.items);
|
||||
break;
|
||||
case TOML_TABLE: {
|
||||
TomlKeyVal* kv = v->as.table.head;
|
||||
while (kv) { TomlKeyVal* nx = kv->next; free(kv->key); value_free(kv->value); free(kv); kv = nx; }
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
free(v);
|
||||
}
|
||||
|
||||
static TomlKeyVal* table_find(const TomlValue* t, const char* key) {
|
||||
if (!t || t->kind != TOML_TABLE) return NULL;
|
||||
for (TomlKeyVal* kv = t->as.table.head; kv; kv = kv->next)
|
||||
if (strcmp(kv->key, key) == 0) return kv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool table_set(TomlValue* t, char* key, TomlValue* val) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv) {
|
||||
free(key);
|
||||
value_free(kv->value);
|
||||
kv->value = val;
|
||||
return true;
|
||||
}
|
||||
kv = (TomlKeyVal*)calloc(1, sizeof(TomlKeyVal));
|
||||
if (!kv) { free(key); value_free(val); return false; }
|
||||
kv->key = key; kv->value = val;
|
||||
if (t->as.table.tail) t->as.table.tail->next = kv;
|
||||
else t->as.table.head = kv;
|
||||
t->as.table.tail = kv;
|
||||
t->as.table.count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
static TomlValue* table_child(TomlValue* t, const char* key, bool create) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv) {
|
||||
if (kv->value->kind == TOML_TABLE) return kv->value;
|
||||
return NULL;
|
||||
}
|
||||
if (!create) return NULL;
|
||||
TomlValue* child = vtable(t->line, t->col);
|
||||
if (!child) return NULL;
|
||||
if (!table_set(t, dup_range(key, strlen(key)), child)) return NULL;
|
||||
return child;
|
||||
}
|
||||
|
||||
/* [[a.b]]: obtem/cria o array em 't' com a chave, devolve o array */
|
||||
static TomlValue* table_array(TomlValue* t, const char* key) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv && kv->value->kind == TOML_ARRAY) return kv->value;
|
||||
if (kv) return NULL;
|
||||
TomlValue* arr = vnew(TOML_ARRAY, t->line, t->col);
|
||||
if (!arr) return NULL;
|
||||
if (!table_set(t, dup_range(key, strlen(key)), arr)) return NULL;
|
||||
return arr;
|
||||
}
|
||||
|
||||
static bool array_push(TomlValue* arr, TomlValue* v) {
|
||||
if (arr->as.array.count >= arr->as.array.cap) {
|
||||
size_t nc = arr->as.array.cap ? arr->as.array.cap * 2 : 8;
|
||||
TomlValue** p = (TomlValue**)realloc(arr->as.array.items, nc * sizeof(TomlValue*));
|
||||
if (!p) return false;
|
||||
arr->as.array.items = p; arr->as.array.cap = nc;
|
||||
}
|
||||
arr->as.array.items[arr->as.array.count++] = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fail(Parser* P, const Lexeme* t, const char* msg) {
|
||||
if (P->err) {
|
||||
P->err->ok = false;
|
||||
snprintf(P->err->msg, sizeof(P->err->msg), "%s", msg);
|
||||
P->err->line = t->line;
|
||||
P->err->col = t->col;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void skip_newlines(Parser* P) { while (at(P, TL_NEWLINE)) advance(P); }
|
||||
|
||||
/* le uma sequencia de chaves separadas por ponto: a, b.c */
|
||||
#define MAX_KEYS 16
|
||||
static int parse_key_path(Parser* P, char* keys[MAX_KEYS]) {
|
||||
int n = 0;
|
||||
for (;;) {
|
||||
const Lexeme* t = peek(P);
|
||||
if (t->kind != TL_BARE && t->kind != TL_STRING &&
|
||||
t->kind != TL_INTEGER && t->kind != TL_FLOAT &&
|
||||
t->kind != TL_BOOL && t->kind != TL_DATETIME) {
|
||||
fail(P, t, "chave esperada"); return -1;
|
||||
}
|
||||
if (n >= MAX_KEYS) { fail(P, t, "chaves demais"); return -1; }
|
||||
keys[n++] = token_key(t);
|
||||
advance(P);
|
||||
if (!accept(P, TL_DOT)) break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void free_keys(char* keys[], int n) { for (int i = 0; i < n; i++) free(keys[i]); }
|
||||
|
||||
static TomlValue* parse_value(Parser* P);
|
||||
|
||||
static TomlValue* parse_array(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* [ */
|
||||
TomlValue* arr = vnew(TOML_ARRAY, open->line, open->col);
|
||||
if (!arr) return NULL;
|
||||
for (;;) {
|
||||
skip_newlines(P);
|
||||
if (accept(P, TL_RBRACKET)) return arr;
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { value_free(arr); return NULL; }
|
||||
array_push(arr, v);
|
||||
skip_newlines(P);
|
||||
if (accept(P, TL_COMMA)) continue;
|
||||
if (at(P, TL_RBRACKET)) continue;
|
||||
fail(P, peek(P), "esperado , ou ]");
|
||||
value_free(arr); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static TomlValue* parse_inline_table(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* { */
|
||||
TomlValue* t = vtable(open->line, open->col);
|
||||
if (!t) return NULL;
|
||||
for (;;) {
|
||||
if (accept(P, TL_RBRACE)) return t;
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) { value_free(t); return NULL; }
|
||||
if (!accept(P, TL_EQUALS)) {
|
||||
fail(P, peek(P), "esperado =");
|
||||
free_keys(keys, n); value_free(t); return NULL;
|
||||
}
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { free_keys(keys, n); value_free(t); return NULL; }
|
||||
TomlValue* dst = t;
|
||||
for (int j = 0; j < n - 1 && dst; j++) dst = table_child(dst, keys[j], true);
|
||||
if (!dst) { free_keys(keys, n); value_free(v); value_free(t); return NULL; }
|
||||
table_set(dst, keys[n - 1], v); /* consome keys[n-1] */
|
||||
for (int j = 0; j < n - 1; j++) free(keys[j]);
|
||||
if (accept(P, TL_COMMA)) continue;
|
||||
if (at(P, TL_RBRACE)) continue;
|
||||
fail(P, peek(P), "esperado , ou }");
|
||||
value_free(t); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static TomlValue* parse_value(Parser* P) {
|
||||
const Lexeme* t = peek(P);
|
||||
switch (t->kind) {
|
||||
case TL_STRING: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_STRING, t->line, t->col);
|
||||
if (!v) return NULL;
|
||||
v->as.string = dup_range(t->text ? t->text : "", t->text ? strlen(t->text) : 0);
|
||||
return v;
|
||||
}
|
||||
case TL_INTEGER: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_INTEGER, t->line, t->col);
|
||||
if (v) v->as.integer = t->ival;
|
||||
return v;
|
||||
}
|
||||
case TL_FLOAT: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_FLOAT, t->line, t->col);
|
||||
if (v) v->as.real = t->fval;
|
||||
return v;
|
||||
}
|
||||
case TL_BOOL: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_BOOL, t->line, t->col);
|
||||
if (v) v->as.boolean = t->bval;
|
||||
return v;
|
||||
}
|
||||
case TL_DATETIME: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_DATETIME, t->line, t->col);
|
||||
if (v) v->as.string = dup_range(t->start, t->len);
|
||||
return v;
|
||||
}
|
||||
case TL_LBRACKET:
|
||||
return parse_array(P);
|
||||
case TL_LBRACE:
|
||||
return parse_inline_table(P);
|
||||
default:
|
||||
fail(P, t, "valor esperado");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* [a.b] / [[a.b]] */
|
||||
static bool parse_table_header(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* [ */
|
||||
bool array = accept(P, TL_LBRACKET);
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) return false;
|
||||
if (!accept(P, TL_RBRACKET)) { fail(P, peek(P), "esperado ]"); free_keys(keys, n); return false; }
|
||||
if (array && !accept(P, TL_RBRACKET)) { fail(P, peek(P), "esperado ]]"); free_keys(keys, n); return false; }
|
||||
|
||||
TomlValue* t = P->root;
|
||||
for (int j = 0; j < n - 1 && t; j++) t = table_child(t, keys[j], true);
|
||||
if (!t) { free_keys(keys, n); return true; }
|
||||
|
||||
if (array) {
|
||||
TomlValue* arr = table_array(t, keys[n - 1]);
|
||||
if (!arr) { free_keys(keys, n); fail(P, open, "array de tabelas invalido"); return false; }
|
||||
TomlValue* elem = vtable(open->line, open->col);
|
||||
if (!elem) { free_keys(keys, n); return false; }
|
||||
array_push(arr, elem);
|
||||
P->cur = elem;
|
||||
} else {
|
||||
TomlValue* child = table_child(t, keys[n - 1], true);
|
||||
if (!child) { free_keys(keys, n); fail(P, open, "tabela invalida"); return false; }
|
||||
P->cur = child;
|
||||
}
|
||||
free_keys(keys, n);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_keyval(Parser* P) {
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) return false;
|
||||
if (!accept(P, TL_EQUALS)) { fail(P, peek(P), "esperado ="); free_keys(keys, n); return false; }
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { free_keys(keys, n); return false; }
|
||||
TomlValue* dst = P->cur ? P->cur : P->root;
|
||||
for (int j = 0; j < n - 1 && dst; j++) dst = table_child(dst, keys[j], true);
|
||||
if (!dst) { free_keys(keys, n); value_free(v); return false; }
|
||||
table_set(dst, keys[n - 1], v); /* consome keys[n-1] */
|
||||
for (int j = 0; j < n - 1; j++) free(keys[j]);
|
||||
return true;
|
||||
}
|
||||
|
||||
TomlDoc* toml_parse(const char* src, TomlLexError* err) {
|
||||
LexemeList toks = {0};
|
||||
if (!toml_lex(src, &toks, err)) { toml_lexemes_free(&toks); return NULL; }
|
||||
|
||||
Parser P = { toks.items, toks.count, 0, NULL, NULL, err };
|
||||
P.root = vtable(1, 1);
|
||||
P.cur = P.root;
|
||||
if (!P.root) { toml_lexemes_free(&toks); return NULL; }
|
||||
|
||||
bool ok = true;
|
||||
for (;;) {
|
||||
skip_newlines(&P);
|
||||
if (at(&P, TL_EOF)) break;
|
||||
if (at(&P, TL_LBRACKET)) { if (!parse_table_header(&P)) { ok = false; break; } }
|
||||
else { if (!parse_keyval(&P)) { ok = false; break; } }
|
||||
if (!accept(&P, TL_NEWLINE) && !at(&P, TL_EOF)) {
|
||||
fail(&P, peek(&P), "esperado quebra de linha");
|
||||
ok = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
toml_lexemes_free(&toks);
|
||||
if (!ok) { value_free(P.root); return NULL; }
|
||||
TomlDoc* doc = (TomlDoc*)calloc(1, sizeof(TomlDoc));
|
||||
if (!doc) { value_free(P.root); return NULL; }
|
||||
doc->root = P.root;
|
||||
return doc;
|
||||
}
|
||||
|
||||
TomlDoc* toml_parse_file(const char* path, TomlLexError* err) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) {
|
||||
if (err) { err->ok = false; snprintf(err->msg, sizeof(err->msg), "nao abriu %s", path); err->line = err->col = 0; }
|
||||
return NULL;
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
long sz = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (sz < 0 || sz > (long)(64 * 1024 * 1024)) { fclose(f); return NULL; }
|
||||
char* buf = (char*)malloc((size_t)sz + 1);
|
||||
if (!buf) { fclose(f); return NULL; }
|
||||
size_t rd = fread(buf, 1, (size_t)sz, f);
|
||||
buf[rd] = 0;
|
||||
fclose(f);
|
||||
TomlDoc* doc = toml_parse(buf, err);
|
||||
free(buf);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void toml_free(TomlDoc* doc) {
|
||||
if (!doc) return;
|
||||
value_free(doc->root);
|
||||
free(doc);
|
||||
}
|
||||
|
||||
/* -- Navegacao ----------------------------------------------------------- */
|
||||
|
||||
const TomlValue* toml_table_get(const TomlValue* table, const char* key) {
|
||||
TomlKeyVal* kv = table_find(table, key);
|
||||
return kv ? kv->value : NULL;
|
||||
}
|
||||
|
||||
const TomlValue* toml_path_get(const TomlValue* root, const char* dotted) {
|
||||
if (!root || !dotted) return NULL;
|
||||
const TomlValue* t = root;
|
||||
const char* p = dotted;
|
||||
char part[128];
|
||||
while (*p) {
|
||||
size_t n = 0;
|
||||
while (*p && *p != '.' && n < sizeof(part) - 1) part[n++] = *p++;
|
||||
part[n] = 0;
|
||||
if (t && t->kind == TOML_ARRAY) {
|
||||
bool digits = part[0] != 0;
|
||||
for (const char* q = part; *q; q++) if (!isdigit((unsigned char)*q)) digits = false;
|
||||
t = digits ? toml_array_get(t, (size_t)strtoul(part, NULL, 10)) : NULL;
|
||||
} else {
|
||||
t = toml_table_get(t, part);
|
||||
}
|
||||
if (!t) return NULL;
|
||||
if (*p == '.') p++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
const TomlValue* toml_array_get(const TomlValue* arr, size_t i) {
|
||||
if (!arr || arr->kind != TOML_ARRAY || i >= arr->as.array.count) return NULL;
|
||||
return arr->as.array.items[i];
|
||||
}
|
||||
|
||||
size_t toml_array_count(const TomlValue* arr) {
|
||||
return (arr && arr->kind == TOML_ARRAY) ? arr->as.array.count : 0;
|
||||
}
|
||||
|
||||
size_t toml_table_count(const TomlValue* table) {
|
||||
return (table && table->kind == TOML_TABLE) ? table->as.table.count : 0;
|
||||
}
|
||||
|
||||
const TomlKeyVal* toml_table_head(const TomlValue* table) {
|
||||
return (table && table->kind == TOML_TABLE) ? table->as.table.head : NULL;
|
||||
}
|
||||
|
||||
const char* toml_as_string(const TomlValue* v, const char* def) {
|
||||
if (!v) return def;
|
||||
if (v->kind == TOML_STRING || v->kind == TOML_DATETIME) return v->as.string;
|
||||
return def;
|
||||
}
|
||||
long long toml_as_int(const TomlValue* v, long long def) {
|
||||
if (v && v->kind == TOML_INTEGER) return v->as.integer;
|
||||
return def;
|
||||
}
|
||||
double toml_as_float(const TomlValue* v, double def) {
|
||||
if (!v) return def;
|
||||
if (v->kind == TOML_FLOAT) return v->as.real;
|
||||
if (v->kind == TOML_INTEGER) return (double)v->as.integer;
|
||||
return def;
|
||||
}
|
||||
bool toml_as_bool(const TomlValue* v, bool def) {
|
||||
if (v && v->kind == TOML_BOOL) return v->as.boolean;
|
||||
return def;
|
||||
}
|
||||
|
||||
static void indent(int n) { for (int i = 0; i < n; i++) fputs(" ", stdout); }
|
||||
|
||||
void toml_dump(const TomlValue* v, int depth) {
|
||||
if (!v) return;
|
||||
switch (v->kind) {
|
||||
case TOML_STRING: indent(depth); printf("\"%s\"\n", v->as.string); break;
|
||||
case TOML_DATETIME: indent(depth); printf("%s\n", v->as.string); break;
|
||||
case TOML_INTEGER: indent(depth); printf("%lld\n", v->as.integer); break;
|
||||
case TOML_FLOAT: indent(depth); printf("%g\n", v->as.real); break;
|
||||
case TOML_BOOL: indent(depth); printf("%s\n", v->as.boolean ? "true" : "false"); break;
|
||||
case TOML_ARRAY:
|
||||
indent(depth); printf("[\n");
|
||||
for (size_t i = 0; i < v->as.array.count; i++) toml_dump(v->as.array.items[i], depth + 1);
|
||||
indent(depth); printf("]\n");
|
||||
break;
|
||||
case TOML_TABLE:
|
||||
for (TomlKeyVal* kv = v->as.table.head; kv; kv = kv->next) {
|
||||
indent(depth); printf("%s = ", kv->key);
|
||||
if (kv->value->kind == TOML_TABLE || kv->value->kind == TOML_ARRAY) { printf("\n"); toml_dump(kv->value, depth + 1); }
|
||||
else toml_dump(kv->value, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* TinyBlocks - tb_toml.c
|
||||
* Library tinyblocks-toml: registra o bloco Toml.Get e helpers de metadados.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_toml.h"
|
||||
|
||||
#define CAT_COLOR 0.62f, 0.44f, 0.86f, 1.f
|
||||
#define CAT_DARK 0.49f, 0.33f, 0.70f, 1.f
|
||||
|
||||
static const char* value_to_text(const TomlValue* v, char* buf, size_t cap) {
|
||||
if (!v) { buf[0] = 0; return buf; }
|
||||
switch (v->kind) {
|
||||
case TOML_STRING:
|
||||
case TOML_DATETIME: snprintf(buf, cap, "%s", v->as.string ? v->as.string : ""); break;
|
||||
case TOML_INTEGER: snprintf(buf, cap, "%lld", v->as.integer); break;
|
||||
case TOML_FLOAT: snprintf(buf, cap, "%g", v->as.real); break;
|
||||
case TOML_BOOL: snprintf(buf, cap, "%s", v->as.boolean ? "true" : "false"); break;
|
||||
default: buf[0] = 0; break;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void eval_toml_get(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value text = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Value key = tb_block_get_input(self, rt, 1);
|
||||
const char* src = (text.kind == TB_VALUE_TEXT && text.as.text) ? text.as.text : "";
|
||||
const char* dotted = (key.kind == TB_VALUE_TEXT && key.as.text) ? key.as.text : "";
|
||||
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse(src, &err);
|
||||
char out[512] = "";
|
||||
if (doc) {
|
||||
const TomlValue* v = toml_path_get(doc->root, dotted);
|
||||
value_to_text(v, out, sizeof(out));
|
||||
toml_free(doc);
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_text(out));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static bool toml_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_Category cat = { "TOML", {CAT_COLOR}, {CAT_DARK} };
|
||||
tb_library_set_category(lib, &cat);
|
||||
|
||||
static const TinyBlocks_SlotDesc in[] = {{"texto", TB_VALUE_TEXT}, {"chave", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc out[] = {{"valor", TB_VALUE_TEXT}};
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, "Toml.Get", in, 2, out, 1, eval_toml_get);
|
||||
return t && tb_library_add(lib, &t->base);
|
||||
}
|
||||
|
||||
static void toml_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) { (void)rt; (void)lib; }
|
||||
|
||||
TINYBLOCKS_DEFINE_LIBRARY(toml,
|
||||
"tinyblocks-toml",
|
||||
"1.0.0",
|
||||
toml_init,
|
||||
toml_deinit)
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* tb_toml_get_library(void) {
|
||||
return &_tb_lib_desc_toml;
|
||||
}
|
||||
|
||||
const char* tb_toml_file_get(const char* path, const char* dotted, const char* def) {
|
||||
static char buf[256];
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse_file(path, &err);
|
||||
if (!doc) return def;
|
||||
const TomlValue* v = toml_path_get(doc->root, dotted);
|
||||
if (!v) { toml_free(doc); return def; }
|
||||
value_to_text(v, buf, sizeof(buf));
|
||||
toml_free(doc);
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library variables (categoria "Variáveis")
|
||||
# Constroi build/libtinyblocks-variables.a e build/libtinyblocks-variables.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_variables.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-variables.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-variables.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_variables.c include/tb_variables.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library variables. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-variables"
|
||||
version = "1.0.0"
|
||||
category = "Variaveis"
|
||||
description = "Mude, adicione e valor de variavel"
|
||||
color = [255, 140, 26, 255]
|
||||
dark = [219, 110, 0, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_variables.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-variables.so"
|
||||
static = "build/libtinyblocks-variables.a"
|
||||
depends = []
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.c
|
||||
* Palco logico (canvas retido) do runtime: uma tela de 480x360 (origem no
|
||||
* centro, y para cima, como no Scratch) onde blocos de desenho escrevem.
|
||||
*
|
||||
* Os desenhos ficam numa lista retida do runtime, entao qualquer library
|
||||
* (como a Caneta) pode desenhar sem depender do editor. A UI chama
|
||||
* tb_stage_set_view + tb_stage_render para exibir.
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tinyblocks/tb_stage.h"
|
||||
|
||||
#define STAGE_W 480.f
|
||||
#define STAGE_H 360.f
|
||||
#define STAGE_MAX_CMDS 4000
|
||||
#define STAGE_TEXT_FS 14.f
|
||||
|
||||
typedef enum { SC_RECT, SC_CIRCLE, SC_LINE, SC_TEXT } StageCmdKind;
|
||||
|
||||
typedef struct {
|
||||
StageCmdKind kind;
|
||||
float a, b, c, d; /* geometria em coordenadas do palco */
|
||||
float size; /* espessura da caneta */
|
||||
float col[3];
|
||||
char text[96];
|
||||
} StageCmd;
|
||||
|
||||
typedef struct {
|
||||
StageCmd* cmds;
|
||||
int n, cap;
|
||||
float bg[3];
|
||||
float pen[3];
|
||||
float pen_size;
|
||||
float view_w, view_h;
|
||||
} Stage;
|
||||
|
||||
static Stage s_stage = {
|
||||
NULL, 0, 0,
|
||||
{1.f, 1.f, 1.f},
|
||||
{76/255.f, 151/255.f, 1.f},
|
||||
2.f, STAGE_W, STAGE_H
|
||||
};
|
||||
|
||||
static float chan(float v) { return v < 0 ? 0.f : v > 255 ? 1.f : v / 255.f; }
|
||||
|
||||
static StageCmd* push(StageCmdKind kind) {
|
||||
Stage* s = &s_stage;
|
||||
if (s->n >= STAGE_MAX_CMDS) return NULL;
|
||||
if (s->n >= s->cap) {
|
||||
int nc = s->cap ? s->cap * 2 : 64;
|
||||
StageCmd* p = (StageCmd*)realloc(s->cmds, (size_t)nc * sizeof(StageCmd));
|
||||
if (!p) return NULL;
|
||||
s->cmds = p; s->cap = nc;
|
||||
}
|
||||
StageCmd* c = &s->cmds[s->n++];
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->kind = kind;
|
||||
memcpy(c->col, s->pen, sizeof(c->col));
|
||||
c->size = s->pen_size;
|
||||
return c;
|
||||
}
|
||||
|
||||
void tb_stage_clear(void) {
|
||||
s_stage.n = 0;
|
||||
}
|
||||
|
||||
void tb_stage_set_background(float r, float g, float b) {
|
||||
s_stage.bg[0] = chan(r); s_stage.bg[1] = chan(g); s_stage.bg[2] = chan(b);
|
||||
}
|
||||
|
||||
void tb_stage_set_pen(float r, float g, float b) {
|
||||
s_stage.pen[0] = chan(r); s_stage.pen[1] = chan(g); s_stage.pen[2] = chan(b);
|
||||
}
|
||||
|
||||
void tb_stage_set_pen_size(float size) {
|
||||
s_stage.pen_size = size < 1.f ? 1.f : size;
|
||||
}
|
||||
|
||||
void tb_stage_line(float x1, float y1, float x2, float y2) {
|
||||
StageCmd* c = push(SC_LINE);
|
||||
if (c) { c->a = x1; c->b = y1; c->c = x2; c->d = y2; }
|
||||
}
|
||||
|
||||
void tb_stage_rect(float x, float y, float w, float h) {
|
||||
StageCmd* c = push(SC_RECT);
|
||||
if (c) { c->a = x; c->b = y; c->c = w; c->d = h; }
|
||||
}
|
||||
|
||||
void tb_stage_circle(float x, float y, float radius) {
|
||||
StageCmd* c = push(SC_CIRCLE);
|
||||
if (c) { c->a = x; c->b = y; c->c = radius; }
|
||||
}
|
||||
|
||||
void tb_stage_text(const char* text, float x, float y) {
|
||||
StageCmd* c = push(SC_TEXT);
|
||||
if (c) {
|
||||
snprintf(c->text, sizeof(c->text), "%s", text ? text : "");
|
||||
c->a = x; c->b = y;
|
||||
}
|
||||
}
|
||||
|
||||
void tb_stage_set_view(float w, float h) {
|
||||
if (w > 0 && h > 0) { s_stage.view_w = w; s_stage.view_h = h; }
|
||||
}
|
||||
|
||||
void tb_stage_reset(void) {
|
||||
free(s_stage.cmds);
|
||||
s_stage.cmds = NULL; s_stage.n = 0; s_stage.cap = 0;
|
||||
s_stage.bg[0] = s_stage.bg[1] = s_stage.bg[2] = 1.f;
|
||||
s_stage.pen[0] = 76/255.f; s_stage.pen[1] = 151/255.f; s_stage.pen[2] = 1.f;
|
||||
s_stage.pen_size = 2.f;
|
||||
s_stage.view_w = STAGE_W; s_stage.view_h = STAGE_H;
|
||||
}
|
||||
|
||||
bool tb_stage_render(TinyBlocks_RenderableBlock* rb) {
|
||||
if (!rb) return false;
|
||||
Stage* s = &s_stage;
|
||||
|
||||
float sc = s->view_w / STAGE_W < s->view_h / STAGE_H ? s->view_w / STAGE_W : s->view_h / STAGE_H;
|
||||
float ox = (s->view_w - STAGE_W*sc) * 0.5f, oy = (s->view_h - STAGE_H*sc) * 0.5f;
|
||||
#define SX(x) (ox + ((x) + STAGE_W*0.5f) * sc)
|
||||
#define SY(y) (oy + (STAGE_H*0.5f - (y)) * sc)
|
||||
|
||||
if (ox > 0.5f || oy > 0.5f)
|
||||
tb_draw_fill_rect(rb, 0, 0, s->view_w, s->view_h, 0.12f, 0.12f, 0.14f, 1.f);
|
||||
tb_draw_fill_rect(rb, ox, oy, STAGE_W*sc, STAGE_H*sc, s->bg[0], s->bg[1], s->bg[2], 1.f);
|
||||
tb_draw_set_clip(rb, ox, oy, STAGE_W*sc, STAGE_H*sc);
|
||||
|
||||
for (int i = 0; i < s->n && rb->count < TB_DRAW_CMD_CAP - 2; i++) {
|
||||
const StageCmd* c = &s->cmds[i];
|
||||
float r = c->col[0], g = c->col[1], b = c->col[2];
|
||||
switch (c->kind) {
|
||||
case SC_RECT:
|
||||
tb_draw_fill_rect(rb, SX(c->a - c->c*0.5f), SY(c->b + c->d*0.5f),
|
||||
c->c*sc, c->d*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_CIRCLE:
|
||||
tb_draw_fill_circle(rb, SX(c->a), SY(c->b), c->c*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_LINE:
|
||||
tb_draw_stroke_line(rb, SX(c->a), SY(c->b), SX(c->c), SY(c->d),
|
||||
c->size*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_TEXT: {
|
||||
float fs = STAGE_TEXT_FS * sc;
|
||||
tb_draw_text(rb, SX(c->a), SY(c->b) + fs*0.36f, c->text, fs, r, g, b, 1.f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tb_draw_clear_clip(rb);
|
||||
#undef SX
|
||||
#undef SY
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Teste de plugin: prova que um library .so e standalone e cargavel via
|
||||
* dlopen, resolvendo os simbolos do core exportados pelo binario (-rdynamic).
|
||||
*
|
||||
* Uso: plugin_test <caminho.so>
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_block.h>
|
||||
#include <tinyblocks/tb_type_block.h>
|
||||
#include <tinyblocks/tb_library_block.h>
|
||||
|
||||
typedef const TinyBlocks_LibraryDescriptor* (*GetLibFn)(void);
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; } } while (0)
|
||||
|
||||
static TinyBlocks_Block* mk(TinyBlocks* rt, const char* type) {
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_find(rt, type);
|
||||
if (!t) { printf("FAIL tipo %s nao encontrado\n", type); fails++; return NULL; }
|
||||
return tb_block_create(rt, t);
|
||||
}
|
||||
|
||||
static void set_text(TinyBlocks_Block* b, uint32_t i, const char* s) {
|
||||
TinyBlocks_Value v = tb_value_text(s);
|
||||
tb_block_set_default(b, i, v);
|
||||
tb_value_free(&v);
|
||||
}
|
||||
static void set_int(TinyBlocks_Block* b, uint32_t i, int64_t n) {
|
||||
TinyBlocks_Value v = tb_value_integer(n);
|
||||
tb_block_set_default(b, i, v);
|
||||
tb_value_free(&v);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* so = argc > 1 ? argv[1] : "libraries/tinyblocks-fs/build/libtinyblocks-fs.so";
|
||||
char path[256];
|
||||
snprintf(path, sizeof(path), "/tmp/tb_plugin_%d.txt", (int)getpid());
|
||||
unlink(path);
|
||||
|
||||
TinyBlocks* rt = NULL;
|
||||
CHECK(tinyblocks_init(&rt, NULL), "runtime inicializa");
|
||||
|
||||
void* dl = dlopen(so, RTLD_NOW | RTLD_LOCAL);
|
||||
if (!dl) { printf("FAIL dlopen %s: %s\n", so, dlerror()); return 1; }
|
||||
printf("ok dlopen %s\n", so);
|
||||
|
||||
GetLibFn get = (GetLibFn)(uintptr_t)dlsym(dl, "tinyblocks_get_library");
|
||||
CHECK(get != NULL, "simbolo tinyblocks_get_library presente");
|
||||
if (!get) return 1;
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* desc = get();
|
||||
CHECK(desc && desc->name && strstr(desc->name, "fs") != NULL, "descriptor da library");
|
||||
CHECK(tb_library_register(rt, desc) != NULL, "library registra no runtime");
|
||||
|
||||
/* Anexa duas linhas e le de volta. */
|
||||
TinyBlocks_Block* app = mk(rt, "FS.Append");
|
||||
if (app) {
|
||||
set_text(app, 0, path);
|
||||
set_text(app, 1, "linha-1\n");
|
||||
tb_block_eval(app, rt);
|
||||
set_text(app, 1, "linha-2\n");
|
||||
tb_block_eval(app, rt);
|
||||
}
|
||||
|
||||
TinyBlocks_Block* op = mk(rt, "FS.Open");
|
||||
int64_t handle = 0;
|
||||
if (op) {
|
||||
set_text(op, 0, path);
|
||||
tb_block_eval(op, rt);
|
||||
handle = op->outputs[0].as.integer;
|
||||
}
|
||||
CHECK(handle >= 1, "FS.Open devolve handle");
|
||||
|
||||
TinyBlocks_Block* rd = mk(rt, "FS.Read");
|
||||
if (rd) {
|
||||
set_int(rd, 0, handle);
|
||||
set_int(rd, 1, 0);
|
||||
tb_block_eval(rd, rt);
|
||||
const char* got = rd->outputs[0].as.text;
|
||||
CHECK(got && strcmp(got, "linha-1\nlinha-2\n") == 0, "FS.Read le o conteudo");
|
||||
if (got && strcmp(got, "linha-1\nlinha-2\n") != 0) printf(" obtido=[%s]\n", got);
|
||||
}
|
||||
|
||||
TinyBlocks_Block* tl = mk(rt, "FS.Tell");
|
||||
if (tl) {
|
||||
set_int(tl, 0, handle);
|
||||
tb_block_eval(tl, rt);
|
||||
CHECK(tl->outputs[0].as.integer == 16, "FS.Tell reporta 16 bytes");
|
||||
}
|
||||
|
||||
TinyBlocks_Block* cl = mk(rt, "FS.Close");
|
||||
if (cl) { set_int(cl, 0, handle); tb_block_eval(cl, rt); }
|
||||
|
||||
unlink(path);
|
||||
dlclose(dl);
|
||||
tinyblocks_deinit(&rt);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
return fails != 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Teste do parser TOML (tinyblocks-toml): valida contra os library.toml do
|
||||
* repo e alguns casos sintaticos.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
#include <ast.h>
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; } } while (0)
|
||||
|
||||
static void test_library_files(void) {
|
||||
glob_t g;
|
||||
if (glob("libraries/*/library.toml", 0, NULL, &g) != 0) {
|
||||
printf("FAIL nenhum library.toml encontrado\n"); fails++; return;
|
||||
}
|
||||
int n = 0;
|
||||
for (size_t i = 0; i < g.gl_pathc; i++) {
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse_file(g.gl_pathv[i], &err);
|
||||
if (!doc) {
|
||||
printf("FAIL parse %s: %s (%d:%d)\n", g.gl_pathv[i], err.msg, err.line, err.col);
|
||||
fails++; continue;
|
||||
}
|
||||
const char* name = toml_as_string(toml_path_get(doc->root, "library.name"), NULL);
|
||||
const char* cat = toml_as_string(toml_path_get(doc->root, "library.category"), NULL);
|
||||
const char* so = toml_as_string(toml_path_get(doc->root, "build.shared"), NULL);
|
||||
if (!name || !cat || !so) {
|
||||
printf("FAIL metadados incompletos em %s\n", g.gl_pathv[i]);
|
||||
fails++;
|
||||
} else {
|
||||
n++;
|
||||
}
|
||||
toml_free(doc);
|
||||
}
|
||||
globfree(&g);
|
||||
CHECK(n >= 13, "todos os library.toml tem name/category/build.shared");
|
||||
printf(" %d arquivos .toml validados\n", n);
|
||||
}
|
||||
|
||||
static void test_syntax(void) {
|
||||
const char* src =
|
||||
"# comentario\n"
|
||||
"title = \"TOML \\u00e9 \\\"legal\\\"\"\n"
|
||||
"lit = 'C:\\Users\\x'\n"
|
||||
"int = 1_000\n"
|
||||
"hex = 0xDEAD_BEEF\n"
|
||||
"flt = 3.14e2\n"
|
||||
"b = true\n"
|
||||
"arr = [1, 2, 3, \"quatro\"]\n"
|
||||
"date = 1979-05-27T07:32:00Z\n"
|
||||
"dotted.key = \"v\"\n"
|
||||
"inline = { x = 1, y = 2 }\n"
|
||||
"\n"
|
||||
"[servidor]\n"
|
||||
"host = \"localhost\"\n"
|
||||
"porta = 8080\n"
|
||||
"\n"
|
||||
"[[itens]]\n"
|
||||
"nome = \"a\"\n"
|
||||
"[[itens]]\n"
|
||||
"nome = \"b\"\n";
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse(src, &err);
|
||||
CHECK(doc != NULL, "parser aceita TOML variado");
|
||||
if (!doc) { printf(" erro: %s (%d:%d)\n", err.msg, err.line, err.col); return; }
|
||||
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "title"), ""), "TOML \xc3\xa9 \"legal\"") == 0,
|
||||
"string basica com escapes/unicode");
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "lit"), ""), "C:\\Users\\x") == 0,
|
||||
"string literal");
|
||||
CHECK(toml_as_int(toml_path_get(doc->root, "int"), 0) == 1000, "inteiro com underline");
|
||||
CHECK(toml_as_int(toml_path_get(doc->root, "hex"), 0) == 0xDEADBEEF, "inteiro hexadecimal");
|
||||
CHECK(toml_as_float(toml_path_get(doc->root, "flt"), 0) == 314.0, "float com expoente");
|
||||
CHECK(toml_as_bool(toml_path_get(doc->root, "b"), false) == true, "booleano");
|
||||
CHECK(toml_array_count(toml_path_get(doc->root, "arr")) == 4, "array com 4 itens");
|
||||
CHECK(strcmp(toml_as_string(toml_array_get(toml_path_get(doc->root, "arr"), 3), ""), "quatro") == 0,
|
||||
"item de array");
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "date"), ""), "1979-05-27T07:32:00Z") == 0,
|
||||
"data/hora");
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "dotted.key"), ""), "v") == 0,
|
||||
"chave pontuada");
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "servidor.host"), ""), "localhost") == 0,
|
||||
"tabela [servidor]");
|
||||
CHECK(toml_as_int(toml_path_get(doc->root, "servidor.porta"), 0) == 8080, "valor de tabela");
|
||||
CHECK(toml_array_count(toml_path_get(doc->root, "itens")) == 2, "array de tabelas");
|
||||
CHECK(strcmp(toml_as_string(toml_path_get(doc->root, "itens.1.nome"), ""), "b") == 0,
|
||||
"segundo item do array de tabelas");
|
||||
CHECK(toml_as_int(toml_path_get(doc->root, "inline.x"), 0) == 1 &&
|
||||
toml_as_int(toml_path_get(doc->root, "inline.y"), 0) == 2, "tabela inline");
|
||||
toml_free(doc);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_syntax();
|
||||
test_library_files();
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
return fails != 0;
|
||||
}
|
||||
Reference in new issue
Block a user