Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental Ink Thread Implementation #4

Merged
merged 9 commits into from
Jan 21, 2021
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ thread->choose(0);
```

## Current Status
`inkcpp.cpp` has a `main()` function which compiles `test.json` -> `test.bin` and executes it using standard output and input.
Run `inkcpp_cl.exe -p myfile.json` to execute a compiled Ink JSON file in play mode. It can also operate on `.ink` files but `inklecate.exe` must me in the same folder or in the PATH.

Many, but not all features of the Ink language are supported (see Glaring Omissions below).
Without the `-p` flag, it'll just compile the JSON/Ink file into InkCPP's binary format (see the Wiki on GitHub).

Many, but not all features of the Ink language are supported (see Glaring Omissions below), but be warned, this runtime is still highly unstable. I am currently working on getting it to pass all the unit tests on [ink-proof](https://github.com/chromy/ink-proof).

* Temporary and global variables
* Int, String, or Divert values
Expand All @@ -57,6 +59,7 @@ Many, but not all features of the Ink language are supported (see Glaring Omissi
* Global store that can be shared between runners
* External function binding (no fallback support yet)
* Tunnels and internal functions
* Ink threads (probably incredibly unstable though)

## CMake
Project is organized using `cmake`. Just run `cmake` and it should configure all the projects properly into a runtime, compiler, and command line project.
Expand All @@ -75,7 +78,6 @@ Part of that involves slowly migrating all the unit tests from the main inkle in
The big things we're missing right now are:

* Fallback functions for externals.
* Threads
* Variable observers
* Lists and whatever cool, crazy stuff Ink has been adding recently.

Expand Down
5 changes: 5 additions & 0 deletions inkcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

list(APPEND SOURCES
collections/restorable.h
collections/restorable.cpp
array.h
choice.cpp
functional.cpp
Expand All @@ -14,6 +18,7 @@ list(APPEND SOURCES
value.h value.cpp
string_table.h string_table.cpp avl_array.h
)
source_group(Collections REGULAR_EXPRESSION collections/.*)
add_library(inkcpp ${SOURCES})

# Make sure the include directory is included
Expand Down
27 changes: 27 additions & 0 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace ink::runtime::internal
void restore();
void forget();

// Resets all values and clears any save points
void clear(const T& value);

protected:
inline T* buffer() { return _array; }

Expand Down Expand Up @@ -131,6 +134,30 @@ namespace ink::runtime::internal
}
}

template<typename T>
inline void basic_restorable_array<T>::clear(const T& value)
{
_saved = false;
for (size_t i = 0; i < _capacity; i++)
{
_temp[i] = null;
_array[i] = value;
}
}

template<typename T, size_t SIZE>
class fixed_restorable_array : public basic_restorable_array<T>
{
public:
fixed_restorable_array(const T& initial) : basic_restorable_array<T>(_buffer, SIZE * 2)
{
clear(initial);
}

private:
T _buffer[SIZE * 2];
};

template<typename T>
class allocated_restorable_array : public basic_restorable_array<T>
{
Expand Down
3 changes: 2 additions & 1 deletion inkcpp/choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ink
{
namespace runtime
{
void choice::setup(internal::basic_stream& in, internal::string_table& strings, int index, uint32_t path)
void choice::setup(internal::basic_stream& in, internal::string_table& strings, int index, uint32_t path, thread_t thread)
{
// if we only have one item in our output stream
if (in.queued() == 2)
Expand All @@ -32,6 +32,7 @@ namespace ink
// Index/path
_index = index;
_path = path;
_thread = thread;
}
}
}
Empty file.
Loading