pythonFluIntegrationFunctionObject::pythonFluIntegrationFunctionObject
(
    const word& name,
    const Time& t,
    const dictionary& dict
)
    :
    pythonIntegrationFunctionObject(name,t,dict)
{
    if(parallelNoRun()) {
        return;
    }

    if(!executeCode("import Foam",false)) {
        FatalErrorIn("pythonFluIntegrationFunctionObject::pythonFluIntegrationFunctionObject")
                << "Python can not import module Foam. Probably no pythonFlu installed"
                << endl
                << exit(FatalError);
    }
    executeCode("import Foam.OpenFOAM as OpenFOAM",false,true);
    executeCode("import Foam.finiteVolume as finiteVolume",false,true);

    executeCode("from Foam.integrationHelpers.getObjectsFromPointers import getTimeFromPtr",false,true); // this should work, but doesn't
    // executeCode("from Foam.src.OpenFOAM.db.Time.Time import getTimeFromPtrOld as getTimeFromPtr",false,true); // This works

    PyObject *time=PyCObject_FromVoidPtr((void*)(&t),NULL);

    PyObject *m = PyImport_AddModule("__main__");
    PyObject_SetAttrString(m,"theTime",time);
    executeCode("time=getTimeFromPtr(theTime)",true,false);

    // Get rid of the helper stuff
    PyRun_SimpleString("del theTime");
    PyRun_SimpleString("del getTimeFromPtr");
}
Esempio n. 2
0
static status
ExecuteWhile(While w)
{ while ( executeCode(w->condition) )
  { if ( notNil(w->body) )
    { TRY( executeCode(w->body) );
    }
  }

  succeed;
}
void pythonIntegrationFunctionObject::writeSimple()
{
    Pbug << "writeSimple" << endl;

    if(!parallelNoRun()) {
        setRunTime();
    }

    executeCode(executeCode_,true);

    if(this->time_.outputTime()) {
        executeCode(writeCode_,true);
    }
}
Esempio n. 4
0
ErrorCode Process::allocateMemory(size_t size, uint32_t protection,
                                  uint64_t *address) {
  if (address == nullptr) {
    return kErrorInvalidArgument;
  }

  bool is32 = is32BitProcess(this);

  U8Vector codestr;
  if (is32) {
    X86Sys::PrepareMmapCode(size, protection, codestr);
  } else {
    X86_64Sys::PrepareMmapCode(size, protection, codestr);
  }

  uint64_t result;
  ErrorCode error = executeCode(codestr, result);
  if (error != kSuccess) {
    return error;
  }

  // MAP_FAILED is -1.
  if ((is32 && static_cast<int64_t>(result) == -1LL) ||
      (!is32 && static_cast<int32_t>(result) == -1)) {
    return kErrorNoMemory;
  }

  *address = result;
  return kSuccess;
}
Esempio n. 5
0
static Any
getExecuteWhen(When w)
{ if ( executeCode(w->condition) )
    return expandCodeArgument(w->then_branch);
  else
    return expandCodeArgument(w->else_branch);
}
void milxQtPythonConsole::executeLine(bool storeOnly)
{
    QTextCursor textCursor = this->textCursor();
    textCursor.movePosition(QTextCursor::End);

    // Select the text from the command prompt until the end of the block
    // and get the selected text.
    textCursor.setPosition(commandPromptPosition());
    textCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QString code = textCursor.selectedText();

    // i don't know where this trailing space is coming from, blast it!
    if (code.endsWith(" "))
    {
        code.truncate(code.length()-1);
    }

    if (!code.isEmpty())
    {
        // Update the history
        _history << code;
        _historyPosition = _history.count();
        _currentMultiLineCode += code + "\n";

        if (!storeOnly)
        {
            executeCode(_currentMultiLineCode);
            _currentMultiLineCode = "";
        }
    }
    // Insert a new command prompt
    appendCommandPrompt(storeOnly);

}
Esempio n. 7
0
ErrorCode Process::deallocateMemory(uint64_t address, size_t size) {
  if (size == 0) {
    return kErrorInvalidArgument;
  }

  U8Vector codestr;
  if (is32BitProcess(this)) {
    X86Sys::PrepareMunmapCode(address, size, codestr);
  } else {
    X86_64Sys::PrepareMunmapCode(address, size, codestr);
  }

  uint64_t result;
  ErrorCode error = executeCode(codestr, result);
  if (error != kSuccess) {
    return error;
  }

  // Negative values returned by the kernel indicate failure.
  if (static_cast<int32_t>(result) < 0) {
    return kErrorInvalidArgument;
  }

  return kSuccess;
}
Esempio n. 8
0
void jsTTY_t :: onLineIn( void )
{
   if( ( JSVAL_VOID != onLineInCode_ ) && ( JSVAL_VOID != onLineInScope_ ) )
   {
      lineQueue_.push_back( getLine() );
      executeCode( JSVAL_TO_OBJECT( onLineInScope_ ), onLineInCode_, "tty.onLineIn" );
   }
}
Esempio n. 9
0
/**
 * Execute the current selection from the editor.
 */
void ScriptFileInterpreter::executeSelection(const Script::ExecutionMode mode) {
  if ((m_editor->hasSelectedText() && (!m_editor->selectedText().isEmpty()))) {
    int firstLineOffset(0), unused(0);
    m_editor->getSelection(&firstLineOffset, &unused, &unused, &unused);
    executeCode(ScriptCode(m_editor->selectedText(), firstLineOffset), mode);
  } else {
    executeAll(mode);
  }
}
bool pythonIntegrationFunctionObject::end()
{
    Pbug << "end" << endl;

    if(!parallelNoRun()) {
        setRunTime();
    }

    return executeCode(endCode_,true);
}
bool pythonIntegrationFunctionObject::start()
{
    Pbug << "start" << endl;

    simpleFunctionObject::start();

    if(!parallelNoRun()) {
        setRunTime();
    }

    return executeCode(startCode_,true);
}
Esempio n. 12
0
void jsTouchPoll_t :: onRelease()
{
   debugPrint( "%s\n", __PRETTY_FUNCTION__);
   if( 0 != curBox_ )
   {
      gettimeofday(&releaseTime_,0);
      curBox_->onRelease_( *curBox_, prevX_, prevY_ );
      curBox_ = 0 ;
   } // touching, move or release box
   else if( JSVAL_VOID != onReleaseCode_ )
      executeCode( JSVAL_TO_OBJECT( onReleaseObject_ ), onReleaseCode_, "onRelease" );
   wasDown_ = false ;
   inputTouchScreen_t::onRelease();
}
Esempio n. 13
0
void jsPort_t :: onChar( void )
{
   jsval handler ;
   if( JS_GetProperty( execContext_, scope_, "onChar", &handler ) 
       &&
       ( JSTYPE_FUNCTION == JS_TypeOfValue( execContext_, handler ) ) )
   {
      executeCode( scope_, handler, "onChar", 0, 0 );
   } // have handler
   else
   {
      printf( "no raw data handler\n" );
      // clear input
      std::string sData ;
      read(sData);
   } // no handler defined
}
Esempio n. 14
0
void jsPort_t :: onLineIn( void )
{
   jsval handler ;
   if( JS_GetProperty( execContext_, scope_, "onLineIn", &handler ) 
       &&
       ( JSTYPE_FUNCTION == JS_TypeOfValue( execContext_, handler ) ) )
   {
      executeCode( scope_, handler, "onLineIn", 0, 0 );
   } // have handler
   else
   {
      printf( "no line input handler\n" );
      // clear input
      std::string sData ;
      while( readln( sData ) )
         ;
   } // no handler defined, purge input
}
Esempio n. 15
0
void jsUsblpPoll_t::onDataIn( void )
{
    jsval handler ;
    if( JS_GetProperty( execContext_, obj_, "onDataIn", &handler )
            &&
            ( JSTYPE_FUNCTION == JS_TypeOfValue( execContext_, handler ) ) )
    {
        executeCode( obj_, handler, "onDataIn", 0, 0 );
    } // have handler
    else
    {
        printf( "no raw data handler\n" );
        char temp[256];
        unsigned numRead ;
        while( read( temp, sizeof(temp), numRead ) )
            ;
    } // no handler defined
}
Esempio n. 16
0
void jsTouchPoll_t :: onMove( int x, int y )
{
   if( 0 != curBox_ )
   {
      if( ( x >= curBox_->xLeft_ )
          &&
          ( x <= curBox_->xRight_ )
          &&
          ( y >= curBox_->yTop_ )
          &&
          ( y <= curBox_->yBottom_ ) )
      {
         curBox_->onTouchMove_( *curBox_, x, y );
         return ;
      } // still on this button
      else
      {
         curBox_->onTouchMoveOff_( *curBox_, x, y );
         curBox_ = 0 ;
      } // moved off of the button
   } // have a box
   
   std::vector<box_t *> boxes = getZMap().getBoxes( x, y );
   if( 0 < boxes.size() )
   {
      curBox_ = boxes[0];
      curBox_->onTouch_( *boxes[0], x, y );
   }
   else
   {
      if( JSVAL_VOID != onMoveCode_ )
         executeCode( JSVAL_TO_OBJECT( onMoveObject_ ), onMoveCode_, "onMove" );
      else
      {
//         printf( "no touch handler %u/%u\n", x, y );
//         dumpZMaps();
      }
   } // no boxes... look for global handler
}
Esempio n. 17
0
void jsTouchPoll_t :: onTouch( unsigned x, unsigned y )
{
   debugPrint( "raw: %d/%d\n", x, y );
//   translate( x, y );
   debugPrint( "cooked: %d/%d\n", x, y );

   prevX_ = x ; // set here so code has access to it
   prevY_ = y ;

   if( 0 != curBox_ )
   {
      onMove( x, y );
   } // already touching, move or release
   else
   {
      gettimeofday(&touchTime_, 0);
      std::vector<box_t *> boxes = getZMap().getBoxes( x, y );
      if( 0 < boxes.size() )
      {
         curBox_ = boxes[0];
         curBox_->onTouch_( *boxes[0], x, y );
      }
      else
      {
         if( JSVAL_VOID != onTouchCode_ )
         {
            executeCode( JSVAL_TO_OBJECT( onTouchObject_ ), onTouchCode_, "onTouch" );
         }
         else
         {
//            printf( "no touch handler %u/%u\n", x, y );
//            dumpZMaps();
         }
      } // no boxes... look for global handler
   }

   wasDown_ = true ;
}
Esempio n. 18
0
int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
{
  //pow(sin(d),dpos)*1.7
  if (need_recompile)
  {
    int err=0;
    int x;
    EnterCriticalSection(&rcs);
    if (!var_b || g_reset_vars_on_recompile)
    {
      clearVars();
      var_x = registerVar("x");
      var_y = registerVar("y");
      var_w = registerVar("w");
      var_h = registerVar("h");
      var_b = registerVar("b");
      var_alpha = registerVar("alpha");
      inited=0;
    }
    need_recompile=0;
    for (x = 0; x < 3; x ++) 
    {
      freeCode(codehandle[x]);
      codehandle[x]=compileCode(effect_exp[x].get());
    }
    LeaveCriticalSection(&rcs);
  }
  *var_w=w;
  *var_h=h;
  *var_b=isBeat?1.0:0.0;

  if (isBeat&0x80000000) return 0;

  if (codehandle[0] && (!inited || m_lasth != h || m_lastw != w)) 
  { 
    m_lastw=w;
    m_lasth=h;
    *var_x=0; *var_y=0; *var_alpha=0.5; 
    executeCode(codehandle[0],visdata); 
    inited=1; 
  }

  executeCode(codehandle[1],visdata);
  if (isBeat) executeCode(codehandle[2],visdata);

  int doblend=blend;
  int ialpha=127;
  if (doblend)
  {
    ialpha=(int)(*var_alpha*255.0);
    if (ialpha <= 0) return 0;
    if (ialpha >= 255) doblend=0;
  }
  int *inptr=framebuffer;
  int *blendptr=framebuffer;
  int *outptr=fbout;
  int xa=(int)*var_x;
  int ya=(int)*var_y;
  
  // var_x, var_y at this point tell us how to shift, and blend also tell us what to do.
  if (!subpixel) 
  {
    int endy=h+ya;
    int endx=w+xa;
    int x,y;
    if (endx > w) endx=w;
    if (endy > h) endy=h;
    if (ya < 0) inptr += -ya*w;
    if (ya > h) ya=h;
    if (xa > w) xa=w;
    for (y = 0; y < ya; y ++)
    {
      x=w; 
      if (!doblend) while (x--) *outptr++ = 0;
      else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
    }
    for (; y < endy; y ++)
    {
      int *ip=inptr;
      if (xa < 0) inptr += -xa;
      if (!doblend)
      {
        for (x = 0; x < xa; x ++) *outptr++=0;
        for (; x < endx; x ++) *outptr++=*inptr++;
        for (; x < w; x ++) *outptr++=0;
      }
      else
      {
        for (x = 0; x < xa; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
        for (; x < endx; x ++) *outptr++ = BLEND_ADJ(*inptr++,*blendptr++,ialpha);
        for (; x < w; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
      }
      inptr=ip+w;
    }
    for (; y < h; y ++)
    {   
      x=w; 
      if (!doblend) while (x--) *outptr++ = 0;
      else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
    }
  }
  else // bilinear filtering version
  {
    
    int xpart,ypart;

    {
      double vx=*var_x;
      double vy=*var_y;
      xpart=(int) ((vx - (int)vx)*255.0);
      if (xpart < 0) xpart=-xpart;
      else { xa++; xpart=255-xpart; }
      if (xpart < 0) xpart=0;
      if (xpart > 255) xpart=255;

      ypart=(int) ((vy - (int)vy)*255.0);
      if (ypart < 0) ypart=-ypart;
      else { ya++; ypart=255-ypart; }
      if (ypart < 0) ypart=0;
      if (ypart > 255) ypart=255;
    }

    int x,y;
    if (ya < 1-h) ya=1-h;
    if (xa < 1-w) xa=1-w;
    if (ya > h-1) ya=h-1;
    if (xa > w-1) xa=w-1;
    if (ya < 0) inptr += -ya*w;
    int endy=h-1+ya;
    int endx=w-1+xa;
    if (endx > w-1) endx=w-1;
    if (endy > h-1) endy=h-1;
    if (endx < 0) endx=0;
    if (endy < 0) endy=0;
    for (y = 0; y < ya; y ++)
    {
      x=w; 
      if (!doblend) while (x--) *outptr++ = 0;
      else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
    }
    for (; y < endy; y ++)
    {
      int *ip=inptr;
      if (xa < 0) inptr += -xa;
      if (!doblend)
      {
        for (x = 0; x < xa; x ++) *outptr++=0;
        for (; x < endx; x ++) *outptr++=BLEND4((unsigned int *)inptr++,w,xpart,ypart);
        for (; x < w; x ++) *outptr++=0;
      }
      else
      {
        for (x = 0; x < xa; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
        for (; x < endx; x ++) *outptr++ = BLEND_ADJ(BLEND4((unsigned int *)inptr++,w,xpart,ypart),*blendptr++,ialpha);
        for (; x < w; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
      }
      inptr=ip+w;
    }
    for (; y < h; y ++)
    {   
      x=w; 
      if (!doblend) while (x--) *outptr++ = 0;
      else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha);
    }
  }
  #ifndef NO_MMX
    __asm emms;
  #endif

  return 1;
}
bool writeIfPythonFunctionObject::checkStopWriting()
{
    return executeCode(stopWriteCode_);
}
bool writeIfPythonFunctionObject::checkStopCooldown()
{
    return executeCode(stopCooldownCode_);
}
Esempio n. 21
0
/**
 * Execute the whole script in the editor.
 */
void ScriptFileInterpreter::executeAll(const Script::ExecutionMode mode)
{
  executeCode(m_editor->text(), mode);
}
Esempio n. 22
0
void jsMouse_t::onData( struct input_event const &event )
{
   assert( cursor_ );

   cursor_->getPos(x_,y_);

   switch( event.type ){
      case EV_SYN:
         cursor_->setPos(x_,y_);
         if( down_ ){
            press();
         }
         if( 0 != wheel_ ){
            printf( "wheel motion: %d\n", wheel_ );
            if( JSVAL_VOID != onWheelCode_ ){
               jsval args[2] = {
                  INT_TO_JSVAL(wheel_)
               ,  JSVAL_NULL
               };
               printf( "call handler here\n" );
               executeCode(JS_GetGlobalObject(execContext_),onWheelCode_, __func__, 1,args);
            } else
               printf( "No wheel handler\n" );
            wheel_ = 0 ;
         }
         break;
      case EV_REL: {
         if( (REL_X==event.code) || (REL_Y==event.code) ){
                 fbDevice_t &fb = getFB();
                 int value = (int)event.value ;
                 int pos = (int)( (REL_X == event.code) ? x_ : y_ );
                 int max = (int)( (REL_X == event.code) ? fb.getWidth() : fb.getHeight() ) - 1 ;
                 pos += value ;
                 if( 0 > pos )
                    pos = 0 ;
                 else if( max < pos ){
                    pos = max ;
                 }
                 if( REL_X == event.code )
                    x_ = pos ;
                 else
                    y_ = pos ;
                 cursor_->setPos(x_,y_);
         } else if(REL_WHEEL==event.code){
                 wheel_ += (int)event.value ;
         } else 
                 printf( "Unknown rel value, code 0x%x, value 0x%x\n", event.code, event.value );
         break;
      }
      case EV_KEY: {
         int down = event.value ;
         int left = ( event.code == LMOUSEBUTTON );
#if defined(KERNEL_FB_DAVINCI) && (KERNEL_FB_DAVINCI == 1)
         if( down ){
            cursor_->setWidth(SMALL);
            cursor_->setHeight(SMALL);
         }
         else {
            cursor_->setWidth(BIG);
            cursor_->setHeight(BIG);
         }
#endif

         if( left && ( down_ != down ) ){
            if( down ){
               press();
            }
            else {
               release();
            }
            down_ = down ;
         } // left button state changed

         break;
      }
      default:
         inputPoll_t::onData(event);
   }
}
Esempio n. 23
0
double runKernel(double externalTime) {
  
  double nextHit, timeElapsed; 

  Task *task, *temp, *oldrunning, *newrunning;
  UserTask *usertask;
  InterruptHandler *hdl;
  DataNode* dn;

  // If no energy, then we can not run
  if (rtsys->energyLevel <= 0) {
    //printf("Energy is out at time: %f\n", rtsys->time);
    return INF;
  }

  
  timeElapsed = externalTime - rtsys->prevHit; // time since last invocation
  rtsys->prevHit = externalTime;  // update previous invocation time
  nextHit = 0.0;

  //printf("runkernel at %f\n", rtsys->time);

#ifdef KERNEL_MATLAB
    /* Write rtsys pointer to global workspace */
  *((long *)mxGetPr(rtsys->rtsysptr)) = (long)rtsys;
#endif

  while (nextHit < EPS) {

    // Count down execution time for current task (usertask or handler)
    // and check if it has finished its execution 

    task = rtsys->running;
    if (task != NULL) {
      // Count down execution time 
      task->execTime -= timeElapsed * rtsys->cpuScaling;
      if (task->execTime < EPS) {
	// Execute next segment 
	task->segment++;

	if (task->isUserTask()) {
	  usertask = (UserTask*) task;
	  // Update budget and lastStart variable at segment change
	  usertask->budget -= (rtsys->time - usertask->lastStart);
	  usertask->lastStart = rtsys->time;
	}

	// Execute next segment of the code function

#ifndef KERNEL_MATLAB
	task->execTime = task->codeFcn(task->segment, task->data);
	if (rtsys->error) {
	  printf("Error in ==> task '%s', segment %d\n", task->name, task->segment);
	  return 0.0;
	}
#else
	if (task->codeFcnMATLAB == NULL) {
	  task->execTime = task->codeFcn(task->segment, task->data);
	} else {
	  task->execTime = executeCode(task->codeFcnMATLAB, task->segment, task);
	}
	if (rtsys->error) {
	  printf("Error in ==> task '%s', segment %d\n", task->name, task->segment);
	  return 0.0;
	}
#endif

	if (task->execTime < 0.0) { 
	  // Negative execution time = task finished
	  task->execTime = 0.0;
	  task->segment = 0;

	  if (task->myList == rtsys->readyQ) {
	    // Remove task from readyQ
	    task->remove();
	  }
	  
	  if (!(task->isUserTask())) {
	    hdl = (InterruptHandler*) task;

	    if (hdl->type == TIMER) {
	      if (hdl->timer->isPeriodic) {
		// if periodic timer put back in timeQ
		hdl->timer->time += hdl->timer->period;
		hdl->moveToList(rtsys->timeQ);
	      } else {
		// Remove timer and free up handler
		dn = getNode(hdl->timer->name, rtsys->timerList);
		rtsys->timerList->deleteNode(dn);
		delete hdl->timer;
		hdl->timer = NULL;
		hdl->type = UNUSED;
	      }
	    }
	    if (hdl->type == EXTERNAL) {
	      if (hdl->pending > 0) {
		// new external interrupt occured before handler finished
		hdl->pending--;
		hdl->moveToList(rtsys->readyQ);
	      }
	    }

	  } else { // the finished task is a usertask
	    usertask = (UserTask*) task;

	    // Execute finish-hook 
	    usertask->finish_hook(usertask);
	    usertask->state = IDLE;

	    // Release next job if any
	    usertask->nbrJobs--;
	    if (usertask->nbrJobs > 0) {
	      // next pending release
	      dn = (DataNode*) usertask->pending->getFirst();
	      double* release = (double*) dn->data;
	      usertask->release = *release;
	      usertask->absDeadline = *release + usertask->deadline;
	      usertask->moveToList(rtsys->timeQ);
	      usertask->pending->deleteNode(dn);
	      delete release;
	      // Execute release-hook 
	      usertask->release_hook(usertask);
	      usertask->state = SLEEPING;
	    
	    }
	  }
	}
      }
    } // end: counting down execution time of running task


    // Check time queue for possible releases

    task = (Task*) rtsys->timeQ->getFirst();
    while (task != NULL) {
      if ((task->wakeupTime() - rtsys->time) < EPS) {
	
	// Task to be released 
	temp = task;
	task = (Task*) task->getNext();
	temp->moveToList(rtsys->readyQ);
	
	if (temp->isUserTask()) {
	  usertask = (UserTask*) temp;
	  usertask->state = READY;

	}
      } else {
	break;
      }
    } // end: checking timeQ for releases


    // Determine task with highest priority and make it running task

    newrunning = (Task*) rtsys->readyQ->getFirst();
    oldrunning = rtsys->running;

    if (newrunning != NULL) {
      
      // Check for suspend- and resume-hooks
      
      if (oldrunning != NULL) {

	// Is oldrunning being suspended?
	if (oldrunning->isUserTask()) {
	  if (newrunning != oldrunning && ((UserTask*) oldrunning)->state == RUNNING) {
	    usertask = (UserTask*) oldrunning;
	    usertask->state = SUSPENDED;
	    usertask->suspend_hook(usertask);
	  }
	}
      }

      // invocation of hooks may have triggered kernelHandler
      newrunning = (Task*) rtsys->readyQ->getFirst();
      
      // Is newrunning being resumed?
      if (newrunning->isUserTask()) {
	if ( (((UserTask*) newrunning)->state == READY) || 
	     (((UserTask*) newrunning)->state == SUSPENDED) ) {
	  // newrunning is being resumed or started
	  usertask = (UserTask*) newrunning;
	  usertask->state = RUNNING;
	  if (usertask->segment == 0) {
	    usertask->start_hook(usertask);
	  } else {
	    usertask->resume_hook(usertask);
	  }
	}
      }

      // invocation of hooks may have triggered kernelHandler
      rtsys->running = (Task*) rtsys->readyQ->getFirst();
      
    } else { // No tasks in readyQ
      
      rtsys->running = NULL;
      
    } // end: task dispatching
    

    // Determine next invocation of kernel
    nextHit = getNextInvocation();
    timeElapsed = 0.0;
    
  } // end: loop while nextHit < EPS

  return nextHit;
}
Esempio n. 24
0
/**
 * Execute the whole script in the editor. Always clears the contents of the
 * local variable dictionary first.
 */
void ScriptFileInterpreter::executeAll(const Script::ExecutionMode mode) {
  m_runner->clearLocals();
  executeCode(ScriptCode(m_editor->text()), mode);
}
Esempio n. 25
0
int main()
{
	int mark, o;
	unsigned char c;
	rmdata *realmachine;
	vmdata *virtualmachine;
	realmachine = malloc(sizeof(rmdata));
	virtualmachine = malloc(sizeof(vmdata));

	SetConsoleTitle(LTITLE);
	strcpy(text, "");
	mode = 1;

	clearRReg(realmachine, 0);
	clearVReg(virtualmachine, 0);
	clearRRam(realmachine, 0xFF);
	clearVRam(virtualmachine, 0xFF);

	callUpdateAndDraw(realmachine, virtualmachine);
	while(1)
	{
		if(mode == 0)
		{
			sprintf(text, "%sExec command: %X\n", text, realmachine->ram[absoluteAdress(realmachine,virtualmachine->IP)]);
			o = executeCode(realmachine, virtualmachine, absoluteAdress(realmachine,virtualmachine->IP), absoluteAdress(realmachine,virtualmachine->IP + 1));
			if(o == 1)
			{
				virtualmachine->IP++;
			}
			else if(o == 'G')
			{
				realmachine->TI = 1;
				callUpdateAndDraw(realmachine, virtualmachine);
				mark = realmachine->ram[absoluteAdress(realmachine,virtualmachine->IP + 1)];
				c = 0;
				while(c != 0x0D)
				{
					if(c)
					{
						realmachine->ram[absoluteAdress(realmachine, mark)] = c;
						sprintf(text, "%s%c", text, c);
						mark++;
					}
					c = getProgramInput();
					callUpdateAndDraw(realmachine, virtualmachine);
				}
				realmachine->ram[absoluteAdress(realmachine, mark)] = 0;
				strcat(text, "\n");
				virtualmachine->IP++;
				realmachine->TI = 0;
			}
			else if(o == 'P')
			{
				virtualmachine->IP++;
				mark = realmachine->ram[absoluteAdress(realmachine,virtualmachine->IP)];
				while((c = realmachine->ram[absoluteAdress(realmachine, mark)]) != 0x00)
				{
					sprintf(text, "%s%c", text, c);
					mark++;
				}
				strcat(text, "\n");
			}
			else if(o == 'H')
			{
				mode = 2;
				strcat(text, "Program ended successfully.\n");
			}
			else if(o == 255)
			{
				mode = 2;
				realmachine->PI = 1;
				strcat(text, "Error, program ended unsuccessfully!\n");
			}
			if(o != 'J')
			{
				virtualmachine->IP++;
			}
			if(realmachine->MODE)
			{
				strcat(text, "Press ENTER key...");
				callUpdateAndDraw(realmachine, virtualmachine);
				while(getchar() != '\n');
				strcat(text, "\n");
			}
			else
			{
				callUpdateAndDraw(realmachine, virtualmachine);
			}
		}
		else if(mode == 1)
		{
			c = getProgramInput();
			if(c && c != '`' && c != 0x0D)
			{
				sprintf(text, "%s%c", text, c);
			}
			if(c == 0x0D)
			{
				if(strcmp(text, "quit") == 0 || strcmp(text, "exit") == 0 || strcmp(text, "e") == 0 || strcmp(text, "q") == 0)
				{
					break;
				}
				else if(strcmp(text, "start") == 0 || strcmp(text, "s") == 0)
				{
					mode = 0;
				}
				else if(strcmp(text, "step") == 0)
				{
					if(realmachine->MODE)
					{
						realmachine->MODE = 0;
					}
					else
					{
						realmachine->MODE = 1;
					}
				}
				else if(strcmp(text, "reset") == 0 || strcmp(text, "r") == 0)
				{
					clearRReg(realmachine, 0);
					clearVReg(virtualmachine, 0);
					clearRRam(realmachine, 0xFF);
					clearVRam(virtualmachine, 0xFF);
				}
				if(strcmp(text, "cls") == 0)
				{
					system("cls");
				}
				else if(strncmp(text, "loadfile", 8) == 0)
				{
					fileToRam(realmachine, text + 9);
				}
				else if(strcmp(text, "load") == 0 || strcmp(text, "l") == 0)
				{
					fileToRam(realmachine, HDDFILE);
				}
				strcpy(text, "");
			}
			callUpdateAndDraw(realmachine, virtualmachine);
		}
		else if(mode == 2)
		{
			//strcat(text, "Press ENTER key...");
			//callUpdateAndDraw(realmachine, virtualmachine);
			//while(getchar() != '\n');
			system("pause");
			strcpy(text, "");
			mode = 1;
			system("cls");
			callUpdateAndDraw(realmachine, virtualmachine);
		}
	}

	return 0;
}