コード例 #1
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
void InterpretGoto(int object_id,local_var_type *local_vars,
				   opcode_type opcode,char *inst_start)
{
	int dest_addr;
	int var_check;
	val_type check_data;
	
	/* This function is called often, so the switch has been
    * optimized away to return the value immediately. */
	
	dest_addr = get_int();
	
	/* unconditional gotos have source2 bits set--otherwise, it's a goto
	only if the source1 bits have a non-zero var */
	if (opcode.source2 == GOTO_UNCONDITIONAL)
	{
		bkod = inst_start + dest_addr;
		return;
	}
	
	var_check = get_int();
	check_data = RetrieveValue(object_id,local_vars,opcode.source1,var_check);
	if ((opcode.dest == GOTO_IF_TRUE && check_data.v.data != 0) ||
		(opcode.dest == GOTO_IF_FALSE && check_data.v.data == 0))
		bkod = inst_start + dest_addr;
}
コード例 #2
0
ファイル: CMonEvent.cpp プロジェクト: techolik/Snippets
CValue CMonEvent::GetValue(const string& key)
{
	if (!_hasValue(key))
		m_map[key] = RetrieveValue(key);
	
	return m_map[key];
}
コード例 #3
0
ファイル: CMonEvent.cpp プロジェクト: techolik/Snippets
bool CMonEvent::FillFields(const vector<string>& keys)
{
	for (const string& key : keys)
	{
		// TODO: may need to drop the keys in the map that are not in the requested vector.
		// those are usually cached by call to GetValue().
		if (!_hasValue(key))
			m_map[key] = RetrieveValue(key);
	}

	// TODO: error handling
	return true;
}
コード例 #4
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
void InterpretUnaryAssign(int object_id,local_var_type *local_vars,opcode_type opcode)
{
	char info;
	int dest,source;
	val_type source_data;
	
	info = get_byte();
	dest = get_int();
	source = get_int();
	
	source_data = RetrieveValue(object_id,local_vars,opcode.source1,source);
	
	switch (info)
	{
	case NOT : 
		if (source_data.v.tag != TAG_INT)
		{
			bprintf("InterpretUnaryAssign can't not non-int %i,%i\n",
				source_data.v.tag,source_data.v.data);
			break;
		}
		source_data.v.data = !source_data.v.data;
		break;
	case NEGATE :
		if (source_data.v.tag != TAG_INT)
		{
			bprintf("InterpretUnaryAssign can't negate non-int %i,%i\n",
				source_data.v.tag,source_data.v.data);
			break;
		}
		source_data.v.data = -source_data.v.data;
		break;
	case NONE :
		break;
	case BITWISE_NOT :
		if (source_data.v.tag != TAG_INT)
		{
			bprintf("InterpretUnaryAssign can't bitwise not non-int %i,%i\n",
				source_data.v.tag,source_data.v.data);
			break;
		}
		source_data.v.data = ~source_data.v.data;
		break;
		
	default :
		bprintf("InterpretUnaryAssign can't perform unary op %i\n",info);
		break;
	}
	
	StoreValue(object_id,local_vars,opcode.dest,dest,source_data);
}
コード例 #5
0
void ProteinFDRestimator::binProteinsEqualDeepth()
{
  //assuming lengths sorted from less to bigger
  std::sort(lengths.begin(),lengths.end());
  unsigned entries = lengths.size();
  //integer divion and its residue
  unsigned nr_bins = (unsigned)((entries - entries%nbins) / nbins);
  unsigned residues = entries % nbins;
  if(VERB > 2)
    std::cerr << "\nBinning proteins using equal deepth\n" << std::endl;
  
  /*while(residues >= nbins && residues != 0)
  {
    nr_bins += (unsigned)((residues - residues%nbins) / nbins);
    residues = residues % nbins; 
  }*/
  
  std::vector<double> values;
  for(unsigned i = 0; i <= nbins; i++)
  {
    unsigned index = (unsigned)(nr_bins * i);
    double value = lengths[index];
    values.push_back(value);
    if(VERB > 2)
      std::cerr << "\nValue of bin : " << i << " with index " << index << " is " << value << std::endl;
  }
  
  //there are some elements at the end that are <= nbins that could not be fitted
  //FIXME I think it fails if it enters here in some scenarios
  
  if(residues > 0)
  {
    values.back() = lengths.back();
    if(VERB > 2)
      std::cerr << "\nValue of last bin is fixed to : " << values.back() << std::endl;
  }

  std::multimap<double,std::string>::iterator itlow,itup;
  for(unsigned i = 0; i < nbins; i++)
  {
    double lowerbound = values[i];
    double upperbound = values[i+1];
    itlow = groupedProteins.lower_bound(lowerbound);
    itup =  groupedProteins.upper_bound(upperbound);
    std::set<std::string> proteins;
    std::transform(itlow, itup, std::inserter(proteins,proteins.begin()), RetrieveValue());
    binnedProteins.insert(std::make_pair(i,proteins));
  }

  return;
}
コード例 #6
0
ファイル: CMemory.cpp プロジェクト: buranela/OpenHoldemV12
const double CMemory::ProcessQuery(const char * pquery, CEvalInfoFunction **logCallingFunction, int *e)
{
	if (memcmp(pquery,"me_st_", 6)==0)
	{
		*e = SUCCESS;
		StoreValue(pquery, logCallingFunction, e);
		return 0.0;
	}

	if (memcmp(pquery,"me_re_", 6)==0)
	{
		*e = SUCCESS;
		return RetrieveValue(pquery, e);
	}

	*e = ERR_INVALID_SYM;
	return 0.0;
}
コード例 #7
0
void ProteinFDRestimator::binProteinsEqualWidth()
{
  //assuming lengths sorted from less to bigger
  std::sort(lengths.begin(),lengths.end());
  double min = lengths.front();
  double max = lengths.back();
  std::vector<double> values;
  double span = abs(max - min);
  double part = span / nbins;
  
  if(VERB > 2)
    std::cerr << "\nBinning proteins using equal width\n" << std::endl;
  
  for(unsigned i = 0; i < nbins; i++)
  {
    unsigned index = static_cast<unsigned>(min + i*part);
    double value = lengths[index];
    values.push_back(value);
    if(VERB > 2)
      std::cerr << "\nValue of bin : " << i << " with index " << index << " is " << value << std::endl;
  }
  values.push_back(max);
  std::multimap<double,std::string>::iterator itlow,itup;
  for(unsigned i = 0; i < nbins; i++)
  {
    double lowerbound = values[i];
    double upperbound = values[i+1];
    itlow = groupedProteins.lower_bound(lowerbound);
    itup =  groupedProteins.upper_bound(upperbound);
    std::set<std::string> proteins;
    std::transform(itlow, itup, std::inserter(proteins,proteins.begin()), RetrieveValue());
    binnedProteins.insert(std::make_pair(i,proteins));
  }

  return;
}
コード例 #8
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
void InterpretBinaryAssign(int object_id,local_var_type *local_vars,opcode_type opcode)
{
	char info;
	int dest,source1,source2;
	val_type source1_data,source2_data;
	
	info = get_byte();
	dest = get_int();
	source1 = get_int();
	source2 = get_int();
	
	source1_data = RetrieveValue(object_id,local_vars,opcode.source1,source1);
	source2_data = RetrieveValue(object_id,local_vars,opcode.source2,source2);
	
	/*
	if (source1_data.v.tag != source2_data.v.tag)
	bprintf("InterpretBinaryAssign is operating on 2 diff types!\n");
	*/
	switch (info)
	{
	case ADD : 
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't add 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data += source2_data.v.data;
		break;
	case SUBTRACT :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't sub 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data -= source2_data.v.data;
		break;
	case MULTIPLY :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't mult 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data *= source2_data.v.data;
		break;
	case DIV :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't div 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		if (source2_data.v.data == 0)
		{
			bprintf("InterpretBinaryAssign can't div by 0\n");
			break;
		}
		source1_data.v.data /= source2_data.v.data;
		break;
	case MOD :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't mod 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		if (source2_data.v.data == 0)
		{
			bprintf("InterpretBinaryAssign can't mod 0\n");
			break;
		}
		source1_data.v.data = abs(source1_data.v.data % source2_data.v.data);
		
		break;
	case AND :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't and 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data && source2_data.v.data;
		break;
	case OR :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't or 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data || source2_data.v.data;
		break;
		
	case EQUAL :
		
#if 0
		// disabled:  used to be only TAG_NIL vs TAG_X, or TAG_X vs TAG_X is legal
		// now:  TAG_X vs TAG_Y is legal, and returns FALSE for equal
		
		if (source1_data.v.tag != source2_data.v.tag &&
			source1_data.v.tag != TAG_NIL && source2_data.v.tag != TAG_NIL)
		{
			bprintf("InterpretBinaryAssign can't = 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
#endif
		
		if (source1_data.v.tag != source2_data.v.tag)
			source1_data.v.data = False;
		else
			source1_data.v.data = source1_data.v.data == source2_data.v.data;
		source1_data.v.tag = TAG_INT;
		break;
		
	case NOT_EQUAL :
		
#if 0
		// disabled:  used to be only TAG_NIL vs TAG_X, or TAG_X vs TAG_X is legal
		// now:  TAG_X vs TAG_Y is legal, and returns TRUE for not equal
		
		if (source1_data.v.tag != source2_data.v.tag &&
			source1_data.v.tag != TAG_NIL && source2_data.v.tag != TAG_NIL)
		{
			bprintf("InterpretBinaryAssign can't <> 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
#endif
		
		if (source1_data.v.tag != source2_data.v.tag)
			source1_data.v.data = True; 
		else
			source1_data.v.data = source1_data.v.data != source2_data.v.data;
		source1_data.v.tag = TAG_INT;
		break;
	case LESS_THAN :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't < 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data < source2_data.v.data;
		break;
	case GREATER_THAN :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't > 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data > source2_data.v.data;
		break;
	case LESS_EQUAL :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't <= 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data <= source2_data.v.data;
		break;
	case GREATER_EQUAL :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't >= 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data >= source2_data.v.data;
		break;
	case BITWISE_AND :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't and 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data & source2_data.v.data;
		break;
	case BITWISE_OR :
		if (source1_data.v.tag != TAG_INT || source2_data.v.tag != TAG_INT)
		{
			bprintf("InterpretBinaryAssign can't or 2 vars %i,%i and %i,%i\n",
				source1_data.v.tag,source1_data.v.data,
				source2_data.v.tag,source2_data.v.data);
			break;
		}
		source1_data.v.data = source1_data.v.data | source2_data.v.data;
		break;
	default :
		bprintf("InterpretBinaryAssign can't perform binary op %i\n",info);
		break;
   }
   
   StoreValue(object_id,local_vars,opcode.dest,dest,source1_data);
}
コード例 #9
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
/* returns either RETURN_PROPAGATE or RETURN_NO_PROPAGATE.  If no propagate,
* then the return value in ret_val is good.
*/
int InterpretAtMessage(int object_id,class_node* c,message_node* m,
					   int num_sent_parms,
					   parm_node sent_parms[],val_type *ret_val)
{
	opcode_type opcode;
	char opcode_char;
	char num_locals,num_parms;
	local_var_type local_vars;
	int parm_id;
	val_type parm_init_value;
	
	int i,j;
	char *inst_start;
	Bool found_parm;
	
	num_locals = get_byte();
	num_parms = get_byte();
	
	local_vars.num_locals = num_locals+num_parms;
	if (local_vars.num_locals > MAX_LOCALS)
	{
		dprintf("InterpretAtMessage found too many locals and parms for OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n",
			object_id,
			c? c->class_name : "(unknown)",
			m? GetNameByID(m->message_id) : "(unknown)",
			BlakodDebugInfo());
		(*ret_val).int_val = NIL;
		return RETURN_NO_PROPAGATE;
	}
	
	if (ConfigBool(DEBUG_INITLOCALS))
	{
		parm_init_value.v.tag = TAG_INVALID;
		parm_init_value.v.data = 1;
		
		for (i = 0; i < local_vars.num_locals; i++)
		{
			local_vars.locals[i] = parm_init_value;
		}
	}
	
	/* both table and call parms are sorted */
	
	j = 0;
	for (i=0;i<num_parms;i++)
	{
		parm_id = get_int(); /* match this with parameters */
		parm_init_value.int_val = get_int();
		
		/* look if we have a value for this parm */
		found_parm = False;
		j = 0;			/* don't assume sorted for now */
		while (j < num_sent_parms)
		{
			if (sent_parms[j].name_id == parm_id)
			{
			/* assuming no RetrieveValue needed here, since InterpretCall
				does that for us */
				local_vars.locals[i].int_val = sent_parms[j].value;
				found_parm = True;
				j++;
				break;
			}
			j++;
		}
		
		if (!found_parm)
			local_vars.locals[i].int_val = parm_init_value.int_val;
	}
	
	for(;;)			/* returns when gets a blakod return */
	{
		num_interpreted++;
		
		/* infinite loop check */
		if (num_interpreted > ConfigInt(BLAKOD_MAX_STATEMENTS))
		{
			bprintf("InterpretAtMessage interpreted too many instructions--infinite loop?\n");
			
			dprintf("Infinite loop at depth %i\n", message_depth);
			dprintf("  OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n",
				object_id,
				c? c->class_name : "(unknown)",
				m? GetNameByID(m->message_id) : "(unknown)",
				BlakodDebugInfo());
			
			dprintf("  Local variables:\n");
			for (i=0;i<local_vars.num_locals;i++)
			{
				dprintf("  %3i : %s %5i\n",
					i,
					GetTagName(local_vars.locals[i]),
					local_vars.locals[i].v.data);
			}
			
			(*ret_val).int_val = NIL;
			return RETURN_NO_PROPAGATE;
		}
		
		opcode_char = get_byte();
		
		//memcpy(&opcode,&opcode_char,1);
		{
			char *ch=(char*)&opcode;
			*ch = opcode_char ;
		}
		
		/* use continues instead of breaks here since there is nothing
		after the switch, for efficiency */
		
		switch (opcode.command)
		{
			case UNARY_ASSIGN : 
				InterpretUnaryAssign(object_id,&local_vars,opcode);
				continue;
			case BINARY_ASSIGN : 
				InterpretBinaryAssign(object_id,&local_vars,opcode);
				continue;
			case GOTO : 
				inst_start = bkod - 1; /* we've read one byte of instruction so far */
				InterpretGoto(object_id,&local_vars,opcode,inst_start);
				continue;
			case CALL : 
				InterpretCall(object_id,&local_vars,opcode);
				continue;
			case RETURN : 
				if (opcode.dest == PROPAGATE)
					return RETURN_PROPAGATE;
				else
				{
					int data;
					data = get_int();	    
					*ret_val = RetrieveValue(object_id,&local_vars,opcode.source1,data);
					return RETURN_NO_PROPAGATE;
				}
				/* can't get here */
					continue;
			default : 
				bprintf("InterpretAtMessage found INVALID OPCODE command %i.  die.\n", opcode.command);
				FlushDefaultChannels();
				continue;
		}
	}
}
コード例 #10
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
void InterpretCall(int object_id,local_var_type *local_vars,opcode_type opcode)
{
	parm_node normal_parm_array[MAX_C_PARMS],name_parm_array[MAX_NAME_PARMS]; 
	unsigned char info,num_normal_parms,num_name_parms,initial_type;
	int initial_value;
	val_type call_return;
	
	val_type name_val;
	int assign_index;
	int i;
	
	info = get_byte(); /* get function id */
	
	switch(opcode.source1)
	{
	case CALL_NO_ASSIGN :
		break;
	case CALL_ASSIGN_LOCAL_VAR :
	case CALL_ASSIGN_PROPERTY :
		assign_index = get_int();
		break;
	}
	
	num_normal_parms = get_byte();
	
	if (num_normal_parms > MAX_C_PARMS)
	{
		bprintf("InterpretCall found a call w/ more than %i parms, DEATH\n",
			MAX_C_PARMS);
		FlushDefaultChannels();
		num_normal_parms = MAX_C_PARMS;
	}
	
	for (i=0;i<num_normal_parms;i++)
	{
		normal_parm_array[i].type = get_byte();
		normal_parm_array[i].value = get_int();
	}
	
	num_name_parms = get_byte();
	
	if (num_name_parms > MAX_NAME_PARMS)
	{
		bprintf("InterpretCall found a call w/ more than %i name parms, DEATH\n",
			MAX_NAME_PARMS);
		FlushDefaultChannels();
		num_name_parms = MAX_NAME_PARMS;
	}
	
	for (i=0;i<num_name_parms;i++)
	{
		name_parm_array[i].name_id = get_int();
		
		initial_type = get_byte();
		initial_value = get_int();
		
		/* translate to literal now, because won't have local vars
		if nested call to sendmessage again */
		
		/* maybe only need to do this in call to sendmessage and postmessage? */
		
		name_val = RetrieveValue(object_id,local_vars,initial_type,initial_value);
		
		name_parm_array[i].value = name_val.int_val;
	}
	
	/* increment count of the c function, for profiling info */
	kod_stat.c_count[info]++;
	
	call_return.int_val = ccall_table[info](object_id,local_vars,num_normal_parms,
					   normal_parm_array,num_name_parms,
					   name_parm_array);
	
	switch(opcode.source1)
	{
		case CALL_NO_ASSIGN :
			break;
		case CALL_ASSIGN_LOCAL_VAR :
		case CALL_ASSIGN_PROPERTY :
			StoreValue(object_id,local_vars,opcode.source1,assign_index,call_return);      
			break;
	}
}