2001-04-09 20:54:03 +01:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* YAP Prolog *
|
|
|
|
|
* *
|
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
|
* *
|
2004-05-14 17:33:47 +01:00
|
|
|
|
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
|
2001-04-09 20:54:03 +01:00
|
|
|
|
* *
|
|
|
|
|
**************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* File: stdpreds.c *
|
|
|
|
|
* comments: General-purpose C implemented system predicates *
|
|
|
|
|
* *
|
2005-01-05 05:32:37 +00:00
|
|
|
|
* Last rev: $Date: 2005-01-05 05:32:37 $,$Author: vsc $ *
|
2004-05-13 21:54:58 +01:00
|
|
|
|
* $Log: not supported by cvs2svn $
|
2005-01-05 05:32:37 +00:00
|
|
|
|
* Revision 1.79 2004/12/28 22:20:36 vsc
|
|
|
|
|
* some extra bug fixes for trail overflows: some cannot be recovered that easily,
|
|
|
|
|
* some can.
|
|
|
|
|
*
|
2004-12-28 22:20:37 +00:00
|
|
|
|
* Revision 1.78 2004/12/08 04:45:03 vsc
|
|
|
|
|
* polish changes to undefp
|
|
|
|
|
* get rid of a few warnings
|
|
|
|
|
*
|
2004-12-08 04:45:04 +00:00
|
|
|
|
* Revision 1.77 2004/12/05 05:07:26 vsc
|
|
|
|
|
* name/2 should accept [] as a valid list (string)
|
|
|
|
|
*
|
2004-12-05 05:07:26 +00:00
|
|
|
|
* Revision 1.76 2004/12/05 05:01:25 vsc
|
|
|
|
|
* try to reduce overheads when running with goal expansion enabled.
|
|
|
|
|
* CLPBN fixes
|
|
|
|
|
* Handle overflows when allocating big clauses properly.
|
|
|
|
|
*
|
2004-12-05 05:01:45 +00:00
|
|
|
|
* Revision 1.75 2004/12/02 06:06:46 vsc
|
|
|
|
|
* fix threads so that they at least start
|
|
|
|
|
* allow error handling to work with threads
|
|
|
|
|
* replace heap_base by Yap_heap_base, according to Yap's convention for globals.
|
|
|
|
|
*
|
2004-12-02 06:06:47 +00:00
|
|
|
|
* Revision 1.74 2004/11/19 22:08:43 vsc
|
|
|
|
|
* replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate.
|
|
|
|
|
*
|
2004-11-19 22:08:43 +00:00
|
|
|
|
* Revision 1.73 2004/11/19 17:14:14 vsc
|
|
|
|
|
* a few fixes for 64 bit compiling.
|
|
|
|
|
*
|
2004-11-19 17:14:15 +00:00
|
|
|
|
* Revision 1.72 2004/11/18 22:32:37 vsc
|
|
|
|
|
* fix situation where we might assume nonextsing double initialisation of C predicates (use
|
|
|
|
|
* Hidden Pred Flag).
|
|
|
|
|
* $host_type was double initialised.
|
|
|
|
|
*
|
2004-11-18 22:32:40 +00:00
|
|
|
|
* Revision 1.71 2004/07/23 21:08:44 vsc
|
|
|
|
|
* windows fixes
|
|
|
|
|
*
|
2004-07-23 22:08:45 +01:00
|
|
|
|
* Revision 1.70 2004/06/29 19:04:42 vsc
|
|
|
|
|
* fix multithreaded version
|
|
|
|
|
* include new version of Ricardo's profiler
|
|
|
|
|
* new predicat atomic_concat
|
|
|
|
|
* allow multithreaded-debugging
|
|
|
|
|
* small fixes
|
|
|
|
|
*
|
2004-06-29 20:04:46 +01:00
|
|
|
|
* Revision 1.69 2004/06/16 14:12:53 vsc
|
|
|
|
|
* miscellaneous fixes
|
|
|
|
|
*
|
2004-06-16 15:12:53 +01:00
|
|
|
|
* Revision 1.68 2004/05/14 17:11:30 vsc
|
|
|
|
|
* support BigNums in interface
|
|
|
|
|
*
|
2004-05-14 18:11:32 +01:00
|
|
|
|
* Revision 1.67 2004/05/14 16:33:45 vsc
|
|
|
|
|
* add Yap_ReadBuffer
|
|
|
|
|
*
|
2004-05-14 17:33:47 +01:00
|
|
|
|
* Revision 1.66 2004/05/13 20:54:58 vsc
|
|
|
|
|
* debugger fixes
|
|
|
|
|
* make sure we always go back to current module, even during initizlization.
|
|
|
|
|
*
|
2004-05-13 21:54:58 +01:00
|
|
|
|
* Revision 1.65 2004/04/27 15:14:36 vsc
|
|
|
|
|
* fix halt/0 and halt/1
|
|
|
|
|
* *
|
2004-04-27 16:14:38 +01:00
|
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*************************************************************************/
|
|
|
|
|
#ifdef SCCS
|
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file includes the definition of a miscellania of standard predicates
|
|
|
|
|
* for yap refering to: Consulting, Executing a C predicate from call,
|
|
|
|
|
* Comparisons (both general and numeric), Structure manipulation, Direct
|
|
|
|
|
* access to atoms and predicates, Basic support for the debugger
|
|
|
|
|
*
|
|
|
|
|
* It also includes a table where all C-predicates are initializated
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
|
#include "Yatom.h"
|
|
|
|
|
#include "Heap.h"
|
|
|
|
|
#include "eval.h"
|
|
|
|
|
#include "yapio.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-21 16:59:38 +00:00
|
|
|
|
#ifdef LOW_PROF
|
2005-01-05 05:32:37 +00:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/time.h>
|
2003-03-21 16:59:38 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
STD_PROTO(static Int p_setval, (void));
|
|
|
|
|
STD_PROTO(static Int p_value, (void));
|
|
|
|
|
STD_PROTO(static Int p_values, (void));
|
|
|
|
|
#ifdef undefined
|
|
|
|
|
STD_PROTO(static CODEADDR *FindAtom, (CODEADDR, int *));
|
|
|
|
|
#endif /* undefined */
|
|
|
|
|
STD_PROTO(static Int p_opdec, (void));
|
|
|
|
|
STD_PROTO(static Term get_num, (char *));
|
|
|
|
|
STD_PROTO(static Int p_name, (void));
|
|
|
|
|
STD_PROTO(static Int p_atom_chars, (void));
|
|
|
|
|
STD_PROTO(static Int p_atom_codes, (void));
|
|
|
|
|
STD_PROTO(static Int p_atom_length, (void));
|
|
|
|
|
STD_PROTO(static Int p_atom_split, (void));
|
|
|
|
|
STD_PROTO(static Int p_number_chars, (void));
|
|
|
|
|
STD_PROTO(static Int p_number_codes, (void));
|
|
|
|
|
STD_PROTO(static Int p_univ, (void));
|
|
|
|
|
STD_PROTO(static Int p_abort, (void));
|
|
|
|
|
STD_PROTO(static Int p_halt, (void));
|
|
|
|
|
STD_PROTO(static Int init_current_atom, (void));
|
|
|
|
|
STD_PROTO(static Int cont_current_atom, (void));
|
2001-10-03 14:39:16 +01:00
|
|
|
|
STD_PROTO(static Int init_current_predicate, (void));
|
|
|
|
|
STD_PROTO(static Int cont_current_predicate, (void));
|
2002-09-02 18:33:00 +01:00
|
|
|
|
STD_PROTO(static Int init_current_predicate_for_atom, (void));
|
|
|
|
|
STD_PROTO(static Int cont_current_predicate_for_atom, (void));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
STD_PROTO(static OpEntry *NextOp, (OpEntry *));
|
|
|
|
|
STD_PROTO(static Int init_current_op, (void));
|
|
|
|
|
STD_PROTO(static Int cont_current_op, (void));
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
STD_PROTO(static Int p_debug, (void));
|
|
|
|
|
#endif
|
|
|
|
|
STD_PROTO(static Int p_flags, (void));
|
|
|
|
|
STD_PROTO(static int AlreadyHidden, (char *));
|
|
|
|
|
STD_PROTO(static Int p_hide, (void));
|
|
|
|
|
STD_PROTO(static Int p_hidden, (void));
|
|
|
|
|
STD_PROTO(static Int p_unhide, (void));
|
|
|
|
|
STD_PROTO(static Int TrailMax, (void));
|
|
|
|
|
STD_PROTO(static Int GlobalMax, (void));
|
|
|
|
|
STD_PROTO(static Int LocalMax, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_heap_max, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_global_max, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_local_max, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_heap_info, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_stacks_info, (void));
|
|
|
|
|
STD_PROTO(static Int p_statistics_trail_info, (void));
|
|
|
|
|
STD_PROTO(static Term mk_argc_list, (void));
|
|
|
|
|
STD_PROTO(static Int p_argv, (void));
|
|
|
|
|
STD_PROTO(static Int p_cputime, (void));
|
|
|
|
|
STD_PROTO(static Int p_runtime, (void));
|
|
|
|
|
STD_PROTO(static Int p_walltime, (void));
|
|
|
|
|
STD_PROTO(static Int p_access_yap_flags, (void));
|
|
|
|
|
STD_PROTO(static Int p_set_yap_flags, (void));
|
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
|
2003-03-21 16:59:38 +00:00
|
|
|
|
#ifdef LOW_PROF
|
|
|
|
|
|
2004-03-04 21:17:40 +00:00
|
|
|
|
#define TIMER_DEFAULT 100
|
2004-02-25 19:06:31 +00:00
|
|
|
|
#define MORE_INFO_FILE 1
|
2005-01-05 05:32:37 +00:00
|
|
|
|
#define PROFILING_FILE 1
|
|
|
|
|
#define PROFPREDS_FILE 2
|
|
|
|
|
|
|
|
|
|
static char *DIRNAME=NULL;
|
|
|
|
|
|
|
|
|
|
char *set_profile_dir(char *);
|
|
|
|
|
char *set_profile_dir(char *name){
|
|
|
|
|
int size=0;
|
|
|
|
|
|
|
|
|
|
if (name!=NULL) {
|
|
|
|
|
size=strlen(name)+1;
|
|
|
|
|
if (DIRNAME!=NULL) free(DIRNAME);
|
|
|
|
|
DIRNAME=malloc(size);
|
|
|
|
|
if (DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
|
|
|
|
|
strcpy(DIRNAME,name);
|
|
|
|
|
}
|
|
|
|
|
if (DIRNAME==NULL) {
|
|
|
|
|
do {
|
|
|
|
|
if (DIRNAME!=NULL) free(DIRNAME);
|
|
|
|
|
size+=20;
|
|
|
|
|
DIRNAME=malloc(size);
|
|
|
|
|
if (DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
|
|
|
|
|
} while (getcwd(DIRNAME, size-15)==NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DIRNAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *profile_names(int);
|
|
|
|
|
char *profile_names(int k) {
|
|
|
|
|
static char *FNAME=NULL;
|
|
|
|
|
int size=200;
|
|
|
|
|
|
|
|
|
|
if (DIRNAME==NULL) set_profile_dir(NULL);
|
|
|
|
|
size=strlen(DIRNAME)+40;
|
|
|
|
|
if (FNAME!=NULL) free(FNAME);
|
|
|
|
|
FNAME=malloc(size);
|
|
|
|
|
if (FNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
|
|
|
|
|
strcpy(FNAME,DIRNAME);
|
|
|
|
|
|
|
|
|
|
if (k==PROFILING_FILE) {
|
|
|
|
|
sprintf(FNAME,"%s/PROFILING_%d",FNAME,getpid());
|
|
|
|
|
} else {
|
|
|
|
|
sprintf(FNAME,"%s/PROFPREDS_%d",FNAME,getpid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// printf("%s\n",FNAME);
|
|
|
|
|
return FNAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void del_profile_files(void);
|
|
|
|
|
void del_profile_files() {
|
|
|
|
|
if (DIRNAME!=NULL) {
|
|
|
|
|
remove(profile_names(PROFPREDS_FILE));
|
|
|
|
|
remove(profile_names(PROFILING_FILE));
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-21 14:00:23 +01:00
|
|
|
|
|
|
|
|
|
void
|
2004-02-25 19:06:31 +00:00
|
|
|
|
Yap_inform_profiler_of_clause(yamop *code_start, yamop *code_end, PredEntry *pe,int index_code) {
|
|
|
|
|
static Int order=0;
|
|
|
|
|
|
2003-05-21 14:00:23 +01:00
|
|
|
|
ProfPreds++;
|
|
|
|
|
if (FPreds != NULL) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
Int temp;
|
|
|
|
|
order++;
|
|
|
|
|
if (index_code) temp=-order; else temp=order;
|
2005-01-05 05:32:37 +00:00
|
|
|
|
fprintf(FPreds,"+%p %p %p %d",code_start,code_end, pe, temp);
|
2004-02-25 19:06:31 +00:00
|
|
|
|
#if MORE_INFO_FILE
|
|
|
|
|
if (pe->FunctorOfPred->KindOfPE==47872) {
|
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
|
fprintf(FPreds," %s/%d", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(FPreds," %s",RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
fprintf(FPreds,"\n");
|
2003-05-21 14:00:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
typedef struct clause_entry {
|
|
|
|
|
yamop *beg, *end;
|
|
|
|
|
PredEntry *pp;
|
2004-02-25 19:06:31 +00:00
|
|
|
|
UInt pcs; /* counter with total for each clause */
|
2004-06-29 20:04:46 +01:00
|
|
|
|
UInt pca; /* counter with total for each predicate (repeated for each clause)*/
|
|
|
|
|
Int ts; /* start end timestamp towards retracts, eventually */
|
2003-05-20 20:11:59 +01:00
|
|
|
|
} clauseentry;
|
2003-03-21 16:59:38 +00:00
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
static int
|
|
|
|
|
cl_cmp(const void *c1, const void *c2)
|
|
|
|
|
{
|
|
|
|
|
const clauseentry *cl1 = (const clauseentry *)c1;
|
|
|
|
|
const clauseentry *cl2 = (const clauseentry *)c2;
|
|
|
|
|
if (cl1->beg > cl2->beg) return 1;
|
|
|
|
|
if (cl1->beg < cl2->beg) return -1;
|
|
|
|
|
return 0;
|
2003-04-30 19:07:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
static int
|
|
|
|
|
p_cmp(const void *c1, const void *c2)
|
|
|
|
|
{
|
|
|
|
|
const clauseentry *cl1 = (const clauseentry *)c1;
|
|
|
|
|
const clauseentry *cl2 = (const clauseentry *)c2;
|
|
|
|
|
if (cl1->pp > cl2->pp) return 1;
|
|
|
|
|
if (cl1->pp < cl2->pp) return -1;
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
|
|
/* else same pp, but they are always different on the ts */
|
|
|
|
|
if (cl1->ts > cl2->ts) return 1;
|
|
|
|
|
else return -1;
|
2003-04-30 19:07:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
static clauseentry *
|
2003-05-20 20:11:59 +01:00
|
|
|
|
search_pc_pred(yamop *pc_ptr,clauseentry *beg, clauseentry *end) {
|
|
|
|
|
Int i, j, f, l;
|
2003-05-21 13:15:09 +01:00
|
|
|
|
f = 0; l = (end-beg);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
i = l/2;
|
|
|
|
|
while (TRUE) {
|
|
|
|
|
if (beg[i].beg > pc_ptr) {
|
|
|
|
|
l = i-1;
|
|
|
|
|
if (l < f) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
return NULL;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
j = i;
|
|
|
|
|
i = (f+l)/2;
|
|
|
|
|
} else if (beg[i].end < pc_ptr) {
|
|
|
|
|
f = i+1;
|
|
|
|
|
if (f > l) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
return NULL;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
i = (f+l)/2;
|
|
|
|
|
} else if (beg[i].beg <= pc_ptr && beg[i].end >= pc_ptr) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
return (&beg[i]);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
} else {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
return NULL;
|
2003-04-30 19:07:01 +01:00
|
|
|
|
}
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
extern void Yap_InitAbsmi(void);
|
|
|
|
|
extern int rational_tree_loop(CELL *pt0, CELL *pt0_end, CELL **to_visit0);
|
|
|
|
|
|
2005-01-05 05:32:37 +00:00
|
|
|
|
#ifdef ANALYST
|
2004-06-29 20:04:46 +01:00
|
|
|
|
static char *op_names[_std_top + 1] =
|
|
|
|
|
{
|
|
|
|
|
#define OPCODE(OP,TYPE) #OP
|
|
|
|
|
#include "YapOpcodes.h"
|
|
|
|
|
#undef OPCODE
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
extern char *op_names[];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static Int profend(void);
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
static int
|
2004-02-25 19:06:31 +00:00
|
|
|
|
showprofres(UInt type) {
|
2004-06-29 20:04:46 +01:00
|
|
|
|
clauseentry *pr, *t, *t2;
|
|
|
|
|
UInt count=0, ProfCalls=0, InGrowHeap=0, InGrowStack=0, InGC=0, InError=0, InUnify=0, InCCall=0;
|
|
|
|
|
yamop *pc_ptr,*y; void *oldpc;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
profend(); /* Make sure profiler has ended */
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
/* First part: Read information about predicates and store it on yap trail */
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
2005-01-05 05:32:37 +00:00
|
|
|
|
FPreds=fopen(profile_names(PROFPREDS_FILE),"r");
|
|
|
|
|
if (FPreds == NULL) { printf("Sorry, profiler couldn't find PROFPREDS file. \n"); return FALSE; }
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
|
|
ProfPreds=0;
|
2004-06-29 20:04:46 +01:00
|
|
|
|
pr=(clauseentry *) TR;
|
2005-01-05 05:32:37 +00:00
|
|
|
|
while (fscanf(FPreds,"+%p %p %p %d",&(pr->beg),&(pr->end),&(pr->pp),&(pr->ts)) > 0){
|
2004-02-25 19:06:31 +00:00
|
|
|
|
int c;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
pr->pcs = 0L;
|
|
|
|
|
pr++;
|
|
|
|
|
if (pr > (clauseentry *)Yap_TrailTop - 1024) {
|
2005-01-05 05:32:37 +00:00
|
|
|
|
Yap_growtrail(64 * 1024L, FALSE);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
2004-02-25 19:06:31 +00:00
|
|
|
|
ProfPreds++;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
do {
|
|
|
|
|
c=fgetc(FPreds);
|
|
|
|
|
} while(c!=EOF && c!='\n');
|
|
|
|
|
}
|
|
|
|
|
fclose(FPreds);
|
2005-01-05 05:32:37 +00:00
|
|
|
|
if (ProfPreds==0) return(TRUE);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
|
|
|
|
qsort((void *)TR, ProfPreds, sizeof(clauseentry), cl_cmp);
|
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
/* Second part: Read Profiling to know how many times each predicate has been profiled */
|
|
|
|
|
|
2005-01-05 05:32:37 +00:00
|
|
|
|
FProf=fopen(profile_names(PROFILING_FILE),"r");
|
|
|
|
|
if (FProf==NULL) { printf("Sorry, profiler couldn't find PROFILING file. \n"); return FALSE; }
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
|
|
t2=NULL;
|
|
|
|
|
ProfCalls=0;
|
2004-06-29 20:04:46 +01:00
|
|
|
|
while(fscanf(FProf,"%p %p\n",&oldpc, &pc_ptr) >0){
|
2004-02-25 19:06:31 +00:00
|
|
|
|
if (type<10) ProfCalls++;
|
2004-06-29 20:04:46 +01:00
|
|
|
|
|
|
|
|
|
if (oldpc!=0 && type<=2) {
|
|
|
|
|
if ((unsigned long)oldpc< 70000) {
|
|
|
|
|
if ((unsigned long) oldpc & GrowHeapMode) { InGrowHeap++; continue; }
|
|
|
|
|
if ((unsigned long)oldpc & GrowStackMode) { InGrowStack++; continue; }
|
|
|
|
|
if ((unsigned long)oldpc & GCMode) { InGC++; continue; }
|
|
|
|
|
if ((unsigned long)oldpc & (ErrorHandlingMode | InErrorMode)) { InError++; continue; }
|
|
|
|
|
}
|
|
|
|
|
if (oldpc>(void *) rational_tree_loop && oldpc<(void *) Yap_InitAbsmi) { InUnify++; continue; }
|
|
|
|
|
y=(yamop *) ((long) pc_ptr-20);
|
|
|
|
|
if ((void *) y->opc==Yap_ABSMI_OPCODES[_call_cpred] || (void *) y->opc==Yap_ABSMI_OPCODES[_call_usercpred]) {
|
|
|
|
|
InCCall++; /* I Was in a C Call */
|
|
|
|
|
pc_ptr=y;
|
|
|
|
|
/*
|
|
|
|
|
printf("Aqui est<73> um call_cpred(%p) \n",y->u.sla.sla_u.p->cs.f_code);
|
|
|
|
|
for(i=0;i<_std_top && pc_ptr->opc!=Yap_ABSMI_OPCODES[i];i++);
|
|
|
|
|
printf("Outro syscall diferente %s\n", op_names[i]);
|
|
|
|
|
*/
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* I should never get here, but since I'm, it is certanly Unknown Code, so
|
|
|
|
|
continue running to try to count it as Prolog Code */
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
t=search_pc_pred(pc_ptr,(clauseentry *)TR,pr);
|
|
|
|
|
if (t!=NULL) { /* pc was found */
|
2004-06-29 20:04:46 +01:00
|
|
|
|
if (type<10) t->pcs++;
|
|
|
|
|
else {
|
|
|
|
|
if (t->pp==(PredEntry *)type) {
|
|
|
|
|
ProfCalls++;
|
|
|
|
|
if (t2!=NULL) t2->pcs++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
t2=t;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
fclose(FProf);
|
2005-01-05 05:32:37 +00:00
|
|
|
|
if (ProfCalls==0) return(TRUE);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
/*I have the counting by clauses, but we also need them by predicate */
|
|
|
|
|
qsort((void *)TR, ProfPreds, sizeof(clauseentry), p_cmp);
|
2003-05-20 20:11:59 +01:00
|
|
|
|
t = (clauseentry *)TR;
|
|
|
|
|
while (t < pr) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
UInt calls=t->pcs;
|
|
|
|
|
|
|
|
|
|
t2=t+1;
|
|
|
|
|
while(t2<pr && t2->pp==t->pp) {
|
|
|
|
|
calls+=t2->pcs;
|
|
|
|
|
t2++;
|
|
|
|
|
}
|
|
|
|
|
while(t<t2) {
|
|
|
|
|
t->pca=calls;
|
|
|
|
|
t++;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
|
|
/* counting done: now it is time to present the results */
|
2004-06-29 20:04:46 +01:00
|
|
|
|
fflush(stdout);
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
/*
|
2004-02-25 19:06:31 +00:00
|
|
|
|
if (type>10) {
|
|
|
|
|
PredEntry *myp = (PredEntry *)type;
|
|
|
|
|
if (myp->FunctorOfPred->KindOfPE==47872) {
|
|
|
|
|
printf("Details on predicate:");
|
|
|
|
|
printf(" %s",RepAtom(AtomOfTerm(myp->ModuleOfPred))->StrOfAE);
|
|
|
|
|
printf(":%s",RepAtom(NameOfFunctor(myp->FunctorOfPred))->StrOfAE);
|
|
|
|
|
if (myp->ArityOfPE) printf("/%d\n",myp->ArityOfPE);
|
|
|
|
|
}
|
|
|
|
|
type=1;
|
|
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
|
*/
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
if (type==0 || type==1 || type==3) { /* Results by predicate */
|
2004-02-25 19:06:31 +00:00
|
|
|
|
t = (clauseentry *)TR;
|
|
|
|
|
while (t < pr) {
|
|
|
|
|
UInt calls=t->pca;
|
|
|
|
|
PredEntry *myp = t->pp;
|
|
|
|
|
|
|
|
|
|
if (calls && myp->FunctorOfPred->KindOfPE==47872) {
|
|
|
|
|
count+=calls;
|
|
|
|
|
printf("%p",myp);
|
|
|
|
|
printf(" %s",RepAtom(AtomOfTerm(myp->ModuleOfPred))->StrOfAE);
|
|
|
|
|
printf(":%s",RepAtom(NameOfFunctor(myp->FunctorOfPred))->StrOfAE);
|
|
|
|
|
if (myp->ArityOfPE) printf("/%d",myp->ArityOfPE);
|
|
|
|
|
printf(" -> %u (%3.1f%c)\n",calls,(float) calls*100/ProfCalls,'%');
|
|
|
|
|
}
|
|
|
|
|
while (t<pr && t->pp == myp) t++;
|
|
|
|
|
}
|
|
|
|
|
} else { /* Results by clauses */
|
|
|
|
|
t = (clauseentry *)TR;
|
|
|
|
|
while (t < pr) {
|
|
|
|
|
if (t->pca!=0 && (t->ts>=0 || t->pcs!=0) && t->pp->FunctorOfPred->KindOfPE==47872) {
|
|
|
|
|
UInt calls=t->pcs;
|
|
|
|
|
if (t->ts<0) { /* join all index entries */
|
|
|
|
|
t2=t+1;
|
|
|
|
|
while(t2<pr && t2->pp==t->pp && t2->ts<0) {
|
|
|
|
|
t++;
|
|
|
|
|
calls+=t->pcs;
|
|
|
|
|
t2++;
|
|
|
|
|
}
|
|
|
|
|
printf("IDX");
|
|
|
|
|
} else {
|
|
|
|
|
printf(" ");
|
|
|
|
|
}
|
|
|
|
|
count+=calls;
|
|
|
|
|
// printf("%p %p",t->pp, t->beg);
|
|
|
|
|
printf(" %s",RepAtom(AtomOfTerm(t->pp->ModuleOfPred))->StrOfAE);
|
|
|
|
|
printf(":%s",RepAtom(NameOfFunctor(t->pp->FunctorOfPred))->StrOfAE);
|
|
|
|
|
if (t->pp->ArityOfPE) printf("/%d",t->pp->ArityOfPE);
|
|
|
|
|
printf(" -> %u (%3.1f%c)\n",calls,(float) calls*100/ProfCalls,'%');
|
|
|
|
|
}
|
|
|
|
|
t++;
|
|
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
|
}
|
|
|
|
|
count=ProfCalls-(count+InGrowHeap+InGrowStack+InGC+InError+InUnify+InCCall); // Falta +InCCall
|
|
|
|
|
if (InGrowHeap>0) printf("%p sys: GrowHeap -> %u (%3.1f%c)\n",(void *) GrowHeapMode,InGrowHeap,(float) InGrowHeap*100/ProfCalls,'%');
|
|
|
|
|
if (InGrowStack>0) printf("%p sys: GrowStack -> %u (%3.1f%c)\n",(void *) GrowStackMode,InGrowStack,(float) InGrowStack*100/ProfCalls,'%');
|
|
|
|
|
if (InGC>0) printf("%p sys: GC -> %u (%3.1f%c)\n",(void *) GCMode,InGC,(float) InGC*100/ProfCalls,'%');
|
|
|
|
|
if (InError>0) printf("%p sys: ErrorHandling -> %u (%3.1f%c)\n",(void *) ErrorHandlingMode,InError,(float) InError*100/ProfCalls,'%');
|
|
|
|
|
if (InUnify>0) printf("%p sys: Unify -> %u (%3.1f%c)\n",(void *) UnifyMode,InUnify,(float) InUnify*100/ProfCalls,'%');
|
|
|
|
|
if (InCCall>0) printf("%p sys: C Code -> %u (%3.1f%c)\n",(void *) CCallMode,InCCall,(float) InCCall*100/ProfCalls,'%');
|
|
|
|
|
if (count>0) printf("Unknown:Unknown -> %u (%3.1f%c)\n",count,(float) count*100/ProfCalls,'%');
|
|
|
|
|
printf("Total of Calls=%u \n",ProfCalls);
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
|
|
|
2004-06-29 20:04:46 +01:00
|
|
|
|
|
|
|
|
|
static Int profinit(void)
|
|
|
|
|
{
|
|
|
|
|
if (ProfilerOn!=0) return (FALSE);
|
|
|
|
|
|
2005-01-05 05:32:37 +00:00
|
|
|
|
FPreds=fopen(profile_names(PROFPREDS_FILE),"w+");
|
2004-06-29 20:04:46 +01:00
|
|
|
|
if (FPreds == NULL) return FALSE;
|
2005-01-05 05:32:37 +00:00
|
|
|
|
FProf=fopen(profile_names(PROFILING_FILE),"w+");
|
2004-06-29 20:04:46 +01:00
|
|
|
|
if (FProf==NULL) { fclose(FPreds); return FALSE; }
|
|
|
|
|
|
|
|
|
|
Yap_dump_code_area_for_profiler();
|
|
|
|
|
|
|
|
|
|
ProfilerOn = -1; /* Inited but not yet started */
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern void prof_alrm(int signo, siginfo_t *si, void *sc);
|
|
|
|
|
|
|
|
|
|
static Int start_profilers(int msec)
|
|
|
|
|
{
|
|
|
|
|
struct itimerval t;
|
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
|
|
if (ProfilerOn!=-1) return (FALSE); /* have to go through profinit */
|
|
|
|
|
|
|
|
|
|
sa.sa_sigaction=prof_alrm;
|
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
sa.sa_flags=SA_SIGINFO;
|
|
|
|
|
if (sigaction(SIGPROF,&sa,NULL)== -1) return FALSE;
|
|
|
|
|
// if (signal(SIGPROF,prof_alrm) == SIG_ERR) return FALSE;
|
|
|
|
|
|
|
|
|
|
t.it_interval.tv_sec=0;
|
|
|
|
|
t.it_interval.tv_usec=msec;
|
|
|
|
|
t.it_value.tv_sec=0;
|
|
|
|
|
t.it_value.tv_usec=msec;
|
|
|
|
|
setitimer(ITIMER_PROF,&t,NULL);
|
|
|
|
|
|
|
|
|
|
ProfilerOn = msec;
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int profon(void) {
|
|
|
|
|
Term p;
|
|
|
|
|
p=Deref(ARG1);
|
|
|
|
|
return(start_profilers(IntOfTerm(p)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int profon0(void) {
|
|
|
|
|
return(start_profilers(TIMER_DEFAULT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int profoff(void) {
|
|
|
|
|
if (ProfilerOn>0) {
|
|
|
|
|
setitimer(ITIMER_PROF,NULL,NULL);
|
|
|
|
|
ProfilerOn = -1;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int profalt(void) {
|
|
|
|
|
if (ProfilerOn==0) return(FALSE);
|
|
|
|
|
if (ProfilerOn==-1) return profon();
|
|
|
|
|
return profoff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int profend(void)
|
|
|
|
|
{
|
|
|
|
|
if (ProfilerOn==0) return(FALSE);
|
|
|
|
|
profoff(); /* Make sure profiler is off */
|
|
|
|
|
fclose(FPreds);
|
|
|
|
|
fclose(FProf);
|
|
|
|
|
ProfilerOn=0;
|
|
|
|
|
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
static Int profres(void) {
|
2004-02-25 19:06:31 +00:00
|
|
|
|
Term p;
|
|
|
|
|
p=Deref(ARG1);
|
|
|
|
|
if (IsLongIntTerm(p)) return(showprofres(LongIntOfTerm(p)));
|
|
|
|
|
else return(showprofres(IntOfTerm(p)));
|
2003-05-20 20:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-25 19:06:31 +00:00
|
|
|
|
static Int profres0(void) {
|
|
|
|
|
return(showprofres(0));
|
2003-03-21 16:59:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* LOW_PROF */
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_setval(void)
|
|
|
|
|
{ /* '$set_value'(+Atom,+Atomic) */
|
|
|
|
|
Term t1 = Deref(ARG1), t2 = Deref(ARG2);
|
|
|
|
|
if (!IsVarTerm(t1) && IsAtomTerm(t1) &&
|
|
|
|
|
(!IsVarTerm(t2) && (IsAtomTerm(t2) || IsNumTerm(t2)))) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_PutValue(AtomOfTerm(t1), t2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_value(void)
|
|
|
|
|
{ /* '$get_value'(+Atom,?Val) */
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2002-09-13 22:30:06 +01:00
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"get_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"get_value/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
2002-09-13 22:30:06 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG2, Yap_GetValue(AtomOfTerm(t1))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_values(void)
|
|
|
|
|
{ /* '$values'(Atom,Old,New) */
|
|
|
|
|
Term t1 = Deref(ARG1), t3 = Deref(ARG3);
|
|
|
|
|
|
2002-09-13 22:30:06 +01:00
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"set_value/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
2002-09-13 22:30:06 +01:00
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"set_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (!Yap_unify_constant(ARG2, Yap_GetValue(AtomOfTerm(t1))))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
if (!IsVarTerm(t3)) {
|
|
|
|
|
if (IsAtomTerm(t3) || IsNumTerm(t3)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_PutValue(AtomOfTerm(t1), t3);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else
|
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
|
inline static void
|
|
|
|
|
do_signal(yap_signals sig)
|
|
|
|
|
{
|
|
|
|
|
LOCK(SignalLock);
|
|
|
|
|
CreepFlag = Unsigned(LCL0);
|
|
|
|
|
ActiveSignals |= sig;
|
|
|
|
|
UNLOCK(SignalLock);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
|
static Int
|
2001-04-09 20:54:03 +01:00
|
|
|
|
p_creep(void)
|
|
|
|
|
{
|
|
|
|
|
Atom at;
|
|
|
|
|
PredEntry *pred;
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
at = Yap_FullLookupAtom("$creep");
|
|
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
2001-10-30 16:42:05 +00:00
|
|
|
|
CreepCode = pred;
|
2004-01-23 02:23:51 +00:00
|
|
|
|
yap_flags[SPY_CREEP_FLAG] = TRUE;
|
|
|
|
|
do_signal(YAP_CREEP_SIGNAL);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_stop_creep(void)
|
|
|
|
|
{
|
2004-02-06 17:22:24 +00:00
|
|
|
|
LOCK(SignalLock);
|
2004-05-13 21:54:58 +01:00
|
|
|
|
ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
|
if (!ActiveSignals) {
|
|
|
|
|
CreepFlag = CalculateStackGap();
|
|
|
|
|
}
|
2004-02-06 17:22:24 +00:00
|
|
|
|
UNLOCK(SignalLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
|
void
|
|
|
|
|
Yap_signal(yap_signals sig)
|
2002-11-11 17:38:10 +00:00
|
|
|
|
{
|
2004-01-23 02:23:51 +00:00
|
|
|
|
do_signal(sig);
|
2002-11-11 17:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#ifdef undefined
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Returns where some particular piece of code is, it may take its time but
|
|
|
|
|
* then you only need it while creeping, so why bother ?
|
|
|
|
|
*/
|
|
|
|
|
static CODEADDR *
|
|
|
|
|
FindAtom(codeToFind, arity)
|
|
|
|
|
CODEADDR codeToFind;
|
|
|
|
|
unsigned int *arityp;
|
|
|
|
|
{
|
|
|
|
|
Atom a;
|
|
|
|
|
int i;
|
|
|
|
|
|
2003-10-28 01:16:03 +00:00
|
|
|
|
for (i = 0; i < AtomHashTableSize; ++i) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_LOCK(HashChain[i].AeRWLock);
|
|
|
|
|
a = HashChain[i].Entry;
|
|
|
|
|
READ_UNLOCK(HashChain[i].AeRWLock);
|
|
|
|
|
while (a != NIL) {
|
|
|
|
|
register PredEntry *pp;
|
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
|
READ_LOCK(ae->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
pp = RepPredProp(RepAtom(a)->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
while (!EndOfPAEntr(pp) && ((pp->KindOfPE & 0x8000)
|
|
|
|
|
|| (pp->CodeOfPred != codeToFind)))
|
|
|
|
|
pp = RepPredProp(pp->NextOfPE);
|
|
|
|
|
if (pp != NIL) {
|
|
|
|
|
CODEADDR *out;
|
|
|
|
|
READ_LOCK(pp->PRWLock);
|
|
|
|
|
out = &(pp->CodeOfPred)
|
|
|
|
|
*arityp = pp->ArityOfPE;
|
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
|
return (out);
|
|
|
|
|
}
|
|
|
|
|
a = RepAtom(a)->NextOfAE;
|
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*arityp = 0;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is called when you want to creep a C-predicate or a predicate written
|
|
|
|
|
* in assembly
|
|
|
|
|
*/
|
|
|
|
|
CELL
|
|
|
|
|
FindWhatCreep(toCreep)
|
|
|
|
|
CELL toCreep;
|
|
|
|
|
{
|
|
|
|
|
unsigned int arity;
|
|
|
|
|
Atom at;
|
|
|
|
|
CODEADDR *place;
|
|
|
|
|
|
|
|
|
|
if (toCreep > 64) { /* written in C */
|
|
|
|
|
int i;
|
|
|
|
|
place = FindAtom((CODEADDR) toCreep, &arity);
|
|
|
|
|
*--ASP = Unsigned(P);
|
|
|
|
|
*--ASP = N = arity;
|
|
|
|
|
for (i = 1; i <= arity; ++i)
|
|
|
|
|
*--ASP = X[i];
|
|
|
|
|
/* P = CellPtr(CCREEPCODE); */
|
|
|
|
|
return (Unsigned(place));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* undefined */
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_opdec(void)
|
2002-09-09 18:40:12 +01:00
|
|
|
|
{ /* '$opdec'(p,type,atom) */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* we know the arguments are integer, atom, atom */
|
|
|
|
|
Term p = Deref(ARG1), t = Deref(ARG2), at = Deref(ARG3);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_OpDec((int) IntOfTerm(p), RepAtom(AtomOfTerm(t))->StrOfAE,
|
2001-04-09 20:54:03 +01:00
|
|
|
|
AtomOfTerm(at)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NO_STRTOD
|
|
|
|
|
|
|
|
|
|
#if HAVE_CTYPE_H
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
strtod(s, pe)
|
|
|
|
|
char *s, **pe;
|
|
|
|
|
{
|
|
|
|
|
double r = atof(s);
|
|
|
|
|
*pe = s;
|
|
|
|
|
while (*s == ' ')
|
|
|
|
|
++s;
|
|
|
|
|
if (*s == '+' || *s == '-')
|
|
|
|
|
++s;
|
|
|
|
|
if (!isdigit(*s))
|
|
|
|
|
return (r);
|
|
|
|
|
while (isdigit(*s))
|
|
|
|
|
++s;
|
|
|
|
|
if (*s == '.')
|
|
|
|
|
++s;
|
|
|
|
|
while (isdigit(*s))
|
|
|
|
|
++s;
|
|
|
|
|
if (*s == 'e' || *s == 'E')
|
|
|
|
|
++s;
|
|
|
|
|
if (*s == '+' || *s == '-')
|
|
|
|
|
++s;
|
|
|
|
|
while (isdigit(*s))
|
|
|
|
|
++s;
|
|
|
|
|
*pe = s;
|
|
|
|
|
return (r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static char *cur_char_ptr;
|
|
|
|
|
|
|
|
|
|
static int
|
2003-01-13 14:02:50 +00:00
|
|
|
|
get_char_from_string(int s)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
|
|
|
|
if (cur_char_ptr[0] == '\0')
|
|
|
|
|
return(-1);
|
|
|
|
|
cur_char_ptr++;
|
|
|
|
|
return((int)(cur_char_ptr[-1]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Term
|
|
|
|
|
get_num(char *t)
|
|
|
|
|
{
|
|
|
|
|
Term out;
|
|
|
|
|
|
|
|
|
|
cur_char_ptr = t;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
out = Yap_scan_num(get_char_from_string);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* not ever iso */
|
|
|
|
|
if (out == TermNil && yap_flags[LANGUAGE_MODE_FLAG] != 1) {
|
|
|
|
|
int sign = 1;
|
|
|
|
|
if (t[0] == '+') {
|
|
|
|
|
t++;
|
|
|
|
|
}
|
|
|
|
|
if (t[0] == '-') {
|
|
|
|
|
t++;
|
|
|
|
|
sign = -1;
|
|
|
|
|
}
|
|
|
|
|
if(strcmp(t,"inf") == 0) {
|
|
|
|
|
Term ta[1];
|
2002-11-18 18:18:05 +00:00
|
|
|
|
ta[0] = MkAtomTerm(Yap_LookupAtom("inf"));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (sign > 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_MkApplTerm(Yap_MkFunctor(AtomPlus, 1), 1, ta));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_MkApplTerm(Yap_MkFunctor(AtomMinus, 1), 1, ta));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if(strcmp(t,"nan") == 0) {
|
|
|
|
|
Term ta[1];
|
2002-11-18 18:18:05 +00:00
|
|
|
|
ta[0] = MkAtomTerm(Yap_LookupAtom("nan"));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (sign > 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_MkApplTerm(Yap_MkFunctor(AtomPlus, 1), 1, ta));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_MkApplTerm(Yap_MkFunctor(AtomMinus, 1), 1, ta));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (cur_char_ptr[0] == '\0')
|
|
|
|
|
return(out);
|
|
|
|
|
else
|
|
|
|
|
return(TermNil);
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-02 16:44:58 +00:00
|
|
|
|
static UInt
|
2001-04-09 20:54:03 +01:00
|
|
|
|
runtime(void)
|
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_cputime()-Yap_total_gc_time()-Yap_total_stack_shift_time());
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Int last_gc_time = 0;
|
|
|
|
|
Int last_ss_time = 0;
|
|
|
|
|
|
|
|
|
|
/* $runtime(-SinceInterval,-SinceStart) */
|
|
|
|
|
static Int
|
|
|
|
|
p_runtime(void)
|
|
|
|
|
{
|
|
|
|
|
Int now, interval,
|
|
|
|
|
gc_time,
|
|
|
|
|
ss_time;
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_cputime_interval(&now, &interval);
|
|
|
|
|
gc_time = Yap_total_gc_time();
|
|
|
|
|
ss_time = Yap_total_stack_shift_time();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
now -= gc_time+ss_time;
|
|
|
|
|
interval -= (gc_time-last_gc_time)+(ss_time-last_ss_time);
|
|
|
|
|
last_gc_time = gc_time;
|
|
|
|
|
last_ss_time = ss_time;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* $cputime(-SinceInterval,-SinceStart) */
|
|
|
|
|
static Int
|
|
|
|
|
p_cputime(void)
|
|
|
|
|
{
|
|
|
|
|
Int now, interval;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_cputime_interval(&now, &interval);
|
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_walltime(void)
|
|
|
|
|
{
|
|
|
|
|
Int now, interval;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_walltime_interval(&now, &interval);
|
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_char_code(void)
|
|
|
|
|
{
|
|
|
|
|
Int t0 = Deref(ARG1);
|
|
|
|
|
if (IsVarTerm(t0)) {
|
|
|
|
|
Term t1 = Deref(ARG2);
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t0,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsIntegerTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t1,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else {
|
|
|
|
|
Int code = IntegerOfTerm(t1);
|
|
|
|
|
char codes[2];
|
|
|
|
|
Term tout;
|
|
|
|
|
|
|
|
|
|
if (code < 0 || code > 256) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,t1,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
codes[0] = code;
|
|
|
|
|
codes[1] = '\0';
|
2002-11-18 18:18:05 +00:00
|
|
|
|
tout = MkAtomTerm(Yap_LookupAtom(codes));
|
|
|
|
|
return(Yap_unify(ARG1,tout));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
} else if (!IsAtomTerm(t0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,t0,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else {
|
|
|
|
|
char *c = RepAtom(AtomOfTerm(t0))->StrOfAE;
|
|
|
|
|
if (c[1] != '\0') {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,t0,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(ARG2,MkIntTerm((Int)(c[0]))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_name(void)
|
|
|
|
|
{ /* name(?Atomic,?String) */
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String, *s; /* alloc temp space on trail */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term t, NewT, AtomNameT = Deref(ARG1);
|
|
|
|
|
|
2004-12-05 05:07:26 +00:00
|
|
|
|
t = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (!IsVarTerm(AtomNameT)) {
|
|
|
|
|
if (IsAtomTerm(AtomNameT)) {
|
|
|
|
|
s = RepAtom(AtomOfTerm(AtomNameT))->StrOfAE;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(s);
|
2004-12-05 05:07:26 +00:00
|
|
|
|
if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,
|
2001-04-09 20:54:03 +01:00
|
|
|
|
"name/2");
|
2004-12-05 05:07:26 +00:00
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2004-12-05 05:07:26 +00:00
|
|
|
|
return Yap_unify(NewT, ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else if (IsIntTerm(AtomNameT)) {
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
|
|
|
|
sprintf(String, "%ld", IntOfTerm(AtomNameT));
|
|
|
|
|
#else
|
|
|
|
|
sprintf(String, "%d", IntOfTerm(AtomNameT));
|
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2004-12-05 05:07:26 +00:00
|
|
|
|
if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else if (IsFloatTerm(AtomNameT)) {
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
sprintf(String, "%f", FloatOfTerm(AtomNameT));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2004-12-05 05:07:26 +00:00
|
|
|
|
if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else if (IsLongIntTerm(AtomNameT)) {
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
|
|
|
|
sprintf(String, "%ld", LongIntOfTerm(AtomNameT));
|
|
|
|
|
#else
|
|
|
|
|
sprintf(String, "%d", LongIntOfTerm(AtomNameT));
|
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2004-12-05 05:07:26 +00:00
|
|
|
|
if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
s = String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (!IsVarTerm(t) && t == MkAtomTerm(AtomNil)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkAtomTerm(Yap_LookupAtom(""))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
while (!IsVarTerm(t) && IsPairTerm(t)) {
|
|
|
|
|
Term Head;
|
|
|
|
|
Int i;
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,Head,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
|
if (i < 0 || i > 255) {
|
|
|
|
|
if (i<0)
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,Head,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = ((AtomEntry *)Yap_ExpandPreAllocCodeSpace(0, NULL))->StrOfAE;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = i;
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
}
|
|
|
|
|
*s = '\0';
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (IsAtomTerm(t) && AtomOfTerm(t) == AtomNil) {
|
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,t,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_atom_chars(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
|
Term NewT;
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(RepAtom(AtomOfTerm(t1))->StrOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToListOfAtoms(RepAtom(AtomOfTerm(t1))->StrOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
|
|
|
|
/* ARG1 unbound */
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE; /* alloc temp space on trail */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
register Term t = Deref(ARG2);
|
|
|
|
|
register char *s = String;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (t == TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(t1, MkAtomTerm(Yap_LookupAtom(""))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if (!IsPairTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register Int i;
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = ((AtomEntry *)Yap_ExpandPreAllocCodeSpace(0,NULL))->StrOfAE;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = i;
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* ISO Prolog Mode */
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register char *is;
|
|
|
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsAtomTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
is = RepAtom(AtomOfTerm(Head))->StrOfAE;
|
|
|
|
|
if (is[1] != '\0') {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = ((AtomEntry *)Yap_ExpandPreAllocCodeSpace(0,NULL))->StrOfAE;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = is[0];
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*s++ = '\0';
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkAtomTerm(Yap_LookupAtom(String))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-17 22:07:41 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_atom_concat(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
char *cptr = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE, *cpt0;
|
2001-04-17 22:07:41 +01:00
|
|
|
|
char *top = (char *)AuxSp;
|
|
|
|
|
char *atom_str;
|
|
|
|
|
UInt sz;
|
|
|
|
|
|
|
|
|
|
restart:
|
|
|
|
|
cpt0 = cptr;
|
|
|
|
|
/* we need to have a list */
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
|
if (IsVarTerm(thead)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(thead)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
atom_str = RepAtom(AtomOfTerm(thead))->StrOfAE;
|
|
|
|
|
/* check for overflows */
|
|
|
|
|
sz = strlen(atom_str);
|
|
|
|
|
if (cptr+sz >= top-1024) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
2004-01-23 02:23:51 +00:00
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2004-11-19 22:08:43 +00:00
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
goto restart;
|
|
|
|
|
}
|
|
|
|
|
memcpy((void *)cptr, (void *)atom_str, sz);
|
|
|
|
|
cptr += sz;
|
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (t1 == TermNil) {
|
|
|
|
|
Term tout;
|
|
|
|
|
cptr[0] = '\0';
|
2002-11-18 18:18:05 +00:00
|
|
|
|
tout = MkAtomTerm(Yap_LookupAtom(cpt0));
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
return(Yap_unify(ARG2, tout));
|
2001-04-17 22:07:41 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-16 15:12:53 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_atomic_concat(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
char *cptr = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE, *cpt0;
|
|
|
|
|
char *top = (char *)AuxSp;
|
|
|
|
|
char *atom_str;
|
|
|
|
|
UInt sz;
|
|
|
|
|
|
|
|
|
|
restart:
|
|
|
|
|
cpt0 = cptr;
|
|
|
|
|
/* we need to have a list */
|
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
|
if (IsVarTerm(thead)) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomicTerm(thead)) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
2004-06-29 20:04:46 +01:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC, ARG1, "atom_concat/2");
|
2004-06-16 15:12:53 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (IsAtomTerm(thead)) {
|
|
|
|
|
atom_str = RepAtom(AtomOfTerm(thead))->StrOfAE;
|
|
|
|
|
/* check for overflows */
|
|
|
|
|
sz = strlen(atom_str);
|
|
|
|
|
if (cptr+sz >= top-1024) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2004-11-19 22:08:43 +00:00
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
2004-06-16 15:12:53 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
|
goto restart;
|
|
|
|
|
}
|
|
|
|
|
memcpy((void *)cptr, (void *)atom_str, sz);
|
|
|
|
|
cptr += sz;
|
|
|
|
|
} else if (IsIntegerTerm(thead)) {
|
|
|
|
|
#if HAVE_SNPRINTF
|
|
|
|
|
snprintf(cptr, (top-cptr)-1024,"%ld", (long int)IntegerOfTerm(thead));
|
|
|
|
|
#else
|
2004-07-23 22:08:45 +01:00
|
|
|
|
sprintf(cptr,"%ld", (long int)IntegerOfTerm(thead));
|
2004-06-29 20:04:46 +01:00
|
|
|
|
#endif
|
|
|
|
|
while (*cptr && cptr < top-1024) cptr++;
|
|
|
|
|
} else if (IsFloatTerm(thead)) {
|
|
|
|
|
#if HAVE_SNPRINTF
|
|
|
|
|
snprintf(cptr,(top-cptr)-1024,"%g", FloatOfTerm(thead));
|
|
|
|
|
#else
|
|
|
|
|
sprintf(cptr,"%g", FloatOfTerm(thead));
|
|
|
|
|
#endif
|
|
|
|
|
while (*cptr && cptr < top-1024) cptr++;
|
|
|
|
|
#if USE_GMP
|
|
|
|
|
} else if (IsBigIntTerm(thead)) {
|
|
|
|
|
MP_INT *n = Yap_BigIntOfTerm(thead);
|
|
|
|
|
int sz;
|
|
|
|
|
|
|
|
|
|
if ((sz = mpz_sizeinbase (n, 10)) > (top-cptr)-1024) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2004-11-19 22:08:43 +00:00
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
2004-06-29 20:04:46 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
goto restart;
|
2004-06-16 15:12:53 +01:00
|
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
|
mpz_get_str(cptr, 10, n);
|
|
|
|
|
while (*cptr) cptr++;
|
|
|
|
|
#endif
|
2004-06-16 15:12:53 +01:00
|
|
|
|
}
|
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (t1 == TermNil) {
|
|
|
|
|
Term tout;
|
|
|
|
|
cptr[0] = '\0';
|
|
|
|
|
tout = MkAtomTerm(Yap_LookupAtom(cpt0));
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
return(Yap_unify(ARG2, tout));
|
|
|
|
|
}
|
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG1, "atom_concat/2");
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_atom_codes(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
|
Term NewT;
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(RepAtom(AtomOfTerm(t1))->StrOfAE);
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
|
|
|
|
/* ARG1 unbound */
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
register Term t = Deref(ARG2);
|
|
|
|
|
register char *s = String;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (t == TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(t1, MkAtomTerm(Yap_LookupAtom(""))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if (!IsPairTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register Int i;
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = ((AtomEntry *)Yap_ExpandPreAllocCodeSpace(0,NULL))->StrOfAE;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = i;
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*s++ = '\0';
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkAtomTerm(Yap_LookupAtom(String))));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_atom_length(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
Term t2 = Deref(ARG2);
|
|
|
|
|
Int len;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsVarTerm(t2)) {
|
|
|
|
|
if (!IsIntTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if ((len = IntOfTerm(t2)) < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
return((Int)strlen(RepAtom(AtomOfTerm(t1))->StrOfAE) == len);
|
|
|
|
|
} else {
|
|
|
|
|
Term tj = MkIntTerm(strlen(RepAtom(AtomOfTerm(t1))->StrOfAE));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify_constant(t2,tj));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* split an atom into two sub-atoms */
|
|
|
|
|
static Int
|
|
|
|
|
p_atom_split(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
Term t2 = Deref(ARG2);
|
|
|
|
|
Int len;
|
|
|
|
|
char *s, *s1;
|
|
|
|
|
int i;
|
|
|
|
|
Term to1, to2;
|
|
|
|
|
|
|
|
|
|
s1 = (char *)H;
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (IsVarTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if ((len = IntOfTerm(t2)) < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
s = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
|
|
|
|
if (len > (Int)strlen(s)) return(FALSE);
|
|
|
|
|
for (i = 0; i< len; i++) {
|
|
|
|
|
if (s1 > (char *)LCL0-1024)
|
2004-11-19 22:08:43 +00:00
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR,t1,"$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
s1[i] = s[i];
|
|
|
|
|
}
|
|
|
|
|
s1[len] = '\0';
|
2002-11-18 18:18:05 +00:00
|
|
|
|
to1 = MkAtomTerm(Yap_LookupAtom(s1));
|
|
|
|
|
to2 = MkAtomTerm(Yap_LookupAtom(s+len));
|
|
|
|
|
return(Yap_unify_constant(ARG3,to1) && Yap_unify_constant(ARG4,to2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-08 06:00:36 +01:00
|
|
|
|
static Term
|
|
|
|
|
gen_syntax_error(char *s)
|
|
|
|
|
{
|
|
|
|
|
Term ts[6], ti[2];
|
|
|
|
|
ti[0] = ARG1;
|
|
|
|
|
ti[1] = ARG2;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(s),2),2,ti);
|
2002-10-08 06:00:36 +01:00
|
|
|
|
ts[1] = ts[4] = ts[5] = MkIntTerm(0);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
ts[2] = MkAtomTerm(Yap_LookupAtom("number syntax"));
|
2002-10-08 06:00:36 +01:00
|
|
|
|
ts[3] = TermNil;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("syntax_error"),6),6,ts));
|
2002-10-08 06:00:36 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_number_chars(void)
|
|
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term NewT;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
register char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsNonVarTerm(t1)) {
|
|
|
|
|
Term NewT;
|
|
|
|
|
if (!IsNumTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (IsIntTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%ld", IntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#else
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%d", IntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToListOfAtoms(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToListOfAtoms(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%ld", LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#else
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%d", LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToListOfAtoms(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsBigIntTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
mpz_get_str(String, 10, Yap_BigIntOfTerm(t1));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToListOfAtoms(String);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-10-08 06:00:36 +01:00
|
|
|
|
if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
s = String;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register Int i;
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = Yap_ExpandPreAllocCodeSpace(0,NULL);
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = i;
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* ISO code */
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register char *is;
|
|
|
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsAtomTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
is = RepAtom(AtomOfTerm(Head))->StrOfAE;
|
|
|
|
|
if (is[1] != '\0') {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = Yap_ExpandPreAllocCodeSpace(0,NULL);
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = is[0];
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*s++ = '\0';
|
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_chars"), "while scanning %s", String);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_number_atom(void)
|
|
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term NewT;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
register char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
|
s = String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsNonVarTerm(t1)) {
|
|
|
|
|
if (IsIntTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term NewT;
|
|
|
|
|
#if SHORT_INTS
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%ld", IntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#else
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%d", IntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
|
Term NewT;
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
|
|
|
|
Term NewT;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%ld", LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#else
|
2001-11-19 23:19:23 +00:00
|
|
|
|
sprintf(String, "%d", LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsBigIntTerm(t1)) {
|
|
|
|
|
Term NewT;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
mpz_get_str(String, 10, Yap_BigIntOfTerm(t1));
|
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_atom/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
return(FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (!IsAtomTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_atom/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
|
if ((NewT = get_num(s)) == TermNil) {
|
2003-03-20 14:21:12 +00:00
|
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_atom"), "while scanning %s", s);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_number_codes(void)
|
|
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term NewT;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
register char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsNonVarTerm(t1)) {
|
|
|
|
|
if (IsIntTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if SHORT_INTS
|
|
|
|
|
sprintf(String, "%ld", IntOfTerm(t1));
|
|
|
|
|
#else
|
|
|
|
|
sprintf(String, "%d", IntOfTerm(t1));
|
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
|
|
|
|
#if SHORT_INTS
|
|
|
|
|
sprintf(String, "%ld", LongIntOfTerm(t1));
|
|
|
|
|
#else
|
|
|
|
|
sprintf(String, "%d", LongIntOfTerm(t1));
|
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else if (IsBigIntTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
mpz_get_str(String, 10, Yap_BigIntOfTerm(t1));
|
|
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_codes/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
return(FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "number_codes/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
|
}
|
2002-10-08 06:00:36 +01:00
|
|
|
|
if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
s = String; /* alloc temp space on Trail */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
while (t != TermNil) {
|
|
|
|
|
register Term Head;
|
|
|
|
|
register Int i;
|
|
|
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
|
|
*H++ = t;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
nString = Yap_ExpandPreAllocCodeSpace(0,NULL);
|
2004-02-05 16:57:02 +00:00
|
|
|
|
t = *--H;
|
|
|
|
|
s = nString+(s-String);
|
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
*s++ = i;
|
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*s++ = '\0';
|
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_codes"), "while scanning %s", String);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_univ(void)
|
|
|
|
|
{ /* A =.. L */
|
|
|
|
|
unsigned int arity;
|
|
|
|
|
register Term tin;
|
|
|
|
|
Term twork, t2;
|
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
|
|
tin = Deref(ARG1);
|
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
|
if (IsVarTerm(tin)) {
|
|
|
|
|
/* we need to have a list */
|
|
|
|
|
Term *Ar;
|
|
|
|
|
if (IsVarTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsPairTerm(t2)) {
|
|
|
|
|
if (t2 == TermNil)
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_NON_EMPTY_LIST, t2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
twork = HeadOfTerm(t2);
|
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (IsNumTerm(twork)) {
|
|
|
|
|
Term tt = TailOfTerm(t2);
|
|
|
|
|
if (IsVarTerm(tt) || tt != MkAtomTerm(AtomNil)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
at = AtomOfTerm(twork);
|
|
|
|
|
twork = TailOfTerm(t2);
|
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else if (!IsPairTerm(twork)) {
|
|
|
|
|
if (twork != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkAtomTerm(at)));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
|
build_compound:
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* build the term directly on the heap */
|
|
|
|
|
Ar = H;
|
|
|
|
|
H++;
|
|
|
|
|
|
|
|
|
|
while (!IsVarTerm(twork) && IsPairTerm(twork)) {
|
|
|
|
|
*H++ = HeadOfTerm(twork);
|
2002-05-07 22:19:52 +01:00
|
|
|
|
if (H > ASP - 1024) {
|
|
|
|
|
/* restore space */
|
|
|
|
|
H = Ar;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (!Yap_gc(2, ENV, P)) {
|
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
2002-10-10 06:58:49 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
|
twork = TailOfTerm(Deref(ARG2));
|
|
|
|
|
goto build_compound;
|
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
twork = TailOfTerm(twork);
|
|
|
|
|
}
|
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (twork != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (FALSE);
|
|
|
|
|
}
|
|
|
|
|
#ifdef SFUNC
|
|
|
|
|
DOES_NOT_WORK();
|
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
|
SFEntry *pe = (SFEntry *) Yap_GetAProp(at, SFProperty);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (pe)
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = MkSFTerm(Yap_MkFunctor(at, SFArity),
|
2001-04-09 20:54:03 +01:00
|
|
|
|
arity, CellPtr(TR), pe->NilValue);
|
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = Yap_MkApplTerm(Yap_MkFunctor(at, arity),
|
2001-04-09 20:54:03 +01:00
|
|
|
|
arity, CellPtr(TR));
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
arity = H-Ar-1;
|
|
|
|
|
if (at == AtomDot && arity == 2) {
|
|
|
|
|
Ar[0] = Ar[1];
|
|
|
|
|
Ar[1] = Ar[2];
|
|
|
|
|
H --;
|
|
|
|
|
twork = AbsPair(Ar);
|
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
*Ar = (CELL)(Yap_MkFunctor(at, arity));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
twork = AbsAppl(Ar);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(ARG1, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if (IsAtomicTerm(tin)) {
|
|
|
|
|
twork = MkPairTerm(tin, MkAtomTerm(AtomNil));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(twork, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
if (IsRefTerm(tin))
|
|
|
|
|
return (FALSE);
|
|
|
|
|
if (IsApplTerm(tin)) {
|
|
|
|
|
Functor fun = FunctorOfTerm(tin);
|
|
|
|
|
arity = ArityOfFunctor(fun);
|
|
|
|
|
at = NameOfFunctor(fun);
|
|
|
|
|
#ifdef SFUNC
|
|
|
|
|
if (arity == SFArity) {
|
|
|
|
|
CELL *p = CellPtr(TR);
|
|
|
|
|
CELL *q = ArgsOfSFTerm(tin);
|
|
|
|
|
int argno = 1;
|
|
|
|
|
while (*q) {
|
|
|
|
|
while (*q > argno++)
|
|
|
|
|
*p++ = MkVarTerm();
|
|
|
|
|
++q;
|
|
|
|
|
*p++ = Deref(*q++);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
|
2002-10-29 04:19:09 +00:00
|
|
|
|
while (IsIntTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (!Yap_gc(2, ENV, P)) {
|
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
2002-10-29 04:19:09 +00:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
|
2002-10-29 04:19:09 +00:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else
|
|
|
|
|
#endif
|
2002-05-07 22:19:52 +01:00
|
|
|
|
{
|
2002-10-29 04:19:09 +00:00
|
|
|
|
while (H+arity*2 > ASP-1024) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (!Yap_gc(2, ENV, P)) {
|
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
2002-10-10 06:58:49 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
|
tin = Deref(ARG1);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = Yap_ArrayToList(RepAppl(tin) + 1, arity);
|
2002-05-07 22:19:52 +01:00
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
|
|
|
|
/* We found a list */
|
|
|
|
|
at = AtomDot;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
twork = Yap_ArrayToList(RepPair(tin), 2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
twork = MkPairTerm(MkAtomTerm(at), twork);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify(ARG2, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_abort(void)
|
|
|
|
|
{ /* abort */
|
|
|
|
|
/* make sure we won't go creeping around */
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(PURE_ABORT, TermNil, "");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_halt(void)
|
|
|
|
|
{ /* halt */
|
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
|
Int out;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"halt/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntegerTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t,"halt/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
out = IntegerOfTerm(t);
|
2004-04-27 16:14:38 +01:00
|
|
|
|
Yap_exit(out);
|
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
cont_current_atom(void)
|
|
|
|
|
{
|
|
|
|
|
Atom catom;
|
|
|
|
|
Int i = IntOfTerm(EXTRA_CBACK_ARG(1,2));
|
|
|
|
|
AtomEntry *ap; /* nasty hack for gcc on hpux */
|
|
|
|
|
|
|
|
|
|
/* protect current hash table line */
|
|
|
|
|
if (IsAtomTerm(EXTRA_CBACK_ARG(1,1)))
|
|
|
|
|
catom = AtomOfTerm(EXTRA_CBACK_ARG(1,1));
|
|
|
|
|
else
|
|
|
|
|
catom = NIL;
|
|
|
|
|
if (catom == NIL){
|
|
|
|
|
i++;
|
|
|
|
|
/* move away from current hash table line */
|
2003-10-28 01:16:03 +00:00
|
|
|
|
while (i < AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
|
catom = HashChain[i].Entry;
|
2004-02-19 19:24:46 +00:00
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (catom != NIL) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-10-28 01:16:03 +00:00
|
|
|
|
if (i == AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
cut_fail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ap = RepAtom(catom);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) {
|
2004-02-19 19:24:46 +00:00
|
|
|
|
READ_LOCK(ap->ARWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (ap->NextOfAE == NIL) {
|
2004-02-19 19:24:46 +00:00
|
|
|
|
READ_UNLOCK(ap->ARWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
i++;
|
2003-10-28 01:16:03 +00:00
|
|
|
|
while (i < AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
|
catom = HashChain[i].Entry;
|
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
|
if (catom != NIL) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-10-28 01:16:03 +00:00
|
|
|
|
if (i == AtomHashTableSize) {
|
2004-02-19 19:24:46 +00:00
|
|
|
|
cut_fail();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(catom);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(ap->NextOfAE);
|
|
|
|
|
READ_UNLOCK(ap->ARWLock);
|
|
|
|
|
}
|
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(i);
|
2004-02-19 19:24:46 +00:00
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
2004-02-19 19:24:46 +00:00
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
init_current_atom(void)
|
|
|
|
|
{ /* current_atom(?Atom) */
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
|
if (IsAtomTerm(t1))
|
|
|
|
|
cut_succeed();
|
|
|
|
|
else
|
|
|
|
|
cut_fail();
|
|
|
|
|
}
|
|
|
|
|
READ_LOCK(HashChain[0].AERWLock);
|
|
|
|
|
if (HashChain[0].Entry != NIL) {
|
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(HashChain[0].Entry);
|
|
|
|
|
} else {
|
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkIntTerm(0);
|
|
|
|
|
}
|
|
|
|
|
READ_UNLOCK(HashChain[0].AERWLock);
|
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(0);
|
|
|
|
|
return (cont_current_atom());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
2001-10-03 14:39:16 +01:00
|
|
|
|
cont_current_predicate(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
2001-11-15 00:01:43 +00:00
|
|
|
|
PredEntry *pp = (PredEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(3,1));
|
2001-10-03 14:39:16 +01:00
|
|
|
|
UInt Arity;
|
2003-10-28 01:16:03 +00:00
|
|
|
|
Term name;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
2002-08-14 17:00:54 +01:00
|
|
|
|
while (pp != NULL) {
|
|
|
|
|
if (pp->PredFlags & HiddenPredFlag)
|
|
|
|
|
pp = pp->NextPredOfModule;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-10-03 14:39:16 +01:00
|
|
|
|
if (pp == NULL)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
cut_fail();
|
2001-11-15 00:01:43 +00:00
|
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL)MkIntegerTerm((Int)(pp->NextPredOfModule));
|
2002-09-17 17:37:48 +01:00
|
|
|
|
if (pp->FunctorOfPred == FunctorModule)
|
|
|
|
|
return(FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
|
if (pp->ModuleOfPred != IDB_MODULE) {
|
2003-10-28 01:16:03 +00:00
|
|
|
|
Arity = pp->ArityOfPE;
|
|
|
|
|
if (Arity)
|
|
|
|
|
name = MkAtomTerm(NameOfFunctor(pp->FunctorOfPred));
|
|
|
|
|
else
|
|
|
|
|
name = MkAtomTerm((Atom)pp->FunctorOfPred);
|
|
|
|
|
} else {
|
|
|
|
|
if (pp->PredFlags & NumberDBPredFlag) {
|
|
|
|
|
name = MkIntegerTerm(pp->src.IndxId);
|
|
|
|
|
Arity = 0;
|
|
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
|
|
|
|
name = MkAtomTerm((Atom)pp->FunctorOfPred);
|
|
|
|
|
Arity = 0;
|
|
|
|
|
} else {
|
|
|
|
|
Functor f = pp->FunctorOfPred;
|
|
|
|
|
name = MkAtomTerm(NameOfFunctor(f));
|
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (Yap_unify(ARG2,name) &&
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_unify(ARG3, MkIntegerTerm((Int)Arity)));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
2001-10-03 14:39:16 +01:00
|
|
|
|
init_current_predicate(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
2001-11-15 00:01:43 +00:00
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsAtomTerm(t1)) cut_fail();
|
2004-02-12 17:09:17 +00:00
|
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)Yap_ModulePred(t1));
|
2001-10-03 14:39:16 +01:00
|
|
|
|
return (cont_current_predicate());
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-02 18:33:00 +01:00
|
|
|
|
static Int
|
|
|
|
|
cont_current_predicate_for_atom(void)
|
|
|
|
|
{
|
|
|
|
|
Prop pf = (Prop)IntegerOfTerm(EXTRA_CBACK_ARG(3,1));
|
2004-02-12 12:37:12 +00:00
|
|
|
|
Term mod = Deref(ARG2);
|
2002-09-02 18:33:00 +01:00
|
|
|
|
|
|
|
|
|
while (pf != NIL) {
|
|
|
|
|
FunctorEntry *pp = RepFunctorProp(pf);
|
|
|
|
|
if (IsFunctorProperty(pp->KindOfPE)) {
|
|
|
|
|
Prop p0 = pp->PropsOfFE;
|
|
|
|
|
while (p0) {
|
|
|
|
|
PredEntry *p = RepPredProp(p0);
|
|
|
|
|
if (p->ModuleOfPred == mod ||
|
|
|
|
|
p->ModuleOfPred == 0) {
|
|
|
|
|
/* we found the predicate */
|
|
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL)MkIntegerTerm((Int)(pp->NextOfPE));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(ARG3,Yap_MkNewApplTerm(p->FunctorOfPred,p->ArityOfPE)));
|
2002-09-02 18:33:00 +01:00
|
|
|
|
}
|
|
|
|
|
p0 = p->NextOfPE;
|
|
|
|
|
}
|
|
|
|
|
} else if (pp->KindOfPE == PEProp) {
|
|
|
|
|
PredEntry *pe = RepPredProp(pf);
|
|
|
|
|
if (pe->ModuleOfPred == mod ||
|
|
|
|
|
pe->ModuleOfPred == 0) {
|
|
|
|
|
/* we found the predicate */
|
|
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL)MkIntegerTerm((Int)(pp->NextOfPE));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(ARG3,MkAtomTerm((Atom)(pe->FunctorOfPred))));
|
2002-09-02 18:33:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pf = pp->NextOfPE;
|
|
|
|
|
}
|
|
|
|
|
cut_fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
init_current_predicate_for_atom(void)
|
|
|
|
|
{
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsAtomTerm(t1)) cut_fail();
|
|
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)RepAtom(AtomOfTerm(t1))->PropsOfAE);
|
|
|
|
|
return (cont_current_predicate_for_atom());
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
static OpEntry *
|
|
|
|
|
NextOp(OpEntry *pp)
|
|
|
|
|
{
|
|
|
|
|
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty)
|
|
|
|
|
pp = RepOpProp(pp->NextOfPE);
|
|
|
|
|
return (pp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
cont_current_op(void)
|
|
|
|
|
{
|
|
|
|
|
int prio;
|
|
|
|
|
Atom a = AtomOfTerm(EXTRA_CBACK_ARG(3,1));
|
|
|
|
|
Int i = IntOfTerm(EXTRA_CBACK_ARG(3,2));
|
|
|
|
|
Int fix = IntOfTerm(EXTRA_CBACK_ARG(3,3));
|
|
|
|
|
Term TType;
|
|
|
|
|
OpEntry *pp = NIL;
|
|
|
|
|
/* fix hp gcc bug */
|
|
|
|
|
AtomEntry *at = RepAtom(a);
|
|
|
|
|
|
|
|
|
|
if (fix > 3) {
|
|
|
|
|
a = AtomOfTerm(Deref(ARG3));
|
|
|
|
|
READ_LOCK(RepAtom(a)->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
if (EndOfPAEntr(pp = NextOp(RepOpProp(RepAtom(a)->PropsOfAE)))) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_UNLOCK(RepAtom(a)->ARWLock);
|
|
|
|
|
cut_fail();
|
|
|
|
|
}
|
|
|
|
|
READ_LOCK(pp->OpRWLock);
|
|
|
|
|
READ_UNLOCK(RepAtom(a)->ARWLock);
|
|
|
|
|
if (fix == 4 && pp->Prefix == 0)
|
|
|
|
|
fix = 5;
|
|
|
|
|
if (fix == 5 && pp->Posfix == 0)
|
|
|
|
|
fix = 6;
|
|
|
|
|
if (fix == 6 && pp->Infix == 0)
|
|
|
|
|
cut_fail();
|
2002-11-18 18:18:05 +00:00
|
|
|
|
TType = MkAtomTerm(Yap_GetOp(pp, &prio, (int) (fix - 4)));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
fix++;
|
|
|
|
|
if (fix == 5 && pp->Posfix == 0)
|
|
|
|
|
fix = 6;
|
|
|
|
|
if (fix == 6 && pp->Infix == 0)
|
|
|
|
|
fix = 7;
|
|
|
|
|
READ_UNLOCK(pp->OpRWLock);
|
|
|
|
|
EXTRA_CBACK_ARG(3,3) = (CELL) MkIntTerm(fix);
|
|
|
|
|
if (fix < 7)
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkIntTerm(prio))
|
|
|
|
|
&& Yap_unify_constant(ARG2, TType));
|
|
|
|
|
if (Yap_unify_constant(ARG1, MkIntTerm(prio)) && Yap_unify_constant(ARG2, TType))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
cut_succeed();
|
|
|
|
|
else
|
|
|
|
|
cut_fail();
|
|
|
|
|
}
|
|
|
|
|
if (fix == 3) {
|
|
|
|
|
do {
|
|
|
|
|
if ((a = at->NextOfAE) == NIL) {
|
|
|
|
|
i++;
|
2004-04-16 22:01:45 +01:00
|
|
|
|
while (i < AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
|
a = HashChain[i].Entry;
|
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
|
if (a != NIL) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-10-28 01:16:03 +00:00
|
|
|
|
if (i == AtomHashTableSize)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
cut_fail();
|
|
|
|
|
EXTRA_CBACK_ARG(3,2) = (CELL) MkIntTerm(i);
|
|
|
|
|
}
|
|
|
|
|
at = RepAtom(a);
|
|
|
|
|
READ_LOCK(at->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
pp = NextOp(RepOpProp(at->PropsOfAE));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
READ_UNLOCK(at->ARWLock);
|
|
|
|
|
} while (EndOfPAEntr(pp));
|
|
|
|
|
fix = 0;
|
|
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a);
|
|
|
|
|
} else {
|
2001-10-30 16:42:05 +00:00
|
|
|
|
pp = NextOp(RepOpProp(at->PropsOfAE));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
READ_LOCK(pp->OpRWLock);
|
|
|
|
|
if (fix == 0 && pp->Prefix == 0)
|
|
|
|
|
fix = 1;
|
|
|
|
|
if (fix == 1 && pp->Posfix == 0)
|
|
|
|
|
fix = 2;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
TType = MkAtomTerm(Yap_GetOp(pp, &prio, (int) fix));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
fix++;
|
|
|
|
|
if (fix == 1 && pp->Posfix == 0)
|
|
|
|
|
fix = 2;
|
|
|
|
|
if (fix == 2 && pp->Infix == 0)
|
|
|
|
|
fix = 3;
|
|
|
|
|
READ_UNLOCK(pp->OpRWLock);
|
|
|
|
|
EXTRA_CBACK_ARG(3,3) = (CELL) MkIntTerm(fix);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return (Yap_unify_constant(ARG1, MkIntTerm(prio)) &&
|
|
|
|
|
Yap_unify_constant(ARG2, TType) &&
|
|
|
|
|
Yap_unify_constant(ARG3, MkAtomTerm(a)));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
init_current_op(void)
|
|
|
|
|
{ /* current_op(-Precedence,-Type,-Atom) */
|
|
|
|
|
Int i = 0;
|
|
|
|
|
Atom a;
|
|
|
|
|
Term tprio = Deref(ARG1);
|
|
|
|
|
Term topsec = Deref(ARG2);
|
|
|
|
|
Term top = Deref(ARG3);
|
|
|
|
|
|
|
|
|
|
if (!IsVarTerm(tprio)) {
|
|
|
|
|
Int prio;
|
|
|
|
|
if (!IsIntTerm(tprio)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_PRIORITY,tprio,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
prio = IntOfTerm(tprio);
|
|
|
|
|
if (prio < 1 || prio > 1200) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_PRIORITY,tprio,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!IsVarTerm(topsec)) {
|
|
|
|
|
char *opsec;
|
|
|
|
|
if (!IsAtomTerm(topsec)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,topsec,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
opsec = RepAtom(AtomOfTerm(topsec))->StrOfAE;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (!Yap_IsOpType(opsec)) {
|
|
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,topsec,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!IsVarTerm(top)) {
|
|
|
|
|
if (!IsAtomTerm(top)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,top,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (TRUE) {
|
|
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
|
a = HashChain[i].Entry;
|
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
|
if (a != NIL) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a);
|
|
|
|
|
EXTRA_CBACK_ARG(3,2) = (CELL) MkIntTerm(i);
|
|
|
|
|
if (IsVarTerm(top))
|
|
|
|
|
EXTRA_CBACK_ARG(3,3) = (CELL) MkIntTerm(3);
|
|
|
|
|
else if (IsAtomTerm(top))
|
|
|
|
|
EXTRA_CBACK_ARG(3,3) = (CELL) MkIntTerm(4);
|
|
|
|
|
else
|
|
|
|
|
cut_fail();
|
|
|
|
|
return (cont_current_op());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
static Int
|
|
|
|
|
p_debug()
|
|
|
|
|
{ /* $debug(+Flag) */
|
|
|
|
|
int i = IntOfTerm(Deref(ARG1));
|
|
|
|
|
|
|
|
|
|
if (i >= 'a' && i <= 'z')
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Option[i - 96] = !Yap_Option[i - 96];
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_flags(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
|
{ /* $flags(+Functor,+Mod,?OldFlags,?NewFlags) */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
PredEntry *pe;
|
|
|
|
|
Int newFl;
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
|
Term mod = Deref(ARG2);
|
2001-11-15 00:01:43 +00:00
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
|
return (FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
if (IsAtomTerm(t1)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
|
pe = RepPredProp(PredPropByAtom(AtomOfTerm(t1), mod));
|
2001-10-30 16:42:05 +00:00
|
|
|
|
} else if (IsApplTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2001-11-15 00:01:43 +00:00
|
|
|
|
pe = RepPredProp(PredPropByFunc(funt, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else
|
|
|
|
|
return (FALSE);
|
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
|
return (FALSE);
|
2004-02-11 13:33:19 +00:00
|
|
|
|
READ_LOCK(pe->PRWLock);
|
2003-12-04 18:13:04 +00:00
|
|
|
|
if (!Yap_unify_constant(ARG3, MkIntegerTerm(pe->PredFlags))) {
|
2004-02-11 13:33:19 +00:00
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
|
ARG4 = Deref(ARG4);
|
|
|
|
|
if (IsVarTerm(ARG4)) {
|
2004-02-11 13:33:19 +00:00
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (TRUE);
|
2003-12-04 18:13:04 +00:00
|
|
|
|
} else if (!IsIntegerTerm(ARG4)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
union arith_ret v;
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (Yap_Eval(ARG4, &v) == long_int_e) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
newFl = v.Int;
|
|
|
|
|
} else {
|
2004-02-11 13:33:19 +00:00
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, ARG4, "flags");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
} else
|
2003-12-04 18:13:04 +00:00
|
|
|
|
newFl = IntegerOfTerm(ARG4);
|
|
|
|
|
pe->PredFlags = (CELL)newFl;
|
2004-02-11 13:33:19 +00:00
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
AlreadyHidden(char *name)
|
|
|
|
|
{
|
|
|
|
|
AtomEntry *chain;
|
|
|
|
|
|
|
|
|
|
READ_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
|
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, name) != 0)
|
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
|
return (FALSE);
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_hide(void)
|
|
|
|
|
{ /* hide(+Atom) */
|
|
|
|
|
Atom atomToInclude;
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"hide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"hide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
atomToInclude = AtomOfTerm(t1);
|
|
|
|
|
if (AlreadyHidden(RepAtom(atomToInclude)->StrOfAE)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(SYSTEM_ERROR,t1,"an atom of name %s was already hidden",
|
2001-04-09 20:54:03 +01:00
|
|
|
|
RepAtom(atomToInclude)->StrOfAE);
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_ReleaseAtom(atomToInclude);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
WRITE_LOCK(RepAtom(atomToInclude)->ARWLock);
|
|
|
|
|
RepAtom(atomToInclude)->NextOfAE = INVISIBLECHAIN.Entry;
|
|
|
|
|
WRITE_UNLOCK(RepAtom(atomToInclude)->ARWLock);
|
|
|
|
|
INVISIBLECHAIN.Entry = atomToInclude;
|
|
|
|
|
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_hidden(void)
|
|
|
|
|
{ /* '$hidden'(+F) */
|
|
|
|
|
Atom at;
|
|
|
|
|
AtomEntry *chain;
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
|
return (FALSE);
|
|
|
|
|
if (IsAtomTerm(t1))
|
|
|
|
|
at = AtomOfTerm(t1);
|
|
|
|
|
else if (IsApplTerm(t1))
|
|
|
|
|
at = NameOfFunctor(FunctorOfTerm(t1));
|
|
|
|
|
else
|
|
|
|
|
return (FALSE);
|
|
|
|
|
READ_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
|
while (!EndOfPAEntr(chain) && AbsAtom(chain) != at)
|
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
2001-10-30 22:13:18 +00:00
|
|
|
|
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
|
return (FALSE);
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_unhide(void)
|
|
|
|
|
{ /* unhide(+Atom) */
|
|
|
|
|
AtomEntry *atom, *old, *chain;
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"unhide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"unhide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
atom = RepAtom(AtomOfTerm(t1));
|
|
|
|
|
WRITE_LOCK(atom->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
if (atom->PropsOfAE != NIL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(SYSTEM_ERROR,t1,"cannot unhide an atom in use");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
|
old = NIL;
|
|
|
|
|
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, atom->StrOfAE) != 0) {
|
|
|
|
|
old = chain;
|
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
|
|
|
|
}
|
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
|
return (FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
|
atom->PropsOfAE = chain->PropsOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (old == NIL)
|
|
|
|
|
INVISIBLECHAIN.Entry = chain->NextOfAE;
|
|
|
|
|
else
|
|
|
|
|
old->NextOfAE = chain->NextOfAE;
|
|
|
|
|
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
|
WRITE_UNLOCK(atom->ARWLock);
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_show_statistics(void)
|
2002-11-11 17:38:10 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long int heap_space_taken =
|
2002-11-18 18:18:05 +00:00
|
|
|
|
(unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase));
|
2002-11-11 17:38:10 +00:00
|
|
|
|
double frag = (100.0*(heap_space_taken-HeapUsed))/heap_space_taken;
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
fprintf(Yap_stderr, "Code Space: %ld (%ld bytes needed, %ld bytes used, fragmentation %.3f%%).\n",
|
|
|
|
|
(unsigned long int)(Unsigned (H0) - Unsigned (Yap_HeapBase)),
|
|
|
|
|
(unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)),
|
2002-11-11 17:38:10 +00:00
|
|
|
|
(unsigned long int)(HeapUsed),
|
|
|
|
|
frag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
fprintf(Yap_stderr, "Stack Space: %ld (%ld for Global, %ld for local).\n",
|
2002-11-11 17:38:10 +00:00
|
|
|
|
(unsigned long int)(sizeof(CELL)*(LCL0-H0)),
|
|
|
|
|
(unsigned long int)(sizeof(CELL)*(H-H0)),
|
|
|
|
|
(unsigned long int)(sizeof(CELL)*(LCL0-ASP)));
|
2002-11-18 18:18:05 +00:00
|
|
|
|
fprintf(Yap_stderr, "Trail Space: %ld (%ld used).\n",
|
|
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(Yap_TrailTop)-Unsigned(Yap_TrailBase))),
|
|
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(TR)-Unsigned(Yap_TrailBase))));
|
|
|
|
|
fprintf(Yap_stderr, "Runtime: %lds.\n", (unsigned long int)(runtime ()));
|
|
|
|
|
fprintf(Yap_stderr, "Cputime: %lds.\n", (unsigned long int)(Yap_cputime ()));
|
|
|
|
|
fprintf(Yap_stderr, "Walltime: %lds.\n", (unsigned long int)(Yap_walltime ()));
|
2002-11-11 17:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_statistics_heap_max(void)
|
|
|
|
|
{
|
|
|
|
|
Term tmax = MkIntegerTerm(HeapMax);
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The results of the next routines are not to be trusted too */
|
|
|
|
|
/* much. Basically, any stack shifting will seriously confuse the */
|
|
|
|
|
/* results */
|
|
|
|
|
|
|
|
|
|
static Int TrailTide = -1, LocalTide = -1, GlobalTide = -1;
|
|
|
|
|
|
|
|
|
|
/* maximum Trail usage */
|
|
|
|
|
static Int
|
|
|
|
|
TrailMax(void)
|
|
|
|
|
{
|
|
|
|
|
Int i;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Int TrWidth = Unsigned(Yap_TrailTop) - Unsigned(Yap_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
|
|
if (TrailTide != TrWidth) {
|
|
|
|
|
pt = (CELL *)TR;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
while (pt+2 < (CELL *)Yap_TrailTop) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (pt[0] == 0 &&
|
|
|
|
|
pt[1] == 0 &&
|
|
|
|
|
pt[2] == 0)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
pt++;
|
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
|
if (pt+2 < (CELL *)Yap_TrailTop)
|
|
|
|
|
i = Unsigned(pt) - Unsigned(Yap_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
else
|
|
|
|
|
i = TrWidth;
|
|
|
|
|
} else
|
|
|
|
|
return(TrWidth);
|
|
|
|
|
if (TrailTide > i)
|
|
|
|
|
i = TrailTide;
|
|
|
|
|
else
|
|
|
|
|
TrailTide = i;
|
|
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_trail_max(void)
|
|
|
|
|
{
|
|
|
|
|
Term tmax = MkIntegerTerm(TrailMax());
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* maximum Global usage */
|
|
|
|
|
static Int
|
|
|
|
|
GlobalMax(void)
|
|
|
|
|
{
|
|
|
|
|
Int i;
|
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
|
|
if (GlobalTide != StkWidth) {
|
|
|
|
|
pt = H;
|
|
|
|
|
while (pt+2 < ASP) {
|
|
|
|
|
if (pt[0] == 0 &&
|
|
|
|
|
pt[1] == 0 &&
|
|
|
|
|
pt[2] == 0)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
pt++;
|
|
|
|
|
}
|
|
|
|
|
if (pt+2 < ASP)
|
|
|
|
|
i = Unsigned(pt) - Unsigned(H0);
|
|
|
|
|
else
|
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
|
} else
|
|
|
|
|
return(StkWidth);
|
|
|
|
|
if (GlobalTide > i)
|
|
|
|
|
i = GlobalTide;
|
|
|
|
|
else
|
|
|
|
|
GlobalTide = i;
|
|
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_global_max(void)
|
|
|
|
|
{
|
|
|
|
|
Term tmax = MkIntegerTerm(GlobalMax());
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
LocalMax(void)
|
|
|
|
|
{
|
|
|
|
|
Int i;
|
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
|
|
if (LocalTide != StkWidth) {
|
|
|
|
|
pt = LCL0;
|
|
|
|
|
while (pt-3 > H) {
|
|
|
|
|
if (pt[-1] == 0 &&
|
|
|
|
|
pt[-2] == 0 &&
|
|
|
|
|
pt[-3] == 0)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
--pt;
|
|
|
|
|
}
|
|
|
|
|
if (pt-3 > H)
|
|
|
|
|
i = Unsigned(LCL0) - Unsigned(pt);
|
|
|
|
|
else
|
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
|
} else
|
|
|
|
|
return(StkWidth);
|
|
|
|
|
if (LocalTide > i)
|
|
|
|
|
i = LocalTide;
|
|
|
|
|
else
|
|
|
|
|
LocalTide = i;
|
|
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_local_max(void)
|
|
|
|
|
{
|
|
|
|
|
Term tmax = MkIntegerTerm(LocalMax());
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_heap_info(void)
|
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Term tmax = MkIntegerTerm(Unsigned(H0) - Unsigned(Yap_HeapBase));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
Term tusage = MkIntegerTerm(HeapUsed);
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_stacks_info(void)
|
|
|
|
|
{
|
|
|
|
|
Term tmax = MkIntegerTerm(Unsigned(LCL0) - Unsigned(H0));
|
|
|
|
|
Term tgusage = MkIntegerTerm(Unsigned(H) - Unsigned(H0));
|
|
|
|
|
Term tlusage = MkIntegerTerm(Unsigned(LCL0) - Unsigned(ASP));
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tgusage,ARG2) && Yap_unify(tlusage,ARG3));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_statistics_trail_info(void)
|
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Term tmax = MkIntegerTerm(Unsigned(Yap_TrailTop) - Unsigned(Yap_TrailBase));
|
|
|
|
|
Term tusage = MkIntegerTerm(Unsigned(TR) - Unsigned(Yap_TrailBase));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Term
|
|
|
|
|
mk_argc_list(void)
|
|
|
|
|
{
|
|
|
|
|
int i =0;
|
|
|
|
|
Term t = TermNil;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
while (i < Yap_argc) {
|
|
|
|
|
char *arg = Yap_argv[i];
|
2001-05-28 20:54:53 +01:00
|
|
|
|
/* check for -L -- */
|
|
|
|
|
if (arg[0] == '-' && arg[1] == 'L') {
|
|
|
|
|
arg += 2;
|
|
|
|
|
while (*arg != '\0' && (*arg == ' ' || *arg == '\t'))
|
|
|
|
|
arg++;
|
|
|
|
|
if (*arg == '-' && arg[1] == '-' && arg[2] == '\0') {
|
|
|
|
|
/* we found the separator */
|
|
|
|
|
int j;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
for (j = Yap_argc-1; j > i+1; --j) {
|
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(Yap_argv[j])),t);
|
2001-05-28 20:54:53 +01:00
|
|
|
|
}
|
|
|
|
|
return(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0') {
|
|
|
|
|
/* we found the separator */
|
|
|
|
|
int j;
|
2002-11-18 18:18:05 +00:00
|
|
|
|
for (j = Yap_argc-1; j > i; --j) {
|
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(Yap_argv[j])),t);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
return(t);
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_argv(void)
|
|
|
|
|
{
|
|
|
|
|
Term t = mk_argc_list();
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(t, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_access_yap_flags(void)
|
|
|
|
|
{
|
|
|
|
|
Term tflag = Deref(ARG1);
|
|
|
|
|
Int flag;
|
|
|
|
|
Term tout;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, tflag, "access_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "access_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
flag = IntOfTerm(tflag);
|
|
|
|
|
if (flag < 0 || flag > NUMBER_OF_YAP_FLAGS) {
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
tout = MkIntegerTerm(yap_flags[flag]);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(ARG2, tout));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_has_yap_or(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef YAPOR
|
|
|
|
|
return(TRUE);
|
|
|
|
|
#else
|
|
|
|
|
return(FALSE);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-22 18:53:36 +01:00
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
static Int
|
|
|
|
|
p_set_yap_flags(void)
|
|
|
|
|
{
|
|
|
|
|
Term tflag = Deref(ARG1);
|
|
|
|
|
Term tvalue = Deref(ARG2);
|
|
|
|
|
Int flag, value;
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, tflag, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
flag = IntOfTerm(tflag);
|
|
|
|
|
if (IsVarTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, tvalue, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (!IsIntTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tvalue, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
value = IntOfTerm(tvalue);
|
|
|
|
|
/* checking should have been performed */
|
|
|
|
|
switch(flag) {
|
|
|
|
|
case CHAR_CONVERSION_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[CHAR_CONVERSION_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case YAP_DOUBLE_QUOTES_FLAG:
|
|
|
|
|
if (value < 0 || value > 2)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case YAP_TO_CHARS_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[YAP_TO_CHARS_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case LANGUAGE_MODE_FLAG:
|
|
|
|
|
if (value < 0 || value > 2)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
if (value == 1) {
|
2004-12-02 06:06:47 +00:00
|
|
|
|
Yap_heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(Yap_MkFunctor(AtomMetaCall,4),0));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
} else {
|
2004-12-02 06:06:47 +00:00
|
|
|
|
Yap_heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(Yap_MkFunctor(AtomMetaCall,4),0));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
yap_flags[LANGUAGE_MODE_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case STRICT_ISO_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[STRICT_ISO_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case SPY_CREEP_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[SPY_CREEP_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case SOURCE_MODE_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[SOURCE_MODE_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case CHARACTER_ESCAPE_FLAG:
|
2001-04-17 22:07:41 +01:00
|
|
|
|
if (value != ISO_CHARACTER_ESCAPES
|
|
|
|
|
&& value != CPROLOG_CHARACTER_ESCAPES
|
|
|
|
|
&& value != SICSTUS_CHARACTER_ESCAPES)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[CHARACTER_ESCAPE_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case WRITE_QUOTED_STRING_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = value;
|
|
|
|
|
break;
|
|
|
|
|
case ALLOW_ASSERTING_STATIC_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = value;
|
|
|
|
|
break;
|
2002-12-10 14:36:22 +00:00
|
|
|
|
case STACK_DUMP_ON_ERROR_FLAG:
|
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[STACK_DUMP_ON_ERROR_FLAG] = value;
|
|
|
|
|
break;
|
2003-06-06 12:54:02 +01:00
|
|
|
|
case INDEXING_MODE_FLAG:
|
|
|
|
|
if (value < INDEX_MODE_OFF || value > INDEX_MODE_MAX)
|
|
|
|
|
return(FALSE);
|
|
|
|
|
yap_flags[INDEXING_MODE_FLAG] = value;
|
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
default:
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-01 17:27:42 +00:00
|
|
|
|
static Int
|
|
|
|
|
p_lock_system(void)
|
|
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
|
LOCK(BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_unlock_system(void)
|
|
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
|
UNLOCK(BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-08 04:45:04 +00:00
|
|
|
|
static Int
|
|
|
|
|
p_enterundefp(void)
|
|
|
|
|
{
|
|
|
|
|
if (DoingUndefp) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
DoingUndefp = TRUE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_exitundefp(void)
|
|
|
|
|
{
|
|
|
|
|
if (DoingUndefp) {
|
|
|
|
|
DoingUndefp = FALSE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-28 20:54:53 +01:00
|
|
|
|
#ifndef YAPOR
|
|
|
|
|
static Int
|
|
|
|
|
p_default_sequential(void) {
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
extern void DumpActiveGoals(void);
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_dump_active_goals(void) {
|
|
|
|
|
DumpActiveGoals();
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-03-04 03:25:41 +00:00
|
|
|
|
#ifdef INES
|
|
|
|
|
static Int
|
|
|
|
|
p_euc_dist(void) {
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
Term t2 = Deref(ARG2);
|
|
|
|
|
double d1 = (double)(IntegerOfTerm(ArgOfTerm(1,t1))-IntegerOfTerm(ArgOfTerm(1,t2)));
|
|
|
|
|
double d2 = (double)(IntegerOfTerm(ArgOfTerm(2,t1))-IntegerOfTerm(ArgOfTerm(2,t2)));
|
|
|
|
|
double d3 = (double)(IntegerOfTerm(ArgOfTerm(3,t1))-IntegerOfTerm(ArgOfTerm(3,t2)));
|
|
|
|
|
Int result = (Int)sqrt(d1*d1+d2*d2+d3*d3);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
return(Yap_unify(ARG3,MkIntegerTerm(result)));
|
2002-03-04 03:25:41 +00:00
|
|
|
|
}
|
2002-03-08 06:32:11 +00:00
|
|
|
|
|
|
|
|
|
volatile int loop_counter = 0;
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
|
p_loop(void) {
|
|
|
|
|
while (loop_counter == 0);
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
2002-03-04 03:25:41 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitBackCPreds(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPredBack("$current_atom", 1, 2, init_current_atom, cont_current_atom,
|
2004-11-18 22:32:40 +00:00
|
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPredBack("$current_predicate", 3, 1, init_current_predicate, cont_current_predicate,
|
2004-11-18 22:32:40 +00:00
|
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPredBack("$current_predicate_for_atom", 3, 1, init_current_predicate_for_atom, cont_current_predicate_for_atom,
|
2004-11-18 22:32:40 +00:00
|
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPredBack("current_op", 3, 3, init_current_op, cont_current_op,
|
2001-04-09 20:54:03 +01:00
|
|
|
|
SafePredFlag|SyncPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitBackIO();
|
|
|
|
|
Yap_InitBackDB();
|
|
|
|
|
Yap_InitUserBacks();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef void (*Proc)(void);
|
|
|
|
|
|
|
|
|
|
Proc E_Modules[]= {/* init_fc,*/ (Proc) 0 };
|
|
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPreds(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
|
|
|
|
/* numerical comparison */
|
2003-08-27 14:37:10 +01:00
|
|
|
|
Yap_InitCPred("set_value", 2, p_setval, SafePredFlag|SyncPredFlag);
|
|
|
|
|
Yap_InitCPred("get_value", 2, p_value, TestPredFlag|SafePredFlag|SyncPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$values", 3, p_values, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* general purpose */
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$opdec", 3, p_opdec, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("name", 2, p_name, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("char_code", 2, p_char_code, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("atom_chars", 2, p_atom_chars, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("atom_codes", 2, p_atom_codes, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("atom_length", 2, p_atom_length, SafePredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$atom_split", 4, p_atom_split, SafePredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("number_chars", 2, p_number_chars, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("number_atom", 2, p_number_atom, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("number_codes", 2, p_number_codes, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("atom_concat", 2, p_atom_concat, SafePredFlag);
|
2004-06-16 15:12:53 +01:00
|
|
|
|
Yap_InitCPred("atomic_concat", 2, p_atomic_concat, SafePredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("=..", 2, p_univ, 0);
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$statistics_trail_max", 1, p_statistics_trail_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_heap_max", 1, p_statistics_heap_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_global_max", 1, p_statistics_global_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_local_max", 1, p_statistics_local_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_heap_info", 2, p_statistics_heap_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_stacks_info", 3, p_statistics_stacks_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$statistics_trail_info", 2, p_statistics_trail_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$argv", 1, p_argv, SafePredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$runtime", 2, p_runtime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$cputime", 2, p_cputime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$walltime", 2, p_walltime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$access_yap_flags", 2, p_access_yap_flags, SafePredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$set_yap_flags", 2, p_set_yap_flags, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("abort", 0, p_abort, SyncPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$halt", 1, p_halt, SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$lock_system", 0, p_lock_system, SafePredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$unlock_system", 0, p_unlock_system, SafePredFlag|HiddenPredFlag);
|
2004-12-08 04:45:04 +00:00
|
|
|
|
Yap_InitCPred("$enter_undefp", 0, p_enterundefp, SafePredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$exit_undefp", 0, p_exitundefp, SafePredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* basic predicates for the prolog machine tracer */
|
|
|
|
|
/* they are defined in analyst.c */
|
|
|
|
|
/* Basic predicates for the debugger */
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$creep", 0, p_creep, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$stop_creep", 0, p_stop_creep, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#ifdef DEBUG
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$debug", 1, p_debug, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
|
|
|
|
/* Accessing and changing the flags for a predicate */
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$flags", 4, p_flags, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
/* hiding and unhiding some predicates */
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("hide", 1, p_hide, SafePredFlag|SyncPredFlag);
|
|
|
|
|
Yap_InitCPred("unhide", 1, p_unhide, SafePredFlag|SyncPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$hidden", 1, p_hidden, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
|
Yap_InitCPred("$has_yap_or", 0, p_has_yap_or, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2003-03-21 16:59:38 +00:00
|
|
|
|
#ifdef LOW_PROF
|
2004-06-29 20:04:46 +01:00
|
|
|
|
Yap_InitCPred("profinit",0, profinit, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profend" ,0, profend, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profon" , 0, profon0, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profon" , 1, profon, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profoff", 0, profoff, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profalt", 0, profalt, SafePredFlag);
|
2004-02-25 19:06:31 +00:00
|
|
|
|
Yap_InitCPred("profres", 1, profres, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("profres", 0, profres0, SafePredFlag);
|
2003-03-21 16:59:38 +00:00
|
|
|
|
#endif
|
2001-05-28 20:54:53 +01:00
|
|
|
|
#ifndef YAPOR
|
2004-11-18 22:32:40 +00:00
|
|
|
|
Yap_InitCPred("$default_sequential", 1, p_default_sequential, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-05-28 20:54:53 +01:00
|
|
|
|
#endif
|
2002-03-04 03:25:41 +00:00
|
|
|
|
#ifdef INES
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("euc_dist", 3, p_euc_dist, SafePredFlag);
|
|
|
|
|
Yap_InitCPred("loop", 0, p_loop, SafePredFlag);
|
2002-03-04 03:25:41 +00:00
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitCPred("dump_active_goals", 0, p_dump_active_goals, SafePredFlag|SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitUnify();
|
|
|
|
|
Yap_InitInlines();
|
|
|
|
|
Yap_InitCdMgr();
|
|
|
|
|
Yap_InitExecFs();
|
|
|
|
|
Yap_InitIOPreds();
|
|
|
|
|
Yap_InitCmpPreds();
|
|
|
|
|
Yap_InitDBPreds();
|
|
|
|
|
Yap_InitBBPreds();
|
|
|
|
|
Yap_InitBigNums();
|
|
|
|
|
Yap_InitSysPreds();
|
|
|
|
|
Yap_InitSavePreds();
|
|
|
|
|
Yap_InitCoroutPreds();
|
|
|
|
|
Yap_InitArrayPreds();
|
|
|
|
|
Yap_InitLoadForeign();
|
2004-02-06 02:26:23 +00:00
|
|
|
|
Yap_InitModulesC();
|
2002-11-18 18:18:05 +00:00
|
|
|
|
|
|
|
|
|
Yap_InitUserCPreds();
|
|
|
|
|
Yap_InitUtilCPreds();
|
|
|
|
|
Yap_InitSortPreds();
|
|
|
|
|
Yap_InitMaVarCPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#ifdef DEPTH_LIMIT
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitItDeepenPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef ANALYST
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitAnalystPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitLowLevelTrace();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitEval();
|
|
|
|
|
Yap_InitGrowPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_init_optyap_preds();
|
2003-11-07 16:31:08 +00:00
|
|
|
|
#endif /* YAPOR || TABLING */
|
2004-01-23 02:23:51 +00:00
|
|
|
|
Yap_InitThreadPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
{
|
|
|
|
|
void (*(*(p))) (void) = E_Modules;
|
|
|
|
|
while (*p)
|
|
|
|
|
(*(*p++)) ();
|
|
|
|
|
}
|
|
|
|
|
#if CAMACHO
|
|
|
|
|
{
|
|
|
|
|
extern void InitForeignPreds(void);
|
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
|
Yap_InitForeignPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2002-09-25 05:29:01 +01:00
|
|
|
|
#if APRIL
|
2002-09-24 20:01:29 +01:00
|
|
|
|
{
|
|
|
|
|
extern void init_ol(void), init_time(void);
|
|
|
|
|
|
|
|
|
|
init_ol();
|
|
|
|
|
init_time();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|