-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e80b6fe
commit 832f74b
Showing
10 changed files
with
147 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef THORIN_PLUGIN_H | ||
#define THORIN_PLUGIN_H | ||
|
||
#include <memory> | ||
|
||
namespace thorin { | ||
class Def; | ||
class Continuation; | ||
class App; | ||
class World; | ||
|
||
struct plugin_intrinsic { | ||
virtual void transform(World* world, const Continuation* cont) = 0; | ||
virtual void destroy() = 0; | ||
|
||
protected: | ||
plugin_intrinsic() = default; | ||
plugin_intrinsic(const plugin_intrinsic&) = default; | ||
plugin_intrinsic(plugin_intrinsic&&) = default; | ||
plugin_intrinsic& operator =(const plugin_intrinsic&) = default; | ||
plugin_intrinsic& operator =(plugin_intrinsic&&) = default; | ||
~plugin_intrinsic() = default; | ||
}; | ||
|
||
struct plugin_deleter { | ||
void operator ()(plugin_intrinsic* ptr) const { | ||
ptr->destroy(); | ||
} | ||
}; | ||
|
||
using unique_plugin_intrinsic = std::unique_ptr<plugin_intrinsic, plugin_deleter>; | ||
|
||
extern "C" { | ||
using plugin_init_func_t = void(); | ||
using plugin_intrinsic_create_func_t = plugin_intrinsic*(); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef THORIN_PLUGIN_HELPERS_H | ||
#define THORIN_PLUGIN_HELPERS_H | ||
|
||
#include "plugin.h" | ||
#include "continuation.h" | ||
#include "world.h" | ||
|
||
namespace thorin { | ||
template <typename Plugin> | ||
class plugin_intrinsic_app_wrapper : public virtual plugin_intrinsic { | ||
virtual const Def* transform(World* world, const App* app) = 0; | ||
|
||
void transform(World* world, const Continuation* cont) final override { | ||
for (auto use : cont->copy_uses()) { | ||
if (!use.def()->isa<App>()) | ||
continue; | ||
|
||
auto app = use.def()->as<App>(); | ||
|
||
// transform plugin(mem, args, ret) to ret(mem, func(args)) | ||
|
||
auto output = static_cast<Plugin*>(this)->transform(world, app); | ||
|
||
auto app_rebuild = | ||
output ? app->rebuild(*world, world->bottom_type(), {app->arg(app->num_args() - 1), app->arg(0), output}) | ||
: app->rebuild(*world, world->bottom_type(), {app->arg(app->num_args() - 1), app->arg(0)}); | ||
|
||
app->replace_uses(app_rebuild); | ||
} | ||
} | ||
|
||
protected: | ||
plugin_intrinsic_app_wrapper() = default; | ||
plugin_intrinsic_app_wrapper(const plugin_intrinsic_app_wrapper&) = default; | ||
plugin_intrinsic_app_wrapper(plugin_intrinsic_app_wrapper&&) = default; | ||
plugin_intrinsic_app_wrapper& operator =(const plugin_intrinsic_app_wrapper&) = default; | ||
plugin_intrinsic_app_wrapper& operator =(plugin_intrinsic_app_wrapper&&) = default; | ||
~plugin_intrinsic_app_wrapper() = default; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters