Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/81cd2d3dd1a394eafa7c to your computer and use it in GitHub Desktop.
Save rightfold/81cd2d3dd1a394eafa7c to your computer and use it in GitHub Desktop.
class Subroutine : public Value {
public:
template<typename F>
explicit Subroutine(F slow)
: slow(std::move(slow)), fast(), fastAvailable(false) { }
boost::intrusive_ptr<Value> operator()(VM& vm, std::size_t argc, Value** argv) {
if (fastAvailable) {
return fast(vm, argc, argv);
} else {
return slow(vm, argc, argv);
}
}
std::function<boost::intrusive_ptr<Value>(VM&, std::size_t, Value**)> slow;
std::function<boost::intrusive_ptr<Value>(VM&, std::size_t, Value**)> fast;
std::atomic<bool> fastAvailable;
};
subroutineValue.fast = jitCompile(vm, object, bodyReader);
subroutineValue.fastAvailable = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment