double * val_array_double(hx::Object * arg1) { Array_obj<double> *a = dynamic_cast< Array_obj<double> * >(arg1); if (a==0) return 0; return (double *)a->GetBase(); }
float * val_array_float(hx::Object * arg1) { Array_obj<float> *a = dynamic_cast< Array_obj<float> * >(arg1); if (a==0) return 0; return (float *)a->GetBase(); }
/** file_contents : f:string -> string <doc>Read the content of the file [f] and return it.</doc> **/ static value file_contents( value name ) { using namespace Kore; buffer s=0; int len; val_check(name,string); fio f(val_filename(name)); const char* fname = val_string(name); gc_enter_blocking(); { FileReader file; if (file.open(fname)) { len = static_cast<int>(file.size()); #ifdef SYS_WIIU void* data = file.readAll(); Array_obj<unsigned char>* b = new Array_obj<unsigned char>(len, len); memcpy(b->GetBase(), data, len); s = (buffer)b; #else s = alloc_buffer_len(len); file.read(buffer_data(s), static_cast<uint>(len)); #endif } else { file_error("file_contents", &f); } } gc_exit_blocking(); return buffer_val(s); }
// Array access - fast if possible - may return null // Resizing the array may invalidate the pointer bool * val_array_bool(hx::Object * arg1) { Array_obj<bool> *a = dynamic_cast< Array_obj<bool> * >(arg1); if (a==0) return 0; return (bool *)a->GetBase(); }
hx::Object *runObject(CppiaCtx *ctx) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); BCR_CHECK; ELEM &elem = thisVal->Item(i); FUNC::run(elem, ctx, args[1]); return Dynamic(elem).mPtr; }
String runString(CppiaCtx *ctx) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); BCR_CHECK; ELEM &elem = thisVal->Item(i); FUNC::run(elem, ctx, args[1]); return ValToString(elem); }
Float runFloat(CppiaCtx *ctx) { if (FUNC==afPop) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToFloat(thisVal->pop()); } if (FUNC==afShift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToFloat(thisVal->shift()); } if (FUNC==af__get) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToFloat(thisVal->__get(args[0]->runInt(ctx))); } if (FUNC==af__set) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); ELEM elem; runValue(elem,ctx,args[1]); BCR_CHECK; thisVal->Item(i) = elem; return ValToFloat(elem); } if (FUNC==af__crement) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); ELEM &elem = thisVal->Item(args[0]->runInt(ctx)); return ValToFloat(CREMENT::run(elem)); } if (FUNC==afPush) return runInt(ctx); return 0.0; }
void runVoid(CppiaCtx *ctx) { if (FUNC==afPop) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; thisVal->pop(); } if (FUNC==afShift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; thisVal->shift(); } if (FUNC==af__set) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; int i = args[0]->runInt(ctx); BCR_VCHECK; ELEM elem; thisVal->Item(i) = runValue(elem,ctx,args[1]); } if (FUNC==af__crement) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; int idx = args[0]->runInt(ctx); BCR_VCHECK; ELEM &elem = thisVal->Item(idx); CREMENT::run(elem); } if (FUNC==afPush || FUNC==afRemove) runInt(ctx); if (FUNC==afConcat || FUNC==afCopy || FUNC==afReverse || FUNC==afSplice || FUNC==afSlice || FUNC==afMap || FUNC==afFilter) runObject(ctx); if (FUNC==afReverse) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; thisVal->reverse(); } if (FUNC==afSort) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; hx::Object * func = args[0]->runObject(ctx); BCR_VCHECK; thisVal->sort(func); } if (FUNC==afInsert) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; int pos = args[0]->runInt(ctx); BCR_VCHECK; ELEM elem; runValue(elem,ctx,args[1]); BCR_VCHECK; thisVal->insert(pos,elem); } if (FUNC==afUnshift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_VCHECK; ELEM elem; runValue(elem,ctx,args[0]); BCR_VCHECK; thisVal->unshift(elem); } }
hx::Object *runObject(CppiaCtx *ctx) { if (FUNC==af__get) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; return thisVal->__GetItem(idx).mPtr; } if (FUNC==af__set) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); BCR_CHECK; ELEM elem; thisVal->Item(i) = runValue(elem,ctx,args[1]); return Dynamic(elem).mPtr; } if (FUNC==af__crement) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; ELEM &elem = thisVal->Item(idx); return Dynamic(CREMENT::run(elem)).mPtr; } if (FUNC==afPop) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return Dynamic(thisVal->pop()).mPtr; } if (FUNC==afShift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return Dynamic(thisVal->shift()).mPtr; } if (FUNC==afConcat) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; Array_obj<ELEM> *inVal = (Array_obj<ELEM>*)args[0]->runObject(ctx); BCR_CHECK; return thisVal->concat(inVal).mPtr; } if (FUNC==afCopy) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return thisVal->copy().mPtr; } if (FUNC==afSplice) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int pos = args[0]->runInt(ctx); BCR_CHECK; int end = args[1]->runInt(ctx); BCR_CHECK; return thisVal->splice(pos,end).mPtr; } if (FUNC==afSlice) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int pos = args[0]->runInt(ctx); BCR_CHECK; hx::Object *end = args[1]->runObject(ctx); BCR_CHECK; return thisVal->slice(pos,end).mPtr; } if (FUNC==afMap) { // TODO - maybe make this more efficient Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; hx::Object *func = args[0]->runObject(ctx); BCR_CHECK; Array<ELEM> result = thisVal->map(func); return result.mPtr; } if (FUNC==afFilter) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; hx::Object *func = args[0]->runObject(ctx); BCR_CHECK; return thisVal->filter(func).mPtr; } if (FUNC==afIterator) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return thisVal->iterator().mPtr; } if (FUNC==afPush) return Dynamic(runInt(ctx)).mPtr; if (FUNC==afRemove) return Dynamic((bool)runInt(ctx)).mPtr; if (FUNC==afJoin) return Dynamic(runString(ctx)).mPtr; return 0; }
::String runString(CppiaCtx *ctx) { if (FUNC==afPop) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToString(thisVal->pop()); } if (FUNC==afShift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToString(thisVal->shift()); } if (FUNC==af__get) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; return ValToString(thisVal->__get(idx)); } if (FUNC==af__set) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[1]); BCR_CHECK; return ValToString( thisVal->Item(i) = elem); } if (FUNC==af__crement) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; ELEM &elem = thisVal->Item(idx); return ValToString(CREMENT::run(elem)); } if (FUNC==afJoin) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; String space = args[0]->runString(ctx); BCR_CHECK; return thisVal->join(space); } if (FUNC==afToString) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return thisVal->toString(); } if (FUNC==afPush) return Dynamic(runInt(ctx))->toString(); return runObject(ctx)->toString(); }
int runInt(CppiaCtx *ctx) { if (FUNC==afPush) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[0]); BCR_CHECK; int result = thisVal->push(elem); return result; } if (FUNC==afPop) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToInt(thisVal->pop()); } if (FUNC==afShift) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; return ValToInt(thisVal->shift()); } if (FUNC==afRemove) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[0]); BCR_CHECK; return thisVal->remove(elem); } if (FUNC==afIndexOf) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[0]); BCR_CHECK; hx::Object *start = args[1]->runObject(ctx); BCR_CHECK; return thisVal->indexOf(elem,start); } if (FUNC==afLastIndexOf) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[0]); BCR_CHECK; hx::Object *start = args[1]->runObject(ctx); BCR_CHECK; return thisVal->lastIndexOf(elem, start); } if (FUNC==af__get) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; return ValToInt(thisVal->__get(idx)); } if (FUNC==af__set) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int i = args[0]->runInt(ctx); BCR_CHECK; ELEM elem; runValue(elem,ctx,args[1]); BCR_CHECK; thisVal->Item(i) = elem; return ValToInt(elem); } if (FUNC==af__crement) { Array_obj<ELEM> *thisVal = (Array_obj<ELEM>*)thisExpr->runObject(ctx); BCR_CHECK; int idx = args[0]->runInt(ctx); BCR_CHECK; ELEM &elem = thisVal->Item(idx); return ValToInt(CREMENT::run(elem)); } return 0; }