コード例 #1
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
 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;
 }
コード例 #2
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
 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);
 }
コード例 #3
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
   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;
   }
コード例 #4
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
   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);
      }


   }
コード例 #5
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
   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;
   }
コード例 #6
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
   ::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();
   }
コード例 #7
0
ファイル: ArrayBuiltin.cpp プロジェクト: cbatson/hxcpp
   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;
   }