ASFUNCTIONBODY(Vector, some) { if (argslen < 1) throw Class<ArgumentError>::getInstanceS("Error #1063"); if (!args[0]->is<IFunction>()) throw Class<TypeError>::getInstanceS("Error #1034"); Vector* th=static_cast<Vector*>(obj); IFunction* f = static_cast<IFunction*>(args[0]); ASObject* params[3]; ASObject *funcRet; for(unsigned int i=0; i < th->size(); i++) { if (!th->vec[i]) continue; params[0] = th->vec[i]; th->vec[i]->incRef(); params[1] = abstract_i(i); params[2] = th; th->incRef(); if(argslen==1) { funcRet=f->call(getSys()->getNullRef(), params, 3); } else { args[1]->incRef(); funcRet=f->call(args[1], params, 3); } if(funcRet) { if(Boolean_concrete(funcRet)) { return funcRet; } funcRet->decRef(); } } return abstract_b(false); }
ASFUNCTIONBODY(Vector, some) { if (argslen < 1) throwError<ArgumentError>(kWrongArgumentCountError, "Vector.some", "1", Integer::toString(argslen)); if (!args[0]->is<IFunction>()) throwError<TypeError>(kCheckTypeFailedError, args[0]->getClassName(), "Function"); Vector* th=static_cast<Vector*>(obj); IFunction* f = static_cast<IFunction*>(args[0]); ASObject* params[3]; ASObject *funcRet; for(unsigned int i=0; i < th->size(); i++) { if (!th->vec[i]) continue; params[0] = th->vec[i]; th->vec[i]->incRef(); params[1] = abstract_i(i); params[2] = th; th->incRef(); if(argslen==1) { funcRet=f->call(getSys()->getNullRef(), params, 3); } else { args[1]->incRef(); funcRet=f->call(args[1], params, 3); } if(funcRet) { if(Boolean_concrete(funcRet)) { return funcRet; } funcRet->decRef(); } } return abstract_b(false); }
ASFUNCTIONBODY(Array,filter) { Array* th=static_cast<Array*>(obj); assert_and_throw(argslen==1 || argslen==2); IFunction* f = static_cast<IFunction*>(args[0]); ASObject* params[3]; Array* ret=Class<Array>::getInstanceS(); ASObject *funcRet; std::map<uint32_t, data_slot>::iterator it=th->data.begin(); for(;it != th->data.end();++it) { assert_and_throw(it->second.type==DATA_OBJECT); params[0] = it->second.data; it->second.data->incRef(); params[1] = abstract_i(it->first); params[2] = th; th->incRef(); if(argslen==1) { funcRet=f->call(getSys()->getNullRef(), params, 3); } else { args[1]->incRef(); funcRet=f->call(args[1], params, 3); } if(funcRet) { if(Boolean_concrete(funcRet)) { it->second.data->incRef(); ret->push(_MR(it->second.data)); } funcRet->decRef(); } } return ret; }
ASFUNCTIONBODY(Array,filter) { Array* th=static_cast<Array*>(obj); assert_and_throw(argslen==1 || argslen==2); IFunction* f = static_cast<IFunction*>(args[0]); ASObject* params[3]; Array* ret=Class<Array>::getInstanceS(); ASObject *funcRet; for(unsigned int i=0;i<th->data.size();i++) { assert_and_throw(th->data[i].type==DATA_OBJECT); params[0] = th->data[i].data; th->data[i].data->incRef(); params[1] = abstract_i(i); params[2] = th; th->incRef(); if(argslen==1) { funcRet=f->call(new Null, params, 3); } else { args[1]->incRef(); funcRet=f->call(args[1], params, 3); } if(funcRet) { if(Boolean_concrete(funcRet)) { th->data[i].data->incRef(); ret->push(th->data[i].data); } funcRet->decRef(); } } return ret; }
ASFUNCTIONBODY(Vector,forEach) { if (argslen < 1) throw Class<ArgumentError>::getInstanceS("Error #1063"); if (!args[0]->is<IFunction>()) throw Class<TypeError>::getInstanceS("Error #1034"); Vector* th=static_cast<Vector*>(obj); IFunction* f = static_cast<IFunction*>(args[0]); ASObject* params[3]; for(unsigned int i=0; i < th->size(); i++) { if (!th->vec[i]) continue; params[0] = th->vec[i]; th->vec[i]->incRef(); params[1] = abstract_i(i); params[2] = th; th->incRef(); ASObject *funcret; if( argslen == 1 ) { funcret=f->call(new Null, params, 3); } else { args[1]->incRef(); funcret=f->call(args[1], params, 3); } if(funcret) funcret->decRef(); } return NULL; }