void EmcAdapter::gatherDeviceData()
{
  if (!mConnected)
  {
    if (!connect())
      sleep(5);
    else
      mAvail.available();
  }
  else
  {
    if (!mEmcStatusBuffer->valid())
    {
      disconnect();
      return;
    }
    
    if(mEmcStatusBuffer->peek() == EMC_STAT_TYPE) {
      memcpy(&mEmcStatus, mEmcStatusBuffer->get_address(), sizeof(EMC_STAT));
      actual();
      commanded();
      spindle();
      feedrate();
      program();
      machine();
      execution();
      alarms();
    }
  } 
}
예제 #2
0
std::vector<CLProgram::CLExecutionPtr> CLProgram::enqueue_work(const CLDevice& device, const std::string& kernelFnName,
	size_t globalWorkSize, size_t localWorkSize)
{
	std::vector<CLProgram::CLExecutionPtr> executions;
	KernalMap::const_iterator fItr = _kernals.find(kernelFnName);
	if(fItr == _kernals.end())
		return executions;

	if(globalWorkSize < localWorkSize)
	{
		localWorkSize = globalWorkSize;
	}
	else
	{
		div_t divRes = ::div((int)globalWorkSize, (int)localWorkSize);
		if(divRes.rem == 0)
			globalWorkSize = localWorkSize * divRes.quot;
		else
			globalWorkSize = localWorkSize * (divRes.quot + 1);
	}
	CLExecutionPtr execution(new CLExecution(0, globalWorkSize, localWorkSize));
	_lastError = ::clEnqueueNDRangeKernel(device.queue, fItr->second.kernel, 1, 
		NULL, &execution->globalWorkSize, &execution->localWorkSize, 0, NULL, &(execution->event));
	if(_lastError != CL_SUCCESS)
	{
		std::cout << "::clEnqueueNDRangeKernel error." << std::endl;
		return executions;
	}
	add_event(execution);
	executions.push_back(execution);

	return executions;
}
예제 #3
0
//main
int main( int argc , char *argv[])
{


execution(argc,argv);

return 0;
}
예제 #4
0
//main
int main( int argc , char *argv[])
{

//char hellp[10];
//stccpy();
execution(argc,argv);

return 0;
}
예제 #5
0
파일: execution.c 프로젝트: GhaisB/42sh
void		execution(t_pars *pars, t_glob *glob)
{
  if (pars && pars->token && my_match(pars->token, PIPE))
    do_fork_pipe(pars->left, glob);
  else
    {
      if (pars->left && pars->left->token)
	execution(pars->left, glob);
      else if (pars->left && pars->token && (!my_match(pars->token, PIPE)))
	if (!execute_member(pars->left, pars->token, glob, 0))
	  return ;
      if (pars->right && pars->right->token)
	execution(pars->right, glob);
      else if (pars->right && pars->token && (!my_match(pars->token, PIPE)))
	if (!execute_member(pars->right, pars->token, glob, 1))
	  return ;
    }

}
예제 #6
0
파일: render.c 프로젝트: consultit/geomorph
void render_pov(render_struct *rs) {
	// buf is the string array passed to the exec function
	// It MUST have one index more than the number of required arguments,
	// and the last index MUST be NULL
	static char *buf[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
	
	save_render_options_inc (rs);
	
	// 2004-12-23 Arguments separated for compatibility with MDK10.1
	buf[0] = RENDERER;
	buf[1] = (gchar *) malloc(strlen(SCENE)+5);
	buf[2] = (gchar *) malloc(15);
	buf[3] = (gchar *) malloc(15);
	buf[4] = (gchar *) malloc(strlen(*rs->filename)+strlen(OUTPUT_PREFIX)+5);
	buf[5] = (gchar *) malloc(strlen(POV_DIR)+5);
	buf[6] = OTHER_RENDER_OPTIONS;
	sprintf(buf[1],"+I%s",SCENE);
	sprintf(buf[2],"+W%05d",RENDER_WIDTH);
	sprintf(buf[3],"+H%05d",RENDER_HEIGHT);
	sprintf(buf[4],"+O%s%s",OUTPUT_PREFIX,*rs->filename);
	sprintf(buf[5],"+L%s",POV_DIR);
	
//	printf("CURRENT_DIR: %s\n",get_current_dir_name());
//	printf("POV: %s str: %s; W: %s; H: %s; Output: %s; POV_DIR: %s; RENDER_OPTIONS: %s\n",buf[0], buf[1],buf[2],buf[3], buf[4], buf[5], buf[6]);
//	printf("HF_OUTPUT_FOR_RENDERING: %s\n",HF_OUTPUT_FOR_RENDERING);

	rs->povray_pid = execution(buf[0],buf);
	
//	printf("PID: %d\n",rs->povray_pid);
	if (buf[1]) {
		free(buf[1]);
		buf[1]=NULL;
	}
	if (buf[2]) {
		free(buf[2]);
		buf[2]=NULL;
	}
	if (buf[3]) {
		free(buf[3]);
		buf[3]=NULL;
	}
	if (buf[4]) {
		free(buf[4]);
		buf[4]=NULL;
	}
	if (buf[5]) {
		free(buf[5]);
		buf[5]=NULL;
	}
}
예제 #7
0
파일: main.c 프로젝트: Szarek-Pol/42sh
void		main_manager(char *s, t_main **my_env)
{
  t_main	*list;
  char		**env;

  env = list_to_tab(*my_env);
  list = NULL;
  parsing_entree(&list, s);
  if (list != NULL)
    {
      if (execution(list, my_env, env) != -1)
	my_free_list(list);
    }
  my_free_tab(env);
}
예제 #8
0
파일: application.hpp 프로젝트: yp/ZRHCstar
  int execute(int argc, char** argv) {
	 boost::posix_time::ptime time_start(boost::posix_time::second_clock::local_time());
	 INFO(_name << " - started at " << time_start);
	 DEBUG("Source code version: " APPLICATION_SOURCE_VERSION);
	 DEBUG("Compiled on:         " __DATE__ "  -  " __TIME__);

	 int result= EXIT_SUCCESS;
	 try {

		DEBUG("Parsing program parameters...");
// Parse options
		po::variables_map vm;
		po::options_description desc= get_named_options();
		po::positional_options_description p= get_positional_options();

		po::store(po::command_line_parser(argc, argv).
					 options(desc).positional(p).run(), vm);

		po::notify(vm);
		DEBUG("Program parameters successfully parsed.");

// Execute
		DEBUG("Beginning execution...");
		result= execution(argc, argv, vm);
		DEBUG("Execution successfully completed.");

	 } catch (std::exception& e) {
		FATAL("EXCEPTION OCCURRED: " << e.what());
		result= EXIT_FAILURE;
	 } catch (assertion_failed_exception& e) {
		FATAL("ASSERTION FAILED: " << e.what());
		result= EXIT_FAILURE;
		throw e;
	 } catch (...) {
		FATAL("GENERIC EXCEPTION OCCURRED.");
		result= EXIT_FAILURE;
	 }

	 boost::posix_time::ptime time_end(boost::posix_time::second_clock::local_time());
	 INFO("Running time:        " << (time_end-time_start));
	 INFO(_name << " - terminated at " << time_end);

	 return result;
  }
예제 #9
0
파일: global_exec.c 프로젝트: heitzls/42sh
int	global_exec(t_cmd *cmd, t_42sh *shell, int tok)
{
  int	i;

  i = 0;
  shell->tok = tok;
  while (shell->tok > 0)
    {
      global_prepa(cmd, i);
      prepa_pipes(cmd, i);
      prepa_semi_col(cmd, i);
      if (execution(cmd, shell, tok, i) == -42)
	return (-42);
      while (cmd[i].token != NULL && cmd[i].token[0] != ';')
	i++;
      i++;
    }
  check_signal(cmd->status);
  return (0);
}
예제 #10
0
int main(int argc, char *argv[])
{
	int continuer = 1;

	Commande *commande = malloc(sizeof(commande));
	initialiseCommande(commande);
	// signal(SIGINT, interrupt);

	Niveau *niveau = malloc(sizeof(niveau));
	decompression(choixNiveau(argc, argv), commande, niveau);


	/***
	*/


	struct sigaction act;
 
	memset (&act, '\0', sizeof(act));
 
	/* Use the sa_sigaction field because the handles has two additional parameters */
	act.sa_sigaction = &hdl;
 
	/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
	act.sa_flags = SA_SIGINFO;
 
	if (sigaction(SIGINT, &act, NULL) < 0) {
		perror ("sigaction");
		return 1;
	}
	/****
	*/

	int ch;
	int finCommande = 0;
	initscr();
	idlok(stdscr, TRUE);
	scrollok(stdscr, TRUE);
	cbreak();
    	noecho();
    	keypad(stdscr, TRUE);
    	intrflush(stdscr, FALSE);
    printw("nom : %s\n", niveau->nom);
	int x, y;
	int nbAppuiUp = 0;
	char *saisie;
	while(continuer){      
		finCommande = 0;
		saisie = malloc(TAILLE_MAX_COMMANDE*sizeof(char));
		debutLigne(commande, niveau);

		while(finCommande == 0){
			ch = wgetch(stdscr);
			if(ch != KEY_UP && ch !=KEY_DOWN)
				nbAppuiUp = 0;
			if (ch == KEY_BACKSPACE)
			{
				getyx(stdscr, y, x);
				if(x > strlen(commande->directory)+3){
					move(y, x-1);
					delch();
					strcpy(saisie, substr(saisie, 0, strlen(saisie)-1));
				}
			}
			else if(ch == KEY_LEFT){
				getyx(stdscr, y, x);
				move(y, x-1);
			}
			else if(ch == KEY_RIGHT){
				getyx(stdscr, y, x);
				move(y, x+1);
			}
			else if (ch == KEY_UP)
			{
				nbAppuiUp++;
				String *temp = malloc(sizeof(String));
				temp = niveau->history->premier;
				if (temp->suivant != NULL)
				{
					int i = 0;
					while(i < nbAppuiUp && temp->suivant != NULL){
						temp = temp->suivant;
						i++;
					}
					free(saisie);
					saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
					strcpy(saisie, temp->string);
					effaceCommande(commande);
					printw("%s", saisie);
				}
			}
			else if (ch == KEY_DOWN)
			{
				nbAppuiUp--;
				String *temp = malloc(sizeof(String));
				temp = niveau->history->premier;
				if (temp->suivant != NULL)
				{
					int i = 0;
					while(i < nbAppuiUp && temp->suivant != NULL){
						temp = temp->suivant;
						i++;
					}
					free(saisie);
					saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
					strcpy(saisie, temp->string);
					effaceCommande(commande);
					printw("%s", saisie);
				}
			}
			else if(ch == KEY_DC){
				delch();
				strcpy(saisie, substr(saisie, 0, strlen(saisie)-1));
			}
			else if(ch == '\t'){
				effaceCommande(commande);
				
				char *essai = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
				if(strlen(autoComplete(saisie, niveau)) == 0)
					finCommande = 1;
				else{
					strcpy(saisie, strcat(saisie, autoComplete(saisie, niveau)));
					printw("%s", saisie);
				}
			}
    		else if(ch == '\n'){
    			finCommande = 1;
    			printw("\n");
    		}
    		else{
    			printw("%c", ch);
    			sprintf(saisie, "%s%c", saisie, ch);
    		}
		}
		strcpy(commande->commande, saisie);
		execution(commande, niveau);
		// free(saisie);
	}
	endwin();
	return 0;
}
예제 #11
0
파일: app.c 프로젝트: consultit/geomorph
void help_callb(GtkWidget *wdg, gpointer app) {
	static char *buf[3] = {NULL, NULL, NULL};
	buf[0] = DOC_READER;
	buf[1] = DOC_DIR;
	execution(buf[0],buf);
}
예제 #12
0
파일: application.hpp 프로젝트: yp/reHCstar
  int execute(int argc, char** argv) {
	 boost::posix_time::ptime time_start(boost::posix_time::second_clock::local_time());
	 INFO(_name << " - started at " << time_start);
	 DEBUG("Source code version: " APPLICATION_SOURCE_VERSION);
	 DEBUG("Compiled on:         " __DATE__ "  -  " __TIME__);

	 int result= EXIT_SUCCESS;
	 try {

		DEBUG("Parsing program parameters...");
// Parse options
		po::variables_map vm;
		po::options_description desc("Help Options",
											  po::options_description::m_default_line_length,
											  po::options_description::m_default_line_length-16);
		desc.add_options()
		  ("help,?", po::bool_switch(),
			"Produce (this) help message.");
		desc.add(get_named_options());
		po::positional_options_description p= get_positional_options();

		po::command_line_parser parser(argc, argv);
		parser.style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing);
		po::store(parser.options(desc).positional(p).run(), vm);

		po::notify(vm);
		DEBUG("Program parameters successfully parsed.");

		if (vm["help"].as<bool>()) {
// Generate the help message and exit
		  std::cout << _name << std::endl;
		  std::cout << desc << std::endl;
		  result= EXIT_SUCCESS;
		} else {
// Check parameter values
		  DEBUG("Checking program parameters...");
		  bool po_check= true;
		  std::string po_failing_desc= "";
		  try {
			 po_check= check_options(vm);
		  } catch (std::logic_error& e) {
			 FATAL("EXCEPTION OCCURRED: " << e.what());
			 po_failing_desc= e.what();
			 po_check= false;
		  }
		  if (!po_check) {
			 DEBUG("Check failed.");
			 std::cout << _name << std::endl;
			 std::cout << std::endl <<
				"*** Invalid parameters!" << std::endl;
			 if (po_failing_desc != "") {
				std::cout << "Reason: " << po_failing_desc << std::endl;
			 }
			 std::cout << std::endl;
			 std::cout << desc << std::endl;
			 result= EXIT_FAILURE;
		  } else {
// Execute
			 DEBUG("Check successfully completed.");
			 DEBUG("Beginning execution...");
			 result= execution(argc, argv, vm);
		  }
		  DEBUG("Execution successfully completed.");
		}


	 } catch (std::exception& e) {
		FATAL("EXCEPTION OCCURRED: " << e.what());
		result= EXIT_FAILURE;
	 } catch (assertion_failed_exception& e) {
		FATAL("ASSERTION FAILED: " << e.what());
		result= EXIT_FAILURE;
		throw e;
	 } catch (...) {
		FATAL("GENERIC EXCEPTION OCCURRED.");
		result= EXIT_FAILURE;
	 }

	 boost::posix_time::ptime time_end(boost::posix_time::second_clock::local_time());
	 INFO("Running time:        " << (time_end-time_start));
	 INFO(_name << " - terminated at " << time_end);

	 return result;
  }
예제 #13
0
int main(){
    int i=0;
    initialize();

    //cycle0
    if(test==1) printf(">>cycle %d\n",cycle);
    instruction_fetch(1);
    initial_SNAP();

    //cycle1
    if(test==1) printf(">>cycle %d\n",cycle);
    instruction_decode(ID_index);
    instruction_fetch(1);
    append_SNAP();

    //cycle2
    if(test==1) printf(">>cycle %d\n",cycle);
    execution(EX_index);
    instruction_decode(ID_index);
    instruction_fetch(1);
    append_ERROR();
    if(halt==1 || halt_count==5){
        return 0;
    }
    append_SNAP();
    if(stall){
        memory(DM_index);
        execution(0);
        instruction_decode(0);
        //instruction_fetch(0);
        append_ERROR();
        if(halt==1 || halt_count==5) return 0;
        stall=0;
        append_SNAP();
    }
    if(flush){
        flush=0;
    }

    //cycle3
    if(test==1) printf(">>cycle %d\n",cycle);
    memory(DM_index);
    execution(EX_index);
    instruction_decode(ID_index);
    instruction_fetch(1);
    append_ERROR();
    if(halt==1 || halt_count==5){
        return 0;
    }
    append_SNAP();
    if(stall){
        write_back(WB_index);
        memory(DM_index);
        execution(0);
        instruction_decode(0);
        //instruction_fetch(0);
        append_ERROR();
        if(halt==1 || halt_count==5) return 0;
        stall=0;
        append_SNAP();
    }
    if(flush){
        flush=0;
    }

    while(i<50){
        i++;
        if(test==1) printf(">>cycle %d\n",cycle);
        write_back(WB_index);
        memory(DM_index);
        execution(EX_index);
        instruction_decode(ID_index);
        instruction_fetch(1);

        append_ERROR();
        if(halt==1 || halt_count==5){
            break;
        }
        append_SNAP();
        if(stall){
            write_back(WB_index);
            memory(DM_index);
            execution(0);
            instruction_decode(0);
            //instruction_fetch(0);
            append_ERROR();
            if(halt==1 || halt_count==5) return 0;
            stall=0;
            append_SNAP();
        }
        if(flush){
            flush=0;
        }

    }

    return 0;
}
예제 #14
0
// TODO: prototype changed - will need rejigging.
ExecutionResult MixClient::debugTransaction(Transaction const& _t, State const& _state, EnvInfo const& _envInfo, bool _call)
{
	State execState = _state;
	execState.addBalance(_t.sender(), _t.gas() * _t.gasPrice()); //give it enough balance for gas estimation
	eth::ExecutionResult er;
	Executive execution(execState, _envInfo);
	execution.setResultRecipient(er);
	execution.initialize(_t);
	execution.execute();

	std::vector<MachineState> machineStates;
	std::vector<unsigned> levels;
	std::vector<MachineCode> codes;
	std::map<bytes const*, unsigned> codeIndexes;
	std::vector<bytes> data;
	std::map<bytesConstRef const*, unsigned> dataIndexes;
	bytes const* lastCode = nullptr;
	bytesConstRef const* lastData = nullptr;
	unsigned codeIndex = 0;
	unsigned dataIndex = 0;
	auto onOp = [&](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, bigint gas, void* voidVM, void const* voidExt)
	{
		VM& vm = *static_cast<VM*>(voidVM);
		ExtVM const& ext = *static_cast<ExtVM const*>(voidExt);
		if (lastCode == nullptr || lastCode != &ext.code)
		{
			auto const& iter = codeIndexes.find(&ext.code);
			if (iter != codeIndexes.end())
				codeIndex = iter->second;
			else
			{
				codeIndex = codes.size();
				codes.push_back(MachineCode({ext.myAddress, ext.code}));
				codeIndexes[&ext.code] = codeIndex;
			}
			lastCode = &ext.code;
		}

		if (lastData == nullptr || lastData != &ext.data)
		{
			auto const& iter = dataIndexes.find(&ext.data);
			if (iter != dataIndexes.end())
				dataIndex = iter->second;
			else
			{
				dataIndex = data.size();
				data.push_back(ext.data.toBytes());
				dataIndexes[&ext.data] = dataIndex;
			}
			lastData = &ext.data;
		}

		if (levels.size() < ext.depth)
			levels.push_back(machineStates.size() - 1);
		else
			levels.resize(ext.depth);

		machineStates.push_back(MachineState{
									steps,
									vm.curPC(),
									inst,
									newMemSize,
									static_cast<u256>(gas),
									vm.stack(),
									vm.memory(),
									gasCost,
									ext.state().storage(ext.myAddress),
									std::move(levels),
									codeIndex,
									dataIndex
								});
	};

	execution.go(onOp);
	execution.finalize();

	switch (er.excepted)
	{
	case TransactionException::None:
		break;
	case TransactionException::NotEnoughCash:
		BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Insufficient balance for contract deployment"));
	case TransactionException::OutOfGasIntrinsic:
	case TransactionException::OutOfGasBase:
	case TransactionException::OutOfGas:
		BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas"));
	case TransactionException::BlockGasLimitReached:
		BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Block gas limit reached"));
	case TransactionException::BadJumpDestination:
		BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Solidity exception (bad jump)"));
	case TransactionException::OutOfStack:
		BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Out of stack"));
	case TransactionException::StackUnderflow:
		BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Stack underflow"));
		//these should not happen in mix
	case TransactionException::Unknown:
	case TransactionException::BadInstruction:
	case TransactionException::InvalidSignature:
	case TransactionException::InvalidNonce:
	case TransactionException::InvalidFormat:
	case TransactionException::BadRLP:
		BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Internal execution error"));
	}

	ExecutionResult d;
	d.inputParameters = _t.data();
	d.result = er;
	d.machineStates = machineStates;
	d.executionCode = std::move(codes);
	d.transactionData = std::move(data);
	d.address = _t.receiveAddress();
	d.sender = _t.sender();
	d.value = _t.value();
	d.gasUsed = er.gasUsed + er.gasRefunded + c_callStipend;
	if (_t.isCreation())
		d.contractAddress = right160(sha3(rlpList(_t.sender(), _t.nonce())));
	if (!_call)
		d.transactionIndex = m_postMine.pending().size();
	d.executonIndex = m_executions.size();
	return d;
}
예제 #15
0
파일: unit_painter.cpp 프로젝트: ejrh/hex
void UnitPainter::repaint(UnitView& unit_view, Unit& unit) {
    Timer paint_time(unit_paint_time);

    unit_view.paint.clear();
    if (!unit_view.view_def)
        return;

    Script *script = unit_view.view_def->script.get();
    if (!script)
        return;

    // The properties order for a unit paint script is:
    //   - Variables
    //   - Unit view
    //   - Unit view def
    //   - Unit
    //   - Unit type
    //   - Tile
    //   - Tile type
    // Initial variables set:
    //   - terrain_type
    //   - faction_type (if owned)
    //   - selected
    PaintExecution execution(&resources->scripts, resources, &unit_view.paint);
    //execution.add_properties(&unit_view.properties);
    //execution.add_properties(&unit_view.view_def->properties);
    execution.add_properties(&unit.properties);
    if (unit.type)
        execution.add_properties(&unit.type->properties);
    //execution.add_properties(&tile.properties);
    //execution.add_properties(&tile.type->properties);

    //Atom terrain_type_atom = AtomRegistry::atom("terrain_type");
    //execution.variables.set<std::string>(terrain_type_atom, tile.type->name);

    /*if (unit.owner) {
        Atom faction_type_atom = AtomRegistry::atom("faction_type");
        execution.variables.set<std::string>(faction_type_atom, unit.owner->type_name);
    }*/

    Atom selected_atom = AtomRegistry::get_instance().atom("selected");
    execution.variables.set<bool>(selected_atom, unit_view.selected);

    Atom shadow_atom = AtomRegistry::get_instance().atom("shadow");
    execution.variables.set<bool>(shadow_atom, unit_view.shadow);

    Atom unit_facing_atom = AtomRegistry::get_instance().atom("unit_facing");
    execution.variables.set<int>(unit_facing_atom, unit_view.facing);

    Atom unit_posture_atom = AtomRegistry::get_instance().atom("unit_posture");
    Atom posture_atoms[] = { AtomRegistry::get_instance().atom("holding"), AtomRegistry::get_instance().atom("moving"), AtomRegistry::get_instance().atom("attacking"), AtomRegistry::get_instance().atom("recoiling"), AtomRegistry::get_instance().atom("dying") };
    execution.variables.set<Atom>(unit_posture_atom, posture_atoms[unit_view.posture]);

    Atom unit_variation_atom = AtomRegistry::get_instance().atom("unit_variation");
    execution.variables.set<int>(unit_variation_atom, unit_view.variation);

    try {
        execution.run(script);
    } catch (ScriptError& err) {
        BOOST_LOG_TRIVIAL(error) << boost::format("Error in script %s: %s") % script->name % err.what();
        ++script_error_counter;
    }

    ++unit_paint_counter;
}
예제 #16
0
void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _call, bool _gasAuto, Secret const& _secret)
{
	Transaction t = _gasAuto ? replaceGas(_t, _secret, m_state.gasLimitRemaining()) : _t;
	bytes rlp = t.rlp();

	// do debugging run first
	LastHashes lastHashes(256);
	lastHashes[0] = bc().numberHash(bc().number());
	for (unsigned i = 1; i < 256; ++i)
		lastHashes[i] = lastHashes[i - 1] ? bc().details(lastHashes[i - 1]).parent : h256();

	State execState = _state;
	Executive execution(execState, lastHashes, 0);
	execution.initialize(&rlp);
	execution.execute();
	std::vector<MachineState> machineStates;
	std::vector<unsigned> levels;
	std::vector<MachineCode> codes;
	std::map<bytes const*, unsigned> codeIndexes;
	std::vector<bytes> data;
	std::map<bytesConstRef const*, unsigned> dataIndexes;
	bytes const* lastCode = nullptr;
	bytesConstRef const* lastData = nullptr;
	unsigned codeIndex = 0;
	unsigned dataIndex = 0;
	auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, void* voidVM, void const* voidExt)
	{
		VM& vm = *static_cast<VM*>(voidVM);
		ExtVM const& ext = *static_cast<ExtVM const*>(voidExt);
		if (lastCode == nullptr || lastCode != &ext.code)
		{
			auto const& iter = codeIndexes.find(&ext.code);
			if (iter != codeIndexes.end())
				codeIndex = iter->second;
			else
			{
				codeIndex = codes.size();
				codes.push_back(MachineCode({ext.myAddress, ext.code}));
				codeIndexes[&ext.code] = codeIndex;
			}
			lastCode = &ext.code;
		}

		if (lastData == nullptr || lastData != &ext.data)
		{
			auto const& iter = dataIndexes.find(&ext.data);
			if (iter != dataIndexes.end())
				dataIndex = iter->second;
			else
			{
				dataIndex = data.size();
				data.push_back(ext.data.toBytes());
				dataIndexes[&ext.data] = dataIndex;
			}
			lastData = &ext.data;
		}

		if (levels.size() < ext.depth)
			levels.push_back(machineStates.size() - 1);
		else
			levels.resize(ext.depth);

		machineStates.emplace_back(MachineState({steps, vm.curPC(), inst, newMemSize, vm.gas(),
									  vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels, codeIndex, dataIndex}));
	};

	execution.go(onOp);
	execution.finalize();
	dev::eth::ExecutionResult er = execution.executionResult();

	switch (er.excepted)
	{
		case TransactionException::None:
			break;
		case TransactionException::NotEnoughCash:
			BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Insufficient balance for contract deployment"));
		case TransactionException::OutOfGasBase:
		case TransactionException::OutOfGas:
			BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas"));
		case TransactionException::BlockGasLimitReached:
			BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Block gas limit reached"));
		case TransactionException::OutOfStack:
			BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Out of stack"));
		case TransactionException::StackUnderflow:
			BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Stack underflow"));
		//these should not happen in mix
		case TransactionException::Unknown:
		case TransactionException::BadInstruction:
		case TransactionException::BadJumpDestination:
		case TransactionException::InvalidSignature:
		case TransactionException::InvalidNonce:
			BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Internal execution error"));
	};

	ExecutionResult d;
	d.result = execution.executionResult();
	d.machineStates = machineStates;
	d.executionCode = std::move(codes);
	d.transactionData = std::move(data);
	d.address = _t.receiveAddress();
	d.sender = _t.sender();
	d.value = _t.value();
	d.gasUsed = er.gasUsed + er.gasRefunded;
	if (_t.isCreation())
		d.contractAddress = right160(sha3(rlpList(_t.sender(), _t.nonce())));
	if (!_call)
		d.transactionIndex = m_state.pending().size();
	d.executonIndex = m_executions.size();

	// execute on a state
	if (!_call)
	{
		t = _gasAuto ? replaceGas(_t, _secret, d.gasUsed) : _t;
		er =_state.execute(lastHashes, t);
		if (t.isCreation() && _state.code(d.contractAddress).empty())
			BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment"));
		d.gasUsed = er.gasUsed + er.gasRefunded + er.gasForDeposit;
		// collect watches
		h256Set changed;
		Guard l(x_filtersWatches);
		for (std::pair<h256 const, eth::InstalledFilter>& i: m_filters)
			if ((unsigned)i.second.filter.latest() > bc().number())
			{
				// acceptable number.
				auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1));
				if (m.size())
				{
					// filter catches them
					for (LogEntry const& l: m)
						i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1));
					changed.insert(i.first);
				}
			}
		changed.insert(dev::eth::PendingChangedFilter);
		noteChanged(changed);
	}
	WriteGuard l(x_executions);
	m_executions.emplace_back(std::move(d));
}