2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: cdmgr.c *
|
|
|
|
* comments: Code manager *
|
|
|
|
* *
|
2008-07-23 00:34:50 +01:00
|
|
|
* Last rev: $Date: 2008-07-22 23:34:44 $,$Author: vsc $ *
|
2004-03-19 11:35:42 +00:00
|
|
|
* $Log: not supported by cvs2svn $
|
2008-07-23 00:34:50 +01:00
|
|
|
* Revision 1.230 2008/06/02 17:20:28 vsc
|
|
|
|
* fix abolish bug
|
|
|
|
*
|
2008-06-02 18:20:28 +01:00
|
|
|
* Revision 1.229 2008/05/28 17:18:35 vsc
|
|
|
|
* thread fixes
|
|
|
|
*
|
2008-05-28 18:18:35 +01:00
|
|
|
* Revision 1.228 2008/04/28 23:02:32 vsc
|
|
|
|
* fix bug in current_predicate/2
|
|
|
|
* fix bug in c_interface.
|
|
|
|
*
|
2008-04-29 00:02:32 +01:00
|
|
|
* Revision 1.227 2008/04/11 16:30:27 ricroc
|
|
|
|
* *** empty log message ***
|
|
|
|
*
|
2008-04-11 17:30:28 +01:00
|
|
|
* Revision 1.226 2008/04/01 22:28:41 vsc
|
|
|
|
* put YAPOR back to life.
|
|
|
|
*
|
2008-04-01 23:28:41 +01:00
|
|
|
* Revision 1.225 2008/04/01 08:42:45 vsc
|
|
|
|
* fix restore and small VISTA thingies
|
|
|
|
*
|
2008-04-01 09:42:46 +01:00
|
|
|
* Revision 1.224 2008/03/31 22:56:21 vsc
|
|
|
|
* more fixes
|
|
|
|
*
|
2008-03-31 23:56:22 +01:00
|
|
|
* Revision 1.223 2008/03/25 16:45:53 vsc
|
|
|
|
* make or-parallelism compile again
|
|
|
|
*
|
2008-03-25 16:45:53 +00:00
|
|
|
* Revision 1.222 2008/03/24 23:48:47 vsc
|
|
|
|
* fix maximum number of threads open error
|
|
|
|
*
|
2008-03-24 23:48:47 +00:00
|
|
|
* Revision 1.221 2008/03/22 23:35:00 vsc
|
|
|
|
* fix bug in all_calls
|
|
|
|
*
|
2008-03-22 23:35:00 +00:00
|
|
|
* Revision 1.220 2008/03/17 18:31:16 vsc
|
|
|
|
* fix breakage in module system
|
|
|
|
* disable stack writing in error for now
|
|
|
|
*
|
2008-03-17 18:31:16 +00:00
|
|
|
* Revision 1.219 2008/02/22 15:08:33 vsc
|
|
|
|
* Big update to support more SICStus/SWI like message handling
|
|
|
|
* fix YAPSHAREDIR
|
|
|
|
* fix yap.tex (Bernd)
|
|
|
|
*
|
2008-02-22 15:08:37 +00:00
|
|
|
* Revision 1.218 2008/01/23 17:57:44 vsc
|
|
|
|
* valgrind it!
|
|
|
|
* enable atom garbage collection.
|
|
|
|
*
|
2008-01-23 17:57:56 +00:00
|
|
|
* Revision 1.217 2007/12/26 19:50:40 vsc
|
|
|
|
* new version of clp(fd)
|
|
|
|
* fix deadlock with empty args facts in clause/2.
|
|
|
|
*
|
2007-12-26 19:50:40 +00:00
|
|
|
* Revision 1.216 2007/12/23 22:48:44 vsc
|
|
|
|
* recover stack space
|
|
|
|
*
|
2007-12-23 22:48:44 +00:00
|
|
|
* Revision 1.215 2007/12/18 17:46:58 vsc
|
|
|
|
* purge_clauses does not need to do anything if there are no clauses
|
|
|
|
* fix gprof bugs.
|
|
|
|
*
|
2007-12-18 17:46:58 +00:00
|
|
|
* Revision 1.214 2007/11/28 23:52:14 vsc
|
|
|
|
* junction tree algorithm
|
|
|
|
*
|
2007-11-28 23:52:14 +00:00
|
|
|
* Revision 1.213 2007/11/26 23:43:07 vsc
|
|
|
|
* fixes to support threads and assert correctly, even if inefficiently.
|
|
|
|
*
|
2007-11-26 23:43:10 +00:00
|
|
|
* Revision 1.212 2007/11/16 14:58:40 vsc
|
|
|
|
* implement sophisticated operations with matrices.
|
|
|
|
*
|
2007-11-16 14:58:41 +00:00
|
|
|
* Revision 1.211 2007/11/08 09:53:01 vsc
|
|
|
|
* YAP would always say the system has tabling!
|
|
|
|
*
|
2007-11-08 09:53:01 +00:00
|
|
|
* Revision 1.210 2007/11/07 09:25:27 vsc
|
|
|
|
* speedup meta-calls
|
|
|
|
*
|
2007-11-07 09:25:27 +00:00
|
|
|
* Revision 1.209 2007/11/06 17:02:11 vsc
|
|
|
|
* compile ground terms away.
|
|
|
|
*
|
2007-11-06 17:02:13 +00:00
|
|
|
* Revision 1.208 2007/11/01 10:01:35 vsc
|
|
|
|
* fix uninitalised lock and reconsult test.
|
|
|
|
*
|
2007-11-01 10:01:35 +00:00
|
|
|
* Revision 1.207 2007/10/29 22:48:54 vsc
|
|
|
|
* small fixes
|
|
|
|
*
|
2007-10-29 22:48:54 +00:00
|
|
|
* Revision 1.206 2007/04/10 22:13:20 vsc
|
|
|
|
* fix max modules limitation
|
|
|
|
*
|
2007-04-10 23:13:21 +01:00
|
|
|
* Revision 1.205 2007/03/26 15:18:43 vsc
|
|
|
|
* debugging and clause/3 over tabled predicates would kill YAP.
|
|
|
|
*
|
2007-03-26 16:18:43 +01:00
|
|
|
* Revision 1.204 2007/01/25 22:11:55 vsc
|
|
|
|
* all/3 should fail on no solutions.
|
|
|
|
* get rid of annoying gcc complaints.
|
|
|
|
*
|
2007-01-25 22:11:55 +00:00
|
|
|
* Revision 1.203 2007/01/24 10:01:38 vsc
|
|
|
|
* fix matrix mess
|
|
|
|
*
|
2007-01-24 10:01:40 +00:00
|
|
|
* Revision 1.202 2006/12/27 01:32:37 vsc
|
|
|
|
* diverse fixes
|
|
|
|
*
|
2006-12-27 01:32:38 +00:00
|
|
|
* Revision 1.201 2006/12/13 16:10:14 vsc
|
|
|
|
* several debugger and CLP(BN) improvements.
|
|
|
|
*
|
2006-12-13 16:10:26 +00:00
|
|
|
* Revision 1.200 2006/11/27 17:42:02 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
2006-11-27 17:42:03 +00:00
|
|
|
* Revision 1.199 2006/11/15 00:13:36 vsc
|
|
|
|
* fixes for indexing code.
|
|
|
|
*
|
2006-11-15 00:13:37 +00:00
|
|
|
* Revision 1.198 2006/11/14 11:42:25 vsc
|
|
|
|
* fix bug in growstack
|
|
|
|
*
|
2006-11-14 11:42:26 +00:00
|
|
|
* Revision 1.197 2006/11/06 18:35:03 vsc
|
|
|
|
* 1estranha
|
|
|
|
*
|
2006-11-06 18:35:05 +00:00
|
|
|
* Revision 1.196 2006/10/16 17:12:48 vsc
|
|
|
|
* fixes for threaded version.
|
|
|
|
*
|
2006-10-16 18:12:48 +01:00
|
|
|
* Revision 1.195 2006/10/11 17:24:36 vsc
|
|
|
|
* make sure we only follow pointers *before* we removed the respective code block,
|
|
|
|
* ie don't kill the child before checking pointers from parent!
|
|
|
|
*
|
2006-10-11 18:24:36 +01:00
|
|
|
* Revision 1.194 2006/10/11 15:08:03 vsc
|
|
|
|
* fix bb entries
|
|
|
|
* comment development code for timestamp overflow.
|
|
|
|
*
|
2006-10-11 16:08:03 +01:00
|
|
|
* Revision 1.193 2006/10/11 14:53:57 vsc
|
|
|
|
* fix memory leak
|
|
|
|
* fix overflow handling
|
|
|
|
* VS: ----------------------------------------------------------------------
|
|
|
|
*
|
2006-10-11 15:53:57 +01:00
|
|
|
* Revision 1.192 2006/10/10 14:08:16 vsc
|
|
|
|
* small fixes on threaded implementation.
|
|
|
|
*
|
2006-10-10 15:08:17 +01:00
|
|
|
* Revision 1.191 2006/09/20 20:03:51 vsc
|
|
|
|
* improve indexing on floats
|
|
|
|
* fix sending large lists to DB
|
|
|
|
*
|
2006-09-20 21:03:51 +01:00
|
|
|
* Revision 1.190 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.189 2006/05/24 02:35:39 vsc
|
|
|
|
* make chr work and other minor fixes.
|
|
|
|
*
|
2006-05-24 03:35:39 +01:00
|
|
|
* Revision 1.188 2006/05/18 16:33:04 vsc
|
|
|
|
* fix info reported by memory manager under DL_MALLOC and SYSTEM_MALLOC
|
|
|
|
*
|
2006-05-18 17:33:05 +01:00
|
|
|
* Revision 1.187 2006/04/29 01:15:18 vsc
|
|
|
|
* fix expand_consult patch
|
|
|
|
*
|
2006-04-29 02:15:18 +01:00
|
|
|
* Revision 1.186 2006/04/28 17:53:44 vsc
|
|
|
|
* fix the expand_consult patch
|
|
|
|
*
|
2006-04-28 18:53:44 +01:00
|
|
|
* Revision 1.185 2006/04/28 13:23:22 vsc
|
|
|
|
* fix number of overflow bugs affecting threaded version
|
|
|
|
* make current_op faster.
|
|
|
|
*
|
2006-04-28 14:23:23 +01:00
|
|
|
* Revision 1.184 2006/04/27 14:11:57 rslopes
|
|
|
|
* *** empty log message ***
|
|
|
|
*
|
2006-04-27 15:13:24 +01:00
|
|
|
* Revision 1.183 2006/03/29 16:00:10 vsc
|
|
|
|
* make tabling compile
|
|
|
|
*
|
2006-03-29 17:00:10 +01:00
|
|
|
* Revision 1.182 2006/03/24 16:26:26 vsc
|
|
|
|
* code review
|
|
|
|
*
|
2006-03-24 16:26:31 +00:00
|
|
|
* Revision 1.181 2006/03/22 20:07:28 vsc
|
|
|
|
* take better care of zombies
|
|
|
|
*
|
2006-03-22 20:07:28 +00:00
|
|
|
* Revision 1.180 2006/03/22 16:14:20 vsc
|
|
|
|
* don't be too eager at throwing indexing code for static predicates away.
|
|
|
|
*
|
2006-03-22 16:14:20 +00:00
|
|
|
* Revision 1.179 2006/03/21 17:11:39 vsc
|
|
|
|
* prevent breakage
|
|
|
|
*
|
2006-03-21 17:11:39 +00:00
|
|
|
* Revision 1.178 2006/03/20 19:51:43 vsc
|
|
|
|
* fix indexing and tabling bugs
|
|
|
|
*
|
2006-03-20 19:51:44 +00:00
|
|
|
* Revision 1.177 2006/03/06 14:04:56 vsc
|
|
|
|
* fixes to garbage collector
|
|
|
|
* fixes to debugger
|
|
|
|
*
|
2006-03-06 14:04:57 +00:00
|
|
|
* Revision 1.176 2006/02/01 13:28:56 vsc
|
|
|
|
* bignum support fixes
|
|
|
|
*
|
2006-02-01 13:28:57 +00:00
|
|
|
* Revision 1.175 2006/01/08 03:12:00 vsc
|
|
|
|
* fix small bug in attvar handling.
|
|
|
|
*
|
2006-01-08 03:12:02 +00:00
|
|
|
* Revision 1.174 2005/12/23 00:20:13 vsc
|
|
|
|
* updates to gprof
|
|
|
|
* support for __POWER__
|
2010-10-26 22:01:29 +01:00
|
|
|
* Try to saveregs before _longjmp.
|
2006-01-08 03:12:02 +00:00
|
|
|
*
|
2005-12-23 00:20:14 +00:00
|
|
|
* Revision 1.173 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.172 2005/11/23 03:01:33 vsc
|
|
|
|
* fix several bugs in save/restore.b
|
|
|
|
*
|
2005-11-23 03:01:33 +00:00
|
|
|
* Revision 1.171 2005/10/29 01:28:37 vsc
|
|
|
|
* make undefined more ISO compatible.
|
|
|
|
*
|
2005-10-29 02:28:37 +01:00
|
|
|
* Revision 1.170 2005/10/18 17:04:43 vsc
|
|
|
|
* 5.1:
|
|
|
|
* - improvements to GC
|
|
|
|
* 2 generations
|
|
|
|
* generic speedups
|
|
|
|
* - new scheme for attvars
|
|
|
|
* - hProlog like interface also supported
|
|
|
|
* - SWI compatibility layer
|
|
|
|
* - extra predicates
|
|
|
|
* - global variables
|
|
|
|
* - moved to Prolog module
|
|
|
|
* - CLP(R) by Leslie De Koninck, Tom Schrijvers, Cristian Holzbaur, Bart
|
|
|
|
* Demoen and Jan Wielemacker
|
|
|
|
* - load_files/2
|
|
|
|
*
|
|
|
|
* from 5.0.1
|
|
|
|
*
|
|
|
|
* - WIN32 missing include files (untested)
|
|
|
|
* - -L trouble (my thanks to Takeyuchi Shiramoto-san)!
|
|
|
|
* - debugging of backtrable user-C preds would core dump.
|
|
|
|
* - redeclaring a C-predicate as Prolog core dumps.
|
|
|
|
* - badly protected YapInterface.h.
|
|
|
|
* - break/0 was failing at exit.
|
|
|
|
* - YAP_cut_fail and YAP_cut_succeed were different from manual.
|
|
|
|
* - tracing through data-bases could core dump.
|
|
|
|
* - cut could break on very large computations.
|
|
|
|
* - first pass at BigNum issues (reported by Roberto).
|
|
|
|
* - debugger could get go awol after fail port.
|
|
|
|
* - weird message on wrong debugger option.
|
|
|
|
*
|
2005-10-18 18:04:43 +01:00
|
|
|
* Revision 1.169 2005/10/15 02:05:57 vsc
|
|
|
|
* fix for trying to add clauses to a C pred.
|
|
|
|
*
|
2005-10-15 03:05:57 +01:00
|
|
|
* Revision 1.168 2005/08/05 14:55:02 vsc
|
|
|
|
* first steps to allow mavars with tabling
|
|
|
|
* fix trailing for tabling with multiple get_cons
|
|
|
|
*
|
2005-08-05 15:55:03 +01:00
|
|
|
* Revision 1.167 2005/08/02 03:09:49 vsc
|
|
|
|
* fix debugger to do well nonsource predicates.
|
|
|
|
*
|
2005-08-02 04:09:52 +01:00
|
|
|
* Revision 1.166 2005/08/01 15:40:37 ricroc
|
|
|
|
* TABLING NEW: better support for incomplete tabling
|
|
|
|
*
|
2005-08-01 16:40:39 +01:00
|
|
|
* Revision 1.165 2005/07/06 19:33:52 ricroc
|
|
|
|
* TABLING: answers for completed calls can now be obtained by loading (new option) or executing (default) them from the trie data structure.
|
|
|
|
*
|
2005-07-06 20:34:12 +01:00
|
|
|
* Revision 1.164 2005/07/06 15:10:03 vsc
|
|
|
|
* improvements to compiler: merged instructions and fixes for ->
|
|
|
|
*
|
2005-07-06 16:10:18 +01:00
|
|
|
* Revision 1.163 2005/06/08 00:35:27 vsc
|
|
|
|
* fix silly calls such as 0.15 ( bug reported by Jude Shavlik)
|
|
|
|
*
|
2005-06-08 01:35:27 +01:00
|
|
|
* Revision 1.162 2005/06/04 07:27:33 ricroc
|
|
|
|
* long int support for tabling
|
|
|
|
*
|
2005-06-04 08:28:24 +01:00
|
|
|
* Revision 1.161 2005/06/03 08:26:32 ricroc
|
|
|
|
* float support for tabling
|
|
|
|
*
|
2005-06-03 09:26:32 +01:00
|
|
|
* Revision 1.160 2005/06/01 14:02:47 vsc
|
|
|
|
* get_rid of try_me?, retry_me? and trust_me? instructions: they are not
|
|
|
|
* significantly used nowadays.
|
|
|
|
*
|
2005-06-01 15:02:52 +01:00
|
|
|
* Revision 1.159 2005/05/31 19:42:27 vsc
|
|
|
|
* insert some more slack for indices in LU
|
|
|
|
* Use doubly linked list for LU indices so that updating is less cumbersome.
|
|
|
|
*
|
2005-05-31 20:42:28 +01:00
|
|
|
* Revision 1.158 2005/05/31 00:30:23 ricroc
|
|
|
|
* remove abort_yapor function
|
|
|
|
*
|
2005-05-31 01:32:02 +01:00
|
|
|
* Revision 1.157 2005/05/12 03:36:32 vsc
|
|
|
|
* debugger was making predicates meta instead of testing
|
|
|
|
* fix handling of dbrefs in facts and in subarguments.
|
|
|
|
*
|
2005-05-12 04:36:33 +01:00
|
|
|
* Revision 1.156 2005/04/20 04:02:15 vsc
|
|
|
|
* fix a few variable warnings
|
|
|
|
* fix erase clause to pass a pointer to clause, not code
|
|
|
|
* get rid of Yap4.4 code in Yap_EraseStaticClause
|
|
|
|
*
|
2005-04-20 05:02:30 +01:00
|
|
|
* Revision 1.155 2005/04/10 04:01:10 vsc
|
|
|
|
* bug fixes, I hope!
|
|
|
|
*
|
2005-04-10 05:01:15 +01:00
|
|
|
* Revision 1.154 2005/03/04 20:30:11 ricroc
|
|
|
|
* bug fixes for YapTab support
|
|
|
|
*
|
2005-03-04 20:30:14 +00:00
|
|
|
* Revision 1.153 2005/02/25 03:39:44 vsc
|
|
|
|
* fix fixes to undefp
|
|
|
|
* fix bug where clause mistook cp for ap
|
|
|
|
*
|
2005-02-25 03:39:45 +00:00
|
|
|
* Revision 1.152 2005/02/08 18:04:57 vsc
|
|
|
|
* library_directory may not be deterministic (usually it isn't).
|
|
|
|
*
|
2005-02-08 18:05:21 +00:00
|
|
|
* Revision 1.151 2005/02/08 04:05:23 vsc
|
|
|
|
* fix mess with add clause
|
|
|
|
* improves on sigsegv handling
|
|
|
|
*
|
2005-02-08 04:05:39 +00:00
|
|
|
* Revision 1.150 2005/01/28 23:14:34 vsc
|
|
|
|
* move to Yap-4.5.7
|
|
|
|
* Fix clause size
|
|
|
|
*
|
2005-01-28 23:14:41 +00:00
|
|
|
* Revision 1.149 2005/01/05 05:35:01 vsc
|
|
|
|
* get rid of debugging stub.
|
|
|
|
*
|
2005-01-05 05:35:01 +00:00
|
|
|
* Revision 1.148 2005/01/04 02:50:21 vsc
|
|
|
|
* - allow MegaClauses with blobs
|
|
|
|
* - change Diffs to be thread specific
|
|
|
|
* - include Christian's updates
|
|
|
|
*
|
2005-01-04 02:50:23 +00:00
|
|
|
* Revision 1.147 2004/12/28 22:20:35 vsc
|
|
|
|
* some extra bug fixes for trail overflows: some cannot be recovered that easily,
|
|
|
|
* some can.
|
|
|
|
*
|
2004-12-28 22:20:37 +00:00
|
|
|
* Revision 1.146 2004/12/20 21:44:57 vsc
|
|
|
|
* more fixes to CLPBN
|
|
|
|
* fix some Yap overflows.
|
|
|
|
*
|
2004-12-20 21:44:58 +00:00
|
|
|
* Revision 1.145 2004/12/16 05:57:23 vsc
|
|
|
|
* fix overflows
|
|
|
|
*
|
2004-12-16 05:57:32 +00:00
|
|
|
* Revision 1.144 2004/12/08 00:10:48 vsc
|
|
|
|
* more grow fixes
|
|
|
|
*
|
2004-12-08 00:10:48 +00:00
|
|
|
* Revision 1.143 2004/12/05 05:01:23 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.142 2004/11/18 22:32:31 vsc
|
|
|
|
* fix situation where we might assume nonextsing double initialisation of C predicates (use
|
|
|
|
* Hidden Pred Flag).
|
|
|
|
* $host_type was double initialised.
|
|
|
|
*
|
2004-11-18 22:32:40 +00:00
|
|
|
* Revision 1.141 2004/11/04 18:22:31 vsc
|
|
|
|
* don't ever use memory that has been freed (that was done by LU).
|
|
|
|
* generic fixes for WIN32 libraries
|
|
|
|
*
|
2004-11-04 18:22:36 +00:00
|
|
|
* Revision 1.140 2004/10/31 02:18:03 vsc
|
|
|
|
* fix bug in handling Yap heap overflow while adding new clause.
|
|
|
|
*
|
2004-10-31 02:18:04 +00:00
|
|
|
* Revision 1.139 2004/10/28 20:12:21 vsc
|
|
|
|
* Use Doug Lea's malloc as an alternative to YAP's standard malloc
|
|
|
|
* don't use TR directly in scanner/parser, this avoids trouble with ^C while
|
|
|
|
* consulting large files.
|
|
|
|
* pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should
|
|
|
|
* compile out of the box now).
|
|
|
|
*
|
2004-10-28 21:12:23 +01:00
|
|
|
* Revision 1.138 2004/10/26 20:15:51 vsc
|
|
|
|
* More bug fixes for overflow handling
|
|
|
|
*
|
2004-10-26 21:16:18 +01:00
|
|
|
* Revision 1.137 2004/10/22 16:53:19 vsc
|
|
|
|
* bug fixes
|
|
|
|
*
|
2004-10-22 17:53:20 +01:00
|
|
|
* Revision 1.136 2004/10/06 16:55:46 vsc
|
|
|
|
* change configure to support big mem configs
|
|
|
|
* get rid of extra globals
|
|
|
|
* fix trouble with multifile preds
|
|
|
|
*
|
2004-10-06 17:55:48 +01:00
|
|
|
* Revision 1.135 2004/09/30 21:37:40 vsc
|
|
|
|
* fixes for thread support
|
|
|
|
*
|
2004-09-30 22:37:41 +01:00
|
|
|
* Revision 1.134 2004/09/30 19:51:53 vsc
|
|
|
|
* fix overflow from within clause/2
|
|
|
|
*
|
2004-09-30 20:51:54 +01:00
|
|
|
* Revision 1.133 2004/09/27 20:45:02 vsc
|
|
|
|
* Mega clauses
|
|
|
|
* Fixes to sizeof(expand_clauses) which was being overestimated
|
|
|
|
* Fixes to profiling+indexing
|
|
|
|
* Fixes to reallocation of memory after restoring
|
|
|
|
* Make sure all clauses, even for C, end in _Ystop
|
|
|
|
* Don't reuse space for Streams
|
|
|
|
* Fix Stream_F on StreaNo+1
|
|
|
|
*
|
2004-09-27 21:45:04 +01:00
|
|
|
* Revision 1.132 2004/09/17 19:34:51 vsc
|
|
|
|
* simplify frozen/2
|
|
|
|
*
|
2004-09-17 20:34:53 +01:00
|
|
|
* Revision 1.131 2004/09/08 17:56:45 vsc
|
|
|
|
* source: a(X) :- true is a fact!
|
|
|
|
* fix use of value after possible overflow in IPred
|
|
|
|
*
|
2004-09-08 18:56:48 +01:00
|
|
|
* Revision 1.130 2004/09/07 16:48:04 vsc
|
|
|
|
* fix bug in unwinding trail at amiops.h
|
|
|
|
*
|
2004-09-07 17:48:04 +01:00
|
|
|
* Revision 1.129 2004/09/07 16:25:22 vsc
|
|
|
|
* memory management bug fixes
|
|
|
|
*
|
2004-09-07 17:25:22 +01:00
|
|
|
* Revision 1.128 2004/09/03 03:11:07 vsc
|
|
|
|
* memory management fixes
|
|
|
|
*
|
2004-09-03 04:11:09 +01:00
|
|
|
* Revision 1.127 2004/08/16 21:02:04 vsc
|
|
|
|
* more fixes for !
|
|
|
|
*
|
2004-08-16 22:02:04 +01:00
|
|
|
* Revision 1.126 2004/07/22 21:32:20 vsc
|
|
|
|
* debugger fixes
|
|
|
|
* initial support for JPL
|
|
|
|
* bad calls to garbage collector and gc
|
|
|
|
* debugger fixes
|
|
|
|
*
|
2004-07-22 22:32:23 +01:00
|
|
|
* Revision 1.125 2004/06/29 19:04:41 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.124 2004/06/05 03:36:59 vsc
|
|
|
|
* coroutining is now a part of attvars.
|
|
|
|
* some more fixes.
|
|
|
|
*
|
2004-06-05 04:37:01 +01:00
|
|
|
* Revision 1.123 2004/05/17 21:42:09 vsc
|
|
|
|
* misc fixes
|
|
|
|
*
|
2004-05-17 22:42:12 +01:00
|
|
|
* Revision 1.122 2004/05/13 21:36:45 vsc
|
|
|
|
* get rid of pesky debugging prints
|
|
|
|
*
|
2004-05-13 22:36:45 +01:00
|
|
|
* Revision 1.121 2004/05/13 20:54:57 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.120 2004/04/27 16:21:16 vsc
|
|
|
|
* stupid bug
|
|
|
|
*
|
2004-04-27 17:21:25 +01:00
|
|
|
* Revision 1.119 2004/04/27 15:03:43 vsc
|
|
|
|
* more fixes for expand_clauses
|
|
|
|
*
|
2004-04-27 16:03:43 +01:00
|
|
|
* Revision 1.118 2004/04/14 19:10:23 vsc
|
|
|
|
* expand_clauses: keep a list of clauses to expand
|
|
|
|
* fix new trail scheme for multi-assignment variables
|
|
|
|
*
|
2004-04-14 20:10:40 +01:00
|
|
|
* Revision 1.117 2004/04/07 22:04:03 vsc
|
|
|
|
* fix memory leaks
|
|
|
|
*
|
2004-04-07 23:04:04 +01:00
|
|
|
* Revision 1.116 2004/03/31 01:03:09 vsc
|
|
|
|
* support expand group of clauses
|
|
|
|
*
|
2004-03-31 02:03:10 +01:00
|
|
|
* Revision 1.115 2004/03/19 11:35:42 vsc
|
|
|
|
* trim_trail for default machine
|
|
|
|
* be more aggressive about try-retry-trust chains.
|
|
|
|
* - handle cases where block starts with a wait
|
|
|
|
* - don't use _killed instructions, just let the thing rot by itself.
|
|
|
|
*
|
2004-03-19 11:35:42 +00:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "clause.h"
|
|
|
|
#include "yapio.h"
|
|
|
|
#include "eval.h"
|
|
|
|
#include "tracer.h"
|
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
|
|
|
#endif /* YAPOR */
|
2006-03-20 19:51:44 +00:00
|
|
|
#ifdef TABLING
|
|
|
|
#include "tab.macros.h"
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-06-18 06:22:35 +01:00
|
|
|
STATIC_PROTO(void retract_all, (PredEntry *, int));
|
2002-12-27 16:53:09 +00:00
|
|
|
STATIC_PROTO(void add_first_static, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void add_first_dynamic, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void asserta_stat_clause, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void asserta_dynam_clause, (PredEntry *, yamop *));
|
|
|
|
STATIC_PROTO(void assertz_stat_clause, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void assertz_dynam_clause, (PredEntry *, yamop *));
|
2011-03-07 16:02:55 +00:00
|
|
|
STATIC_PROTO(void expand_consult, ( void ));
|
2001-12-12 19:36:51 +00:00
|
|
|
STATIC_PROTO(int not_was_reconsulted, (PredEntry *, Term, int));
|
2004-09-27 21:45:04 +01:00
|
|
|
STATIC_PROTO(int RemoveIndexation, (PredEntry *));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(int static_in_use, (PredEntry *, int));
|
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
|
|
|
STATIC_PROTO(Int search_for_static_predicate_in_use, (PredEntry *, int));
|
|
|
|
STATIC_PROTO(void mark_pred, (int, PredEntry *));
|
|
|
|
STATIC_PROTO(void do_toggle_static_predicates_in_use, (int));
|
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
STATIC_PROTO(Int p_number_of_clauses, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_compile, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_compile_dynamic, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_purge_clauses, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_setspy, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_rmspy, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_startconsult, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_showconslultlev, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_endconsult, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_undefined, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_in_use, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_new_multifile, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_is_multifile, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_optimizer_on, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_optimizer_off, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_is_dynamic, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_kill_dynamic, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_compile_mode, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_is_profiled, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_profile_info, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_profile_reset, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_is_call_counted, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_call_count_info, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_call_count_set, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_call_count_reset, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Int p_toggle_static_predicates_in_use, ( USES_REGS1 ));
|
|
|
|
STATIC_PROTO(Atom YapConsultingFile, ( USES_REGS1 ));
|
2004-02-12 12:37:12 +00:00
|
|
|
STATIC_PROTO(Int PredForCode,(yamop *, Atom *, UInt *, Term *));
|
2004-03-19 11:35:42 +00:00
|
|
|
STATIC_PROTO(void kill_first_log_iblock,(LogUpdIndex *, LogUpdIndex *, PredEntry *));
|
2006-03-24 16:26:31 +00:00
|
|
|
STATIC_PROTO(LogUpdIndex *find_owner_log_index,(LogUpdIndex *, yamop *));
|
|
|
|
STATIC_PROTO(StaticIndex *find_owner_static_index,(StaticIndex *, yamop *));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define PredArity(p) (p->ArityOfPE)
|
|
|
|
#define TRYCODE(G,F,N) ( (N)<5 ? (op_numbers)((int)F+(N)*3) : G)
|
|
|
|
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
|
|
|
|
|
2003-11-16 22:12:29 +00:00
|
|
|
#define IN_BLOCK(P,B,SZ) ((CODEADDR)(P) >= (CODEADDR)(B) && \
|
|
|
|
(CODEADDR)(P) < (CODEADDR)(B)+(SZ))
|
2002-12-27 16:53:09 +00:00
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
static PredEntry *
|
2004-10-26 21:16:18 +01:00
|
|
|
PredForChoicePt(yamop *p_code) {
|
2004-09-27 21:45:04 +01:00
|
|
|
while (TRUE) {
|
2008-08-26 01:08:52 +01:00
|
|
|
op_numbers opnum;
|
|
|
|
if (!p_code)
|
|
|
|
return NULL;
|
|
|
|
opnum = Yap_op_from_opcode(p_code->opc);
|
2004-09-27 21:45:04 +01:00
|
|
|
switch(opnum) {
|
|
|
|
case _Nstop:
|
|
|
|
return NULL;
|
2007-12-18 17:46:58 +00:00
|
|
|
case _jump:
|
|
|
|
p_code = p_code->u.l.l;
|
|
|
|
break;
|
2006-03-22 16:14:20 +00:00
|
|
|
case _retry_me:
|
|
|
|
case _trust_me:
|
2008-09-05 05:22:19 +01:00
|
|
|
return p_code->u.Otapl.p;
|
2006-10-10 15:08:17 +01:00
|
|
|
case _try_logical:
|
|
|
|
case _retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _profiled_trust_logical:
|
2008-09-05 05:22:19 +01:00
|
|
|
return p_code->u.OtaLl.d->ClPred;
|
2004-09-27 21:45:04 +01:00
|
|
|
#ifdef TABLING
|
|
|
|
case _trie_trust_var:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_var:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_var_in_pair:
|
|
|
|
case _trie_retry_var_in_pair:
|
2004-09-27 21:45:04 +01:00
|
|
|
case _trie_trust_val:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_val:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_val_in_pair:
|
|
|
|
case _trie_retry_val_in_pair:
|
2004-09-27 21:45:04 +01:00
|
|
|
case _trie_trust_atom:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_atom:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_atom_in_pair:
|
|
|
|
case _trie_retry_atom_in_pair:
|
|
|
|
case _trie_trust_null:
|
|
|
|
case _trie_retry_null:
|
|
|
|
case _trie_trust_null_in_pair:
|
|
|
|
case _trie_retry_null_in_pair:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_trust_pair:
|
|
|
|
case _trie_retry_pair:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_appl:
|
|
|
|
case _trie_retry_appl:
|
|
|
|
case _trie_trust_appl_in_pair:
|
|
|
|
case _trie_retry_appl_in_pair:
|
2005-07-06 20:34:12 +01:00
|
|
|
case _trie_trust_extension:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_extension:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_double:
|
|
|
|
case _trie_retry_double:
|
|
|
|
case _trie_trust_longint:
|
|
|
|
case _trie_retry_longint:
|
|
|
|
case _trie_trust_gterm:
|
|
|
|
case _trie_retry_gterm:
|
2004-09-27 21:45:04 +01:00
|
|
|
return NULL;
|
2005-08-01 16:40:39 +01:00
|
|
|
case _table_load_answer:
|
|
|
|
case _table_try_answer:
|
2004-09-27 21:45:04 +01:00
|
|
|
case _table_answer_resolution:
|
2005-07-06 20:34:12 +01:00
|
|
|
case _table_completion:
|
2011-12-22 16:50:20 +00:00
|
|
|
#ifdef THREADS_CONSUMER_SHARING
|
|
|
|
case _table_answer_resolution_completion:
|
|
|
|
#endif /* THREADS_CONSUMER_SHARING */
|
2005-03-04 20:30:14 +00:00
|
|
|
return NULL; /* ricroc: is this OK? */
|
|
|
|
/* compile error --> return ENV_ToP(gc_B->cp_cp); */
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* TABLING */
|
2004-09-27 21:45:04 +01:00
|
|
|
case _or_else:
|
2008-09-05 05:22:19 +01:00
|
|
|
if (p_code == p_code->u.Osblp.l) {
|
2004-09-27 21:45:04 +01:00
|
|
|
/* repeat */
|
2008-12-23 01:53:52 +00:00
|
|
|
Atom at = AtomRepeatSpace;
|
2004-09-27 21:45:04 +01:00
|
|
|
return RepPredProp(PredPropByAtom(at, PROLOG_MODULE));
|
2004-12-08 00:10:48 +00:00
|
|
|
} else {
|
2008-09-05 05:22:19 +01:00
|
|
|
return p_code->u.Osblp.p0;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2004-12-08 00:10:48 +00:00
|
|
|
break;
|
2004-09-27 21:45:04 +01:00
|
|
|
case _or_last:
|
|
|
|
#ifdef YAPOR
|
2008-09-05 05:22:19 +01:00
|
|
|
return p_code->u.Osblp.p0;
|
2004-10-26 21:16:18 +01:00
|
|
|
#else
|
|
|
|
return p_code->u.p.p;
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* YAPOR */
|
2004-09-27 21:45:04 +01:00
|
|
|
break;
|
|
|
|
case _count_retry_me:
|
|
|
|
case _retry_profiled:
|
|
|
|
case _retry2:
|
|
|
|
case _retry3:
|
|
|
|
case _retry4:
|
|
|
|
p_code = NEXTOP(p_code,l);
|
|
|
|
break;
|
|
|
|
default:
|
2008-09-05 05:22:19 +01:00
|
|
|
return p_code->u.Otapl.p;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PredEntry *
|
|
|
|
Yap_PredForChoicePt(choiceptr cp) {
|
2004-10-26 21:16:18 +01:00
|
|
|
if (cp == NULL)
|
|
|
|
return NULL;
|
|
|
|
return PredForChoicePt(cp->cp_ap);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 22:12:42 +00:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
InitConsultStack( void )
|
2010-03-21 22:12:42 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultLow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
|
|
|
if (LOCAL_ConsultLow == NULL) {
|
2010-03-21 22:12:42 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
|
|
|
return;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity = InitialConsultCapacity;
|
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp =
|
|
|
|
LOCAL_ConsultLow + LOCAL_ConsultCapacity;
|
2010-03-21 22:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-03-07 16:02:55 +00:00
|
|
|
Yap_ResetConsultStack( void )
|
2010-03-21 22:12:42 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_FreeCodeSpace((char *)LOCAL_ConsultLow);
|
|
|
|
LOCAL_ConsultBase =
|
|
|
|
LOCAL_ConsultSp =
|
|
|
|
LOCAL_ConsultLow =
|
2010-03-21 22:12:42 +00:00
|
|
|
NULL;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity = InitialConsultCapacity;
|
2010-03-21 22:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
EXECUTING PROLOG CLAUSES
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static_in_use(PredEntry *p, int check_everything)
|
|
|
|
{
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2006-03-24 16:26:31 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
|
|
|
CELL pflags = p->PredFlags;
|
|
|
|
if (pflags & (DynamicPredFlag|LogUpdatePredFlag)) {
|
2008-01-23 17:57:56 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (STATIC_PREDICATES_MARKED) {
|
2003-04-30 18:46:05 +01:00
|
|
|
return (p->PredFlags & InUsePredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* This code does not work for YAPOR or THREADS!!!!!!!! */
|
2002-02-26 20:16:36 +00:00
|
|
|
return(search_for_static_predicate_in_use(p, check_everything));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
ADDING AND REMOVE INFO TO A PROCEDURE
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have three kinds of predicates: dynamic DynamicPredFlag
|
|
|
|
* static CompiledPredFlag fast FastPredFlag all the
|
|
|
|
* database predicates are supported for dynamic predicates only abolish and
|
|
|
|
* assertz are supported for static predicates no database predicates are
|
|
|
|
* supportted for fast predicates
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define is_dynamic(pe) (pe->PredFlags & DynamicPredFlag)
|
|
|
|
#define is_static(pe) (pe->PredFlags & CompiledPredFlag)
|
|
|
|
#define is_logupd(pe) (pe->PredFlags & LogUpdatePredFlag)
|
|
|
|
#ifdef TABLING
|
|
|
|
#define is_tabled(pe) (pe->PredFlags & TabledPredFlag)
|
|
|
|
#endif /* TABLING */
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
static PredEntry *
|
|
|
|
get_pred(Term t, Term tmod, char *pname)
|
|
|
|
{
|
|
|
|
Term t0 = t;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
if (IsVarTerm(t)) {
|
2009-11-18 13:13:16 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t0, pname);
|
2007-11-26 23:43:10 +00:00
|
|
|
return NULL;
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
return RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod));
|
2008-09-15 04:30:09 +01:00
|
|
|
} else if (IsIntegerTerm(t) && tmod == IDB_MODULE) {
|
|
|
|
return Yap_FindLUIntKey(IntegerOfTerm(t));
|
2007-11-26 23:43:10 +00:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2009-11-18 13:13:16 +00:00
|
|
|
if (IsExtensionFunctor(fun)) {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, t0, pname);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
if (fun == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1, t);
|
|
|
|
if (IsVarTerm(tmod) ) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t0, pname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(tmod) ) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t0, pname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
t = ArgOfTerm(2, t);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
return RepPredProp(Yap_GetPredPropByFunc(fun, tmod));
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
Mega Clauses
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
2008-09-05 05:22:19 +01:00
|
|
|
#define OrArgAdjust(P)
|
|
|
|
#define TabEntryAdjust(P)
|
2008-08-29 17:27:11 +01:00
|
|
|
#define DoubleInCodeAdjust(D)
|
|
|
|
#define IntegerInCodeAdjust(D)
|
|
|
|
#define IntegerAdjust(D) (D)
|
2005-01-04 02:50:23 +00:00
|
|
|
#define PtoPredAdjust(X) (X)
|
|
|
|
#define PtoOpAdjust(X) (X)
|
2006-10-10 15:08:17 +01:00
|
|
|
#define PtoLUClauseAdjust(P) (P)
|
2006-11-27 17:42:03 +00:00
|
|
|
#define PtoLUIndexAdjust(P) (P)
|
2005-01-04 02:50:23 +00:00
|
|
|
#define XAdjust(X) (X)
|
|
|
|
#define YAdjust(X) (X)
|
|
|
|
#define AtomTermAdjust(X) (X)
|
|
|
|
#define CellPtoHeapAdjust(X) (X)
|
|
|
|
#define FuncAdjust(X) (X)
|
|
|
|
#define CodeAddrAdjust(X) (X)
|
2008-04-01 09:42:46 +01:00
|
|
|
#define CodeComposedTermAdjust(X) (X)
|
2008-08-29 17:27:11 +01:00
|
|
|
#define ConstantAdjust(X) (X)
|
|
|
|
#define ArityAdjust(X) (X)
|
|
|
|
#define OpcodeAdjust(X) (X)
|
|
|
|
#define ModuleAdjust(X) (X)
|
|
|
|
#define ExternalFunctionAdjust(X) (X)
|
|
|
|
#define AdjustSwitchTable(X,Y,Z)
|
2010-12-16 20:39:53 +00:00
|
|
|
#define DBGroundTermAdjust(X) (X)
|
2005-01-04 02:50:23 +00:00
|
|
|
#define rehash(A,B,C)
|
2010-12-16 20:39:53 +00:00
|
|
|
|
|
|
|
static Term BlobTermInCodeAdjust(Term t)
|
2005-01-04 02:50:23 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2005-01-04 02:50:23 +00:00
|
|
|
#if TAGS_FAST_OPS
|
2011-05-04 10:11:41 +01:00
|
|
|
return t-LOCAL_ClDiff;
|
2005-01-04 02:50:23 +00:00
|
|
|
#else
|
2011-05-04 10:11:41 +01:00
|
|
|
return t+LOCAL_ClDiff;
|
2005-01-04 02:50:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-29 17:27:11 +01:00
|
|
|
static Term
|
|
|
|
ConstantTermAdjust (Term t)
|
|
|
|
{
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
return AtomTermAdjust(t);
|
2010-12-16 20:39:53 +00:00
|
|
|
return t;
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-04 02:50:23 +00:00
|
|
|
#include "rclause.h"
|
|
|
|
|
2006-09-20 21:03:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
static UInt total_megaclause, total_released, nof_megaclauses;
|
|
|
|
#endif
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
void
|
|
|
|
Yap_BuildMegaClause(PredEntry *ap)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2004-09-27 21:45:04 +01:00
|
|
|
StaticClause *cl;
|
|
|
|
UInt sz;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
2012-12-14 19:35:26 +00:00
|
|
|
size_t required;
|
2004-09-27 21:45:04 +01:00
|
|
|
UInt has_blobs = 0;
|
|
|
|
|
|
|
|
if (ap->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MegaClausePredFlag
|
|
|
|
#ifdef TABLING
|
|
|
|
|TabledPredFlag
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* TABLING */
|
2009-02-20 11:42:48 +00:00
|
|
|
|UDIPredFlag) ||
|
2004-09-27 21:45:04 +01:00
|
|
|
ap->cs.p_code.FirstClause == NULL ||
|
|
|
|
ap->cs.p_code.NOfClauses < 16) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cl =
|
|
|
|
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
|
|
|
sz = cl->ClSize;
|
|
|
|
while (TRUE) {
|
|
|
|
if (!(cl->ClFlags & FactMask)) return; /* no mega clause, sorry */
|
|
|
|
if (cl->ClSize != sz) return; /* no mega clause, sorry */
|
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
has_blobs |= (cl->ClFlags & HasBlobsMask);
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
/* ok, we got the chance for a mega clause */
|
|
|
|
if (has_blobs) {
|
|
|
|
sz -= sizeof(StaticClause);
|
2005-01-04 02:50:23 +00:00
|
|
|
} else {
|
2005-12-17 03:25:39 +00:00
|
|
|
sz -= (UInt)NEXTOP((yamop *)NULL,p) + sizeof(StaticClause);
|
2005-01-04 02:50:23 +00:00
|
|
|
}
|
2005-12-17 03:25:39 +00:00
|
|
|
required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l);
|
2012-12-14 19:35:26 +00:00
|
|
|
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
|
|
|
if (!Yap_growheap(FALSE, required, NULL)) {
|
|
|
|
/* just fail, the system will keep on going */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-09-20 21:03:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
total_megaclause += required;
|
2011-09-01 05:13:29 +01:00
|
|
|
cl =
|
|
|
|
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
|
|
|
total_released += ap->cs.p_code.NOfClauses*cl->ClSize;
|
2006-09-20 21:03:51 +01:00
|
|
|
nof_megaclauses++;
|
|
|
|
#endif
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += required;
|
2004-09-27 21:45:04 +01:00
|
|
|
/* cool, it's our turn to do the conversion */
|
|
|
|
mcl->ClFlags = MegaMask | has_blobs;
|
2011-09-01 05:13:29 +01:00
|
|
|
mcl->ClSize = required;
|
2004-09-27 21:45:04 +01:00
|
|
|
mcl->ClPred = ap;
|
|
|
|
mcl->ClItemSize = sz;
|
2006-03-22 20:07:28 +00:00
|
|
|
mcl->ClNext = NULL;
|
2004-09-27 21:45:04 +01:00
|
|
|
cl =
|
|
|
|
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
|
|
|
ptr = mcl->ClCode;
|
|
|
|
while (TRUE) {
|
|
|
|
memcpy((void *)ptr, (void *)cl->ClCode, sz);
|
2005-01-04 02:50:23 +00:00
|
|
|
if (has_blobs) {
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ClDiff = (char *)(ptr)-(char *)cl->ClCode;
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(ptr, NULL PASS_REGS);
|
2005-01-04 02:50:23 +00:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
ptr = (yamop *)((char *)ptr + sz);
|
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
ptr->opc = Yap_opcode(_Ystop);
|
|
|
|
cl =
|
|
|
|
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
|
|
|
/* recover the space spent on the original clauses */
|
|
|
|
while (TRUE) {
|
2005-12-23 00:20:14 +00:00
|
|
|
StaticClause *ncl, *curcl = cl;
|
2004-09-27 21:45:04 +01:00
|
|
|
|
|
|
|
ncl = cl->ClNext;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)cl);
|
2005-12-23 00:20:14 +00:00
|
|
|
if (curcl->ClCode == ap->cs.p_code.LastClause)
|
2004-09-27 21:45:04 +01:00
|
|
|
break;
|
|
|
|
cl = ncl;
|
|
|
|
}
|
|
|
|
ap->cs.p_code.FirstClause =
|
|
|
|
ap->cs.p_code.LastClause =
|
|
|
|
mcl->ClCode;
|
|
|
|
ap->PredFlags |= MegaClausePredFlag;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(mcl, (char *)mcl+required, ap, GPROF_MEGA);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
split_megaclause(PredEntry *ap)
|
|
|
|
{
|
|
|
|
StaticClause *start = NULL, *prev = NULL;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
|
|
|
UInt ncls = ap->cs.p_code.NOfClauses, i;
|
|
|
|
|
|
|
|
RemoveIndexation(ap);
|
|
|
|
mcl =
|
|
|
|
ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
|
|
|
|
for (i = 0, ptr = mcl->ClCode; i < ncls; i++) {
|
2009-09-12 22:43:44 +01:00
|
|
|
StaticClause *new = (StaticClause *)Yap_AllocCodeSpace(sizeof(StaticClause)+mcl->ClItemSize+(UInt)NEXTOP((yamop *)NULL,p));
|
2004-09-27 21:45:04 +01:00
|
|
|
if (new == NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, (sizeof(StaticClause)+mcl->ClItemSize)*(ncls-i), NULL)) {
|
|
|
|
while (start) {
|
|
|
|
StaticClause *cl = start;
|
|
|
|
start = cl->ClNext;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
if (ap->ArityOfPE) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while breaking up mega clause for %s/%d\n",RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE,ap->ArityOfPE);
|
|
|
|
} else {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while breaking up mega clause for %s\n", RepAtom((Atom)ap->FunctorOfPred)->StrOfAE);
|
|
|
|
}
|
2004-10-22 17:53:20 +01:00
|
|
|
return;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2010-12-31 05:37:25 +00:00
|
|
|
break;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2009-09-12 22:43:44 +01:00
|
|
|
Yap_ClauseSpace += sizeof(StaticClause)+mcl->ClItemSize+(UInt)NEXTOP((yamop *)NULL,p);
|
2008-03-31 23:56:22 +01:00
|
|
|
new->ClFlags = StaticMask|FactMask;
|
2004-10-22 17:53:20 +01:00
|
|
|
new->ClSize = mcl->ClItemSize;
|
|
|
|
new->usc.ClPred = ap;
|
|
|
|
new->ClNext = NULL;
|
|
|
|
memcpy((void *)new->ClCode, (void *)ptr, mcl->ClItemSize);
|
|
|
|
if (prev) {
|
|
|
|
prev->ClNext = new;
|
|
|
|
} else {
|
|
|
|
start = new;
|
|
|
|
}
|
|
|
|
ptr = (yamop *)((char *)ptr + mcl->ClItemSize);
|
|
|
|
prev = new;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
ap->PredFlags &= ~MegaClausePredFlag;
|
|
|
|
ap->cs.p_code.FirstClause = start->ClCode;
|
|
|
|
ap->cs.p_code.LastClause = prev->ClCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
Indexation Info
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
#define ByteAdr(X) ((Int) &(X))
|
|
|
|
|
|
|
|
/* Index a prolog pred, given its predicate entry */
|
2003-12-01 17:27:42 +00:00
|
|
|
/* ap is already locked. */
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(PredEntry *ap, UInt NSlots, yamop *next_pc)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-03-07 16:34:20 +00:00
|
|
|
CACHE_REGS
|
2011-05-25 16:40:36 +01:00
|
|
|
if (GLOBAL_Option['i' - 'a' + 1]) {
|
2004-02-12 12:37:12 +00:00
|
|
|
Term tmod = ap->ModuleOfPred;
|
|
|
|
if (!tmod)
|
|
|
|
tmod = TermProlog;
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,'\t');
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(tmod);
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,':');
|
2004-02-12 12:37:12 +00:00
|
|
|
if (ap->ModuleOfPred == IDB_MODULE) {
|
2003-08-27 14:37:10 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
if (IsAtomTerm(t)) {
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(t);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else if (IsIntegerTerm(t)) {
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(t);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
Atom At = NameOfFunctor(f);
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,'/');
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(MkIntTerm(ArityOfFunctor(f)));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ap->ArityOfPE == 0) {
|
|
|
|
Atom At = (Atom)ap->FunctorOfPred;
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
|
|
|
Functor f = ap->FunctorOfPred;
|
|
|
|
Atom At = NameOfFunctor(f);
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,'/');
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(MkIntTerm(ArityOfFunctor(f)));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,'\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Do not try to index a dynamic predicate or one whithout args */
|
|
|
|
if (is_dynamic(ap)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"trying to index a dynamic predicate");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-29 15:21:00 +00:00
|
|
|
if ((BaseAddr = Yap_PredIsIndexable(ap, NSlots, next_pc)) != NULL) {
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
ap->PredFlags |= IndexedPredFlag;
|
|
|
|
}
|
2009-06-22 17:12:56 +01:00
|
|
|
if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
} else if (ap->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->OpcodeOfPred = ap->CodeOfPred->opc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2011-05-25 16:40:36 +01:00
|
|
|
if (GLOBAL_Option['i' - 'a' + 1])
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_DebugPutc(LOCAL_c_error_stream,'\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2010-01-29 15:21:00 +00:00
|
|
|
Yap_IPred(PredEntry *p, UInt NSlots, yamop *next_pc)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(p, NSlots, next_pc);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define GONEXT(TYPE) code_p = ((yamop *)(&(code_p->u.TYPE.next)))
|
|
|
|
|
|
|
|
static void
|
2003-08-27 14:37:10 +01:00
|
|
|
RemoveMainIndex(PredEntry *ap)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *First = ap->cs.p_code.FirstClause;
|
2009-06-22 17:12:56 +01:00
|
|
|
int spied = ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2003-10-14 01:53:10 +01:00
|
|
|
ap->PredFlags &= ~IndexedPredFlag;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (First == NULL) {
|
|
|
|
ap->cs.p_code.TrueCodeOfPred = FAILCODE;
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = First;
|
|
|
|
}
|
|
|
|
if (First != NULL && spied) {
|
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2009-06-24 05:24:16 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2003-12-18 16:38:40 +00:00
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1
|
|
|
|
#ifdef TABLING
|
|
|
|
||ap->PredFlags & TabledPredFlag
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* TABLING */
|
2003-12-18 16:38:40 +00:00
|
|
|
) {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->OpcodeOfPred = ap->cs.p_code.TrueCodeOfPred->opc;
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
|
|
|
decrease_ref_counter(yamop *ptr, yamop *b, yamop *e, yamop *sc)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ptr != FAILCODE && ptr != sc && (ptr < b || ptr > e)) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(ptr);
|
|
|
|
cl->ClRefCount--;
|
2003-11-12 12:33:31 +00:00
|
|
|
if (cl->ClFlags & ErasedMask &&
|
|
|
|
!(cl->ClRefCount) &&
|
|
|
|
!(cl->ClFlags & InUseMask)) {
|
|
|
|
/* last ref to the clause */
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
static yamop *
|
2004-04-27 16:03:43 +01:00
|
|
|
release_wcls(yamop *cop, OPCODE ecs)
|
|
|
|
{
|
|
|
|
if (cop->opc == ecs) {
|
2008-08-21 13:38:25 +01:00
|
|
|
cop->u.sssllp.s3--;
|
|
|
|
if (!cop->u.sssllp.s3) {
|
|
|
|
UInt sz = (UInt)NEXTOP((yamop *)NULL,sssllp)+cop->u.sssllp.s1*sizeof(yamop *);
|
2008-01-23 17:57:56 +00:00
|
|
|
LOCK(ExpandClausesListLock);
|
|
|
|
#ifdef DEBUG
|
|
|
|
Yap_expand_clauses_sz -= sz;
|
|
|
|
Yap_ExpandClauses--;
|
2004-09-03 04:11:09 +01:00
|
|
|
#endif
|
2008-08-21 13:38:25 +01:00
|
|
|
if (cop->u.sssllp.p->PredFlags & LogUpdatePredFlag) {
|
2008-01-23 17:57:56 +00:00
|
|
|
Yap_LUIndexSpace_EXT -= sz;
|
2006-11-06 18:35:05 +00:00
|
|
|
} else {
|
2008-01-23 17:57:56 +00:00
|
|
|
Yap_IndexSpace_EXT -= sz;
|
|
|
|
}
|
|
|
|
if (ExpandClausesFirst == cop)
|
2008-08-21 13:38:25 +01:00
|
|
|
ExpandClausesFirst = cop->u.sssllp.snext;
|
2008-01-23 17:57:56 +00:00
|
|
|
if (ExpandClausesLast == cop) {
|
2008-08-21 13:38:25 +01:00
|
|
|
ExpandClausesLast = cop->u.sssllp.sprev;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
2008-08-21 13:38:25 +01:00
|
|
|
if (cop->u.sssllp.sprev) {
|
|
|
|
cop->u.sssllp.sprev->u.sssllp.snext = cop->u.sssllp.snext;
|
2006-11-06 18:35:05 +00:00
|
|
|
}
|
2008-08-21 13:38:25 +01:00
|
|
|
if (cop->u.sssllp.snext) {
|
|
|
|
cop->u.sssllp.snext->u.sssllp.sprev = cop->u.sssllp.sprev;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
|
|
|
UNLOCK(ExpandClausesListLock);
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cop);
|
2004-04-27 16:03:43 +01:00
|
|
|
Yap_FreeCodeSpace((char *)cop);
|
|
|
|
}
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
return FAILCODE;
|
2004-04-27 16:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2003-11-12 12:33:31 +00:00
|
|
|
cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-04-27 16:03:43 +01:00
|
|
|
OPCODE ecs = Yap_opcode(_expand_clauses);
|
|
|
|
|
2006-10-11 15:53:57 +01:00
|
|
|
while (ipc) {
|
2003-08-27 14:37:10 +01:00
|
|
|
op_numbers op = Yap_op_from_opcode(ipc->opc);
|
2006-10-16 18:12:48 +01:00
|
|
|
/* fprintf(stderr,"op: %d %p->%p\n", op, ipc, end);*/
|
2003-08-27 14:37:10 +01:00
|
|
|
switch(op) {
|
|
|
|
case _Ystop:
|
|
|
|
/* end of clause, for now */
|
|
|
|
return;
|
|
|
|
case _index_dbref:
|
|
|
|
case _index_blob:
|
2009-02-09 21:56:40 +00:00
|
|
|
case _index_long:
|
2003-08-27 14:37:10 +01:00
|
|
|
ipc = NEXTOP(ipc,e);
|
|
|
|
break;
|
2004-02-05 16:57:02 +00:00
|
|
|
case _lock_lu:
|
2004-02-09 14:19:05 +00:00
|
|
|
case _unlock_lu:
|
2008-01-23 17:57:56 +00:00
|
|
|
/* locking should be done already */
|
2004-02-09 14:19:05 +00:00
|
|
|
ipc = NEXTOP(ipc,e);
|
2003-08-27 14:37:10 +01:00
|
|
|
case _retry_profiled:
|
|
|
|
case _count_retry:
|
2003-10-28 16:20:44 +00:00
|
|
|
ipc = NEXTOP(ipc,p);
|
|
|
|
break;
|
2004-09-27 21:45:04 +01:00
|
|
|
case _try_clause2:
|
|
|
|
case _try_clause3:
|
|
|
|
case _try_clause4:
|
|
|
|
ipc = NEXTOP(ipc,l);
|
|
|
|
break;
|
|
|
|
case _retry2:
|
|
|
|
case _retry3:
|
|
|
|
case _retry4:
|
|
|
|
decrease_ref_counter(ipc->u.l.l, beg, end, suspend_code);
|
|
|
|
ipc = NEXTOP(ipc,l);
|
|
|
|
break;
|
2003-10-28 16:20:44 +00:00
|
|
|
case _retry:
|
2003-08-27 14:37:10 +01:00
|
|
|
case _trust:
|
2008-09-05 05:22:19 +01:00
|
|
|
decrease_ref_counter(ipc->u.Otapl.d, beg, end, suspend_code);
|
|
|
|
ipc = NEXTOP(ipc,Otapl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _try_clause:
|
|
|
|
case _try_me:
|
|
|
|
case _retry_me:
|
|
|
|
case _profiled_trust_me:
|
|
|
|
case _trust_me:
|
|
|
|
case _count_trust_me:
|
2008-09-05 05:22:19 +01:00
|
|
|
ipc = NEXTOP(ipc,Otapl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2006-10-10 15:08:17 +01:00
|
|
|
case _try_logical:
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
{
|
|
|
|
yamop *oipc = ipc;
|
2008-09-05 05:22:19 +01:00
|
|
|
decrease_ref_counter(ipc->u.OtaLl.d->ClCode, beg, end, suspend_code);
|
|
|
|
ipc = ipc->u.OtaLl.n;
|
|
|
|
Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL,OtaLl);
|
2006-10-10 15:08:17 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)oipc);
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
Yap_DirtyCps--;
|
|
|
|
Yap_FreedCps++;
|
|
|
|
#endif
|
2006-10-10 15:08:17 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
Yap_DirtyCps--;
|
|
|
|
Yap_FreedCps++;
|
|
|
|
#endif
|
2008-09-05 05:22:19 +01:00
|
|
|
decrease_ref_counter(ipc->u.OtILl.d->ClCode, beg, end, suspend_code);
|
|
|
|
Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL,OtILl);
|
2006-10-10 15:08:17 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)ipc);
|
|
|
|
return;
|
2003-09-15 02:25:29 +01:00
|
|
|
case _enter_lu_pred:
|
2008-01-23 17:57:56 +00:00
|
|
|
{
|
|
|
|
yamop *oipc = ipc;
|
2011-06-24 21:08:22 +01:00
|
|
|
if (ipc->u.Illss.I->ClFlags & InUseMask || ipc->u.Illss.I->ClRefCount)
|
2008-01-23 17:57:56 +00:00
|
|
|
return;
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
2011-06-24 21:08:22 +01:00
|
|
|
Yap_DirtyCps+=ipc->u.Illss.s;
|
|
|
|
Yap_LiveCps-=ipc->u.Illss.s;
|
2006-10-11 15:53:57 +01:00
|
|
|
#endif
|
2011-06-24 21:08:22 +01:00
|
|
|
ipc = ipc->u.Illss.l1;
|
2008-01-23 17:57:56 +00:00
|
|
|
/* in case we visit again */
|
2011-06-24 21:08:22 +01:00
|
|
|
oipc->u.Illss.l1 = FAILCODE;
|
|
|
|
oipc->u.Illss.s = 0;
|
|
|
|
oipc->u.Illss.e = 0;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
2003-09-15 02:25:29 +01:00
|
|
|
break;
|
2003-08-27 14:37:10 +01:00
|
|
|
case _try_in:
|
|
|
|
case _jump:
|
|
|
|
case _jump_if_var:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.l.l = release_wcls(ipc->u.l.l, ecs);
|
2003-08-27 14:37:10 +01:00
|
|
|
ipc = NEXTOP(ipc,l);
|
|
|
|
break;
|
2003-10-28 01:16:03 +00:00
|
|
|
/* instructions type xl */
|
|
|
|
case _jump_if_nonvar:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.xll.l1 = release_wcls(ipc->u.xll.l1, ecs);
|
2005-04-10 05:01:15 +01:00
|
|
|
ipc = NEXTOP(ipc,xll);
|
2003-10-28 01:16:03 +00:00
|
|
|
break;
|
2009-02-12 21:35:31 +00:00
|
|
|
/* instructions type p */
|
|
|
|
case _user_switch:
|
2009-02-12 21:45:41 +00:00
|
|
|
ipc = NEXTOP(ipc,lp);
|
2009-02-12 21:35:31 +00:00
|
|
|
break;
|
2003-08-27 14:37:10 +01:00
|
|
|
/* instructions type e */
|
|
|
|
case _switch_on_type:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.llll.l1 = release_wcls(ipc->u.llll.l1, ecs);
|
|
|
|
ipc->u.llll.l2 = release_wcls(ipc->u.llll.l2, ecs);
|
|
|
|
ipc->u.llll.l3 = release_wcls(ipc->u.llll.l3, ecs);
|
|
|
|
ipc->u.llll.l4 = release_wcls(ipc->u.llll.l4, ecs);
|
2004-04-27 17:21:25 +01:00
|
|
|
ipc = NEXTOP(ipc,llll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_list_nl:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.ollll.l1 = release_wcls(ipc->u.ollll.l1, ecs);
|
|
|
|
ipc->u.ollll.l2 = release_wcls(ipc->u.ollll.l2, ecs);
|
|
|
|
ipc->u.ollll.l3 = release_wcls(ipc->u.ollll.l3, ecs);
|
|
|
|
ipc->u.ollll.l4 = release_wcls(ipc->u.ollll.l4, ecs);
|
2003-08-27 14:37:10 +01:00
|
|
|
ipc = NEXTOP(ipc,ollll);
|
|
|
|
break;
|
|
|
|
case _switch_on_arg_type:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.xllll.l1 = release_wcls(ipc->u.xllll.l1, ecs);
|
|
|
|
ipc->u.xllll.l2 = release_wcls(ipc->u.xllll.l2, ecs);
|
|
|
|
ipc->u.xllll.l3 = release_wcls(ipc->u.xllll.l3, ecs);
|
|
|
|
ipc->u.xllll.l4 = release_wcls(ipc->u.xllll.l4, ecs);
|
2003-08-27 14:37:10 +01:00
|
|
|
ipc = NEXTOP(ipc,xllll);
|
|
|
|
break;
|
|
|
|
case _switch_on_sub_arg_type:
|
2008-01-23 17:57:56 +00:00
|
|
|
ipc->u.sllll.l1 = release_wcls(ipc->u.sllll.l1, ecs);
|
|
|
|
ipc->u.sllll.l2 = release_wcls(ipc->u.sllll.l2, ecs);
|
|
|
|
ipc->u.sllll.l3 = release_wcls(ipc->u.sllll.l3, ecs);
|
|
|
|
ipc->u.sllll.l4 = release_wcls(ipc->u.sllll.l4, ecs);
|
2003-08-27 14:37:10 +01:00
|
|
|
ipc = NEXTOP(ipc,sllll);
|
|
|
|
break;
|
|
|
|
case _if_not_then:
|
2003-10-02 13:59:05 +01:00
|
|
|
ipc = NEXTOP(ipc,clll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_on_func:
|
|
|
|
case _if_func:
|
|
|
|
case _go_on_func:
|
|
|
|
case _switch_on_cons:
|
|
|
|
case _if_cons:
|
|
|
|
case _go_on_cons:
|
2011-02-04 01:23:01 +00:00
|
|
|
/* make sure we don't leave dangling references to memory that is going to be removed */
|
|
|
|
ipc->u.sssl.l = NULL;
|
2004-03-31 02:03:10 +01:00
|
|
|
ipc = NEXTOP(ipc,sssl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2008-01-23 17:57:56 +00:00
|
|
|
case _op_fail:
|
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
default:
|
2003-12-01 17:27:42 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"Bug in Indexing Code: opcode %d", op);
|
2004-09-27 21:45:04 +01:00
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
ipc = (yamop *)((CELL)ipc & ~1);
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
static void
|
|
|
|
decrease_log_indices(LogUpdIndex *c, yamop *suspend_code)
|
|
|
|
{
|
|
|
|
/* decrease all reference counters */
|
|
|
|
yamop *beg = c->ClCode, *end, *ipc;
|
2011-12-30 16:02:59 +00:00
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
if (c->ClFlags & SwitchTableMask) {
|
2004-03-31 02:03:10 +01:00
|
|
|
CELL *end = (CELL *)((char *)c+c->ClSize);
|
|
|
|
CELL *beg = (CELL *)(c->ClCode);
|
|
|
|
OPCODE ecs = Yap_opcode(_expand_clauses);
|
|
|
|
|
|
|
|
while (beg < end) {
|
2008-01-23 17:57:56 +00:00
|
|
|
yamop **x = (yamop **)(beg+1);
|
2004-03-31 02:03:10 +01:00
|
|
|
beg += 2;
|
2008-01-23 17:57:56 +00:00
|
|
|
*x = release_wcls(*x, ecs);
|
2004-03-31 02:03:10 +01:00
|
|
|
}
|
2003-11-12 12:33:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
end = (yamop *)((CODEADDR)c+c->ClSize);
|
2003-11-12 12:33:31 +00:00
|
|
|
ipc = beg;
|
|
|
|
cleanup_dangling_indices(ipc, beg, end, suspend_code);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
2006-03-22 20:07:28 +00:00
|
|
|
kill_static_child_indxs(StaticIndex *indx, int in_use)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
|
|
|
StaticIndex *cl = indx->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
StaticIndex *next = cl->SiblingIndex;
|
2006-03-22 20:07:28 +00:00
|
|
|
kill_static_child_indxs(cl, in_use);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = next;
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
if (in_use) {
|
|
|
|
LOCK(DeadStaticIndicesLock);
|
|
|
|
indx->SiblingIndex = DeadStaticIndices;
|
|
|
|
indx->ChildIndex = NULL;
|
|
|
|
DeadStaticIndices = indx;
|
|
|
|
UNLOCK(DeadStaticIndicesLock);
|
2006-03-22 16:14:20 +00:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(indx);
|
2006-11-06 18:35:05 +00:00
|
|
|
if (indx->ClFlags & SwitchTableMask)
|
|
|
|
Yap_IndexSpace_SW -= indx->ClSize;
|
|
|
|
else
|
|
|
|
Yap_IndexSpace_Tree -= indx->ClSize;
|
2006-03-22 16:14:20 +00:00
|
|
|
Yap_FreeCodeSpace((char *)indx);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2006-03-20 19:51:44 +00:00
|
|
|
static void
|
|
|
|
kill_children(LogUpdIndex *c, PredEntry *ap)
|
|
|
|
{
|
|
|
|
LogUpdIndex *ncl;
|
|
|
|
|
|
|
|
c->ClRefCount++;
|
|
|
|
ncl = c->ChildIndex;
|
|
|
|
/* kill children */
|
|
|
|
while (ncl) {
|
|
|
|
kill_first_log_iblock(ncl, c, ap);
|
|
|
|
ncl = c->ChildIndex;
|
|
|
|
}
|
|
|
|
c->ClRefCount--;
|
|
|
|
}
|
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
/* assumes c is already locked */
|
2004-03-19 11:35:42 +00:00
|
|
|
static void
|
|
|
|
kill_off_lu_block(LogUpdIndex *c, LogUpdIndex *parent, PredEntry *ap)
|
|
|
|
{
|
2006-03-20 19:51:44 +00:00
|
|
|
/* first, make sure that I killed off all my children, some children may
|
|
|
|
remain in case I have tables as children */
|
2004-03-19 11:35:42 +00:00
|
|
|
if (parent != NULL) {
|
|
|
|
/* sat bye bye */
|
|
|
|
/* decrease refs */
|
|
|
|
parent->ClRefCount--;
|
|
|
|
if (parent->ClFlags & ErasedMask &&
|
|
|
|
!(parent->ClFlags & InUseMask) &&
|
|
|
|
parent->ClRefCount == 0) {
|
|
|
|
/* cool, I can erase the father too. */
|
|
|
|
if (parent->ClFlags & SwitchRootMask) {
|
|
|
|
kill_off_lu_block(parent, NULL, ap);
|
|
|
|
} else {
|
2005-12-17 03:25:39 +00:00
|
|
|
kill_off_lu_block(parent, parent->ParentIndex, ap);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
decrease_log_indices(c, (yamop *)&(ap->cs.p_code.ExpandCode));
|
|
|
|
/* remove from list */
|
|
|
|
if (c->SiblingIndex)
|
|
|
|
c->SiblingIndex->PrevSiblingIndex = c->PrevSiblingIndex;
|
|
|
|
if (c->PrevSiblingIndex) {
|
|
|
|
c->PrevSiblingIndex->SiblingIndex = c->SiblingIndex;
|
|
|
|
} else {
|
|
|
|
DBErasedIList = c->SiblingIndex;
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(c);
|
2006-11-06 18:35:05 +00:00
|
|
|
if (c->ClFlags & SwitchTableMask)
|
|
|
|
Yap_LUIndexSpace_SW -= c->ClSize;
|
|
|
|
else {
|
|
|
|
Yap_LUIndexSpace_Tree -= c->ClSize;
|
|
|
|
}
|
2005-07-06 16:10:18 +01:00
|
|
|
Yap_FreeCodeSpace((char *)c);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
2003-11-24 00:00:43 +00:00
|
|
|
kill_first_log_iblock(LogUpdIndex *c, LogUpdIndex *parent, PredEntry *ap)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
2004-02-19 19:24:46 +00:00
|
|
|
/* parent is always locked, now I lock myself */
|
2004-02-20 02:28:19 +00:00
|
|
|
if (parent != NULL) {
|
2004-02-19 19:24:46 +00:00
|
|
|
/* remove myself from parent */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (c == parent->ChildIndex) {
|
|
|
|
parent->ChildIndex = c->SiblingIndex;
|
2005-05-31 20:42:28 +01:00
|
|
|
if (parent->ChildIndex) {
|
|
|
|
parent->ChildIndex->PrevSiblingIndex = NULL;
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2005-05-31 20:42:28 +01:00
|
|
|
c->PrevSiblingIndex->SiblingIndex =
|
|
|
|
c->SiblingIndex;
|
|
|
|
if (c->SiblingIndex) {
|
|
|
|
c->SiblingIndex->PrevSiblingIndex =
|
|
|
|
c->PrevSiblingIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
} else {
|
|
|
|
/* I am top node */
|
|
|
|
if (ap->cs.p_code.TrueCodeOfPred == c->ClCode) {
|
|
|
|
RemoveMainIndex(ap);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
decrease_log_indices(c, (yamop *)&(ap->cs.p_code.ExpandCode));
|
2003-10-30 11:31:05 +00:00
|
|
|
/* make sure that a child cannot remove us */
|
2006-03-20 19:51:44 +00:00
|
|
|
kill_children(c, ap);
|
2003-10-14 02:32:55 +01:00
|
|
|
/* check if we are still the main index */
|
2008-01-23 17:57:56 +00:00
|
|
|
/* always add to erased list */
|
|
|
|
c->SiblingIndex = DBErasedIList;
|
|
|
|
c->PrevSiblingIndex = NULL;
|
|
|
|
if (DBErasedIList)
|
|
|
|
DBErasedIList->PrevSiblingIndex = c;
|
|
|
|
DBErasedIList = c;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (!((c->ClFlags & InUseMask) || c->ClRefCount)) {
|
2004-03-19 11:35:42 +00:00
|
|
|
kill_off_lu_block(c, parent, ap);
|
2003-10-14 01:53:10 +01:00
|
|
|
} else {
|
2004-03-19 11:35:42 +00:00
|
|
|
if (c->ClFlags & ErasedMask)
|
|
|
|
return;
|
2003-10-30 11:31:05 +00:00
|
|
|
c->ClFlags |= ErasedMask;
|
2004-02-20 02:28:19 +00:00
|
|
|
/* try to move up, so that we don't hold a switch table */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (parent != NULL &&
|
|
|
|
parent->ClFlags & SwitchTableMask) {
|
2004-02-20 02:28:19 +00:00
|
|
|
|
2005-12-17 03:25:39 +00:00
|
|
|
c->ParentIndex = parent->ParentIndex;
|
|
|
|
parent->ParentIndex->ClRefCount++;
|
2003-11-24 00:00:43 +00:00
|
|
|
parent->ClRefCount--;
|
2003-10-31 00:20:52 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kill_top_static_iblock(StaticIndex *c, PredEntry *ap)
|
|
|
|
{
|
2006-03-22 20:07:28 +00:00
|
|
|
kill_static_child_indxs(c, static_in_use(ap, TRUE));
|
2003-08-27 14:37:10 +01:00
|
|
|
RemoveMainIndex(ap);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_kill_iblock(ClauseUnion *blk, ClauseUnion *parent_blk, PredEntry *ap)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdIndex *c = (LogUpdIndex *)blk;
|
|
|
|
if (parent_blk != NULL) {
|
|
|
|
LogUpdIndex *cl = (LogUpdIndex *)parent_blk;
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
cl->ClRefCount++;
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
kill_first_log_iblock(c, cl, ap);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
cl->ClRefCount--;
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
|
|
|
kill_first_log_iblock(c, NULL, ap);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StaticIndex *c = (StaticIndex *)blk;
|
|
|
|
if (parent_blk != NULL) {
|
|
|
|
StaticIndex *cl = parent_blk->si.ChildIndex;
|
|
|
|
if (cl == c) {
|
|
|
|
parent_blk->si.ChildIndex = c->SiblingIndex;
|
|
|
|
} else {
|
|
|
|
while (cl->SiblingIndex != c) {
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
cl->SiblingIndex = c->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
kill_static_child_indxs(c, static_in_use(ap, TRUE));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:53:10 +01:00
|
|
|
/*
|
|
|
|
This predicate is supposed to be called with a
|
|
|
|
lock on the current predicate
|
|
|
|
*/
|
2006-10-10 15:08:17 +01:00
|
|
|
void
|
|
|
|
Yap_ErLogUpdIndex(LogUpdIndex *clau)
|
2003-10-14 01:53:10 +01:00
|
|
|
{
|
2004-02-19 19:24:46 +00:00
|
|
|
if (clau->ClFlags & ErasedMask) {
|
2006-10-10 15:08:17 +01:00
|
|
|
if (!clau->ClRefCount) {
|
2006-10-11 18:24:36 +01:00
|
|
|
decrease_log_indices(clau, (yamop *)&(clau->ClPred->cs.p_code.ExpandCode));
|
2006-10-10 15:08:17 +01:00
|
|
|
if (clau->ClFlags & SwitchRootMask) {
|
|
|
|
kill_off_lu_block(clau, NULL, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else {
|
2005-12-17 03:25:39 +00:00
|
|
|
kill_off_lu_block(clau, clau->ParentIndex, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* otherwise, nothing I can do, I have been erased already */
|
2006-10-10 15:08:17 +01:00
|
|
|
return;
|
2004-02-19 19:24:46 +00:00
|
|
|
}
|
2006-10-10 15:08:17 +01:00
|
|
|
if (clau->ClFlags & SwitchRootMask) {
|
|
|
|
kill_first_log_iblock(clau, NULL, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else {
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount++;
|
|
|
|
#endif
|
2005-12-17 03:25:39 +00:00
|
|
|
kill_first_log_iblock(clau, clau->ParentIndex, clau->ClPred);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount--;
|
|
|
|
#endif
|
2004-11-04 18:22:36 +00:00
|
|
|
}
|
2003-10-14 01:53:10 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Routine used when wanting to remove the indexation */
|
|
|
|
/* ap is known to already have been locked for WRITING */
|
2002-11-11 17:38:10 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
RemoveIndexation(PredEntry *ap)
|
|
|
|
{
|
2003-10-14 01:53:10 +01:00
|
|
|
if (ap->OpcodeOfPred == INDEX_OPCODE) {
|
2003-08-27 14:37:10 +01:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
|
|
|
kill_first_log_iblock(ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred), NULL, ap);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
StaticIndex *cl;
|
|
|
|
|
|
|
|
cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
|
|
|
|
kill_top_static_iblock(cl, ap);
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_RemoveIndexation(PredEntry *ap)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
return RemoveIndexation(ap);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
Adding clauses
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#define assertz 0
|
|
|
|
#define consult 1
|
|
|
|
#define asserta 2
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-06-18 06:22:35 +01:00
|
|
|
retract_all(PredEntry *p, int in_use)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *q;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
q = p->cs.p_code.FirstClause;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (q != NULL) {
|
2003-04-30 18:46:05 +01:00
|
|
|
if (p->PredFlags & LogUpdatePredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(q);
|
2003-04-30 18:46:05 +01:00
|
|
|
do {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdClause *ncl = cl->ClNext;
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_ErLogUpdCl(cl);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = ncl;
|
|
|
|
} while (cl != NULL);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else if (p->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *cl = ClauseCodeToMegaClause(q);
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
if (in_use || cl->ClFlags & HasBlobsMask) {
|
|
|
|
LOCK(DeadMegaClausesLock);
|
|
|
|
cl->ClNext = DeadMegaClauses;
|
|
|
|
DeadMegaClauses = cl;
|
|
|
|
UNLOCK(DeadMegaClausesLock);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
/* make sure this is not a MegaClause */
|
|
|
|
p->PredFlags &= ~MegaClausePredFlag;
|
2004-09-27 21:45:04 +01:00
|
|
|
p->cs.p_code.NOfClauses = 0;
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
while (cl) {
|
|
|
|
StaticClause *ncl = cl->ClNext;
|
|
|
|
|
|
|
|
if (in_use|| cl->ClFlags & HasBlobsMask) {
|
2006-03-24 16:26:31 +00:00
|
|
|
LOCK(DeadStaticClausesLock);
|
2006-03-22 20:07:28 +00:00
|
|
|
cl->ClNext = DeadStaticClauses;
|
|
|
|
DeadStaticClauses = cl;
|
2006-03-24 16:26:31 +00:00
|
|
|
UNLOCK(DeadStaticClausesLock);
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
2002-06-11 06:30:47 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.NOfClauses--;
|
2006-03-22 20:07:28 +00:00
|
|
|
if (!ncl) break;
|
|
|
|
cl = ncl;
|
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
p->cs.p_code.FirstClause = NULL;
|
|
|
|
p->cs.p_code.LastClause = NULL;
|
2011-09-07 22:35:11 +01:00
|
|
|
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MultiFileFlag)) {
|
2006-03-20 19:51:44 +00:00
|
|
|
p->OpcodeOfPred = FAIL_OPCODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2006-03-20 19:51:44 +00:00
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-20 19:51:44 +00:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 03:19:27 +01:00
|
|
|
static int
|
|
|
|
source_pred(PredEntry *p, yamop *q)
|
|
|
|
{
|
|
|
|
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))
|
|
|
|
return FALSE;
|
|
|
|
if (p->PredFlags & MultiFileFlag)
|
|
|
|
return TRUE;
|
|
|
|
if (yap_flags[SOURCE_MODE_FLAG]) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
add_first_static(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *pt = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
if (is_logupd(p)) {
|
2012-11-07 13:49:54 +00:00
|
|
|
if (p == PredGoalExpansion || p->FunctorOfPred == FunctorGoalExpansion2) {
|
2003-08-27 14:37:10 +01:00
|
|
|
PRED_GOAL_EXPANSION_ON = TRUE;
|
|
|
|
Yap_InitComma();
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef TABLING
|
2003-08-27 14:37:10 +01:00
|
|
|
if (is_tabled(p)) {
|
2003-12-18 16:38:40 +00:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* TABLING */
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = pt;
|
|
|
|
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = cp;
|
2008-01-23 17:57:56 +00:00
|
|
|
p->OpcodeOfPred = pt->opc;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
2008-01-23 17:57:56 +00:00
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
p->CodeOfPred = pt;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
spy_flag = TRUE;
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
}
|
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
|
|
|
spy_flag = TRUE;
|
|
|
|
} else {
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (spy_flag) {
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2011-08-25 03:19:27 +01:00
|
|
|
if (source_pred(p, cp)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= SourcePredFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
yamop *ncp = ((DynamicClause *)NULL)->ClCode;
|
|
|
|
DynamicClause *cl;
|
2012-11-07 13:49:54 +00:00
|
|
|
if (p == PredGoalExpansion || p->FunctorOfPred == FunctorGoalExpansion2) {
|
2003-01-29 14:47:17 +00:00
|
|
|
PRED_GOAL_EXPANSION_ON = TRUE;
|
|
|
|
Yap_InitComma();
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
spy_flag = TRUE;
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
}
|
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
|
|
|
spy_flag = TRUE;
|
|
|
|
} else {
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
#endif /* YAPOR */
|
|
|
|
/* allocate starter block, containing info needed to start execution,
|
|
|
|
* that is a try_mark to start the code and a fail to finish things up */
|
|
|
|
cl =
|
2008-09-05 05:22:19 +01:00
|
|
|
(DynamicClause *) Yap_AllocCodeSpace((Int)NEXTOP(NEXTOP(NEXTOP(ncp,Otapl),e),l));
|
2001-04-09 20:54:03 +01:00
|
|
|
if (cl == NIL) {
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"Heap crashed against Stacks");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-09-05 05:22:19 +01:00
|
|
|
Yap_ClauseSpace += (Int)NEXTOP(NEXTOP(NEXTOP(ncp,Otapl),e),l);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* skip the first entry, this contains the back link and will always be
|
|
|
|
empty for this entry */
|
|
|
|
ncp = (yamop *)(((CELL *)ncp)+1);
|
|
|
|
/* next we have the flags. For this block mainly say whether we are
|
|
|
|
* being spied */
|
2003-04-30 18:46:05 +01:00
|
|
|
cl->ClFlags = DynamicMask;
|
|
|
|
ncp = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_LOCK(cl->ClLock);
|
|
|
|
INIT_CLREF_COUNT(cl);
|
|
|
|
/* next, set the first instruction to execute in the dyamic
|
|
|
|
* predicate */
|
|
|
|
if (spy_flag)
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = ncp->opc = Yap_opcode(_spy_or_trymark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = ncp->opc = Yap_opcode(_try_and_mark);
|
2008-09-05 05:22:19 +01:00
|
|
|
ncp->u.Otapl.s = p->ArityOfPE;
|
|
|
|
ncp->u.Otapl.p = p;
|
|
|
|
ncp->u.Otapl.d = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* This is the point we enter the code */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = ncp;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 1;
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* set the first clause to have a retry and mark which will
|
|
|
|
* backtrack to the previous block */
|
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_count_retry_and_mark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_retry_and_mark);
|
2008-09-05 05:22:19 +01:00
|
|
|
cp->u.Otapl.s = p->ArityOfPE;
|
|
|
|
cp->u.Otapl.p = p;
|
|
|
|
cp->u.Otapl.d = ncp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep a backpointer for the days you delete the clause */
|
2003-04-30 18:46:05 +01:00
|
|
|
ClauseCodeToDynamicClause(cp)->ClPrevious = ncp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Don't forget to say who is the only clause for the predicate so
|
|
|
|
far */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.LastClause = p->cs.p_code.FirstClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we're only missing what to do when we actually exit the procedure
|
|
|
|
*/
|
2008-09-05 05:22:19 +01:00
|
|
|
ncp = NEXTOP(ncp,Otapl);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* and the last instruction to execute to exit the predicate, note
|
|
|
|
the retry is pointing to this pseudo clause */
|
2002-11-18 18:18:05 +00:00
|
|
|
ncp->opc = Yap_opcode(_trust_fail);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we're only missing what to do when we actually exit the procedure
|
|
|
|
*/
|
|
|
|
/* and close the code */
|
|
|
|
ncp = NEXTOP(ncp,e);
|
2002-11-18 18:18:05 +00:00
|
|
|
ncp->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
ncp->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2003-11-26 18:36:35 +00:00
|
|
|
asserta_stat_clause(PredEntry *p, yamop *q, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
p->cs.p_code.NOfClauses++;
|
|
|
|
if (is_logupd(p)) {
|
|
|
|
LogUpdClause
|
|
|
|
*clp = ClauseCodeToLogUpdClause(p->cs.p_code.FirstClause),
|
2003-11-26 18:36:35 +00:00
|
|
|
*clq = ClauseCodeToLogUpdClause(q);
|
2003-08-27 14:37:10 +01:00
|
|
|
clq->ClPrev = NULL;
|
|
|
|
clq->ClNext = clp;
|
|
|
|
clp->ClPrev = clq;
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.FirstClause = q;
|
2009-06-22 17:12:56 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2009-06-23 12:51:28 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2009-06-23 12:51:28 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2011-03-15 09:08:09 +00:00
|
|
|
if (p->ModuleOfPred != IDB_MODULE &&
|
|
|
|
!(p->PredFlags & ThreadLocalPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
cl->ClNext = ClauseCodeToStaticClause(p->cs.p_code.FirstClause);
|
|
|
|
p->cs.p_code.FirstClause = q;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = q;
|
2009-06-22 17:12:56 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
2003-10-02 19:20:11 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2008-09-05 05:22:19 +01:00
|
|
|
p->cs.p_code.LastClause->u.Otapl.d = q;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
asserta_dynam_clause(PredEntry *p, yamop *cp)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
yamop *q;
|
2003-08-27 14:37:10 +01:00
|
|
|
DynamicClause *cl = ClauseCodeToDynamicClause(cp);
|
2002-12-27 16:53:09 +00:00
|
|
|
q = cp;
|
2003-04-30 18:46:05 +01:00
|
|
|
LOCK(ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep backpointers for the days we'll delete all the clause */
|
2003-04-30 18:46:05 +01:00
|
|
|
ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClPrevious = q;
|
2003-08-27 14:37:10 +01:00
|
|
|
cl->ClPrevious = (yamop *)(p->CodeOfPred);
|
|
|
|
cl->ClFlags |= DynamicMask;
|
2003-04-30 18:46:05 +01:00
|
|
|
UNLOCK(ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClLock);
|
2008-09-05 05:22:19 +01:00
|
|
|
q->u.Otapl.d = p->cs.p_code.FirstClause;
|
|
|
|
q->u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->u.Otapl.p = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_count_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_retry_and_mark);
|
2008-09-05 05:22:19 +01:00
|
|
|
cp->u.Otapl.s = p->ArityOfPE;
|
|
|
|
cp->u.Otapl.p = p;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.FirstClause = cp;
|
|
|
|
q = p->CodeOfPred;
|
2008-09-05 05:22:19 +01:00
|
|
|
q->u.Otapl.d = cp;
|
|
|
|
q->u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->u.Otapl.p = p;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
assertz_stat_clause(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
yamop *pt;
|
2003-11-26 18:36:35 +00:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
p->cs.p_code.NOfClauses++;
|
|
|
|
pt = p->cs.p_code.LastClause;
|
|
|
|
if (is_logupd(p)) {
|
|
|
|
LogUpdClause
|
|
|
|
*clp = ClauseCodeToLogUpdClause(cp),
|
|
|
|
*clq = ClauseCodeToLogUpdClause(pt);
|
|
|
|
|
|
|
|
clq->ClNext = clp;
|
|
|
|
clp->ClPrev = clq;
|
|
|
|
clp->ClNext = NULL;
|
|
|
|
p->cs.p_code.LastClause = cp;
|
2009-04-22 00:51:01 +01:00
|
|
|
if (!(p->PredFlags & IndexedPredFlag)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2011-03-15 09:08:09 +00:00
|
|
|
if (p->ModuleOfPred != IDB_MODULE &&
|
|
|
|
!(p->PredFlags & ThreadLocalPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-22 17:12:56 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
2009-04-22 00:51:01 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
2006-03-20 19:51:44 +00:00
|
|
|
} else {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pt);
|
|
|
|
|
|
|
|
cl->ClNext = ClauseCodeToStaticClause(cp);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (p->cs.p_code.FirstClause == p->cs.p_code.LastClause) {
|
2009-06-22 17:12:56 +01:00
|
|
|
if (!(p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag))) {
|
2003-11-26 18:36:35 +00:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.LastClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
assertz_dynam_clause(PredEntry *p, yamop *cp)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
yamop *q;
|
2003-08-27 14:37:10 +01:00
|
|
|
DynamicClause *cl = ClauseCodeToDynamicClause(cp);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
q = p->cs.p_code.LastClause;
|
2003-04-30 18:46:05 +01:00
|
|
|
LOCK(ClauseCodeToDynamicClause(q)->ClLock);
|
2008-09-05 05:22:19 +01:00
|
|
|
q->u.Otapl.d = cp;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.LastClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep backpointers for the days we'll delete all the clause */
|
2003-08-27 14:37:10 +01:00
|
|
|
cl->ClPrevious = q;
|
|
|
|
cl->ClFlags |= DynamicMask;
|
2003-04-30 18:46:05 +01:00
|
|
|
UNLOCK(ClauseCodeToDynamicClause(q)->ClLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
q = (yamop *)cp;
|
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_count_retry_and_mark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_retry_and_mark);
|
2008-09-05 05:22:19 +01:00
|
|
|
q->u.Otapl.d = p->CodeOfPred;
|
|
|
|
q->u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->u.Otapl.p = p;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2011-08-24 04:11:54 +01:00
|
|
|
void
|
|
|
|
Yap_AssertzClause(PredEntry *p, yamop *cp)
|
|
|
|
{
|
|
|
|
if (p->PredFlags & DynamicPredFlag) {
|
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_dynamic(p, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_dynam_clause(p, cp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_static(p, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_stat_clause(p, cp, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
static void expand_consult( void )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-04-29 02:15:18 +01:00
|
|
|
consult_obj *new_cl, *new_cs;
|
2011-05-04 10:11:41 +01:00
|
|
|
UInt OldConsultCapacity = LOCAL_ConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-01-01 05:26:25 +00:00
|
|
|
/* now double consult capacity */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity += InitialConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* I assume it always works ;-) */
|
2011-05-04 10:11:41 +01:00
|
|
|
while ((new_cl = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*LOCAL_ConsultCapacity)) == NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, sizeof(consult_obj)*LOCAL_ConsultCapacity, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,LOCAL_ErrorMessage);
|
2002-02-27 02:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-04-28 14:23:23 +01:00
|
|
|
new_cs = new_cl + InitialConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* start copying */
|
2011-05-04 10:11:41 +01:00
|
|
|
memcpy((void *)new_cs, (void *)LOCAL_ConsultLow, OldConsultCapacity*sizeof(consult_obj));
|
2001-04-09 20:54:03 +01:00
|
|
|
/* copying done, release old space */
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_FreeCodeSpace((char *)LOCAL_ConsultLow);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* next, set up pointers correctly */
|
2011-05-04 10:11:41 +01:00
|
|
|
new_cs += (LOCAL_ConsultSp-LOCAL_ConsultLow);
|
|
|
|
/* put LOCAL_ConsultBase at same offset as before move */
|
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultBase+(new_cs-LOCAL_ConsultSp);
|
2006-04-28 14:23:23 +01:00
|
|
|
/* new consult pointer */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp = new_cs;
|
2006-04-28 14:23:23 +01:00
|
|
|
/* new end of memory */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultLow = new_cl;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p was already locked */
|
|
|
|
static int
|
2001-12-12 19:36:51 +00:00
|
|
|
not_was_reconsulted(PredEntry *p, Term t, int mode)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
register consult_obj *fp;
|
|
|
|
Prop p0 = AbsProp((PropEntry *)p);
|
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
if (p == LOCAL_LastAssertedPred)
|
2009-02-10 23:42:26 +00:00
|
|
|
return FALSE;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_LastAssertedPred = p;
|
|
|
|
if (!LOCAL_ConsultSp) {
|
2010-03-21 22:12:42 +00:00
|
|
|
InitConsultStack();
|
|
|
|
}
|
2008-05-28 18:18:35 +01:00
|
|
|
if (p->cs.p_code.NOfClauses) {
|
2011-05-04 10:11:41 +01:00
|
|
|
for (fp = LOCAL_ConsultSp; fp < LOCAL_ConsultBase; ++fp)
|
2008-05-28 18:18:35 +01:00
|
|
|
if (fp->p == p0)
|
|
|
|
break;
|
|
|
|
} else {
|
2011-05-04 10:11:41 +01:00
|
|
|
fp = LOCAL_ConsultBase;
|
2008-05-28 18:18:35 +01:00
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
if (fp != LOCAL_ConsultBase)
|
2009-02-10 23:42:26 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode) {
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_ConsultSp == LOCAL_ConsultLow+1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
expand_consult();
|
2004-05-13 21:54:58 +01:00
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
--LOCAL_ConsultSp;
|
|
|
|
LOCAL_ConsultSp->p = p0;
|
|
|
|
if (LOCAL_ConsultBase[1].mode &&
|
2003-11-26 18:36:35 +00:00
|
|
|
!(p->PredFlags & MultiFileFlag)) /* we are in reconsult mode */ {
|
2002-06-18 06:22:35 +01:00
|
|
|
retract_all(p, static_in_use(p,TRUE));
|
2001-12-12 19:36:51 +00:00
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
p->src.OwnerFile = YapConsultingFile( PASS_REGS1 );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-04-28 14:23:23 +01:00
|
|
|
return TRUE; /* careful */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-01-02 16:55:24 +00:00
|
|
|
addcl_permission_error(AtomEntry *ap, Int Arity, int in_use)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t, ti[2];
|
|
|
|
|
|
|
|
ti[0] = MkAtomTerm(AbsAtom(ap));
|
|
|
|
ti[1] = MkIntegerTerm(Arity);
|
2008-12-23 01:53:52 +00:00
|
|
|
t = Yap_MkApplTerm(FunctorSlash, 2, ti);
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_ErrorMessage = LOCAL_ErrorSay;
|
|
|
|
LOCAL_Error_Term = t;
|
|
|
|
LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
|
2002-01-02 16:55:24 +00:00
|
|
|
if (in_use) {
|
|
|
|
if (Arity == 0)
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage, "static predicate %s is in use", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage,
|
2010-05-06 15:00:44 +01:00
|
|
|
"static predicate %s/" Int_FORMAT " is in use",
|
2002-01-02 16:55:24 +00:00
|
|
|
ap->StrOfAE, Arity);
|
|
|
|
} else {
|
|
|
|
if (Arity == 0)
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage, "system predicate %s", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage,
|
2010-05-06 15:00:44 +01:00
|
|
|
"system predicate %s/" Int_FORMAT,
|
2002-01-02 16:55:24 +00:00
|
|
|
ap->StrOfAE, Arity);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2004-09-08 18:56:48 +01:00
|
|
|
|
|
|
|
static int
|
|
|
|
is_fact(Term t)
|
|
|
|
{
|
|
|
|
Term a1;
|
|
|
|
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
return TRUE;
|
|
|
|
if (FunctorOfTerm(t) != FunctorAssert)
|
|
|
|
return TRUE;
|
|
|
|
a1 = ArgOfTerm(2, t);
|
|
|
|
if (a1 == MkAtomTerm(AtomTrue))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-16 14:58:41 +00:00
|
|
|
static void
|
|
|
|
mark_preds_with_this_func(Functor f, Prop p0)
|
|
|
|
{
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
UInt i;
|
|
|
|
|
|
|
|
pe->PredFlags |= GoalExPredFlag;
|
|
|
|
for (i = 0; i < PredHashTableSize; i++) {
|
|
|
|
PredEntry *p = PredHash[i];
|
|
|
|
|
2012-11-07 13:49:54 +00:00
|
|
|
/* search the whole pred table, kind of inneficient */
|
2007-11-16 14:58:41 +00:00
|
|
|
while (p) {
|
|
|
|
Prop nextp = p->NextOfPE;
|
|
|
|
if (p->FunctorOfPred == f)
|
|
|
|
p->PredFlags |= GoalExPredFlag;
|
|
|
|
p = RepPredProp(nextp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 13:49:54 +00:00
|
|
|
static void
|
|
|
|
mark_preds_with_this_atom(Prop p)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2012-11-07 13:49:54 +00:00
|
|
|
while (p) {
|
|
|
|
Prop nextp = p->NextOfPE;
|
|
|
|
if (p->KindOfPE == PEProp)
|
|
|
|
RepPredProp(p)->PredFlags |= GoalExPredFlag;
|
|
|
|
p = nextp;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2012-11-07 13:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
goal_expansion_support(PredEntry *p, Term tf)
|
|
|
|
{
|
2004-12-05 05:01:45 +00:00
|
|
|
if (p == PredGoalExpansion) {
|
|
|
|
Term tg = ArgOfTerm(1, tf);
|
|
|
|
Term tm = ArgOfTerm(2, tf);
|
|
|
|
|
|
|
|
if (IsVarTerm(tg) || IsVarTerm(tm)) {
|
|
|
|
if (!IsVarTerm(tg)) {
|
|
|
|
/* this is the complicated case, first I need to inform
|
|
|
|
predicates for this functor */
|
|
|
|
PRED_GOAL_EXPANSION_FUNC = TRUE;
|
|
|
|
if (IsAtomTerm(tg)) {
|
|
|
|
AtomEntry *ae = RepAtom(AtomOfTerm(tg));
|
|
|
|
Prop p0 = ae->PropsOfAE;
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
if (pe->KindOfPE == PEProp) {
|
|
|
|
pe->PredFlags |= GoalExPredFlag;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
p0 = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
PredEntry *npe = RepPredProp(PredPropByAtom(AtomOfTerm(tg),IDB_MODULE));
|
|
|
|
npe->PredFlags |= GoalExPredFlag;
|
|
|
|
}
|
|
|
|
} else if (IsApplTerm(tg)) {
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)FunctorOfTerm(tg);
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
p0 = fe->PropsOfFE;
|
2007-11-16 14:58:41 +00:00
|
|
|
if (p0) {
|
|
|
|
mark_preds_with_this_func(FunctorOfTerm(tg), p0);
|
|
|
|
} else {
|
2012-12-07 08:08:32 +00:00
|
|
|
CACHE_REGS
|
2007-11-16 14:58:41 +00:00
|
|
|
Term mod = CurrentModule;
|
|
|
|
PredEntry *npe;
|
|
|
|
if (CurrentModule == PROLOG_MODULE)
|
|
|
|
mod = IDB_MODULE;
|
|
|
|
npe = RepPredProp(PredPropByFunc(fe,mod));
|
2004-12-05 05:01:45 +00:00
|
|
|
npe->PredFlags |= GoalExPredFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PRED_GOAL_EXPANSION_ALL = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (IsAtomTerm(tm)) {
|
|
|
|
if (IsAtomTerm(tg)) {
|
|
|
|
PredEntry *p = RepPredProp(PredPropByAtom(AtomOfTerm(tg), tm));
|
|
|
|
p->PredFlags |= GoalExPredFlag;
|
|
|
|
} else if (IsApplTerm(tg)) {
|
|
|
|
PredEntry *p = RepPredProp(PredPropByFunc(FunctorOfTerm(tg), tm));
|
|
|
|
p->PredFlags |= GoalExPredFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-07 13:49:54 +00:00
|
|
|
} else if (p->FunctorOfPred == FunctorGoalExpansion2) {
|
|
|
|
Term tg = ArgOfTerm(1, tf);
|
|
|
|
|
|
|
|
if (IsVarTerm(tg)) {
|
|
|
|
PRED_GOAL_EXPANSION_ALL = TRUE;
|
|
|
|
} else if (IsApplTerm(tg)) {
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)FunctorOfTerm(tg);
|
|
|
|
Prop p0;
|
|
|
|
PredEntry *npe;
|
|
|
|
|
|
|
|
p0 = fe->PropsOfFE;
|
|
|
|
if (p0 && (p->ModuleOfPred == PROLOG_MODULE || p->ModuleOfPred == SYSTEM_MODULE || p->ModuleOfPred == USER_MODULE)) {
|
|
|
|
mark_preds_with_this_func(fe, p0);
|
|
|
|
PRED_GOAL_EXPANSION_FUNC = TRUE;
|
|
|
|
}
|
|
|
|
npe = RepPredProp(PredPropByFunc(fe,p->ModuleOfPred));
|
|
|
|
npe->PredFlags |= GoalExPredFlag;
|
|
|
|
} else if (IsAtomTerm(tg)) {
|
|
|
|
Atom at = AtomOfTerm(tg);
|
|
|
|
Prop p0;
|
|
|
|
PredEntry *npe;
|
|
|
|
|
|
|
|
p0 = RepAtom(at)->PropsOfAE;
|
|
|
|
if (p0 && (p->ModuleOfPred == PROLOG_MODULE || p->ModuleOfPred == SYSTEM_MODULE || p->ModuleOfPred == USER_MODULE)) {
|
|
|
|
mark_preds_with_this_atom(p0);
|
|
|
|
PRED_GOAL_EXPANSION_FUNC = TRUE;
|
|
|
|
}
|
|
|
|
npe = RepPredProp(PredPropByAtom(at,p->ModuleOfPred));
|
|
|
|
npe->PredFlags |= GoalExPredFlag;
|
|
|
|
}
|
2004-12-05 05:01:45 +00:00
|
|
|
}
|
2012-11-07 13:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref)
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
mode
|
|
|
|
0 assertz
|
|
|
|
1 consult
|
|
|
|
2 asserta
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CACHE_REGS
|
|
|
|
PredEntry *p;
|
|
|
|
int spy_flag = FALSE;
|
|
|
|
Atom at;
|
|
|
|
UInt Arity;
|
|
|
|
CELL pflags;
|
|
|
|
Term tf;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorAssert)
|
|
|
|
tf = ArgOfTerm(1, t);
|
|
|
|
else
|
|
|
|
tf = t;
|
|
|
|
if (IsAtomTerm(tf)) {
|
|
|
|
at = AtomOfTerm(tf);
|
|
|
|
p = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
Arity = 0;
|
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(tf);
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
at = NameOfFunctor(f);
|
|
|
|
p = RepPredProp(PredPropByFunc(f, mod));
|
|
|
|
}
|
|
|
|
Yap_PutValue(AtomAbol, TermNil);
|
|
|
|
PELOCK(20,p);
|
|
|
|
pflags = p->PredFlags;
|
|
|
|
/* we are redefining a prolog module predicate */
|
|
|
|
if ((pflags & (UserCPredFlag|CArgsPredFlag|NumberDBPredFlag|AtomDBPredFlag|TestPredFlag|AsmPredFlag|CPredFlag|BinaryPredFlag)) ||
|
|
|
|
(p->ModuleOfPred == PROLOG_MODULE &&
|
|
|
|
mod != TermProlog && mod) ) {
|
|
|
|
addcl_permission_error(RepAtom(at), Arity, FALSE);
|
|
|
|
UNLOCKPE(30,p);
|
|
|
|
return TermNil;
|
|
|
|
}
|
|
|
|
/* we are redefining a prolog module predicate */
|
|
|
|
if (pflags & MegaClausePredFlag) {
|
|
|
|
split_megaclause(p);
|
|
|
|
}
|
|
|
|
/* The only problem we have now is when we need to throw away
|
|
|
|
Indexing blocks
|
|
|
|
*/
|
|
|
|
if (pflags & IndexedPredFlag) {
|
|
|
|
Yap_AddClauseToIndex(p, cp, mode == asserta);
|
|
|
|
}
|
|
|
|
if (pflags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag))
|
|
|
|
spy_flag = TRUE;
|
|
|
|
goal_expansion_support(p, tf);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode == consult)
|
2001-12-12 19:36:51 +00:00
|
|
|
not_was_reconsulted(p, t, TRUE);
|
2002-03-07 05:47:24 +00:00
|
|
|
/* always check if we have a valid error first */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage && LOCAL_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(31,p);
|
2003-08-27 14:37:10 +01:00
|
|
|
return TermNil;
|
|
|
|
}
|
2009-02-12 21:35:31 +00:00
|
|
|
if (pflags & UDIPredFlag) {
|
|
|
|
Yap_new_udi_clause(p, cp, t);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!is_dynamic(p)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
2003-04-30 18:46:05 +01:00
|
|
|
LogUpdClause *clp = ClauseCodeToLogUpdClause(cp);
|
2003-08-27 14:37:10 +01:00
|
|
|
clp->ClFlags |= LogUpdMask;
|
2004-09-08 18:56:48 +01:00
|
|
|
if (is_fact(t)) {
|
2003-11-18 19:24:46 +00:00
|
|
|
clp->ClFlags |= FactMask;
|
|
|
|
clp->ClSource = NULL;
|
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
|
|
|
StaticClause *clp = ClauseCodeToStaticClause(cp);
|
|
|
|
clp->ClFlags |= StaticMask;
|
2007-03-26 16:18:43 +01:00
|
|
|
if (is_fact(t) && !(p->PredFlags & TabledPredFlag)) {
|
2003-11-18 19:24:46 +00:00
|
|
|
clp->ClFlags |= FactMask;
|
2003-11-24 00:00:43 +00:00
|
|
|
clp->usc.ClPred = p;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (compile_mode)
|
2003-12-04 18:13:04 +00:00
|
|
|
p->PredFlags = p->PredFlags | CompiledPredFlag;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2003-11-27 21:47:44 +00:00
|
|
|
p->PredFlags = p->PredFlags | CompiledPredFlag;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-06-06 12:54:02 +01:00
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (!(pflags & DynamicPredFlag)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
add_first_static(p, cp, spy_flag);
|
|
|
|
/* make sure we have a place to jump to */
|
2002-10-14 17:25:38 +01:00
|
|
|
if (p->OpcodeOfPred == UNDEF_OPCODE ||
|
|
|
|
p->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->OpcodeOfPred = ((yamop *)(p->CodeOfPred))->opc;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
2007-11-26 23:43:10 +00:00
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
add_first_dynamic(p, cp, spy_flag);
|
|
|
|
}
|
|
|
|
} else if (mode == asserta) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & DynamicPredFlag)
|
2001-04-09 20:54:03 +01:00
|
|
|
asserta_dynam_clause(p, cp);
|
|
|
|
else
|
|
|
|
asserta_stat_clause(p, cp, spy_flag);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (pflags & DynamicPredFlag)
|
2001-04-09 20:54:03 +01:00
|
|
|
assertz_dynam_clause(p, cp);
|
|
|
|
else {
|
|
|
|
assertz_stat_clause(p, cp, spy_flag);
|
|
|
|
if (p->OpcodeOfPred != INDEX_OPCODE &&
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred != Yap_opcode(_spy_pred)) {
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->OpcodeOfPred = ((yamop *)(p->CodeOfPred))->opc;
|
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2007-11-26 23:43:10 +00:00
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(32,p);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
2009-08-20 03:53:49 +01:00
|
|
|
LogUpdClause *cl = (LogUpdClause *)ClauseCodeToLogUpdClause(cp);
|
2009-08-12 16:00:38 +01:00
|
|
|
tf = MkDBRefTerm((DBRef)cl);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2009-08-12 16:00:38 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
INC_CLREF_COUNT(cl);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2005-04-20 05:02:30 +01:00
|
|
|
tf = Yap_MkStaticRefTerm(ClauseCodeToStaticClause(cp));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2004-10-31 02:18:04 +00:00
|
|
|
if (*t4ref != TermNil) {
|
|
|
|
if (!Yap_unify(*t4ref,tf)) {
|
2004-10-06 17:55:48 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pflags & MultiFileFlag) {
|
|
|
|
/* add Info on new clause for multifile predicates to the DB */
|
|
|
|
Term t[5], tn;
|
2011-03-07 16:02:55 +00:00
|
|
|
t[0] = MkAtomTerm(YapConsultingFile( PASS_REGS1 ));
|
2004-10-06 17:55:48 +01:00
|
|
|
t[1] = MkAtomTerm(at);
|
|
|
|
t[2] = MkIntegerTerm(Arity);
|
|
|
|
t[3] = mod;
|
|
|
|
t[4] = tf;
|
|
|
|
tn = Yap_MkApplTerm(FunctorMultiFileClause,5,t);
|
|
|
|
Yap_Recordz(AtomMultiFile,tn);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2004-10-06 17:55:48 +01:00
|
|
|
int
|
2004-10-31 02:18:04 +00:00
|
|
|
Yap_addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref) {
|
2004-10-06 17:55:48 +01:00
|
|
|
return addclause(t, cp, mode, mod, t4ref);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
void
|
|
|
|
Yap_EraseMegaClause(yamop *cl,PredEntry *ap) {
|
|
|
|
/* just make it fail */
|
|
|
|
cl->opc = Yap_opcode(_op_fail);
|
|
|
|
}
|
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
void
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_EraseStaticClause(StaticClause *cl, Term mod) {
|
2003-11-26 18:36:35 +00:00
|
|
|
PredEntry *ap;
|
|
|
|
|
|
|
|
/* ok, first I need to find out the parent predicate */
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
ap = cl->usc.ClPred;
|
|
|
|
} else {
|
|
|
|
Term t = ArgOfTerm(1,cl->usc.ClSource->Entry);
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
ap = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
|
|
|
} else {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
ap = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
|
|
|
}
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
if (ap->PredFlags & MegaClausePredFlag) {
|
|
|
|
split_megaclause(ap);
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (ap->PredFlags & IndexedPredFlag)
|
|
|
|
RemoveIndexation(ap);
|
|
|
|
ap->cs.p_code.NOfClauses--;
|
|
|
|
if (ap->cs.p_code.FirstClause == cl->ClCode) {
|
|
|
|
/* got rid of first clause */
|
|
|
|
if (ap->cs.p_code.LastClause == cl->ClCode) {
|
|
|
|
/* got rid of all clauses */
|
|
|
|
ap->cs.p_code.LastClause = ap->cs.p_code.FirstClause = NULL;
|
|
|
|
ap->OpcodeOfPred = UNDEF_OPCODE;
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else {
|
|
|
|
yamop *ncl = cl->ClNext->ClCode;
|
|
|
|
ap->cs.p_code.FirstClause = ncl;
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
ncl;
|
|
|
|
ap->OpcodeOfPred = ncl->opc;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StaticClause *pcl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause),
|
|
|
|
*ocl = NULL;
|
|
|
|
|
|
|
|
while (pcl != cl) {
|
|
|
|
ocl = pcl;
|
|
|
|
pcl = pcl->ClNext;
|
|
|
|
}
|
|
|
|
ocl->ClNext = cl->ClNext;
|
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause) {
|
|
|
|
ap->cs.p_code.LastClause = ocl->ClCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 1) {
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
ap->cs.p_code.FirstClause;
|
|
|
|
ap->OpcodeOfPred =
|
|
|
|
ap->cs.p_code.TrueCodeOfPred->opc;
|
|
|
|
}
|
|
|
|
if (cl->ClFlags & HasBlobsMask || static_in_use(ap,TRUE)) {
|
2006-03-24 16:26:31 +00:00
|
|
|
LOCK(DeadStaticClausesLock);
|
2006-03-22 20:07:28 +00:00
|
|
|
cl->ClNext = DeadStaticClauses;
|
|
|
|
DeadStaticClauses = cl;
|
2006-03-24 16:26:31 +00:00
|
|
|
UNLOCK(DeadStaticClausesLock);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 0) {
|
|
|
|
ap->CodeOfPred =
|
|
|
|
ap->cs.p_code.TrueCodeOfPred;
|
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1) {
|
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2009-06-22 17:12:56 +01:00
|
|
|
} else if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
2003-11-26 18:36:35 +00:00
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else {
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
void
|
|
|
|
Yap_add_logupd_clause(PredEntry *pe, LogUpdClause *cl, int mode) {
|
|
|
|
yamop *cp = cl->ClCode;
|
|
|
|
|
|
|
|
if (pe->PredFlags & IndexedPredFlag) {
|
|
|
|
Yap_AddClauseToIndex(pe, cp, mode == asserta);
|
|
|
|
}
|
|
|
|
if (pe->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_static(pe, cp, FALSE);
|
|
|
|
/* make sure we have a place to jump to */
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE ||
|
|
|
|
pe->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(pe->PredFlags & ThreadLocalPredFlag) &&
|
2007-11-26 23:43:10 +00:00
|
|
|
pe->ModuleOfPred != IDB_MODULE) {
|
|
|
|
pe->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred;
|
|
|
|
pe->OpcodeOfPred = ((yamop *)(pe->CodeOfPred))->opc;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (mode == asserta) {
|
|
|
|
asserta_stat_clause(pe, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_stat_clause(pe, cp, FALSE);
|
|
|
|
}
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_compile( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$compile'(+C,+Flags, Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term t1 = Deref(ARG2);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG4);
|
2004-10-31 02:18:04 +00:00
|
|
|
Term tn = TermNil;
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *codeadr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsIntTerm(t1))
|
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2003-12-01 17:27:42 +00:00
|
|
|
|
|
|
|
YAPEnterCriticalSection();
|
2004-12-28 22:20:37 +00:00
|
|
|
codeadr = Yap_cclause(t, 4, mod, Deref(ARG3)); /* vsc: give the number of arguments
|
2001-04-09 20:54:03 +01:00
|
|
|
to cclause in case there is overflow */
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!LOCAL_ErrorMessage)
|
2004-10-31 02:18:04 +00:00
|
|
|
addclause(t, codeadr, (int) (IntOfTerm(t1) & 3), mod, &tn);
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IntOfTerm(t1) & 4) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term,
|
|
|
|
"in line %d, %s", Yap_FirstLineInParse(), LOCAL_ErrorMessage);
|
2004-11-18 22:32:40 +00:00
|
|
|
} else {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
|
2004-11-18 22:32:40 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-11-18 22:32:40 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_compile_dynamic( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$compile_dynamic'(+C,+Flags,Mod,-Ref) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term t1 = Deref(ARG2);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG4);
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *code_adr;
|
2005-02-08 04:05:39 +00:00
|
|
|
int old_optimize, mode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-02-08 04:05:39 +00:00
|
|
|
if (IsVarTerm(t1) || !IsAtomicTerm(t1))
|
2005-01-28 23:14:41 +00:00
|
|
|
return FALSE;
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2005-01-28 23:14:41 +00:00
|
|
|
return FALSE;
|
2005-02-08 04:05:39 +00:00
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
if (RepAtom(AtomOfTerm(t1))->StrOfAE[0] == 'f') mode = asserta;
|
|
|
|
else mode = assertz;
|
|
|
|
} else mode = IntegerOfTerm(t1);
|
2011-05-02 23:29:48 +01:00
|
|
|
/* separate assert in current file from reconsult
|
2011-05-04 11:10:20 +01:00
|
|
|
if (mode == assertz && LOCAL_consult_level && mod == CurrentModule)
|
2011-05-02 23:29:48 +01:00
|
|
|
mode = consult;
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
old_optimize = optimizer_on;
|
|
|
|
optimizer_on = FALSE;
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPEnterCriticalSection();
|
2004-12-16 05:57:32 +00:00
|
|
|
code_adr = Yap_cclause(t, 5, mod, Deref(ARG3)); /* vsc: give the number of arguments to
|
2001-04-09 20:54:03 +01:00
|
|
|
cclause() in case there is a overflow */
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!LOCAL_ErrorMessage) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-01-28 23:14:41 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
optimizer_on = old_optimize;
|
2005-02-08 04:05:39 +00:00
|
|
|
addclause(t, code_adr, mode , mod, &ARG5);
|
2004-10-06 17:55:48 +01:00
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
|
|
|
if (!LOCAL_Error_Term)
|
|
|
|
LOCAL_Error_Term = TermNil;
|
|
|
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2004-10-06 17:55:48 +01:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2004-10-06 17:55:48 +01:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Atom
|
2011-03-07 16:02:55 +00:00
|
|
|
YapConsultingFile ( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_consult_level == 0) {
|
2008-12-23 01:53:52 +00:00
|
|
|
return(AtomUser);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2011-05-04 10:11:41 +01:00
|
|
|
return(Yap_LookupAtom(LOCAL_ConsultBase[2].filename));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Atom
|
2011-03-07 16:02:55 +00:00
|
|
|
Yap_ConsultingFile ( void )
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
return YapConsultingFile( PASS_REGS1 );
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* consult file *file*, *mode* may be one of either consult or reconsult */
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
init_consult(int mode, char *file)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
if (!LOCAL_ConsultSp) {
|
2010-03-21 22:12:42 +00:00
|
|
|
InitConsultStack();
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp--;
|
|
|
|
LOCAL_ConsultSp->filename = file;
|
|
|
|
LOCAL_ConsultSp--;
|
|
|
|
LOCAL_ConsultSp->mode = mode;
|
|
|
|
LOCAL_ConsultSp--;
|
|
|
|
LOCAL_ConsultSp->c = (LOCAL_ConsultBase-LOCAL_ConsultSp);
|
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if !defined(YAPOR) && !defined(YAPOR_SBA)
|
2011-05-04 10:11:41 +01:00
|
|
|
/* if (LOCAL_consult_level == 0)
|
2002-02-26 15:51:54 +00:00
|
|
|
do_toggle_static_predicates_in_use(TRUE); */
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_consult_level++;
|
|
|
|
LOCAL_LastAssertedPred = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_consult(int mode, char *file)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
init_consult(mode,file);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_startconsult( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$start_consult'(+Mode) */
|
|
|
|
Term t;
|
|
|
|
char *smode = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
mode = strcmp("consult",smode);
|
|
|
|
init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE);
|
2011-05-04 10:11:41 +01:00
|
|
|
t = MkIntTerm(LOCAL_consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG3, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_showconslultlev( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
t = MkIntTerm(LOCAL_consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG1, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
end_consult( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp = LOCAL_ConsultBase;
|
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp+LOCAL_ConsultSp->c;
|
|
|
|
LOCAL_ConsultSp += 3;
|
|
|
|
LOCAL_consult_level--;
|
|
|
|
LOCAL_LastAssertedPred = NULL;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if !defined(YAPOR) && !defined(YAPOR_SBA)
|
2011-05-04 10:11:41 +01:00
|
|
|
/* if (LOCAL_consult_level == 0)
|
2002-02-26 15:51:54 +00:00
|
|
|
do_toggle_static_predicates_in_use(FALSE);*/
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2011-03-07 16:02:55 +00:00
|
|
|
Yap_end_consult( void ) {
|
|
|
|
CACHE_REGS
|
|
|
|
end_consult( PASS_REGS1 );
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_endconsult( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$end_consult' */
|
2011-03-07 16:02:55 +00:00
|
|
|
end_consult( PASS_REGS1 );
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2004-02-11 01:20:56 +00:00
|
|
|
static void
|
|
|
|
purge_clauses(PredEntry *pred)
|
|
|
|
{
|
2012-06-21 16:47:19 +01:00
|
|
|
if (pred->PredFlags & UDIPredFlag) {
|
|
|
|
Yap_udi_abolish(pred);
|
|
|
|
}
|
2007-12-18 17:46:58 +00:00
|
|
|
if (pred->cs.p_code.NOfClauses) {
|
|
|
|
if (pred->PredFlags & IndexedPredFlag)
|
|
|
|
RemoveIndexation(pred);
|
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
|
|
|
retract_all(pred, static_in_use(pred,TRUE));
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
pred->src.OwnerFile = AtomNil;
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_Abolish(PredEntry *pred)
|
|
|
|
{
|
|
|
|
purge_clauses(pred);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_purge_clauses( USES_REGS1 )
|
2004-02-11 01:20:56 +00:00
|
|
|
{ /* '$purge_clauses'(+Func) */
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2012-04-23 23:28:41 +01:00
|
|
|
MegaClause *before = DeadMegaClauses;
|
2004-02-11 01:20:56 +00:00
|
|
|
|
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomNil));
|
|
|
|
if (IsVarTerm(t))
|
2004-02-12 12:37:12 +00:00
|
|
|
return FALSE;
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
|
|
|
return FALSE;
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
pred = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
pred = RepPredProp(PredPropByFunc(fun, mod));
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(21,pred);
|
2004-02-11 01:20:56 +00:00
|
|
|
if (pred->PredFlags & StandardPredFlag) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(33,pred);
|
2004-02-11 01:20:56 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, t, "assert/1");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
purge_clauses(pred);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(34,pred);
|
2012-04-23 23:28:41 +01:00
|
|
|
/* try to use the garbage collector to recover the mega clause,
|
|
|
|
in case the objs pointing to it are dead themselves */
|
|
|
|
if (DeadMegaClauses != before) {
|
|
|
|
if (!Yap_gc(2, ENV, gc_P(P,CP))) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
MANAGING SPY-POINTS
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_setspy( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$set_spy'(+Fun,+M) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
CELL fg;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term t, mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
at = AtomSpy;
|
2002-11-18 18:18:05 +00:00
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
2001-10-30 16:42:05 +00:00
|
|
|
SpyCode = pred;
|
2001-04-09 20:54:03 +01:00
|
|
|
t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(t))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom at = AtomOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByAtomNonThreadLocal(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByFunctorNonThreadLocal(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(22,pred);
|
2003-12-01 17:27:42 +00:00
|
|
|
restart_spy:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pred->PredFlags & (CPredFlag | SafePredFlag)) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(35,pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-10-14 17:25:38 +01:00
|
|
|
if (pred->OpcodeOfPred == UNDEF_OPCODE ||
|
|
|
|
pred->OpcodeOfPred == FAIL_OPCODE) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(36,pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (pred->OpcodeOfPred == INDEX_OPCODE) {
|
2005-04-10 05:01:15 +01:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < pred->ArityOfPE; i++) {
|
|
|
|
XREGS[i+1] = MkVarTerm();
|
|
|
|
}
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(pred, 0, CP);
|
2001-04-09 20:54:03 +01:00
|
|
|
goto restart_spy;
|
|
|
|
}
|
|
|
|
fg = pred->PredFlags;
|
|
|
|
if (fg & DynamicPredFlag) {
|
|
|
|
pred->OpcodeOfPred =
|
|
|
|
((yamop *)(pred->CodeOfPred))->opc =
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_opcode(_spy_or_trymark);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
pred->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2002-12-27 16:53:09 +00:00
|
|
|
pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
pred->PredFlags |= SpiedPredFlag;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(37,pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_rmspy( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$rm_spy'(+T,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
at = AtomOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByAtomNonThreadLocal(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByFunctorNonThreadLocal(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(23,pred);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!(pred->PredFlags & SpiedPredFlag)) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(38,pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#if THREADS
|
2004-02-11 13:33:19 +00:00
|
|
|
if (!(pred->PredFlags & ThreadLocalPredFlag)) {
|
|
|
|
pred->OpcodeOfPred = Yap_opcode(_thread_local);
|
2007-11-26 23:43:10 +00:00
|
|
|
pred->PredFlags ^= SpiedPredFlag;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(39,pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-22 17:12:56 +01:00
|
|
|
if (!(pred->PredFlags & (CountPredFlag|ProfiledPredFlag))) {
|
|
|
|
if (!(pred->PredFlags & DynamicPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2009-06-22 17:12:56 +01:00
|
|
|
if (pred->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(pred->PredFlags & ThreadLocalPredFlag) &&
|
2009-06-22 17:12:56 +01:00
|
|
|
pred->ModuleOfPred != IDB_MODULE) {
|
|
|
|
pred->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred));
|
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2009-06-22 17:12:56 +01:00
|
|
|
pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred;
|
|
|
|
pred->OpcodeOfPred = pred->CodeOfPred->opc;
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2009-06-22 17:12:56 +01:00
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2009-06-22 17:12:56 +01:00
|
|
|
} else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) {
|
|
|
|
pred->OpcodeOfPred = Yap_opcode(_try_and_mark);
|
|
|
|
} else {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(39,pred);
|
2009-06-22 17:12:56 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
pred->PredFlags ^= SpiedPredFlag;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(40,pred);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
INFO ABOUT PREDICATES
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_number_of_clauses( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$number_of_clauses'(Predicate,M,N) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
int ncl = 0;
|
|
|
|
Prop pe;
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-10-03 14:39:16 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = Yap_GetPredPropByAtom(a, mod);
|
2001-10-03 14:39:16 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
register Functor f = FunctorOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = Yap_GetPredPropByFunc(f, mod);
|
2003-05-01 22:07:11 +01:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(24,RepPredProp(pe));
|
2003-05-01 22:07:11 +01:00
|
|
|
ncl = RepPredProp(pe)->cs.p_code.NOfClauses;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(41,RepPredProp(pe));
|
2003-05-01 22:07:11 +01:00
|
|
|
return (Yap_unify_constant(ARG3, MkIntegerTerm(ncl)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_in_use( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$in_use'(+P,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$in_use");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(25,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
out = static_in_use(pe,TRUE);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(42,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_new_multifile( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$new_multifile'(+N,+Ar,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
int arity;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG3);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
else
|
|
|
|
return (FALSE);
|
|
|
|
t = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsIntTerm(t))
|
|
|
|
arity = IntOfTerm(t);
|
|
|
|
else
|
2005-02-08 04:05:39 +00:00
|
|
|
return FALSE;
|
2001-11-15 00:01:43 +00:00
|
|
|
if (arity == 0)
|
|
|
|
pe = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity),mod));
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(26,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags |= MultiFileFlag;
|
2011-09-07 21:04:42 +01:00
|
|
|
/* mutifile-predicates are weird, they do not seat really on the default module */
|
|
|
|
if (pe->ModuleOfPred == PROLOG_MODULE)
|
|
|
|
pe->ModuleOfPred = TermProlog;
|
2003-11-26 18:36:35 +00:00
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
|
|
|
/* static */
|
2003-12-04 18:13:04 +00:00
|
|
|
pe->PredFlags |= (SourcePredFlag|CompiledPredFlag);
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(43,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_multifile( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$is_multifile'(+S,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_multifile");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(27,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
out = (pe->PredFlags & MultiFileFlag);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(44,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_log_updatable( USES_REGS1 )
|
2003-08-27 14:37:10 +01:00
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_log_updatable");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(27,pe);
|
2003-08-27 14:37:10 +01:00
|
|
|
out = (pe->PredFlags & LogUpdatePredFlag);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(45,pe);
|
2003-08-27 14:37:10 +01:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_source( USES_REGS1 )
|
2003-11-21 16:56:20 +00:00
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(28,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
out = (pe->PredFlags & SourcePredFlag);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(46,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2010-02-28 22:24:51 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_owner_file( USES_REGS1 )
|
2010-02-28 22:24:51 +00:00
|
|
|
{ /* '$owner_file'(+P,M,F) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Atom owner;
|
|
|
|
|
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(29,pe);
|
2010-02-28 22:24:51 +00:00
|
|
|
if (pe->ModuleOfPred == IDB_MODULE) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(47,pe);
|
2010-02-28 22:24:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & MultiFileFlag) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(48,pe);
|
2010-02-28 22:24:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-01 00:06:45 +00:00
|
|
|
owner = pe->src.OwnerFile;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(49,pe);
|
2010-02-28 22:24:51 +00:00
|
|
|
return Yap_unify(ARG3, MkAtomTerm(owner));
|
|
|
|
}
|
|
|
|
|
2008-04-29 00:02:32 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_mk_d( USES_REGS1 )
|
2008-04-29 00:02:32 +01:00
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(30,pe);
|
2008-04-29 00:02:32 +01:00
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
|
|
|
pe->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
}
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(50,pe);
|
2008-04-29 00:02:32 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_dynamic( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_dynamic");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(31,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
out = (pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag));
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(51,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2004-12-05 05:01:45 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_metapredicate( USES_REGS1 )
|
2004-12-05 05:01:45 +00:00
|
|
|
{ /* '$is_metapredicate'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_meta");
|
2004-12-05 05:01:45 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(32,pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
out = (pe->PredFlags & MetaPredFlag);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(52,pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_expandgoalormetapredicate( USES_REGS1 )
|
2004-12-05 05:01:45 +00:00
|
|
|
{ /* '$is_expand_goal_predicate'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
Int out;
|
|
|
|
|
|
|
|
if (PRED_GOAL_EXPANSION_ALL)
|
|
|
|
return TRUE;
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
|
|
|
if (EndOfPAEntr(pe)) {
|
|
|
|
if (PRED_GOAL_EXPANSION_FUNC) {
|
|
|
|
Prop p1 = RepAtom(at)->PropsOfAE;
|
|
|
|
|
|
|
|
while (p1) {
|
|
|
|
PredEntry *pe = RepPredProp(p1);
|
|
|
|
|
|
|
|
if (pe->KindOfPE == PEProp) {
|
|
|
|
if (pe->PredFlags & GoalExPredFlag) {
|
|
|
|
PredPropByAtom(at, mod);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p1 = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2005-06-08 01:35:27 +01:00
|
|
|
|
|
|
|
if (IsExtensionFunctor(fun)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-05 05:01:45 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
|
|
|
if (EndOfPAEntr(pe)) {
|
|
|
|
if (PRED_GOAL_EXPANSION_FUNC) {
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)fun;
|
|
|
|
if (fe->PropsOfFE &&
|
|
|
|
(RepPredProp(fe->PropsOfFE)->PredFlags & GoalExPredFlag)) {
|
|
|
|
PredPropByFunc(fun, mod);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(33,pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
out = (pe->PredFlags & (GoalExPredFlag|MetaPredFlag));
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(53,pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2002-10-14 17:25:38 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_pred_exists( USES_REGS1 )
|
2002-10-14 17:25:38 +01:00
|
|
|
{ /* '$pred_exists'(+P,+M) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$exists");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(34,pe);
|
2004-02-22 00:35:07 +00:00
|
|
|
if (pe->PredFlags & HiddenPredFlag){
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(54,pe);
|
2004-02-22 00:35:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-10-14 17:25:38 +01:00
|
|
|
out = (pe->OpcodeOfPred != UNDEF_OPCODE);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(55,pe);
|
2004-02-22 00:35:07 +00:00
|
|
|
return out;
|
2002-10-14 17:25:38 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_set_pred_module( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$set_pred_module'(+P,+Mod) */
|
|
|
|
PredEntry *pe;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred(Deref(ARG1), CurrentModule, "set_pred_module/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(35,pe);
|
2004-02-12 12:37:12 +00:00
|
|
|
pe->ModuleOfPred = Deref(ARG2);
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(56,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_undefined( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$undefined'(P,Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2007-11-28 23:52:14 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "undefined/1");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(36,pe);
|
2011-11-09 10:24:39 +00:00
|
|
|
if (pe->PredFlags & (CPredFlag|UserCPredFlag|TestPredFlag|AsmPredFlag|DynamicPredFlag|LogUpdatePredFlag|TabledPredFlag)) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(57,pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(58,pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(59,pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this predicate should only be called when all clauses for the dynamic
|
|
|
|
* predicate were remove, otherwise chaos will follow!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_kill_dynamic( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$kill_dynamic'(P,M) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2007-11-28 23:52:14 +00:00
|
|
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "kill_dynamic/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(37,pe);
|
2003-11-26 18:36:35 +00:00
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(60,pe);
|
2008-04-29 00:02:32 +01:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.LastClause != pe->cs.p_code.FirstClause) {
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(61,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
pe->cs.p_code.LastClause = pe->cs.p_code.FirstClause = NULL;
|
2008-06-02 18:20:28 +01:00
|
|
|
pe->OpcodeOfPred = UNDEF_OPCODE;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
2004-12-05 05:01:45 +00:00
|
|
|
pe->PredFlags = pe->PredFlags & GoalExPredFlag;
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(62,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_optimizer_on( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$optimizer_on' */
|
|
|
|
optimizer_on = TRUE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_optimizer_off( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$optimizer_off' */
|
|
|
|
optimizer_on = FALSE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_compile_mode( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* $compile_mode(Old,New) */
|
|
|
|
Term t2, t3 = MkIntTerm(compile_mode);
|
2002-11-18 18:18:05 +00:00
|
|
|
if (!Yap_unify_constant(ARG1, t3))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t2) || !IsIntTerm(t2))
|
|
|
|
return (FALSE);
|
|
|
|
compile_mode = IntOfTerm(t2) & 1;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
2003-04-30 18:46:05 +01:00
|
|
|
static yamop *cur_clause(PredEntry *pe, yamop *codeptr)
|
2002-02-26 20:16:36 +00:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
StaticClause *cl;
|
2003-11-26 18:36:35 +00:00
|
|
|
|
|
|
|
cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause);
|
2002-02-26 20:16:36 +00:00
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,cl,cl->ClSize)) {
|
2003-11-26 18:36:35 +00:00
|
|
|
return cl->ClCode;
|
2002-02-26 20:16:36 +00:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pe->cs.p_code.LastClause)
|
2003-04-30 18:46:05 +01:00
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = cl->ClNext;
|
2002-02-26 20:16:36 +00:00
|
|
|
} while (TRUE);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"could not find clause for indexing code");
|
2002-02-26 20:16:36 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-30 18:46:05 +01:00
|
|
|
static yamop *cur_log_upd_clause(PredEntry *pe, yamop *codeptr)
|
2002-02-26 20:16:36 +00:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
LogUpdClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause);
|
2002-02-26 20:16:36 +00:00
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,cl->ClCode,cl->ClSize)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
return((yamop *)cl->ClCode);
|
2002-02-26 20:16:36 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"could not find clause for indexing code");
|
2002-02-26 20:16:36 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
search_for_static_predicate_in_use(PredEntry *p, int check_everything)
|
|
|
|
{
|
|
|
|
choiceptr b_ptr = B;
|
|
|
|
CELL *env_ptr = ENV;
|
|
|
|
|
2004-05-13 22:36:45 +01:00
|
|
|
if (check_everything && P) {
|
2003-02-11 16:33:24 +00:00
|
|
|
PredEntry *pe = EnvPreg(P);
|
2004-05-13 22:36:45 +01:00
|
|
|
if (p == pe) return TRUE;
|
2003-02-11 16:33:24 +00:00
|
|
|
pe = EnvPreg(CP);
|
2004-05-13 22:36:45 +01:00
|
|
|
if (p == pe) return TRUE;
|
2003-02-11 16:33:24 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
2004-09-27 21:45:04 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check first environments that are younger than our latest choicepoint */
|
2004-06-05 04:37:01 +01:00
|
|
|
if (check_everything && env_ptr) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
|
|
|
I do not need to check environments for asserts,
|
|
|
|
only for retracts
|
|
|
|
*/
|
2004-06-05 04:37:01 +01:00
|
|
|
while (env_ptr && b_ptr > (choiceptr)env_ptr) {
|
2010-06-01 00:40:58 +01:00
|
|
|
yamop *cp = (yamop *)env_ptr[E_CP];
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
pe = EnvPreg(cp);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (p == pe) return(TRUE);
|
|
|
|
if (env_ptr != NULL)
|
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now mark the choicepoint */
|
2004-09-27 21:45:04 +01:00
|
|
|
|
2004-10-26 21:16:18 +01:00
|
|
|
if (b_ptr)
|
|
|
|
pe = PredForChoicePt(b_ptr->cp_ap);
|
|
|
|
else
|
2004-10-28 21:12:23 +01:00
|
|
|
return FALSE;
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe == p) {
|
|
|
|
if (check_everything)
|
|
|
|
return TRUE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(38,p);
|
2004-09-27 21:45:04 +01:00
|
|
|
if (p->PredFlags & IndexedPredFlag) {
|
|
|
|
yamop *code_p = b_ptr->cp_ap;
|
|
|
|
yamop *code_beg = p->cs.p_code.TrueCodeOfPred;
|
|
|
|
|
|
|
|
/* FIX ME */
|
|
|
|
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(code_beg);
|
|
|
|
if (find_owner_log_index(cl, code_p))
|
2008-09-05 05:22:19 +01:00
|
|
|
b_ptr->cp_ap = cur_log_upd_clause(pe, b_ptr->cp_ap->u.Otapl.d);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else if (p->PredFlags & MegaClausePredFlag) {
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(code_beg);
|
|
|
|
if (find_owner_static_index(cl, code_p))
|
2008-09-05 05:22:19 +01:00
|
|
|
b_ptr->cp_ap = cur_clause(pe, b_ptr->cp_ap->u.Otapl.d);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
|
|
|
/* static clause */
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(code_beg);
|
|
|
|
if (find_owner_static_index(cl, code_p)) {
|
2008-09-05 05:22:19 +01:00
|
|
|
b_ptr->cp_ap = cur_clause(pe, b_ptr->cp_ap->u.Otapl.d);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
2010-07-28 11:26:20 +01:00
|
|
|
UNLOCKPE(63,pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
env_ptr = b_ptr->cp_env;
|
|
|
|
b_ptr = b_ptr->cp_b;
|
2001-04-09 20:54:03 +01:00
|
|
|
} while (b_ptr != NULL);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2002-02-26 17:49:09 +00:00
|
|
|
static void
|
|
|
|
mark_pred(int mark, PredEntry *pe)
|
|
|
|
{
|
|
|
|
/* if the predicate is static mark it */
|
|
|
|
if (pe->ModuleOfPred) {
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(39,p);
|
2002-02-26 17:49:09 +00:00
|
|
|
if (mark) {
|
2003-04-30 18:46:05 +01:00
|
|
|
pe->PredFlags |= InUsePredFlag;
|
2002-02-26 17:49:09 +00:00
|
|
|
} else {
|
2003-04-30 18:46:05 +01:00
|
|
|
pe->PredFlags &= ~InUsePredFlag;
|
2002-02-26 15:51:54 +00:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2002-02-26 15:51:54 +00:00
|
|
|
}
|
2002-02-26 17:49:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* go up the chain of choice_points and environments,
|
|
|
|
marking all static predicates that current execution is depending
|
|
|
|
upon */
|
|
|
|
static void
|
|
|
|
do_toggle_static_predicates_in_use(int mask)
|
|
|
|
{
|
|
|
|
choiceptr b_ptr = B;
|
|
|
|
CELL *env_ptr = ENV;
|
|
|
|
|
|
|
|
if (b_ptr == NULL)
|
|
|
|
return;
|
2002-02-26 15:51:54 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
2001-12-12 19:36:51 +00:00
|
|
|
PredEntry *pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check first environments that are younger than our latest choicepoint */
|
|
|
|
while (b_ptr > (choiceptr)env_ptr) {
|
2008-08-29 17:27:11 +01:00
|
|
|
PredEntry *pe = EnvPreg((yamop *)env_ptr[E_CP]);
|
2002-02-26 15:51:54 +00:00
|
|
|
|
2002-02-26 17:49:09 +00:00
|
|
|
mark_pred(mask, pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
/* now mark the choicepoint */
|
2004-10-26 21:16:18 +01:00
|
|
|
if ((b_ptr)) {
|
2004-10-28 21:12:23 +01:00
|
|
|
if ((pe = PredForChoicePt(b_ptr->cp_ap))) {
|
2001-04-09 20:54:03 +01:00
|
|
|
mark_pred(mask, pe);
|
2004-10-26 21:16:18 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
env_ptr = b_ptr->cp_env;
|
|
|
|
b_ptr = b_ptr->cp_b;
|
2001-04-09 20:54:03 +01:00
|
|
|
} while (b_ptr != NULL);
|
2001-12-12 19:36:51 +00:00
|
|
|
/* mark or unmark all predicates */
|
|
|
|
STATIC_PREDICATES_MARKED = mask;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
#endif /* !defined(YAPOR) && !defined(THREADS) */
|
|
|
|
|
|
|
|
static LogUpdIndex *
|
|
|
|
find_owner_log_index(LogUpdIndex *cl, yamop *code_p)
|
|
|
|
{
|
|
|
|
yamop *code_beg = cl->ClCode;
|
|
|
|
yamop *code_end = (yamop *)((char *)cl + cl->ClSize);
|
|
|
|
|
|
|
|
if (code_p >= code_beg && code_p <= code_end) {
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
LogUpdIndex *out;
|
|
|
|
if ((out = find_owner_log_index(cl, code_p)) != NULL) {
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static StaticIndex *
|
|
|
|
find_owner_static_index(StaticIndex *cl, yamop *code_p)
|
|
|
|
{
|
|
|
|
yamop *code_beg = cl->ClCode;
|
|
|
|
yamop *code_end = (yamop *)((char *)cl + cl->ClSize);
|
|
|
|
|
|
|
|
if (code_p >= code_beg && code_p <= code_end) {
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
StaticIndex *out;
|
|
|
|
if ((out = find_owner_static_index(cl, code_p)) != NULL) {
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClauseUnion *
|
|
|
|
Yap_find_owner_index(yamop *ipc, PredEntry *ap)
|
|
|
|
{
|
|
|
|
/* we assume we have an owner index */
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
return (ClauseUnion *)find_owner_log_index(cl,ipc);
|
|
|
|
} else {
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
return (ClauseUnion *)find_owner_static_index(cl,ipc);
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-26 22:28:32 +00:00
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
all_envs(CELL *env_ptr USES_REGS)
|
2002-11-26 22:28:32 +00:00
|
|
|
{
|
2002-12-10 14:36:22 +00:00
|
|
|
Term tf = AbsPair(H);
|
2010-04-29 10:29:06 +01:00
|
|
|
CELL *start = H;
|
2002-11-26 22:28:32 +00:00
|
|
|
CELL *bp = NULL;
|
2002-12-10 14:36:22 +00:00
|
|
|
|
2002-11-26 22:28:32 +00:00
|
|
|
/* walk the environment chain */
|
2010-04-29 10:29:06 +01:00
|
|
|
while (env_ptr) {
|
2002-11-26 22:28:32 +00:00
|
|
|
bp = H;
|
|
|
|
H += 2;
|
|
|
|
/* notice that MkIntegerTerm may increase the Heap */
|
2007-01-24 10:01:40 +00:00
|
|
|
bp[0] = MkIntegerTerm(LCL0-env_ptr);
|
2010-04-29 10:29:06 +01:00
|
|
|
if (H >= ASP-1024) {
|
|
|
|
H = start;
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_Size = (ASP-1024)-H;
|
2010-04-29 10:29:06 +01:00
|
|
|
while (env_ptr) {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_Size += 2;
|
2010-04-29 10:29:06 +01:00
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
return 0L;
|
2002-11-26 22:28:32 +00:00
|
|
|
} else {
|
|
|
|
bp[1] = AbsPair(H);
|
|
|
|
}
|
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
all_cps(choiceptr b_ptr USES_REGS)
|
2002-12-10 14:36:22 +00:00
|
|
|
{
|
|
|
|
CELL *bp = NULL;
|
2010-04-29 10:29:06 +01:00
|
|
|
CELL *start = H;
|
2002-12-10 14:36:22 +00:00
|
|
|
Term tf = AbsPair(H);
|
|
|
|
|
2010-04-29 10:29:06 +01:00
|
|
|
while (b_ptr) {
|
2002-11-26 22:28:32 +00:00
|
|
|
bp = H;
|
|
|
|
H += 2;
|
|
|
|
/* notice that MkIntegerTerm may increase the Heap */
|
2006-03-06 14:04:57 +00:00
|
|
|
bp[0] = MkIntegerTerm((Int)(LCL0-(CELL *)b_ptr));
|
2010-04-29 10:29:06 +01:00
|
|
|
if (H >= ASP-1024) {
|
|
|
|
H = start;
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_Size = (ASP-1024)-H;
|
2010-04-29 10:29:06 +01:00
|
|
|
while (b_ptr) {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_Size += 2;
|
2010-04-29 10:29:06 +01:00
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
}
|
|
|
|
return 0L;
|
2002-11-26 22:28:32 +00:00
|
|
|
} else {
|
|
|
|
bp[1] = AbsPair(H);
|
|
|
|
}
|
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
}
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
all_calls( USES_REGS1 )
|
2002-12-10 14:36:22 +00:00
|
|
|
{
|
2008-03-22 23:35:00 +00:00
|
|
|
Term ts[4];
|
2010-04-16 02:08:06 +01:00
|
|
|
Functor f = Yap_MkFunctor(AtomLocalSp,4);
|
2002-12-10 14:36:22 +00:00
|
|
|
|
|
|
|
ts[0] = MkIntegerTerm((Int)P);
|
2008-02-22 15:08:37 +00:00
|
|
|
ts[1] = MkIntegerTerm((Int)CP);
|
2002-12-10 14:36:22 +00:00
|
|
|
if (yap_flags[STACK_DUMP_ON_ERROR_FLAG]) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ts[2] = all_envs(ENV PASS_REGS);
|
|
|
|
ts[3] = all_cps(B PASS_REGS);
|
2010-04-29 10:29:06 +01:00
|
|
|
if (ts[2] == 0L ||
|
|
|
|
ts[3] == 0L)
|
|
|
|
return 0L;
|
2002-12-10 14:36:22 +00:00
|
|
|
} else {
|
2008-02-22 15:08:37 +00:00
|
|
|
ts[2] = ts[3] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
}
|
2008-03-24 23:48:47 +00:00
|
|
|
return Yap_MkApplTerm(f,4,ts);
|
2002-11-26 22:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2011-03-07 16:02:55 +00:00
|
|
|
Yap_all_calls( void )
|
2002-11-26 22:28:32 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
return all_calls( PASS_REGS1 );
|
2002-11-26 22:28:32 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 14:04:57 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_all_choicepoints( USES_REGS1 )
|
2006-03-06 14:04:57 +00:00
|
|
|
{
|
2010-04-29 10:29:06 +01:00
|
|
|
Term t;
|
2011-03-07 16:02:55 +00:00
|
|
|
while ((t = all_cps(B PASS_REGS)) == 0L) {
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
|
2010-04-29 10:29:06 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping choicepoints");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG1,t);
|
2006-03-06 14:04:57 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_all_envs( USES_REGS1 )
|
2006-12-13 16:10:26 +00:00
|
|
|
{
|
2010-04-29 10:29:06 +01:00
|
|
|
Term t;
|
2011-03-07 16:02:55 +00:00
|
|
|
while ((t = all_envs(ENV PASS_REGS)) == 0L) {
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
|
2010-04-29 10:29:06 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping environments");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG1,t);
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 23:14:29 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_current_stack( USES_REGS1 )
|
2002-10-21 23:14:29 +01:00
|
|
|
{
|
2010-04-29 10:29:06 +01:00
|
|
|
Term t;
|
2011-03-07 16:02:55 +00:00
|
|
|
while ((t = all_calls( PASS_REGS1 )) == 0L) {
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
|
2010-04-29 10:29:06 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping stack");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG1,t);
|
2002-10-21 23:14:29 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* This predicate is to be used by reconsult to mark all predicates
|
|
|
|
currently in use as being executed.
|
|
|
|
|
|
|
|
The idea is to go up the chain of choice_points and environments.
|
|
|
|
|
|
|
|
*/
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_toggle_static_predicates_in_use( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Int mask;
|
|
|
|
|
|
|
|
/* find out whether we need to mark or unmark */
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"toggle_static_predicates_in_use/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t,"toggle_static_predicates_in_use/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else {
|
|
|
|
mask = IntOfTerm(t);
|
|
|
|
}
|
|
|
|
do_toggle_static_predicates_in_use(mask);
|
|
|
|
#endif
|
2006-03-24 16:26:31 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
2004-09-03 04:11:09 +01:00
|
|
|
clause_was_found(PredEntry *pp, Atom *pat, UInt *parity) {
|
|
|
|
if (pp->ModuleOfPred == IDB_MODULE) {
|
|
|
|
if (pp->PredFlags & NumberDBPredFlag) {
|
|
|
|
*parity = 0;
|
2008-12-23 01:53:52 +00:00
|
|
|
*pat = AtomInteger;
|
2004-09-03 04:11:09 +01:00
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
|
|
|
*parity = 0;
|
|
|
|
*pat = (Atom)pp->FunctorOfPred;
|
|
|
|
} else {
|
|
|
|
*pat = NameOfFunctor(pp->FunctorOfPred);
|
|
|
|
*parity = ArityOfFunctor(pp->FunctorOfPred);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2004-09-03 04:11:09 +01:00
|
|
|
*parity = pp->ArityOfPE;
|
|
|
|
if (pp->ArityOfPE) {
|
|
|
|
*pat = NameOfFunctor(pp->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
*pat = (Atom)(pp->FunctorOfPred);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-12-02 00:36:27 +00:00
|
|
|
static void
|
|
|
|
code_in_pred_info(PredEntry *pp, Atom *pat, UInt *parity) {
|
2004-09-03 04:11:09 +01:00
|
|
|
clause_was_found(pp, pat, parity);
|
2003-12-02 00:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-12-17 03:25:39 +00:00
|
|
|
code_in_pred_lu_index(LogUpdIndex *icl, yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
|
2003-12-02 00:36:27 +00:00
|
|
|
LogUpdIndex *cicl;
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,icl,icl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp) *startp = (CODEADDR)icl;
|
|
|
|
if (endp) *endp = (CODEADDR)icl+icl->ClSize;
|
2003-12-02 00:36:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cicl = icl->ChildIndex;
|
|
|
|
while (cicl != NULL) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (code_in_pred_lu_index(cicl, codeptr, startp, endp))
|
2003-12-02 00:36:27 +00:00
|
|
|
return TRUE;
|
|
|
|
cicl = cicl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-12-17 03:25:39 +00:00
|
|
|
code_in_pred_s_index(StaticIndex *icl, yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
|
2003-12-02 00:36:27 +00:00
|
|
|
StaticIndex *cicl;
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,icl,icl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp) *startp = (CODEADDR)icl;
|
|
|
|
if (endp) *endp = (CODEADDR)icl+icl->ClSize;
|
2003-12-02 00:36:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cicl = icl->ChildIndex;
|
|
|
|
while (cicl != NULL) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (code_in_pred_s_index(cicl, codeptr, startp, endp))
|
2003-12-02 00:36:27 +00:00
|
|
|
return TRUE;
|
|
|
|
cicl = cicl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2005-12-17 03:25:39 +00:00
|
|
|
find_code_in_clause(PredEntry *pp, yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
|
2005-02-08 18:05:21 +00:00
|
|
|
Int i = 1;
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *clcode;
|
2001-12-11 19:12:41 +00:00
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
clcode = pp->cs.p_code.FirstClause;
|
2003-04-30 18:46:05 +01:00
|
|
|
if (clcode != NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode);
|
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,(CODEADDR)cl,cl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp)
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
if (endp)
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
2003-08-27 14:37:10 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
DynamicClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2004-03-05 15:26:33 +00:00
|
|
|
cl = ClauseCodeToDynamicClause(clcode);
|
|
|
|
if (IN_BLOCK(codeptr,cl,cl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp)
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
if (endp)
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
2003-08-27 14:37:10 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (clcode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
i++;
|
2003-11-26 18:36:35 +00:00
|
|
|
clcode = NextDynamicClause(clcode);
|
|
|
|
} while (TRUE);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else if (pp->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *cl;
|
|
|
|
|
|
|
|
cl = ClauseCodeToMegaClause(clcode);
|
|
|
|
if (IN_BLOCK(codeptr,cl,cl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp)
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
if (endp)
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
return 1+((char *)codeptr-(char *)cl->ClCode)/cl->ClItemSize;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
|
|
|
StaticClause *cl;
|
|
|
|
|
|
|
|
cl = ClauseCodeToStaticClause(clcode);
|
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
if (IN_BLOCK(codeptr,cl,cl->ClSize)) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (startp)
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
if (endp)
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (cl->ClCode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-12-17 03:25:39 +00:00
|
|
|
static int
|
|
|
|
cl_code_in_pred(PredEntry *pp, yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
|
|
|
|
Int out;
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(39,pp);
|
2005-12-17 03:25:39 +00:00
|
|
|
/* check if the codeptr comes from the indexing code */
|
|
|
|
if (pp->PredFlags & IndexedPredFlag) {
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
if (code_in_pred_lu_index(ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, startp, endp)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-12-17 03:25:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (code_in_pred_s_index(ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, startp, endp)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-12-17 03:25:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pp->PredFlags & (CPredFlag|AsmPredFlag|UserCPredFlag)) {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pp->CodeOfPred);
|
|
|
|
if (IN_BLOCK(codeptr,(CODEADDR)cl,cl->ClSize)) {
|
|
|
|
if (startp)
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
if (endp)
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-12-17 03:25:39 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-12-17 03:25:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out = find_code_in_clause(pp, codeptr, startp, endp);
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-12-17 03:25:39 +00:00
|
|
|
if (out) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-08 18:05:21 +00:00
|
|
|
static Int
|
|
|
|
code_in_pred(PredEntry *pp, Atom *pat, UInt *parity, yamop *codeptr) {
|
|
|
|
Int out;
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(40,pp);
|
2005-02-08 18:05:21 +00:00
|
|
|
/* check if the codeptr comes from the indexing code */
|
|
|
|
if (pp->PredFlags & IndexedPredFlag) {
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (code_in_pred_lu_index(ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, NULL, NULL)) {
|
2005-02-08 18:05:21 +00:00
|
|
|
code_in_pred_info(pp, pat, parity);
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-02-08 18:05:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (code_in_pred_s_index(ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, NULL, NULL)) {
|
2005-02-08 18:05:21 +00:00
|
|
|
code_in_pred_info(pp, pat, parity);
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-02-08 18:05:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-17 03:25:39 +00:00
|
|
|
if ((out = find_code_in_clause(pp, codeptr, NULL, NULL))) {
|
|
|
|
clause_was_found(pp, pat, parity);
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2005-02-08 18:05:21 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
PredForCode(yamop *codeptr, Atom *pat, UInt *parity, Term *pmodule) {
|
2001-12-12 19:36:51 +00:00
|
|
|
Int found = 0;
|
2007-04-10 23:13:21 +01:00
|
|
|
ModEntry *me = CurrentModules;
|
2001-12-11 19:12:41 +00:00
|
|
|
|
2001-12-12 19:36:51 +00:00
|
|
|
/* should we allow the user to see hidden predicates? */
|
2007-04-10 23:13:21 +01:00
|
|
|
while (me) {
|
2004-09-03 04:11:09 +01:00
|
|
|
|
|
|
|
PredEntry *pp;
|
2007-04-10 23:13:21 +01:00
|
|
|
pp = me->PredForME;
|
2001-12-11 19:12:41 +00:00
|
|
|
while (pp != NULL) {
|
|
|
|
if ((found = code_in_pred(pp, pat, parity, codeptr)) != 0) {
|
2007-04-10 23:13:21 +01:00
|
|
|
*pmodule = MkAtomTerm(me->AtomOfME);
|
|
|
|
return found;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-12-11 19:12:41 +00:00
|
|
|
pp = pp->NextPredOfModule;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
2007-04-10 23:13:21 +01:00
|
|
|
me = me->NextME;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
2001-12-12 19:36:51 +00:00
|
|
|
return(0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Int
|
2004-10-26 21:16:18 +01:00
|
|
|
Yap_PredForCode(yamop *codeptr, find_pred_type where_from, Atom *pat, UInt *parity, Term *pmodule) {
|
|
|
|
PredEntry *p;
|
|
|
|
|
|
|
|
if (where_from == FIND_PRED_FROM_CP) {
|
|
|
|
p = PredForChoicePt(codeptr);
|
|
|
|
} else if (where_from == FIND_PRED_FROM_ENV) {
|
|
|
|
p = EnvPreg(codeptr);
|
2005-02-08 18:05:21 +00:00
|
|
|
if (p) {
|
2005-12-17 03:25:39 +00:00
|
|
|
Int out;
|
2005-02-08 18:05:21 +00:00
|
|
|
if (p->ModuleOfPred == PROLOG_MODULE)
|
2007-04-10 23:13:21 +01:00
|
|
|
*pmodule = TermProlog;
|
2005-02-08 18:05:21 +00:00
|
|
|
else
|
|
|
|
*pmodule = p->ModuleOfPred;
|
2005-12-17 03:25:39 +00:00
|
|
|
out = find_code_in_clause(p, codeptr, NULL, NULL);
|
|
|
|
clause_was_found(p, pat, parity);
|
|
|
|
return out;
|
2005-02-08 18:05:21 +00:00
|
|
|
}
|
2004-10-26 21:16:18 +01:00
|
|
|
} else {
|
|
|
|
return PredForCode(codeptr, pat, parity, pmodule);
|
|
|
|
}
|
|
|
|
if (p == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
clause_was_found(p, pat, parity);
|
|
|
|
if (p->ModuleOfPred == PROLOG_MODULE)
|
2007-04-10 23:13:21 +01:00
|
|
|
*pmodule = TermProlog;
|
2004-10-26 21:16:18 +01:00
|
|
|
else
|
|
|
|
*pmodule = p->ModuleOfPred;
|
|
|
|
return -1;
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-24 09:04:44 +00:00
|
|
|
/* intruction blocks we found ourselves at */
|
|
|
|
static PredEntry *
|
|
|
|
walk_got_lu_block(LogUpdIndex *cl, CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
|
|
|
PredEntry *pp = cl->ClPred;
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* intruction blocks we found ourselves at */
|
|
|
|
static PredEntry *
|
|
|
|
walk_got_lu_clause(LogUpdClause *cl, CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
return cl->ClPred;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we hit a meta-call, so we don't know what is happening */
|
|
|
|
static PredEntry *
|
|
|
|
found_meta_call(CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
2009-02-26 00:00:23 +00:00
|
|
|
PredEntry *pp = PredMetaCall;
|
2008-12-24 09:04:44 +00:00
|
|
|
*startp = (CODEADDR)&(pp->OpcodeOfPred);
|
|
|
|
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred),e);
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
2009-02-26 00:00:23 +00:00
|
|
|
/* intruction blocks we found ourselves at */
|
|
|
|
static PredEntry *
|
|
|
|
walk_found_c_pred(PredEntry *pp, CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pp->CodeOfPred);
|
|
|
|
*startp = (CODEADDR)&(cl->ClCode);
|
|
|
|
*endp = (CODEADDR)&(cl->ClCode)+cl->ClSize;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
2008-12-24 09:04:44 +00:00
|
|
|
/* we hit a mega-clause, no point in going on */
|
|
|
|
static PredEntry *
|
|
|
|
found_mega_clause(PredEntry *pp, CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
|
|
|
|
*startp = (CODEADDR)mcl;
|
|
|
|
*endp = (CODEADDR)mcl+mcl->ClSize;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we hit a mega-clause, no point in going on */
|
|
|
|
static PredEntry *
|
|
|
|
found_idb_clause(yamop *pc, CODEADDR *startp, CODEADDR *endp)
|
|
|
|
{
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(pc);
|
|
|
|
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
return cl->ClPred;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we hit a expand_index, no point in going on */
|
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
found_expand_index(yamop *pc, CODEADDR *startp, CODEADDR *endp, yamop *codeptr USES_REGS)
|
2008-12-24 09:04:44 +00:00
|
|
|
{
|
2009-02-25 22:15:18 +00:00
|
|
|
PredEntry *pp = codeptr->u.sssllp.p;
|
2008-12-24 09:04:44 +00:00
|
|
|
if (pc == codeptr) {
|
2009-02-25 22:15:18 +00:00
|
|
|
*startp = (CODEADDR)codeptr;
|
|
|
|
*endp = (CODEADDR)NEXTOP(codeptr,sssllp);
|
2008-12-24 09:04:44 +00:00
|
|
|
}
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we hit a expand_index, no point in going on */
|
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
found_fail(yamop *pc, CODEADDR *startp, CODEADDR *endp USES_REGS)
|
2008-12-24 09:04:44 +00:00
|
|
|
{
|
|
|
|
PredEntry *pp = RepPredProp(Yap_GetPredPropByAtom(AtomFail,CurrentModule));
|
|
|
|
*startp = *endp = (CODEADDR)FAILCODE;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we hit a expand_index, no point in going on */
|
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
found_owner_op(yamop *pc, CODEADDR *startp, CODEADDR *endp USES_REGS)
|
2008-12-24 09:04:44 +00:00
|
|
|
{
|
|
|
|
PredEntry *pp = ((PredEntry *)(Unsigned(pc)-(CELL)(&(((PredEntry *)NULL)->OpcodeOfPred))));
|
|
|
|
*startp = (CODEADDR)&(pp->OpcodeOfPred);
|
|
|
|
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred),e);
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
2009-02-25 22:15:18 +00:00
|
|
|
/* we hit a expand_index, no point in going on */
|
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
found_expand(yamop *pc, CODEADDR *startp, CODEADDR *endp USES_REGS)
|
2009-02-25 22:15:18 +00:00
|
|
|
{
|
|
|
|
PredEntry *pp = ((PredEntry *)(Unsigned(pc)-(CELL)(&(((PredEntry *)NULL)->cs.p_code.ExpandCode))));
|
|
|
|
*startp = (CODEADDR)&(pp->cs.p_code.ExpandCode);
|
|
|
|
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->cs.p_code.ExpandCode),e);
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
2008-12-24 09:04:44 +00:00
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
found_ystop(yamop *pc, int clause_code, CODEADDR *startp, CODEADDR *endp, PredEntry *pp USES_REGS)
|
2008-12-24 09:04:44 +00:00
|
|
|
{
|
|
|
|
if (pc == YESCODE) {
|
|
|
|
pp = RepPredProp(Yap_GetPredPropByAtom(AtomTrue,CurrentModule));
|
|
|
|
*startp = (CODEADDR)YESCODE;
|
|
|
|
*endp = (CODEADDR)YESCODE+(CELL)(NEXTOP((yamop *)NULL,e));
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
if (!pp) {
|
|
|
|
/* must be an index */
|
|
|
|
PredEntry **pep = (PredEntry **)pc->u.l.l;
|
|
|
|
pp = pep[-1];
|
|
|
|
}
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
if (clause_code) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(pc->u.l.l);
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
} else {
|
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(pc->u.l.l);
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
}
|
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
|
|
|
DynamicClause *cl = ClauseCodeToDynamicClause(pc->u.l.l);
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
} else {
|
|
|
|
if (clause_code) {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pc->u.l.l);
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
} else {
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(pc->u.l.l);
|
|
|
|
*startp = (CODEADDR)cl;
|
|
|
|
*endp = (CODEADDR)cl+cl->ClSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
2005-12-17 03:25:39 +00:00
|
|
|
static PredEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp USES_REGS) {
|
2005-12-17 03:25:39 +00:00
|
|
|
yamop *pc;
|
|
|
|
PredEntry *pp = NULL;
|
|
|
|
int clause_code = FALSE;
|
|
|
|
|
|
|
|
if (codeptr >= COMMA_CODE &&
|
|
|
|
codeptr < FAILCODE) {
|
|
|
|
pp = RepPredProp(Yap_GetPredPropByFunc(FunctorComma,CurrentModule));
|
|
|
|
*startp = (CODEADDR)COMMA_CODE;
|
|
|
|
*endp = (CODEADDR)(FAILCODE-1);
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
pc = codeptr;
|
2008-12-24 09:04:44 +00:00
|
|
|
#include "walkclause.h"
|
2005-12-17 03:25:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PredEntry *
|
|
|
|
Yap_PredEntryForCode(yamop *codeptr, find_pred_type where_from, CODEADDR *startp, CODEADDR *endp) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2005-12-17 03:25:39 +00:00
|
|
|
if (where_from == FIND_PRED_FROM_CP) {
|
|
|
|
PredEntry *pp = PredForChoicePt(codeptr);
|
|
|
|
if (cl_code_in_pred(pp, codeptr, startp, endp)) {
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
} else if (where_from == FIND_PRED_FROM_ENV) {
|
|
|
|
PredEntry *pp = EnvPreg(codeptr);
|
|
|
|
if (cl_code_in_pred(pp, codeptr, startp, endp)) {
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-07 16:02:55 +00:00
|
|
|
return ClauseInfoForCode(codeptr, startp, endp PASS_REGS);
|
2005-12-17 03:25:39 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
|
2002-09-09 18:40:12 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_pred_for_code( USES_REGS1 ) {
|
2003-12-02 00:36:27 +00:00
|
|
|
yamop *codeptr;
|
2002-09-09 18:40:12 +01:00
|
|
|
Atom at;
|
|
|
|
UInt arity;
|
2006-03-24 16:26:31 +00:00
|
|
|
Term tmodule = TermProlog;
|
2002-09-09 18:40:12 +01:00
|
|
|
Int cl;
|
2003-12-02 00:36:27 +00:00
|
|
|
Term t = Deref(ARG1);
|
2002-09-09 18:40:12 +01:00
|
|
|
|
2003-12-02 00:36:27 +00:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return FALSE;
|
2004-09-27 21:45:04 +01:00
|
|
|
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorStaticClause) {
|
|
|
|
codeptr = Yap_ClauseFromTerm(t)->ClCode;
|
2003-12-02 00:36:27 +00:00
|
|
|
} else if (IsIntegerTerm(t)) {
|
|
|
|
codeptr = (yamop *)IntegerOfTerm(t);
|
|
|
|
} else if (IsDBRefTerm(t)) {
|
|
|
|
codeptr = (yamop *)DBRefOfTerm(t);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-03-24 16:26:31 +00:00
|
|
|
cl = PredForCode(codeptr, &at, &arity, &tmodule);
|
|
|
|
if (!tmodule) tmodule = TermProlog;
|
2003-12-02 00:36:27 +00:00
|
|
|
if (cl == 0) {
|
2006-03-24 16:26:31 +00:00
|
|
|
return Yap_unify(ARG5,MkIntTerm(0));
|
2003-12-02 00:36:27 +00:00
|
|
|
} else {
|
|
|
|
return(Yap_unify(ARG2,MkAtomTerm(at)) &&
|
|
|
|
Yap_unify(ARG3,MkIntegerTerm(arity)) &&
|
2006-03-24 16:26:31 +00:00
|
|
|
Yap_unify(ARG4,tmodule) &&
|
2003-12-02 00:36:27 +00:00
|
|
|
Yap_unify(ARG5,MkIntegerTerm(cl)));
|
|
|
|
}
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_profiled( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
if (PROFILING) ta = MkAtomTerm(AtomOn);
|
|
|
|
else ta = MkAtomTerm(AtomOff);
|
2011-03-18 19:34:58 +00:00
|
|
|
Bind((CELL *)t,ta);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (!IsAtomTerm(t)) return(FALSE);
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
if (strcmp(s,"on") == 0) {
|
|
|
|
PROFILING = TRUE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (strcmp(s,"off") == 0) {
|
|
|
|
PROFILING = FALSE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_profile_info( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tfun = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
Term out;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term p[3];
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (IsVarTerm(tfun)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsAtomTerm(tfun)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
LOCK(pe->StatisticsForPred.lock);
|
|
|
|
if (!(pe->StatisticsForPred.NOfEntries)) {
|
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2003-03-20 15:10:18 +00:00
|
|
|
p[0] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfEntries);
|
|
|
|
p[1] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfHeadSuccesses);
|
|
|
|
p[2] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfRetries);
|
2001-04-09 20:54:03 +01:00
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_MkApplTerm(Yap_MkFunctor(AtomProfile,3),3,p);
|
|
|
|
return(Yap_unify(ARG3,out));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_profile_reset( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tfun = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
if (IsVarTerm(tfun)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsAtomTerm(tfun)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
LOCK(pe->StatisticsForPred.lock);
|
|
|
|
pe->StatisticsForPred.NOfEntries = 0;
|
|
|
|
pe->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
pe->StatisticsForPred.NOfRetries = 0;
|
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-09-03 15:28:09 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_is_call_counted( USES_REGS1 )
|
2002-09-03 15:28:09 +01:00
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
if (CALL_COUNTING) ta = MkAtomTerm(AtomOn);
|
|
|
|
else ta = MkAtomTerm(AtomOff);
|
2011-03-18 19:34:58 +00:00
|
|
|
Bind((CELL *)t,ta);
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (!IsAtomTerm(t)) return(FALSE);
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
if (strcmp(s,"on") == 0) {
|
|
|
|
CALL_COUNTING = TRUE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (strcmp(s,"off") == 0) {
|
|
|
|
CALL_COUNTING = FALSE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_call_count_info( USES_REGS1 )
|
2002-09-03 15:28:09 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
return(Yap_unify(MkIntegerTerm(LOCAL_ReductionsCounter),ARG1) &&
|
|
|
|
Yap_unify(MkIntegerTerm(LOCAL_PredEntriesCounter),ARG2) &&
|
|
|
|
Yap_unify(MkIntegerTerm(LOCAL_PredEntriesCounter),ARG3));
|
2002-09-03 15:28:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_call_count_reset( USES_REGS1 )
|
2002-09-03 15:28:09 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ReductionsCounter = 0;
|
|
|
|
LOCAL_ReductionsCounterOn = FALSE;
|
|
|
|
LOCAL_PredEntriesCounter = 0;
|
|
|
|
LOCAL_PredEntriesCounterOn = FALSE;
|
|
|
|
LOCAL_RetriesCounter = 0;
|
|
|
|
LOCAL_RetriesCounterOn = FALSE;
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_call_count_set( USES_REGS1 )
|
2002-09-03 15:28:09 +01:00
|
|
|
{
|
|
|
|
int do_calls = IntOfTerm(ARG2);
|
|
|
|
int do_retries = IntOfTerm(ARG4);
|
|
|
|
int do_entries = IntOfTerm(ARG6);
|
|
|
|
|
|
|
|
if (do_calls)
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ReductionsCounter = IntegerOfTerm(Deref(ARG1));
|
|
|
|
LOCAL_ReductionsCounterOn = do_calls;
|
2002-09-03 15:28:09 +01:00
|
|
|
if (do_retries)
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_RetriesCounter = IntegerOfTerm(Deref(ARG3));
|
|
|
|
LOCAL_RetriesCounterOn = do_retries;
|
2002-09-03 15:28:09 +01:00
|
|
|
if (do_entries)
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_PredEntriesCounter = IntegerOfTerm(Deref(ARG5));
|
|
|
|
LOCAL_PredEntriesCounterOn = do_entries;
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_clean_up_dead_clauses( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2006-03-22 20:07:28 +00:00
|
|
|
while (DeadStaticClauses != NULL) {
|
|
|
|
char *pt = (char *)DeadStaticClauses;
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= DeadStaticClauses->ClSize;
|
2006-03-22 20:07:28 +00:00
|
|
|
DeadStaticClauses = DeadStaticClauses->ClNext;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(pt);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace(pt);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
while (DeadStaticIndices != NULL) {
|
|
|
|
char *pt = (char *)DeadStaticIndices;
|
2006-11-06 18:35:05 +00:00
|
|
|
if (DeadStaticIndices->ClFlags & SwitchTableMask)
|
|
|
|
Yap_IndexSpace_SW -= DeadStaticIndices->ClSize;
|
|
|
|
else
|
|
|
|
Yap_IndexSpace_Tree -= DeadStaticIndices->ClSize;
|
2006-03-22 20:07:28 +00:00
|
|
|
DeadStaticIndices = DeadStaticIndices->SiblingIndex;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(pt);
|
2006-03-22 20:07:28 +00:00
|
|
|
Yap_FreeCodeSpace(pt);
|
|
|
|
}
|
|
|
|
while (DeadMegaClauses != NULL) {
|
|
|
|
char *pt = (char *)DeadMegaClauses;
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= DeadMegaClauses->ClSize;
|
2006-03-22 20:07:28 +00:00
|
|
|
DeadMegaClauses = DeadMegaClauses->ClNext;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(pt);
|
2006-03-22 20:07:28 +00:00
|
|
|
Yap_FreeCodeSpace(pt);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-08-08 22:17:27 +01:00
|
|
|
static Int /* $parent_pred(Module, Name, Arity) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_parent_pred( USES_REGS1 )
|
2001-08-08 22:17:27 +01:00
|
|
|
{
|
2001-09-12 16:52:28 +01:00
|
|
|
/* This predicate is called from the debugger.
|
|
|
|
We assume a sequence of the form a -> b */
|
2001-08-08 22:17:27 +01:00
|
|
|
Atom at;
|
2002-12-06 20:03:26 +00:00
|
|
|
UInt arity;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term module;
|
2002-12-27 16:53:09 +00:00
|
|
|
if (!PredForCode(P_before_spy, &at, &arity, &module)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG1, MkIntTerm(0)) &&
|
|
|
|
Yap_unify(ARG2, MkAtomTerm(AtomMetaCall)) &&
|
|
|
|
Yap_unify(ARG3, MkIntTerm(0)));
|
2001-08-08 22:17:27 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG1, MkIntTerm(module)) &&
|
|
|
|
Yap_unify(ARG2, MkAtomTerm(at)) &&
|
|
|
|
Yap_unify(ARG3, MkIntTerm(arity)));
|
2001-08-08 22:17:27 +01:00
|
|
|
}
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
static Int /* $system_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_system_pred( USES_REGS1 )
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-01-08 05:22:40 +00:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
restart_system_pred:
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsVarTerm(t1))
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (IsExtensionFunctor(funt)) {
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2002-02-22 06:12:18 +00:00
|
|
|
if (funt == FunctorModule) {
|
2001-10-30 16:42:05 +00:00
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"system_predicate/1");
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"system_predicate/1");
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
2001-11-15 00:01:43 +00:00
|
|
|
goto restart_system_pred;
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-03-04 15:55:13 +00:00
|
|
|
} else if (IsPairTerm(t1)) {
|
2004-05-17 22:42:12 +01:00
|
|
|
return TRUE;
|
2001-10-30 16:42:05 +00:00
|
|
|
} else
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2005-10-18 18:04:43 +01:00
|
|
|
return FALSE;
|
|
|
|
return(!pe->ModuleOfPred || /* any predicate in prolog module */
|
|
|
|
/* any C-pred */
|
2009-02-09 21:56:40 +00:00
|
|
|
pe->PredFlags & (UserCPredFlag|CPredFlag|BinaryPredFlag|AsmPredFlag|TestPredFlag) ||
|
2005-10-18 18:04:43 +01:00
|
|
|
/* any weird user built-in */
|
|
|
|
pe->OpcodeOfPred == Yap_opcode(_try_userc));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 09:25:27 +00:00
|
|
|
static Int /* $system_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_all_system_pred( USES_REGS1 )
|
2007-11-07 09:25:27 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return TRUE;
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"system_predicate/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"system_predicate/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
return FALSE;
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2008-07-23 00:34:50 +01:00
|
|
|
if (pe->ModuleOfPred) {
|
|
|
|
if (!Yap_unify(ARG3,pe->ModuleOfPred))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!Yap_unify(ARG3,TermProlog))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-07 09:25:27 +00:00
|
|
|
return(!pe->ModuleOfPred || /* any predicate in prolog module */
|
|
|
|
/* any C-pred */
|
2009-02-09 21:56:40 +00:00
|
|
|
pe->PredFlags & (UserCPredFlag|CPredFlag|BinaryPredFlag|AsmPredFlag|TestPredFlag) ||
|
2007-11-07 09:25:27 +00:00
|
|
|
/* any weird user built-in */
|
|
|
|
pe->OpcodeOfPred == Yap_opcode(_try_userc));
|
|
|
|
}
|
|
|
|
|
2012-10-19 18:10:48 +01:00
|
|
|
void
|
|
|
|
Yap_HidePred(PredEntry *pe)
|
|
|
|
{
|
|
|
|
Prop p0 = AbsPredProp(pe);
|
|
|
|
if (pe->ArityOfPE == 0) {
|
|
|
|
Atom a = (Atom)pe->FunctorOfPred;
|
|
|
|
|
|
|
|
p0 = RepAtom(a)->PropsOfAE;
|
|
|
|
if (p0 == AbsPredProp(pe)) {
|
|
|
|
RepAtom(a)->PropsOfAE = pe->NextOfPE;
|
|
|
|
} else {
|
|
|
|
while (p0->NextOfPE != AbsPredProp(pe))
|
|
|
|
p0 = p0->NextOfPE;
|
|
|
|
if (p0 == NIL)
|
|
|
|
return;
|
|
|
|
p0->NextOfPE = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Functor funt = pe->FunctorOfPred;
|
|
|
|
|
|
|
|
p0 = funt->PropsOfFE;
|
|
|
|
if (p0 == AbsPredProp(pe)) {
|
|
|
|
funt->PropsOfFE = pe->NextOfPE;
|
|
|
|
} else {
|
|
|
|
while (p0->NextOfPE != AbsPredProp(pe))
|
|
|
|
p0 = p0->NextOfPE;
|
|
|
|
if (p0 == NIL)
|
|
|
|
return;
|
|
|
|
p0->NextOfPE = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pe->NextOfPE = HIDDEN_PREDICATES;
|
|
|
|
HIDDEN_PREDICATES = AbsPredProp(pe);
|
|
|
|
pe->PredFlags |= HiddenPredFlag;
|
|
|
|
}
|
|
|
|
|
2002-08-14 17:00:54 +01:00
|
|
|
static Int /* $system_predicate(P) */
|
2012-11-25 23:36:43 +00:00
|
|
|
p_stash_predicate( USES_REGS1 )
|
2002-08-14 17:00:54 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-08-14 17:00:54 +01:00
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2012-10-19 18:10:48 +01:00
|
|
|
Atom a = AtomOfTerm(t1);
|
|
|
|
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(a, mod));
|
2002-08-14 17:00:54 +01:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
2002-08-14 17:00:54 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
2002-08-14 17:00:54 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-08-14 17:00:54 +01:00
|
|
|
} else if (IsPairTerm(t1)) {
|
2012-10-19 18:10:48 +01:00
|
|
|
return TRUE;
|
2002-08-14 17:00:54 +01:00
|
|
|
} else
|
2012-10-19 18:10:48 +01:00
|
|
|
return FALSE;
|
2002-08-14 17:00:54 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
2008-07-23 00:34:50 +01:00
|
|
|
return FALSE;
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_HidePred(pe);
|
|
|
|
return TRUE;
|
2002-08-14 17:00:54 +01:00
|
|
|
}
|
|
|
|
|
2012-11-25 23:36:43 +00:00
|
|
|
static Int /* $system_predicate(P) */
|
|
|
|
p_hide_predicate( USES_REGS1 )
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
Atom a = AtomOfTerm(t1);
|
|
|
|
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(a, mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
return FALSE;
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
pe->PredFlags |= HiddenPredFlag;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-19 18:10:48 +01:00
|
|
|
|
2002-09-02 18:33:00 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_hidden_predicate( USES_REGS1 )
|
2002-09-02 18:33:00 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-09-02 18:33:00 +01:00
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
2002-09-02 18:33:00 +01:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
2002-09-02 18:33:00 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
2002-09-02 18:33:00 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-09-02 18:33:00 +01:00
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return (TRUE);
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return(FALSE);
|
|
|
|
return(pe->PredFlags & HiddenPredFlag);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static Int
|
2003-10-17 03:11:21 +01:00
|
|
|
fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, yamop *cp_ptr, int first_time)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2003-12-01 17:27:42 +00:00
|
|
|
LogUpdClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
Term rtn;
|
2004-03-31 02:03:10 +01:00
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2008-09-05 05:22:19 +01:00
|
|
|
cl = Yap_FollowIndexingCode(pe, i_code, Terms, NEXTOP(PredLogUpdClause->CodeOfPred,Otapl), cp_ptr);
|
2004-09-30 20:51:54 +01:00
|
|
|
th = Terms[0];
|
|
|
|
tb = Terms[1];
|
|
|
|
tr = Terms[2];
|
2004-08-16 22:02:04 +01:00
|
|
|
/* don't do this!! I might have stored a choice-point and changed ASP
|
|
|
|
Yap_RecoverSlots(3);
|
|
|
|
*/
|
2003-12-01 17:27:42 +00:00
|
|
|
if (cl == NULL) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2003-08-27 14:37:10 +01:00
|
|
|
return FALSE;
|
2003-12-01 17:27:42 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2003-08-27 14:37:10 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2003-12-18 17:23:22 +00:00
|
|
|
INC_CLREF_COUNT(cl);
|
2003-08-27 14:37:10 +01:00
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
#endif
|
2003-11-18 19:24:46 +00:00
|
|
|
if (cl->ClFlags & FactMask) {
|
2005-05-12 04:36:33 +01:00
|
|
|
if (!Yap_unify_constant(tb, MkAtomTerm(AtomTrue)) ||
|
2007-11-26 23:43:10 +00:00
|
|
|
!Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCK(pe->PELock);
|
2003-11-18 19:24:46 +00:00
|
|
|
return FALSE;
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2008-08-28 04:43:00 +01:00
|
|
|
if (first_time &&
|
2008-09-01 16:48:05 +01:00
|
|
|
P->opc != EXECUTE_CPRED_OP_CODE) {
|
2003-11-21 16:56:20 +00:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
2008-08-28 04:43:00 +01:00
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
P = cl->ClCode;
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2010-07-28 11:26:20 +01:00
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
} else {
|
|
|
|
PP = pe;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2007-12-26 19:50:40 +00:00
|
|
|
} else {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) {
|
|
|
|
if (first_time) {
|
2004-07-22 22:32:23 +01:00
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2004-09-17 20:34:53 +01:00
|
|
|
if (!Yap_growglobal(NULL)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
|
2004-09-17 20:34:53 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P,CP))) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2004-09-17 20:34:53 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
2004-07-22 22:32:23 +01:00
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
2003-11-18 19:24:46 +00:00
|
|
|
} else {
|
2004-07-22 22:32:23 +01:00
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, gc_P(P,CP))) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2003-11-18 19:24:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-07-22 22:32:23 +01:00
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2003-08-27 14:37:10 +01:00
|
|
|
return(Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_log_update_clause( USES_REGS1 )
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-19 19:24:46 +00:00
|
|
|
Int ret;
|
2008-09-01 16:30:37 +01:00
|
|
|
yamop *new_cp;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2008-09-01 16:48:05 +01:00
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
2008-09-01 16:30:37 +01:00
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(41,pe);
|
2008-09-01 16:30:37 +01:00
|
|
|
ret = fetch_next_lu_clause(pe, pe->CodeOfPred, t1, ARG3, ARG4, new_cp, TRUE);
|
2004-02-19 19:24:46 +00:00
|
|
|
return ret;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_continue_log_update_clause( USES_REGS1 )
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(42,pe);
|
2005-02-25 03:39:45 +00:00
|
|
|
return fetch_next_lu_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_cp, FALSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2008-01-23 17:57:56 +00:00
|
|
|
static Int
|
|
|
|
fetch_next_lu_clause_erase(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, yamop *cp_ptr, int first_time)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2008-01-23 17:57:56 +00:00
|
|
|
LogUpdClause *cl;
|
|
|
|
Term rtn;
|
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2008-09-05 05:22:19 +01:00
|
|
|
cl = Yap_FollowIndexingCode(pe, i_code, Terms, NEXTOP(PredLogUpdClauseErase->CodeOfPred,Otapl), cp_ptr);
|
2008-01-23 17:57:56 +00:00
|
|
|
th = Terms[0];
|
|
|
|
tb = Terms[1];
|
|
|
|
tr = Terms[2];
|
|
|
|
/* don't do this!! I might have stored a choice-point and changed ASP
|
|
|
|
Yap_RecoverSlots(3);
|
|
|
|
*/
|
|
|
|
if (cl == NULL) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2008-01-23 17:57:56 +00:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
INC_CLREF_COUNT(cl);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
if (!Yap_unify_constant(tb, MkAtomTerm(AtomTrue)) ||
|
|
|
|
!Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2008-08-28 04:43:00 +01:00
|
|
|
if (first_time &&
|
2008-09-01 16:48:05 +01:00
|
|
|
P->opc != EXECUTE_CPRED_OP_CODE) {
|
2008-01-23 17:57:56 +00:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
|
|
|
P = cl->ClCode;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2010-07-28 17:12:17 +01:00
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
} else {
|
|
|
|
PP = pe;
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
}
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
Int res;
|
|
|
|
|
|
|
|
while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) {
|
|
|
|
if (first_time) {
|
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2008-01-23 17:57:56 +00:00
|
|
|
if (!Yap_growglobal(NULL)) {
|
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
|
2008-01-23 17:57:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P,CP))) {
|
2008-01-23 17:57:56 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2008-01-23 17:57:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
|
|
|
} else {
|
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
|
2008-01-23 17:57:56 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2008-01-23 17:57:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)) &&
|
|
|
|
Yap_unify(tr, rtn);
|
|
|
|
if (res)
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_log_update_clause_erase( USES_REGS1 )
|
2008-01-23 17:57:56 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Int ret;
|
2008-09-01 16:30:37 +01:00
|
|
|
yamop *new_cp;
|
2008-01-23 17:57:56 +00:00
|
|
|
|
2008-09-01 16:48:05 +01:00
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
2008-09-01 16:30:37 +01:00
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(43,pe);
|
2008-09-01 16:30:37 +01:00
|
|
|
ret = fetch_next_lu_clause_erase(pe, pe->CodeOfPred, t1, ARG3, ARG4, new_cp, TRUE);
|
2008-01-23 17:57:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_continue_log_update_clause_erase( USES_REGS1 )
|
2008-01-23 17:57:56 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(44,pe);
|
2008-01-23 17:57:56 +00:00
|
|
|
return fetch_next_lu_clause_erase(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_cp, FALSE);
|
|
|
|
}
|
|
|
|
|
2006-10-11 15:53:57 +01:00
|
|
|
static void
|
2006-11-15 00:13:37 +00:00
|
|
|
adjust_cl_timestamp(LogUpdClause *cl, UInt *arp, UInt *base)
|
2006-10-11 15:53:57 +01:00
|
|
|
{
|
2006-11-15 00:13:37 +00:00
|
|
|
UInt clstamp = cl->ClTimeEnd;
|
|
|
|
if (cl->ClTimeEnd != TIMESTAMP_EOT) {
|
|
|
|
while (arp[0] > clstamp)
|
|
|
|
arp--;
|
|
|
|
if (arp[0] == clstamp) {
|
|
|
|
cl->ClTimeEnd = (arp-base);
|
|
|
|
} else {
|
|
|
|
cl->ClTimeEnd = (arp-base)+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clstamp = cl->ClTimeStart;
|
|
|
|
while (arp[0] > clstamp)
|
|
|
|
arp--;
|
|
|
|
if (arp[0] == clstamp) {
|
|
|
|
cl->ClTimeStart = (arp-base);
|
|
|
|
} else {
|
|
|
|
cl->ClTimeStart = (arp-base)+1;
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
clstamp = cl->ClTimeEnd;
|
|
|
|
}
|
|
|
|
|
2006-11-15 00:13:37 +00:00
|
|
|
|
|
|
|
static Term
|
|
|
|
replace_integer(Term orig, UInt new)
|
|
|
|
{
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (IntInBnd((Int)new))
|
|
|
|
return MkIntTerm(new);
|
|
|
|
/* should create an old integer */
|
|
|
|
if (!IsApplTerm(orig)) {
|
|
|
|
Yap_Error(SYSTEM_ERROR,orig,"%uld-->%uld where it should increase",(unsigned long int)IntegerOfTerm(orig),(unsigned long int)new);
|
|
|
|
return MkIntegerTerm(new);
|
|
|
|
}
|
|
|
|
/* appl->appl */
|
|
|
|
/* replace integer in situ */
|
|
|
|
pt = RepAppl(orig)+1;
|
|
|
|
*pt = new;
|
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
2006-10-11 15:53:57 +01:00
|
|
|
void /* $hidden_predicate(P) */
|
2006-11-15 00:13:37 +00:00
|
|
|
Yap_UpdateTimestamps(PredEntry *ap)
|
2006-10-11 15:53:57 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-10-11 15:53:57 +01:00
|
|
|
choiceptr bptr = B;
|
2008-09-05 05:22:19 +01:00
|
|
|
yamop *cl0 = NEXTOP(PredLogUpdClause0->CodeOfPred,Otapl);
|
|
|
|
yamop *cl = NEXTOP(PredLogUpdClause->CodeOfPred,Otapl);
|
|
|
|
yamop *cle = NEXTOP(PredLogUpdClauseErase->CodeOfPred,Otapl);
|
2006-10-11 15:53:57 +01:00
|
|
|
UInt ar = ap->ArityOfPE;
|
2006-11-15 00:13:37 +00:00
|
|
|
UInt *arp, *top, *base;
|
|
|
|
LogUpdClause *lcl;
|
2006-10-11 15:53:57 +01:00
|
|
|
|
|
|
|
#if THREADS
|
2006-11-15 00:13:37 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"Timestamp overflow %p", ap);
|
|
|
|
return;
|
2006-10-11 15:53:57 +01:00
|
|
|
#endif
|
2006-11-15 00:13:37 +00:00
|
|
|
if (!ap->cs.p_code.NOfClauses)
|
2006-10-11 15:53:57 +01:00
|
|
|
return;
|
|
|
|
restart:
|
2006-11-15 00:13:37 +00:00
|
|
|
*--ASP = TIMESTAMP_EOT;
|
|
|
|
top = arp = (UInt *)ASP;
|
2006-10-11 15:53:57 +01:00
|
|
|
while (bptr) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(bptr->cp_ap->opc);
|
|
|
|
|
|
|
|
switch (opnum) {
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
2008-09-05 05:22:19 +01:00
|
|
|
if (bptr->cp_ap->u.OtaLl.d->ClPred == ap) {
|
2006-10-11 15:53:57 +01:00
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[ar]);
|
|
|
|
if (ts != arp[0]) {
|
|
|
|
if (arp-H < 1024) {
|
|
|
|
goto overflow;
|
|
|
|
}
|
2006-11-15 00:13:37 +00:00
|
|
|
/* be thrifty, have this in case there is a hole */
|
|
|
|
if (ts != arp[0]-1) {
|
|
|
|
UInt x = arp[0];
|
|
|
|
*--arp = x;
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
*--arp = ts;
|
|
|
|
}
|
|
|
|
}
|
2006-11-15 00:13:37 +00:00
|
|
|
bptr = bptr->cp_b;
|
2006-10-11 15:53:57 +01:00
|
|
|
break;
|
|
|
|
case _retry:
|
2008-01-23 17:57:56 +00:00
|
|
|
if ((bptr->cp_ap == cl0 || bptr->cp_ap == cl || bptr->cp_ap == cle) &&
|
2006-11-15 00:13:37 +00:00
|
|
|
((PredEntry *)IntegerOfTerm(bptr->cp_args[0]) == ap)) {
|
2006-10-11 15:53:57 +01:00
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[5]);
|
|
|
|
if (ts != arp[0]) {
|
|
|
|
if (arp-H < 1024) {
|
|
|
|
goto overflow;
|
|
|
|
}
|
2006-11-15 00:13:37 +00:00
|
|
|
if (ts != arp[0]-1) {
|
|
|
|
UInt x = arp[0];
|
|
|
|
*--arp = x;
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
*--arp = ts;
|
|
|
|
}
|
|
|
|
}
|
2006-11-15 00:13:37 +00:00
|
|
|
bptr = bptr->cp_b;
|
2006-10-11 15:53:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2006-11-15 00:13:37 +00:00
|
|
|
bptr = bptr->cp_b;
|
2006-10-11 15:53:57 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2006-11-15 00:13:37 +00:00
|
|
|
if (*arp)
|
|
|
|
*--arp = 0L;
|
|
|
|
base = arp;
|
|
|
|
lcl = ClauseCodeToLogUpdClause(ap->cs.p_code.FirstClause);
|
|
|
|
while (lcl) {
|
|
|
|
adjust_cl_timestamp(lcl, top-1, base);
|
|
|
|
lcl = lcl->ClNext;
|
|
|
|
}
|
|
|
|
lcl = DBErasedList;
|
|
|
|
while (lcl) {
|
|
|
|
if (lcl->ClPred == ap)
|
|
|
|
adjust_cl_timestamp(lcl, top-1, base);
|
|
|
|
lcl = lcl->ClNext;
|
|
|
|
}
|
|
|
|
arp = top-1;
|
|
|
|
bptr = B;
|
|
|
|
while (bptr) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(bptr->cp_ap->opc);
|
|
|
|
|
|
|
|
switch (opnum) {
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
2008-09-05 05:22:19 +01:00
|
|
|
if (bptr->cp_ap->u.OtaLl.d->ClPred == ap) {
|
2006-11-15 00:13:37 +00:00
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[ar]);
|
|
|
|
while (ts != arp[0])
|
|
|
|
arp--;
|
|
|
|
bptr->cp_args[ar] = replace_integer(bptr->cp_args[ar], arp-base);
|
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
case _retry:
|
2008-01-23 17:57:56 +00:00
|
|
|
if ((bptr->cp_ap == cl0 || bptr->cp_ap == cl || bptr->cp_ap == cle) &&
|
2006-11-15 00:13:37 +00:00
|
|
|
((PredEntry *)IntegerOfTerm(bptr->cp_args[0]) == ap)) {
|
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[5]);
|
|
|
|
while (ts != arp[0])
|
|
|
|
arp--;
|
|
|
|
bptr->cp_args[5] = replace_integer(bptr->cp_args[5], arp-base);
|
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
continue;
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
overflow:
|
2006-11-15 00:13:37 +00:00
|
|
|
if (!Yap_growstack(64*1024)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-10-11 15:53:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int
|
|
|
|
fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, yamop *cp_ptr, int first_time)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2003-12-01 17:27:42 +00:00
|
|
|
StaticClause *cl;
|
2003-11-21 16:56:20 +00:00
|
|
|
Term rtn;
|
2004-03-31 02:03:10 +01:00
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2008-09-05 05:22:19 +01:00
|
|
|
cl = (StaticClause *)Yap_FollowIndexingCode(pe, i_code, Terms, NEXTOP(PredStaticClause->CodeOfPred,Otapl), cp_ptr);
|
2009-11-17 00:23:34 +00:00
|
|
|
th = Deref(Terms[0]);
|
|
|
|
tb = Deref(Terms[1]);
|
|
|
|
tr = Deref(Terms[2]);
|
2004-08-16 22:02:04 +01:00
|
|
|
/* don't do this!! I might have stored a choice-point and changed ASP
|
|
|
|
Yap_RecoverSlots(3);
|
|
|
|
*/
|
2010-07-28 17:12:17 +01:00
|
|
|
if (cl == NULL) {
|
|
|
|
UNLOCKPE(45,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->PredFlags & MegaClausePredFlag) {
|
|
|
|
yamop *code = (yamop *)cl;
|
|
|
|
rtn = Yap_MkMegaRefTerm(pe,code);
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
|
2010-07-28 17:12:17 +01:00
|
|
|
!Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCKPE(45,pe);
|
2004-09-27 21:45:04 +01:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2008-09-01 16:48:05 +01:00
|
|
|
if (first_time && P->opc != EXECUTE_CPRED_OP_CODE) {
|
2004-09-27 21:45:04 +01:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
|
|
|
P = code;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
rtn = Yap_MkStaticRefTerm(cl);
|
2003-11-21 16:56:20 +00:00
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
|
2010-07-28 17:12:17 +01:00
|
|
|
!Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCKPE(45,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2008-08-28 04:43:00 +01:00
|
|
|
if (first_time &&
|
2008-09-01 16:48:05 +01:00
|
|
|
P->opc != EXECUTE_CPRED_OP_CODE) {
|
2003-11-21 16:56:20 +00:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
P = cl->ClCode;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
2010-07-28 17:12:17 +01:00
|
|
|
UNLOCKPE(45,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
2005-08-05 15:55:03 +01:00
|
|
|
|
|
|
|
if (!(pe->PredFlags & SourcePredFlag)) {
|
|
|
|
/* no source */
|
|
|
|
rtn = Yap_MkStaticRefTerm(cl);
|
2010-07-28 17:12:17 +01:00
|
|
|
UNLOCKPE(45,pe);
|
2005-08-05 15:55:03 +01:00
|
|
|
return Yap_unify(tr, rtn);
|
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
|
2005-08-02 04:09:52 +01:00
|
|
|
if (!(pe->PredFlags & SourcePredFlag)) {
|
|
|
|
rtn = Yap_MkStaticRefTerm(cl);
|
|
|
|
return Yap_unify(tr, rtn);
|
|
|
|
}
|
2003-11-24 00:00:43 +00:00
|
|
|
while ((t = Yap_FetchTermFromDB(cl->usc.ClSource)) == 0L) {
|
2003-11-21 16:56:20 +00:00
|
|
|
if (first_time) {
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2004-09-17 20:34:53 +01:00
|
|
|
if (!Yap_growglobal(NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
|
2004-09-17 20:34:53 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2005-01-28 23:14:41 +00:00
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
2008-09-02 03:48:02 +01:00
|
|
|
if (!Yap_gc(7, ENV, gc_P(P,CP))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2004-09-17 20:34:53 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-01-28 23:14:41 +00:00
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2005-01-28 23:14:41 +00:00
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2003-11-21 16:56:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-01-28 23:14:41 +00:00
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-28 23:14:41 +00:00
|
|
|
rtn = Yap_MkStaticRefTerm(cl);
|
2010-07-28 17:12:17 +01:00
|
|
|
UNLOCKPE(45,pe);
|
2007-03-26 16:18:43 +01:00
|
|
|
if (!IsApplTerm(t) || FunctorOfTerm(t) != FunctorAssert) {
|
|
|
|
return(Yap_unify(th, t) &&
|
|
|
|
Yap_unify(tb, MkAtomTerm(AtomTrue)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
|
|
|
} else {
|
|
|
|
return(Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_static_clause( USES_REGS1 )
|
2003-11-21 16:56:20 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
2008-09-01 16:30:37 +01:00
|
|
|
yamop * new_cp;
|
2003-11-21 16:56:20 +00:00
|
|
|
|
2008-09-01 16:48:05 +01:00
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
2008-09-01 16:30:37 +01:00
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(46,pe);
|
2008-09-01 16:30:37 +01:00
|
|
|
return fetch_next_static_clause(pe, pe->CodeOfPred, ARG1, ARG3, ARG4, new_cp, TRUE);
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_nth_clause( USES_REGS1 )
|
2003-12-01 19:22:01 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
LogUpdClause *cl;
|
|
|
|
Int ncls;
|
|
|
|
|
|
|
|
if (!IsIntegerTerm(tn))
|
|
|
|
return FALSE;
|
|
|
|
ncls = IntegerOfTerm(tn);
|
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(47,pe);
|
2004-02-18 01:43:32 +00:00
|
|
|
if (!(pe->PredFlags & (SourcePredFlag|LogUpdatePredFlag))) {
|
2003-12-01 19:22:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* in case we have to index or to expand code */
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pe->ModuleOfPred != IDB_MODULE) {
|
2003-12-01 19:22:01 +00:00
|
|
|
UInt i;
|
|
|
|
|
|
|
|
for (i = 1; i <= pe->ArityOfPE; i++) {
|
|
|
|
XREGS[i] = MkVarTerm();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XREGS[2] = MkVarTerm();
|
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(pe, 0, CP);
|
2004-02-18 01:43:32 +00:00
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
cl = Yap_NthClause(pe, ncls);
|
2007-11-26 23:43:10 +00:00
|
|
|
if (cl == NULL) {
|
|
|
|
UNLOCK(pe->PELock);
|
2003-12-01 19:22:01 +00:00
|
|
|
return FALSE;
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->PredFlags & LogUpdatePredFlag) {
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2003-12-01 19:22:01 +00:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2003-12-18 17:23:22 +00:00
|
|
|
INC_CLREF_COUNT(cl);
|
2003-12-01 19:22:01 +00:00
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
|
|
|
#endif
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2004-09-27 21:45:04 +01:00
|
|
|
return Yap_unify(MkDBRefTerm((DBRef)cl), ARG4);
|
|
|
|
} else if (pe->PredFlags & MegaClausePredFlag) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2004-09-27 21:45:04 +01:00
|
|
|
return Yap_unify(Yap_MkMegaRefTerm(pe,(yamop *)cl), ARG4);
|
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2004-09-27 21:45:04 +01:00
|
|
|
return Yap_unify(Yap_MkStaticRefTerm((StaticClause *)cl), ARG4);
|
2003-12-01 19:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int /* $hidden_predicate(P) */
|
2011-03-07 16:02:55 +00:00
|
|
|
p_continue_static_clause( USES_REGS1 )
|
2003-11-21 16:56:20 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(48,pe);
|
2003-11-21 16:56:20 +00:00
|
|
|
return fetch_next_static_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
|
|
|
|
}
|
|
|
|
|
2005-12-17 03:25:39 +00:00
|
|
|
#if LOW_PROF
|
2003-05-20 20:11:59 +01:00
|
|
|
|
2010-10-26 22:01:29 +01:00
|
|
|
static void
|
|
|
|
add_code_in_lu_index(LogUpdIndex *cl, PredEntry *pp)
|
|
|
|
{
|
2012-04-11 22:08:02 +01:00
|
|
|
CACHE_REGS
|
|
|
|
|
2010-10-26 22:01:29 +01:00
|
|
|
char *code_end = (char *)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_LU_INDEX);
|
2010-10-26 22:01:29 +01:00
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
add_code_in_lu_index(cl, pp);
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_code_in_static_index(StaticIndex *cl, PredEntry *pp)
|
|
|
|
{
|
2012-04-11 22:08:02 +01:00
|
|
|
CACHE_REGS
|
2010-10-26 22:01:29 +01:00
|
|
|
char *code_end = (char *)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_STATIC_INDEX);
|
2010-10-26 22:01:29 +01:00
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
add_code_in_static_index(cl, pp);
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
static void
|
|
|
|
add_code_in_pred(PredEntry *pp) {
|
2012-04-11 22:08:02 +01:00
|
|
|
CACHE_REGS
|
2003-05-20 20:11:59 +01:00
|
|
|
yamop *clcode;
|
|
|
|
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(49,pp);
|
2003-05-20 20:11:59 +01:00
|
|
|
/* check if the codeptr comes from the indexing code */
|
2005-12-17 03:25:39 +00:00
|
|
|
|
|
|
|
/* highly likely this is used for indexing */
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(&(pp->OpcodeOfPred), &(pp->OpcodeOfPred)+1, pp, GPROF_INIT_OPCODE);
|
2003-05-21 13:15:09 +01:00
|
|
|
if (pp->PredFlags & (CPredFlag|AsmPredFlag)) {
|
|
|
|
char *code_end;
|
|
|
|
StaticClause *cl;
|
|
|
|
|
|
|
|
clcode = pp->CodeOfPred;
|
|
|
|
cl = ClauseCodeToStaticClause(clcode);
|
2004-03-05 15:26:33 +00:00
|
|
|
code_end = (char *)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_INIT_SYSTEM_CODE);
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2003-05-21 13:15:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(&(pp->cs.p_code.ExpandCode), &(pp->cs.p_code.ExpandCode)+1, pp, GPROF_INIT_EXPAND);
|
2003-05-20 20:11:59 +01:00
|
|
|
clcode = pp->cs.p_code.TrueCodeOfPred;
|
|
|
|
if (pp->PredFlags & IndexedPredFlag) {
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(clcode);
|
2010-10-26 22:01:29 +01:00
|
|
|
add_code_in_lu_index(cl, pp);
|
2003-05-20 20:11:59 +01:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(clcode);
|
2010-10-26 22:01:29 +01:00
|
|
|
add_code_in_static_index(cl, pp);
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clcode = pp->cs.p_code.FirstClause;
|
|
|
|
if (clcode != NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode);
|
|
|
|
do {
|
|
|
|
char *code_end;
|
|
|
|
|
2004-03-05 15:26:33 +00:00
|
|
|
code_end = (char *)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_INIT_LOG_UPD_CLAUSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
do {
|
2004-03-05 15:26:33 +00:00
|
|
|
DynamicClause *cl;
|
2005-12-17 03:25:39 +00:00
|
|
|
CODEADDR code_end;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2004-03-05 15:26:33 +00:00
|
|
|
cl = ClauseCodeToDynamicClause(clcode);
|
2005-12-17 03:25:39 +00:00
|
|
|
code_end = (CODEADDR)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_INIT_DYNAMIC_CLAUSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (clcode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
clcode = NextDynamicClause(clcode);
|
|
|
|
} while (TRUE);
|
|
|
|
} else {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(clcode);
|
|
|
|
do {
|
|
|
|
char *code_end;
|
|
|
|
|
2004-03-05 15:26:33 +00:00
|
|
|
code_end = (char *)cl + cl->ClSize;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(cl, code_end, pp,GPROF_INIT_STATIC_CLAUSE);
|
2010-10-26 22:01:29 +01:00
|
|
|
if (cl->ClCode == pp->cs.p_code.LastClause)
|
2003-11-26 18:36:35 +00:00
|
|
|
break;
|
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_dump_code_area_for_profiler(void) {
|
2012-04-11 22:08:02 +01:00
|
|
|
CACHE_REGS
|
2007-04-10 23:13:21 +01:00
|
|
|
ModEntry *me = CurrentModules;
|
|
|
|
|
|
|
|
while (me) {
|
|
|
|
PredEntry *pp = me->PredForME;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
|
|
|
while (pp != NULL) {
|
2003-05-21 14:00:23 +01:00
|
|
|
/* if (pp->ArityOfPE) {
|
2003-05-21 13:15:09 +01:00
|
|
|
fprintf(stderr,"%s/%d %p\n",
|
|
|
|
RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE,
|
|
|
|
pp->ArityOfPE,
|
|
|
|
pp);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"%s %p\n",
|
|
|
|
RepAtom((Atom)(pp->FunctorOfPred))->StrOfAE,
|
|
|
|
pp);
|
2003-05-21 14:00:23 +01:00
|
|
|
}*/
|
2003-05-20 20:11:59 +01:00
|
|
|
add_code_in_pred(pp);
|
|
|
|
pp = pp->NextPredOfModule;
|
|
|
|
}
|
2007-04-10 23:13:21 +01:00
|
|
|
me = me->NextME;
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_inform_profiler_of_clause(COMMA_CODE, FAILCODE, RepPredProp(Yap_GetPredPropByFunc(FunctorComma,0)), GPROF_INIT_COMMA);
|
|
|
|
Yap_inform_profiler_of_clause(FAILCODE, FAILCODE+1, RepPredProp(Yap_GetPredPropByAtom(AtomFail,0)), GPROF_INIT_FAIL);
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LOW_PROF */
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
static UInt
|
|
|
|
index_ssz(StaticIndex *x)
|
|
|
|
{
|
2004-03-05 15:26:33 +00:00
|
|
|
UInt sz = x->ClSize;
|
2003-11-12 12:33:31 +00:00
|
|
|
x = x->ChildIndex;
|
|
|
|
while (x != NULL) {
|
|
|
|
sz += index_ssz(x);
|
|
|
|
x = x->SiblingIndex;
|
|
|
|
}
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
static_statistics(PredEntry *pe)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2003-11-12 12:33:31 +00:00
|
|
|
UInt sz = 0, cls = 0, isz = 0;
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause);
|
2003-11-12 12:33:31 +00:00
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->cs.p_code.NOfClauses > 1 &&
|
|
|
|
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause) {
|
|
|
|
isz = index_ssz(ClauseCodeToStaticIndex(pe->cs.p_code.TrueCodeOfPred));
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
|
|
|
return Yap_unify(ARG3, MkIntegerTerm(mcl->ClSize/mcl->ClItemSize)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(mcl->ClSize)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (pe->cs.p_code.NOfClauses) {
|
2003-11-12 12:33:31 +00:00
|
|
|
do {
|
|
|
|
cls++;
|
2004-03-05 15:26:33 +00:00
|
|
|
sz += cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pe->cs.p_code.LastClause)
|
2003-11-12 12:33:31 +00:00
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = cl->ClNext;
|
2003-11-12 12:33:31 +00:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG3, MkIntegerTerm(cls)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(sz)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_static_pred_statistics( USES_REGS1 )
|
2003-11-12 12:33:31 +00:00
|
|
|
{
|
2007-11-26 23:43:10 +00:00
|
|
|
Int out;
|
2003-11-12 12:33:31 +00:00
|
|
|
PredEntry *pe;
|
|
|
|
|
2007-11-26 23:43:10 +00:00
|
|
|
pe = get_pred( Deref(ARG1), Deref(ARG2), "predicate_statistics");
|
2003-11-12 12:33:31 +00:00
|
|
|
if (pe == NIL)
|
|
|
|
return (FALSE);
|
2010-07-28 11:26:20 +01:00
|
|
|
PELOCK(50,pe);
|
2009-02-09 21:56:40 +00:00
|
|
|
if (pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|UserCPredFlag|AsmPredFlag|CPredFlag|BinaryPredFlag)) {
|
2003-11-12 12:33:31 +00:00
|
|
|
/* should use '$recordedp' in this case */
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2003-11-12 12:33:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
out = static_statistics(pe);
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return out;
|
2003-11-12 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
2004-04-07 23:04:04 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_predicate_erased_statistics( USES_REGS1 )
|
2004-04-07 23:04:04 +01:00
|
|
|
{
|
|
|
|
UInt sz = 0, cls = 0;
|
|
|
|
UInt isz = 0, icls = 0;
|
|
|
|
PredEntry *pe;
|
|
|
|
LogUpdClause *cl = DBErasedList;
|
|
|
|
LogUpdIndex *icl = DBErasedIList;
|
2008-01-23 17:57:56 +00:00
|
|
|
Term tpred = ArgOfTerm(2,Deref(ARG1));
|
|
|
|
Term tmod = ArgOfTerm(1,Deref(ARG1));
|
2004-04-07 23:04:04 +01:00
|
|
|
|
2007-12-18 17:46:58 +00:00
|
|
|
if (EndOfPAEntr(pe=get_pred(tpred, tmod, "predicate_erased_statistics")))
|
2004-04-07 23:04:04 +01:00
|
|
|
return FALSE;
|
|
|
|
while (cl) {
|
|
|
|
if (cl->ClPred == pe) {
|
|
|
|
cls++;
|
|
|
|
sz += cl->ClSize;
|
|
|
|
}
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
while (icl) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (pe == icl->ClPred) {
|
2004-04-07 23:04:04 +01:00
|
|
|
icls++;
|
2005-12-17 03:25:39 +00:00
|
|
|
isz += icl->ClSize;
|
2004-04-07 23:04:04 +01:00
|
|
|
}
|
|
|
|
icl = icl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return
|
|
|
|
Yap_unify(ARG2,MkIntegerTerm(cls)) &&
|
|
|
|
Yap_unify(ARG3,MkIntegerTerm(sz)) &&
|
|
|
|
Yap_unify(ARG4,MkIntegerTerm(icls)) &&
|
|
|
|
Yap_unify(ARG5,MkIntegerTerm(isz));
|
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
|
2006-11-15 00:13:37 +00:00
|
|
|
#ifdef DEBUG
|
2006-10-11 15:53:57 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_predicate_lu_cps( USES_REGS1 )
|
2006-10-11 15:53:57 +01:00
|
|
|
{
|
|
|
|
return Yap_unify(ARG1, MkIntegerTerm(Yap_LiveCps)) &&
|
|
|
|
Yap_unify(ARG2, MkIntegerTerm(Yap_FreedCps)) &&
|
|
|
|
Yap_unify(ARG3, MkIntegerTerm(Yap_DirtyCps)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(Yap_NewCps));
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
#endif
|
2004-04-07 23:04:04 +01:00
|
|
|
|
2006-02-01 13:28:57 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_program_continuation( USES_REGS1 )
|
2005-10-29 02:28:37 +01:00
|
|
|
{
|
2008-08-29 17:27:11 +01:00
|
|
|
PredEntry *pe = EnvPreg((yamop *)((ENV_Parent(ENV))[E_CP]));
|
2005-10-29 02:28:37 +01:00
|
|
|
if (pe->ModuleOfPred) {
|
|
|
|
if (!Yap_unify(ARG1,pe->ModuleOfPred))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!Yap_unify(ARG1,TermProlog))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
if (!Yap_unify(ARG2,MkAtomTerm(NameOfFunctor(pe->FunctorOfPred))))
|
|
|
|
return FALSE;
|
|
|
|
if (!Yap_unify(ARG3,MkIntegerTerm(ArityOfFunctor(pe->FunctorOfPred))))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!Yap_unify(ARG2,MkAtomTerm((Atom)pe->FunctorOfPred)))
|
|
|
|
return FALSE;
|
|
|
|
if (!Yap_unify(ARG3,MkIntTerm(0)))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-05-20 20:11:59 +01:00
|
|
|
|
2006-03-06 14:04:57 +00:00
|
|
|
static Term
|
|
|
|
BuildActivePred(PredEntry *ap, CELL *vect)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-12-13 16:10:26 +00:00
|
|
|
UInt i;
|
|
|
|
|
2006-03-06 14:04:57 +00:00
|
|
|
if (!ap->ArityOfPE) {
|
|
|
|
return MkVarTerm();
|
|
|
|
}
|
2006-12-13 16:10:26 +00:00
|
|
|
for (i = 0; i < ap->ArityOfPE; i++) {
|
|
|
|
Term t = Deref(vect[i]);
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
CELL *pt = VarOfTerm(t);
|
|
|
|
/* one stack */
|
|
|
|
if (pt > H) {
|
|
|
|
Term nt = MkVarTerm();
|
|
|
|
Yap_unify(t, nt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-06 14:04:57 +00:00
|
|
|
return Yap_MkApplTerm(ap->FunctorOfPred, ap->ArityOfPE, vect);
|
|
|
|
}
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
UnifyPredInfo(PredEntry *pe, int start_arg USES_REGS) {
|
2006-12-13 16:10:26 +00:00
|
|
|
UInt arity = pe->ArityOfPE;
|
|
|
|
Term tmod, tname;
|
|
|
|
|
|
|
|
if (pe->ModuleOfPred != IDB_MODULE) {
|
|
|
|
if (pe->ModuleOfPred == PROLOG_MODULE) {
|
|
|
|
tmod = TermProlog;
|
|
|
|
} else {
|
|
|
|
tmod = pe->ModuleOfPred;
|
|
|
|
}
|
|
|
|
if (pe->ArityOfPE == 0) {
|
|
|
|
tname = MkAtomTerm((Atom)pe->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
Functor f = pe->FunctorOfPred;
|
|
|
|
tname = MkAtomTerm(NameOfFunctor(f));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tmod = pe->ModuleOfPred;
|
|
|
|
if (pe->PredFlags & NumberDBPredFlag) {
|
|
|
|
tname = MkIntegerTerm(pe->src.IndxId);
|
|
|
|
} else if (pe->PredFlags & AtomDBPredFlag) {
|
|
|
|
tname = MkAtomTerm((Atom)pe->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
Functor f = pe->FunctorOfPred;
|
|
|
|
tname = MkAtomTerm(NameOfFunctor(f));
|
|
|
|
}
|
|
|
|
}
|
2007-01-24 10:01:40 +00:00
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
return Yap_unify(XREGS[start_arg], tmod) &&
|
|
|
|
Yap_unify(XREGS[start_arg+1],tname) &&
|
|
|
|
Yap_unify(XREGS[start_arg+2],MkIntegerTerm(arity));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-24 10:01:40 +00:00
|
|
|
static Int
|
|
|
|
ClauseId(yamop *ipc, PredEntry *pe)
|
|
|
|
{
|
|
|
|
if (!ipc)
|
|
|
|
return 0;
|
|
|
|
return find_code_in_clause(pe, ipc, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_env_info( USES_REGS1 )
|
2006-12-13 16:10:26 +00:00
|
|
|
{
|
2007-01-24 10:01:40 +00:00
|
|
|
CELL *env = LCL0-IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *env_cp;
|
|
|
|
Term env_b, taddr;
|
|
|
|
|
|
|
|
if (!env)
|
|
|
|
return FALSE;
|
|
|
|
env_b = MkIntegerTerm((Int)(LCL0-(CELL *)env[E_CB]));
|
|
|
|
env_cp = (yamop *)env[E_CP];
|
|
|
|
|
2011-12-30 16:02:59 +00:00
|
|
|
/* pe = PREVOP(env_cp,Osbpp)->u.Osbpp.p0; */
|
2007-01-24 10:01:40 +00:00
|
|
|
taddr = MkIntegerTerm((Int)env);
|
|
|
|
return Yap_unify(ARG3,MkIntegerTerm((Int)env_cp)) &&
|
|
|
|
Yap_unify(ARG2, taddr) &&
|
|
|
|
Yap_unify(ARG4, env_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_cpc_info( USES_REGS1 )
|
2007-01-24 10:01:40 +00:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
|
2008-09-05 05:22:19 +01:00
|
|
|
pe = PREVOP(ipc,Osbpp)->u.Osbpp.p0;
|
2011-03-07 16:02:55 +00:00
|
|
|
return UnifyPredInfo(pe, 2 PASS_REGS) &&
|
2007-01-24 10:01:40 +00:00
|
|
|
Yap_unify(ARG5,MkIntegerTerm(ClauseId(ipc,pe)));
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 14:04:57 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_choicepoint_info( USES_REGS1 )
|
2006-03-06 14:04:57 +00:00
|
|
|
{
|
|
|
|
choiceptr cptr = (choiceptr)(LCL0-IntegerOfTerm(Deref(ARG1)));
|
2007-01-25 22:11:55 +00:00
|
|
|
PredEntry *pe = NULL;
|
2006-03-06 14:04:57 +00:00
|
|
|
int go_on = TRUE;
|
|
|
|
yamop *ipc = cptr->cp_ap;
|
2007-01-24 10:01:40 +00:00
|
|
|
yamop *ncl = NULL;
|
2007-01-25 22:11:55 +00:00
|
|
|
Term t = TermNil, taddr;
|
2007-01-24 10:01:40 +00:00
|
|
|
|
|
|
|
taddr = MkIntegerTerm((Int)cptr);
|
2006-03-06 14:04:57 +00:00
|
|
|
while (go_on) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(ipc->opc);
|
|
|
|
go_on = FALSE;
|
|
|
|
switch (opnum) {
|
|
|
|
#ifdef TABLING
|
|
|
|
case _table_load_answer:
|
2006-03-29 17:00:10 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2006-03-06 14:04:57 +00:00
|
|
|
pe = LOAD_CP(cptr)->cp_pred_entry;
|
2006-03-29 17:00:10 +01:00
|
|
|
#else
|
|
|
|
pe = UndefCode;
|
|
|
|
#endif
|
2006-03-06 14:04:57 +00:00
|
|
|
t = MkVarTerm();
|
|
|
|
break;
|
|
|
|
case _table_try_answer:
|
|
|
|
case _table_retry_me:
|
|
|
|
case _table_trust_me:
|
|
|
|
case _table_retry:
|
|
|
|
case _table_trust:
|
|
|
|
case _table_completion:
|
2011-12-22 16:50:20 +00:00
|
|
|
#ifdef THREADS_CONSUMER_SHARING
|
|
|
|
case _table_answer_resolution_completion:
|
|
|
|
#endif /* THREADS_CONSUMER_SHARING */
|
2006-03-29 17:00:10 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2009-08-07 17:29:53 +01:00
|
|
|
#ifdef DETERMINISTIC_TABLING
|
|
|
|
if (IS_DET_GEN_CP(cptr)) {
|
|
|
|
pe = DET_GEN_CP(cptr)->cp_pred_entry;
|
|
|
|
t = MkVarTerm();
|
|
|
|
} else
|
|
|
|
#endif /* DETERMINISTIC_TABLING */
|
|
|
|
{
|
|
|
|
pe = GEN_CP(cptr)->cp_pred_entry;
|
|
|
|
t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1));
|
|
|
|
}
|
2006-03-29 17:00:10 +01:00
|
|
|
#else
|
|
|
|
pe = UndefCode;
|
|
|
|
t = MkVarTerm();
|
|
|
|
#endif
|
2006-03-06 14:04:57 +00:00
|
|
|
break;
|
|
|
|
case _table_answer_resolution:
|
2006-03-29 17:00:10 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2006-03-06 14:04:57 +00:00
|
|
|
pe = CONS_CP(cptr)->cp_pred_entry;
|
2006-03-29 17:00:10 +01:00
|
|
|
#else
|
|
|
|
pe = UndefCode;
|
|
|
|
#endif
|
2006-03-06 14:04:57 +00:00
|
|
|
t = MkVarTerm();
|
|
|
|
break;
|
|
|
|
case _trie_trust_var:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_var:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_var_in_pair:
|
|
|
|
case _trie_retry_var_in_pair:
|
2006-03-06 14:04:57 +00:00
|
|
|
case _trie_trust_val:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_val:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_val_in_pair:
|
|
|
|
case _trie_retry_val_in_pair:
|
2006-03-06 14:04:57 +00:00
|
|
|
case _trie_trust_atom:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_atom:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_atom_in_pair:
|
|
|
|
case _trie_retry_atom_in_pair:
|
|
|
|
case _trie_trust_null:
|
|
|
|
case _trie_retry_null:
|
|
|
|
case _trie_trust_null_in_pair:
|
|
|
|
case _trie_retry_null_in_pair:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_trust_pair:
|
|
|
|
case _trie_retry_pair:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_appl:
|
|
|
|
case _trie_retry_appl:
|
|
|
|
case _trie_trust_appl_in_pair:
|
|
|
|
case _trie_retry_appl_in_pair:
|
2006-03-06 14:04:57 +00:00
|
|
|
case _trie_trust_extension:
|
2009-07-05 05:14:08 +01:00
|
|
|
case _trie_retry_extension:
|
2010-04-15 01:09:59 +01:00
|
|
|
case _trie_trust_double:
|
|
|
|
case _trie_retry_double:
|
|
|
|
case _trie_trust_longint:
|
|
|
|
case _trie_retry_longint:
|
|
|
|
case _trie_trust_gterm:
|
|
|
|
case _trie_retry_gterm:
|
2006-03-06 14:04:57 +00:00
|
|
|
pe = UndefCode;
|
|
|
|
t = MkVarTerm();
|
|
|
|
break;
|
2006-11-14 11:42:26 +00:00
|
|
|
#endif /* TABLING */
|
2006-10-10 15:08:17 +01:00
|
|
|
case _try_logical:
|
|
|
|
case _retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _profiled_trust_logical:
|
2008-09-05 05:22:19 +01:00
|
|
|
ncl = ipc->u.OtaLl.d->ClCode;
|
|
|
|
pe = ipc->u.OtaLl.d->ClPred;
|
2006-10-10 15:08:17 +01:00
|
|
|
t = BuildActivePred(pe, cptr->cp_args);
|
|
|
|
break;
|
2006-03-06 14:04:57 +00:00
|
|
|
case _or_else:
|
2008-09-05 05:22:19 +01:00
|
|
|
pe = ipc->u.Osblp.p0;
|
2007-01-24 10:01:40 +00:00
|
|
|
ncl = ipc;
|
2006-03-06 14:04:57 +00:00
|
|
|
t = Yap_MkNewApplTerm(FunctorOr, 2);
|
|
|
|
break;
|
2010-01-15 16:15:36 +00:00
|
|
|
|
2006-03-06 14:04:57 +00:00
|
|
|
case _or_last:
|
2010-01-15 16:15:36 +00:00
|
|
|
#ifdef YAPOR
|
|
|
|
pe = ipc->u.Osblp.p0;
|
|
|
|
#else
|
2006-03-06 14:04:57 +00:00
|
|
|
pe = ipc->u.p.p;
|
2010-01-15 16:15:36 +00:00
|
|
|
#endif
|
2007-01-24 10:01:40 +00:00
|
|
|
ncl = ipc;
|
2006-03-06 14:04:57 +00:00
|
|
|
t = Yap_MkNewApplTerm(FunctorOr, 2);
|
|
|
|
break;
|
|
|
|
case _retry2:
|
|
|
|
case _retry3:
|
|
|
|
case _retry4:
|
2006-05-18 17:33:05 +01:00
|
|
|
pe = NULL;
|
|
|
|
t = TermNil;
|
2006-03-06 14:04:57 +00:00
|
|
|
ipc = NEXTOP(ipc,l);
|
2007-01-24 10:01:40 +00:00
|
|
|
if (!ncl)
|
2008-09-05 05:22:19 +01:00
|
|
|
ncl = ipc->u.Otapl.d;
|
2006-03-06 14:04:57 +00:00
|
|
|
go_on = TRUE;
|
|
|
|
break;
|
|
|
|
case _jump:
|
2006-05-18 17:33:05 +01:00
|
|
|
pe = NULL;
|
|
|
|
t = TermNil;
|
2006-03-06 14:04:57 +00:00
|
|
|
ipc = ipc->u.l.l;
|
|
|
|
go_on = TRUE;
|
|
|
|
break;
|
|
|
|
case _retry_c:
|
|
|
|
case _retry_userc:
|
2008-09-05 05:22:19 +01:00
|
|
|
ncl = NEXTOP(ipc,OtapFs);
|
|
|
|
pe = ipc->u.OtapFs.p;
|
2006-03-06 14:04:57 +00:00
|
|
|
t = BuildActivePred(pe, cptr->cp_args);
|
|
|
|
break;
|
|
|
|
case _retry_profiled:
|
|
|
|
case _count_retry:
|
2006-05-18 17:33:05 +01:00
|
|
|
pe = NULL;
|
|
|
|
t = TermNil;
|
2008-09-05 05:22:19 +01:00
|
|
|
ncl = ipc->u.Otapl.d;
|
2006-03-06 14:04:57 +00:00
|
|
|
ipc = NEXTOP(ipc,p);
|
|
|
|
go_on = TRUE;
|
|
|
|
break;
|
|
|
|
case _retry_me:
|
|
|
|
case _trust_me:
|
|
|
|
case _count_retry_me:
|
|
|
|
case _count_trust_me:
|
|
|
|
case _profiled_retry_me:
|
|
|
|
case _profiled_trust_me:
|
|
|
|
case _retry_and_mark:
|
|
|
|
case _profiled_retry_and_mark:
|
|
|
|
case _retry:
|
|
|
|
case _trust:
|
2007-01-24 10:01:40 +00:00
|
|
|
if (!ncl)
|
2008-09-05 05:22:19 +01:00
|
|
|
ncl = ipc->u.Otapl.d;
|
|
|
|
pe = ipc->u.Otapl.p;
|
2006-03-06 14:04:57 +00:00
|
|
|
t = BuildActivePred(pe, cptr->cp_args);
|
|
|
|
break;
|
|
|
|
case _Nstop:
|
2006-12-13 16:10:26 +00:00
|
|
|
{
|
2009-10-23 16:50:43 +01:00
|
|
|
Atom at = AtomLive;
|
2006-12-13 16:10:26 +00:00
|
|
|
t = MkAtomTerm(at);
|
|
|
|
pe = RepPredProp(PredPropByAtom(at, CurrentModule));
|
|
|
|
}
|
|
|
|
break;
|
2006-03-06 14:04:57 +00:00
|
|
|
case _Ystop:
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
return UnifyPredInfo(pe, 3 PASS_REGS) &&
|
2007-01-24 10:01:40 +00:00
|
|
|
Yap_unify(ARG2, taddr) &&
|
|
|
|
Yap_unify(ARG6,t) &&
|
|
|
|
Yap_unify(ARG7,MkIntegerTerm(ClauseId(ncl,pe)));
|
2006-03-06 14:04:57 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 01:16:40 +01:00
|
|
|
|
|
|
|
static UInt
|
|
|
|
compute_dbcl_size(UInt arity)
|
|
|
|
{
|
|
|
|
UInt sz;
|
|
|
|
switch(arity) {
|
|
|
|
case 2:
|
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL,cc);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL,ccc);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL,cccc);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL,ccccc);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL,cccccc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sz = arity*(UInt)NEXTOP((yamop *)NULL,xc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (UInt)NEXTOP((yamop *)sz,p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DerefAndCheck(t, V) \
|
|
|
|
t = Deref(V); if(IsVarTerm(t) || !(IsAtomOrIntTerm(t))) Yap_Error(TYPE_ERROR_ATOM, t0, "load_db");
|
|
|
|
|
|
|
|
static int
|
|
|
|
store_dbcl_size(yamop *pc, UInt arity, Term t0, PredEntry *pe)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
CELL *tp = RepAppl(t0)+1;
|
|
|
|
switch(arity) {
|
|
|
|
case 2:
|
|
|
|
pc->opc = Yap_opcode(_get_2atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.cc.c1 = t;
|
|
|
|
DerefAndCheck(t, tp[1]);
|
|
|
|
pc->u.cc.c2 = t;
|
|
|
|
pc = NEXTOP(pc,cc);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pc->opc = Yap_opcode(_get_3atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.ccc.c1 = t;
|
|
|
|
DerefAndCheck(t, tp[1]);
|
|
|
|
pc->u.ccc.c2 = t;
|
|
|
|
DerefAndCheck(t, tp[2]);
|
|
|
|
pc->u.ccc.c3 = t;
|
|
|
|
pc = NEXTOP(pc,ccc);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pc->opc = Yap_opcode(_get_4atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.cccc.c1 = t;
|
|
|
|
DerefAndCheck(t, tp[1]);
|
|
|
|
pc->u.cccc.c2 = t;
|
|
|
|
DerefAndCheck(t, tp[2]);
|
|
|
|
pc->u.cccc.c3 = t;
|
|
|
|
DerefAndCheck(t, tp[3]);
|
|
|
|
pc->u.cccc.c4 = t;
|
|
|
|
pc = NEXTOP(pc,cccc);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
pc->opc = Yap_opcode(_get_5atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.ccccc.c1 = t;
|
|
|
|
DerefAndCheck(t, tp[1]);
|
|
|
|
pc->u.ccccc.c2 = t;
|
|
|
|
DerefAndCheck(t, tp[2]);
|
|
|
|
pc->u.ccccc.c3 = t;
|
|
|
|
DerefAndCheck(t, tp[3]);
|
|
|
|
pc->u.ccccc.c4 = t;
|
|
|
|
DerefAndCheck(t, tp[4]);
|
|
|
|
pc->u.ccccc.c5 = t;
|
|
|
|
pc = NEXTOP(pc,ccccc);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
pc->opc = Yap_opcode(_get_6atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.cccccc.c1 = t;
|
|
|
|
DerefAndCheck(t, tp[1]);
|
|
|
|
pc->u.cccccc.c2 = t;
|
|
|
|
DerefAndCheck(t, tp[2]);
|
|
|
|
pc->u.cccccc.c3 = t;
|
|
|
|
DerefAndCheck(t, tp[3]);
|
|
|
|
pc->u.cccccc.c4 = t;
|
|
|
|
DerefAndCheck(t, tp[4]);
|
|
|
|
pc->u.cccccc.c5 = t;
|
|
|
|
DerefAndCheck(t, tp[5]);
|
|
|
|
pc->u.cccccc.c6 = t;
|
|
|
|
pc = NEXTOP(pc,cccccc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
UInt i;
|
|
|
|
for (i = 0; i< arity; i++) {
|
|
|
|
pc->opc = Yap_opcode(_get_atom);
|
|
|
|
#if PRECOMPUTE_REGADDRESS
|
|
|
|
pc->u.xc.x = (CELL) (XREGS + (i+1));
|
|
|
|
#else
|
|
|
|
pc->u.xc.x = i+1;
|
|
|
|
#endif
|
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->u.xc.c = t;
|
|
|
|
tp++;
|
|
|
|
pc = NEXTOP(pc,xc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pc->opc = Yap_opcode(_procceed);
|
|
|
|
pc->u.p.p = pe;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_dbload_get_space( USES_REGS1 )
|
|
|
|
{ /* '$number_of_clauses'(Predicate,M,N) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
UInt arity;
|
|
|
|
Prop pe;
|
|
|
|
PredEntry *ap;
|
|
|
|
UInt sz;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
|
|
|
UInt ncls;
|
|
|
|
UInt required;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
arity = 0;
|
|
|
|
pe = PredPropByAtom(a, mod);
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
pe = PredPropByFunc(f, mod);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
ap = RepPredProp(pe);
|
|
|
|
if (ap->PredFlags & (DynamicPredFlag|LogUpdatePredFlag
|
|
|
|
#ifdef TABLING
|
|
|
|
|TabledPredFlag
|
|
|
|
#endif /* TABLING */
|
|
|
|
)) {
|
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE,t,"dbload_get_space/4");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (IsVarTerm(tn) || !IsIntegerTerm(tn)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ncls = IntegerOfTerm(tn);
|
|
|
|
if (ncls <= 1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = compute_dbcl_size(arity);
|
|
|
|
required = sz*ncls+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l);
|
|
|
|
#ifdef DEBUG
|
|
|
|
total_megaclause += required;
|
|
|
|
nof_megaclauses++;
|
|
|
|
#endif
|
|
|
|
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
|
|
|
if (!Yap_growheap(FALSE, required, NULL)) {
|
|
|
|
/* just fail, the system will keep on going */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Yap_ClauseSpace += required;
|
|
|
|
/* cool, it's our turn to do the conversion */
|
|
|
|
mcl->ClFlags = MegaMask;
|
|
|
|
mcl->ClSize = sz*ncls;
|
|
|
|
mcl->ClPred = ap;
|
|
|
|
mcl->ClItemSize = sz;
|
|
|
|
mcl->ClNext = NULL;
|
|
|
|
ap->cs.p_code.FirstClause =
|
|
|
|
ap->cs.p_code.LastClause =
|
|
|
|
mcl->ClCode;
|
|
|
|
ap->PredFlags |= MegaClausePredFlag;
|
|
|
|
ap->cs.p_code.NOfClauses = ncls;
|
|
|
|
if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
} else {
|
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
}
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
ptr = (yamop *)((ADDR)mcl->ClCode+ncls*sz);
|
|
|
|
ptr->opc = Yap_opcode(_Ystop);
|
|
|
|
return Yap_unify(ARG4, MkIntegerTerm((Int)mcl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_dbassert( USES_REGS1 )
|
|
|
|
{ /* '$number_of_clauses'(Predicate,M,N) */
|
|
|
|
Term thandle = Deref(ARG2);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
PredEntry *pe;
|
|
|
|
MegaClause *mcl;
|
|
|
|
Int n;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsVarTerm(thandle) || !IsIntegerTerm(thandle)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
mcl = (MegaClause *)IntegerOfTerm(thandle);
|
|
|
|
if (IsVarTerm(tn) || !IsIntegerTerm(tn)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
n = IntegerOfTerm(tn);
|
|
|
|
pe = mcl->ClPred;
|
|
|
|
return store_dbcl_size((yamop *)((ADDR)mcl->ClCode+n*(mcl->ClItemSize)),pe->ArityOfPE,Deref(ARG1),pe);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCdMgr(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2007-01-24 10:01:40 +00:00
|
|
|
Term cm = CurrentModule;
|
|
|
|
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$compile_mode", 2, p_compile_mode, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$start_consult", 3, p_startconsult, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$show_consult_level", 1, p_showconslultlev, SafePredFlag);
|
|
|
|
Yap_InitCPred("$end_consult", 0, p_endconsult, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$set_spy", 2, p_setspy, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$rm_spy", 2, p_rmspy, SafePredFlag|SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* gc() may happen during compilation, hence these predicates are
|
|
|
|
now unsafe */
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$compile", 4, p_compile, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$compile_dynamic", 5, p_compile_dynamic, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$purge_clauses", 2, p_purge_clauses, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$in_use", 2, p_in_use, TestPredFlag | SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_dynamic", 2, p_is_dynamic, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_metapredicate", 2, p_is_metapredicate, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_expand_goal_or_meta_predicate", 2, p_is_expandgoalormetapredicate, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_log_updatable", 2, p_is_log_updatable, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_source", 2, p_is_source, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$owner_file", 3, p_owner_file, SafePredFlag);
|
|
|
|
Yap_InitCPred("$mk_d", 2, p_mk_d, SafePredFlag);
|
|
|
|
Yap_InitCPred("$pred_exists", 2, p_pred_exists, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$number_of_clauses", 3, p_number_of_clauses, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$undefined", 2, p_undefined, SafePredFlag|TestPredFlag);
|
|
|
|
Yap_InitCPred("$optimizer_on", 0, p_optimizer_on, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$clean_up_dead_clauses", 0, p_clean_up_dead_clauses, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$optimizer_off", 0, p_optimizer_off, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$kill_dynamic", 2, p_kill_dynamic, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$new_multifile", 3, p_new_multifile, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_multifile", 2, p_is_multifile, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_profiled", 1, p_is_profiled, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$profile_info", 3, p_profile_info, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$profile_reset", 2, p_profile_reset, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_call_counted", 1, p_is_call_counted, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_info", 3, p_call_count_info, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_set", 6, p_call_count_set, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_reset", 0, p_call_count_reset, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$toggle_static_predicates_in_use", 0, p_toggle_static_predicates_in_use, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$set_pred_module", 2, p_set_pred_module, SafePredFlag);
|
|
|
|
Yap_InitCPred("$parent_pred", 3, p_parent_pred, SafePredFlag);
|
|
|
|
Yap_InitCPred("$system_predicate", 2, p_system_pred, SafePredFlag);
|
|
|
|
Yap_InitCPred("$all_system_predicate", 3, p_all_system_pred, SafePredFlag);
|
|
|
|
Yap_InitCPred("$hide_predicate", 2, p_hide_predicate, SafePredFlag);
|
2012-11-25 23:36:43 +00:00
|
|
|
Yap_InitCPred("$stash_predicate", 2, p_stash_predicate, SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$hidden_predicate", 2, p_hidden_predicate, SafePredFlag);
|
|
|
|
Yap_InitCPred("$pred_for_code", 5, p_pred_for_code, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$current_stack", 1, p_current_stack, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$log_update_clause", 4, p_log_update_clause, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_log_update_clause", 5, p_continue_log_update_clause, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$log_update_clause_erase", 4, p_log_update_clause_erase, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_log_update_clause_erase", 5, p_continue_log_update_clause_erase, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$static_clause", 4, p_static_clause, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_static_clause", 5, p_continue_static_clause, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$static_pred_statistics", 5, p_static_pred_statistics, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$p_nth_clause", 4, p_nth_clause, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$program_continuation", 3, p_program_continuation, SafePredFlag|SyncPredFlag);
|
2007-01-24 10:01:40 +00:00
|
|
|
CurrentModule = HACKS_MODULE;
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("current_choicepoints", 1, p_all_choicepoints, 0);
|
|
|
|
Yap_InitCPred("current_continuations", 1, p_all_envs, 0);
|
|
|
|
Yap_InitCPred("choicepoint", 7, p_choicepoint_info, 0);
|
|
|
|
Yap_InitCPred("continuation", 4, p_env_info,0);
|
|
|
|
Yap_InitCPred("cp_to_predicate", 5, p_cpc_info, 0);
|
2007-01-24 10:01:40 +00:00
|
|
|
CurrentModule = cm;
|
2011-04-30 01:16:40 +01:00
|
|
|
CurrentModule = DBLOAD_MODULE;
|
|
|
|
Yap_InitCPred("dbload_get_space", 4, p_dbload_get_space, 0L);
|
|
|
|
Yap_InitCPred("dbassert", 3, p_dbassert, 0L);
|
|
|
|
CurrentModule = cm;
|
2006-11-15 00:13:37 +00:00
|
|
|
Yap_InitCPred("$predicate_erased_statistics", 5, p_predicate_erased_statistics, SyncPredFlag);
|
2004-04-07 23:04:04 +01:00
|
|
|
#ifdef DEBUG
|
2006-11-15 00:13:37 +00:00
|
|
|
Yap_InitCPred("$predicate_live_cps", 4, p_predicate_lu_cps, 0L);
|
2004-04-07 23:04:04 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
|