inkcpp_rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (273) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +1 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +84 -0
  6. data/LICENSE +7 -0
  7. data/README.md +3 -0
  8. data/Rakefile +16 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +10 -0
  11. data/bin/tapioca +29 -0
  12. data/ext/inkcpp_rb/extconf.rb +19 -0
  13. data/ext/inkcpp_rb/inkcpp/.clang-format +99 -0
  14. data/ext/inkcpp_rb/inkcpp/.github/FUNDING.yml +1 -0
  15. data/ext/inkcpp_rb/inkcpp/.github/workflows/build.yml +344 -0
  16. data/ext/inkcpp_rb/inkcpp/.github/workflows/release.yml +49 -0
  17. data/ext/inkcpp_rb/inkcpp/.gitignore +25 -0
  18. data/ext/inkcpp_rb/inkcpp/.gitmodules +9 -0
  19. data/ext/inkcpp_rb/inkcpp/CMakeLists.txt +170 -0
  20. data/ext/inkcpp_rb/inkcpp/CODE_OF_CONDUCT.md +76 -0
  21. data/ext/inkcpp_rb/inkcpp/CONTRIBUTING.md +55 -0
  22. data/ext/inkcpp_rb/inkcpp/Config.cmake.in +2 -0
  23. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/CMakeLists.txt +13 -0
  24. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.c +38 -0
  25. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.cpp +40 -0
  26. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink +8 -0
  27. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink.json +1 -0
  28. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example.zip +0 -0
  29. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/InkCPP_DEMO.zip +0 -0
  30. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/CreateThread.png +0 -0
  31. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/HandleChoice.png +0 -0
  32. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ListElementOf.png +0 -0
  33. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalRuntime.png +0 -0
  34. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalThread.png +0 -0
  35. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ObseverChange.png +0 -0
  36. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/TagListGetValue.png +0 -0
  37. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/YieldResume.png +0 -0
  38. data/ext/inkcpp_rb/inkcpp/Doxyfile +2825 -0
  39. data/ext/inkcpp_rb/inkcpp/LICENSE.txt +22 -0
  40. data/ext/inkcpp_rb/inkcpp/Minimal.runsettings +8 -0
  41. data/ext/inkcpp_rb/inkcpp/README.md +192 -0
  42. data/ext/inkcpp_rb/inkcpp/inkcpp/CMakeLists.txt +67 -0
  43. data/ext/inkcpp_rb/inkcpp/inkcpp/array.h +481 -0
  44. data/ext/inkcpp_rb/inkcpp/inkcpp/avl_array.h +833 -0
  45. data/ext/inkcpp_rb/inkcpp/inkcpp/casting.h +93 -0
  46. data/ext/inkcpp_rb/inkcpp/inkcpp/choice.cpp +54 -0
  47. data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.cpp +124 -0
  48. data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.h +406 -0
  49. data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.cpp +52 -0
  50. data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.h +34 -0
  51. data/ext/inkcpp_rb/inkcpp/inkcpp/executioner.h +179 -0
  52. data/ext/inkcpp_rb/inkcpp/inkcpp/functional.cpp +86 -0
  53. data/ext/inkcpp_rb/inkcpp/inkcpp/functions.cpp +54 -0
  54. data/ext/inkcpp_rb/inkcpp/inkcpp/functions.h +40 -0
  55. data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.cpp +289 -0
  56. data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.h +149 -0
  57. data/ext/inkcpp_rb/inkcpp/inkcpp/header.cpp +44 -0
  58. data/ext/inkcpp_rb/inkcpp/inkcpp/include/choice.h +106 -0
  59. data/ext/inkcpp_rb/inkcpp/inkcpp/include/functional.h +327 -0
  60. data/ext/inkcpp_rb/inkcpp/inkcpp/include/globals.h +196 -0
  61. data/ext/inkcpp_rb/inkcpp/inkcpp/include/list.h +187 -0
  62. data/ext/inkcpp_rb/inkcpp/inkcpp/include/runner.h +291 -0
  63. data/ext/inkcpp_rb/inkcpp/inkcpp/include/snapshot.h +61 -0
  64. data/ext/inkcpp_rb/inkcpp/inkcpp/include/story.h +219 -0
  65. data/ext/inkcpp_rb/inkcpp/inkcpp/include/story_ptr.h +233 -0
  66. data/ext/inkcpp_rb/inkcpp/inkcpp/include/traits.h +270 -0
  67. data/ext/inkcpp_rb/inkcpp/inkcpp/include/types.h +169 -0
  68. data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.cpp +79 -0
  69. data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.h +39 -0
  70. data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.cpp +276 -0
  71. data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.h +356 -0
  72. data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.cpp +841 -0
  73. data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.h +450 -0
  74. data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.cpp +40 -0
  75. data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.h +529 -0
  76. data/ext/inkcpp_rb/inkcpp/inkcpp/operation_bases.h +164 -0
  77. data/ext/inkcpp_rb/inkcpp/inkcpp/operations.h +100 -0
  78. data/ext/inkcpp_rb/inkcpp/inkcpp/output.cpp +528 -0
  79. data/ext/inkcpp_rb/inkcpp/inkcpp/output.h +153 -0
  80. data/ext/inkcpp_rb/inkcpp/inkcpp/platform.h +22 -0
  81. data/ext/inkcpp_rb/inkcpp/inkcpp/random.h +38 -0
  82. data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.cpp +1396 -0
  83. data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.h +336 -0
  84. data/ext/inkcpp_rb/inkcpp/inkcpp/simple_restorable_stack.h +335 -0
  85. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.cpp +182 -0
  86. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.h +91 -0
  87. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_interface.h +57 -0
  88. data/ext/inkcpp_rb/inkcpp/inkcpp/stack.cpp +618 -0
  89. data/ext/inkcpp_rb/inkcpp/inkcpp/stack.h +243 -0
  90. data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.cpp +361 -0
  91. data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.h +92 -0
  92. data/ext/inkcpp_rb/inkcpp/inkcpp/story_ptr.cpp +75 -0
  93. data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.cpp +125 -0
  94. data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.h +67 -0
  95. data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.cpp +149 -0
  96. data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.h +47 -0
  97. data/ext/inkcpp_rb/inkcpp/inkcpp/string_utils.h +207 -0
  98. data/ext/inkcpp_rb/inkcpp/inkcpp/system.cpp +39 -0
  99. data/ext/inkcpp_rb/inkcpp/inkcpp/tuple.hpp +151 -0
  100. data/ext/inkcpp_rb/inkcpp/inkcpp/value.cpp +279 -0
  101. data/ext/inkcpp_rb/inkcpp/inkcpp/value.h +666 -0
  102. data/ext/inkcpp_rb/inkcpp/inkcpp_c/CMakeLists.txt +62 -0
  103. data/ext/inkcpp_rb/inkcpp/inkcpp_c/include/inkcpp.h +393 -0
  104. data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp.cpp +344 -0
  105. data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp_c.pc.in +10 -0
  106. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/ExternalFunction.c +56 -0
  107. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Globals.c +98 -0
  108. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Lists.c +73 -0
  109. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c +36 -0
  110. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Snapshot.c +65 -0
  111. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/CMakeLists.txt +49 -0
  112. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/inkcpp_cl.cpp +215 -0
  113. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.cpp +209 -0
  114. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.h +8 -0
  115. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/CMakeLists.txt +37 -0
  116. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.cpp +446 -0
  117. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.h +70 -0
  118. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.cpp +166 -0
  119. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.h +79 -0
  120. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/command.cpp +107 -0
  121. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/compiler.cpp +96 -0
  122. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.cpp +62 -0
  123. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.h +104 -0
  124. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compilation_results.h +22 -0
  125. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compiler.h +44 -0
  126. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json.hpp +24596 -0
  127. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.cpp +411 -0
  128. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.h +62 -0
  129. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.cpp +47 -0
  130. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.h +70 -0
  131. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.cpp +107 -0
  132. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.h +55 -0
  133. data/ext/inkcpp_rb/inkcpp/inkcpp_py/CMakeLists.txt +19 -0
  134. data/ext/inkcpp_rb/inkcpp/inkcpp_py/example.py +78 -0
  135. data/ext/inkcpp_rb/inkcpp/inkcpp_py/src/module.cpp +317 -0
  136. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/conftest.py +53 -0
  137. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_ExternalFunctions.py +35 -0
  138. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Globals.py +40 -0
  139. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Lists.py +43 -0
  140. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Observer.py +27 -0
  141. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Snapshot.py +57 -0
  142. data/ext/inkcpp_rb/inkcpp/inkcpp_py/unreal_example.ink +71 -0
  143. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Array.cpp +115 -0
  144. data/ext/inkcpp_rb/inkcpp/inkcpp_test/CMakeLists.txt +117 -0
  145. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Callstack.cpp +392 -0
  146. data/ext/inkcpp_rb/inkcpp/inkcpp_test/EmptyStringForDivert.cpp +36 -0
  147. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ExternalFunctionsExecuteProperly.cpp +34 -0
  148. data/ext/inkcpp_rb/inkcpp/inkcpp_test/FallbackFunction.cpp +77 -0
  149. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Globals.cpp +73 -0
  150. data/ext/inkcpp_rb/inkcpp/inkcpp_test/InkyJson.cpp +34 -0
  151. data/ext/inkcpp_rb/inkcpp/inkcpp_test/LabelCondition.cpp +60 -0
  152. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Lists.cpp +144 -0
  153. data/ext/inkcpp_rb/inkcpp/inkcpp_test/LookaheadSafe.cpp +46 -0
  154. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Main.cpp +7 -0
  155. data/ext/inkcpp_rb/inkcpp/inkcpp_test/MoveTo.cpp +95 -0
  156. data/ext/inkcpp_rb/inkcpp/inkcpp_test/NewLines.cpp +76 -0
  157. data/ext/inkcpp_rb/inkcpp/inkcpp_test/NoEarlyTags.cpp +33 -0
  158. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Observer.cpp +245 -0
  159. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Pointer.cpp +191 -0
  160. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Restorable.cpp +294 -0
  161. data/ext/inkcpp_rb/inkcpp/inkcpp_test/SpaceAfterBracketChoice.cpp +45 -0
  162. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Stack.cpp +224 -0
  163. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Tags.cpp +131 -0
  164. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ThirdTierChoiceAfterBrackets.cpp +38 -0
  165. data/ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp +56 -0
  166. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Value.cpp +210 -0
  167. data/ext/inkcpp_rb/inkcpp/inkcpp_test/catch.hpp +17970 -0
  168. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/AHF.ink +7 -0
  169. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ChoiceBracketStory.ink +7 -0
  170. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/EmptyStringForDivert.ink +13 -0
  171. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ExternalFunctionsExecuteProperly.ink +11 -0
  172. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/FallBack.ink +15 -0
  173. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/GlobalStory.ink +9 -0
  174. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LabelConditionStory.ink +5 -0
  175. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LinesStory.ink +42 -0
  176. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListLogicStory.ink +40 -0
  177. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListStory.ink +8 -0
  178. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LookaheadSafe.ink +14 -0
  179. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/MoveTo.ink +36 -0
  180. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/NoEarlyTags.ink +19 -0
  181. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ObserverStory.ink +8 -0
  182. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/SimpleStoryFlow.ink +65 -0
  183. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TagsStory.ink +22 -0
  184. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TheIntercept.ink +1686 -0
  185. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ThirdTierChoiceAfterBracketsStory.ink +13 -0
  186. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF-8-demo.txt +212 -0
  187. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF8Story.ink +218 -0
  188. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inklecate.json +154 -0
  189. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inky.json +160 -0
  190. data/ext/inkcpp_rb/inkcpp/notes/ArchitectureNotes.md +54 -0
  191. data/ext/inkcpp_rb/inkcpp/notes/ListNotes.md +69 -0
  192. data/ext/inkcpp_rb/inkcpp/notes/OperationNotes.md +35 -0
  193. data/ext/inkcpp_rb/inkcpp/notes/TagsNotes.md +24 -0
  194. data/ext/inkcpp_rb/inkcpp/notes/WhitespaceNotes.md +28 -0
  195. data/ext/inkcpp_rb/inkcpp/proofing/README.md +3 -0
  196. data/ext/inkcpp_rb/inkcpp/proofing/inkcpp_runtime_driver +12 -0
  197. data/ext/inkcpp_rb/inkcpp/pyproject.toml +63 -0
  198. data/ext/inkcpp_rb/inkcpp/setup.py +166 -0
  199. data/ext/inkcpp_rb/inkcpp/shared/CMakeLists.txt +14 -0
  200. data/ext/inkcpp_rb/inkcpp/shared/private/command.h +172 -0
  201. data/ext/inkcpp_rb/inkcpp/shared/private/header.h +46 -0
  202. data/ext/inkcpp_rb/inkcpp/shared/public/config.h +53 -0
  203. data/ext/inkcpp_rb/inkcpp/shared/public/system.h +307 -0
  204. data/ext/inkcpp_rb/inkcpp/shared/public/version.h +14 -0
  205. data/ext/inkcpp_rb/inkcpp/tests/TestAllSequenceTypes.ink +59 -0
  206. data/ext/inkcpp_rb/inkcpp/tests/TestArithmetic.ink +17 -0
  207. data/ext/inkcpp_rb/inkcpp/tests/TestBasicStringLiterals.ink +8 -0
  208. data/ext/inkcpp_rb/inkcpp/tests/TestBasicTunnel.ink +10 -0
  209. data/ext/inkcpp_rb/inkcpp/tests/TestBlanksInInlineSequences.ink +51 -0
  210. data/ext/inkcpp_rb/inkcpp/tests/TestCallStackEvaluation.ink +15 -0
  211. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceCount.ink +15 -0
  212. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceDivertsToDone.ink +6 -0
  213. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceWithBracketsOnly.ink +9 -0
  214. data/ext/inkcpp_rb/inkcpp/tests/TestCompareDivertTargets.ink +26 -0
  215. data/ext/inkcpp_rb/inkcpp/tests/TestComplexTunnels.ink +22 -0
  216. data/ext/inkcpp_rb/inkcpp/tests/TestConditionalChoiceInWeave.ink +19 -0
  217. data/ext/inkcpp_rb/inkcpp/tests/TestTunnelOnwardsAfterTunnel.ink +17 -0
  218. data/ext/inkcpp_rb/inkcpp/unreal/CMakeLists.txt +51 -0
  219. data/ext/inkcpp_rb/inkcpp/unreal/UE_example.ink +92 -0
  220. data/ext/inkcpp_rb/inkcpp/unreal/blueprint_filter.js +377 -0
  221. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Resources/Icon128.png +0 -0
  222. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkAsset.cpp +47 -0
  223. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkChoice.cpp +40 -0
  224. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkList.cpp +86 -0
  225. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkRuntime.cpp +265 -0
  226. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkThread.cpp +239 -0
  227. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkVar.cpp +143 -0
  228. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/TagList.cpp +95 -0
  229. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/inkcpp.cpp +13 -0
  230. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkAsset.h +50 -0
  231. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkChoice.h +58 -0
  232. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkDelegates.h +139 -0
  233. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkList.h +102 -0
  234. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkRuntime.h +177 -0
  235. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkSnapshot.h +30 -0
  236. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkThread.h +215 -0
  237. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkVar.h +245 -0
  238. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/TagList.h +77 -0
  239. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/inkcpp.h +217 -0
  240. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/inkcpp.Build.cs +62 -0
  241. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.cpp +237 -0
  242. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.h +43 -0
  243. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inkcpp_editor.cpp +13 -0
  244. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inklecate_cmd.cpp.in +24 -0
  245. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Public/inkcpp_editor.h +9 -0
  246. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/inkcpp_editor.Build.cs +61 -0
  247. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/inkcpp.uplugin +44 -0
  248. data/ext/inkcpp_rb/inkcpp/unreal/render.css +1 -0
  249. data/ext/inkcpp_rb/inkcpp_rb.cpp +321 -0
  250. data/inkcpp_rb.gemspec +54 -0
  251. data/rbi/inkcpp_rb.rbi +211 -0
  252. data/sorbet/config +4 -0
  253. data/sorbet/rbi/annotations/.gitattributes +1 -0
  254. data/sorbet/rbi/annotations/minitest.rbi +119 -0
  255. data/sorbet/rbi/gems/.gitattributes +1 -0
  256. data/sorbet/rbi/gems/benchmark@0.4.0.rbi +618 -0
  257. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  258. data/sorbet/rbi/gems/minitest@5.25.4.rbi +1547 -0
  259. data/sorbet/rbi/gems/netrc@0.11.0.rbi +159 -0
  260. data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
  261. data/sorbet/rbi/gems/prism@1.3.0.rbi +40040 -0
  262. data/sorbet/rbi/gems/rake-compiler@1.2.8.rbi +9 -0
  263. data/sorbet/rbi/gems/rake@13.2.1.rbi +3033 -0
  264. data/sorbet/rbi/gems/rbi@0.2.2.rbi +4527 -0
  265. data/sorbet/rbi/gems/rice@4.3.3.rbi +44 -0
  266. data/sorbet/rbi/gems/spoom@1.5.0.rbi +4932 -0
  267. data/sorbet/rbi/gems/tapioca@0.16.7.rbi +3611 -0
  268. data/sorbet/rbi/gems/thor@1.3.2.rbi +4378 -0
  269. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +435 -0
  270. data/sorbet/rbi/gems/yard@0.9.37.rbi +18379 -0
  271. data/sorbet/tapioca/config.yml +13 -0
  272. data/sorbet/tapioca/require.rb +4 -0
  273. metadata +400 -0
@@ -0,0 +1,411 @@
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
+ #include "json_compiler.h"
8
+
9
+ #include "command.h"
10
+ #include "list_data.h"
11
+ #include "system.h"
12
+ #include "version.h"
13
+
14
+ #include <string_view>
15
+
16
+ namespace ink::compiler::internal
17
+ {
18
+ using nlohmann::json;
19
+ using std::vector;
20
+
21
+ typedef std::tuple<json, std::string> defer_entry;
22
+
23
+ json_compiler::json_compiler()
24
+ : _emitter(nullptr)
25
+ , _next_container_index(0)
26
+ {
27
+ }
28
+
29
+ void json_compiler::compile(
30
+ const nlohmann::json& input, emitter* output, compilation_results* results
31
+ )
32
+ {
33
+ // Get the runtime version
34
+ _ink_version = input["inkVersion"];
35
+
36
+ // Start the output
37
+ set_results(results);
38
+ _emitter = output;
39
+
40
+ // Initialize emitter
41
+ _emitter->start(_ink_version, results);
42
+
43
+ if (auto itr = input.find("listDefs"); itr != input.end()) {
44
+ compile_lists_definition(*itr);
45
+ _emitter->set_list_meta(_list_meta);
46
+ }
47
+ // Compile the root container
48
+ compile_container(input["root"], 0);
49
+
50
+ // finalize
51
+ _emitter->finish(_next_container_index);
52
+
53
+ // Clear
54
+ _emitter = nullptr;
55
+ _next_container_index = 0;
56
+ clear_results();
57
+ }
58
+
59
+ struct container_meta {
60
+ std::string name;
61
+ container_t indexToReturn = ~0;
62
+ bool recordInContainerMap = false;
63
+ vector<defer_entry> deferred;
64
+ CommandFlag cmd_flags = CommandFlag::NO_FLAGS;
65
+ };
66
+
67
+ void json_compiler::handle_container_metadata(const json& meta, container_meta& data)
68
+ {
69
+ if (meta.is_object()) {
70
+ for (auto& meta_iter : meta.items()) {
71
+ // Name
72
+ if (meta_iter.key() == "#n") {
73
+ data.name = meta_iter.value().get<std::string>();
74
+ }
75
+ // Flags
76
+ else if (meta_iter.key() == "#f") {
77
+ int flags = meta_iter.value().get<int>();
78
+
79
+ bool visits = false, turns = false, onlyFirst = false;
80
+
81
+ if ((flags & 0x1) > 0) // Should record visit counts
82
+ {
83
+ visits = true;
84
+ }
85
+ if ((flags & 0x2) > 0) // Should record turn counts
86
+ {
87
+ turns = true;
88
+ }
89
+ if ((flags & 0x4) > 0) // Only count when you enter the first subelement
90
+ {
91
+ onlyFirst = true;
92
+ }
93
+
94
+ if (visits || turns) {
95
+ container_t myIndex = _next_container_index++;
96
+
97
+ // Make appropriate flags
98
+ data.cmd_flags = CommandFlag::NO_FLAGS;
99
+ if (visits)
100
+ data.cmd_flags |= CommandFlag::CONTAINER_MARKER_TRACK_VISITS;
101
+ if (turns)
102
+ data.cmd_flags |= CommandFlag::CONTAINER_MARKER_TRACK_TURNS;
103
+ if (onlyFirst)
104
+ data.cmd_flags |= CommandFlag::CONTAINER_MARKER_ONLY_FIRST;
105
+
106
+
107
+ data.indexToReturn = myIndex;
108
+
109
+ // if (!onlyFirst) // ????
110
+ {
111
+ data.recordInContainerMap = true;
112
+ }
113
+ }
114
+ }
115
+ // Child container
116
+ else {
117
+ // Add to deferred compilation list
118
+ data.deferred.push_back(std::make_tuple(meta_iter.value(), meta_iter.key()));
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ void json_compiler::compile_container(
125
+ const nlohmann::json& container, int index_in_parent, const std::string& name_override
126
+ )
127
+ {
128
+ // Grab metadata from the last object in this container
129
+ container_meta meta;
130
+ handle_container_metadata(*container.rbegin(), meta);
131
+
132
+ // tell the emitter we're beginning a new container
133
+ uint32_t position = _emitter->start_container(
134
+ index_in_parent, name_override.empty() ? meta.name : name_override
135
+ );
136
+ // Write command out at this position
137
+ if (meta.cmd_flags != CommandFlag::NO_FLAGS) {
138
+ _emitter->write(Command::START_CONTAINER_MARKER, meta.indexToReturn, meta.cmd_flags);
139
+ }
140
+ if (meta.recordInContainerMap) {
141
+ _emitter->add_start_to_container_map(position, meta.indexToReturn);
142
+ }
143
+
144
+ // Now, we want to iterate children of this container, save the last
145
+ // The last is the settings object handled above
146
+ int index = -1;
147
+ auto end = container.end() - 1;
148
+ for (auto iter = container.begin(); iter != end; ++iter) {
149
+ // Increment index
150
+ index++;
151
+
152
+ // Arrays are child containers. Recurse.
153
+ if (iter->is_array())
154
+ compile_container(*iter, index);
155
+
156
+ // Strings are either commands, nops, or raw strings
157
+ else if (iter->is_string()) {
158
+ // Get the string
159
+ std::string string = iter->get<std::string>();
160
+
161
+ if (string[0] == '^')
162
+ _emitter->write_string(Command::STR, CommandFlag::NO_FLAGS, string);
163
+ else if (string == "nop")
164
+ _emitter->handle_nop(index);
165
+ else
166
+ compile_command(string);
167
+ }
168
+
169
+ // Numbers (floats and integers)
170
+ else if (iter->is_number()) {
171
+ if (iter->is_number_float()) {
172
+ float value = iter->get<float>();
173
+ _emitter->write(Command::FLOAT, value);
174
+ } else {
175
+ int value = iter->get<int>();
176
+ _emitter->write(Command::INT, value);
177
+ }
178
+ }
179
+
180
+ // Booleans
181
+ else if (iter->is_boolean()) {
182
+ int value = iter->get<bool>() ? 1 : 0;
183
+ _emitter->write(Command::BOOL, value);
184
+ }
185
+
186
+ // Complex commands
187
+ else if (iter->is_object()) {
188
+ compile_complex_command(*iter);
189
+ }
190
+
191
+ else {
192
+ throw ink_exception("Failed to container member!");
193
+ }
194
+ }
195
+
196
+ if (meta.deferred.size() > 0) {
197
+ std::vector<size_t> divert_positions;
198
+
199
+ // Write empty divert to be patched later
200
+ uint32_t divert_position = _emitter->fallthrough_divert();
201
+ divert_positions.push_back(divert_position);
202
+
203
+ // (2) Write deffered containers
204
+ for (auto& t : meta.deferred) {
205
+ using std::get;
206
+
207
+ // Add to named child list
208
+ compile_container(get<0>(t), -1, get<1>(t));
209
+
210
+ // Need a divert here
211
+ uint32_t pos = _emitter->fallthrough_divert();
212
+ divert_positions.push_back(pos);
213
+ }
214
+
215
+ // (3) Set divert positions
216
+ for (size_t offset : divert_positions)
217
+ _emitter->patch_fallthroughs(offset);
218
+ }
219
+
220
+ // End container
221
+ uint32_t end_position = _emitter->end_container();
222
+
223
+ // Write end container marker, End pointer should point to End command (form symetry with START
224
+ // command)
225
+ if (meta.indexToReturn != ~0)
226
+ _emitter->write(Command::END_CONTAINER_MARKER, meta.indexToReturn, meta.cmd_flags);
227
+
228
+ // Record end position in map
229
+ if (meta.recordInContainerMap)
230
+ _emitter->add_end_to_container_map(end_position, meta.indexToReturn);
231
+ }
232
+
233
+ void json_compiler::compile_command(const std::string& command)
234
+ {
235
+ // Find command
236
+ for (int i = 0; i < ( int ) Command::NUM_COMMANDS; i++) {
237
+ if (CommandStrings[i] != nullptr && command == CommandStrings[i]) {
238
+ _emitter->write_raw(( Command ) i, CommandFlag::NO_FLAGS, nullptr, 0);
239
+ return;
240
+ }
241
+ }
242
+
243
+ // Missing command warning
244
+ err() << "Unknown command '" << command << "'. Skipping." << std::flush;
245
+ }
246
+
247
+ void json_compiler::compile_complex_command(const nlohmann::json& command)
248
+ {
249
+ std::string val;
250
+
251
+ // Divert
252
+ if (get(command, "->", val)) {
253
+ // Check if this is a conditional divert
254
+ bool isConditional = false;
255
+ CommandFlag flag = CommandFlag::NO_FLAGS;
256
+ if (get(command, "c", isConditional) && isConditional)
257
+ flag = CommandFlag::DIVERT_HAS_CONDITION;
258
+
259
+ // Switch on whether this is a variable divert or a path divert
260
+ bool isVariableDivert = false;
261
+ if (get(command, "var", isVariableDivert) && isVariableDivert)
262
+ _emitter->write_variable(Command::DIVERT_TO_VARIABLE, flag, val);
263
+ else
264
+ _emitter->write_path(Command::DIVERT, flag, val);
265
+ }
266
+
267
+ // Divert to a value
268
+ else if (get(command, "^->", val)) {
269
+ // Write path in a divert_val command
270
+ _emitter->write_path(Command::DIVERT_VAL, CommandFlag::NO_FLAGS, val);
271
+ }
272
+
273
+ // Tunnel
274
+ else if (get(command, "->t->", val)) {
275
+ bool is_var;
276
+ if (get(command, "var", is_var) && is_var) {
277
+ _emitter->write_variable(Command::TUNNEL, CommandFlag::TUNNEL_TO_VARIABLE, val);
278
+ } else {
279
+ _emitter->write_path(Command::TUNNEL, CommandFlag::NO_FLAGS, val);
280
+ }
281
+ }
282
+
283
+ // Declare temporary variable
284
+ else if (get(command, "temp=", val)) {
285
+ bool is_redef = false;
286
+ get(command, "re", is_redef);
287
+ _emitter->write_variable(
288
+ Command::DEFINE_TEMP,
289
+ is_redef ? CommandFlag::ASSIGNMENT_IS_REDEFINE : CommandFlag::NO_FLAGS, val
290
+ );
291
+ }
292
+
293
+ // Set variable
294
+ else if (get(command, "VAR=", val)) {
295
+ // check if it's a redefinition
296
+ bool is_redef = false;
297
+ get(command, "re", is_redef);
298
+
299
+ // Set variable
300
+ _emitter->write_variable(
301
+ Command::SET_VARIABLE,
302
+ is_redef ? CommandFlag::ASSIGNMENT_IS_REDEFINE : CommandFlag::NO_FLAGS, val
303
+ );
304
+ }
305
+
306
+ // create pointer value
307
+ else if (get(command, "^var", val)) {
308
+ int ci;
309
+ if (! get(command, "ci", ci)) {
310
+ throw ink_exception("failed to parse ci for pointer!");
311
+ }
312
+ inkAssert(ci < 255, "only support until 255 stack hight for refernces");
313
+ _emitter->write_variable(Command::VALUE_POINTER, static_cast<CommandFlag>(ci + 1), val);
314
+ }
315
+
316
+ // Push variable
317
+ else if (get(command, "VAR?", val)) {
318
+ _emitter->write_variable(Command::PUSH_VARIABLE_VALUE, CommandFlag::NO_FLAGS, val);
319
+ }
320
+
321
+ // Choice
322
+ else if (get(command, "*", val)) {
323
+ // Get flags
324
+ int flags = 0;
325
+ get(command, "flg", flags);
326
+
327
+ // Write choice path
328
+ _emitter->write_path(Command::CHOICE, ( CommandFlag ) flags, val);
329
+ }
330
+
331
+ // Read count
332
+ else if (get(command, "CNT?", val)) {
333
+ // TODO: Why is this true again?
334
+ _emitter->write_path(Command::READ_COUNT, CommandFlag::NO_FLAGS, val, true);
335
+ }
336
+
337
+ // Internal function call
338
+ else if (get(command, "f()", val)) {
339
+ bool is_var; // function address is stored in jump
340
+ if (get(command, "var", is_var) && is_var) {
341
+ _emitter->write_variable(Command::FUNCTION, CommandFlag::FUNCTION_TO_VARIABLE, val);
342
+ } else {
343
+ _emitter->write_path(Command::FUNCTION, CommandFlag::NO_FLAGS, val);
344
+ }
345
+ }
346
+
347
+ // External function call
348
+ else if (get(command, "x()", val)) {
349
+ // Get argument count
350
+ int numArgs = 0;
351
+ get(command, "exArgs", numArgs);
352
+
353
+ // Encode argument count into command flag and write out the hash of the function name
354
+ _emitter->write(
355
+ Command::CALL_EXTERNAL, hash_string(val.c_str()), static_cast<CommandFlag>(numArgs)
356
+ );
357
+ _emitter->write_path(Command::FUNCTION, CommandFlag::FALLBACK_FUNCTION, val);
358
+ }
359
+
360
+ // list initialisation
361
+ else if (has(command, "list")) {
362
+ std::vector<list_flag> entries;
363
+ auto& list = command["list"];
364
+
365
+ if (list.size()) {
366
+ for (const auto& [key, value] : list.items()) {
367
+ entries.push_back(
368
+ {_list_meta.get_lid(key.substr(0, key.find('.'))),
369
+ static_cast<decltype(list_flag::flag)>(value.get<int>())}
370
+ );
371
+ }
372
+ } else {
373
+ if (has(command, "origins")) {
374
+ for (const auto& origin_list : command["origins"]) {
375
+ // list id < -1 -> origin flag
376
+ entries.push_back(
377
+ {static_cast<int16_t>(-2 - _list_meta.get_lid(origin_list.get<std::string>())), -1}
378
+ );
379
+ }
380
+ } else {
381
+ entries.push_back(empty_flag);
382
+ }
383
+ }
384
+
385
+ _emitter->write_list(Command::LIST, CommandFlag::NO_FLAGS, entries);
386
+ }
387
+
388
+ else if (get(command, "#", val)) {
389
+ if (_ink_version > 20) {
390
+ ink_exception("with inkVerison 21 the tag system chages, and the '#: <tag>' is deprecated now"
391
+ );
392
+ }
393
+ _emitter->write_string(Command::TAG, CommandFlag::NO_FLAGS, val);
394
+ }
395
+
396
+ else {
397
+ throw ink_exception("failed to parse complex command!");
398
+ }
399
+ }
400
+
401
+ void json_compiler::compile_lists_definition(const nlohmann::json& list_defs)
402
+ {
403
+ for (auto& [list_name, flags] : list_defs.items()) {
404
+ _list_meta.new_list(list_name);
405
+ for (auto& [flag_name, value] : flags.items()) {
406
+ _list_meta.new_flag(flag_name, value.get<int>());
407
+ }
408
+ }
409
+ _list_meta.sort();
410
+ }
411
+ } // namespace ink::compiler::internal
@@ -0,0 +1,62 @@
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
+ #include "json.hpp"
9
+ #include "system.h"
10
+ #include "compilation_results.h"
11
+ #include "emitter.h"
12
+ #include "reporter.h"
13
+ #include "list_data.h"
14
+
15
+ #include <vector>
16
+
17
+ namespace ink::compiler::internal
18
+ {
19
+ struct container_meta;
20
+
21
+ // Compiles ink json and outputs using a given emitter
22
+ class json_compiler : public reporter
23
+ {
24
+ public:
25
+ // create new compiler
26
+ json_compiler();
27
+
28
+ // compile from json using an emitter
29
+ void compile(const nlohmann::json& input, emitter* output, compilation_results* results = nullptr);
30
+
31
+ private: // == Compiler methods ==
32
+ void handle_container_metadata(const nlohmann::json& meta, container_meta& data);
33
+ void compile_container(const nlohmann::json& container, int index_in_parent, const std::string& name_override = "");
34
+ void compile_command(const std::string& command);
35
+ void compile_complex_command(const nlohmann::json& command);
36
+ void compile_lists_definition(const nlohmann::json& list_defs);
37
+
38
+ private: // == JSON Helpers ==
39
+ inline bool has(const nlohmann::json& json, const std::string& key)
40
+ {
41
+ return json.find(key) != json.end();
42
+ }
43
+
44
+ template<typename T>
45
+ bool get(const nlohmann::json& json, const std::string& key, T& value)
46
+ {
47
+ auto iter = json.find(key);
48
+ if (iter == json.end())
49
+ return false;
50
+
51
+ value = iter->get<T>();
52
+ return true;
53
+ }
54
+
55
+ private: // == Private members ==
56
+ emitter* _emitter;
57
+ container_t _next_container_index;
58
+
59
+ list_data _list_meta;
60
+ int _ink_version;
61
+ };
62
+ }
@@ -0,0 +1,47 @@
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
+ #include "list_data.h"
8
+
9
+ #include <algorithm>
10
+ #include <limits>
11
+
12
+ namespace ink::compiler::internal
13
+ {
14
+ void list_data::new_list(const std::string& list_name)
15
+ {
16
+ _lists.insert({list_name, static_cast<int>(_list_end.size())});
17
+ _list_name.emplace_back(list_name);
18
+ int current_back = _list_end.empty() ? 0 : _list_end.back();
19
+ _list_end.push_back(current_back);
20
+ }
21
+
22
+ void list_data::new_flag(const std::string& flag_name, int value)
23
+ {
24
+ inkAssert(
25
+ value <= std::numeric_limits<decltype(list_flag::flag)>::max()
26
+ && value >= std::numeric_limits<decltype(list_flag::flag)>::min(),
27
+ "Value outside of current supported scope"
28
+ );
29
+ _list_end.back() += 1;
30
+ _flags.emplace_back(
31
+ &flag_name,
32
+ list_flag{
33
+ .list_id = static_cast<decltype(list_flag::list_id)>(_list_name.size() - 1),
34
+ .flag = static_cast<decltype(list_flag::flag)>(value)}
35
+ );
36
+ }
37
+
38
+ void list_data::sort()
39
+ {
40
+ size_t begin = 0;
41
+ for (size_t i = 0; i < _list_end.size(); ++i) {
42
+ std::sort(_flags.begin() + begin, _flags.begin() + _list_end[i]);
43
+ begin = _list_end[i];
44
+ }
45
+ }
46
+
47
+ } // namespace ink::compiler::internal
@@ -0,0 +1,70 @@
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
+
11
+ #include <vector>
12
+ #include <string>
13
+ #include <map>
14
+ #include <string_view>
15
+
16
+ namespace ink::compiler::internal
17
+ {
18
+ class list_data
19
+ {
20
+ using flag_t = decltype(list_flag::flag);
21
+ using lid_t = decltype(list_flag::list_id);
22
+
23
+ public:
24
+ // add new list and set it to current
25
+ void new_list(const std::string& list_name);
26
+
27
+ // add flag to current list
28
+ void new_flag(const std::string& flag_name, int value);
29
+
30
+ // sort flags per list
31
+ void sort();
32
+
33
+ lid_t get_lid(const std::string_view& list_name)
34
+ {
35
+ auto itr = _lists.find(list_name);
36
+ return static_cast<lid_t>(itr->second);
37
+ }
38
+
39
+ bool empty() const { return _lists.empty(); }
40
+
41
+ struct named_list_flag {
42
+ named_list_flag(const std::string* name, list_flag flag)
43
+ : name{name}
44
+ , flag{flag}
45
+ {
46
+ }
47
+
48
+ const std::string* name;
49
+ list_flag flag;
50
+
51
+ bool operator<(const named_list_flag& oth) const
52
+ {
53
+ inkAssert(
54
+ flag.list_id == oth.flag.list_id, "Compare flags from different lists is not supported"
55
+ );
56
+ return flag.flag < oth.flag.flag;
57
+ }
58
+ };
59
+
60
+ const std::vector<named_list_flag>& get_flags() const { return _flags; }
61
+
62
+ const std::vector<std::string_view>& get_list_names() const { return _list_name; }
63
+
64
+ private:
65
+ std::map<std::string, int, std::less<>> _lists;
66
+ std::vector<std::string_view> _list_name;
67
+ std::vector<int> _list_end;
68
+ std::vector<named_list_flag> _flags;
69
+ };
70
+ } // namespace ink::compiler::internal
@@ -0,0 +1,107 @@
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
+ #include "reporter.h"
8
+ #include "compilation_results.h"
9
+ #include "system.h"
10
+
11
+ #include <iostream>
12
+ #include <sstream>
13
+
14
+ namespace ink::compiler::internal
15
+ {
16
+ reporter::reporter()
17
+ : _results(nullptr), _stream(&_buffer)
18
+ {
19
+ }
20
+
21
+ void reporter::set_results(compilation_results* results)
22
+ {
23
+ _results = results;
24
+ }
25
+
26
+ void reporter::clear_results()
27
+ {
28
+ _results = nullptr;
29
+ }
30
+
31
+ std::ostream& reporter::warn()
32
+ {
33
+ // setp warning buffer
34
+ if (_results != nullptr)
35
+ {
36
+ _buffer.start(&_results->warnings);
37
+ }
38
+
39
+ return _stream;
40
+ }
41
+
42
+ std::ostream& reporter::err()
43
+ {
44
+ // setp error buffer
45
+ if (_results != nullptr)
46
+ {
47
+ _buffer.start(&_results->errors);
48
+ }
49
+
50
+ return _stream;
51
+ }
52
+
53
+ std::ostream& reporter::crit()
54
+ {
55
+ // setp error buffer
56
+ if (_results != nullptr)
57
+ {
58
+ _buffer.start(&_results->errors);
59
+ _buffer.throw_on_sync(true);
60
+ }
61
+
62
+ return _stream;
63
+ }
64
+
65
+ void error_strbuf::start(error_list* list)
66
+ {
67
+ // store list
68
+ _list = list;
69
+
70
+ // Make sure our buffer is empty
71
+ #ifdef WIN32
72
+ _Tidy();
73
+ #endif
74
+ }
75
+
76
+ void error_strbuf::throw_on_sync(bool t)
77
+ {
78
+ _throw = t;
79
+ }
80
+
81
+ int error_strbuf::sync()
82
+ {
83
+ // TODO: Assert?
84
+ if (_list == nullptr)
85
+ return -1;
86
+
87
+ // Add string to list
88
+ std::string val = str();
89
+ _list->push_back(val);
90
+
91
+ // Clear our state
92
+ _list = nullptr;
93
+ #ifdef WIN32
94
+ _Tidy();
95
+ #endif
96
+
97
+ // Should we throw?
98
+ if (_throw)
99
+ {
100
+ _throw = false;
101
+ throw ink::ink_exception(("CRITICAL ERROR: " + val).c_str());
102
+ }
103
+
104
+ // Return success
105
+ return 0;
106
+ }
107
+ }