// Add a wrapper for the named method that actually points to the trampoline // function so that the function will call back to the interpreter to actually // execute the method. Object repl_addmethod(Object self, int nparts, int *argcv, Object *args, int flags) { Object o = args[0]; Object objname = args[1]; gc_root(objname); Object methname = args[2]; gc_root(methname); int pos = integerfromAny(args[3]); Object(*func)(Object, int, int*, Object*, int); func = (Object(*)(Object, int, int*, Object*, int))trampoline; Method *m = add_Method(o->class, cstringfromString(methname), func); m->flags &= ~MFLAG_REALSELFONLY; m->flags |= MFLAG_REALSELFALSO; m->pos = pos; Object callinfo = alloc_List(); gc_root(callinfo); // ugly workaround gc_pause(); int largcv[] = {1}; callmethod(callinfo, "push", 1, largcv, &objname); callmethod(callinfo, "push", 1, largcv, &methname); gc_unpause(); adddatum2(o, callinfo, pos); return alloc_none(); }
Object cuda_do_infer(Object self, int nparts, int *argcv, Object *argv, int flags) { int argcv2[2]; Object argv2[argcv[0]]; for (int i=1; i<argcv[0]; i++) argv2[i-1] = argv[i]; argv2[argcv[0] - 1] = argv[0]; argcv2[0] = argcv[0] - 1; argcv2[1] = 1; return callmethod(self, "using()do", 2, argcv2, argv2); }
status docommand ( rpc::context& context, json::value& result, yieldstrategy const&) { boost::optional <handler const&> handler; if (auto error = fillhandler (context, handler)) { inject_error (error, result); return error; } if (auto method = handler->valuemethod_) return callmethod (context, method, handler->name_, result); return rpcunknown_command; }
Object cuda_do_dimensions_infer(Object self, int nparts, int *argcv, Object *argv, int flags) { int argcv2[6]; Object argv2[argcv[0] + 5]; for (int i=1; i<argcv[0]; i++) argv2[i-1] = argv[i]; argv2[argcv[0] - 1] = argv[0]; for (int i=argcv[0]; i<argcv[0]+4; i++) argv2[i] = argv[i]; argcv2[0] = argcv[0] - 1; argcv2[1] = 1; argcv2[2] = 1; argcv2[3] = 1; argcv2[4] = 1; argcv2[5] = 1; for (int i=2; i<nparts; i++) argcv[i] = argcv[i-1]; return callmethod(self, "using()do()blockWidth()blockHeight()gridWidth()gridHeight", 6, argcv2, argv2); }
static void raiseError(char *errstr) { Object a = alloc_String(errstr); int i = 1; callmethod(CudaError, "raise", 1, &i, &a); }
Object math_asDebugString(Object self, int nparts, int *argcv, Object *args, int flags) { return callmethod(self, "asString", 0, NULL, NULL); }
// This function will receive the name and target object of a method, // create the appropriate interactive objects for the interpreter and then // call back to the interpreter with them. This way the actual method gets // executed in the interpreter and we don't have to create functions at // runtime. Object trampoline(Object self, Object realself, int nparts, int *argcv, Object *args, int flags) { int pos = (flags >> 16) & 255; Object callinfo = getdatum(self, pos, 0); int largcv[] = {1}; Object idx1 = alloc_Integer32(1); Object idx2 = alloc_Integer32(2); Object objname = callmethod(callinfo, "at", 1, largcv, &idx1); Object methname = callmethod(callinfo, "at", 1, largcv, &idx2); Object replobjclass = callmethod(module_interactive, "replObj", 0, NULL, NULL); Object kind = alloc_String("value"); Object roargs[] = {kind, self}; int roargcv[] = {2}; Object selfreplobj = callmethod(replobjclass, "new", 1, roargcv, roargs); gc_root(selfreplobj); Object idclass = callmethod(module_ast, "identifierNode", 0, NULL, NULL); Object idargs[] = {objname, alloc_Boolean(0)}; int idargcv[] = {2}; Object selfid = callmethod(idclass, "new", 1, idargcv, idargs); gc_root(selfid); Object memberclass = callmethod(module_ast, "memberNode", 0, NULL, NULL); Object memberargs[] = {methname, selfid}; int memberargcv[] = {2}; Object methmember = callmethod(memberclass, "new", 1, memberargcv, memberargs); gc_root(methmember); Object withclass = callmethod(module_ast, "callWithPart", 0, NULL, NULL); Object with = alloc_List(); int i, j; int k = 0; int pushargcv[] = {1}; int withargcv[] = {2}; for (i = 0; i < nparts; i++) { Object curpart = alloc_List(); for (j = 0; j < argcv[i]; j++) { Object curarg = args[k]; callmethod(curpart, "push", 1, pushargcv, &curarg); k++; } Object withargs[] = {alloc_String(""), curpart}; Object withpart = callmethod(withclass, "new", 1, withargcv, withargs); gc_root(withpart); callmethod(with, "push", 1, pushargcv, &withpart); } gc_root(with); Object callclass = callmethod(module_ast, "callNode", 0, NULL, NULL); Object nodeargs[] = {methmember, with}; int nodeargcv[] = {2}; Object callnode = callmethod(callclass, "new", 1, nodeargcv, nodeargs); gc_root(callnode); int acceptargcv[] = {1}; callmethod(callnode, "accept", 1, acceptargcv, &visitor); Object replvar = callmethod(visitor, "_result", 0, NULL, NULL); return callmethod(replvar, "val", 0, NULL, NULL); }