Skip to content

Instantly share code, notes, and snippets.

@drmeister
Created August 18, 2020 19:56
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 drmeister/4c45e76ae2e3783ee4a169375f583cde to your computer and use it in GitHub Desktop.
Save drmeister/4c45e76ae2e3783ee4a169375f583cde to your computer and use it in GitHub Desktop.
template <typename Pols , typename RT ,typename ARG0,typename ARG1,typename ARG2,typename ARG3,typename ARG4 >
class VariadicFunctor
< RT (*)(ARG0, ARG1, ARG2, ARG3, ARG4), Pols>
: public core::BuiltinClosure_O {
public:
typedef VariadicFunctor < RT (*)(ARG0, ARG1, ARG2, ARG3, ARG4), Pols> MyType;
typedef core::BuiltinClosure_O TemplatedBase;
public:
typedef RT(*Type)(ARG0, ARG1, ARG2, ARG3, ARG4);
Type fptr;
public:
virtual const char* describe() const { return "VariadicFunctor"; };
enum { NumParams = 5 };
VariadicFunctor(core::FunctionDescription* fdesc, Type ptr) : core::BuiltinClosure_O(entry_point,fdesc), fptr(ptr) {};
virtual size_t templatedSizeof() const { return sizeof(*this);};
static inline LCC_RETURN LISP_CALLING_CONVENTION()
{
MyType* closure = gctools::untag_general<MyType*>((MyType*)lcc_closure);
INCREMENT_FUNCTION_CALL_COUNTER(closure);
INITIALIZE_VA_LIST();
INVOCATION_HISTORY_FRAME();
MAKE_STACK_FRAME(frame,closure->asSmartPtr().raw_(),5);
MAKE_SPECIAL_BINDINGS_HOLDER(numSpecialBindings, specialBindingsVLA,
lisp_lambda_list_handler_number_of_specials(closure->_lambdaListHandler));
core::StackFrameDynamicScopeManager scope(numSpecialBindings,specialBindingsVLA,frame);
lambdaListHandler_createBindings(closure->asSmartPtr(),closure->_lambdaListHandler,scope,LCC_PASS_ARGS_LLH);
translate::from_object<ARG0,typename DoesNotContain_<Pols,pureOutValue<1> >::type > a0(frame->arg(0));
//IncWhen<typename DoesNotContain_<Pols,pureOutValue<1> >::type >::go(args);
translate::from_object<ARG1,typename DoesNotContain_<Pols,pureOutValue<2> >::type > a1(frame->arg(1));
//IncWhen<typename DoesNotContain_<Pols,pureOutValue<2> >::type >::go(args);
translate::from_object<ARG2,typename DoesNotContain_<Pols,pureOutValue<3> >::type > a2(frame->arg(2));
//IncWhen<typename DoesNotContain_<Pols,pureOutValue<3> >::type >::go(args);
translate::from_object<ARG3,typename DoesNotContain_<Pols,pureOutValue<4> >::type > a3(frame->arg(3));
//IncWhen<typename DoesNotContain_<Pols,pureOutValue<4> >::type >::go(args);
translate::from_object<ARG4,typename DoesNotContain_<Pols,pureOutValue<5> >::type > a4(frame->arg(4));
//IncWhen<typename DoesNotContain_<Pols,pureOutValue<5> >::type >::go(args);
RT retval = closure->fptr(a0._v,a1._v,a2._v,a3._v,a4._v);
core::MultipleValues& returnValues = core::lisp_multipleValues();
returnValues.setSize(0);
int oidx = 1;
ReturnValueWhen(returnValues,oidx
, typename is_outValue<Pols,0>::type()
, typename AdoptPointer<Pols,0>::type()
, a0._v);
ReturnValueWhen(returnValues,oidx
, typename is_outValue<Pols,1>::type()
, typename AdoptPointer<Pols,1>::type()
, a1._v);
ReturnValueWhen(returnValues,oidx
, typename is_outValue<Pols,2>::type()
, typename AdoptPointer<Pols,2>::type()
, a2._v);
ReturnValueWhen(returnValues,oidx
, typename is_outValue<Pols,3>::type()
, typename AdoptPointer<Pols,3>::type()
, a3._v);
ReturnValueWhen(returnValues,oidx
, typename is_outValue<Pols,4>::type()
, typename AdoptPointer<Pols,4>::type()
, a4._v);
return LCC_RETURN(translate::to_object<RT,typename AdoptPointer<Pols,result>::type >::convert(retval).raw_(),oidx);
}
}
@jasom
Copy link

jasom commented Aug 18, 2020

class FrameCollector {
    FrameType frame;
    int i;
    public:
        FrameCollector(FrameType f) : frame(f), i(0);
        template <typename T>
        auto operator()() {
            return T(frame->arg++);
        }
}

...
        core::StackFrameDynamicScopeManager scope(numSpecialBindings,specialBindingsVLA,frame);
        lambdaListHandler_createBindings(closure->asSmartPtr(),closure->_lambdaListHandler,scope,LCC_PASS_ARGS_LLH);
        FrameCollector fc(frame);
        std::make_tuple(fc<Args...>(), ...);

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment