Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonSmith committed Mar 19, 2024
1 parent 4b028d0 commit 45babfb
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,57 @@
#include <cstring>
#include <optional> // Include the necessary header file

class CanonicalOptionsImpl : public CanonicalOptions
namespace cmcpp
{
private:
const GuestRealloc &_realloc;
const GuestPostReturn &_post_return;

public:
CanonicalOptionsImpl(const GuestMemory &memory, HostEncoding string_encoding,
const GuestRealloc &realloc, const GuestPostReturn &post_return)
: _realloc(realloc), _post_return(post_return)
{
this->memory = memory;
this->string_encoding = string_encoding;
}

int realloc(int ptr, int old_size, int align, int new_size)
class CanonicalOptionsImpl : public CanonicalOptions
{
return _realloc(ptr, old_size, align, new_size);
}
private:
const GuestRealloc &_realloc;
const GuestPostReturn &_post_return;

public:
CanonicalOptionsImpl(const GuestMemory &memory, HostEncoding string_encoding,
const GuestRealloc &realloc, const GuestPostReturn &post_return)
: _realloc(realloc), _post_return(post_return)
{
this->memory = memory;
this->string_encoding = string_encoding;
}

void post_return()
{
// Optional
if (_post_return)
int realloc(int ptr, int old_size, int align, int new_size)
{
return _realloc(ptr, old_size, align, new_size);
}

void post_return()
{
_post_return();
// Optional
if (_post_return)
{
_post_return();
}
}
};

CanonicalOptionsPtr createCanonicalOptions(const GuestMemory &memory, const GuestRealloc &realloc,
HostEncoding encoding,
const GuestPostReturn &post_return)
{
return std::make_shared<CanonicalOptionsImpl>(memory, encoding, realloc, post_return);
}
};

CanonicalOptionsPtr createCanonicalOptions(const GuestMemory &memory, const GuestRealloc &realloc,
HostEncoding encoding,
const GuestPostReturn &post_return)
{
return std::make_shared<CanonicalOptionsImpl>(memory, encoding, realloc, post_return);
}
class CallContextImpl : public CallContext
{
public:
CallContextImpl(CanonicalOptionsPtr options) { opts = options; }
};

class CallContextImpl : public CallContext
{
public:
CallContextImpl(CanonicalOptionsPtr options) { opts = options; }
};
CallContextPtr createCallContext(const GuestMemory &memory, const GuestRealloc &realloc,
HostEncoding encoding, const GuestPostReturn &post_return)
{
return std::make_shared<CallContextImpl>(
createCanonicalOptions(memory, realloc, encoding, post_return));
}

CallContextPtr createCallContext(const GuestMemory &memory, const GuestRealloc &realloc,
HostEncoding encoding, const GuestPostReturn &post_return)
{
return std::make_shared<CallContextImpl>(
createCanonicalOptions(memory, realloc, encoding, post_return));
}
}

0 comments on commit 45babfb

Please sign in to comment.