Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Data Structures | Macros | Typedefs | Functions
rhsfun.h File Reference

Go to the source code of this file.

Data Structures

struct  action_struct
struct  rhs_function_struct

Macros

#define FUNCALL_ACTION   1
#define I_SUPPORT   2
#define MAKE_ACTION   0
#define O_SUPPORT   1
#define UNKNOWN_SUPPORT   0

Typedefs

typedef struct action_struct action
typedef struct agent_struct agent
typedef char Bool
typedef unsigned char byte
typedef struct cons_struct cons
typedef cons list
typedef unsigned short rete_node_level
typedef struct rhs_function_struct rhs_function
typedef Symbol *(* rhs_function_routine )(agent *thisAgent,::list *args, void *user_data))
typedef char * rhs_value
typedef union symbol_union Symbol

Functions

void add_rhs_function (agent *thisAgent, Symbol *name, rhs_function_routine f, int num_args_expected, Bool can_be_rhs_value, Bool can_be_stand_alone_action, void *user_data)
rhs_value funcall_list_to_rhs_value (::list *fl)
void init_built_in_rhs_functions (agent *thisAgent)
rhs_functionlookup_rhs_function (agent *thisAgent, Symbol *name)
void remove_built_in_rhs_functions (agent *thisAgent)
void remove_rhs_function (agent *thisAgent, Symbol *name)
rhs_value reteloc_to_rhs_value (byte field_num, rete_node_level levels_up)
bool rhs_value_is_funcall (rhs_value rv)
bool rhs_value_is_reteloc (rhs_value rv)
bool rhs_value_is_symbol (rhs_value rv)
bool rhs_value_is_unboundvar (rhs_value rv)
inline::listrhs_value_to_funcall_list (rhs_value rv)
uint8_t rhs_value_to_reteloc_field_num (rhs_value rv)
uint16_t rhs_value_to_reteloc_levels_up (rhs_value rv)
Symbolrhs_value_to_symbol (rhs_value rv)
uint64_t rhs_value_to_unboundvar (rhs_value rv)
rhs_value symbol_to_rhs_value (Symbol *sym)
rhs_value unboundvar_to_rhs_value (uint64_t n)

Macro Definition Documentation

#define FUNCALL_ACTION   1
#define I_SUPPORT   2

Definition at line 211 of file rhsfun.h.

Referenced by calculate_compile_time_o_support().

#define MAKE_ACTION   0
#define O_SUPPORT   1

Definition at line 210 of file rhsfun.h.

Referenced by calculate_compile_time_o_support().

#define UNKNOWN_SUPPORT   0

Definition at line 209 of file rhsfun.h.

Referenced by calculate_compile_time_o_support(), and make_production().

Typedef Documentation

typedef struct action_struct action
typedef struct agent_struct agent

Definition at line 216 of file rhsfun.h.

typedef char Bool

Definition at line 213 of file rhsfun.h.

typedef unsigned char byte

Definition at line 64 of file rhsfun.h.

typedef struct cons_struct cons

Definition at line 66 of file rhsfun.h.

typedef cons list

Definition at line 67 of file rhsfun.h.

typedef unsigned short rete_node_level

Definition at line 65 of file rhsfun.h.

typedef Symbol*(* rhs_function_routine)(agent *thisAgent,::list *args, void *user_data))

Definition at line 230 of file rhsfun.h.

typedef char* rhs_value

Definition at line 63 of file rhsfun.h.

typedef union symbol_union Symbol

Definition at line 68 of file rhsfun.h.

Function Documentation

void add_rhs_function ( agent thisAgent,
Symbol name,
rhs_function_routine  f,
int  num_args_expected,
Bool  can_be_rhs_value,
Bool  can_be_stand_alone_action,
void *  user_data 
)

Definition at line 63 of file rhsfun.cpp.

References allocate_memory(), rhs_function_struct::can_be_rhs_value, rhs_function_struct::can_be_stand_alone_action, rhs_function_struct::f, MISCELLANEOUS_MEM_USAGE, rhs_function_struct::name, rhs_function_struct::next, NIL, rhs_function_struct::num_args_expected, print(), print_with_symbols(), agent_struct::rhs_functions, and rhs_function_struct::user_data.

Referenced by init_built_in_rhs_functions(), and init_built_in_rhs_math_functions().

{
if ((!can_be_rhs_value) && (!can_be_stand_alone_action))
{
print (thisAgent, "Internal error: attempt to add_rhs_function that can't appear anywhere\n");
return;
}
for (rf=thisAgent->rhs_functions; rf!=NIL; rf=rf->next)
{
if (rf->name==name)
{
print_with_symbols (thisAgent, "Internal error: attempt to add_rhs_function that already exists: %y\n", name);
return;
}
}
rf = static_cast<rhs_function_struct *>(allocate_memory (thisAgent, sizeof(rhs_function), MISCELLANEOUS_MEM_USAGE));
/* Insertion into the list */
rf->next = thisAgent->rhs_functions;
thisAgent->rhs_functions = rf;
/* Rest of the stuff */
rf->name = name;
rf->f = f;
rf->num_args_expected = num_args_expected;
rf->can_be_rhs_value = can_be_rhs_value;
rf->can_be_stand_alone_action = can_be_stand_alone_action;
rf->user_data = user_data;
}
rhs_value funcall_list_to_rhs_value ( ::list fl)
inline

Definition at line 127 of file rhsfun.h.

Referenced by copy_rhs_value(), copy_rhs_value_and_substitute_varnames(), parse_function_call_after_lparen(), and reteload_rhs_value().

{
return reinterpret_cast<rhs_value>(reinterpret_cast<char *>(fl) + 1);
}
void init_built_in_rhs_functions ( agent thisAgent)

Definition at line 731 of file rhsfun.cpp.

References accept_rhs_function_code(), add_rhs_function(), capitalize_symbol_rhs_function_code(), count_rhs_function_code(), crlf_rhs_function_code(), deep_copy_rhs_function_code(), dont_learn_rhs_function_code(), FALSE, force_learn_rhs_function_code(), halt_rhs_function_code(), ifeq_rhs_function_code(), init_built_in_rhs_math_functions(), make_constant_symbol_rhs_function_code(), make_sym_constant(), strlen_rhs_function_code(), timestamp_rhs_function_code(), trim_rhs_function_code(), TRUE, and write_rhs_function_code().

Referenced by init_soar_agent().

{
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "write"), write_rhs_function_code,
-1, FALSE, TRUE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "crlf"), crlf_rhs_function_code,
0, TRUE, FALSE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "halt"), halt_rhs_function_code,
0, FALSE, TRUE, 0);
/*
Replaced with a gSKI rhs function
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "interrupt"),
interrupt_rhs_function_code,
0, FALSE, TRUE, 0);
*/
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "make-constant-symbol"),
-1, TRUE, FALSE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "timestamp"),
0, TRUE, FALSE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "accept"), accept_rhs_function_code,
0, TRUE, FALSE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "trim"),
1,
0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "capitalize-symbol"),
1,
0);
/* AGR 520 begin */
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "ifeq"), ifeq_rhs_function_code,
4, TRUE, FALSE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "strlen"), strlen_rhs_function_code,
1, TRUE, FALSE, 0);
/* AGR 520 end */
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "dont-learn"),
1, FALSE, TRUE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "force-learn"),
1, FALSE, TRUE, 0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "deep-copy"),
1,TRUE,FALSE,0);
add_rhs_function (thisAgent, make_sym_constant (thisAgent, "count"),
-1,FALSE,TRUE,0);
}
rhs_function* lookup_rhs_function ( agent thisAgent,
Symbol name 
)

Definition at line 102 of file rhsfun.cpp.

References rhs_function_struct::name, rhs_function_struct::next, NIL, and agent_struct::rhs_functions.

Referenced by parse_function_call_after_lparen(), and reteload_rhs_value().

{
for (rf=thisAgent->rhs_functions; rf!=NIL; rf=rf->next)
{
if (rf->name==name)
return rf;
}
return NIL;
}
void remove_built_in_rhs_functions ( agent thisAgent)

Definition at line 789 of file rhsfun.cpp.

References find_sym_constant(), remove_built_in_rhs_math_functions(), and remove_rhs_function().

Referenced by destroy_soar_agent().

{
// DJP-FREE: These used to call make_sym_constant, but the symbols must already exist and if we call make here again we leak a reference.
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "write"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "crlf"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "halt"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "make-constant-symbol"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "timestamp"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "accept"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "trim"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "capitalize-symbol"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "ifeq"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "strlen"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "dont-learn"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "force-learn"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "deep-copy"));
remove_rhs_function (thisAgent, find_sym_constant (thisAgent, "count"));
}
void remove_rhs_function ( agent thisAgent,
Symbol name 
)

Definition at line 114 of file rhsfun.cpp.

References free_memory(), MISCELLANEOUS_MEM_USAGE, rhs_function_struct::name, rhs_function_struct::next, NIL, print_with_symbols(), agent_struct::rhs_functions, and symbol_remove_ref().

Referenced by remove_built_in_rhs_functions(), and remove_built_in_rhs_math_functions().

{ /* code from Koss 8/00 */
rhs_function *rf = NIL, *prev;
/* Find registered function by name */
for (prev = NIL, rf = thisAgent->rhs_functions;
rf != NIL;
prev = rf, rf = rf->next)
{
if (rf->name == name)
break;
}
/* If not found, there's a problem */
if (rf == NIL) {
fprintf(stderr, "Internal error: attempt to remove_rhs_function that does not exist.\n");
print_with_symbols(thisAgent, "Internal error: attempt to remove_rhs_function that does not exist: %y\n", name);
}
/* Else, remove it */
else
{
/* Head of list special */
if (prev == NIL)
thisAgent->rhs_functions = rf->next;
else
prev->next = rf->next;
}
// DJP-FREE: The name reference needs to be released now the function is gone
symbol_remove_ref(thisAgent,name);
}
rhs_value reteloc_to_rhs_value ( byte  field_num,
rete_node_level  levels_up 
)
inline

Definition at line 133 of file rhsfun.h.

Referenced by fixup_rhs_value_variable_references(), and reteload_rhs_value().

{
return reinterpret_cast<rhs_value>(levels_up << 4) + (field_num << 2) + 2;
}
bool rhs_value_is_funcall ( rhs_value  rv)
inline
bool rhs_value_is_reteloc ( rhs_value  rv)
inline
bool rhs_value_is_symbol ( rhs_value  rv)
inline
bool rhs_value_is_unboundvar ( rhs_value  rv)
inline

Definition at line 113 of file rhsfun.h.

Referenced by copy_rhs_value(), copy_rhs_value_and_substitute_varnames(), deallocate_rhs_value(), instantiate_rhs_value(), and shouldCreateInstantiation().

{
return (reinterpret_cast<uintptr_t>(rv) & 3) == 3;
}
inline ::list* rhs_value_to_funcall_list ( rhs_value  rv)
uint8_t rhs_value_to_reteloc_field_num ( rhs_value  rv)
inline

Definition at line 157 of file rhsfun.h.

Referenced by calculate_support_for_instantiation_preferences(), copy_rhs_value_and_substitute_varnames(), instantiate_rhs_value(), p_node_left_addition(), retesave_rhs_value(), and shouldCreateInstantiation().

{
return static_cast<uint8_t>((reinterpret_cast<uintptr_t>(rv) >> 2) & 3);
}
uint16_t rhs_value_to_reteloc_levels_up ( rhs_value  rv)
inline

Definition at line 163 of file rhsfun.h.

Referenced by calculate_support_for_instantiation_preferences(), copy_rhs_value_and_substitute_varnames(), instantiate_rhs_value(), p_node_left_addition(), retesave_rhs_value(), and shouldCreateInstantiation().

{
return static_cast<uint16_t>((reinterpret_cast<uintptr_t>(rv) >> 4) & 0xFFFF);
}
Symbol* rhs_value_to_symbol ( rhs_value  rv)
inline
uint64_t rhs_value_to_unboundvar ( rhs_value  rv)
inline

Definition at line 169 of file rhsfun.h.

Referenced by copy_rhs_value_and_substitute_varnames(), instantiate_rhs_value(), and retesave_rhs_value().

{
return static_cast<uint64_t>((reinterpret_cast<uintptr_t>(rv) >> 2));
}
rhs_value symbol_to_rhs_value ( Symbol sym)
inline
rhs_value unboundvar_to_rhs_value ( uint64_t  n)
inline

Definition at line 139 of file rhsfun.h.

Referenced by fixup_rhs_value_variable_references(), and reteload_rhs_value().

{
return reinterpret_cast<rhs_value>((n << 2) + 3);
}