Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ ctest -C Release
To test the python bindings use:

```sh
pip install .
python -m pip install build pytest
python -m build
python -m pip install dist/*.whl --user
Expand Down
4 changes: 2 additions & 2 deletions inkcpp/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ template<>
int32_t function_base::pop<int32_t>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::int32, "Type missmatch!");
inkAssert(val.type() == value_type::int32, "Type mismatch!");
return val.get<value_type::int32>();
}

template<>
const char* function_base::pop<const char*>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::string, "Type missmatch!");
inkAssert(val.type() == value_type::string, "Type mismatch!");
return val.get<value_type::string>().str;
}

Expand Down
2 changes: 1 addition & 1 deletion inkcpp/globals_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ globals_impl::globals_impl(const story_impl* story)
_visit_counts.resize(_num_containers);
_visit_counts_backup.resize(_num_containers);
if (_lists) {
// initelize static lists
// initialize static lists
const list_flag* flags = story->lists();
while (*flags != null_flag) {
list_table::list l = _lists.create_permament();
Expand Down
4 changes: 2 additions & 2 deletions inkcpp/include/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class choice;
/**
* A runner to execute ink script from a story.
*
* An independant runner which can execute ink script from a
* story independant of other runners. Think of the ink story
* An independent runner which can execute ink script from a
* story independent of other runners. Think of the ink story
* object like an executable file and the runners as 'threads'
* (not to be confused with ink threads, which are a language
* feature). Runners track their own instruction pointer, choice
Expand Down
10 changes: 5 additions & 5 deletions inkcpp/include/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace ink::runtime
/**
* Container for an InkCPP runtime snapshot.
* Each snapshot contains a @ref ink::runtime::globals_interface "globals store"
* and all assoziated @ref ink::runtime::runner_interface "runners/threads"
* and all associated @ref ink::runtime::runner_interface "runners/threads"
* For convinience there exist @ref ink::runtime::globals_interface::create_snapshot() and
* runner_interface::create_snapshot() . If the runner is assoziated to the globals the snapshot
* will be identical. If multiple runners are assoziated to the same globals all will be contained,
* runner_interface::create_snapshot() . If the runner is associated to the globals the snapshot
* will be identical. If multiple runners are associated to the same globals all will be contained,
* and cann be reconsrtucted with the id parameter of @ref
* ink::runtime::story::new_runner_from_snapshot()
*
Expand All @@ -38,7 +38,7 @@ class snapshot
*/
static snapshot* from_binary(const unsigned char* data, size_t length, bool freeOnDestroy = true);

/** acces blob inside snapshot */
/** access blob inside snapshot */
virtual const unsigned char* get_data() const = 0;
/** size of blob inside snapshot */
virtual size_t get_data_len() const = 0;
Expand All @@ -53,7 +53,7 @@ class snapshot
static snapshot* from_file(const char* filename);
/** serialize snapshot to file
* @param filename output file filename, if already exist it will be overwritten
* @throws ink_exception if it failt to open the file
* @throws ink_exception if it fails to open the file
*/
void write_to_file(const char* filename) const;
#endif
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/include/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# include <string>
#endif

/** Util templates and implimentation of STL if STL is not available */
/** Util templates and implementation of STL if STL is not available */
namespace ink::runtime::internal
{
template<typename... Ts>
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using list = list_interface*;

/** A Ink variable
*
* Used for accassing, writing and observing global variables
* Used for accessing, writing and observing global variables
* @ref ink::runtime::globals_interface::get()
* @ref ink::runtime::globals_interface::set()
* @ref ink::runtime::globals_interface::observe()
Expand Down
106 changes: 53 additions & 53 deletions inkcpp/story_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,68 @@

namespace ink::runtime::internal
{
void ref_block::remove_reference(ref_block*& block)
{
if (block == nullptr)
return;

// If we only have one references left
if (block->references <= 1)
{
// delete the block
delete block;
block = nullptr;
return;
}
void ref_block::remove_reference(ref_block*& block)
{
if (block == nullptr)
return;

// Otherwise, derecement references
block->references--;
// If we only have one references left
if (block->references <= 1) {
// delete the block
delete block;
block = nullptr;
return;
}

story_ptr_base::story_ptr_base(internal::ref_block* story)
: _story_block(story)
{
_instance_block = new ref_block();
}
// Otherwise, decrement references
block->references--;
}

story_ptr_base::story_ptr_base(internal::ref_block* story, internal::ref_block* instance)
: _story_block(story), _instance_block(instance)
{
}
story_ptr_base::story_ptr_base(internal::ref_block* story)
: _story_block(story)
{
_instance_block = new ref_block();
}

story_ptr_base::story_ptr_base(const story_ptr_base& other)
: _story_block(other._story_block)
, _instance_block(other._instance_block)
{
}
story_ptr_base::story_ptr_base(internal::ref_block* story, internal::ref_block* instance)
: _story_block(story)
, _instance_block(instance)
{
}

void story_ptr_base::set(const story_ptr_base& other)
{
_story_block = other._story_block;
_instance_block = other._instance_block;
}
story_ptr_base::story_ptr_base(const story_ptr_base& other)
: _story_block(other._story_block)
, _instance_block(other._instance_block)
{
}

void story_ptr_base::add_reference()
{
// If our block isn't valid, don't bother
if (_story_block == nullptr || _instance_block == nullptr || !_story_block->valid || !_instance_block->valid)
{
_story_block = _instance_block = nullptr;
return;
}
void story_ptr_base::set(const story_ptr_base& other)
{
_story_block = other._story_block;
_instance_block = other._instance_block;
}

_instance_block->references++;
_story_block->references++;
void story_ptr_base::add_reference()
{
// If our block isn't valid, don't bother
if (_story_block == nullptr || _instance_block == nullptr || ! _story_block->valid
|| ! _instance_block->valid) {
_story_block = _instance_block = nullptr;
return;
}

bool story_ptr_base::remove_reference()
{
ref_block::remove_reference(_story_block);
ref_block::remove_reference(_instance_block);
_instance_block->references++;
_story_block->references++;
}

bool is_destroyed = _instance_block == nullptr;
bool story_ptr_base::remove_reference()
{
ref_block::remove_reference(_story_block);
ref_block::remove_reference(_instance_block);

_instance_block = _story_block = nullptr;
return is_destroyed;
}
} // namespace ink::runtime::internal
bool is_destroyed = _instance_block == nullptr;

_instance_block = _story_block = nullptr;
return is_destroyed;
}
} // namespace ink::runtime::internal
50 changes: 25 additions & 25 deletions inkcpp/string_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@

namespace ink::runtime::internal
{
// hash tree sorted by string pointers
class string_table final : public snapshot_interface
{
public:
virtual ~string_table();
// hash tree sorted by string pointers
class string_table final : public snapshot_interface
{
public:
virtual ~string_table();

// Create a dynmaic string of a particular length
char* create(size_t length);
char* duplicate(const char* str);
// Create a dynamic string of a particular length
char* create(size_t length);
char* duplicate(const char* str);

// zeroes all usage values
void clear_usage();
// zeroes all usage values
void clear_usage();

// mark a string as used
void mark_used(const char* string);
// mark a string as used
void mark_used(const char* string);


// snapshot interface implementation
size_t snap(unsigned char* data, const snapper&) const;
const unsigned char* snap_load(const unsigned char* data, const loader&);
// snapshot interface implementation
size_t snap(unsigned char* data, const snapper&) const;
const unsigned char* snap_load(const unsigned char* data, const loader&);

// get position of string when iterate through data
// used to enable storing a string table references
size_t get_id(const char* string) const;
// get position of string when iterate through data
// used to enable storing a string table references
size_t get_id(const char* string) const;

// deletes all unused strings
void gc();
// deletes all unused strings
void gc();

private:
avl_array<const char*, bool, ink::size_t, 100> _table;
static constexpr const char* EMPTY_STRING = "\x03";
};
}
private:
avl_array<const char*, bool, ink::size_t, 100> _table;
static constexpr const char* EMPTY_STRING = "\x03";
};
} // namespace ink::runtime::internal
1 change: 0 additions & 1 deletion inkcpp_python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def story_path(tmpdir_factory):

@pytest.fixture(scope='session', autouse=True)
def assets(story_path, inklecate_cmd):
print(ink.__dict__, file=sys.stderr)
res = {}
for (name, files) in story_path.items():
if not os.path.exists(files[0]):
Expand Down
4 changes: 2 additions & 2 deletions inkcpp_python/tests/test_ExternalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_lookaheadSafe(self, assets, generate):
assert out == "Call1 glued to Call 2\n"
assert cnt.cnt == 3
out = runner.getline()
assert out == "Call 3 is seperated\n"
assert out == "Call 3 is separated\n"
assert cnt.cnt == 4

def test_lookahadeUnsafe(self, assets, generate):
Expand All @@ -30,6 +30,6 @@ def test_lookahadeUnsafe(self, assets, generate):
assert out == "glued to Call 2\n"
assert cnt.cnt == 2
out = runner.getline()
assert out == "Call 3 is seperated\n"
assert out == "Call 3 is separated\n"
assert cnt.cnt == 3

2 changes: 1 addition & 1 deletion inkcpp_test/LabelCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace ink::runtime;

SCENARIO( "run story with hidden choice" )
{
GIVEN( "a story with choice visibale by second visit" )
GIVEN("a story with choice visible by second visit")
{
auto ink = story::from_file(INK_TEST_RESOURCE_DIR "LabelConditionStory.bin");
globals globals = ink->new_globals();
Expand Down
4 changes: 2 additions & 2 deletions inkcpp_test/LookaheadSafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SCENARIO("A story with external functions and glue", "[external]")
REQUIRE(cnt == 3);
REQUIRE(out == "Call1 glued to Call 2\n");
out = thread->getline();
REQUIRE(out == "Call 3 is seperated\n");
REQUIRE(out == "Call 3 is separated\n");
REQUIRE(cnt == 4);
}
WHEN("the function is not lookahead save")
Expand All @@ -39,7 +39,7 @@ SCENARIO("A story with external functions and glue", "[external]")
REQUIRE(out == "glued to Call 2\n");
REQUIRE(cnt == 2);
out = thread->getline();
REQUIRE(out == "Call 3 is seperated\n");
REQUIRE(out == "Call 3 is separated\n");
REQUIRE(cnt == 3);
}
}
Expand Down
14 changes: 7 additions & 7 deletions inkcpp_test/MoveTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ SCENARIO("run a story, but jump around manually", "[move_to]")
REQUIRE(main->num_choices() == 1);
REQUIRE(main->get_choice(0)->text() == std::string("Hellow mister menistery"));
main->choose(0);
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you shold give up\n");
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you should give up\n");
}
}

WHEN("skip intorduction")
WHEN("skip introduction")
{
main->move_to(ink::hash_string("Dialog.core"));
THEN("expect output minus introduction")
Expand All @@ -41,7 +41,7 @@ SCENARIO("run a story, but jump around manually", "[move_to]")
REQUIRE(main->num_choices() == 1);
REQUIRE(main->get_choice(0)->text() == std::string("Hellow mister menistery"));
main->choose(0);
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you shold give up\n");
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you should give up\n");
}
}

Expand All @@ -57,7 +57,7 @@ SCENARIO("run a story, but jump around manually", "[move_to]")
REQUIRE(main->num_choices() == 1);
REQUIRE(main->get_choice(0)->text() == std::string("Hellow mister menistery"));
main->choose(0);
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you shold give up\n");
REQUIRE(main->getall() == "Hellow mister menistery\nYou are head to head to the minister\nIt seems you are out of options, you should give up\n");
}
}
WHEN("second runner modifies value")
Expand All @@ -71,10 +71,10 @@ SCENARIO("run a story, but jump around manually", "[move_to]")
REQUIRE(main->num_choices() == 1);
REQUIRE(main->get_choice(0)->text() == std::string("Roar"));
main->choose(0);
REQUIRE(main->getall() == "Grrrrh, Roarrr\nThe people are quit confused\nYou are head to head to the minister\nIt seems you are out of options, you shold give up\n");
REQUIRE(main->getall() == "Grrrrh, Roarrr\nThe people are quit confused\nYou are head to head to the minister\nIt seems you are out of options, you should give up\n");
}
}
WHEN("execute mutliple small runners with sideeffects")
WHEN("execute multiple small runners with sideeffects")
{
main->move_to(ink::hash_string("Dialog.core"));
side->move_to(ink::hash_string("Transformations.ToTiger"));
Expand All @@ -88,7 +88,7 @@ SCENARIO("run a story, but jump around manually", "[move_to]")
REQUIRE(main->num_choices() == 1);
REQUIRE(main->get_choice(0)->text() == std::string("Roar"));
main->choose(0);
REQUIRE(main->getall() == "Grrrrh, Roarrr\nThe people are quit confused\nYou are head to head to the minister\nIt seems you are out of options, you shold give up\n");
REQUIRE(main->getall() == "Grrrrh, Roarrr\nThe people are quit confused\nYou are head to head to the minister\nIt seems you are out of options, you should give up\n");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion inkcpp_test/ink/LookaheadSafe.ink
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Call1
~ foo()
<> glued to Call 2
~ foo()
Call 3 is seperated
Call 3 is separated
-> DONE
Loading
Loading