#include #include #include #define USER_VAR 6 #define TERM 2 #define ATOM 3 #define SUCCESS 1 #define FAILURE 0 #define NON_ACTION 0 #define ACTION 1 #define A_MOD 0 #define C_MOD 1 /* read in the automatically generated reserved word definitions */ #include "reserved_def.aux" /* the debugging switches */ #define MYDEBUG 0 #define WINDOW_OUTPUT 1 #define FULL_PROP 0 #define DETAIL_DEBUG 0 typedef struct term *term_pointer; typedef struct module_str * module_ptr; typedef struct term *term_ptr; struct term { short int term_type; /* VARIABLE, NONVAR, INTEGER, TUPLE, STRING or USER_VAR*/ int functor; /* if VARIABLE, functor is its offset if TUPLE, functor is 0 if NONVAR, functor is the functor number if INTEGER, functor is the integer */ char *const_string; int arity; struct term **argument_array; }; struct list /* these are linked lists */ { int type; void *object; struct list *next; }; struct clause { struct term *head; int var_counter; int body_size; struct term **body; }; typedef struct functor_struc functor; typedef void (*function_type)(int arity, module_ptr agent, struct term ** args, void *data); typedef struct { int functor; function_type funct; void *data; } module_function_descriptor; typedef void (*action_call)(module_ptr,term_ptr); typedef struct { int functor; action_call funct; } SystemActionDescriptor; typedef struct term *(*eval_function)(int, /*arity*/ struct term ** /*argument_array */); typedef struct { int functor; eval_function funct; } EvalFunctionDescriptor; typedef void (* generic_function)(module_ptr,term_ptr); struct module_str { char name[50]; int agent_functor; /* the number by which this agent is known to other agents */ int type;/* C_MOD or A_MOD */ int clause_counter; struct clause **clause_array; struct list **prop_table; struct list **clause_head_table; struct list **clause_body_table; struct list **clause_direct_table; struct list **direct_forward_table; struct list **encountered; int function_count; module_function_descriptor *f_table; generic_function generic; }; /* the symbol table data structure */ struct functor_struc { char name[40]; char type; char action_type; module_ptr agent_ref; int priority; }; typedef struct { struct list *garbage_vars; struct list *garbage_clauses; struct list *garbage_list_cells; struct list *garbage_terms; } garbage_lists; typedef struct atom *atom_ptr; typedef struct clause *clause_ptr; struct indexed_clause { int position; struct clause *cl; }; struct agent_term { module_ptr agent; struct term *term; }; struct proposition { module_ptr agent; struct term *term; struct proposition *negation; struct proposition *meta;/* if the prop is itself meta, the meta field represents the condition for adopting this goal (if any) */ struct clause_list *in_body_list; short int counter; unsigned int is_unique; unsigned int state: 1; unsigned int is_meta:1; unsigned int is_negative:1; unsigned int is_abducible:1; unsigned int processed:1; unsigned int is_incomplete:1; unsigned int is_action:1; int spy_id; /* if non-zero, indicates the ID of the spy window */ }; struct literal_list { unsigned int sign: 1; struct proposition *prop; struct literal_list *next; }; struct tms_clause { unsigned int c_type : 1; union { struct { struct proposition *ab; struct proposition *ab_bar; unsigned int firing : 1; int priority; } non_mon; struct { short int counter; struct tms_clause_element *c_e; } mon; } cl; }; struct tms_clause_element { struct proposition *prop; unsigned int private_counter : 1; unsigned int firing : 1; struct tms_clause_element *next; }; typedef struct { int length; term_pointer *array; } var_array; typedef struct term *(*sys_function)(struct term *); typedef struct { int functor; sys_function funct;/* the function associated with this system call */ } SystemCallDescriptor; struct list *cons(void *object,struct list *tail); struct proposition *make_complete(module_ptr agent,struct term *t, int action_type); struct proposition *make_incomplete(module_ptr agent, struct term *t, int action_type); struct proposition *make_abducible(module_ptr agent,struct term *t, int action_type); struct proposition *get_prop(module_ptr agent,struct term *t, int type, int action_flag); struct literal_list *cons_literal(int s, struct proposition *p, struct literal_list *list); term_pointer dereference(term_pointer var_term, var_array *vars); void update_clause_tables(module_ptr mod,struct clause *cl); void *nth_element(struct list *l, int i); struct atom *copy_atom(struct atom *a); struct term *copy_term(struct term *t); struct clause *copy_clause(struct clause *cl); int list_length(struct list *l); struct term *maketerm(int term_type,int functor, int arity,char *const_string, struct term **argument_array); term_pointer *maketermarray(int n); module_ptr parser_main(char *file_name); void print_prop_id(struct proposition *prop); void print_prop(struct proposition *prop); void print_module(module_ptr module); void print_clause(clause_ptr ptr, functor **sym_table); void print_atom(atom_ptr ptr, functor **sym_table); void print_term(term_ptr ptr,functor **sym_table); module_ptr read_module(char *file_name); struct list *append(struct list *l1, struct list *l2); var_array *create_vars(int n); void copy_vars(var_array *v1, var_array *v2); struct term *offset_copy_term(struct term *t,int offset); struct atom *offset_copy_atom(struct atom *a,int offset); struct clause *offset_copy_clause(struct clause *cl,int offset); struct list *direct_conj(module_ptr agent, struct term **dir, int count, int entry, struct list *vars_list,garbage_lists *g); struct list *g_cons(void *t, struct list *tail,garbage_lists *g); void collect(garbage_lists g); struct list *merge(struct list *l1, struct list *l2); struct list *var_sequence(struct term *t, garbage_lists *g); void print_int_list(struct list *l); int position(int t, struct list *l); void replace_vars(struct term *t, struct list *var_sequence); struct clause *parse_interactive_input(char *input); extern functor **sym_table; struct agent_term *next_action(); int functor_string(char *string); void make_goal(struct proposition *p); void make_fact(struct proposition *p); void initialize_tms(); void interface_c_func(int type, module_ptr agent, term_pointer term); void *send_message(int message_type, int recepient, int sender, struct term *content); void dispatch_loop(); void free_atom(struct atom *a); void free_clause(struct clause *cl); void free_term(struct term *t); struct term *intersection(struct term *set_list); struct term *least_element(struct term *set); struct term *t_next(struct term *l); int t_empty_list(struct term *t); void print_list(struct term *l, functor **sym_table); int loose_match(struct term *t1, struct term *t2); int term_on_list(struct term *t, var_array *vars,struct list *l); extern char *TermToString(term_pointer term); SystemCallDescriptor *GetSysDescriptor(int functor); struct list *system_call(SystemCallDescriptor *d, struct term *call_term, var_array *vars, garbage_lists *g); void time_trim(); void garbage_init(garbage_lists *g); typedef int (*comp_funct)(void *, void *); /* Term library */ extern int GetTermFunctor(term_pointer term); extern char *GetTermString(term_pointer term); extern int *GetTermValue(term_pointer term); extern term_pointer GetTermArgument(term_pointer term, int arg_num); extern char *TermToString(term_pointer term); /* Modules definitions */ typedef void (*module_entry_function)(int request_num); # define MODULE_INIT 1 # define MODULE_EXIT 2 /* Interpreter exiting function. */ extern void exit_interpreter();