Esempio n. 1
0
preference *execute_action (action *a, struct token_struct *tok, wme *w) {
  Symbol *id, *attr, *value, *referent;
  char first_letter;
  
  if (a->type==FUNCALL_ACTION) {
    value = instantiate_rhs_value (a->value, -1, 'v', tok, w);
    if (value) symbol_remove_ref (value);
    return NIL;
  }

  attr = NIL;
  value = NIL;
  referent = NIL;
  
  id = instantiate_rhs_value (a->id, -1, 's', tok, w);
  if (!id) goto abort_execute_action;
  if (id->common.symbol_type!=IDENTIFIER_SYMBOL_TYPE) {
    print_with_symbols ("Error: RHS makes a preference for %y (not an identifier)\n", id);
    goto abort_execute_action;
  }
  
  attr = instantiate_rhs_value (a->attr, id->id.level, 'a', tok, w);
  if (!attr) goto abort_execute_action;

  first_letter = first_letter_from_symbol (attr);
  
  value = instantiate_rhs_value (a->value, id->id.level,
                                 first_letter, tok, w);
  if (!value) goto abort_execute_action;

  if (preference_is_binary(a->preference_type)) {
    referent = instantiate_rhs_value (a->referent, id->id.level,
                                      first_letter, tok, w);
    if (!referent) goto abort_execute_action;
  }

  /* --- RBD 4/17/95 added stuff to handle attribute_preferences_mode --- */
  if (((a->preference_type != ACCEPTABLE_PREFERENCE_TYPE) &&
       (a->preference_type != REJECT_PREFERENCE_TYPE)) &&
      (! (id->id.isa_goal && (attr==current_agent(operator_symbol))) )) {
    if ((current_agent(attribute_preferences_mode)==2) ||
	(current_agent(operand2_mode) ==TRUE) ) {
      print_with_symbols ("\nError: attribute preference other than +/- for %y ^%y -- ignoring it.", id, attr);
      goto abort_execute_action;
    } else if (current_agent(attribute_preferences_mode)==1) {
      print_with_symbols ("\nWarning: attribute preference other than +/- for %y ^%y.", id, attr);
    }  
  }

  return make_preference (a->preference_type, id, attr, value, referent);

  abort_execute_action:   /* control comes here when some error occurred */
  if (id) symbol_remove_ref (id);  
  if (attr) symbol_remove_ref (attr);  
  if (value) symbol_remove_ref (value);  
  if (referent) symbol_remove_ref (referent);
  return NIL;
}
Esempio n. 2
0
/* Add a new preference for an audio format. */
static void load_each_preference (const char *preference)
{
    const char *prefix;
    lists_t_strs *tokens;
    decoder_t_preference *pref;

    assert (preference && preference[0]);

    tokens = lists_strs_new (4);
    lists_strs_split (tokens, preference, "(,)");
    prefix = lists_strs_at (tokens, 0);
    pref = make_preference (prefix);
#ifdef DEBUG
    pref->source = preference;
#endif
    load_decoders (pref, tokens);
    pref->next = preferences;
    preferences = pref;
    lists_strs_free (tokens);
}
Esempio n. 3
0
	instantiation* make_fake_instantiation( agent* my_agent, Symbol* state, wme_set* conditions, symbol_triple_list* actions )
	{
		// make fake instantiation
		instantiation* inst;
		allocate_with_pool( my_agent, &( my_agent->instantiation_pool ), &inst );
		inst->prod = NULL;
		inst->next = inst->prev = NULL;
		inst->rete_token = NULL;
		inst->rete_wme = NULL;
		inst->match_goal = state;
		inst->match_goal_level = state->id.level;
		inst->reliable = true;
		inst->backtrace_number = 0;
		inst->in_ms = FALSE;
		inst->GDS_evaluated_already = FALSE;

		// create preferences
		inst->preferences_generated = NULL;
		{
			preference* pref;

			for ( symbol_triple_list::iterator a_it=actions->begin(); a_it!=actions->end(); a_it++ )
			{
				pref = make_preference( my_agent, ACCEPTABLE_PREFERENCE_TYPE, (*a_it)->id, (*a_it)->attr, (*a_it)->value, NIL );
				pref->o_supported = true;
				symbol_add_ref( pref->id );
				symbol_add_ref( pref->attr );
				symbol_add_ref( pref->value );

				pref->inst = inst;
				pref->inst_next = pref->inst_prev = NULL;

				insert_at_head_of_dll( inst->preferences_generated, pref, inst_next, inst_prev );
			}
		}

		// create conditions
		{
			condition *cond = NULL;
			condition *prev_cond = NULL;

			for ( wme_set::iterator c_it=conditions->begin(); c_it!=conditions->end(); c_it++ )
			{
				// construct the condition
				allocate_with_pool( my_agent, &( my_agent->condition_pool ), &cond );
				cond->type = POSITIVE_CONDITION;
				cond->prev = prev_cond;
				cond->next = NULL;
				if ( prev_cond != NULL )
				{
					prev_cond->next = cond;
				}
				else
				{
					inst->top_of_instantiated_conditions = cond;
					inst->bottom_of_instantiated_conditions = cond;
					inst->nots = NULL;
				}
				cond->data.tests.id_test = make_equality_test( (*c_it)->id );
				cond->data.tests.attr_test = make_equality_test( (*c_it)->attr );
				cond->data.tests.value_test = make_equality_test( (*c_it)->value );
				cond->test_for_acceptable_preference = (*c_it)->acceptable;
				cond->bt.wme_ = (*c_it);

				#ifndef DO_TOP_LEVEL_REF_CTS
				if ( inst->match_goal_level > TOP_GOAL_LEVEL )
				#endif
				{
					wme_add_ref( (*c_it) );
				}			
				
				cond->bt.level = (*c_it)->id->id.level;
				cond->bt.trace = (*c_it)->preference;
				
				if ( cond->bt.trace )
				{
					#ifndef DO_TOP_LEVEL_REF_CTS
					if ( inst->match_goal_level > TOP_GOAL_LEVEL )
					#endif
					{
						preference_add_ref( cond->bt.trace );
					}
				}				

        cond->bt.CDPS = NULL;

				prev_cond = cond;
			}
		}

		return inst;
	}