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 *
|
|
|
|
* *
|
2014-11-25 12:03:48 +00:00
|
|
|
* Last rev: $Date: 2008-07-24 16:02:00 $,$Author: vsc $
|
|
|
|
**
|
2004-05-13 21:54:58 +01:00
|
|
|
* $Log: not supported by cvs2svn $
|
2008-07-24 17:02:04 +01:00
|
|
|
* Revision 1.131 2008/06/12 10:55:52 vsc
|
|
|
|
* fix syntax error messages
|
|
|
|
*
|
2008-06-12 11:55:52 +01:00
|
|
|
* Revision 1.130 2008/04/06 11:53:02 vsc
|
|
|
|
* fix some restore bugs
|
|
|
|
*
|
2008-04-06 12:53:02 +01:00
|
|
|
* Revision 1.129 2008/03/15 12:19:33 vsc
|
|
|
|
* fix flags
|
|
|
|
*
|
2008-03-15 12:19:33 +00:00
|
|
|
* Revision 1.128 2008/02/15 12:41:33 vsc
|
|
|
|
* more fixes to modules
|
|
|
|
*
|
2008-02-15 12:41:33 +00:00
|
|
|
* Revision 1.127 2008/02/13 10:15:35 vsc
|
|
|
|
* fix some bugs from yesterday plus improve support for modules in
|
|
|
|
* operators.
|
|
|
|
*
|
2008-02-13 10:15:36 +00:00
|
|
|
* Revision 1.126 2008/02/07 23:09:13 vsc
|
|
|
|
* don't break ISO standard in current_predicate/1.
|
|
|
|
* Include Nicos flag.
|
|
|
|
*
|
2008-02-07 23:09:13 +00:00
|
|
|
* Revision 1.125 2008/01/23 17:57:53 vsc
|
|
|
|
* valgrind it!
|
|
|
|
* enable atom garbage collection.
|
|
|
|
*
|
2008-01-23 17:57:56 +00:00
|
|
|
* Revision 1.124 2007/11/26 23:43:08 vsc
|
|
|
|
* fixes to support threads and assert correctly, even if inefficiently.
|
|
|
|
*
|
2007-11-26 23:43:10 +00:00
|
|
|
* Revision 1.123 2007/11/06 17:02:12 vsc
|
|
|
|
* compile ground terms away.
|
|
|
|
*
|
2007-11-06 17:02:13 +00:00
|
|
|
* Revision 1.122 2007/10/18 08:24:16 vsc
|
|
|
|
* fix global variables
|
|
|
|
*
|
2007-10-18 09:24:16 +01:00
|
|
|
* Revision 1.121 2007/10/10 09:44:24 vsc
|
|
|
|
* some more fixes to make YAP swi compatible
|
|
|
|
* fix absolute_file_name (again)
|
|
|
|
* fix setarg
|
|
|
|
*
|
2007-10-10 10:44:28 +01:00
|
|
|
* Revision 1.120 2007/10/08 23:02:15 vsc
|
|
|
|
* minor fixes
|
|
|
|
*
|
2007-10-09 00:02:16 +01:00
|
|
|
* Revision 1.119 2007/04/18 23:01:16 vsc
|
|
|
|
* fix deadlock when trying to create a module with the same name as a
|
|
|
|
* predicate (for now, just don't lock modules). obs Paulo Moura.
|
|
|
|
*
|
2007-04-19 00:01:16 +01:00
|
|
|
* Revision 1.118 2007/02/26 10:41:40 vsc
|
|
|
|
* fix prolog_flags for chr.
|
|
|
|
*
|
2007-02-26 10:41:40 +00:00
|
|
|
* Revision 1.117 2007/01/28 14:26:37 vsc
|
|
|
|
* WIN32 support
|
|
|
|
*
|
2007-01-28 14:26:37 +00:00
|
|
|
* Revision 1.116 2006/12/13 16:10:23 vsc
|
|
|
|
* several debugger and CLP(BN) improvements.
|
|
|
|
*
|
2006-12-13 16:10:26 +00:00
|
|
|
* Revision 1.115 2006/11/28 13:46:41 vsc
|
|
|
|
* fix wide_char support for name/2.
|
|
|
|
*
|
2006-11-28 13:46:41 +00:00
|
|
|
* Revision 1.114 2006/11/27 17:42:03 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
2006-11-27 17:42:03 +00:00
|
|
|
* Revision 1.113 2006/11/16 14:26:00 vsc
|
|
|
|
* fix handling of infinity in name/2 and friends.
|
|
|
|
*
|
2006-11-16 14:26:00 +00:00
|
|
|
* Revision 1.112 2006/11/08 01:56:47 vsc
|
|
|
|
* fix argument order in db statistics.
|
|
|
|
*
|
2006-11-08 01:56:47 +00:00
|
|
|
* Revision 1.111 2006/11/06 18:35:04 vsc
|
|
|
|
* 1estranha
|
|
|
|
*
|
2006-11-06 18:35:05 +00:00
|
|
|
* Revision 1.110 2006/10/10 14:08:17 vsc
|
|
|
|
* small fixes on threaded implementation.
|
|
|
|
*
|
2006-10-10 15:08:17 +01:00
|
|
|
* Revision 1.109 2006/09/15 19:32:47 vsc
|
|
|
|
* ichanges for QSAR
|
|
|
|
*
|
2006-09-15 20:32:47 +01:00
|
|
|
* Revision 1.108 2006/09/01 20:14:42 vsc
|
|
|
|
* more fixes for global data-structures.
|
|
|
|
* statistics on atom space.
|
|
|
|
*
|
2006-09-01 21:14:42 +01:00
|
|
|
* Revision 1.107 2006/08/22 16:12:46 vsc
|
|
|
|
* global variables
|
|
|
|
*
|
2006-08-22 17:12:46 +01:00
|
|
|
* Revision 1.106 2006/08/07 18:51:44 vsc
|
|
|
|
* fix garbage collector not to try to garbage collect when we ask for large
|
|
|
|
* chunks of stack in a single go.
|
|
|
|
*
|
2006-08-07 19:51:44 +01:00
|
|
|
* Revision 1.105 2006/06/05 19:36:00 vsc
|
|
|
|
* hacks
|
|
|
|
*
|
2006-06-05 20:36:00 +01:00
|
|
|
* Revision 1.104 2006/05/19 14:31:32 vsc
|
|
|
|
* get rid of IntArrays and FloatArray code.
|
|
|
|
* include holes when calculating memory usage.
|
|
|
|
*
|
2006-05-19 15:31:32 +01:00
|
|
|
* Revision 1.103 2006/05/18 16:33:05 vsc
|
|
|
|
* fix info reported by memory manager under DL_MALLOC and SYSTEM_MALLOC
|
|
|
|
*
|
2006-05-18 17:33:05 +01:00
|
|
|
* Revision 1.102 2006/04/28 17:53:44 vsc
|
|
|
|
* fix the expand_consult patch
|
|
|
|
*
|
2006-04-28 18:53:44 +01:00
|
|
|
* Revision 1.101 2006/04/28 13:23:23 vsc
|
|
|
|
* fix number of overflow bugs affecting threaded version
|
|
|
|
* make current_op faster.
|
|
|
|
*
|
2006-04-28 14:23:23 +01:00
|
|
|
* Revision 1.100 2006/02/05 02:26:35 tiagosoares
|
|
|
|
* MYDDAS: Top Level Functionality
|
|
|
|
*
|
2006-02-05 02:26:35 +00:00
|
|
|
* Revision 1.99 2006/02/05 02:17:54 tiagosoares
|
|
|
|
* MYDDAS: Top Level Functionality
|
|
|
|
*
|
2006-02-05 02:19:15 +00:00
|
|
|
* Revision 1.98 2005/12/17 03:25:39 vsc
|
|
|
|
* major changes to support online event-based profiling
|
|
|
|
* improve error discovery and restart on scanner.
|
|
|
|
*
|
2005-12-17 03:25:39 +00:00
|
|
|
* Revision 1.97 2005/11/22 11:25:59 tiagosoares
|
|
|
|
* support for the MyDDAS interface library
|
|
|
|
*
|
2005-11-22 11:25:59 +00:00
|
|
|
* Revision 1.96 2005/10/28 17:38:49 vsc
|
|
|
|
* sveral updates
|
|
|
|
*
|
2005-10-28 18:38:50 +01:00
|
|
|
* Revision 1.95 2005/10/21 16:09:02 vsc
|
|
|
|
* SWI compatible module only operators
|
|
|
|
*
|
2005-10-21 17:09:03 +01:00
|
|
|
* Revision 1.94 2005/09/08 22:06:45 rslopes
|
|
|
|
* BEAM for YAP update...
|
|
|
|
*
|
2005-09-08 23:06:45 +01:00
|
|
|
* Revision 1.93 2005/08/04 15:45:53 ricroc
|
|
|
|
* TABLING NEW: support to limit the table space size
|
|
|
|
*
|
2005-08-04 16:45:56 +01:00
|
|
|
* Revision 1.92 2005/07/20 13:54:27 rslopes
|
|
|
|
* solved warning: cast from pointer to integer of different size
|
|
|
|
*
|
2005-07-20 14:54:42 +01:00
|
|
|
* Revision 1.91 2005/07/06 19:33:54 ricroc
|
2014-11-25 12:03:48 +00:00
|
|
|
* TABLING: answers for completed calls can now be obtained by loading (new
|
|
|
|
*option) or executing (default) them from the trie data structure.
|
2005-07-20 14:54:42 +01:00
|
|
|
*
|
2005-07-06 20:34:12 +01:00
|
|
|
* Revision 1.90 2005/07/06 15:10:14 vsc
|
|
|
|
* improvements to compiler: merged instructions and fixes for ->
|
|
|
|
*
|
2005-07-06 16:10:18 +01:00
|
|
|
* Revision 1.89 2005/05/26 18:01:11 rslopes
|
|
|
|
* *** empty log message ***
|
|
|
|
*
|
2005-05-26 19:03:08 +01:00
|
|
|
* Revision 1.88 2005/04/27 20:09:25 vsc
|
|
|
|
* indexing code could get confused with suspension points
|
|
|
|
* some further improvements on oveflow handling
|
|
|
|
* fix paths in Java makefile
|
|
|
|
* changs to support gibbs sampling in CLP(BN)
|
|
|
|
*
|
2005-04-27 21:09:26 +01:00
|
|
|
* Revision 1.87 2005/04/07 17:48:55 ricroc
|
2014-11-25 12:03:48 +00:00
|
|
|
* Adding tabling support for mixed strategy evaluation (batched and local
|
|
|
|
*scheduling)
|
|
|
|
* UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and
|
|
|
|
*-DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the
|
|
|
|
*Makefile or --enable-tabling in configure.
|
|
|
|
* NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all
|
|
|
|
*tabled predicates to MODE (batched, local or default).
|
|
|
|
* NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of
|
|
|
|
*predicate PRED to MODE (batched or local).
|
2005-04-27 21:09:26 +01:00
|
|
|
*
|
2005-04-07 18:56:58 +01:00
|
|
|
* Revision 1.86 2005/03/13 06:26:11 vsc
|
|
|
|
* fix excessive pruning in meta-calls
|
|
|
|
* fix Term->int breakage in compiler
|
|
|
|
* improve JPL (at least it does something now for amd64).
|
|
|
|
*
|
2005-03-13 06:26:13 +00:00
|
|
|
* Revision 1.85 2005/03/02 19:48:02 vsc
|
|
|
|
* Fix some possible errors in name/2 and friends, and cleanup code a bit
|
|
|
|
* YAP_Error changed.
|
|
|
|
*
|
2005-03-02 19:48:03 +00:00
|
|
|
* Revision 1.84 2005/03/02 18:35:46 vsc
|
|
|
|
* try to make initialisation process more robust
|
|
|
|
* try to make name more robust (in case Lookup new atom fails)
|
|
|
|
*
|
2005-03-02 18:35:49 +00:00
|
|
|
* Revision 1.83 2005/03/01 22:25:09 vsc
|
|
|
|
* fix pruning bug
|
|
|
|
* make DL_MALLOC less enthusiastic about walking through buckets.
|
|
|
|
*
|
2005-03-01 22:25:09 +00:00
|
|
|
* Revision 1.82 2005/02/21 16:50:04 vsc
|
|
|
|
* amd64 fixes
|
|
|
|
* library fixes
|
|
|
|
*
|
2005-02-21 16:50:21 +00:00
|
|
|
* Revision 1.81 2005/02/08 04:05:35 vsc
|
|
|
|
* fix mess with add clause
|
|
|
|
* improves on sigsegv handling
|
|
|
|
*
|
2005-02-08 04:05:39 +00:00
|
|
|
* Revision 1.80 2005/01/05 05:32:37 vsc
|
|
|
|
* Ricardo's latest version of profiler.
|
|
|
|
*
|
2005-01-05 05:32:37 +00:00
|
|
|
* Revision 1.79 2004/12/28 22:20:36 vsc
|
2014-11-25 12:03:48 +00:00
|
|
|
* some extra bug fixes for trail overflows: some cannot be recovered that
|
|
|
|
*easily,
|
2005-01-05 05:32:37 +00:00
|
|
|
* 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
|
2014-11-25 12:03:48 +00:00
|
|
|
* fix situation where we might assume nonextsing double initialisation of C
|
|
|
|
*predicates (use
|
2004-11-19 17:14:15 +00:00
|
|
|
* 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
|
2014-11-25 12:03:48 +00:00
|
|
|
static char SccsId[] = "%W% %G%";
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
#define HAS_CACHE_REGS 1
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
2014-11-25 12:03:48 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "Yatom.h"
|
2009-10-23 14:22:17 +01:00
|
|
|
#include "YapHeap.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "eval.h"
|
|
|
|
#include "yapio.h"
|
2013-11-15 15:45:55 +00:00
|
|
|
#include "pl-shared.h"
|
2015-01-26 04:02:46 +00:00
|
|
|
#include "Foreign.h"
|
2010-04-16 02:08:06 +01:00
|
|
|
#ifdef TABLING
|
|
|
|
#include "tab.macros.h"
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2006-05-18 17:33:05 +01:00
|
|
|
#if HAVE_MALLOC_H
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2015-01-26 04:02:46 +00:00
|
|
|
#if YAP_JIT
|
|
|
|
#include <JIT_Compiler.hpp>
|
|
|
|
#endif
|
2006-11-27 17:42:03 +00:00
|
|
|
#include <wchar.h>
|
2015-01-26 04:02:46 +00:00
|
|
|
#include <fcntl.h>
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_setval(USES_REGS1);
|
|
|
|
static Int p_value(USES_REGS1);
|
|
|
|
static Int p_values(USES_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef undefined
|
2013-04-25 23:15:04 +01:00
|
|
|
static CODEADDR *FindAtom(CODEADDR, int *);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* undefined */
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_opdec(USES_REGS1);
|
|
|
|
static Int p_univ(USES_REGS1);
|
|
|
|
static Int p_abort(USES_REGS1);
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
Int p_halt(USES_REGS1);
|
2005-09-08 23:06:45 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_halt(USES_REGS1);
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int init_current_predicate(USES_REGS1);
|
|
|
|
static Int cont_current_predicate(USES_REGS1);
|
|
|
|
static OpEntry *NextOp(OpEntry *CACHE_TYPE);
|
|
|
|
static Int init_current_op(USES_REGS1);
|
|
|
|
static Int cont_current_op(USES_REGS1);
|
|
|
|
static Int init_current_atom_op(USES_REGS1);
|
|
|
|
static Int cont_current_atom_op(USES_REGS1);
|
|
|
|
static Int p_flags(USES_REGS1);
|
2013-04-25 23:15:04 +01:00
|
|
|
static Int TrailMax(void);
|
|
|
|
static Int GlobalMax(void);
|
|
|
|
static Int LocalMax(void);
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_heap_max(USES_REGS1);
|
|
|
|
static Int p_statistics_global_max(USES_REGS1);
|
|
|
|
static Int p_statistics_local_max(USES_REGS1);
|
|
|
|
static Int p_statistics_heap_info(USES_REGS1);
|
|
|
|
static Int p_statistics_stacks_info(USES_REGS1);
|
|
|
|
static Int p_statistics_trail_info(USES_REGS1);
|
|
|
|
static Term mk_argc_list(USES_REGS1);
|
|
|
|
static Int p_argv(USES_REGS1);
|
|
|
|
static Int p_cputime(USES_REGS1);
|
|
|
|
static Int p_systime(USES_REGS1);
|
|
|
|
static Int p_runtime(USES_REGS1);
|
|
|
|
static Int p_walltime(USES_REGS1);
|
|
|
|
static Int p_access_yap_flags(USES_REGS1);
|
|
|
|
static Int p_set_yap_flags(USES_REGS1);
|
|
|
|
static Int p_break(USES_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
#if YAP_JIT
|
2015-02-06 18:11:52 +00:00
|
|
|
void* (*Yap_JitCall)(JIT_Compiler* jc, yamop* p);
|
2015-01-26 04:02:46 +00:00
|
|
|
void (* Yap_llvmShutdown)(void ) ;
|
2015-02-06 18:11:52 +00:00
|
|
|
Int (* Yap_traced_absmi)(void ) ;
|
2015-01-26 04:02:46 +00:00
|
|
|
|
|
|
|
Environment ExpEnv;
|
|
|
|
|
|
|
|
static Int p_jit(USES_REGS1) { /* '$set_value'(+Atom,+Atomic) */
|
|
|
|
void *jit_handle;
|
|
|
|
if ( (jit_handle = Yap_LoadForeignFile( YAP_YAPJITLIB, 0 ) ) ) {
|
|
|
|
if (!Yap_CallForeignFile(jit_handle, "init_jit") )
|
|
|
|
fprintf(stderr, "Could not load JIT\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* YAP_JIT */
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
Int use_eam(USES_REGS1);
|
|
|
|
Int eager_split(USES_REGS1);
|
|
|
|
Int force_wait(USES_REGS1);
|
|
|
|
Int commit(USES_REGS1);
|
|
|
|
Int skip_while_var(USES_REGS1);
|
|
|
|
Int wait_while_var(USES_REGS1);
|
|
|
|
Int show_time(USES_REGS1);
|
|
|
|
Int start_eam(USES_REGS1);
|
|
|
|
Int cont_eam(USES_REGS1);
|
2005-09-08 23:06:45 +01:00
|
|
|
|
|
|
|
extern int EAM;
|
2014-11-25 12:03:48 +00:00
|
|
|
extern int eam_am(PredEntry *);
|
|
|
|
extern int showTime(void);
|
2005-09-08 23:06:45 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int start_eam(USES_REGS1) {
|
|
|
|
if (eam_am((PredEntry *)0x1))
|
|
|
|
return (TRUE);
|
|
|
|
else {
|
|
|
|
cut_fail();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int cont_eam(USES_REGS1) {
|
|
|
|
if (eam_am((PredEntry *)0x2))
|
|
|
|
return (TRUE);
|
|
|
|
else {
|
|
|
|
cut_fail();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int use_eam(USES_REGS1) {
|
|
|
|
if (EAM)
|
|
|
|
EAM = 0;
|
|
|
|
else {
|
|
|
|
Yap_PutValue(AtomCArith, 0);
|
|
|
|
EAM = 1;
|
|
|
|
}
|
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int commit(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
2014-11-25 12:03:48 +00:00
|
|
|
printf("Nao deveria ter sido chamado commit do stdpreds\n");
|
|
|
|
exit(1);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int skip_while_var(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
2014-11-25 12:03:48 +00:00
|
|
|
printf("Nao deveria ter sido chamado skip_while_var do stdpreds\n");
|
|
|
|
exit(1);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int wait_while_var(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
2014-11-25 12:03:48 +00:00
|
|
|
printf("Nao deveria ter sido chamado wait_while_var do stdpreds\n");
|
|
|
|
exit(1);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int force_wait(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
2014-11-25 12:03:48 +00:00
|
|
|
printf("Nao deveria ter sido chamado force_wait do stdpreds\n");
|
|
|
|
exit(1);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int eager_split(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
2014-11-25 12:03:48 +00:00
|
|
|
printf("Nao deveria ter sido chamado eager_split do stdpreds\n");
|
|
|
|
exit(1);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int show_time(USES_REGS1) /* MORE PRECISION */
|
2005-09-08 23:06:45 +01:00
|
|
|
{
|
|
|
|
return (showTime());
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
#endif /* BEAM */
|
2015-01-04 23:58:23 +00:00
|
|
|
// @{
|
2005-09-08 23:06:45 +01:00
|
|
|
|
2015-01-04 23:58:23 +00:00
|
|
|
/**
|
|
|
|
@defgroup YAPSetVal
|
|
|
|
@ingroup Internal_Database
|
|
|
|
|
|
|
|
Maintain a light-weight map where the key is an atom, and the value can be any constant.
|
|
|
|
*/
|
2015-02-03 02:36:51 +00:00
|
|
|
|
2015-01-04 23:58:23 +00:00
|
|
|
/** @pred set_value(+ _A_,+ _C_)
|
|
|
|
|
|
|
|
|
|
|
|
Associate atom _A_ with constant _C_.
|
|
|
|
|
|
|
|
The `set_value` and `get_value` built-ins give a fast alternative to
|
|
|
|
the internal data-base. This is a simple form of implementing a global
|
|
|
|
counter.
|
|
|
|
|
|
|
|
~~~~~
|
|
|
|
read_and_increment_counter(Value) :-
|
|
|
|
get_value(counter, Value),
|
|
|
|
Value1 is Value+1,
|
|
|
|
set_value(counter, Value1).
|
|
|
|
~~~~~
|
|
|
|
This predicate is YAP specific.
|
|
|
|
*/
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_setval(USES_REGS1) { /* '$set_value'(+Atom,+Atomic) */
|
|
|
|
Term t1 = Deref(ARG1), t2 = Deref(ARG2);
|
|
|
|
if (!IsVarTerm(t1) && IsAtomTerm(t1) &&
|
|
|
|
(!IsVarTerm(t2) && (IsAtomTerm(t2) || IsNumTerm(t2)))) {
|
|
|
|
Yap_PutValue(AtomOfTerm(t1), t2);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-01-04 23:58:23 +00:00
|
|
|
/** @pred get_value(+ _A_,- _V_)
|
|
|
|
In YAP, atoms can be associated with constants. If one such
|
|
|
|
association exists for atom _A_, unify the second argument with the
|
|
|
|
constant. Otherwise, unify _V_ with `[]`.
|
|
|
|
|
|
|
|
This predicate is YAP specific.
|
|
|
|
*/
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_value(USES_REGS1) { /* '$get_value'(+Atom,?Val) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
2002-09-13 22:30:06 +01:00
|
|
|
if (IsVarTerm(t1)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "get_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2014-11-25 12:03:48 +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
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_values(USES_REGS1) { /* '$values'(Atom,Old,New) */
|
|
|
|
Term t1 = Deref(ARG1), t3 = Deref(ARG3);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-09-13 22:30:06 +01:00
|
|
|
if (IsVarTerm(t1)) {
|
2015-01-05 16:06:32 +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)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "set_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (!Yap_unify_constant(ARG2, Yap_GetValue(AtomOfTerm(t1)))) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-01-04 23:58:23 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_opdec(USES_REGS1) { /* '$opdec'(p,type,atom) */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we know the arguments are integer, atom, atom */
|
2014-11-25 12:03:48 +00:00
|
|
|
Term p = Deref(ARG1), t = Deref(ARG2), at = Deref(ARG3);
|
2005-10-21 17:09:03 +01:00
|
|
|
Term tmod = Deref(ARG4);
|
|
|
|
if (tmod == TermProlog) {
|
|
|
|
tmod = PROLOG_MODULE;
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_OpDec((int)IntOfTerm(p), RepAtom(AtomOfTerm(t))->StrOfAE,
|
|
|
|
AtomOfTerm(at), tmod);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NO_STRTOD
|
|
|
|
|
|
|
|
#if HAVE_CTYPE_H
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
double strtod(s, pe) char *s, **pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2014-11-25 12:03:48 +00:00
|
|
|
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);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-11-16 14:26:00 +00:00
|
|
|
#ifndef INFINITY
|
2014-11-25 12:03:48 +00:00
|
|
|
#define INFINITY (1.0 / 0.0)
|
2006-11-16 14:26:00 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static UInt runtime(USES_REGS1) {
|
|
|
|
return (Yap_cputime() - Yap_total_gc_time() - Yap_total_stack_shift_time());
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2013-05-10 00:00:41 +01:00
|
|
|
/* $runtime(-SinceInterval,-SinceStart) */
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_runtime(USES_REGS1) {
|
|
|
|
Int now, interval, gc_time, ss_time;
|
2013-05-10 00:00:41 +01:00
|
|
|
Term tnow, tinterval;
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2013-05-10 00:00:41 +01:00
|
|
|
Yap_cputime_interval(&now, &interval);
|
|
|
|
gc_time = Yap_total_gc_time();
|
|
|
|
now -= gc_time;
|
|
|
|
ss_time = Yap_total_stack_shift_time();
|
|
|
|
now -= ss_time;
|
2014-11-25 12:03:48 +00:00
|
|
|
interval -= (gc_time - LOCAL_LastGcTime) + (ss_time - LOCAL_LastSSTime);
|
2013-05-10 00:00:41 +01:00
|
|
|
LOCAL_LastGcTime = gc_time;
|
|
|
|
LOCAL_LastSSTime = ss_time;
|
|
|
|
tnow = MkIntegerTerm(now);
|
|
|
|
tinterval = MkIntegerTerm(interval);
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify_constant(ARG1, tnow) &&
|
|
|
|
Yap_unify_constant(ARG2, tinterval));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2013-05-10 00:00:41 +01:00
|
|
|
/* $cputime(-SinceInterval,-SinceStart) */
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_cputime(USES_REGS1) {
|
2013-05-10 00:00:41 +01:00
|
|
|
Int now, interval;
|
|
|
|
Yap_cputime_interval(&now, &interval);
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_systime(USES_REGS1) {
|
2013-05-10 00:00:41 +01:00
|
|
|
Int now, interval;
|
|
|
|
Yap_systime_interval(&now, &interval);
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)));
|
2013-05-10 00:00:41 +01:00
|
|
|
}
|
2012-02-17 11:31:46 +00:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_walltime(USES_REGS1) {
|
2013-05-10 00:00:41 +01:00
|
|
|
Int now, interval;
|
|
|
|
Yap_walltime_interval(&now, &interval);
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)));
|
2007-10-09 00:02:16 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_univ(USES_REGS1) { /* A =.. L */
|
|
|
|
unsigned int arity;
|
|
|
|
register Term tin;
|
|
|
|
Term twork, t2;
|
|
|
|
Atom at;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
tin = Deref(ARG1);
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(tin)) {
|
|
|
|
/* we need to have a list */
|
2014-11-25 12:03:48 +00:00
|
|
|
Term *Ar;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "(=..)/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsPairTerm(t2)) {
|
|
|
|
if (t2 == TermNil)
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_NON_EMPTY_LIST, t2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2014-11-25 12:03:48 +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");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (IsNumTerm(twork)) {
|
|
|
|
Term tt = TailOfTerm(t2);
|
2014-10-22 10:43:38 +01:00
|
|
|
if (IsVarTerm(tt)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tt, "(=..)/2");
|
|
|
|
return (FALSE);
|
2014-10-22 10:43:38 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (tt != MkAtomTerm(AtomNil)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC, twork, "(=..)/2");
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
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)) {
|
2014-10-22 10:43:38 +01:00
|
|
|
Term tt = TailOfTerm(t2);
|
|
|
|
if (IsVarTerm(tt)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
|
|
|
return (FALSE);
|
2014-10-22 10:43:38 +01:00
|
|
|
} else if (tt == MkAtomTerm(AtomNil)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC, twork, "(=..)/2");
|
|
|
|
return (FALSE);
|
2014-10-22 10:43:38 +01:00
|
|
|
} else {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, twork, "(=..)/2");
|
|
|
|
return (FALSE);
|
2014-10-22 10:43:38 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
at = AtomOfTerm(twork);
|
|
|
|
twork = TailOfTerm(t2);
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else if (!IsPairTerm(twork)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (twork != TermNil) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
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 */
|
2014-01-19 21:15:05 +00:00
|
|
|
Ar = HR;
|
|
|
|
HR++;
|
2014-11-25 12:03:48 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
while (!IsVarTerm(twork) && IsPairTerm(twork)) {
|
2014-01-19 21:15:05 +00:00
|
|
|
*HR++ = HeadOfTerm(twork);
|
|
|
|
if (HR > ASP - 1024) {
|
2014-11-25 12:03:48 +00:00
|
|
|
/* restore space */
|
|
|
|
HR = Ar;
|
|
|
|
if (!Yap_gcl((ASP - HR) * sizeof(CELL), 2, ENV, gc_P(P, CP))) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
twork = TailOfTerm(Deref(ARG2));
|
|
|
|
goto build_compound;
|
2002-05-07 22:19:52 +01:00
|
|
|
}
|
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");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
{
|
2014-11-25 12:03:48 +00:00
|
|
|
SFEntry *pe = (SFEntry *)Yap_GetAProp(at, SFProperty);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe)
|
2014-11-25 12:03:48 +00:00
|
|
|
twork = MkSFTerm(Yap_MkFunctor(at, SFArity), arity, CellPtr(TR),
|
|
|
|
pe->NilValue);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
twork = Yap_MkApplTerm(Yap_MkFunctor(at, arity), arity, CellPtr(TR));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
arity = HR - Ar - 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (at == AtomDot && arity == 2) {
|
|
|
|
Ar[0] = Ar[1];
|
|
|
|
Ar[1] = Ar[2];
|
2014-11-25 12:03:48 +00:00
|
|
|
HR--;
|
2001-04-09 20:54:03 +01:00
|
|
|
twork = AbsPair(Ar);
|
2014-11-25 12:03:48 +00:00
|
|
|
} 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)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Functor fun = FunctorOfTerm(tin);
|
|
|
|
if (IsExtensionFunctor(fun)) {
|
2014-02-02 21:45:47 +00:00
|
|
|
twork = MkPairTerm(tin, MkAtomTerm(AtomNil));
|
|
|
|
return (Yap_unify(twork, ARG2));
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = ArityOfFunctor(fun);
|
|
|
|
at = NameOfFunctor(fun);
|
|
|
|
#ifdef SFUNC
|
|
|
|
if (arity == SFArity) {
|
2014-11-25 12:03:48 +00:00
|
|
|
CELL *p = CellPtr(TR);
|
|
|
|
CELL *q = ArgsOfSFTerm(tin);
|
|
|
|
int argno = 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
while (*q) {
|
2014-11-25 12:03:48 +00:00
|
|
|
while (*q > argno++)
|
|
|
|
*p++ = MkVarTerm();
|
|
|
|
++q;
|
|
|
|
*p++ = Deref(*q++);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
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)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
if (!Yap_gc(2, ENV, gc_P(P, CP))) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
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
|
2014-11-25 12:03:48 +00:00
|
|
|
{
|
|
|
|
while (HR + arity * 2 > ASP - 1024) {
|
|
|
|
if (!Yap_gcl((arity * 2) * sizeof(CELL), 2, ENV, gc_P(P, CP))) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
tin = Deref(ARG1);
|
2002-05-07 22:19:52 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
twork = Yap_ArrayToList(RepAppl(tin) + 1, arity);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_abort(USES_REGS1) { /* abort */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* make sure we won't go creeping around */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PURE_ABORT, TermNil, "");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
extern void exit_eam(char *s);
|
2005-09-08 23:06:45 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Int
|
2005-09-08 23:06:45 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
2014-11-25 12:03:48 +00:00
|
|
|
p_halt(USES_REGS1) { /* halt */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Int out;
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
if (EAM)
|
|
|
|
exit_eam("\n\n[ Prolog execution halted ]\n");
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "halt/1");
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(t)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t, "halt/1");
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
out = IntegerOfTerm(t);
|
2015-01-26 04:02:46 +00:00
|
|
|
#if YAP_JIT
|
|
|
|
if (ExpEnv.analysis_struc.stats_enabled || ExpEnv.analysis_struc.time_pass_enabled) {
|
|
|
|
if (strcmp(((char*)ExpEnv.analysis_struc.outfile), "STDERR")) {
|
|
|
|
int stderrcopy = dup(2);
|
|
|
|
if (strcmp(((char*)ExpEnv.analysis_struc.outfile), "STDOUT") == 0) {
|
|
|
|
dup2(1, 2);
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
|
|
|
|
shutdown_llvm();
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
dup2(stderrcopy, 2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int Outputfile = open(((char*)ExpEnv.analysis_struc.outfile), O_CREAT | O_APPEND | O_WRONLY, 0777);
|
|
|
|
if (Outputfile < 0) {
|
|
|
|
fprintf(stderr, "Error:: I can not write analysis passes's output on %s...\n", ((char*)ExpEnv.analysis_struc.outfile));
|
|
|
|
fprintf(stderr, " %s...\n", strerror(errno));
|
|
|
|
errno = 0;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
dup2(Outputfile, 2);
|
|
|
|
shutdown_llvm();
|
|
|
|
close(Outputfile);
|
|
|
|
dup2(stderrcopy, 2);
|
|
|
|
}
|
|
|
|
close(stderrcopy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shutdown_llvm();
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-03 02:36:51 +00:00
|
|
|
|
2004-04-27 16:14:38 +01:00
|
|
|
Yap_exit(out);
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int cont_current_predicate(USES_REGS1) {
|
|
|
|
PredEntry *pp = NULL;
|
2001-10-03 14:39:16 +01:00
|
|
|
UInt Arity;
|
2003-10-28 01:16:03 +00:00
|
|
|
Term name;
|
2014-11-25 12:03:48 +00:00
|
|
|
Term t1 = Deref(ARG1), t2 = Deref(ARG2), t3;
|
|
|
|
bool is_det = false, rc;
|
|
|
|
Functor f;
|
|
|
|
|
|
|
|
if (IsNonVarTerm(t1)) {
|
2015-01-18 01:32:13 +00:00
|
|
|
PropEntry *p = AddressOfTerm(EXTRA_CBACK_ARG(4, 1));
|
|
|
|
PropEntry *q = AddressOfTerm(EXTRA_CBACK_ARG(4, 2));
|
|
|
|
// restart inner loop
|
|
|
|
for (; q; q = q->NextOfPE) {
|
|
|
|
if (q->KindOfPE == PEProp) {
|
|
|
|
pp = RepPredProp(q);
|
|
|
|
q = q->NextOfPE;
|
|
|
|
if (q == NIL)
|
|
|
|
p = p->NextOfPE;
|
|
|
|
if (!p)
|
|
|
|
is_det = true;
|
|
|
|
// we are done with this loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!pp && p) {
|
|
|
|
// try using outer loop
|
|
|
|
for (; p; p = p->NextOfPE) {
|
|
|
|
if (p->KindOfPE == PEProp) {
|
|
|
|
q = NULL;
|
|
|
|
pp = RepPredProp(p);
|
|
|
|
p = p->NextOfPE;
|
|
|
|
if (!p)
|
|
|
|
is_det = true;
|
|
|
|
break;
|
|
|
|
} else if (p->KindOfPE == FunctorProperty) {
|
|
|
|
// looping on p/n
|
|
|
|
for (q = RepFunctorProp(p)->PropsOfFE; q; q = q->NextOfPE) {
|
|
|
|
if (q->KindOfPE == PEProp) {
|
|
|
|
pp = RepPredProp(q);
|
|
|
|
q = q->NextOfPE;
|
|
|
|
if (!q && !p->NextOfPE)
|
|
|
|
is_det = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pp == NULL) // nothing more
|
2015-01-18 01:32:13 +00:00
|
|
|
cut_fail();
|
2014-11-25 12:03:48 +00:00
|
|
|
if (!is_det) {
|
|
|
|
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
|
|
|
|
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
|
|
|
|
}
|
|
|
|
} else if (IsNonVarTerm(t2)) {
|
|
|
|
// operating within the same module.
|
|
|
|
PredEntry *npp;
|
|
|
|
pp = AddressOfTerm(EXTRA_CBACK_ARG(4, 1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
if (!pp)
|
|
|
|
cut_fail();
|
|
|
|
// just try next one
|
|
|
|
npp = pp->NextPredOfModule;
|
|
|
|
if (npp) {
|
|
|
|
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(npp);
|
|
|
|
} else {
|
|
|
|
is_det = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pp = AddressOfTerm(EXTRA_CBACK_ARG(4, 1));
|
|
|
|
|
|
|
|
while (!pp) {
|
|
|
|
ModEntry *m = AddressOfTerm(EXTRA_CBACK_ARG(4, 2));
|
|
|
|
m = m->NextME;
|
|
|
|
if (!m)
|
|
|
|
cut_fail();
|
|
|
|
else {
|
|
|
|
pp = m->PredForME;
|
|
|
|
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
|
|
|
|
}
|
|
|
|
} // we found a new answer
|
|
|
|
if (!pp)
|
|
|
|
cut_fail();
|
|
|
|
else
|
|
|
|
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(pp->NextPredOfModule);
|
2002-08-14 17:00:54 +01:00
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pp->ModuleOfPred != IDB_MODULE) {
|
2014-11-25 12:03:48 +00:00
|
|
|
f = pp->FunctorOfPred;
|
2003-10-28 01:16:03 +00:00
|
|
|
Arity = pp->ArityOfPE;
|
|
|
|
if (Arity)
|
2014-11-25 12:03:48 +00:00
|
|
|
name = MkAtomTerm(NameOfFunctor(f));
|
2003-10-28 01:16:03 +00:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
name = MkAtomTerm((Atom)f);
|
2003-10-28 01:16:03 +00:00
|
|
|
} else {
|
|
|
|
if (pp->PredFlags & NumberDBPredFlag) {
|
|
|
|
name = MkIntegerTerm(pp->src.IndxId);
|
|
|
|
Arity = 0;
|
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
2014-11-25 12:03:48 +00:00
|
|
|
f = pp->FunctorOfPred;
|
|
|
|
name = MkAtomTerm((Atom)f);
|
2003-10-28 01:16:03 +00:00
|
|
|
Arity = 0;
|
|
|
|
} else {
|
2014-11-25 12:03:48 +00:00
|
|
|
f = pp->FunctorOfPred;
|
|
|
|
f = pp->FunctorOfPred;
|
2003-10-28 01:16:03 +00:00
|
|
|
name = MkAtomTerm(NameOfFunctor(f));
|
2014-11-25 12:03:48 +00:00
|
|
|
Arity = ArityOfFunctor(pp->FunctorOfPred);
|
2003-10-28 01:16:03 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (Arity) {
|
|
|
|
t3 = Yap_MkNewApplTerm(f, Arity);
|
|
|
|
} else {
|
|
|
|
t3 = name;
|
|
|
|
}
|
|
|
|
rc = (!(pp->PredFlags & HiddenPredFlag)) &&
|
|
|
|
Yap_unify(ARG2, ModToTerm(pp->ModuleOfPred)) && Yap_unify(ARG1, name) &&
|
|
|
|
Yap_unify(ARG3, t3) && Yap_unify(ARG4, MkIntegerTerm(pp->PredFlags));
|
|
|
|
if (is_det) {
|
|
|
|
if (rc)
|
|
|
|
cut_succeed();
|
|
|
|
else
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
return rc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int init_current_predicate(USES_REGS1) {
|
|
|
|
Term t1 = Deref(ARG1), t2 = Deref(ARG2), t3 = Deref(ARG3);
|
|
|
|
unsigned int arity;
|
|
|
|
Functor f = NIL;
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pp = NULL;
|
|
|
|
ModEntry *m = NULL;
|
2002-09-02 18:33:00 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
// check term
|
|
|
|
if (!IsVarTerm(t3)) {
|
|
|
|
t3 = Yap_StripModule(t3, &t2);
|
|
|
|
if (IsAtomTerm(t3)) {
|
|
|
|
at = AtomOfTerm(t3);
|
|
|
|
arity = 0;
|
|
|
|
} else if (IsIntTerm(t3)) {
|
|
|
|
if (IsNonVarTerm(t2) && t2 != IDB_MODULE) {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, t3, "current_predicate/2");
|
|
|
|
cut_fail();
|
|
|
|
} else if (IsVarTerm(t2)) {
|
|
|
|
Yap_unify(t2, IDB_MODULE); // should always succeed
|
|
|
|
if (Yap_unify(ARG1, t3))
|
|
|
|
cut_succeed();
|
|
|
|
else
|
|
|
|
cut_fail();
|
|
|
|
}
|
2014-12-04 07:59:30 +00:00
|
|
|
return FALSE;
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (IsPairTerm(t3)) {
|
|
|
|
f = FunctorDot;
|
|
|
|
at = AtomDot;
|
|
|
|
arity = 2;
|
|
|
|
} else {
|
|
|
|
f = FunctorOfTerm(t3);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, t3, "current_predicate/2");
|
|
|
|
cut_fail();
|
2014-11-25 19:52:51 +00:00
|
|
|
return FALSE;
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
|
|
|
at = NameOfFunctor(f);
|
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
}
|
2014-11-26 09:45:11 +00:00
|
|
|
if (IsAtomTerm(t2)) { // we know the module and the main predicate
|
2014-11-25 12:03:48 +00:00
|
|
|
// so that we are deterministic
|
|
|
|
if (arity == 0) {
|
|
|
|
if (Yap_GetPredPropByAtom(at, t2) != NIL &&
|
2014-11-26 09:45:11 +00:00
|
|
|
Yap_unify(ARG1, MkAtomTerm(at))) {
|
2014-11-25 12:03:48 +00:00
|
|
|
cut_succeed();
|
2014-11-26 09:45:11 +00:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
} else {
|
|
|
|
if (Yap_GetPredPropByFunc(f, t2) != NIL &&
|
2014-11-26 09:45:11 +00:00
|
|
|
Yap_unify(ARG1, MkAtomTerm(at))) {
|
2014-11-25 12:03:48 +00:00
|
|
|
cut_succeed();
|
2014-11-26 09:45:11 +00:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check name
|
|
|
|
if (IsNonVarTerm(t1)) {
|
|
|
|
if (IsIntTerm(t1) && (IsVarTerm(t2) || t2 == IDB_MODULE)) {
|
|
|
|
// idb allows numeric keys.
|
|
|
|
if (Yap_FindLUIntKey(IntOfTerm(t2))) {
|
|
|
|
if (Yap_unify(ARG2, IDB_MODULE))
|
|
|
|
cut_succeed();
|
|
|
|
cut_fail();
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (!IsAtomTerm(t1)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "current_predicate/2");
|
|
|
|
cut_fail();
|
|
|
|
} else {
|
|
|
|
PropEntry *p = RepAtom(AtomOfTerm(t1))->PropsOfAE, *q = NIL;
|
2015-01-18 01:32:13 +00:00
|
|
|
while (p && p->KindOfPE == FunctorProperty &&
|
|
|
|
(q = RepFunctorProp(p)->PropsOfFE) == NIL) {
|
|
|
|
p = p->NextOfPE;
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
2015-01-18 01:32:13 +00:00
|
|
|
if (!p)
|
|
|
|
cut_fail();
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
|
|
|
|
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
// check module
|
|
|
|
else {
|
|
|
|
if (IsNonVarTerm(t2)) {
|
|
|
|
if (!IsAtomTerm(t2)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t2, "current_predicate/2");
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
m = Yap_GetModuleEntry(t2);
|
|
|
|
} else {
|
|
|
|
m = CurrentModules;
|
|
|
|
}
|
|
|
|
if (!m)
|
|
|
|
cut_fail();
|
|
|
|
pp = m->PredForME;
|
|
|
|
if (IsNonVarTerm(t2) && !pp) {
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
|
|
|
|
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp);
|
|
|
|
}
|
|
|
|
// ensure deref access to choice-point fields.
|
|
|
|
return cont_current_predicate(PASS_REGS1);
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static OpEntry *NextOp(OpEntry *pp USES_REGS) {
|
2009-11-27 16:09:48 +00:00
|
|
|
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty &&
|
2014-11-25 12:03:48 +00:00
|
|
|
(pp->OpModule != PROLOG_MODULE || pp->OpModule != CurrentModule))
|
2001-04-09 20:54:03 +01:00
|
|
|
pp = RepOpProp(pp->NextOfPE);
|
|
|
|
return (pp);
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
int Yap_IsOp(Atom at) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
2009-11-27 16:09:48 +00:00
|
|
|
return (!EndOfPAEntr(op));
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
int Yap_IsOpMaxPrio(Atom at) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
2010-02-26 14:14:10 +00:00
|
|
|
int max;
|
|
|
|
|
|
|
|
if (EndOfPAEntr(op))
|
|
|
|
return 0;
|
|
|
|
max = (op->Prefix & 0xfff);
|
|
|
|
if ((op->Infix & 0xfff) > max)
|
|
|
|
max = op->Infix & 0xfff;
|
|
|
|
if ((op->Posfix & 0xfff) > max)
|
|
|
|
max = op->Posfix & 0xfff;
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int unify_op(OpEntry *op USES_REGS) {
|
2009-11-25 00:38:47 +00:00
|
|
|
Term tmod = op->OpModule;
|
|
|
|
|
|
|
|
if (tmod == PROLOG_MODULE)
|
|
|
|
tmod = TermProlog;
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify_constant(ARG2, tmod) &&
|
|
|
|
Yap_unify_constant(ARG3, MkIntegerTerm(op->Prefix)) &&
|
|
|
|
Yap_unify_constant(ARG4, MkIntegerTerm(op->Infix)) &&
|
|
|
|
Yap_unify_constant(ARG5, MkIntegerTerm(op->Posfix));
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int cont_current_op(USES_REGS1) {
|
|
|
|
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)), *next;
|
|
|
|
|
2009-11-25 00:38:47 +00:00
|
|
|
READ_LOCK(op->OpRWLock);
|
|
|
|
next = op->OpNext;
|
2014-11-25 12:03:48 +00:00
|
|
|
if (Yap_unify_constant(ARG1, MkAtomTerm(op->OpName)) &&
|
2011-03-07 16:02:55 +00:00
|
|
|
unify_op(op PASS_REGS)) {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
|
2009-11-25 00:38:47 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_succeed();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
|
2009-11-25 00:38:47 +00:00
|
|
|
return FALSE;
|
2006-04-28 14:23:23 +01:00
|
|
|
} else {
|
|
|
|
cut_fail();
|
|
|
|
}
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int init_current_op(
|
|
|
|
USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
|
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)OpList);
|
|
|
|
return cont_current_op(PASS_REGS1);
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int cont_current_atom_op(USES_REGS1) {
|
|
|
|
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)), *next;
|
|
|
|
|
2009-11-25 00:38:47 +00:00
|
|
|
READ_LOCK(op->OpRWLock);
|
2011-03-07 16:02:55 +00:00
|
|
|
next = NextOp(RepOpProp(op->NextOfPE) PASS_REGS);
|
|
|
|
if (unify_op(op PASS_REGS)) {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
|
2009-11-25 00:38:47 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cut_succeed();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-04-28 14:23:23 +01:00
|
|
|
} else {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
|
2009-11-25 00:38:47 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2006-04-28 14:23:23 +01:00
|
|
|
cut_fail();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int init_current_atom_op(
|
|
|
|
USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
|
2009-11-25 00:38:47 +00:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
AtomEntry *ae;
|
|
|
|
OpEntry *ope;
|
|
|
|
|
|
|
|
if (IsVarTerm(t) || !IsAtomTerm(t)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t, "current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_fail();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
ae = RepAtom(AtomOfTerm(t));
|
2011-03-07 16:02:55 +00:00
|
|
|
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) {
|
2009-11-25 00:38:47 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
|
|
|
|
return cont_current_atom_op(PASS_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_flags(USES_REGS1) { /* $flags(+Functor,+Mod,?OldFlags,?NewFlags) */
|
|
|
|
PredEntry *pe;
|
2015-01-06 17:47:58 +00:00
|
|
|
pred_flags_t newFl;
|
2001-04-09 20:54:03 +01:00
|
|
|
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)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsAtomTerm(t1)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
while ((pe = RepPredProp(PredPropByAtom(AtomOfTerm(t1), mod))) == NULL) {
|
2007-11-06 17:02:13 +00:00
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
2007-11-06 17:02:13 +00:00
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsApplTerm(t1)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
while ((pe = RepPredProp(PredPropByFunc(funt, mod))) == NULL) {
|
2007-11-06 17:02:13 +00:00
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
2007-11-06 17:02:13 +00:00
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return (FALSE);
|
2014-11-25 12:03:48 +00:00
|
|
|
PELOCK(92, pe);
|
2015-01-18 01:32:13 +00:00
|
|
|
if (!Yap_unify_constant(ARG3, MkIntegerTerm(pe->PredFlags))) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
ARG4 = Deref(ARG4);
|
|
|
|
if (IsVarTerm(ARG4)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
2015-01-18 01:32:13 +00:00
|
|
|
} else if (!IsIntegerTerm(ARG4)) {
|
2008-12-04 23:33:32 +00:00
|
|
|
Term te = Yap_Eval(ARG4);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-01-18 01:32:13 +00:00
|
|
|
if (IsIntegerTerm(te)) {
|
|
|
|
newFl = IntegerOfTerm(te);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, ARG4, "flags");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else
|
2015-01-18 01:32:13 +00:00
|
|
|
newFl = IntegerOfTerm(ARG4);
|
2015-01-06 17:47:58 +00:00
|
|
|
pe->PredFlags = newFl;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int
|
|
|
|
p_set_flag(USES_REGS1) { /* $flags(+Functor,+Mod,?OldFlags,?NewFlags) */
|
|
|
|
PredEntry *pe;
|
2013-11-25 10:26:42 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
Term v = Deref(ARG4);
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2013-11-25 10:26:42 +00:00
|
|
|
}
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
while ((pe = RepPredProp(PredPropByAtom(AtomOfTerm(t1), mod))) == NULL) {
|
2013-11-25 10:26:42 +00:00
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
2013-11-25 10:26:42 +00:00
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
|
|
|
} else if (IsApplTerm(t1)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
while ((pe = RepPredProp(PredPropByFunc(funt, mod))) == NULL) {
|
2013-11-25 10:26:42 +00:00
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
2013-11-25 10:26:42 +00:00
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return (FALSE);
|
|
|
|
ARG3 = Deref(ARG3);
|
|
|
|
if (IsVarTerm(ARG3)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return (FALSE);
|
|
|
|
} else if (!IsAtomTerm(ARG3)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG3, "set_property/1");
|
|
|
|
return (FALSE);
|
2013-11-25 10:26:42 +00:00
|
|
|
}
|
|
|
|
v = Deref(ARG4);
|
|
|
|
if (IsVarTerm(ARG4)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return (FALSE);
|
2015-01-18 01:32:13 +00:00
|
|
|
} else if (!IsIntTerm(v)) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, v, "set_property/1");
|
|
|
|
return (FALSE);
|
2013-11-25 10:26:42 +00:00
|
|
|
}
|
|
|
|
s = RepAtom(AtomOfTerm(ARG3))->StrOfAE;
|
|
|
|
if (v == MkIntTerm(1)) {
|
|
|
|
if (!strcmp(s, "quasi_quotation_syntax")) {
|
2014-11-25 12:03:48 +00:00
|
|
|
pe->PredFlags |= QuasiQuotationPredFlag;
|
2013-11-25 10:26:42 +00:00
|
|
|
} else if (!strcmp(s, "trace")) {
|
|
|
|
// proc->ExtraPredFlags |= QuasiQuotationPredFlag;
|
|
|
|
} else {
|
2014-11-25 12:03:48 +00:00
|
|
|
fprintf(stderr, "not implemented");
|
2013-11-25 10:26:42 +00:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else if (v == MkIntTerm(0)) {
|
|
|
|
if (!strcmp(s, "quasi_quotation_syntax")) {
|
2014-11-25 12:03:48 +00:00
|
|
|
pe->PredFlags &= ~QuasiQuotationPredFlag;
|
2013-11-25 10:26:42 +00:00
|
|
|
} else if (!strcmp(s, "trace")) {
|
2014-11-25 12:03:48 +00:00
|
|
|
// proc->PredFlags |= QuasiQuotationPredFlag;
|
2013-11-25 10:26:42 +00:00
|
|
|
} else {
|
2014-11-25 12:03:48 +00:00
|
|
|
fprintf(stderr, "not implemented");
|
2013-11-25 10:26:42 +00:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
|
2013-11-25 10:26:42 +00:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
void Yap_show_statistics(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-05-18 17:33:05 +01:00
|
|
|
unsigned long int heap_space_taken;
|
|
|
|
double frag;
|
|
|
|
|
|
|
|
#if USE_SYSTEM_MALLOC && HAVE_MALLINFO
|
|
|
|
struct mallinfo mi = mallinfo();
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
heap_space_taken = (mi.arena + mi.hblkhd) - Yap_HoleSize;
|
2006-05-18 17:33:05 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
heap_space_taken =
|
|
|
|
(unsigned long int)(Unsigned(HeapTop) - Unsigned(Yap_HeapBase)) -
|
|
|
|
Yap_HoleSize;
|
2006-05-18 17:33:05 +01:00
|
|
|
#endif
|
2014-11-25 12:03:48 +00:00
|
|
|
frag = (100.0 * (heap_space_taken - HeapUsed)) / heap_space_taken;
|
|
|
|
|
|
|
|
Sfprintf(GLOBAL_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)),
|
|
|
|
(unsigned long int)(HeapUsed), frag);
|
|
|
|
Sfprintf(GLOBAL_stderr, "Stack Space: %ld (%ld for Global, %ld for local).\n",
|
|
|
|
(unsigned long int)(sizeof(CELL) * (LCL0 - H0)),
|
|
|
|
(unsigned long int)(sizeof(CELL) * (HR - H0)),
|
|
|
|
(unsigned long int)(sizeof(CELL) * (LCL0 - ASP)));
|
|
|
|
Sfprintf(GLOBAL_stderr, "Trail Space: %ld (%ld used).\n",
|
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr) * (Unsigned(LOCAL_TrailTop) -
|
|
|
|
Unsigned(LOCAL_TrailBase))),
|
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr) *
|
|
|
|
(Unsigned(TR) - Unsigned(LOCAL_TrailBase))));
|
|
|
|
Sfprintf(GLOBAL_stderr, "Runtime: %lds.\n",
|
|
|
|
(unsigned long int)(runtime(PASS_REGS1)));
|
|
|
|
Sfprintf(GLOBAL_stderr, "Cputime: %lds.\n",
|
|
|
|
(unsigned long int)(Yap_cputime()));
|
|
|
|
Sfprintf(GLOBAL_stderr, "Walltime: %lds.\n",
|
|
|
|
(unsigned long int)(Yap_walltime()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int p_statistics_heap_max(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tmax = MkIntegerTerm(HeapMax);
|
|
|
|
|
2014-11-25 12:03:48 +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 */
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int TrailTide = -1, LocalTide = -1, GlobalTide = -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* maximum Trail usage */
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int TrailMax(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
2011-05-23 16:19:47 +01:00
|
|
|
Int TrWidth = Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (TrailTide != TrWidth) {
|
|
|
|
pt = (CELL *)TR;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (pt + 2 < (CELL *)LOCAL_TrailTop) {
|
|
|
|
if (pt[0] == 0 && pt[1] == 0 && pt[2] == 0)
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
pt++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (pt + 2 < (CELL *)LOCAL_TrailTop)
|
2011-05-23 16:19:47 +01:00
|
|
|
i = Unsigned(pt) - Unsigned(LOCAL_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
|
|
|
i = TrWidth;
|
|
|
|
} else
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TrWidth);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (TrailTide > i)
|
|
|
|
i = TrailTide;
|
|
|
|
else
|
|
|
|
TrailTide = i;
|
2014-11-25 12:03:48 +00:00
|
|
|
return (i);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_trail_max(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tmax = MkIntegerTerm(TrailMax());
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* maximum Global usage */
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int GlobalMax(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (GlobalTide != StkWidth) {
|
2014-01-19 21:15:05 +00:00
|
|
|
pt = HR;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (pt + 2 < ASP) {
|
|
|
|
if (pt[0] == 0 && pt[1] == 0 && pt[2] == 0)
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
pt++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (pt + 2 < ASP)
|
2001-04-09 20:54:03 +01:00
|
|
|
i = Unsigned(pt) - Unsigned(H0);
|
|
|
|
else
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
} else
|
2014-11-25 12:03:48 +00:00
|
|
|
return (StkWidth);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (GlobalTide > i)
|
|
|
|
i = GlobalTide;
|
|
|
|
else
|
|
|
|
GlobalTide = i;
|
2014-11-25 12:03:48 +00:00
|
|
|
return (i);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_global_max(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tmax = MkIntegerTerm(GlobalMax());
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int LocalMax(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (LocalTide != StkWidth) {
|
|
|
|
pt = LCL0;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (pt - 3 > HR) {
|
|
|
|
if (pt[-1] == 0 && pt[-2] == 0 && pt[-3] == 0)
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
--pt;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
if (pt - 3 > HR)
|
2001-04-09 20:54:03 +01:00
|
|
|
i = Unsigned(LCL0) - Unsigned(pt);
|
|
|
|
else
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
} else
|
2014-11-25 12:03:48 +00:00
|
|
|
return (StkWidth);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (LocalTide > i)
|
|
|
|
i = LocalTide;
|
|
|
|
else
|
|
|
|
LocalTide = i;
|
2014-11-25 12:03:48 +00:00
|
|
|
return (i);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_local_max(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tmax = MkIntegerTerm(LocalMax());
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_heap_info(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tusage = MkIntegerTerm(HeapUsed);
|
|
|
|
|
2006-05-18 17:33:05 +01:00
|
|
|
#if USE_SYSTEM_MALLOC && HAVE_MALLINFO
|
|
|
|
struct mallinfo mi = mallinfo();
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
UInt sstack = Yap_HoleSize + (LOCAL_TrailTop - LOCAL_GlobalBase);
|
|
|
|
UInt mmax = (mi.arena + mi.hblkhd);
|
|
|
|
Term tmax = MkIntegerTerm(mmax - sstack);
|
|
|
|
tusage = MkIntegerTerm(mmax - (mi.fordblks + sstack));
|
2006-05-18 17:33:05 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
Term tmax = MkIntegerTerm((LOCAL_GlobalBase - Yap_HeapBase) - Yap_HoleSize);
|
2006-05-18 17:33:05 +01:00
|
|
|
#endif
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1) && Yap_unify(tusage, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_stacks_info(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tmax = MkIntegerTerm(Unsigned(LCL0) - Unsigned(H0));
|
2014-01-19 21:15:05 +00:00
|
|
|
Term tgusage = MkIntegerTerm(Unsigned(HR) - Unsigned(H0));
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tlusage = MkIntegerTerm(Unsigned(LCL0) - Unsigned(ASP));
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1) && Yap_unify(tgusage, ARG2) &&
|
|
|
|
Yap_unify(tlusage, ARG3));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_trail_info(USES_REGS1) {
|
|
|
|
Term tmax =
|
|
|
|
MkIntegerTerm(Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase));
|
2011-05-23 16:19:47 +01:00
|
|
|
Term tusage = MkIntegerTerm(Unsigned(TR) - Unsigned(LOCAL_TrailBase));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return (Yap_unify(tmax, ARG1) && Yap_unify(tusage, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_atom_info(USES_REGS1) {
|
2006-09-01 21:14:42 +01:00
|
|
|
UInt count = 0, spaceused = 0, i;
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
for (i = 0; i < AtomHashTableSize; i++) {
|
2006-09-01 21:14:42 +01:00
|
|
|
Atom catom;
|
|
|
|
|
2006-10-10 15:08:17 +01:00
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
2006-09-01 21:14:42 +01:00
|
|
|
catom = HashChain[i].Entry;
|
|
|
|
if (catom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(catom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
while (catom != NIL) {
|
|
|
|
Atom ncatom;
|
|
|
|
count++;
|
2014-11-25 12:03:48 +00:00
|
|
|
spaceused += sizeof(AtomEntry) + strlen(RepAtom(catom)->StrOfAE) + 1;
|
2006-09-01 21:14:42 +01:00
|
|
|
ncatom = RepAtom(catom)->NextOfAE;
|
|
|
|
if (ncatom != NIL) {
|
2014-11-25 12:03:48 +00:00
|
|
|
READ_LOCK(RepAtom(ncatom)->ARWLock);
|
2006-09-01 21:14:42 +01:00
|
|
|
}
|
2013-01-23 09:55:11 +00:00
|
|
|
READ_UNLOCK(RepAtom(catom)->ARWLock);
|
2006-09-01 21:14:42 +01:00
|
|
|
catom = ncatom;
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
for (i = 0; i < WideAtomHashTableSize; i++) {
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom catom;
|
|
|
|
|
|
|
|
READ_LOCK(WideHashChain[i].AERWLock);
|
|
|
|
catom = WideHashChain[i].Entry;
|
|
|
|
if (catom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(catom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(WideHashChain[i].AERWLock);
|
|
|
|
while (catom != NIL) {
|
|
|
|
Atom ncatom;
|
|
|
|
count++;
|
2014-11-25 12:03:48 +00:00
|
|
|
spaceused +=
|
|
|
|
sizeof(AtomEntry) +
|
|
|
|
sizeof(wchar_t) * (wcslen((wchar_t *)(RepAtom(catom)->StrOfAE) + 1));
|
2006-11-27 17:42:03 +00:00
|
|
|
ncatom = RepAtom(catom)->NextOfAE;
|
|
|
|
if (ncatom != NIL) {
|
2014-11-25 12:03:48 +00:00
|
|
|
READ_LOCK(RepAtom(ncatom)->ARWLock);
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2013-01-23 09:55:11 +00:00
|
|
|
READ_UNLOCK(RepAtom(catom)->ARWLock);
|
2006-11-27 17:42:03 +00:00
|
|
|
catom = ncatom;
|
|
|
|
}
|
|
|
|
}
|
2006-09-01 21:14:42 +01:00
|
|
|
return Yap_unify(ARG1, MkIntegerTerm(count)) &&
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_unify(ARG2, MkIntegerTerm(spaceused));
|
2006-09-01 21:14:42 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_db_size(USES_REGS1) {
|
2006-11-06 18:35:05 +00:00
|
|
|
Term t = MkIntegerTerm(Yap_ClauseSpace);
|
|
|
|
Term tit = MkIntegerTerm(Yap_IndexSpace_Tree);
|
|
|
|
Term tis = MkIntegerTerm(Yap_IndexSpace_SW);
|
|
|
|
Term tie = MkIntegerTerm(Yap_IndexSpace_EXT);
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify(t, ARG1) && Yap_unify(tit, ARG2) && Yap_unify(tis, ARG3) &&
|
|
|
|
Yap_unify(tie, ARG4);
|
2006-11-06 18:35:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_statistics_lu_db_size(USES_REGS1) {
|
2006-11-06 18:35:05 +00:00
|
|
|
Term t = MkIntegerTerm(Yap_LUClauseSpace);
|
|
|
|
Term tit = MkIntegerTerm(Yap_LUIndexSpace_Tree);
|
|
|
|
Term tic = MkIntegerTerm(Yap_LUIndexSpace_CP);
|
|
|
|
Term tix = MkIntegerTerm(Yap_LUIndexSpace_EXT);
|
|
|
|
Term tis = MkIntegerTerm(Yap_LUIndexSpace_SW);
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify(t, ARG1) && Yap_unify(tit, ARG2) && Yap_unify(tic, ARG3) &&
|
|
|
|
Yap_unify(tis, ARG4) && Yap_unify(tix, ARG5);
|
2006-11-06 18:35:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Term mk_argc_list(USES_REGS1) {
|
|
|
|
int i = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = TermNil;
|
2011-05-25 16:40:36 +01:00
|
|
|
while (i < GLOBAL_argc) {
|
|
|
|
char *arg = GLOBAL_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'))
|
2014-11-25 12:03:48 +00:00
|
|
|
arg++;
|
2001-05-28 20:54:53 +01:00
|
|
|
if (*arg == '-' && arg[1] == '-' && arg[2] == '\0') {
|
2014-11-25 12:03:48 +00:00
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
|
|
|
for (j = GLOBAL_argc - 1; j > i + 1; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])), t);
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
} else if (GLOBAL_argv[i + 1] && GLOBAL_argv[i + 1][0] == '-' &&
|
|
|
|
GLOBAL_argv[i + 1][1] == '-' &&
|
|
|
|
GLOBAL_argv[i + 1][2] == '\0') {
|
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
|
|
|
for (j = GLOBAL_argc - 1; j > i + 2; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])), t);
|
|
|
|
}
|
|
|
|
return t;
|
2001-05-28 20:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0') {
|
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
2014-11-25 12:03:48 +00:00
|
|
|
for (j = GLOBAL_argc - 1; j > i; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])), t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
i++;
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
|
|
|
return (t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Term mk_os_argc_list(USES_REGS1) {
|
|
|
|
int i = 0;
|
2014-10-26 17:38:41 +00:00
|
|
|
Term t = TermNil;
|
2014-11-25 12:03:48 +00:00
|
|
|
for (i = 0; i < GLOBAL_argc; i++) {
|
2014-10-26 17:38:41 +00:00
|
|
|
char *arg = GLOBAL_argv[i];
|
2014-11-25 12:03:48 +00:00
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(arg)), t);
|
|
|
|
}
|
|
|
|
return (t);
|
2014-10-26 17:38:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_argv(USES_REGS1) {
|
|
|
|
Term t = mk_argc_list(PASS_REGS1);
|
2009-12-10 01:16:29 +00:00
|
|
|
return Yap_unify(t, ARG1);
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_os_argv(USES_REGS1) {
|
|
|
|
Term t = mk_os_argc_list(PASS_REGS1);
|
2014-10-26 17:38:41 +00:00
|
|
|
return Yap_unify(t, ARG1);
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_executable(USES_REGS1) {
|
2013-01-13 17:55:13 +00:00
|
|
|
if (GLOBAL_argv && GLOBAL_argv[0])
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_TrueFileName(GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
2013-01-13 17:55:13 +00:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);
|
2013-01-13 17:55:13 +00:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_access_yap_flags(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term tflag = Deref(ARG1);
|
|
|
|
Int flag;
|
2005-08-04 16:45:56 +01:00
|
|
|
Term tout = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tflag, "access_yap_flags/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "access_yap_flags/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
flag = IntOfTerm(tflag);
|
2013-01-09 09:20:41 +00:00
|
|
|
if (flag < 0 || flag >= NUMBER_OF_YAP_FLAGS) {
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-07-06 20:34:12 +01:00
|
|
|
if (flag == TABLING_MODE_FLAG) {
|
2013-01-29 10:50:04 +00:00
|
|
|
#ifdef TABLING
|
2010-04-16 02:08:06 +01:00
|
|
|
tout = TermNil;
|
|
|
|
if (IsMode_LocalTrie(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLocalTrie), tout);
|
2013-12-18 15:01:02 +00:00
|
|
|
else if (IsMode_GlobalTrie(yap_flags[flag]))
|
2010-04-16 02:08:06 +01:00
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomGlobalTrie), tout);
|
2013-01-29 10:50:04 +00:00
|
|
|
if (IsMode_LoadAnswers(yap_flags[flag]))
|
2010-04-16 02:08:06 +01:00
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLoadAnswers), tout);
|
2013-12-18 15:01:02 +00:00
|
|
|
else if (IsMode_ExecAnswers(yap_flags[flag]))
|
2013-01-29 10:50:04 +00:00
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomExecAnswers), tout);
|
|
|
|
if (IsMode_Local(yap_flags[flag]))
|
2010-04-16 02:08:06 +01:00
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLocal), tout);
|
2013-12-18 15:01:02 +00:00
|
|
|
else if (IsMode_Batched(yap_flags[flag]))
|
2013-01-29 10:50:04 +00:00
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomBatched), tout);
|
2013-12-19 16:56:55 +00:00
|
|
|
else if (IsMode_CoInductive(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomCoInductive), tout);
|
2013-01-29 10:50:04 +00:00
|
|
|
#else
|
|
|
|
tout = MkAtomTerm(AtomFalse);
|
2005-07-06 20:34:12 +01:00
|
|
|
#endif /* TABLING */
|
2013-01-29 10:50:04 +00:00
|
|
|
} else
|
2014-11-25 12:03:48 +00:00
|
|
|
tout = MkIntegerTerm(yap_flags[flag]);
|
|
|
|
return (Yap_unify(ARG2, tout));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_has_yap_or(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_has_eam(USES_REGS1) {
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2005-09-08 23:06:45 +01:00
|
|
|
#else
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-03 02:36:51 +00:00
|
|
|
static Int p_has_jit(USES_REGS1) {
|
|
|
|
#ifdef HAS_JIT
|
|
|
|
return (TRUE);
|
|
|
|
#else
|
|
|
|
return (FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_set_yap_flags(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
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");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "set_yap_flags/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
flag = IntOfTerm(tflag);
|
|
|
|
if (IsVarTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tvalue, "set_yap_flags/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsIntTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tvalue, "set_yap_flags/2");
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
value = IntOfTerm(tvalue);
|
|
|
|
/* checking should have been performed */
|
2014-11-25 12:03:48 +00:00
|
|
|
switch (flag) {
|
2001-04-09 20:54:03 +01:00
|
|
|
case LANGUAGE_MODE_FLAG:
|
|
|
|
if (value < 0 || value > 2)
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (value == 1) {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_heap_regs->pred_meta_call =
|
|
|
|
RepPredProp(PredPropByFunc(FunctorMetaCall, 0));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_heap_regs->pred_meta_call =
|
|
|
|
RepPredProp(PredPropByFunc(FunctorMetaCall, 0));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
yap_flags[LANGUAGE_MODE_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case SOURCE_MODE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[SOURCE_MODE_FLAG] = value;
|
|
|
|
break;
|
2014-10-19 11:27:53 +01:00
|
|
|
case FLOATING_POINT_EXCEPTION_MODE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2014-10-19 11:27:53 +01:00
|
|
|
yap_flags[FLOATING_POINT_EXCEPTION_MODE_FLAG] = value;
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
case WRITE_QUOTED_STRING_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case ALLOW_ASSERTING_STATIC_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = value;
|
|
|
|
break;
|
2002-12-10 14:36:22 +00:00
|
|
|
case STACK_DUMP_ON_ERROR_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2002-12-10 14:36:22 +00:00
|
|
|
yap_flags[STACK_DUMP_ON_ERROR_FLAG] = value;
|
|
|
|
break;
|
2003-06-06 12:54:02 +01:00
|
|
|
case INDEXING_MODE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value < INDEX_MODE_OFF || value > INDEX_MODE_MAX)
|
|
|
|
return (FALSE);
|
2003-06-06 12:54:02 +01:00
|
|
|
yap_flags[INDEXING_MODE_FLAG] = value;
|
|
|
|
break;
|
2005-04-07 18:56:58 +01:00
|
|
|
#ifdef TABLING
|
2005-07-06 20:34:12 +01:00
|
|
|
case TABLING_MODE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value == 0) { /* default */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
TabEnt_mode(tab_ent) = TabEnt_flags(tab_ent);
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
|
|
|
yap_flags[TABLING_MODE_FLAG] = 0;
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 1) { /* batched */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_Batched(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
|
|
|
SetMode_Batched(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 2) { /* local */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_Local(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
|
|
|
SetMode_Local(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 3) { /* exec_answers */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_ExecAnswers(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
|
|
|
SetMode_ExecAnswers(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 4) { /* load_answers */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_LoadAnswers(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
|
|
|
SetMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 5) { /* local_trie */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_LocalTrie(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2010-04-16 02:08:06 +01:00
|
|
|
}
|
|
|
|
SetMode_LocalTrie(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 6) { /* global_trie */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
|
|
|
SetMode_GlobalTrie(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
2010-04-16 02:08:06 +01:00
|
|
|
}
|
|
|
|
SetMode_GlobalTrie(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
} else if (value == 7) { /* CoInductive */
|
2013-12-19 16:56:55 +00:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2014-11-25 12:03:48 +00:00
|
|
|
while (tab_ent) {
|
2013-12-19 16:56:55 +00:00
|
|
|
SetMode_CoInductive(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_CoInductive(yap_flags[TABLING_MODE_FLAG]);
|
2014-11-25 12:03:48 +00:00
|
|
|
}
|
2005-04-07 18:56:58 +01:00
|
|
|
break;
|
2005-07-06 20:34:12 +01:00
|
|
|
#endif /* TABLING */
|
2008-02-07 23:09:13 +00:00
|
|
|
case VARS_CAN_HAVE_QUOTE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return (FALSE);
|
2008-02-07 23:09:13 +00:00
|
|
|
yap_flags[VARS_CAN_HAVE_QUOTE_FLAG] = value;
|
|
|
|
break;
|
2008-03-15 12:19:33 +00:00
|
|
|
case QUIET_MODE_FLAG:
|
2014-11-25 12:03:48 +00:00
|
|
|
if (value != 0 && value != 1)
|
2010-04-14 23:47:01 +01:00
|
|
|
return FALSE;
|
|
|
|
yap_flags[QUIET_MODE_FLAG] = value;
|
2008-03-15 12:19:33 +00:00
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
default:
|
2014-11-25 12:03:48 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_system_mode(USES_REGS1) {
|
2013-12-10 22:58:02 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
if (LOCAL_PrologMode & SystemMode)
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify(t1, MkAtomTerm(AtomTrue));
|
2013-12-10 22:58:02 +00:00
|
|
|
else
|
2014-11-25 12:03:48 +00:00
|
|
|
return Yap_unify(t1, MkAtomTerm(AtomFalse));
|
2013-12-10 22:58:02 +00:00
|
|
|
} else {
|
|
|
|
Atom at = AtomOfTerm(t1);
|
2014-11-25 12:03:48 +00:00
|
|
|
if (at == AtomFalse)
|
2013-12-10 22:58:02 +00:00
|
|
|
LOCAL_PrologMode &= ~SystemMode;
|
|
|
|
else
|
|
|
|
LOCAL_PrologMode |= SystemMode;
|
|
|
|
}
|
2006-12-13 16:10:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_lock_system(USES_REGS1) {
|
2011-05-10 10:06:51 +01:00
|
|
|
LOCK(GLOBAL_BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_unlock_system(USES_REGS1) {
|
2011-05-10 10:06:51 +01:00
|
|
|
UNLOCK(GLOBAL_BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_enterundefp(USES_REGS1) {
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_DoingUndefp) {
|
2004-12-08 04:45:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_DoingUndefp = TRUE;
|
2004-12-08 04:45:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_exitundefp(USES_REGS1) {
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_DoingUndefp) {
|
|
|
|
LOCAL_DoingUndefp = FALSE;
|
2004-12-08 04:45:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern void DumpActiveGoals(void);
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_dump_active_goals(USES_REGS1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
DumpActiveGoals();
|
2014-11-25 12:03:48 +00:00
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-04 03:25:41 +00:00
|
|
|
#ifdef INES
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_euc_dist(USES_REGS1) {
|
2002-03-04 03:25:41 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term t2 = Deref(ARG2);
|
2014-11-25 12:03:48 +00:00
|
|
|
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);
|
|
|
|
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;
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_loop(USES_REGS1) {
|
|
|
|
while (loop_counter == 0)
|
|
|
|
;
|
|
|
|
return (TRUE);
|
2002-03-08 06:32:11 +00:00
|
|
|
}
|
2002-03-04 03:25:41 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_break(USES_REGS1) {
|
|
|
|
Atom at = AtomOfTerm(Deref(ARG1));
|
2013-11-15 15:45:55 +00:00
|
|
|
if (at == AtomTrue) {
|
|
|
|
LOCAL_PL_local_data_p->break_level++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (at == AtomFalse) {
|
|
|
|
LOCAL_PL_local_data_p->break_level--;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
void Yap_InitBackCPreds(void) {
|
|
|
|
Yap_InitCPredBack("$current_predicate", 4, 2, init_current_predicate,
|
|
|
|
cont_current_predicate, SafePredFlag | SyncPredFlag);
|
2009-11-25 00:38:47 +00:00
|
|
|
Yap_InitCPredBack("$current_op", 5, 1, init_current_op, cont_current_op,
|
2014-11-25 12:03:48 +00:00
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPredBack("$current_atom_op", 5, 1, init_current_atom_op,
|
|
|
|
cont_current_atom_op, SafePredFlag | SyncPredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPredBack("eam", 1, 0, start_eam, cont_eam, SafePredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
|
|
|
|
2013-05-10 00:00:41 +01:00
|
|
|
Yap_InitBackAtoms();
|
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);
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Proc E_Modules[] = {/* init_fc,*/ (Proc)0};
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-02-03 02:36:51 +00:00
|
|
|
#ifdef YAPOR
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_parallel_mode(USES_REGS1) { return FALSE; }
|
2011-06-21 15:19:07 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
static Int p_yapor_workers(USES_REGS1) { return FALSE; }
|
2011-06-21 15:19:07 +01:00
|
|
|
#endif /* YAPOR */
|
2010-01-15 01:03:34 +00:00
|
|
|
|
2015-01-26 04:02:46 +00:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
void Yap_InitCPreds(void) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* numerical comparison */
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("set_value", 2, p_setval, SafePredFlag | SyncPredFlag);
|
2015-01-04 23:58:23 +00:00
|
|
|
Yap_InitCPred("get_value", 2, p_value,
|
2014-11-25 12:03:48 +00:00
|
|
|
TestPredFlag | SafePredFlag | SyncPredFlag);
|
2015-01-04 23:58:23 +00:00
|
|
|
Yap_InitCPred("$values", 3, p_values, SafePredFlag | SyncPredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
/* general purpose */
|
|
|
|
Yap_InitCPred("$opdec", 4, p_opdec, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("=..", 2, p_univ, 0);
|
|
|
|
/** @pred _T_ =.. _L_ is iso
|
|
|
|
|
|
|
|
|
|
|
|
The list _L_ is built with the functor and arguments of the term
|
|
|
|
_T_. If _T_ is instantiated to a variable, then _L_ must be
|
|
|
|
instantiated either to a list whose head is an atom, or to a list
|
|
|
|
consisting of just a number.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
Yap_InitCPred("$statistics_trail_max", 1, p_statistics_trail_max,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_heap_max", 1, p_statistics_heap_max,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_global_max", 1, p_statistics_global_max,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_local_max", 1, p_statistics_local_max,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_heap_info", 2, p_statistics_heap_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_stacks_info", 3, p_statistics_stacks_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_trail_info", 2, p_statistics_trail_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_atom_info", 2, p_statistics_atom_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_db_size", 4, p_statistics_db_size,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_lu_db_size", 5, p_statistics_lu_db_size,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$argv", 1, p_argv, SafePredFlag);
|
2014-10-26 17:38:41 +00:00
|
|
|
Yap_InitCPred("$os_argv", 1, p_os_argv, SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$executable", 1, p_executable, SafePredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("$runtime", 2, p_runtime, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$cputime", 2, p_cputime, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$systime", 2, p_systime, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$walltime", 2, p_walltime, SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$access_yap_flags", 2, p_access_yap_flags, SafePredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("$set_yap_flags", 2, p_set_yap_flags,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$system_mode", 1, p_system_mode, SafePredFlag | SyncPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("abort", 0, p_abort, SyncPredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
/** @pred abort
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
Abandons the execution of the current goal and returns to top level. All
|
|
|
|
break levels (see break/0 below) are terminated. It is mainly
|
|
|
|
used during debugging or after a serious execution error, to return to
|
|
|
|
the top-level.
|
2014-09-11 20:06:57 +01:00
|
|
|
|
2014-11-25 12:03:48 +00:00
|
|
|
|
|
|
|
*/
|
2013-11-15 15:45:55 +00:00
|
|
|
Yap_InitCPred("$break", 1, p_break, SafePredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
Yap_InitCPred("@", 0, eager_split, SafePredFlag);
|
|
|
|
Yap_InitCPred(":", 0, force_wait, SafePredFlag);
|
|
|
|
Yap_InitCPred("/", 0, commit, SafePredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("skip_while_var", 1, skip_while_var, SafePredFlag);
|
|
|
|
Yap_InitCPred("wait_while_var", 1, wait_while_var, SafePredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
Yap_InitCPred("eamtime", 0, show_time, SafePredFlag);
|
|
|
|
Yap_InitCPred("eam", 0, use_eam, SafePredFlag);
|
|
|
|
#endif
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$halt", 1, p_halt, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$lock_system", 0, p_lock_system, SafePredFlag);
|
|
|
|
Yap_InitCPred("$unlock_system", 0, p_unlock_system, SafePredFlag);
|
|
|
|
Yap_InitCPred("$enter_undefp", 0, p_enterundefp, SafePredFlag);
|
|
|
|
Yap_InitCPred("$exit_undefp", 0, p_exitundefp, SafePredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Accessing and changing the flags for a predicate */
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$flags", 4, p_flags, SyncPredFlag);
|
2013-11-25 10:26:42 +00:00
|
|
|
Yap_InitCPred("$set_flag", 4, p_set_flag, SyncPredFlag);
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("$has_yap_or", 0, p_has_yap_or, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$has_eam", 0, p_has_eam, SafePredFlag | SyncPredFlag);
|
2015-02-03 02:36:51 +00:00
|
|
|
Yap_InitCPred("$has_jit", 0, p_has_jit, SafePredFlag | SyncPredFlag);
|
2015-01-26 04:02:46 +00:00
|
|
|
#ifdef YAPOR
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("parallel_mode", 1, p_parallel_mode,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2015-02-03 02:36:51 +00:00
|
|
|
#endif
|
2015-01-26 04:02:46 +00:00
|
|
|
#ifdef YAP_JIT
|
2015-02-03 02:36:51 +00:00
|
|
|
Yap_InitCPred("$jit_init", 1, p_jit,
|
2015-01-26 04:02:46 +00:00
|
|
|
SafePredFlag | SyncPredFlag);
|
2015-02-03 02:36:51 +00:00
|
|
|
#endif /* YAPOR */
|
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
|
2006-06-05 20:36:00 +01:00
|
|
|
#if QSAR
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("in_range", 8, p_in_range, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("in_range", 4, p_in_range2, TestPredFlag | SafePredFlag);
|
2006-06-05 20:36:00 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
2014-11-25 12:03:48 +00:00
|
|
|
Yap_InitCPred("dump_active_goals", 0, p_dump_active_goals,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitArrayPreds();
|
2013-05-10 00:00:41 +01:00
|
|
|
Yap_InitAtomPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitBBPreds();
|
|
|
|
Yap_InitBigNums();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitCdMgr();
|
|
|
|
Yap_InitCmpPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCoroutPreds();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitDBPreds();
|
|
|
|
Yap_InitExecFs();
|
|
|
|
Yap_InitGlobals();
|
|
|
|
Yap_InitInlines();
|
|
|
|
Yap_InitIOPreds();
|
2013-01-07 09:47:14 +00:00
|
|
|
Yap_InitExoPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitLoadForeign();
|
2004-02-06 02:26:23 +00:00
|
|
|
Yap_InitModulesC();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitSavePreds();
|
2012-10-23 14:55:44 +01:00
|
|
|
Yap_InitRange();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitSysPreds();
|
|
|
|
Yap_InitUnify();
|
2011-08-03 08:23:00 +01:00
|
|
|
Yap_InitQLY();
|
2011-08-24 04:11:54 +01:00
|
|
|
Yap_InitQLYR();
|
2009-02-20 11:42:48 +00:00
|
|
|
Yap_udi_init();
|
2013-04-25 20:21:41 +01:00
|
|
|
Yap_udi_Interval_init();
|
2013-02-08 16:36:45 +00:00
|
|
|
Yap_InitSignalCPreds();
|
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();
|
2005-12-17 03:25:39 +00:00
|
|
|
Yap_InitLowProf();
|
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 */
|
2015-01-26 04:02:46 +00:00
|
|
|
#if YAP_JIT
|
|
|
|
Yap_InitCPred("jit", 0, p_jit,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
#endif
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_InitThreadPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2014-11-25 12:03:48 +00:00
|
|
|
void (*(*(p)))(void) = E_Modules;
|
2001-04-09 20:54:03 +01:00
|
|
|
while (*p)
|
2014-11-25 12:03:48 +00:00
|
|
|
(*(*p++))();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#if CAMACHO
|
|
|
|
{
|
|
|
|
extern void InitForeignPreds(void);
|
2014-11-25 12:03:48 +00:00
|
|
|
|
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);
|
2014-11-25 12:03:48 +00:00
|
|
|
|
2002-09-24 20:01:29 +01:00
|
|
|
init_ol();
|
|
|
|
init_time();
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-28 18:53:44 +01:00
|
|
|
#if SUPPORT_CONDOR
|
|
|
|
init_sys();
|
|
|
|
init_random();
|
|
|
|
// init_tries();
|
|
|
|
init_regexp();
|
|
|
|
#endif
|
2007-10-10 10:44:28 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2007-10-10 10:44:28 +01:00
|
|
|
Term cm = CurrentModule;
|
|
|
|
CurrentModule = SWI_MODULE;
|
2007-10-18 09:24:16 +01:00
|
|
|
Yap_swi_install();
|
2007-10-10 10:44:28 +01:00
|
|
|
CurrentModule = cm;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|