Skip to content

Сериализация/десериализация ачисел на основе МТС#4

Open
konard wants to merge 6 commits intonetkeep80:mainfrom
konard:issue-3-d3af30f6e279
Open

Сериализация/десериализация ачисел на основе МТС#4
konard wants to merge 6 commits intonetkeep80:mainfrom
konard:issue-3-d3af30f6e279

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 2, 2026

Описание / Summary

Реализация сериализации и десериализации ассоциативных чисел (ачисел) на основе черновика Метатеории связей (МТС), как запрошено в issue #3.

Implementation of associative number (anumber) serialization and deserialization based on the Meta-Theory of Links (MTS) draft specification, as requested in issue #3.

Изменения / Changes

Создано / Created

  1. include/anumber.h — Полная реализация сериализации/десериализации ачисел:

    • EBNF грамматика: anumber = "∞" { abit }; abit = "1" | "-1" | "(" abit_seq ")"; abit_seq = { abit };
    • 4 абита: 1 (наличие связи), -1 (отсутствие связи), ( (начало группы), ) (конец группы)
    • Сериализация: граф rel_t → строка ачисла
    • Десериализация: строка ачисла → граф rel_t
    • Четверичная нотация: -1→0, 1→1, (→2, )→3
    • Токенизатор с поддержкой пробелов и префикса ∞
  2. include/json_io.h — Вынесены функции import_json/export_json в общий заголовочный файл для переиспользования в тестах

  3. test/src/test_anumber.cpp — 20 тестов (65 проверок):

    • Токенизация (с/без ∞, пробелы)
    • Четверичная нотация (roundtrip)
    • Сериализация базовых типов (E, R, True, False)
    • Сериализация строк ("a", "ab"), чисел (42u), массивов ([true,false,true])
    • Вложенные массивы ([[true],[false]])
    • Десериализация и roundtrip
    • Обработка ошибок (непарные скобки)
    • Стабильность двойного roundtrip
  4. experiments/ — Отладочные скрипты для анализа внутренней структуры rel_t

Обновлено / Updated

  1. include/avm.h — Исправлен деструктор base_voc (use-after-free при завершении программы)

  2. src/main.cpp — Рефакторинг: использование json_io.h и anumber.h, вывод ачисла

  3. CMakeLists.txt — Кроссплатформенная сборка, тестовая цель test_anumber с CTest, версия 0.0.0 → 0.0.1

Исправленные баги / Fixed bugs

  • use-after-free в деструкторе base_voc: При завершении программы db->clear() вызывал деструкторы rel_t, которые обращались к картам уже уничтоженных объектов. Исправлено вызовом ptr.release() перед clear().

Тесты / Tests

=== Итоги ===
  Passed: 65
  Failed: 0
ALL TESTS PASSED!

CTest: 1/1 test passed, 100%.

Чеклист / Checklist

  • EBNF грамматика ачисел определена на основе МТС
  • Сериализация rel_t → ачисло
  • Десериализация ачисло → rel_t
  • Четверичная нотация (quaternary)
  • Токенизатор с обработкой ошибок
  • 20 тестов (65 проверок), все проходят
  • CTest интеграция
  • Кроссплатформенная сборка (Linux/Windows)
  • Исправлен use-after-free баг
  • Версия обновлена до 0.0.1

Ссылки / References

Fixes #3


Этот PR был создан с помощью AI issue solver

konard and others added 5 commits February 2, 2026 19:49
Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: netkeep80#3
The base_voc destructor was calling db->clear() which destroyed
unique_ptrs, triggering ~rel_t() destructors that tried to erase
from maps of already-destroyed objects. Now we release() all
unique_ptrs first to prevent destructors from running during
static destruction order.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move JSON import/export functions from main.cpp into include/json_io.h
so they can be reused by test code and other modules. Main.cpp now
includes the shared header instead of defining these functions inline.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add anumber.h with complete implementation of associative number
(ачисло) serialization and deserialization based on the Meta-Theory
of Links (МТС/MTS) draft specification.

Features:
- EBNF grammar: anumber = "∞" { abit }; abit = "1" | "-1" | "(" abit_seq ")"
- 4 abits: 1 (link presence), -1 (link absence), ( (group open), ) (group close)
- Serialization: rel_t graph → anumber string
- Deserialization: anumber string → rel_t graph
- Quaternary notation: -1→0, 1→1, (→2, )→3
- Tokenizer with whitespace tolerance
- 20 test cases (65 assertions) covering roundtrips, edge cases, errors

Updated CMakeLists.txt:
- Cross-platform build (Windows DLL dependency gated by if(WIN32))
- Added test_anumber target with CTest integration
- Version bump 0.0.0 → 0.0.1

Fixes netkeep80#3

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These scripts were used during development to understand the internal
rel_t encoding of strings, numbers, and arrays. Kept for future
reference and debugging.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Необходимо доработать сериализацию/десериализацию ачисел на основе МТС Сериализация/десериализация ачисел на основе МТС Feb 2, 2026
@konard konard marked this pull request as ready for review February 2, 2026 19:08
@konard
Copy link
Contributor Author

konard commented Feb 2, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $8.340853 USD
  • Calculated by Anthropic: $6.480338 USD
  • Difference: $-1.860515 (-22.31%)
    📎 Log file uploaded as Gist (1312KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Feb 2, 2026

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

?? res.json

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

@konard
Copy link
Contributor Author

konard commented Feb 2, 2026

🔄 Auto-restart 1/3 Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.451920 USD
  • Calculated by Anthropic: $0.786703 USD
  • Difference: $-0.665217 (-45.82%)
    📎 Log file uploaded as Gist (1563KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Feb 2, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.451920 USD
  • Calculated by Anthropic: $0.786703 USD
  • Difference: $-0.665217 (-45.82%)
    📎 Log file uploaded as Gist (1567KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Необходимо доработать сериализацию/десериализацию ачисел на основе МТС

1 participant