|
|
|
@@ -7,56 +7,6 @@ define_array_list(String*, String); |
|
|
|
define_array_list(int, Int); |
|
|
|
define_array_list(void*, Void_Ptr); |
|
|
|
|
|
|
|
// ----------------------------- |
|
|
|
// <crazy lambda wrapper> |
|
|
|
// ----------------------------- |
|
|
|
// SOURCE: http://brnz.org/hbr/?p=1767 |
|
|
|
template<typename> |
|
|
|
struct TransientFunction; // intentionally not defined |
|
|
|
|
|
|
|
template<typename R, typename ...Args> |
|
|
|
struct TransientFunction<R(Args...)> |
|
|
|
{ |
|
|
|
using Dispatcher = R(*)(void*, Args...); |
|
|
|
|
|
|
|
Dispatcher m_Dispatcher; // A pointer to the static function that will call the |
|
|
|
// wrapped invokable object |
|
|
|
void* m_Target; // A pointer to the invokable object |
|
|
|
|
|
|
|
// Dispatch() is instantiated by the TransientFunction constructor, |
|
|
|
// which will store a pointer to the function in m_Dispatcher. |
|
|
|
template<typename S> |
|
|
|
static R Dispatch(void* target, Args... args) { |
|
|
|
return (*(S*)target)(args...); |
|
|
|
} |
|
|
|
|
|
|
|
template<typename T> |
|
|
|
TransientFunction(T&& target) |
|
|
|
: m_Dispatcher(&Dispatch<typename std::decay<T>::type>) |
|
|
|
, m_Target(&target) |
|
|
|
{} |
|
|
|
|
|
|
|
// Specialize for reference-to-function, to ensure that a valid pointer is |
|
|
|
// stored. |
|
|
|
using TargetFunctionRef = R(Args...); |
|
|
|
TransientFunction(TargetFunctionRef target) |
|
|
|
: m_Dispatcher(Dispatch<TargetFunctionRef>) |
|
|
|
{ |
|
|
|
static_assert(sizeof(void*) == sizeof target, |
|
|
|
"It will not be possible to pass functions by reference on this platform. " |
|
|
|
"Please use explicit function pointers i.e. foo(target) -> foo(&target)"); |
|
|
|
m_Target = (void*)target; |
|
|
|
} |
|
|
|
|
|
|
|
R operator()(Args... args) const { |
|
|
|
return m_Dispatcher(m_Target, args...); |
|
|
|
} |
|
|
|
}; |
|
|
|
// ----------------------------- |
|
|
|
// </crazy lambda wrapper> |
|
|
|
// ----------------------------- |
|
|
|
|
|
|
|
|
|
|
|
enum struct Lisp_Object_Type { |
|
|
|
Nil, |
|
|
|
T, |
|
|
|
@@ -157,10 +107,8 @@ struct Function { |
|
|
|
Environment* parent_environment; // we are doing closures now!! |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct Lambda_Wrapper { |
|
|
|
Lambda_Wrapper(TransientFunction<Lisp_Object* (Lisp_Object*, Environment*)> f) : function(f) {} |
|
|
|
TransientFunction<Lisp_Object* (Lisp_Object*, Environment*)> function; |
|
|
|
struct cFunction { |
|
|
|
std::function<Lisp_Object* (Lisp_Object*, Environment*)> function; |
|
|
|
}; |
|
|
|
|
|
|
|
struct Lisp_Object { |
|
|
|
@@ -173,7 +121,7 @@ struct Lisp_Object { |
|
|
|
String* string; |
|
|
|
Pair* pair; |
|
|
|
Function* function; |
|
|
|
Lambda_Wrapper* lambdaWrapper; |
|
|
|
cFunction* cFunction; |
|
|
|
} value; |
|
|
|
}; |
|
|
|
|
|
|
|
|