inkcpp_rb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +84 -0
- data/LICENSE +7 -0
- data/README.md +3 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +10 -0
- data/bin/tapioca +29 -0
- data/ext/inkcpp_rb/extconf.rb +19 -0
- data/ext/inkcpp_rb/inkcpp/.clang-format +99 -0
- data/ext/inkcpp_rb/inkcpp/.github/FUNDING.yml +1 -0
- data/ext/inkcpp_rb/inkcpp/.github/workflows/build.yml +344 -0
- data/ext/inkcpp_rb/inkcpp/.github/workflows/release.yml +49 -0
- data/ext/inkcpp_rb/inkcpp/.gitignore +25 -0
- data/ext/inkcpp_rb/inkcpp/.gitmodules +9 -0
- data/ext/inkcpp_rb/inkcpp/CMakeLists.txt +170 -0
- data/ext/inkcpp_rb/inkcpp/CODE_OF_CONDUCT.md +76 -0
- data/ext/inkcpp_rb/inkcpp/CONTRIBUTING.md +55 -0
- data/ext/inkcpp_rb/inkcpp/Config.cmake.in +2 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/CMakeLists.txt +13 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.c +38 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.cpp +40 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink +8 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink.json +1 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example.zip +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/InkCPP_DEMO.zip +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/CreateThread.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/HandleChoice.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ListElementOf.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalRuntime.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalThread.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ObseverChange.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/TagListGetValue.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/YieldResume.png +0 -0
- data/ext/inkcpp_rb/inkcpp/Doxyfile +2825 -0
- data/ext/inkcpp_rb/inkcpp/LICENSE.txt +22 -0
- data/ext/inkcpp_rb/inkcpp/Minimal.runsettings +8 -0
- data/ext/inkcpp_rb/inkcpp/README.md +192 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/CMakeLists.txt +67 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/array.h +481 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/avl_array.h +833 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/casting.h +93 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/choice.cpp +54 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.cpp +124 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.h +406 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.cpp +52 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.h +34 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/executioner.h +179 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/functional.cpp +86 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/functions.cpp +54 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/functions.h +40 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.cpp +289 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.h +149 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/header.cpp +44 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/choice.h +106 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/functional.h +327 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/globals.h +196 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/list.h +187 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/runner.h +291 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/snapshot.h +61 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/story.h +219 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/story_ptr.h +233 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/traits.h +270 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/include/types.h +169 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.cpp +79 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.h +39 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.cpp +276 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.h +356 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.cpp +841 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.h +450 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.cpp +40 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.h +529 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/operation_bases.h +164 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/operations.h +100 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/output.cpp +528 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/output.h +153 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/platform.h +22 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/random.h +38 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.cpp +1396 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.h +336 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/simple_restorable_stack.h +335 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.cpp +182 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.h +91 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_interface.h +57 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/stack.cpp +618 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/stack.h +243 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.cpp +361 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.h +92 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/story_ptr.cpp +75 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.cpp +125 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.h +67 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.cpp +149 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.h +47 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/string_utils.h +207 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/system.cpp +39 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/tuple.hpp +151 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/value.cpp +279 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp/value.h +666 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/CMakeLists.txt +62 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/include/inkcpp.h +393 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp.cpp +344 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp_c.pc.in +10 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/ExternalFunction.c +56 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Globals.c +98 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Lists.c +73 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c +36 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Snapshot.c +65 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_cl/CMakeLists.txt +49 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_cl/inkcpp_cl.cpp +215 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.cpp +209 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.h +8 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/CMakeLists.txt +37 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.cpp +446 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.h +70 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.cpp +166 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.h +79 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/command.cpp +107 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/compiler.cpp +96 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.cpp +62 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.h +104 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compilation_results.h +22 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compiler.h +44 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json.hpp +24596 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.cpp +411 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.h +62 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.cpp +47 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.h +70 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.cpp +107 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.h +55 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/CMakeLists.txt +19 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/example.py +78 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/src/module.cpp +317 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/conftest.py +53 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_ExternalFunctions.py +35 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Globals.py +40 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Lists.py +43 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Observer.py +27 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Snapshot.py +57 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_py/unreal_example.ink +71 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Array.cpp +115 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/CMakeLists.txt +117 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Callstack.cpp +392 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/EmptyStringForDivert.cpp +36 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ExternalFunctionsExecuteProperly.cpp +34 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/FallbackFunction.cpp +77 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Globals.cpp +73 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/InkyJson.cpp +34 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/LabelCondition.cpp +60 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Lists.cpp +144 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/LookaheadSafe.cpp +46 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Main.cpp +7 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/MoveTo.cpp +95 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/NewLines.cpp +76 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/NoEarlyTags.cpp +33 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Observer.cpp +245 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Pointer.cpp +191 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Restorable.cpp +294 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/SpaceAfterBracketChoice.cpp +45 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Stack.cpp +224 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Tags.cpp +131 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ThirdTierChoiceAfterBrackets.cpp +38 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp +56 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/Value.cpp +210 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/catch.hpp +17970 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/AHF.ink +7 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ChoiceBracketStory.ink +7 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/EmptyStringForDivert.ink +13 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ExternalFunctionsExecuteProperly.ink +11 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/FallBack.ink +15 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/GlobalStory.ink +9 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LabelConditionStory.ink +5 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LinesStory.ink +42 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListLogicStory.ink +40 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListStory.ink +8 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LookaheadSafe.ink +14 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/MoveTo.ink +36 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/NoEarlyTags.ink +19 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ObserverStory.ink +8 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/SimpleStoryFlow.ink +65 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TagsStory.ink +22 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TheIntercept.ink +1686 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ThirdTierChoiceAfterBracketsStory.ink +13 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF-8-demo.txt +212 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF8Story.ink +218 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inklecate.json +154 -0
- data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inky.json +160 -0
- data/ext/inkcpp_rb/inkcpp/notes/ArchitectureNotes.md +54 -0
- data/ext/inkcpp_rb/inkcpp/notes/ListNotes.md +69 -0
- data/ext/inkcpp_rb/inkcpp/notes/OperationNotes.md +35 -0
- data/ext/inkcpp_rb/inkcpp/notes/TagsNotes.md +24 -0
- data/ext/inkcpp_rb/inkcpp/notes/WhitespaceNotes.md +28 -0
- data/ext/inkcpp_rb/inkcpp/proofing/README.md +3 -0
- data/ext/inkcpp_rb/inkcpp/proofing/inkcpp_runtime_driver +12 -0
- data/ext/inkcpp_rb/inkcpp/pyproject.toml +63 -0
- data/ext/inkcpp_rb/inkcpp/setup.py +166 -0
- data/ext/inkcpp_rb/inkcpp/shared/CMakeLists.txt +14 -0
- data/ext/inkcpp_rb/inkcpp/shared/private/command.h +172 -0
- data/ext/inkcpp_rb/inkcpp/shared/private/header.h +46 -0
- data/ext/inkcpp_rb/inkcpp/shared/public/config.h +53 -0
- data/ext/inkcpp_rb/inkcpp/shared/public/system.h +307 -0
- data/ext/inkcpp_rb/inkcpp/shared/public/version.h +14 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestAllSequenceTypes.ink +59 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestArithmetic.ink +17 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestBasicStringLiterals.ink +8 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestBasicTunnel.ink +10 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestBlanksInInlineSequences.ink +51 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestCallStackEvaluation.ink +15 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestChoiceCount.ink +15 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestChoiceDivertsToDone.ink +6 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestChoiceWithBracketsOnly.ink +9 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestCompareDivertTargets.ink +26 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestComplexTunnels.ink +22 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestConditionalChoiceInWeave.ink +19 -0
- data/ext/inkcpp_rb/inkcpp/tests/TestTunnelOnwardsAfterTunnel.ink +17 -0
- data/ext/inkcpp_rb/inkcpp/unreal/CMakeLists.txt +51 -0
- data/ext/inkcpp_rb/inkcpp/unreal/UE_example.ink +92 -0
- data/ext/inkcpp_rb/inkcpp/unreal/blueprint_filter.js +377 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Resources/Icon128.png +0 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkAsset.cpp +47 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkChoice.cpp +40 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkList.cpp +86 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkRuntime.cpp +265 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkThread.cpp +239 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkVar.cpp +143 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/TagList.cpp +95 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/inkcpp.cpp +13 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkAsset.h +50 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkChoice.h +58 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkDelegates.h +139 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkList.h +102 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkRuntime.h +177 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkSnapshot.h +30 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkThread.h +215 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkVar.h +245 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/TagList.h +77 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/inkcpp.h +217 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/inkcpp.Build.cs +62 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.cpp +237 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.h +43 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inkcpp_editor.cpp +13 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inklecate_cmd.cpp.in +24 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Public/inkcpp_editor.h +9 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/inkcpp_editor.Build.cs +61 -0
- data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/inkcpp.uplugin +44 -0
- data/ext/inkcpp_rb/inkcpp/unreal/render.css +1 -0
- data/ext/inkcpp_rb/inkcpp_rb.cpp +321 -0
- data/inkcpp_rb.gemspec +54 -0
- data/rbi/inkcpp_rb.rbi +211 -0
- data/sorbet/config +4 -0
- data/sorbet/rbi/annotations/.gitattributes +1 -0
- data/sorbet/rbi/annotations/minitest.rbi +119 -0
- data/sorbet/rbi/gems/.gitattributes +1 -0
- data/sorbet/rbi/gems/benchmark@0.4.0.rbi +618 -0
- data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
- data/sorbet/rbi/gems/minitest@5.25.4.rbi +1547 -0
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +159 -0
- data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
- data/sorbet/rbi/gems/prism@1.3.0.rbi +40040 -0
- data/sorbet/rbi/gems/rake-compiler@1.2.8.rbi +9 -0
- data/sorbet/rbi/gems/rake@13.2.1.rbi +3033 -0
- data/sorbet/rbi/gems/rbi@0.2.2.rbi +4527 -0
- data/sorbet/rbi/gems/rice@4.3.3.rbi +44 -0
- data/sorbet/rbi/gems/spoom@1.5.0.rbi +4932 -0
- data/sorbet/rbi/gems/tapioca@0.16.7.rbi +3611 -0
- data/sorbet/rbi/gems/thor@1.3.2.rbi +4378 -0
- data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +435 -0
- data/sorbet/rbi/gems/yard@0.9.37.rbi +18379 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +4 -0
- metadata +400 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/* Copyright (c) 2024 Julian Benda
|
|
2
|
+
*
|
|
3
|
+
* This file is part of inkCPP which is released under MIT license.
|
|
4
|
+
* See file LICENSE.txt or go to
|
|
5
|
+
* https://github.com/JBenda/inkcpp for full license details.
|
|
6
|
+
*/
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "value.h"
|
|
10
|
+
#include "system.h"
|
|
11
|
+
#include "output.h"
|
|
12
|
+
#include "stack.h"
|
|
13
|
+
#include "choice.h"
|
|
14
|
+
#include "config.h"
|
|
15
|
+
#include "simple_restorable_stack.h"
|
|
16
|
+
#include "types.h"
|
|
17
|
+
#include "functions.h"
|
|
18
|
+
#include "string_table.h"
|
|
19
|
+
#include "list_table.h"
|
|
20
|
+
#include "array.h"
|
|
21
|
+
#include "random.h"
|
|
22
|
+
#include "snapshot_impl.h"
|
|
23
|
+
|
|
24
|
+
#include "runner.h"
|
|
25
|
+
#include "choice.h"
|
|
26
|
+
|
|
27
|
+
#include "executioner.h"
|
|
28
|
+
|
|
29
|
+
namespace ink::runtime::internal
|
|
30
|
+
{
|
|
31
|
+
class story_impl;
|
|
32
|
+
class globals_impl;
|
|
33
|
+
class snapshot_impl;
|
|
34
|
+
|
|
35
|
+
class runner_impl
|
|
36
|
+
: public runner_interface
|
|
37
|
+
, public snapshot_interface
|
|
38
|
+
{
|
|
39
|
+
public:
|
|
40
|
+
// Creates a new runner at the start of a loaded ink story
|
|
41
|
+
runner_impl(const story_impl*, globals);
|
|
42
|
+
virtual ~runner_impl();
|
|
43
|
+
|
|
44
|
+
// used by the globals object to do garbage collection
|
|
45
|
+
void mark_used(string_table&, list_table&) const;
|
|
46
|
+
|
|
47
|
+
#pragma region runner Implementation
|
|
48
|
+
|
|
49
|
+
// sets seed for prng in runner
|
|
50
|
+
virtual void set_rng_seed(uint32_t seed) override { _rng.srand(seed); }
|
|
51
|
+
|
|
52
|
+
// Checks that the runner can continue
|
|
53
|
+
virtual bool can_continue() const override;
|
|
54
|
+
|
|
55
|
+
// Begin iterating choices
|
|
56
|
+
virtual const choice* begin() const override { return _choices.begin(); }
|
|
57
|
+
|
|
58
|
+
// End iterating choices
|
|
59
|
+
virtual const choice* end() const override { return _choices.end(); }
|
|
60
|
+
|
|
61
|
+
// Chooses a choice by index
|
|
62
|
+
virtual void choose(size_t index) override;
|
|
63
|
+
|
|
64
|
+
/** Continue one line silently.
|
|
65
|
+
* executes story until end of next line and discards the result. */
|
|
66
|
+
void getline_silent();
|
|
67
|
+
|
|
68
|
+
virtual bool has_tags() const override;
|
|
69
|
+
virtual size_t num_tags() const override;
|
|
70
|
+
virtual const char* get_tag(size_t index) const override;
|
|
71
|
+
|
|
72
|
+
snapshot* create_snapshot() const override;
|
|
73
|
+
|
|
74
|
+
size_t snap(unsigned char* data, snapper&) const;
|
|
75
|
+
const unsigned char* snap_load(const unsigned char* data, loader&);
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
#ifdef INK_ENABLE_CSTD
|
|
79
|
+
// c-style getline
|
|
80
|
+
virtual const char* getline_alloc() override;
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
// move to path
|
|
84
|
+
virtual bool move_to(hash_t path) override;
|
|
85
|
+
|
|
86
|
+
#ifdef INK_ENABLE_STL
|
|
87
|
+
// Gets a single line of output and stores it in a C++ std::string
|
|
88
|
+
virtual std::string getline() override;
|
|
89
|
+
|
|
90
|
+
// Reads a line into a std::ostream
|
|
91
|
+
virtual void getline(std::ostream&) override;
|
|
92
|
+
|
|
93
|
+
// get all into string
|
|
94
|
+
virtual std::string getall() override;
|
|
95
|
+
|
|
96
|
+
// get all into stream
|
|
97
|
+
virtual void getall(std::ostream&) override;
|
|
98
|
+
#endif
|
|
99
|
+
#ifdef INK_ENABLE_UNREAL
|
|
100
|
+
// Reads a line into an Unreal FString
|
|
101
|
+
virtual FString getline() override;
|
|
102
|
+
#endif
|
|
103
|
+
#pragma endregion
|
|
104
|
+
|
|
105
|
+
protected:
|
|
106
|
+
// bind external
|
|
107
|
+
virtual void internal_bind(hash_t name, internal::function_base* function) override;
|
|
108
|
+
|
|
109
|
+
private:
|
|
110
|
+
// Advances the interpreter by a line. This fills the output buffer
|
|
111
|
+
void advance_line();
|
|
112
|
+
|
|
113
|
+
// Steps the interpreter a single instruction and returns
|
|
114
|
+
// when it has hit a new line
|
|
115
|
+
bool line_step();
|
|
116
|
+
|
|
117
|
+
// Steps the interpreter a single instruction
|
|
118
|
+
void step();
|
|
119
|
+
|
|
120
|
+
// Resets the runtime
|
|
121
|
+
void reset();
|
|
122
|
+
|
|
123
|
+
// == Save/Restore
|
|
124
|
+
void save();
|
|
125
|
+
void restore();
|
|
126
|
+
void forget();
|
|
127
|
+
|
|
128
|
+
enum class Scope {
|
|
129
|
+
NONE,
|
|
130
|
+
GLOBAL,
|
|
131
|
+
LOCAL
|
|
132
|
+
};
|
|
133
|
+
template<Scope Hint = Scope::NONE>
|
|
134
|
+
value* get_var(hash_t variableName);
|
|
135
|
+
template<Scope Hint = Scope::NONE>
|
|
136
|
+
const value* get_var(hash_t variableName) const;
|
|
137
|
+
template<Scope Hint = Scope::NONE>
|
|
138
|
+
void set_var(hash_t variableName, const value& val, bool is_redef);
|
|
139
|
+
const value* dereference(const value& val);
|
|
140
|
+
|
|
141
|
+
enum class change_type {
|
|
142
|
+
no_change,
|
|
143
|
+
extended_past_newline,
|
|
144
|
+
newline_removed
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
change_type detect_change() const;
|
|
148
|
+
|
|
149
|
+
private:
|
|
150
|
+
template<typename T>
|
|
151
|
+
inline T read();
|
|
152
|
+
|
|
153
|
+
choice& add_choice();
|
|
154
|
+
void clear_choices();
|
|
155
|
+
|
|
156
|
+
void clear_tags();
|
|
157
|
+
|
|
158
|
+
// Special code for jumping from the current IP to another
|
|
159
|
+
void jump(ip_t, bool record_visits);
|
|
160
|
+
|
|
161
|
+
void run_binary_operator(unsigned char cmd);
|
|
162
|
+
void run_unary_operator(unsigned char cmd);
|
|
163
|
+
|
|
164
|
+
frame_type execute_return();
|
|
165
|
+
template<frame_type type>
|
|
166
|
+
void start_frame(uint32_t target);
|
|
167
|
+
|
|
168
|
+
void on_done(bool setDone);
|
|
169
|
+
void set_done_ptr(ip_t ptr);
|
|
170
|
+
|
|
171
|
+
inline thread_t current_thread() const { return _threads.empty() ? ~0 : _threads.top(); }
|
|
172
|
+
|
|
173
|
+
public:
|
|
174
|
+
template<bool dynamic, size_t N>
|
|
175
|
+
class threads : public internal::managed_restorable_stack<thread_t, dynamic, N>
|
|
176
|
+
{
|
|
177
|
+
using base = internal::managed_restorable_stack<thread_t, dynamic, N>;
|
|
178
|
+
|
|
179
|
+
public:
|
|
180
|
+
template<bool... D, bool con = dynamic, enable_if_t<con, bool> = true>
|
|
181
|
+
threads()
|
|
182
|
+
: base(~0)
|
|
183
|
+
, _threadDone(nullptr, reinterpret_cast<ip_t>(~0))
|
|
184
|
+
{
|
|
185
|
+
static_assert(sizeof...(D) == 0, "Don't use explicit template arguments!");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
template<bool... D, bool con = dynamic, enable_if_t<! con, bool> = true>
|
|
189
|
+
threads()
|
|
190
|
+
: base(~0)
|
|
191
|
+
, _threadDone(nullptr, reinterpret_cast<ip_t>(~0))
|
|
192
|
+
{
|
|
193
|
+
static_assert(sizeof...(D) == 0, "Don't use explicit template arguments");
|
|
194
|
+
_threadDone.clear(nullptr);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
void clear()
|
|
198
|
+
{
|
|
199
|
+
base::clear();
|
|
200
|
+
_threadDone.clear(nullptr);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
void save()
|
|
204
|
+
{
|
|
205
|
+
base::save();
|
|
206
|
+
_threadDone.save();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
void restore()
|
|
210
|
+
{
|
|
211
|
+
base::restore();
|
|
212
|
+
_threadDone.restore();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void forget()
|
|
216
|
+
{
|
|
217
|
+
base::forget();
|
|
218
|
+
_threadDone.forget();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
void set(size_t index, const ip_t& value) { _threadDone.set(index, value); }
|
|
222
|
+
|
|
223
|
+
const ip_t& get(size_t index) const { return _threadDone.get(index); }
|
|
224
|
+
|
|
225
|
+
const ip_t& operator[](size_t index) const { return get(index); }
|
|
226
|
+
|
|
227
|
+
// snapshot interface
|
|
228
|
+
size_t snap(unsigned char* data, const snapper&) const override;
|
|
229
|
+
const unsigned char* snap_load(const unsigned char* data, const loader&) override;
|
|
230
|
+
|
|
231
|
+
protected:
|
|
232
|
+
virtual void overflow(thread_t*& buffer, size_t& size) override final;
|
|
233
|
+
|
|
234
|
+
private:
|
|
235
|
+
using array_type = if_t<
|
|
236
|
+
dynamic, internal::allocated_restorable_array<ip_t>,
|
|
237
|
+
internal::fixed_restorable_array<ip_t, N>>;
|
|
238
|
+
|
|
239
|
+
void resize(size_t size, int) { _threadDone.resize(size); }
|
|
240
|
+
|
|
241
|
+
array_type _threadDone;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
private:
|
|
245
|
+
const story_impl* const _story;
|
|
246
|
+
story_ptr<globals_impl> _globals;
|
|
247
|
+
executer _operations;
|
|
248
|
+
|
|
249
|
+
// == State ==
|
|
250
|
+
|
|
251
|
+
// Instruction pointer
|
|
252
|
+
ip_t _ptr;
|
|
253
|
+
ip_t _backup; // backup pointer
|
|
254
|
+
ip_t _done; // when we last hit a done
|
|
255
|
+
|
|
256
|
+
// Output stream
|
|
257
|
+
internal::stream<config::limitOutputSize> _output;
|
|
258
|
+
|
|
259
|
+
// Runtime stack. Used to store temporary variables and callstack
|
|
260
|
+
internal::stack < abs(config::limitRuntimeStack), config::limitRuntimeStack<0> _stack;
|
|
261
|
+
internal::stack < abs(config::limitReferenceStack), config::limitReferenceStack<0> _ref_stack;
|
|
262
|
+
|
|
263
|
+
// Evaluation stack
|
|
264
|
+
bool _evaluation_mode = false;
|
|
265
|
+
bool _string_mode = false;
|
|
266
|
+
internal::eval_stack < abs(config::limitEvalStackDepth), config::limitEvalStackDepth<0> _eval;
|
|
267
|
+
bool _saved_evaluation_mode = false;
|
|
268
|
+
|
|
269
|
+
// Keeps track of what threads we're inside
|
|
270
|
+
threads < config::limitContainerDepth<0, abs(config::limitThreadDepth)> _threads;
|
|
271
|
+
|
|
272
|
+
// Choice list
|
|
273
|
+
managed_restorable_array < snap_choice, config::maxChoices<0, abs(config::maxChoices)> _choices;
|
|
274
|
+
optional<snap_choice> _fallback_choice;
|
|
275
|
+
|
|
276
|
+
// Tag list
|
|
277
|
+
managed_restorable_array < snap_tag,
|
|
278
|
+
config::limitActiveTags<0, abs(config::limitActiveTags)> _tags;
|
|
279
|
+
int _choice_tags_begin;
|
|
280
|
+
|
|
281
|
+
// TODO: Move to story? Both?
|
|
282
|
+
functions _functions;
|
|
283
|
+
|
|
284
|
+
// Container set
|
|
285
|
+
struct ContainerData {
|
|
286
|
+
container_t id = ~0u;
|
|
287
|
+
ip_t offset = 0;
|
|
288
|
+
|
|
289
|
+
bool operator==(const ContainerData& oth) const { return oth.id == id && oth.offset == offset; }
|
|
290
|
+
|
|
291
|
+
bool operator!=(const ContainerData& oth) const { return ! (*this == oth); }
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
internal::managed_restorable_stack < ContainerData,
|
|
295
|
+
config::limitContainerDepth<0, abs(config::limitContainerDepth)> _container;
|
|
296
|
+
bool _is_falling = false;
|
|
297
|
+
|
|
298
|
+
bool _saved = false;
|
|
299
|
+
|
|
300
|
+
prng _rng;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
template<bool dynamic, size_t N>
|
|
304
|
+
void runner_impl::threads<dynamic, N>::overflow(thread_t*& buffer, size_t& size)
|
|
305
|
+
{
|
|
306
|
+
base::overflow(buffer, size);
|
|
307
|
+
if constexpr (dynamic) {
|
|
308
|
+
resize(size, 0);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
template<bool dynamic, size_t N>
|
|
313
|
+
size_t runner_impl::threads<dynamic, N>::snap(unsigned char* data, const snapper& snapper) const
|
|
314
|
+
{
|
|
315
|
+
unsigned char* ptr = data;
|
|
316
|
+
ptr += base::snap(data ? ptr : nullptr, snapper);
|
|
317
|
+
ptr += _threadDone.snap(data ? ptr : nullptr, snapper);
|
|
318
|
+
return ptr - data;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
template<bool dynamic, size_t N>
|
|
322
|
+
const unsigned char*
|
|
323
|
+
runner_impl::threads<dynamic, N>::snap_load(const unsigned char* ptr, const loader& loader)
|
|
324
|
+
{
|
|
325
|
+
ptr = base::snap_load(ptr, loader);
|
|
326
|
+
ptr = _threadDone.snap_load(ptr, loader);
|
|
327
|
+
return ptr;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
template<>
|
|
331
|
+
inline const char* runner_impl::read();
|
|
332
|
+
|
|
333
|
+
#ifdef INK_ENABLE_STL
|
|
334
|
+
std::ostream& operator<<(std::ostream&, runner_impl&);
|
|
335
|
+
#endif
|
|
336
|
+
} // namespace ink::runtime::internal
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/* Copyright (c) 2024 Julian Benda
|
|
2
|
+
*
|
|
3
|
+
* This file is part of inkCPP which is released under MIT license.
|
|
4
|
+
* See file LICENSE.txt or go to
|
|
5
|
+
* https://github.com/JBenda/inkcpp for full license details.
|
|
6
|
+
*/
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "system.h"
|
|
10
|
+
#include "array.h"
|
|
11
|
+
#include "snapshot_impl.h"
|
|
12
|
+
|
|
13
|
+
namespace ink::runtime::internal
|
|
14
|
+
{
|
|
15
|
+
/// only use this type for simple objects with simple copy operator and no heap references
|
|
16
|
+
/// because they will may be serialized, stored and loaded in a different instance
|
|
17
|
+
template<typename T>
|
|
18
|
+
class simple_restorable_stack : public snapshot_interface
|
|
19
|
+
{
|
|
20
|
+
public:
|
|
21
|
+
simple_restorable_stack(T* buffer, size_t size, const T& null)
|
|
22
|
+
: _buffer(buffer)
|
|
23
|
+
, _size(size)
|
|
24
|
+
, _null(null)
|
|
25
|
+
{
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
virtual ~simple_restorable_stack() = default;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
void push(const T& value);
|
|
32
|
+
T pop();
|
|
33
|
+
const T& top() const;
|
|
34
|
+
|
|
35
|
+
size_t size() const;
|
|
36
|
+
bool empty() const;
|
|
37
|
+
void clear();
|
|
38
|
+
|
|
39
|
+
bool iter(const T*& iterator) const;
|
|
40
|
+
bool rev_iter(const T*& iterator) const;
|
|
41
|
+
|
|
42
|
+
// == Save/Restore ==
|
|
43
|
+
void save();
|
|
44
|
+
void restore();
|
|
45
|
+
void forget();
|
|
46
|
+
|
|
47
|
+
virtual size_t snap(unsigned char* data, const snapper&) const;
|
|
48
|
+
virtual const unsigned char* snap_load(const unsigned char* data, const loader&);
|
|
49
|
+
|
|
50
|
+
protected:
|
|
51
|
+
virtual void overflow(T*& buffer, size_t& size) { inkFail("Stack overflow!"); }
|
|
52
|
+
|
|
53
|
+
void initialize_data(T* buffer, size_t size)
|
|
54
|
+
{
|
|
55
|
+
inkAssert(
|
|
56
|
+
_buffer == nullptr && _size == 0,
|
|
57
|
+
"Try to double initialize a restorable stack."
|
|
58
|
+
"To extend the size use overflow()"
|
|
59
|
+
);
|
|
60
|
+
_buffer = buffer;
|
|
61
|
+
_size = size;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private:
|
|
65
|
+
T* _buffer;
|
|
66
|
+
size_t _size;
|
|
67
|
+
const T _null;
|
|
68
|
+
|
|
69
|
+
const static size_t InvalidIndex = ~0;
|
|
70
|
+
|
|
71
|
+
size_t _pos = 0;
|
|
72
|
+
size_t _save = InvalidIndex, _jump = InvalidIndex;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
template<typename T, bool dynamic, size_t N>
|
|
76
|
+
class managed_restorable_stack : public simple_restorable_stack<T>
|
|
77
|
+
{
|
|
78
|
+
using base = simple_restorable_stack<T>;
|
|
79
|
+
|
|
80
|
+
public:
|
|
81
|
+
template<bool... D, bool con = dynamic, enable_if_t<con, bool> = true>
|
|
82
|
+
managed_restorable_stack(const T& null)
|
|
83
|
+
: simple_restorable_stack<T>(nullptr, 0, null)
|
|
84
|
+
{
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
template<bool... D, bool con = dynamic, enable_if_t<! con, bool> = true>
|
|
88
|
+
managed_restorable_stack(const T& null)
|
|
89
|
+
: simple_restorable_stack<T>(nullptr, 0, null)
|
|
90
|
+
, _stack{}
|
|
91
|
+
{
|
|
92
|
+
base::initialize_data(_stack.data(), N);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
virtual void overflow(T*& buffer, size_t& size) override
|
|
96
|
+
{
|
|
97
|
+
if constexpr (dynamic) {
|
|
98
|
+
if (buffer) {
|
|
99
|
+
_stack.extend();
|
|
100
|
+
}
|
|
101
|
+
buffer = _stack.data();
|
|
102
|
+
size = _stack.capacity();
|
|
103
|
+
} else {
|
|
104
|
+
base::overflow(buffer, size);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private:
|
|
109
|
+
managed_array<T, dynamic, N> _stack;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
template<typename T>
|
|
113
|
+
inline void simple_restorable_stack<T>::push(const T& value)
|
|
114
|
+
{
|
|
115
|
+
inkAssert(value != _null, "Can not push a 'null' value onto the stack.");
|
|
116
|
+
|
|
117
|
+
// Don't overwrite saved data. Jump over it and record where we jumped from
|
|
118
|
+
if (_save != InvalidIndex && _pos < _save) {
|
|
119
|
+
_jump = _pos;
|
|
120
|
+
_pos = _save;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (_pos >= _size) {
|
|
124
|
+
overflow(_buffer, _size);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Push onto the top of the stack
|
|
128
|
+
_buffer[_pos++] = value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
template<typename T>
|
|
132
|
+
inline T simple_restorable_stack<T>::pop()
|
|
133
|
+
{
|
|
134
|
+
inkAssert(_pos > 0, "Nothing left to pop!");
|
|
135
|
+
|
|
136
|
+
// Move over jump area
|
|
137
|
+
if (_pos == _save) {
|
|
138
|
+
_pos = _jump;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Decrement and return
|
|
142
|
+
return _buffer[--_pos];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
template<typename T>
|
|
146
|
+
inline const T& simple_restorable_stack<T>::top() const
|
|
147
|
+
{
|
|
148
|
+
if (_pos == _save) {
|
|
149
|
+
inkAssert(_jump > 0, "Stack is empty! No top()");
|
|
150
|
+
return _buffer[_jump - 1];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
inkAssert(_pos > 0, "Stack is empty! No top()");
|
|
154
|
+
return _buffer[_pos - 1];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
template<typename T>
|
|
158
|
+
inline size_t simple_restorable_stack<T>::size() const
|
|
159
|
+
{
|
|
160
|
+
// If we're past the save point, ignore anything in the jump region
|
|
161
|
+
if (_pos >= _save)
|
|
162
|
+
return _pos - (_save - _jump);
|
|
163
|
+
|
|
164
|
+
// Otherwise, pos == size
|
|
165
|
+
return _pos;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
template<typename T>
|
|
169
|
+
inline bool simple_restorable_stack<T>::empty() const
|
|
170
|
+
{
|
|
171
|
+
return size() == 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
template<typename T>
|
|
175
|
+
inline void simple_restorable_stack<T>::clear()
|
|
176
|
+
{
|
|
177
|
+
// Reset to start
|
|
178
|
+
_save = _jump = InvalidIndex;
|
|
179
|
+
_pos = 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
template<typename T>
|
|
183
|
+
inline bool simple_restorable_stack<T>::iter(const T*& iterator) const
|
|
184
|
+
{
|
|
185
|
+
// If empty, nothing to iterate
|
|
186
|
+
if (_pos == 0)
|
|
187
|
+
return false;
|
|
188
|
+
|
|
189
|
+
// Begin at the top of the stack
|
|
190
|
+
if (iterator == nullptr || iterator < _buffer || iterator > _buffer + _pos) {
|
|
191
|
+
if (_pos == _save) {
|
|
192
|
+
if (_jump == 0) {
|
|
193
|
+
iterator = nullptr;
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
iterator = _buffer + _jump - 1;
|
|
197
|
+
} else {
|
|
198
|
+
iterator = _buffer + _pos - 1;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Move over stored data
|
|
204
|
+
if (iterator == _buffer + _save)
|
|
205
|
+
iterator = _buffer + _jump;
|
|
206
|
+
|
|
207
|
+
// Run backwards
|
|
208
|
+
iterator--;
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
// End
|
|
212
|
+
if (iterator < _buffer) {
|
|
213
|
+
iterator = nullptr;
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
template<typename T>
|
|
221
|
+
inline bool simple_restorable_stack<T>::rev_iter(const T*& iterator) const
|
|
222
|
+
{
|
|
223
|
+
if (_pos == 0)
|
|
224
|
+
return false;
|
|
225
|
+
if (iterator == nullptr || iterator < _buffer || iterator > _buffer + _pos) {
|
|
226
|
+
if (_jump == 0) {
|
|
227
|
+
if (_save == _pos) {
|
|
228
|
+
iterator = nullptr;
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
iterator = _buffer + _save;
|
|
232
|
+
} else {
|
|
233
|
+
iterator = _buffer;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
++iterator;
|
|
238
|
+
if (iterator == _buffer + _jump) {
|
|
239
|
+
iterator = _buffer + _save;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (iterator == _buffer + _pos) {
|
|
243
|
+
iterator = nullptr;
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
template<typename T>
|
|
250
|
+
inline void simple_restorable_stack<T>::save()
|
|
251
|
+
{
|
|
252
|
+
inkAssert(_save == InvalidIndex, "Can not save stack twice! restore() or forget() first");
|
|
253
|
+
|
|
254
|
+
// Save current stack position
|
|
255
|
+
_save = _jump = _pos;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
template<typename T>
|
|
259
|
+
inline void simple_restorable_stack<T>::restore()
|
|
260
|
+
{
|
|
261
|
+
inkAssert(_save != InvalidIndex, "Can not restore() when there is no save!");
|
|
262
|
+
|
|
263
|
+
// Move position back to saved position
|
|
264
|
+
_pos = _save;
|
|
265
|
+
_save = _jump = InvalidIndex;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
template<typename T>
|
|
269
|
+
inline void simple_restorable_stack<T>::forget()
|
|
270
|
+
{
|
|
271
|
+
inkAssert(_save != InvalidIndex, "Can not forget when the stack has never been saved!");
|
|
272
|
+
|
|
273
|
+
inkAssert(_pos >= _save || _pos < _jump, "Pos is in backup areal! (should be impossible)");
|
|
274
|
+
// if we are below the backup areal, no changes are needed
|
|
275
|
+
// if we above the backup areal, we need to collpse it
|
|
276
|
+
if (_pos >= _save) {
|
|
277
|
+
size_t delta = _save - _jump;
|
|
278
|
+
for (size_t i = _save; i < _pos; ++i) {
|
|
279
|
+
_buffer[i - delta] = _buffer[i];
|
|
280
|
+
}
|
|
281
|
+
_pos -= delta;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Just reset save position
|
|
285
|
+
_save = _jump = InvalidIndex;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
template<typename T>
|
|
289
|
+
size_t simple_restorable_stack<T>::snap(unsigned char* data, const snapper&) const
|
|
290
|
+
{
|
|
291
|
+
unsigned char* ptr = data;
|
|
292
|
+
bool should_write = data != nullptr;
|
|
293
|
+
ptr = snap_write(ptr, _null, should_write);
|
|
294
|
+
ptr = snap_write(ptr, _pos, should_write);
|
|
295
|
+
ptr = snap_write(ptr, _save, should_write);
|
|
296
|
+
ptr = snap_write(ptr, _jump, should_write);
|
|
297
|
+
size_t max = _pos;
|
|
298
|
+
if (_save != InvalidIndex && _save > max) {
|
|
299
|
+
max = _save;
|
|
300
|
+
}
|
|
301
|
+
if (_jump != InvalidIndex && _jump > max) {
|
|
302
|
+
max = _jump;
|
|
303
|
+
}
|
|
304
|
+
for (size_t i = 0; i < max; ++i) {
|
|
305
|
+
ptr = snap_write(ptr, _buffer[i], should_write);
|
|
306
|
+
}
|
|
307
|
+
return ptr - data;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
template<typename T>
|
|
311
|
+
const unsigned char*
|
|
312
|
+
simple_restorable_stack<T>::snap_load(const unsigned char* ptr, const loader& loader)
|
|
313
|
+
{
|
|
314
|
+
T null;
|
|
315
|
+
ptr = snap_read(ptr, null);
|
|
316
|
+
inkAssert(null == _null, "different null value compared to snapshot!");
|
|
317
|
+
ptr = snap_read(ptr, _pos);
|
|
318
|
+
ptr = snap_read(ptr, _save);
|
|
319
|
+
ptr = snap_read(ptr, _jump);
|
|
320
|
+
size_t max = _pos;
|
|
321
|
+
if (_save != InvalidIndex && _save > max) {
|
|
322
|
+
max = _save;
|
|
323
|
+
}
|
|
324
|
+
if (_jump != InvalidIndex && _jump > max) {
|
|
325
|
+
max = _jump;
|
|
326
|
+
}
|
|
327
|
+
while (_size < max) {
|
|
328
|
+
overflow(_buffer, _size);
|
|
329
|
+
}
|
|
330
|
+
for (size_t i = 0; i < max; ++i) {
|
|
331
|
+
ptr = snap_read(ptr, _buffer[i]);
|
|
332
|
+
}
|
|
333
|
+
return ptr;
|
|
334
|
+
}
|
|
335
|
+
} // namespace ink::runtime::internal
|