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
23 changes: 21 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ jobs:

# Upload results artifact
- name: Upload Results Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: results
path: proofing/ink-proof/${{ matrix.artifact }}.txt

# Upload website artifact
- name: Upload Ink-Proof Website Artifact
if: ${{ matrix.proof }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact }}-www
path: proofing/ink-proof/out
Expand All @@ -199,9 +199,28 @@ jobs:
python3 -m
pip install
build
pytest
--user
- name: Build python release
run: python3 -m build

- uses: suisei-cn/[email protected]
name: Download Inklecate
id: download_inklecate
with:
url: https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_linux.zip
target: "inklecate/"
- name: Deploy Inkelcate
shell: bash
run: |
cd inklecate
unzip *.zip
echo "INKLECATE=${{ matrix.inklecate_pre }}$GITHUB_WORKSPACE/inklecate/inklecate${{ matrix.inklecate_post }}" >> $GITHUB_ENV

- name: Test python release
run: |
python3 -m pip install dist/*.whl --user
python3 -m pytest
- name: Remove wheel
run: |
rm dist/*.whl
Expand Down
87 changes: 39 additions & 48 deletions inkcpp/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,47 @@

namespace ink::runtime::internal
{
functions::functions() : _list(nullptr), _last(nullptr)
{
}

functions::~functions()
{
// clean list
while (_list)
{
entry* toDelete = _list;
_list = _list->next;
functions::functions()
: _list(nullptr)
, _last(nullptr)
{
}

// delete both value and entry
delete toDelete->value;
delete toDelete;
}
_list = _last = nullptr;
functions::~functions()
{
// clean list
while (_list) {
entry* toDelete = _list;
_list = _list->next;

// delete both value and entry
delete toDelete->value;
delete toDelete;
}
_list = _last = nullptr;
}

void functions::add(hash_t name, function_base* func)
{
entry* current = new entry;
current->name = name;
current->value = func;
current->next = nullptr;

if (_list == nullptr)
{
_list = _last = current;
}
else
{
_last->next = current;
_last = current;
}
void functions::add(hash_t name, function_base* func)
{
entry* current = new entry;
current->name = name;
current->value = func;
current->next = nullptr;

if (_list == nullptr) {
_list = _last = current;
} else {
_last->next = current;
_last = current;
}
}

bool functions::call(hash_t name, basic_eval_stack* stack, size_t num_arguments, string_table& strings, list_table& lists)
{
// find entry
entry* iter = _list;
while (iter != nullptr && iter->name != name)
iter = iter->next;

// failed to find
if (iter == nullptr)
return false;

// call
iter->value->call(stack, num_arguments, strings, lists);
return true;
}
}
function_base* functions::find(hash_t name)
{
// find entry
entry* iter = _list;
while (iter != nullptr && iter->name != name)
iter = iter->next;
return iter == nullptr ? nullptr : iter->value;
}
} // namespace ink::runtime::internal
45 changes: 22 additions & 23 deletions inkcpp/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@

namespace ink::runtime::internal
{
class basic_eval_stack;
class basic_eval_stack;

// Stores bound functions
class functions
{
public:
functions();
~functions();

// Adds a function to the registry
void add(hash_t name, function_base* func);
// Stores bound functions
class functions
{
public:
functions();
~functions();

// Calls a function (if available)
bool call(hash_t name, basic_eval_stack* stack, size_t num_arguments, string_table& strings, list_table& lists);
// Adds a function to the registry
void add(hash_t name, function_base* func);

private:
struct entry
{
hash_t name;
function_base* value;
entry* next;
};
// Calls a function (if available)
function_base* find(hash_t name);

// TODO: Better than a linked list?
entry* _list;
entry* _last;
private:
struct entry {
hash_t name;
function_base* value;
entry* next;
};
}

// TODO: Better than a linked list?
entry* _list;
entry* _last;
};
} // namespace ink::runtime::internal
Loading