10 static unsigned int randomseed;
148 *fn = t->type->keyword->symbol;
229 if (smaller && t->value_3) {
230 *v= *(
REAL *)t->value_3;
259 *v= *(
REAL *)t->value_3;
294 success=
matches(t->type,
boolean,&smaller);
380 printf(
"*** BUG: value already present in UNIFY_REAL_RESULT\n");
389 *(
REAL *)t->value_3 = v;
411 warningline(
"the persistent term '%P' appears in an arithmetic constraint and cannot be refined\n",t);
437 if(success && arg2) {
449 switch(num1+num2*2+num3*4) {
472 success=(val3==(
REAL)(val1>val2));
503 if(success && arg2) {
515 switch(num1+2*num2+4*num3) {
532 if(arg1==arg2 && !val3)
550 success=(val3==(
REAL)(val1==val2));
597 Errorline(
"malformed disjunction '%P'\n",funct);
628 if(success && arg2) {
640 switch(num1+num2*2+num3*4) {
663 success=(val3==(
REAL)(val1<val2));
695 if(success && arg2) {
707 switch(num1+num2*2+num3*4) {
730 success=(val3==(
REAL)(val1>=val2));
761 if(success && arg2) {
773 switch(num1+num2*2+num3*4) {
796 success=(val3==(
REAL)(val1<=val2));
817 long success=
TRUE,succ,lesseq;
854 Errorline(
"function result '%P' should be a boolean or a predicate.\n",
863 Errorline(
"missing argument to '*boolpred*'.\n");
896 long a1comp, a2comp, a3comp;
912 if (a1comp && a2comp && a3comp) {
916 if (a1== !sel || a2== !sel) {
918 }
else if (a1==sel) {
923 }
else if (a2==sel) {
928 }
else if (a3==sel) {
931 }
else if (arg1==arg2) {
947 Errorline(
"Non-boolean argument or result in '%P'.\n",funct);
999 if (a1comp && a2comp) {
1006 }
else if (arg1==arg2) {
1017 Errorline(
"Non-boolean argument or result in '%P'.\n",funct);
1038 long a1comp, a2comp, a3comp;
1054 if (a1comp && a2comp && a3comp) {
1065 }
else if (a1==
TRUE && arg3==arg2) {
1067 }
else if (a2==
TRUE && arg3==arg2) {
1069 }
else if (a3==
TRUE && arg1==arg2) {
1072 }
else if (a1==
FALSE) {
1074 }
else if (a2==
FALSE) {
1076 }
else if (a3==
FALSE) {
1079 }
else if (arg1==arg2) {
1081 }
else if (arg1==arg3) {
1083 }
else if (arg3==arg2) {
1096 Errorline(
"Non-boolean argument or result in '%P'.\n",funct);
1129 Errorline(
"argument is not a function in %P.\n",funct);
1188 (void)snprintf(thebuffer,20,
"%ld",(
long)v);
1192 Errorline(
"non-integer numeric feature in %P\n",funct);
1210 Errorline(
"attempt to add a feature to curried function %P\n",
1226 arity_add(arg1,label);
1261 long num1,num2,num3;
1262 REAL val1,val2,val3;
1272 if(success && arg2) {
1284 switch(num1+2*num2+4*num3) {
1301 if(arg1==arg2 && val3)
1319 success=(val3==(
REAL)(val1!=val2));
1630 if ((f=fopen(e,
"r"))) {
1722 long gts,success=
TRUE;
1761 long num,success=
TRUE;
1774 gts=(
unsigned long)gts_r;
1815 long ans,gts1,gts2,num,success=
TRUE;
1829 if (success && num) {
1830 gts1 = (
unsigned long) gts_r;
1832 if (success && num) {
1833 gts2 = (
unsigned long) gts_r;
1846 Errorline(
"bad second argument to %P.\n",funct);
1851 Errorline(
"bad first argument %P.\n",funct);
1892 ((sort==
QUERY)?
"query":
1893 ((sort==
FACT)?
"declaration":
"error")));
1909 long smaller,sort,old_var_occurred;
1943 ((sort==
QUERY)?
"query":((sort==
FACT)?
"declaration":
"error"))
1993 static long c_read(
long);
2015 Errorline(
"attempt to read past end of file (%E).\n");
2036 ((sort==
QUERY)?
"query":((sort==
FACT)?
"declaration":
"error"))
2072 Errorline(
"argument missing in %P.\n",g);
2096 if (nl_flag) printf(
"\n");
2097 printf(
"*** Exiting Wild_Life ");
2098 printf(
"[%1.3fs cpu, %1.3fs gc (%2.1f%%)]\n",
2099 (
life_end.tms_utime-life_start.tms_utime)/60.0,
2133 if(
NOTQUIET) fprintf(stderr,
"\n*** Abort");
2134 if(
NOTQUIET && nlflag) fprintf(stderr,
"\n");
2145 if(
NOTQUIET) fprintf(stderr,
"\n*** Abort");
2146 if(
NOTQUIET && nlflag) fprintf(stderr,
"\n");
2151 fprintf(stderr,
"\n*** END Abort");
2163 Errorline(
"built-in %P is not implemented yet.\n",t);
2178 Errorline(
"%P is a declaration, not a query.\n",t);
2222 Errorline(
"%P may not have arguments in %P.\n",arg1,g);
2225 Errorline(
"%P should be dynamic in %P.\n",arg1,g);
2228 Errorline(
"%P should be a function or uninterpreted in %P.\n",arg1,g);
2231 Errorline(
"%P is missing one or both arguments.\n",g);
2311 if (!strcmp(t->type->keyword->symbol,
"->")) {
2320 else if (!strcmp(t->type->keyword->symbol,
":-")) {
2354 Errorline(
"bad argument in %s.\n", (r?
"retract":
"clause"));
2415 if (eval_2)
return !error;
2420 Errorline(
"argument(s) missing in %P\n",g);
2430 int *error, *eval_2;
2442 Errorline(
"%P is an incorrect global variable declaration (%E).\n",t);
2453 Errorline(
"%T %P cannot be redeclared as a global variable (%E).\n",
2531 Errorline(
"argument(s) missing in %P\n",g);
2549 Errorline(
"%T %P cannot be redeclared persistent (%E).\n",
2616 Errorline(
"bad input stream in %P.\n",g);
2697 if (thestream!=
NULL) {
2746 long inclose,outclose;
2769 if (inclose || outclose) {
2771 (void)fclose((FILE *)arg1->
value_3);
2835 Errorline(
"argument missing in %P.\n",g);
2866 long i,success=
FALSE;
2868 char tstr[2], *str=tstr;
2878 i = (
unsigned long) floor(*(
REAL *) arg1->
value_3);
2879 if (i==(
unsigned long)(
unsigned char)i) {
2880 str[0] = i; str[1] = 0;
2884 Errorline(
"out-of-range character value in %P.\n",g);
2894 Errorline(
"argument missing in %P.\n",g);
3045 Errorline(
"argument in %P must be positive.\n",g);
3056 Errorline(
"argument missing in %P.\n",g);
3083 Errorline(
"argument in %P must be positive or zero.\n",g);
3153 traceline(
"pushing predicate disjunction choice point for %P\n",g);
3156 if (!arg1 && !arg2) {
3158 Errorline(
"neither first nor second arguments exist in %P.\n",g);
3203 *arg1addr=call_once;
3230 Errorline(
"argument to cond is not boolean in %P\n",g);
3250 long success=
TRUE,v;
3283 (
void)snprintf(thebuffer,20,
"%ld",(
long)v);
3341 if(arg1 && success) {
3395 if(arg1 && success) {
3621 success=(arg1!=arg2);
3663 success=(arg1==arg2);
3819 Errorline(
"non-numeric arguments in %P\n",funct);
3868 Errorline(
"result is not a real in %P\n",funct);
3872 Errorline(
"argument is not a string in %P\n",funct);
3904 Errorline(
"bad argument in %P\n",funct);
3907 Errorline(
"argument missing in %P\n",funct);
3937 Errorline(
"argument of %P should be a predicate.\n",funct);
3989 Errorline(
"argument of %P should be a predicate.\n",funct);
4038 Errorline(
"cannot use '<-' on persistent value in %P\n",g);
4064 Errorline(
"argument missing in %P.\n",g);
4098 Errorline(
"argument missing in %P.\n",g);
4142 Errorline(
"argument missing in %P.\n",g);
4194 Errorline(
"argument missing in %P.\n",g);
4288 Errorline(
"argument missing in %P.\n",g);
4340 Errorline(
"the argument %P of freeze must be a predicate.\n",arg1);
4358 traceline(
"evaluate frozen predicate %P\n",g);
4363 Errorline(
"the argument %P of freeze must be user-defined.\n",arg1);
4370 traceline(
"alternative clause has been retracted\n");
4470 str[0] = (
unsigned char) floor(*(
REAL *) arg1->
value_3);
4480 Errorline(
"argument of %P must be an integer.\n",funct);
4526 Errorline(
"String argument expected in '%P'\n",funct);
4595 warningline(
"argument of '%P' is not a string.\n",funct);
4603 Errorline(
"error occurred in '%P'\n",funct);
4633 (void)snprintf(buf,100,
"%g", *((
double *)(arg1->
value_3)));
4659 long success=
TRUE,i;
4661 REAL the_int,next,neg;
4676 if (the_int!=floor(the_int))
return FALSE;
4678 neg = (the_int<0.0);
4679 if (neg) the_int = -the_int;
4686 Errorline(
"internal buffer too small for int2str(%P).\n",arg1);
4689 next = floor(the_int/10);
4690 val[i]=
'0' + (
unsigned long) (the_int-next*10);
4694 if (neg) { i--; val[i]=
'-'; }
4814 return ((
unsigned long)r>0 && (
unsigned long)r<
MAX_BUILT_INS);
4885 s2=
" with an empty definition";
4909 outputline(
"'%s' is a %sglobal variable worth %P.\n",
4953 Errorline(
"argument of %P must be a predicate, function, or sort.\n",g);
4959 Errorline(
"argument missing in %P.\n",g);
5003 Errorline(
"argument(s) missing in %P.\n",g);
5062 fprintf(stderr,
"Too many primitives, increase MAX_BUILT_INS in extern.h\n");
5091 Errorline(
"operator precedence must be in the range 0..%d.\n",
5128 if (n && prec && type) {
5155 Errorline(
"precedence must range from 1 to 1200 in %P.\n",t);
5158 Errorline(
"precedence must be a positive integer in %P.\n",t);
5161 Errorline(
"numbers or strings may not be operators in %P.\n",t);
5164 Errorline(
"argument missing in %P.\n",t);
5176 result=(
char *)
heap_alloc(strlen(s1)+strlen(s2)+1);
5177 sprintf(result,
"%s%s",s1,s2);
5194 if(p>l || p<0 || n<0)
5202 *(result+i)= *(s+p+i-1);
5223 (void)fputc(fgetc(f2),f1);
5278 c_arg1= (
char *)arg1->
value_3;
5296 c_arg2= (
char *)arg2->
value_3;
5310 if(success && all_args) {
5311 c_result=
str_conc( c_arg1, c_arg2 );
5314 temp_result->value_3= (
GENERIC)c_result;
5415 c_arg1= (
char *)arg1->
value_3;
5429 if (success && all_args) {
5430 c_result=strlen(c_arg1);
5484 c_arg1= (
char *)arg1->
value_3;
5502 c_arg2= (long)(* (
double *)(arg2->
value_3));
5520 c_arg3= (long)(* (
double *)(arg3->value_3));
5534 if (success && all_args) {
5535 c_result=
sub_str(c_arg1,c_arg2,c_arg3);
5538 temp_result->value_3=(
GENERIC)c_result;
5582 c_arg1= (
char *)arg1->
value_3;
5600 c_arg2= (
char *)arg2->
value_3;
5652 c_arg1= (long)(* (
double *)(arg1->
value_3));
5666 if (success && all_args) {
5669 c_result=(rand_r(&randomseed)<<15) + rand_r(&randomseed);
5673 c_result=c_result-(c_result/c_arg1)*c_arg1;
5715 c_arg1= (long)(* (
double *)(arg1->
value_3));
5729 if (success && all_args) randomseed=c_arg1;
5731 if (success && all_args) srandom(c_arg1);
5759 while(arg1->
coref) {
5786 for(i=
arg_c-1;i>=0;i--) {
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
ptr_definition boolpredsym
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
long trail_condition(psi_term *Q)
static long built_in_index
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
long open_output_file(char *file)
void undo(ptr_stack limit)
static long c_combined_name()
void get_one_arg_addr(ptr_node t, ptr_psi_term **a)
static long c_exists_choice()
static long c_unify_func()
struct wl_definition * def_type
static long c_declaration()
ptr_psi_term stack_cons(ptr_psi_term head, ptr_psi_term tail)
void insert_type_builtins()
void residuate(ptr_psi_term t)
void listing_pred_write(ptr_node n, long fflag)
void exit_life(long nl_flag)
static long c_put_main(long)
long pred_clause(ptr_psi_term t, long r, ptr_psi_term g)
static long c_delay_check()
void push_ptr_value(type_ptr t, GENERIC *p)
ptr_module current_module
ptr_definition dynamicsym
ptr_psi_term real_stack_psi_term(long stat, REAL thereal)
static long c_exist_feature()
void push_choice_point(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
static long c_persistent()
void list_special(ptr_psi_term t)
static long generic_write()
ptr_definition listingsym
static long c_call_once()
ptr_psi_term exact_copy(ptr_psi_term t, long heap_flag)
void unify_bool_result(ptr_psi_term t, long v)
long only_arg1(ptr_psi_term t, ptr_psi_term *arg1)
void save_parse_state(ptr_parse_block pb)
static long c_freeze_inner(long freeze_flag)
void merge_unify(ptr_node *u, ptr_node v)
long(* c_rule[MAX_BUILT_INS])()
static long c_int2string()
ptr_psi_term heap_psi_term(long stat)
void delete_attr(char *s, ptr_node *n)
long redefine(ptr_psi_term t)
static long c_same_address()
void push_psi_ptr_value(ptr_psi_term q, GENERIC *p)
ptr_psi_term null_psi_term
void persistent_error_check(ptr_node n, int *error)
void restore_parse_state(ptr_parse_block pb)
void display_psi_stream(ptr_psi_term t)
ptr_psi_term new_psi_term(long numargs, ptr_definition typ, ptr_psi_term **a1, ptr_psi_term **a2)
long get_real_value(ptr_psi_term t, REAL *v, long *n)
void persistent_tree(ptr_node n)
static long c_unify_pred()
static void unify_bool(ptr_psi_term arg)
void global_error_check(ptr_node n, int *error, int *eval_2)
ptr_psi_term stack_bytes(char *s, int n)
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
void assert_protected(ptr_node n, long prot)
static long c_string2psi()
ptr_definition aborthooksym
static long c_diff_address()
void persistent_one(ptr_psi_term t)
void nonnum_warning(ptr_psi_term t, ptr_psi_term arg1, ptr_psi_term arg2)
static long c_print_codes()
ptr_hash_table symbol_table
void get_one_arg(ptr_node t, ptr_psi_term *a)
struct tms life_start life_end
ptr_node distinct_tree(ptr_node t)
static long c_string_address()
char * heap_ncopy_string(char *s, int n)
char * sub_str(char *s, long p, long n)
FILE * get_stream(ptr_psi_term t)
long overlap_type(ptr_definition t1, ptr_definition t2)
ptr_definition update_symbol(ptr_module module, char *symbol)
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
void insert_system_builtins()
ptr_resid_list resid_vars
static long c_page_width()
int get_module(ptr_psi_term psi, ptr_module *module)
long abort_life(int nlflag)
ptr_definition minus_symbol
void stack_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
void release_resid(ptr_psi_term t)
static long c_psi2string()
long sub_type(ptr_definition t1, ptr_definition t2)
void traceline(char *format,...)
long c_display_persistent()
void fetch_def_lazy(ptr_psi_term u, ptr_definition old1, ptr_definition old2, ptr_node old1attr, ptr_node old2attr, long old1stat, long old2stat)
ptr_definition add_module3
static long c_global_assign()
static long c_split_double()
ptr_psi_term quote_copy(ptr_psi_term t, long heap_flag)
void Errorline(char *format,...)
char * heap_copy_string(char *s)
static long c_write_err()
void assert_delay_check(ptr_node n)
ptr_int_list cons(GENERIC v, ptr_int_list l)
void stack_add_int_attr(ptr_psi_term t, char *attrname, long value)
static long c_writeq_err()
ptr_psi_term stack_pair(ptr_psi_term left, ptr_psi_term right)
long check_real(ptr_psi_term t, REAL *v, long *n)
void residuate2(ptr_psi_term u, ptr_psi_term v)
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
void bk_mark_quote(ptr_psi_term t)
static long c_get_choice()
void insert_sys_builtins()
void global_tree(ptr_node n)
ptr_psi_term distinct_copy(ptr_psi_term t)
long all_public_symbols()
long has_rules(ptr_pair_list r)
ptr_definition first_definition
static void clean_trail(ptr_choice_point cutpt)
static long c_logical_main(long sel)
ptr_psi_term error_psi_term
long append_files(char *s1, char *s2)
void mark_eval(ptr_psi_term t)
ptr_psi_term stack_int(long n)
void release_resid_notrail(ptr_psi_term t)
static long c_non_strict()
static long c_copy_term()
ptr_psi_term global_value
long is_built_in(ptr_pair_list r)
ptr_definition quoted_string
static long c_eval_disjunction()
ptr_psi_term stack_psi_term(long stat)
struct wl_operator_data * ptr_operator_data
struct wl_pair_list * ptr_pair_list
ptr_definition leftarrowsym
ptr_definition calloncesym
void pred_write(ptr_node n)
ptr_definition disjunction
ptr_psi_term inc_heap_copy(ptr_psi_term t)
static long get_bool(ptr_definition typ)
#define equal_types(A, B)
void mark_quote(ptr_psi_term t)
static long c_assert_last()
ptr_definition add_module2
ptr_node find(long comp, char *keystr, ptr_node tree)
void save_resid(ptr_resid_block rb, ptr_psi_term match_date)
ptr_psi_term stack_copy_psi_term(psi_term t)
long featcmp(char *str1, char *str2)
static long c_read_token()
void restore_state(ptr_psi_term t)
void outputline(char *format,...)
ptr_definition delay_checksym
ptr_psi_term make_feature_list(ptr_node tree, ptr_psi_term tail, ptr_module module, int val)
ptr_definition final_question
static long c_is_predicate()
long deref_eval(ptr_psi_term t)
static long c_is_function()
ptr_definition add_module1
void insert_math_builtins()
static long c_eval_inplace()
ptr_psi_term collect_symbols(long sel)
struct wl_psi_term * ptr_psi_term
void read_token_b(ptr_psi_term tok)
void save_state(ptr_psi_term t)
void init_built_in_types()
long print_variables(long printflag)
long unify_real_result(ptr_psi_term t, REAL v)
static long c_not_implemented()
long file_exists(char *s)
unsigned long global_time_stamp
long declare_operator(ptr_psi_term t)
void inherit_always_check()
void global_one(ptr_psi_term t)
static long c_bk_assign()
ptr_psi_term eval_copy(ptr_psi_term t, long heap_flag)
ptr_definition update_feature(ptr_module module, char *feature)
static ptr_node copy_attr_list(ptr_node n)
void warningline(char *format,...)
static long c_set_input()
static void op_declare(long p, operator t, char *s)
ptr_psi_term stack_string(char *s)
static long c_module_name()
static long c_write_canonical()
char * str_conc(char *s1, char *s2)
long hidden_type(ptr_definition t)
char * expand_file_name(char *s)
static long get_bool_value(ptr_psi_term t, REAL *v, long *n)
ptr_definition inputfilesym
static long c_print_depth()
long open_input_file(char *file)
static long c_copy_pointer()
static long c_feature_values()
ptr_module set_current_module(ptr_module module)
static long c_assert_first()
void assert_clause(ptr_psi_term t)
static long c_print_variables()
static long c_set_choice()
ptr_operator_data op_data
long i_check_out(ptr_psi_term t)
ptr_definition call_handlersym
GENERIC heap_alloc(long s)
static void set_parse_queryflag(ptr_node thelist, long sort)
ptr_choice_point choice_stack
static long c_set_output()
ptr_definition eval_argsym
static long c_such_that()
void assert_args_not_eval(ptr_node n)
long psi_to_string(ptr_psi_term t, char **fn)