| 
									
										
										
										
											2001-04-09 19:54:03 +00: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:		index.c							 * | 
					
						
							|  |  |  |  | * comments:	Indexing a Prolog predicate				 * | 
					
						
							|  |  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  |  | * Last rev:     $Date: 2008-08-07 20:51:21 $,$Author: vsc $						 * | 
					
						
							| 
									
										
										
										
											2004-03-25 02:19:10 +00:00
										 |  |  |  | * $Log: not supported by cvs2svn $ | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  |  | * Revision 1.202  2008/07/11 17:02:07  vsc | 
					
						
							|  |  |  |  | * fixes by Bart and Tom: mostly libraries but nasty one in indexing | 
					
						
							|  |  |  |  | * compilation. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-07-11 17:02:10 +00:00
										 |  |  |  | * Revision 1.201  2008/05/10 23:24:11  vsc | 
					
						
							|  |  |  |  | * fix threads and LU | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | * Revision 1.200  2008/04/16 17:16:47  vsc | 
					
						
							|  |  |  |  | * make static_clause only commit to a lause if it is sure that is the true | 
					
						
							|  |  |  |  | * clause. Otherwise, search for the clause. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | * Revision 1.199  2008/04/14 21:20:35  vsc | 
					
						
							|  |  |  |  | * fixed a bug in static_clause (thanks to Jose Santos) | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-14 21:20:36 +00:00
										 |  |  |  | * Revision 1.198  2008/03/25 16:45:53  vsc | 
					
						
							|  |  |  |  | * make or-parallelism compile again | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-03-25 16:45:53 +00:00
										 |  |  |  | * Revision 1.197  2008/02/14 14:35:13  vsc | 
					
						
							|  |  |  |  | * fixes for indexing code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-02-14 14:35:13 +00:00
										 |  |  |  | * Revision 1.196  2008/01/30 10:35:43  vsc | 
					
						
							|  |  |  |  | * fix indexing in 64 bits (it would split ints from atoms :( ). | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  | * Revision 1.195  2008/01/24 10:20:42  vsc | 
					
						
							|  |  |  |  | * clause should not try to discover who is fail. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-01-24 10:20:42 +00:00
										 |  |  |  | * Revision 1.194  2008/01/24 00:11:59  vsc | 
					
						
							|  |  |  |  | * garbage collector was not asking for space. | 
					
						
							|  |  |  |  | * avoid 0 sized calls to mmap. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-01-24 00:11:59 +00:00
										 |  |  |  | * Revision 1.193  2008/01/23 17:57:46  vsc | 
					
						
							|  |  |  |  | * valgrind it! | 
					
						
							|  |  |  |  | * enable atom garbage collection. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | * Revision 1.192  2007/11/26 23:43:08  vsc | 
					
						
							|  |  |  |  | * fixes to support threads and assert correctly, even if inefficiently. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | * Revision 1.191  2007/11/08 15:52:15  vsc | 
					
						
							|  |  |  |  | * fix some bugs in new dbterm code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-08 15:52:15 +00:00
										 |  |  |  | * Revision 1.190  2007/11/07 09:25:27  vsc | 
					
						
							|  |  |  |  | * speedup meta-calls | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-07 09:25:27 +00:00
										 |  |  |  | * Revision 1.189  2007/11/06 17:02:12  vsc | 
					
						
							|  |  |  |  | * compile ground terms away. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-06 17:02:13 +00:00
										 |  |  |  | * Revision 1.188  2007/10/28 11:23:40  vsc | 
					
						
							|  |  |  |  | * fix overflow | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-28 11:23:41 +00:00
										 |  |  |  | * Revision 1.187  2007/09/22 08:38:05  vsc | 
					
						
							|  |  |  |  | * nb_ extra stuff plus an indexing overflow fix. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  | * Revision 1.186  2007/06/20 13:48:45  vsc | 
					
						
							|  |  |  |  | * fix bug in index emulator | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | * Revision 1.185  2007/05/02 11:01:37  vsc | 
					
						
							|  |  |  |  | * get rid of type punning warnings. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | * Revision 1.184  2007/03/26 15:18:43  vsc | 
					
						
							|  |  |  |  | * debugging and clause/3 over tabled predicates would kill YAP. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-03-26 15:18:43 +00:00
										 |  |  |  | * Revision 1.183  2007/03/21 23:23:46  vsc | 
					
						
							|  |  |  |  | * fix excessive trail cleaning in gc tr overflow. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | * Revision 1.182  2007/01/28 14:26:36  vsc | 
					
						
							|  |  |  |  | * WIN32 support | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  |  | * Revision 1.181  2007/01/08 08:27:19  vsc | 
					
						
							|  |  |  |  | * fix restore (Trevor) | 
					
						
							|  |  |  |  | * make indexing a bit faster on IDB | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |  | * Revision 1.180  2006/12/27 01:32:37  vsc | 
					
						
							|  |  |  |  | * diverse fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | * Revision 1.179  2006/11/27 17:42:02  vsc | 
					
						
							|  |  |  |  | * support for UNICODE, and other bug fixes. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  | * Revision 1.178  2006/11/21 16:21:31  vsc | 
					
						
							|  |  |  |  | * fix I/O mess | 
					
						
							|  |  |  |  | * fix spy/reconsult mess | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-21 16:21:33 +00:00
										 |  |  |  | * Revision 1.177  2006/11/15 00:13:36  vsc | 
					
						
							|  |  |  |  | * fixes for indexing code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-15 00:13:37 +00:00
										 |  |  |  | * Revision 1.176  2006/11/08 01:53:08  vsc | 
					
						
							|  |  |  |  | * avoid generating suspensions on static code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-08 01:53:08 +00:00
										 |  |  |  | * Revision 1.175  2006/11/06 18:35:04  vsc | 
					
						
							|  |  |  |  | * 1estranha | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | * Revision 1.174  2006/10/25 02:31:07  vsc | 
					
						
							|  |  |  |  | * fix emulation of trust_logical | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-10-25 02:31:07 +00:00
										 |  |  |  | * Revision 1.173  2006/10/18 13:47:31  vsc | 
					
						
							|  |  |  |  | * index.c implementation of trust_logical was decrementing the wrong | 
					
						
							|  |  |  |  | * cp_tr | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-10-18 13:47:32 +00:00
										 |  |  |  | * Revision 1.172  2006/10/16 17:12:48  vsc | 
					
						
							|  |  |  |  | * fixes for threaded version. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-10-16 17:12:48 +00:00
										 |  |  |  | * Revision 1.171  2006/10/11 14:53:57  vsc | 
					
						
							|  |  |  |  | * fix memory leak | 
					
						
							|  |  |  |  | * fix overflow handling | 
					
						
							|  |  |  |  | * VS: ---------------------------------------------------------------------- | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | * Revision 1.170  2006/10/10 14:08:16  vsc | 
					
						
							|  |  |  |  | * small fixes on threaded implementation. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | * Revision 1.169  2006/09/20 20:03:51  vsc | 
					
						
							|  |  |  |  | * improve indexing on floats | 
					
						
							|  |  |  |  | * fix sending large lists to DB | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  | * Revision 1.168  2006/05/16 18:37:30  vsc | 
					
						
							|  |  |  |  | * WIN32 fixes | 
					
						
							|  |  |  |  | * compiler bug fixes | 
					
						
							|  |  |  |  | * extend interface | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  | * Revision 1.167  2006/05/02 16:44:11  vsc | 
					
						
							|  |  |  |  | * avoid uninitialised memory at overflow. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-05-02 16:44:11 +00:00
										 |  |  |  | * Revision 1.166  2006/05/02 16:39:06  vsc | 
					
						
							|  |  |  |  | * bug in indexing code | 
					
						
							|  |  |  |  | * fix warning messages for write.c | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-05-02 16:39:06 +00:00
										 |  |  |  | * Revision 1.165  2006/04/27 17:04:08  vsc | 
					
						
							|  |  |  |  | * don't use <= to compare with block top (libc may not have block header). | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  | * Revision 1.164  2006/04/27 14:10:36  rslopes | 
					
						
							|  |  |  |  | * *** empty log message *** | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-04-27 14:13:24 +00:00
										 |  |  |  | * Revision 1.163  2006/04/20 15:28:08  vsc | 
					
						
							|  |  |  |  | * more graph stuff. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-04-20 15:28:08 +00:00
										 |  |  |  | * Revision 1.162  2006/04/12 18:56:50  vsc | 
					
						
							|  |  |  |  | * fix bug in clause: a trust_me followed by a try should be implemented by | 
					
						
							|  |  |  |  | * reusing the choice-point. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  | * Revision 1.161  2006/04/05 00:16:54  vsc | 
					
						
							|  |  |  |  | * Lots of fixes (check logfile for details | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-04-05 00:16:55 +00:00
										 |  |  |  | * Revision 1.160  2006/03/24 17:13:41  rslopes | 
					
						
							|  |  |  |  | * New update to BEAM engine. | 
					
						
							|  |  |  |  | * BEAM now uses YAP Indexing (JITI) | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-24 17:13:41 +00:00
										 |  |  |  | * Revision 1.159  2006/03/22 20:07:28  vsc | 
					
						
							|  |  |  |  | * take better care of zombies | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-22 20:07:28 +00:00
										 |  |  |  | * Revision 1.158  2006/03/21 21:30:54  vsc | 
					
						
							|  |  |  |  | * avoid looking around when expanding for statics too. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | * Revision 1.157  2006/03/21 19:20:34  vsc | 
					
						
							|  |  |  |  | * fix fix on index expansion | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-21 19:20:35 +00:00
										 |  |  |  | * Revision 1.156  2006/03/21 17:11:39  vsc | 
					
						
							|  |  |  |  | * prevent breakage | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-21 17:11:39 +00:00
										 |  |  |  | * Revision 1.155  2006/03/21 15:06:35  vsc | 
					
						
							|  |  |  |  | * fixes to handle expansion of dyn amic predicates more efficiently. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  | * Revision 1.154  2006/03/20 19:51:43  vsc | 
					
						
							|  |  |  |  | * fix indexing and tabling bugs | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  | * Revision 1.153  2006/02/22 11:55:36  vsc | 
					
						
							|  |  |  |  | * indexing code would get confused about size of float/1, db_reference1. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-02-22 11:55:36 +00:00
										 |  |  |  | * Revision 1.152  2006/02/19 02:55:46  vsc | 
					
						
							|  |  |  |  | * disable indexing on bigints | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-02-19 02:55:46 +00:00
										 |  |  |  | * Revision 1.151  2006/01/16 02:57:51  vsc | 
					
						
							|  |  |  |  | * fix bug with very large integers | 
					
						
							|  |  |  |  | * fix bug where indexing code was looking at code after a cut. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-01-16 02:57:52 +00:00
										 |  |  |  | * Revision 1.150  2005/12/23 00:20:13  vsc | 
					
						
							|  |  |  |  | * updates to gprof | 
					
						
							|  |  |  |  | * support for __POWER__ | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  | * Try to saveregs before siglongjmp. | 
					
						
							| 
									
										
										
										
											2006-01-16 02:57:52 +00:00
										 |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  | * Revision 1.149  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.148  2005/11/24 15:33:52  tiagosoares | 
					
						
							|  |  |  |  | * removed some compilation warnings related to the cut-c code | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-11-24 15:35:29 +00:00
										 |  |  |  | * Revision 1.147  2005/11/18 18:48:52  tiagosoares | 
					
						
							|  |  |  |  | * support for executing c code when a cut occurs | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | * Revision 1.146  2005/10/29 02:21:47  vsc | 
					
						
							|  |  |  |  | * people should be able to disable indexing. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-29 02:21:47 +00:00
										 |  |  |  | * Revision 1.145  2005/09/08 22:06:44  rslopes | 
					
						
							|  |  |  |  | * BEAM for YAP update... | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  |  | * Revision 1.144  2005/08/17 18:48:35  vsc | 
					
						
							|  |  |  |  | * fix bug in processing overflows of expand_clauses. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-08-17 18:48:35 +00:00
										 |  |  |  | * Revision 1.143  2005/08/02 03:09:50  vsc | 
					
						
							|  |  |  |  | * fix debugger to do well nonsource predicates. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-08-02 03:09:52 +00:00
										 |  |  |  | * Revision 1.142  2005/08/01 15:40:37  ricroc | 
					
						
							|  |  |  |  | * TABLING NEW: better support for incomplete tabling | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-08-01 15:40:39 +00:00
										 |  |  |  | * Revision 1.141  2005/07/19 16:54:20  rslopes | 
					
						
							|  |  |  |  | * fix for older compilers... | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-07-19 16:54:20 +00:00
										 |  |  |  | * Revision 1.140  2005/07/18 17:41:16  vsc | 
					
						
							|  |  |  |  | * Yap should respect single argument indexing. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-07-18 17:41:16 +00:00
										 |  |  |  | * Revision 1.139  2005/07/06 19:33:53  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 19:34:12 +00:00
										 |  |  |  | * Revision 1.138  2005/07/05 18:32:32  vsc | 
					
						
							|  |  |  |  | * ifix some wierd cases in indexing code: | 
					
						
							|  |  |  |  | * would not look at next argument | 
					
						
							|  |  |  |  | * problem with pvar as last clause (R Camacho). | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  | * Revision 1.137  2005/06/04 07:27:34  ricroc | 
					
						
							|  |  |  |  | * long int support for tabling | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-06-04 07:28:24 +00:00
										 |  |  |  | * Revision 1.136  2005/06/03 08:26:32  ricroc | 
					
						
							|  |  |  |  | * float support for tabling | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-06-03 08:26:32 +00:00
										 |  |  |  | * Revision 1.135  2005/06/01 20:25:23  vsc | 
					
						
							|  |  |  |  | * == and \= should not need a choice-point in -> | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-06-01 20:25:23 +00:00
										 |  |  |  | * Revision 1.134  2005/06/01 16:42:30  vsc | 
					
						
							|  |  |  |  | * put switch_list_nl back | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  | * Revision 1.133  2005/06/01 14:02:50  vsc | 
					
						
							|  |  |  |  | * get_rid of try_me?, retry_me? and trust_me? instructions: they are not | 
					
						
							|  |  |  |  | * significantly used nowadays. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-06-01 14:02:52 +00:00
										 |  |  |  | * Revision 1.132  2005/05/31 20:04:17  vsc | 
					
						
							|  |  |  |  | * fix cleanup of expand_clauses: make sure we have everything with NULL afterwards. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-31 20:04:17 +00:00
										 |  |  |  | * Revision 1.131  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 19:42:28 +00:00
										 |  |  |  | * Revision 1.130  2005/05/31 04:46:06  vsc | 
					
						
							|  |  |  |  | * fix expand_index on tabled code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  | * Revision 1.129  2005/05/31 02:15:53  vsc | 
					
						
							|  |  |  |  | * fix SYSTEM_ERROR messages | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-31 02:15:53 +00:00
										 |  |  |  | * Revision 1.128  2005/05/30 05:26:49  vsc | 
					
						
							|  |  |  |  | * fix tabling | 
					
						
							|  |  |  |  | * allow atom gc again for now. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  | * Revision 1.127  2005/05/27 21:44:00  vsc | 
					
						
							|  |  |  |  | * Don't try to mess with sequences that don't end with a trust. | 
					
						
							|  |  |  |  | * A fix for the atom garbage collector actually ignore floats ;-). | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-27 21:44:00 +00:00
										 |  |  |  | * Revision 1.126  2005/05/25 18:58:37  vsc | 
					
						
							|  |  |  |  | * fix another bug in nth_instance, thanks to Pat Caldon | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-25 18:58:38 +00:00
										 |  |  |  | * Revision 1.125  2005/04/28 14:50:45  vsc | 
					
						
							|  |  |  |  | * clause should always deref before testing type | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-28 14:50:45 +00:00
										 |  |  |  | * Revision 1.124  2005/04/27 20:09:25  vsc | 
					
						
							|  |  |  |  | * indexing code could get confused with suspension points | 
					
						
							|  |  |  |  | * some further improvements on oveflow handling | 
					
						
							|  |  |  |  | * fix paths in Java makefile | 
					
						
							|  |  |  |  | * changs to support gibbs sampling in CLP(BN) | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-27 20:09:26 +00:00
										 |  |  |  | * Revision 1.123  2005/04/21 13:53:05  vsc | 
					
						
							|  |  |  |  | * fix bug with (var(X) -> being interpreted as var(X) by indexing code | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-21 13:53:05 +00:00
										 |  |  |  | * Revision 1.122  2005/04/10 04:01:12  vsc | 
					
						
							|  |  |  |  | * bug fixes, I hope! | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | * Revision 1.121  2005/04/07 17:48:54  ricroc | 
					
						
							|  |  |  |  | * Adding tabling support for mixed strategy evaluation (batched and local scheduling) | 
					
						
							|  |  |  |  | *   UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and -DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the Makefile or --enable-tabling in configure. | 
					
						
							|  |  |  |  | *   NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all tabled predicates to MODE (batched, local or default). | 
					
						
							|  |  |  |  | *   NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of predicate PRED to MODE (batched or local). | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | * Revision 1.120  2005/03/15 18:29:23  vsc | 
					
						
							|  |  |  |  | * fix GPL | 
					
						
							|  |  |  |  | * fix idb: stuff in coroutines. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-15 18:29:25 +00:00
										 |  |  |  | * Revision 1.119  2005/03/04 20:30:12  ricroc | 
					
						
							|  |  |  |  | * bug fixes for YapTab support | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-04 20:30:14 +00:00
										 |  |  |  | * Revision 1.118  2005/03/01 22:25:08  vsc | 
					
						
							|  |  |  |  | * fix pruning bug | 
					
						
							|  |  |  |  | * make DL_MALLOC less enthusiastic about walking through buckets. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |  | * Revision 1.117  2005/02/25 00:09:06  vsc | 
					
						
							|  |  |  |  | * fix fix, otherwise I'd remove two choice-points :-(. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-02-25 00:09:06 +00:00
										 |  |  |  | * Revision 1.116  2005/02/24 21:46:39  vsc | 
					
						
							|  |  |  |  | * Improve error handling routine, trying to make it more robust. | 
					
						
							|  |  |  |  | * Improve hole handling in stack expansion | 
					
						
							|  |  |  |  | * Clause interrpeter was supposed to prune _trust_me | 
					
						
							|  |  |  |  | * Wrong messages for acos and atanh | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-02-24 21:46:40 +00:00
										 |  |  |  | * Revision 1.115  2005/02/21 16:50:00  vsc | 
					
						
							|  |  |  |  | * amd64 fixes | 
					
						
							|  |  |  |  | * library fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-02-21 16:50:21 +00:00
										 |  |  |  | * Revision 1.114  2005/01/28 23:14:36  vsc | 
					
						
							|  |  |  |  | * move to Yap-4.5.7 | 
					
						
							|  |  |  |  | * Fix clause size | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-01-28 23:14:41 +00:00
										 |  |  |  | * Revision 1.113  2005/01/15 05:21:36  vsc | 
					
						
							|  |  |  |  | * fix bug in clause emulator | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-01-15 05:21:36 +00:00
										 |  |  |  | * Revision 1.112  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.111  2004/12/21 17:17:15  vsc | 
					
						
							|  |  |  |  | * miscounting of variable-only clauses in groups might lead to bug in indexing | 
					
						
							|  |  |  |  | * code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-12-21 17:17:15 +00:00
										 |  |  |  | * Revision 1.110  2004/12/06 04:50:22  vsc | 
					
						
							|  |  |  |  | * fix bug in removing first clause of a try sequence (lu preds) | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-12-06 04:50:22 +00:00
										 |  |  |  | * Revision 1.109  2004/12/05 05:01:24  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.108  2004/11/19 22:08:42  vsc | 
					
						
							|  |  |  |  | * replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-11-19 22:08:43 +00:00
										 |  |  |  | * Revision 1.107  2004/11/19 17:14:14  vsc | 
					
						
							|  |  |  |  | * a few fixes for 64 bit compiling. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-11-19 17:14:15 +00:00
										 |  |  |  | * Revision 1.106  2004/11/18 22:32:36  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.105  2004/11/04 18:22:32  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.104  2004/10/27 15:56:33  vsc | 
					
						
							|  |  |  |  | * bug fixes on memory overflows and on clauses :- fail being ignored by clause. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-27 15:56:34 +00:00
										 |  |  |  | * Revision 1.103  2004/10/22 16:53:19  vsc | 
					
						
							|  |  |  |  | * bug fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  | * Revision 1.102  2004/10/04 18:56:19  vsc | 
					
						
							|  |  |  |  | * fixes for thread support | 
					
						
							|  |  |  |  | * fix indexing bug (serious) | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-04 18:56:20 +00:00
										 |  |  |  | * Revision 1.101  2004/09/30 21:37:41  vsc | 
					
						
							|  |  |  |  | * fixes for thread support | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-09-30 21:37:41 +00:00
										 |  |  |  | * Revision 1.100  2004/09/30 19:51:54  vsc | 
					
						
							|  |  |  |  | * fix overflow from within clause/2 | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  | * Revision 1.99  2004/09/27 20:45:03  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 20:45:04 +00:00
										 |  |  |  | * Revision 1.98  2004/09/14 03:30:06  vsc | 
					
						
							|  |  |  |  | * make sure that condor version always grows trail! | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | * Revision 1.97  2004/09/03 03:11:09  vsc | 
					
						
							|  |  |  |  | * memory management fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-09-03 03:11:09 +00:00
										 |  |  |  | * Revision 1.96  2004/08/27 20:18:52  vsc | 
					
						
							|  |  |  |  | * more small fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-08-27 20:18:52 +00:00
										 |  |  |  | * Revision 1.95  2004/08/11 16:14:52  vsc | 
					
						
							|  |  |  |  | * whole lot of fixes: | 
					
						
							|  |  |  |  | *   - memory leak in indexing | 
					
						
							|  |  |  |  | *   - memory management in WIN32 now supports holes | 
					
						
							|  |  |  |  | *   - extend Yap interface, more support for SWI-Interface | 
					
						
							|  |  |  |  | *   - new predicate mktime in system | 
					
						
							|  |  |  |  | *   - buffer console I/O in WIN32 | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  |  | * Revision 1.94  2004/07/29 18:15:18  vsc | 
					
						
							|  |  |  |  | * fix severe bug in indexing of floating point numbers | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-07-29 18:15:19 +00:00
										 |  |  |  | * Revision 1.93  2004/07/23 19:01:14  vsc | 
					
						
							|  |  |  |  | * fix bad ref count in expand_clauses when copying indexing block | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-07-23 19:01:14 +00:00
										 |  |  |  | * Revision 1.92  2004/06/29 19:04:42  vsc | 
					
						
							|  |  |  |  | * fix multithreaded version | 
					
						
							|  |  |  |  | * include new version of Ricardo's profiler | 
					
						
							|  |  |  |  | * new predicat atomic_concat | 
					
						
							|  |  |  |  | * allow multithreaded-debugging | 
					
						
							|  |  |  |  | * small fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  |  | * Revision 1.91  2004/06/17 22:07:23  vsc | 
					
						
							|  |  |  |  | * bad bug in indexing code. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-17 22:07:23 +00:00
										 |  |  |  | * Revision 1.90  2004/04/29 03:44:04  vsc | 
					
						
							|  |  |  |  | * fix bad suspended clause counter | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-29 03:44:04 +00:00
										 |  |  |  | * Revision 1.89  2004/04/27 15:03:43  vsc | 
					
						
							|  |  |  |  | * more fixes for expand_clauses | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-27 15:03:43 +00:00
										 |  |  |  | * Revision 1.88  2004/04/22 03:24:17  vsc | 
					
						
							|  |  |  |  | * trust_logical should protect the last clause, otherwise it cannot | 
					
						
							|  |  |  |  | * jump there. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-22 03:24:17 +00:00
										 |  |  |  | * Revision 1.87  2004/04/21 04:01:53  vsc | 
					
						
							|  |  |  |  | * fix bad ordering when inserting second clause | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-21 04:01:53 +00:00
										 |  |  |  | * Revision 1.86  2004/04/20 22:08:23  vsc | 
					
						
							|  |  |  |  | * fixes for corourining | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-20 22:08:57 +00:00
										 |  |  |  | * Revision 1.85  2004/04/16 19:27:31  vsc | 
					
						
							|  |  |  |  | * more bug fixes | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | * Revision 1.84  2004/04/14 19:10:38  vsc | 
					
						
							|  |  |  |  | * expand_clauses: keep a list of clauses to expand | 
					
						
							|  |  |  |  | * fix new trail scheme for multi-assignment variables | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  | * Revision 1.83  2004/04/07 22:04:04  vsc | 
					
						
							|  |  |  |  | * fix memory leaks | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-07 22:04:04 +00:00
										 |  |  |  | * Revision 1.82  2004/03/31 01:02:18  vsc | 
					
						
							|  |  |  |  | * if number of left-over < 1/5 keep list of clauses to expand around | 
					
						
							|  |  |  |  | * fix call to stack expander | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | * Revision 1.81  2004/03/25 02:19:10  pmoura | 
					
						
							|  |  |  |  | * Removed debugging line to allow compilation. | 
					
						
							|  |  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-03-25 02:19:10 +00:00
										 |  |  |  | * Revision 1.80  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 19:54:03 +00:00
										 |  |  |  | *************************************************************************/ | 
					
						
							|  |  |  |  | #ifdef SCCS
 | 
					
						
							|  |  |  |  | static char     SccsId[] = "%W% %G%"; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * This file compiles and removes the indexation code for the prolog compiler  | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Some remarks: *try_me always point to inside the code; | 
					
						
							|  |  |  |  |  * try always points to outside  | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  Algorithm: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  - fetch info on all clauses | 
					
						
							|  |  |  |  |  - if #clauses =1  return | 
					
						
							|  |  |  |  |  - compute groups: | 
					
						
							|  |  |  |  |     seq of variable only clauses | 
					
						
							|  |  |  |  |     seq: of one or more type instructions | 
					
						
							|  |  |  |  |          bound clauses | 
					
						
							|  |  |  |  |  - sort group | 
					
						
							|  |  |  |  |  - select constant | 
					
						
							|  |  |  |  |           --> type instructions | 
					
						
							|  |  |  |  |           --> count constants | 
					
						
							|  |  |  |  |           --> switch | 
					
						
							|  |  |  |  | 	       for all arguments: | 
					
						
							|  |  |  |  | 	       select new argument  | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #include "absmi.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | #include "compile.h"
 | 
					
						
							|  |  |  |  | #include "index.h"
 | 
					
						
							|  |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  | #include "yapio.h"
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | #ifndef NULL
 | 
					
						
							|  |  |  |  | #define NULL (void *)0
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | #if HAVE_STRING_H
 | 
					
						
							|  |  |  |  | #include <string.h>
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  | #include "cut_c.h"
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							|  |  |  |  | #define SET_JLBL(X) jlbl = &(ipc->u.X)
 | 
					
						
							|  |  |  |  | #else
 | 
					
						
							|  |  |  |  | #define SET_JLBL(X)
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | UInt STATIC_PROTO(do_index, (ClauseDef *,ClauseDef *,struct intermediates *,UInt,UInt,int,int,CELL *)); | 
					
						
							|  |  |  |  | UInt STATIC_PROTO(do_compound_index, (ClauseDef *,ClauseDef *,Term *t,struct intermediates *,UInt,UInt,UInt,UInt,int,int,int,CELL *,int)); | 
					
						
							|  |  |  |  | UInt STATIC_PROTO(do_dbref_index, (ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *)); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | UInt STATIC_PROTO(do_blob_index, (ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *,int)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | static UInt | 
					
						
							|  |  |  |  | cleanup_sw_on_clauses(CELL larg, UInt sz, OPCODE ecls) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (larg & 1) { | 
					
						
							|  |  |  |  |     return sz; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     yamop *xp = (yamop *)larg; | 
					
						
							|  |  |  |  |     if (xp->opc == ecls) { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       if (xp->u.sssllp.s3 == 1) { | 
					
						
							|  |  |  |  | 	UInt nsz = sz + (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	LOCK(ExpandClausesListLock); | 
					
						
							|  |  |  |  | 	if (ExpandClausesFirst == xp) | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	  ExpandClausesFirst = xp->u.sssllp.snext; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	if (ExpandClausesLast == xp) { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	  ExpandClausesLast = xp->u.sssllp.sprev; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	if (xp->u.sssllp.sprev) { | 
					
						
							|  |  |  |  | 	  xp->u.sssllp.sprev->u.sssllp.snext = xp->u.sssllp.snext; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	if (xp->u.sssllp.snext) { | 
					
						
							|  |  |  |  | 	  xp->u.sssllp.snext->u.sssllp.sprev = xp->u.sssllp.sprev; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	UNLOCK(ExpandClausesListLock); | 
					
						
							| 
									
										
										
										
											2004-09-03 03:11:09 +00:00
										 |  |  |  | #if DEBUG
 | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | 	Yap_ExpandClauses--; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-09-03 03:11:09 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	if (xp->u.sssllp.p->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	  Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+xp->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	  Yap_IndexSpace_EXT -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	Yap_FreeCodeSpace((char *)xp); | 
					
						
							|  |  |  |  | 	return nsz; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	xp->u.sssllp.s3--; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	return sz; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       return sz; | 
					
						
							| 
									
										
										
										
											2004-08-27 20:18:52 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static UInt | 
					
						
							|  |  |  |  | recover_from_failed_susp_on_cls(struct intermediates *cint, UInt sz) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   /* we have to recover all allocated blocks,
 | 
					
						
							|  |  |  |  |      just follow the code through. */ | 
					
						
							|  |  |  |  |   struct PSEUDO *cpc = cint->CodeStart; | 
					
						
							|  |  |  |  |   OPCODE ecls = Yap_opcode(_expand_clauses); | 
					
						
							|  |  |  |  |   UInt log_upd_pred = cint->CurrentPred->PredFlags & LogUpdatePredFlag; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (cpc) { | 
					
						
							|  |  |  |  |     switch(cpc->op) { | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     case enter_lu_op: | 
					
						
							|  |  |  |  |       if (cpc->rnd4) { | 
					
						
							|  |  |  |  | 	yamop *code_p = (yamop *)cpc->rnd4; | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	yamop *first = code_p->u.Illss.l1; | 
					
						
							|  |  |  |  | 	yamop *last = code_p->u.Illss.l2; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | 	while (first) { | 
					
						
							|  |  |  |  | 	  yamop *next = first->u.OtaLl.n; | 
					
						
							|  |  |  |  | 	  LogUpdClause *cl = first->u.OtaLl.d; | 
					
						
							|  |  |  |  | 	  cl->ClRefCount--; | 
					
						
							|  |  |  |  | 	  Yap_FreeCodeSpace((char *)first); | 
					
						
							|  |  |  |  | 	  if (first == last)  | 
					
						
							|  |  |  |  | 	    break; | 
					
						
							|  |  |  |  | 	  first = next; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       cpc->rnd4 = Zero; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     case jump_v_op: | 
					
						
							|  |  |  |  |     case jump_nv_op: | 
					
						
							| 
									
										
										
										
											2004-08-27 20:18:52 +00:00
										 |  |  |  |       sz = cleanup_sw_on_clauses(cpc->rnd1, sz, ecls); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case switch_on_type_op: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	TypeSwitch *type_sw = (TypeSwitch *)(cpc->arnds); | 
					
						
							|  |  |  |  | 	sz = cleanup_sw_on_clauses(type_sw->PairEntry, sz, ecls); | 
					
						
							|  |  |  |  | 	sz = cleanup_sw_on_clauses(type_sw->ConstEntry, sz, ecls); | 
					
						
							|  |  |  |  | 	sz = cleanup_sw_on_clauses(type_sw->FuncEntry, sz, ecls); | 
					
						
							|  |  |  |  | 	sz = cleanup_sw_on_clauses(type_sw->VarEntry, sz, ecls); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case switch_c_op: | 
					
						
							|  |  |  |  |     case if_c_op: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	AtomSwiEntry *target = (AtomSwiEntry *)(cpc->rnd2); | 
					
						
							|  |  |  |  | 	int cases = cpc->rnd1, i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	for (i = 0; i < cases; i++) { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  sz = cleanup_sw_on_clauses(target[i].u.Label, sz, ecls); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (log_upd_pred) { | 
					
						
							|  |  |  |  | 	  LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); | 
					
						
							|  |  |  |  | 	  sz += sizeof(LogUpdIndex)+cases*sizeof(AtomSwiEntry); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | 	  Yap_LUIndexSpace_SW -= sizeof(LogUpdIndex)+cases*sizeof(AtomSwiEntry); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	  Yap_FreeCodeSpace((char *)lcl); | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); | 
					
						
							|  |  |  |  | 	  sz += sizeof(StaticIndex)+cases*sizeof(AtomSwiEntry); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | 	  Yap_IndexSpace_SW -= sizeof(StaticIndex)+cases*sizeof(AtomSwiEntry); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	  Yap_FreeCodeSpace((char *)scl); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case switch_f_op: | 
					
						
							|  |  |  |  |     case if_f_op: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	FuncSwiEntry *target = (FuncSwiEntry *)(cpc->rnd2); | 
					
						
							|  |  |  |  | 	int cases = cpc->rnd1, i; | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	for (i = 0; i < cases; i++) { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  sz = cleanup_sw_on_clauses(target[i].u.Label, sz, ecls); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (log_upd_pred) { | 
					
						
							|  |  |  |  | 	  LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); | 
					
						
							| 
									
										
										
										
											2004-08-27 20:18:52 +00:00
										 |  |  |  | 	  sz += sizeof(LogUpdIndex)+cases*sizeof(FuncSwiEntry); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | 	  Yap_LUIndexSpace_SW -= sizeof(LogUpdIndex)+cases*sizeof(FuncSwiEntry); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	  Yap_FreeCodeSpace((char *)lcl); | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  | 	  Yap_IndexSpace_SW -= sizeof(StaticIndex)+cases*sizeof(FuncSwiEntry); | 
					
						
							| 
									
										
										
										
											2004-08-27 20:18:52 +00:00
										 |  |  |  | 	  sz += sizeof(StaticIndex)+cases*sizeof(FuncSwiEntry); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	  Yap_FreeCodeSpace((char *)scl); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     default: | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     cpc = cpc->nextInst; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-15 11:37:39 +01:00
										 |  |  |  |   Yap_ReleaseCMem(cint); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |   if (cint->code_addr) { | 
					
						
							|  |  |  |  |     Yap_FreeCodeSpace((char *)cint->code_addr); | 
					
						
							|  |  |  |  |     cint->code_addr = NULL; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   return sz; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | static inline int | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | smaller(Term t1, Term t2) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   if (tg1 == tg2) { | 
					
						
							|  |  |  |  |     return t1 < t2; | 
					
						
							|  |  |  |  |   } else | 
					
						
							|  |  |  |  |     return tg1 < tg2; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | static inline int | 
					
						
							|  |  |  |  | smaller_or_eq(Term t1, Term t2) | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   if (tg1 == tg2) { | 
					
						
							|  |  |  |  |     return t1 <= t2; | 
					
						
							|  |  |  |  |   } else | 
					
						
							|  |  |  |  |     return tg1 < tg2; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static inline void | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | clcpy(ClauseDef *d, ClauseDef *s) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   memcpy((void *)d, (void *)s, sizeof(ClauseDef)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | insort(ClauseDef base[], CELL *p, CELL *q, int my_p) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   CELL *j; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   if (my_p) { | 
					
						
							|  |  |  |  |     p[1] = p[0]; | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     for (j = p; j < q; j += 2) { | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |       Term key; | 
					
						
							|  |  |  |  |       Int off = *j; | 
					
						
							|  |  |  |  |       CELL *i; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |       key = base[off].Tag; | 
					
						
							|  |  |  |  |       i = j+1; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |       /* we are at offset 1 */ | 
					
						
							|  |  |  |  |       while (i > p+1 && smaller(key,base[i[-2]].Tag)) { | 
					
						
							|  |  |  |  | 	i[0] = i[-2]; | 
					
						
							|  |  |  |  | 	i -= 2; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       i[0] = off; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     for (j = p+2; j < q; j += 2) { | 
					
						
							|  |  |  |  |       Term key; | 
					
						
							|  |  |  |  |       Int off = *j; | 
					
						
							|  |  |  |  |       CELL *i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       key = base[off].Tag; | 
					
						
							|  |  |  |  |       i = j; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |       /* we are at offset 1 */ | 
					
						
							|  |  |  |  |       while (i > p && smaller(key,base[i[-2]].Tag)) { | 
					
						
							|  |  |  |  | 	i[0] = i[-2]; | 
					
						
							|  |  |  |  | 	i -= 2; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       i[0] = off; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /* copy to a new list of terms */ | 
					
						
							|  |  |  |  | static | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  | void msort(ClauseDef *base, CELL *pt, Int size, int my_p) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (size > 2) { | 
					
						
							|  |  |  |  |     Int half_size = size / 2; | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  |     CELL *pt_left, *pt_right, *end_pt, *end_pt_left; | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |     int left_p, right_p; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (size < 50) { | 
					
						
							|  |  |  |  |        insort(base, pt, pt+2*size, my_p); | 
					
						
							|  |  |  |  |        return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     pt_right = pt + half_size*2; | 
					
						
							|  |  |  |  |     left_p = my_p^1; | 
					
						
							|  |  |  |  |     right_p = my_p; | 
					
						
							|  |  |  |  |     msort(base, pt, half_size, left_p); | 
					
						
							|  |  |  |  |     msort(base, pt_right, size-half_size, right_p); | 
					
						
							|  |  |  |  |     /* now implement a simple merge routine */ | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |      | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |     /* pointer to after the end of the list */ | 
					
						
							|  |  |  |  |     end_pt = pt + 2*size; | 
					
						
							|  |  |  |  |     /* pointer to the element after the last element to the left */ | 
					
						
							|  |  |  |  |     end_pt_left = pt+half_size*2; | 
					
						
							|  |  |  |  |     /* where is left list */ | 
					
						
							|  |  |  |  |     pt_left = pt+left_p; | 
					
						
							|  |  |  |  |     /* where is right list */ | 
					
						
							|  |  |  |  |     pt_right += right_p; | 
					
						
							|  |  |  |  |     /* where is new list */ | 
					
						
							|  |  |  |  |     pt += my_p; | 
					
						
							|  |  |  |  |     /* while there are elements in the left or right vector do compares */ | 
					
						
							|  |  |  |  |     while (pt_left < end_pt_left && pt_right < end_pt) { | 
					
						
							|  |  |  |  |       /* if the element to the left is larger than the one to the right */ | 
					
						
							|  |  |  |  |       if (smaller_or_eq(base[pt_left[0]].Tag, base[pt_right[0]].Tag)) { | 
					
						
							|  |  |  |  | 	/* copy the one to the left */ | 
					
						
							|  |  |  |  | 	pt[0] = pt_left[0]; | 
					
						
							|  |  |  |  | 	/* and avance the two pointers */ | 
					
						
							|  |  |  |  | 	pt += 2; | 
					
						
							|  |  |  |  | 	pt_left += 2; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* otherwise, copy the one to the right */ | 
					
						
							|  |  |  |  | 	pt[0] = pt_right[0]; | 
					
						
							|  |  |  |  | 	pt += 2; | 
					
						
							|  |  |  |  | 	pt_right += 2; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* if any elements were left in the left vector just copy them */ | 
					
						
							|  |  |  |  |     while (pt_left < end_pt_left) { | 
					
						
							|  |  |  |  |       pt[0] = pt_left[0]; | 
					
						
							|  |  |  |  |       pt += 2; | 
					
						
							|  |  |  |  |       pt_left += 2; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* if any elements were left in the right vector
 | 
					
						
							|  |  |  |  |        and they are in the wrong place, just copy them */ | 
					
						
							|  |  |  |  |     if (my_p != right_p) { | 
					
						
							|  |  |  |  |       while(pt_right < end_pt) { | 
					
						
							|  |  |  |  | 	pt[0] = pt_right[0]; | 
					
						
							|  |  |  |  | 	pt += 2; | 
					
						
							|  |  |  |  | 	pt_right += 2; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     if (size > 1 && smaller(base[pt[2]].Tag,base[pt[0]].Tag)) { | 
					
						
							|  |  |  |  |       CELL t = pt[2]; | 
					
						
							|  |  |  |  |       pt[2+my_p] = pt[0]; | 
					
						
							|  |  |  |  |       pt[my_p] = t; | 
					
						
							|  |  |  |  |     } else if (my_p) { | 
					
						
							|  |  |  |  |       pt[1] = pt[0]; | 
					
						
							|  |  |  |  |       if (size > 1) | 
					
						
							|  |  |  |  | 	pt[3] = pt[2]; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | copy_back(ClauseDef *dest, CELL *pt, int max) { | 
					
						
							|  |  |  |  |   /* first need to say that we had no need to make a copy */ | 
					
						
							|  |  |  |  |   int i; | 
					
						
							|  |  |  |  |   CELL *tmp = pt; | 
					
						
							|  |  |  |  |   for (i=0; i < max; i++) { | 
					
						
							|  |  |  |  |     if (*tmp != i) { | 
					
						
							|  |  |  |  |       ClauseDef cl; | 
					
						
							|  |  |  |  |       int j = i; | 
					
						
							|  |  |  |  |       CELL *pnt = tmp; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       /* found a chain */ | 
					
						
							|  |  |  |  |       /* make a backup copy */ | 
					
						
							|  |  |  |  |       clcpy(&cl, dest+i); | 
					
						
							|  |  |  |  |       do { | 
					
						
							|  |  |  |  | 	/* follow the chain */ | 
					
						
							|  |  |  |  | 	int k = *pnt; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	*pnt = j; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	/*	printf("i=%d, k = %d, j = %d\n",i,j,k); */ | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | 	if (k == i) { | 
					
						
							|  |  |  |  | 	  clcpy(dest+j, &cl); | 
					
						
							|  |  |  |  | 	  break; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  clcpy(dest+j, dest+k); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	pnt = pt+2*k; | 
					
						
							|  |  |  |  | 	j = k; | 
					
						
							|  |  |  |  |       } while (TRUE); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |     /* we don't need to do swap */ | 
					
						
							|  |  |  |  |     tmp += 2; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* sort a group of clauses by using their tags */ | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  | sort_group(GroupDef *grp, CELL *top, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   int max = (grp->LastClause-grp->FirstClause)+1, i; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   CELL *pt, *base; | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   if (!(base = (CELL *)Yap_AllocCodeSpace(2*max*sizeof(CELL)))) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |     CACHE_REGS | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     LOCAL_Error_Size = 2*max*sizeof(CELL); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   base = top; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   while (top+2*max > (CELL *)LOCAL_TrailTop) { | 
					
						
							| 
									
										
										
										
											2004-12-28 22:20:37 +00:00
										 |  |  |  |     if (!Yap_growtrail(2*max*CellSize, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size = 2*max*CellSize; | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,4); | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |       return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   pt = base; | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   /* initialise vector */ | 
					
						
							|  |  |  |  |   for (i=0; i < max; i++) { | 
					
						
							|  |  |  |  |     *pt = i; | 
					
						
							|  |  |  |  |     pt += 2; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | #define M_EVEN  0
 | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   msort(grp->FirstClause, base, max, M_EVEN); | 
					
						
							|  |  |  |  |   copy_back(grp->FirstClause, base, max); | 
					
						
							|  |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							|  |  |  |  |   Yap_FreeCodeSpace((ADDR)base); | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* add copy to register stack for original reg */ | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | init_regcopy(wamreg regs[MAX_REG_COPIES], wamreg copy) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  |   regs[0] = copy; | 
					
						
							|  |  |  |  |   return 1; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | /* add copy to register stack for original reg */ | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | is_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  |   int i = 0; | 
					
						
							|  |  |  |  |   while (i < regs_count) { | 
					
						
							|  |  |  |  |     if (regs[i] == copy) { | 
					
						
							|  |  |  |  |       return TRUE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     i++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   /* this copy had overflowed, or it just was not there */ | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* add copy to register stack for original reg */ | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | delete_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   int i = 0; | 
					
						
							|  |  |  |  |   while (i < regs_count) { | 
					
						
							|  |  |  |  |     if (regs[i] == copy) { | 
					
						
							|  |  |  |  |       /* we found it */ | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  |       regs[i] = regs[regs_count-1]; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       return regs_count-1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     i++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-05-23 12:31:50 +00:00
										 |  |  |  |   /* this copy had overflowed, or it just was not there */ | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return regs_count; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | /* add copy to register stack for original reg */ | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | add_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, Int source, Int copy) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   int i = 0; | 
					
						
							|  |  |  |  |   while (i < regs_count) { | 
					
						
							|  |  |  |  |     if (regs[i] == source) { | 
					
						
							|  |  |  |  |       /* we found it, add new element as last element */ | 
					
						
							|  |  |  |  |       if (regs_count == MAX_REG_COPIES) { | 
					
						
							|  |  |  |  | 	return regs_count; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       regs[regs_count] = copy; | 
					
						
							|  |  |  |  |       return regs_count+1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     i++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   /* be careful: we may overwrite an existing copy */ | 
					
						
							|  |  |  |  |   return delete_regcopy(regs, regs_count, copy); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* add copy to register stack for original reg */ | 
					
						
							|  |  |  |  | inline static int | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | link_regcopies(wamreg regs[MAX_REG_COPIES], int regs_count, Int c1, Int c2) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  |   int i; | 
					
						
							|  |  |  |  |   for (i=0; i<regs_count; i++) { | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  |     if (regs[i] == c1) { | 
					
						
							|  |  |  |  |       return add_regcopy(regs, regs_count, c1, c2); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (regs[i] == c2) { | 
					
						
							|  |  |  |  |       return add_regcopy(regs, regs_count, c2, c1); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   /* this copy could not be found */ | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  |   regs_count = delete_regcopy(regs, regs_count, c1); | 
					
						
							|  |  |  |  |   return delete_regcopy(regs, regs_count, c2); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | add_info(ClauseDef *clause, UInt regno) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   wamreg myregs[MAX_REG_COPIES]; | 
					
						
							|  |  |  |  |   int nofregs; | 
					
						
							|  |  |  |  |   yamop *cl; | 
					
						
							|  |  |  |  |    | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   nofregs = init_regcopy(myregs, Yap_regnotoreg(regno)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   cl = clause->CurrentCode; | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | #include "findclause.h"
 | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | static void  | 
					
						
							|  |  |  |  | add_head_info(ClauseDef *clause, UInt regno) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   wamreg iarg = Yap_regnotoreg(regno); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   yamop *cl = clause->CurrentCode; | 
					
						
							| 
									
										
										
										
											2008-12-29 00:14:47 +00:00
										 |  |  |  | #include "headclause.h"
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void  | 
					
						
							|  |  |  |  | move_next(ClauseDef *clause, UInt regno) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   yamop *cl = clause->CurrentCode; | 
					
						
							|  |  |  |  |   wamreg wreg = Yap_regnotoreg(regno); | 
					
						
							|  |  |  |  |   op_numbers op = Yap_op_from_opcode(cl->opc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   switch (op) { | 
					
						
							| 
									
										
										
										
											2009-04-08 00:32:36 +01:00
										 |  |  |  |   case _native_me: | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   case _p_db_ref_x: | 
					
						
							|  |  |  |  |   case _p_float_x: | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     if (wreg == cl->u.xl.x) { | 
					
						
							|  |  |  |  |       clause->CurrentCode = NEXTOP(cl,xl); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     }	 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   case _get_list: | 
					
						
							|  |  |  |  |     if (wreg == cl->u.x.x) { | 
					
						
							|  |  |  |  |       clause->CurrentCode = NEXTOP(cl,x); | 
					
						
							|  |  |  |  |     }	 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |   case _glist_valx: | 
					
						
							|  |  |  |  |   case _gl_void_vary: | 
					
						
							|  |  |  |  |   case _gl_void_valy: | 
					
						
							|  |  |  |  |   case _gl_void_varx: | 
					
						
							|  |  |  |  |   case _gl_void_valx: | 
					
						
							|  |  |  |  |   case _glist_valy: | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   case _get_atom: | 
					
						
							|  |  |  |  |     if (wreg == cl->u.xc.x) { | 
					
						
							|  |  |  |  |       clause->CurrentCode = NEXTOP(cl,xc); | 
					
						
							|  |  |  |  |     }	 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   case _get_2atoms: | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   case _get_3atoms: | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   case _get_4atoms: | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   case _get_5atoms: | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   case _get_6atoms: | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2004-07-29 18:15:19 +00:00
										 |  |  |  |     /*
 | 
					
						
							|  |  |  |  |       matching is not guaranteed: | 
					
						
							|  |  |  |  |   case _get_float: | 
					
						
							|  |  |  |  |   case _get_longint: | 
					
						
							|  |  |  |  |   case _get_bigint: | 
					
						
							|  |  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   case _get_struct: | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     if (wreg == cl->u.xfa.x) { | 
					
						
							|  |  |  |  |       clause->CurrentCode = NEXTOP(cl,xfa); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     }	 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   default: | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     clause->CurrentCode = clause->Code; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     return; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   yamop *cl; | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |  |   if (ap->ModuleOfPred == IDB_MODULE) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     cl = clause->Code; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     cl = clause->u.WorkPC; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(cl->opc); | 
					
						
							|  |  |  |  |     switch (op) { | 
					
						
							|  |  |  |  |     case _glist_valx: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,xx); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _gl_void_vary: | 
					
						
							|  |  |  |  |     case _gl_void_valy: | 
					
						
							|  |  |  |  |     case _gl_void_varx: | 
					
						
							|  |  |  |  |     case _gl_void_valx: | 
					
						
							|  |  |  |  |       clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     case _glist_valy: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-05-02 16:39:06 +00:00
										 |  |  |  |       argno = 2; | 
					
						
							| 
									
										
										
										
											2009-03-05 16:12:21 +00:00
										 |  |  |  |       cl = NEXTOP(cl,yx); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_l_x_var: | 
					
						
							|  |  |  |  |     case _unify_l_x_val: | 
					
						
							|  |  |  |  |     case _unify_l_x_loc: | 
					
						
							|  |  |  |  |     case _unify_x_var: | 
					
						
							|  |  |  |  |     case _unify_x_val: | 
					
						
							|  |  |  |  |     case _unify_x_loc: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							|  |  |  |  |     case _unify_l_x_var_write: | 
					
						
							|  |  |  |  |     case _unify_l_x_val_write: | 
					
						
							|  |  |  |  |     case _unify_l_x_loc_write: | 
					
						
							|  |  |  |  |     case _unify_x_var_write: | 
					
						
							|  |  |  |  |     case _unify_x_val_write: | 
					
						
							|  |  |  |  |     case _unify_x_loc_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,ox); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _save_pair_x_write: | 
					
						
							|  |  |  |  |     case _save_pair_x: | 
					
						
							|  |  |  |  |     case _save_appl_x_write: | 
					
						
							|  |  |  |  |     case _save_appl_x: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,ox); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_l_x_var2: | 
					
						
							|  |  |  |  |     case _unify_x_var2: | 
					
						
							|  |  |  |  |       if (argno == 1 || argno == 2) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno -= 2; | 
					
						
							|  |  |  |  |     case _unify_l_x_var2_write: | 
					
						
							|  |  |  |  |     case _unify_x_var2_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oxx); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_y_var: | 
					
						
							|  |  |  |  |     case _unify_y_val: | 
					
						
							|  |  |  |  |     case _unify_y_loc: | 
					
						
							|  |  |  |  |     case _unify_l_y_var: | 
					
						
							|  |  |  |  |     case _unify_l_y_val: | 
					
						
							|  |  |  |  |     case _unify_l_y_loc: | 
					
						
							|  |  |  |  |       /* we're just done with the head of a list, but there
 | 
					
						
							|  |  |  |  | 	 is nothing inside. | 
					
						
							|  |  |  |  |        */ | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							|  |  |  |  |     case _unify_y_var_write: | 
					
						
							|  |  |  |  |     case _unify_y_val_write: | 
					
						
							|  |  |  |  |     case _unify_y_loc_write: | 
					
						
							|  |  |  |  |     case _unify_l_y_var_write: | 
					
						
							|  |  |  |  |     case _unify_l_y_val_write: | 
					
						
							|  |  |  |  |     case _unify_l_y_loc_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oy); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _save_pair_y_write: | 
					
						
							|  |  |  |  |     case _save_pair_y: | 
					
						
							|  |  |  |  |     case _save_appl_y_write: | 
					
						
							|  |  |  |  |     case _save_appl_y: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oy); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_l_void: | 
					
						
							|  |  |  |  |     case _unify_void: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							|  |  |  |  |     case _unify_l_void_write: | 
					
						
							|  |  |  |  |     case _unify_void_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,o); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_list: | 
					
						
							|  |  |  |  |     case _unify_l_list: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = AbsPair(NULL); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	clause->u.WorkPC = NEXTOP(cl,o); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno += 1; /* 2-1: have two extra arguments to skip */ | 
					
						
							|  |  |  |  |     case _unify_list_write: | 
					
						
							|  |  |  |  |     case _unify_l_list_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,o); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_n_voids: | 
					
						
							|  |  |  |  |     case _unify_l_n_voids: | 
					
						
							|  |  |  |  |       if (argno <= cl->u.os.s) { | 
					
						
							|  |  |  |  | 	clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno -= cl->u.os.s; | 
					
						
							|  |  |  |  |     case _unify_n_voids_write: | 
					
						
							|  |  |  |  |     case _unify_l_n_voids_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,os); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _unify_atom: | 
					
						
							|  |  |  |  |     case _unify_l_atom: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = cl->u.oc.c; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							|  |  |  |  |     case _unify_atom_write: | 
					
						
							|  |  |  |  |     case _unify_l_atom_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oc); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  |     case _unify_float_write: | 
					
						
							|  |  |  |  |     case _unify_l_float_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,od); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							| 
									
										
										
										
											2003-10-08 00:47:04 +00:00
										 |  |  |  |     case _unify_float: | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_l_float: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = AbsAppl((CELL *)FunctorDouble); | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  | 	clause->u.t_ptr = AbsAppl(cl->u.od.d); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  |       cl = NEXTOP(cl,od); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       argno--; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_longint: | 
					
						
							|  |  |  |  |     case _unify_l_longint: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = AbsAppl((CELL *)FunctorLongInt); | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  | 	clause->u.t_ptr = AbsAppl(cl->u.oi.i); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno--; | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  |       cl = NEXTOP(cl,oi); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_bigint: | 
					
						
							|  |  |  |  |     case _unify_l_bigint: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							|  |  |  |  | 	clause->Tag = AbsAppl((CELL *)FunctorBigInt); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	clause->u.t_ptr = cl->u.oc.c; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cl = NEXTOP(cl,oc); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       argno--; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_n_atoms: | 
					
						
							|  |  |  |  |       if (argno <= cl->u.osc.s) { | 
					
						
							|  |  |  |  | 	clause->Tag = cl->u.osc.c; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno -= cl->u.osc.s; | 
					
						
							|  |  |  |  |     case _unify_n_atoms_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,osc); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _unify_struct: | 
					
						
							|  |  |  |  |     case _unify_l_struc: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	clause->Tag = AbsAppl((CELL *)cl->u.ofa.f); | 
					
						
							|  |  |  |  | 	clause->u.WorkPC = NEXTOP(cl,ofa); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-05-02 16:39:06 +00:00
										 |  |  |  |       /* must skip next n arguments */ | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       argno += cl->u.ofa.a-1; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_l_struc_write: | 
					
						
							|  |  |  |  |     case _unify_struct_write: | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       cl = NEXTOP(cl,ofa); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _pop: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,e); | 
					
						
							|  |  |  |  |       break;             | 
					
						
							|  |  |  |  |     case _pop_n: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,s); | 
					
						
							| 
									
										
										
										
											2006-03-24 17:13:41 +00:00
										 |  |  |  |       break;    | 
					
						
							|  |  |  |  | #ifdef BEAM
 | 
					
						
							|  |  |  |  |     case _run_eam: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,os); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  | #endif   
 | 
					
						
							| 
									
										
										
										
											2007-11-06 17:02:13 +00:00
										 |  |  |  |     case _get_dbterm: | 
					
						
							| 
									
										
										
										
											2007-11-08 15:52:15 +00:00
										 |  |  |  |       cl = NEXTOP(cl,xc); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _unify_dbterm: | 
					
						
							|  |  |  |  |     case _unify_l_dbterm: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oc); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _unify_idb_term: | 
					
						
							|  |  |  |  |     case _copy_idb_term: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	Term t = clause->u.c_sreg[argno]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (IsVarTerm(t)) { | 
					
						
							|  |  |  |  | 	  clause->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	} else if (IsApplTerm(t)) { | 
					
						
							|  |  |  |  | 	  CELL *pt = RepAppl(t); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	  clause->Tag = AbsAppl((CELL *)pt[0]); | 
					
						
							|  |  |  |  | 	  if (IsExtensionFunctor(FunctorOfTerm(t))) { | 
					
						
							|  |  |  |  | 	    clause->u.t_ptr = t; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    clause->u.c_sreg = pt; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	  CELL *pt = RepPair(t); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	  clause->Tag = AbsPair(NULL); | 
					
						
							|  |  |  |  | 	  clause->u.c_sreg = pt-1; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  clause->Tag = t; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     default: | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | skip_to_arg(ClauseDef *clause, PredEntry *ap, UInt argno, int at_point) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   yamop *cl; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   int done = FALSE; | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |  |   if (ap->ModuleOfPred == IDB_MODULE) { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     cl = clause->CurrentCode; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!at_point) { | 
					
						
							|  |  |  |  |     clause->CurrentCode = clause->Code; | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (!done) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(cl->opc); | 
					
						
							|  |  |  |  |     switch (op) { | 
					
						
							| 
									
										
										
										
											2006-03-24 17:13:41 +00:00
										 |  |  |  | #ifdef BEAM
 | 
					
						
							|  |  |  |  |     case _run_eam: | 
					
						
							|  |  |  |  | 	clause->CurrentCode = clause->Code; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_void: | 
					
						
							|  |  |  |  |       if (argno == 1) { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	clause->CurrentCode = clause->Code; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	argno--; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     case _unify_void_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,o); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_list: | 
					
						
							|  |  |  |  |     case _unify_l_list: | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     case _unify_atom: | 
					
						
							|  |  |  |  |     case _unify_l_atom: | 
					
						
							| 
									
										
										
										
											2004-07-29 18:15:19 +00:00
										 |  |  |  |       /*
 | 
					
						
							|  |  |  |  | 	unification is not guaranteed | 
					
						
							|  |  |  |  | 	case _unify_longint: | 
					
						
							|  |  |  |  | 	case _unify_l_longint: | 
					
						
							|  |  |  |  | 	case _unify_bigint: | 
					
						
							|  |  |  |  | 	case _unify_l_bigint: | 
					
						
							|  |  |  |  | 	case _unify_l_float: | 
					
						
							|  |  |  |  |       */ | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     case _unify_struct: | 
					
						
							|  |  |  |  |     case _unify_l_struc: | 
					
						
							|  |  |  |  |       if (cl == clause->u.WorkPC) { | 
					
						
							|  |  |  |  | 	clause->CurrentCode = cl; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	clause->CurrentCode = clause->Code; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_list_write: | 
					
						
							|  |  |  |  |     case _unify_l_list_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,o); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _unify_n_voids: | 
					
						
							|  |  |  |  |     case _unify_l_n_voids: | 
					
						
							|  |  |  |  |       if (argno <= cl->u.os.s) { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	clause->CurrentCode = clause->Code; | 
					
						
							|  |  |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	argno -= cl->u.os.s; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     case _unify_n_voids_write: | 
					
						
							|  |  |  |  |     case _unify_l_n_voids_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,os); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _unify_atom_write: | 
					
						
							|  |  |  |  |     case _unify_l_atom_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,oc); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  |  |     case _unify_float_write: | 
					
						
							|  |  |  |  |     case _unify_l_float_write: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,od); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     case _unify_l_struc_write: | 
					
						
							|  |  |  |  |     case _unify_struct_write: | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       cl = NEXTOP(cl,ofa); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       break;       | 
					
						
							|  |  |  |  |     case _pop: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,e); | 
					
						
							|  |  |  |  |       break;             | 
					
						
							|  |  |  |  |     case _pop_n: | 
					
						
							|  |  |  |  |       cl = NEXTOP(cl,s); | 
					
						
							|  |  |  |  |       break;       | 
					
						
							|  |  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       clause->CurrentCode = clause->Code; | 
					
						
							|  |  |  |  |       return;       | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  | groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   UInt groups = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while(min <= max) { | 
					
						
							|  |  |  |  |     grp->FirstClause = min; | 
					
						
							|  |  |  |  |     grp->AtomClauses = 0; | 
					
						
							|  |  |  |  |     grp->PairClauses = 0; | 
					
						
							|  |  |  |  |     grp->StructClauses = 0; | 
					
						
							|  |  |  |  |     grp->TestClauses = 0; | 
					
						
							|  |  |  |  |     if (min->Tag == (_var+1)*sizeof(CELL)) { | 
					
						
							|  |  |  |  |       min++; | 
					
						
							|  |  |  |  |       continue; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* only do this for the first clauses in a group */ | 
					
						
							|  |  |  |  |     if (IsVarTerm(min->Tag)) { | 
					
						
							|  |  |  |  |       ClauseDef *clp = min+1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       grp->VarClauses = 1; | 
					
						
							|  |  |  |  |       do { | 
					
						
							|  |  |  |  | 	if (clp > max || | 
					
						
							|  |  |  |  | 	    !IsVarTerm(clp->Tag)) { | 
					
						
							|  |  |  |  | 	  grp->LastClause = (min = clp)-1; | 
					
						
							|  |  |  |  | 	  break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (clp->Tag != (_var+1)*sizeof(CELL)) | 
					
						
							|  |  |  |  | 	  grp->VarClauses++; | 
					
						
							| 
									
										
										
										
											2004-12-21 17:17:15 +00:00
										 |  |  |  | 	clp++; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } while (TRUE); | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       grp->VarClauses = 0; | 
					
						
							|  |  |  |  |       do { | 
					
						
							|  |  |  |  |       restart_loop: | 
					
						
							|  |  |  |  | 	if (IsAtomTerm(min->Tag) || IsIntTerm(min->Tag)) { | 
					
						
							|  |  |  |  | 	  grp->AtomClauses++; | 
					
						
							|  |  |  |  | 	} else if (IsPairTerm(min->Tag)) { | 
					
						
							|  |  |  |  | 	  grp->PairClauses++; | 
					
						
							|  |  |  |  | 	} else if (IsApplTerm(min->Tag)) { | 
					
						
							|  |  |  |  | 	  grp->StructClauses++; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  grp->TestClauses++; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	min++; | 
					
						
							|  |  |  |  |       } while (min <= max && | 
					
						
							|  |  |  |  | 	       (!IsVarTerm(min->Tag))); | 
					
						
							|  |  |  |  |       if (min <= max && min->Tag == (_var+1)*sizeof(CELL)) { | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | 	min++; | 
					
						
							|  |  |  |  | 	if (min < max) | 
					
						
							|  |  |  |  | 	  goto restart_loop; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       grp->LastClause = min-1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     groups++; | 
					
						
							|  |  |  |  |     grp++; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     while (grp+16 > (GroupDef *)LOCAL_TrailTop) { | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |       UInt sz = (groups+16)*sizeof(GroupDef); | 
					
						
							|  |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size = sz; | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |       /* grow stack */ | 
					
						
							|  |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,4); | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  |       if (!Yap_growtrail(sz, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  | 	LOCAL_Error_Size = sz; | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  | 	save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  | 	siglongjmp(cint->CompilerBotch,4); | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  | 	return 0; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   return groups; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  | new_label(struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   UInt lbl = cint->i_labelno; | 
					
						
							|  |  |  |  |   cint->i_labelno += 2; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return lbl; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  | static Int has_cut(yamop *pc, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     LogUpdClause *lcl = ClauseCodeToLogUpdClause(pc); | 
					
						
							| 
									
										
										
										
											2011-07-14 09:40:15 +01:00
										 |  |  |  |     return ( (lcl->ClFlags & HasCutMask) != 0); | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |   }  else if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     /* must be a fact */ | 
					
						
							|  |  |  |  |     return FALSE; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     StaticClause *scl; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     scl = ClauseCodeToStaticClause(pc); | 
					
						
							| 
									
										
										
										
											2011-07-14 09:40:15 +01:00
										 |  |  |  |     return ( (scl->ClFlags & HasCutMask) != 0); | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_trust(ClauseDef *cl, struct intermediates *cint, UInt nxtlbl, int clauses) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   yamop *clcode = cl->Code; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   if (ap->PredFlags & TabledPredFlag) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     clcode = NEXTOP(clcode,Otapl); | 
					
						
							| 
									
										
										
										
											2008-02-14 14:35:13 +00:00
										 |  |  |  |   if (!(ap->PredFlags & LogUpdatePredFlag)) { | 
					
						
							|  |  |  |  |     /* this should not be generated for logical update predicates!! */ | 
					
						
							|  |  |  |  |     if (ap->PredFlags & ProfiledPredFlag) { | 
					
						
							|  |  |  |  |       Yap_emit(retry_profiled_op, Unsigned(ap), Zero, cint); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ap->PredFlags & CountPredFlag) { | 
					
						
							|  |  |  |  |       Yap_emit(count_retry_op, Unsigned(ap), Zero, cint); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   if (clauses == 0) { | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |     Yap_emit(trust_op, (CELL)clcode, has_cut(cl->Code, ap) , cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |     Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap) , cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(jumpi_op, nxtlbl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_retry(ClauseDef *cl, struct intermediates *cint, int clauses) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   yamop *clcode = cl->Code; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   if (ap->PredFlags & TabledPredFlag) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     clcode = NEXTOP(clcode,Otapl); | 
					
						
							| 
									
										
										
										
											2008-02-14 14:35:13 +00:00
										 |  |  |  |   if (!(ap->PredFlags & LogUpdatePredFlag)) { | 
					
						
							|  |  |  |  |     /* this should not be generated for logical update predicates!! */ | 
					
						
							|  |  |  |  |     if (ap->PredFlags & ProfiledPredFlag) { | 
					
						
							|  |  |  |  |       Yap_emit(retry_profiled_op, Unsigned(ap), Zero, cint); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ap->PredFlags & CountPredFlag) { | 
					
						
							|  |  |  |  |       Yap_emit(count_retry_op, Unsigned(ap), Zero, cint); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |   Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap), cint); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | static compiler_vm_op | 
					
						
							| 
									
										
										
										
											2003-12-18 16:38:40 +00:00
										 |  |  |  | emit_optry(int var_group, int first, int clauses, int clleft, PredEntry *ap) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   /* var group */ | 
					
						
							|  |  |  |  |   if (var_group || clauses == 0) { | 
					
						
							|  |  |  |  |     if (first) { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       return try_op; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } else if (clleft+clauses) { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       return retry_op; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       return trust_op; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else if (clleft == 0) { | 
					
						
							| 
									
										
										
										
											2003-12-18 17:23:22 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							| 
									
										
										
										
											2003-12-18 16:38:40 +00:00
										 |  |  |  |     if (ap->PredFlags & TabledPredFlag && !first) { | 
					
						
							|  |  |  |  |       /* we never actually get to remove the last choice-point in this case */ | 
					
						
							|  |  |  |  |       return retry_op; | 
					
						
							| 
									
										
										
										
											2003-12-18 17:23:22 +00:00
										 |  |  |  |     } else | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #endif /* TABLING */
 | 
					
						
							| 
									
										
										
										
											2003-12-18 17:23:22 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-12-18 16:38:40 +00:00
										 |  |  |  |       /* last group */ | 
					
						
							|  |  |  |  |       return try_op; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     /* nonvar group */ | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     return try_in_op; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_try(ClauseDef *cl, struct intermediates *cint, int var_group, int first, int clauses, int clleft, UInt nxtlbl) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   yamop *clcode; | 
					
						
							| 
									
										
										
										
											2005-07-19 16:54:20 +00:00
										 |  |  |  |   compiler_vm_op comp_op; | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     clcode = cl->Code; | 
					
						
							|  |  |  |  |   } else if (ap->PredFlags & TabledPredFlag) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     clcode = NEXTOP(cl->Code,Otapl); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     clcode = cl->CurrentCode; | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-19 16:54:20 +00:00
										 |  |  |  |   comp_op = emit_optry(var_group, first, clauses, clleft, cint->CurrentPred); | 
					
						
							| 
									
										
										
										
											2011-07-05 07:28:28 +01:00
										 |  |  |  |   Yap_emit(comp_op, (CELL)clcode, ((clauses+clleft) << 1) | has_cut(cl->Code, ap), cint); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static TypeSwitch * | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_type_switch(compiler_vm_op op, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |  return (TypeSwitch *)Yap_emit_extra_size(op, 0, sizeof(TypeSwitch), cint); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static yamop * | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | emit_switch_space(UInt n, UInt item_size, struct intermediates *cint, CELL func_mask) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-14 18:51:11 +01:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     UInt sz = sizeof(LogUpdIndex)+n*item_size; | 
					
						
							|  |  |  |  |     LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sz); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     if (cl == NULL) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size = sz; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       /* grow stack */ | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     Yap_LUIndexSpace_SW += sz; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     cl->ClFlags = SwitchTableMask|LogUpdMask|func_mask; | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     cl->ClSize = sz; | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     cl->ClPred = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     /* insert into code chain */ | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_inform_profiler_of_clause(cl, (CODEADDR)cl+sz, ap, GPROF_NEW_LU_SWITCH); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return cl->ClCode; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     UInt sz = sizeof(StaticIndex)+n*item_size; | 
					
						
							|  |  |  |  |     StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sz); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     if (cl == NULL) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size = sz; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       /* grow stack */ | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     Yap_IndexSpace_SW += sz; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     cl->ClFlags = SwitchTableMask; | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     cl->ClSize = sz; | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     cl->ClPred = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_inform_profiler_of_clause(cl, (CODEADDR)cl+sz, ap, GPROF_NEW_STATIC_SWITCH); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return cl->ClCode; | 
					
						
							|  |  |  |  |     /* insert into code chain */ | 
					
						
							|  |  |  |  |   }   | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static AtomSwiEntry * | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  | emit_cswitch(COUNT n, yamop *fail_l, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   compiler_vm_op op; | 
					
						
							|  |  |  |  |   AtomSwiEntry *target; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |     COUNT cases = MIN_HASH_ENTRIES, i; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     n += 1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n) cases *= 2; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     n = cases; | 
					
						
							|  |  |  |  |     op = switch_c_op; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (AtomSwiEntry *)emit_switch_space(n, sizeof(AtomSwiEntry), cint, 0); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     for (i=0; i<n; i++) { | 
					
						
							|  |  |  |  |       target[i].Tag = Zero; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(op, Unsigned(n), (CELL)target, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     UInt i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     op = if_c_op; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (AtomSwiEntry *)emit_switch_space(n+1, sizeof(AtomSwiEntry), cint, 0); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     for (i=0; i<n; i++) { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     target[n].Tag = Zero; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     target[n].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(op, Unsigned(n), (CELL)target, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   return target; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static AtomSwiEntry * | 
					
						
							|  |  |  |  | lookup_c_hash(Term t, yamop *tab, COUNT entries) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   AtomSwiEntry *cebase = (AtomSwiEntry *)tab; | 
					
						
							|  |  |  |  |   int hash, d; | 
					
						
							|  |  |  |  |   AtomSwiEntry *centry; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   hash = (t >> HASH_SHIFT) & (entries-1); | 
					
						
							|  |  |  |  |   centry = cebase + hash; | 
					
						
							|  |  |  |  |   d = (entries-1) & (t|1); | 
					
						
							|  |  |  |  |   while (centry->Tag != t) { | 
					
						
							|  |  |  |  |     if (centry->Tag == 0L) | 
					
						
							|  |  |  |  |       return centry; | 
					
						
							|  |  |  |  |     hash = (hash + d) & (entries-1); | 
					
						
							|  |  |  |  |     centry = cebase + hash; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return centry; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static AtomSwiEntry * | 
					
						
							|  |  |  |  | fetch_centry(AtomSwiEntry *cebase, Term wt, int i, int n) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     int cases = MIN_HASH_ENTRIES; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     n += 1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n) cases *= 2; | 
					
						
							|  |  |  |  |     return lookup_c_hash(wt, (yamop *)cebase, cases); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     return cebase + i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static FuncSwiEntry * | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  | emit_fswitch(COUNT n, yamop *fail_l, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   compiler_vm_op op; | 
					
						
							|  |  |  |  |   FuncSwiEntry *target; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							|  |  |  |  |     int cases = MIN_HASH_ENTRIES, i; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     n += 1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n) cases *= 2; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     n = cases; | 
					
						
							|  |  |  |  |     op = switch_f_op; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (FuncSwiEntry *)emit_switch_space(n, sizeof(FuncSwiEntry), cint, FuncSwitchMask); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     for (i=0; i<n; i++) { | 
					
						
							|  |  |  |  |       target[i].Tag = NULL; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(op, Unsigned(n), (CELL)target, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     UInt i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     op = if_f_op; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (FuncSwiEntry *)emit_switch_space(n+1, sizeof(FuncSwiEntry), cint, FuncSwitchMask); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     for (i=0; i<n; i++) { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     target[n].Tag = NULL; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     target[n].u.labp = fail_l; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(op, Unsigned(n), (CELL)target, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   return target; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static FuncSwiEntry * | 
					
						
							|  |  |  |  | lookup_f_hash(Functor f, yamop *tab, COUNT entries) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   FuncSwiEntry *febase = (FuncSwiEntry *)tab; | 
					
						
							|  |  |  |  |   int hash, d; | 
					
						
							|  |  |  |  |   FuncSwiEntry *fentry; | 
					
						
							|  |  |  |  |   Term wt = (Term)f; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   hash = (wt >> HASH_SHIFT) & (entries-1); | 
					
						
							|  |  |  |  |   fentry = febase + hash; | 
					
						
							|  |  |  |  |   d = (entries-1) & (wt|1); | 
					
						
							|  |  |  |  |   while (fentry->Tag != f) { | 
					
						
							|  |  |  |  |     if (fentry->Tag == NULL) | 
					
						
							|  |  |  |  |       return fentry; | 
					
						
							|  |  |  |  |     hash = (hash + d) & (entries-1); | 
					
						
							|  |  |  |  |     fentry = febase + hash; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return fentry; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static FuncSwiEntry * | 
					
						
							|  |  |  |  | fetch_fentry(FuncSwiEntry *febase, Functor ft, int i, int n) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     int cases = MIN_HASH_ENTRIES; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     n += 1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n) cases *= 2; | 
					
						
							|  |  |  |  |     return lookup_f_hash(ft, (yamop *)febase, cases); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     return febase + i; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* we assume there is at least one clause, that is, c0 < cf */ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_var_clauses(ClauseDef *c0, ClauseDef *cf, int var_group, struct intermediates *cint, int first, int clleft, UInt nxtlbl, UInt argno0) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   UInt labl; | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |   UInt labl_dyn0 = 0, labl_dynf = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   Yap_emit(label_op, labl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /*
 | 
					
						
							|  |  |  |  |     add expand_node if var_group == TRUE (jump on var) || | 
					
						
							|  |  |  |  | 		       var_group == FALSE (leaf node) | 
					
						
							|  |  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |   if (first && | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       cint->CurrentPred->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |     UInt ncls; | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     labl_dyn0 = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |     if (clleft) | 
					
						
							|  |  |  |  |       labl_dynf = labl_dyn0; | 
					
						
							|  |  |  |  |     else | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |       labl_dynf = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |     if (clleft == 0) /* trust*/ | 
					
						
							|  |  |  |  |       ncls = (cf-c0)+1; | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |       ncls = 0; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     Yap_emit_4ops(enter_lu_op, labl_dyn0, labl_dynf, ncls, Zero, cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op, labl_dyn0, Zero, cint);  | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (c0 == cf) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     emit_try(c0, cint, var_group, first, 0, clleft, nxtlbl); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     if (c0 < cf) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       emit_try(c0, cint, var_group, first, cf-c0, clleft, nxtlbl); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     c0++; | 
					
						
							|  |  |  |  |     while (c0 < cf) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       emit_retry(c0, cint, clleft+(cf-c0)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       c0++; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (c0 == cf) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       emit_trust(c0, cint, nxtlbl, clleft); | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |       if (!clleft &&  | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	  cint->CurrentPred->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	Yap_emit(label_op, labl_dynf, Zero, cint);  | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return labl; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_var_group(GroupDef *grp, struct intermediates *cint, int var_group, int first, int clleft, UInt nxtlbl, UInt argno0) { | 
					
						
							|  |  |  |  |   return do_var_clauses(grp->FirstClause, grp->LastClause, var_group, cint, first, clleft, nxtlbl, argno0); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | /* count the number of different constants */ | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | count_consts(GroupDef *grp) | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   Term current = MkAtomTerm(AtomFoundVar); | 
					
						
							|  |  |  |  |   UInt i = 0; | 
					
						
							|  |  |  |  |   ClauseDef *cl = grp->FirstClause; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |   while (IsAtomTerm(cl->Tag) || IsIntTerm(cl->Tag)) { | 
					
						
							|  |  |  |  |     if (current != cl->Tag) { | 
					
						
							|  |  |  |  |       i++; | 
					
						
							|  |  |  |  |       current = cl->Tag; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (cl == grp->LastClause) { | 
					
						
							|  |  |  |  |       return i; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | count_blobs(GroupDef *grp) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-20 12:01:18 -06:00
										 |  |  |  |   UInt i = 1; | 
					
						
							|  |  |  |  |   ClauseDef *cl = grp->FirstClause+1; | 
					
						
							|  |  |  |  |   Term current = grp->FirstClause->Tag; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-01-20 12:01:18 -06:00
										 |  |  |  |   while (cl <= grp->LastClause) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     if (current != cl->Tag) { | 
					
						
							|  |  |  |  |       i++; | 
					
						
							|  |  |  |  |       current = cl->Tag; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* count the number of different constants */ | 
					
						
							|  |  |  |  | static UInt | 
					
						
							|  |  |  |  | count_funcs(GroupDef *grp) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   Term current = MkAtomTerm(AtomFoundVar); | 
					
						
							|  |  |  |  |   UInt i = 0; | 
					
						
							|  |  |  |  |   ClauseDef *cl = grp->FirstClause; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |   while (IsApplTerm(cl->Tag)) { | 
					
						
							|  |  |  |  |     if (current != cl->Tag) { | 
					
						
							|  |  |  |  |       i++; | 
					
						
							|  |  |  |  |       current = cl->Tag; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     if (cl == grp->LastClause) { | 
					
						
							|  |  |  |  |       return i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_single_switch_case(ClauseDef *min, struct intermediates *cint, int first, int clleft, UInt nxtlbl) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 20:30:14 +00:00
										 |  |  |  |   if (cint->CurrentPred->PredFlags & TabledPredFlag) { | 
					
						
							| 
									
										
										
										
											2005-05-30 05:26:50 +00:00
										 |  |  |  |     /* with tabling we don't clean trust at the very end of computation.
 | 
					
						
							| 
									
										
										
										
											2003-12-18 16:38:40 +00:00
										 |  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2009-02-10 22:35:54 +00:00
										 |  |  |  |     if (clleft || !first) { | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |       /*
 | 
					
						
							|  |  |  |  | 	if we still have clauses left, means we already created a CP, | 
					
						
							|  |  |  |  | 	so I should avoid creating again  | 
					
						
							|  |  |  |  |       */ | 
					
						
							| 
									
										
										
										
											2009-02-10 22:35:54 +00:00
										 |  |  |  |       return (UInt)NEXTOP(min->Code,Otapl); | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       return (UInt)min->Code; | 
					
						
							|  |  |  |  |     }     | 
					
						
							| 
									
										
										
										
											2003-12-18 16:38:40 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |   if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     return (UInt)(min->Code); | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     return (UInt)(min->CurrentCode); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  | suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-11 22:08:02 +01:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   UInt tcls = ap->cs.p_code.NOfClauses; | 
					
						
							|  |  |  |  |   UInt cls = (max-min)+1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |   if (cint->expand_block && | 
					
						
							| 
									
										
										
										
											2005-04-27 20:09:26 +00:00
										 |  |  |  |       cint->expand_block != (yamop *)(&(ap->cs.p_code.ExpandCode)) && | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       cint->expand_block->u.sssllp.s2 < 2*(max-min)) { | 
					
						
							|  |  |  |  |     cint->expand_block->u.sssllp.s3++; | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     return (UInt)(cint->expand_block); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-29 03:44:04 +00:00
										 |  |  |  |   if (cls < tcls/8) { | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     yamop *ncode; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     yamop **st; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     UInt tels; | 
					
						
							|  |  |  |  |     UInt sz; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       /* give it some slack */ | 
					
						
							|  |  |  |  |       tels = cls + 4; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       tels = cls; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-30 21:52:11 -05:00
										 |  |  |  |     sz = (UInt)NEXTOP((yamop *)NULL,sssllp)+tels*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     if ((ncode = (yamop *)Yap_AllocCodeSpace(sz)) == NULL) { | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch, 2); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | #if DEBUG
 | 
					
						
							|  |  |  |  |     Yap_ExpandClauses++; | 
					
						
							|  |  |  |  |     Yap_expand_clauses_sz += sz; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       Yap_LUIndexSpace_EXT += sz; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       Yap_IndexSpace_EXT += sz; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode+sz, ap, GPROF_NEW_EXPAND_BLOCK);  | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     /* create an expand_block */ | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     ncode->opc = Yap_opcode(_expand_clauses); | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     ncode->u.sssllp.p = ap; | 
					
						
							|  |  |  |  |     ncode->u.sssllp.s1 = tels; | 
					
						
							|  |  |  |  |     ncode->u.sssllp.s2 = cls; | 
					
						
							|  |  |  |  |     ncode->u.sssllp.s3 = 1; | 
					
						
							|  |  |  |  |     st = (yamop **)NEXTOP(ncode,sssllp); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     while (min <= max) { | 
					
						
							|  |  |  |  |       *st++ = min->Code; | 
					
						
							|  |  |  |  |       min++; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     while (cls < tels) { | 
					
						
							|  |  |  |  |       *st++ = NULL; | 
					
						
							|  |  |  |  |       cls++; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     LOCK(ExpandClausesListLock); | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     ncode->u.sssllp.snext = ExpandClausesFirst; | 
					
						
							|  |  |  |  |     ncode->u.sssllp.sprev = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     if (ExpandClausesFirst) | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       ExpandClausesFirst->u.sssllp.sprev = ncode; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     ExpandClausesFirst = ncode; | 
					
						
							|  |  |  |  |     if (ExpandClausesLast == NULL) | 
					
						
							|  |  |  |  |       ExpandClausesLast = ncode; | 
					
						
							|  |  |  |  |     UNLOCK(ExpandClausesListLock); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     return (UInt)ncode; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return (UInt)&(ap->cs.p_code.ExpandCode); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | recover_ecls_block(yamop *ipc) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   ipc->u.sssllp.s3--; | 
					
						
							|  |  |  |  |   if (!ipc->u.sssllp.s3) { | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     LOCK(ExpandClausesListLock); | 
					
						
							|  |  |  |  |     if (ExpandClausesFirst == ipc) | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       ExpandClausesFirst = ipc->u.sssllp.snext; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     if (ExpandClausesLast == ipc) { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       ExpandClausesLast = ipc->u.sssllp.sprev; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     if (ipc->u.sssllp.sprev) { | 
					
						
							|  |  |  |  |       ipc->u.sssllp.sprev->u.sssllp.snext = ipc->u.sssllp.snext; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     if (ipc->u.sssllp.snext) { | 
					
						
							|  |  |  |  |       ipc->u.sssllp.snext->u.sssllp.sprev = ipc->u.sssllp.sprev; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     UNLOCK(ExpandClausesListLock); | 
					
						
							| 
									
										
										
										
											2004-09-03 03:11:09 +00:00
										 |  |  |  | #if DEBUG
 | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     Yap_ExpandClauses--; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+ipc->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-09-03 03:11:09 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     /* no dangling pointers for gprof */ | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_InformOfRemoval(ipc); | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     if (ipc->u.sssllp.p->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+ipc->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     } else | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       Yap_IndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+ipc->u.sssllp.s1*sizeof(yamop *); | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     Yap_FreeCodeSpace((char *)ipc); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_var_entries(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int clleft, UInt nxtlbl){ | 
					
						
							|  |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  |   if (!IsVarTerm(t) || t != 0L) { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     return suspend_indexing(grp->FirstClause, grp->LastClause, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   return do_var_group(grp, cint, FALSE, first, clleft, nxtlbl, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_consts(GroupDef *grp, Term t, struct intermediates *cint, int compound_term, CELL *sreg, UInt arity, int last_arg, UInt argno, int first, UInt nxtlbl, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT n; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   ClauseDef *min = grp->FirstClause; | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT i; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   UInt lbl; | 
					
						
							|  |  |  |  |   /* generate a switch */ | 
					
						
							|  |  |  |  |   AtomSwiEntry *cs; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!IsAtomTerm(min->Tag) && !IsIntTerm(min->Tag)) { | 
					
						
							|  |  |  |  |     /* no clauses, just skip */ | 
					
						
							|  |  |  |  |     return nxtlbl; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   n = count_consts(grp); | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   lbl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   Yap_emit(label_op, lbl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |   cs = emit_cswitch(n, FAILCODE, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   for (i = 0; i < n; i++) { | 
					
						
							|  |  |  |  |     AtomSwiEntry *ics; | 
					
						
							|  |  |  |  |     ClauseDef *max = min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ics = fetch_centry(cs, min->Tag, i, n); | 
					
						
							|  |  |  |  |     ics->Tag = min->Tag; | 
					
						
							| 
									
										
										
										
											2010-04-08 00:52:59 +01:00
										 |  |  |  |     while (max != grp->LastClause && (max+1)->Tag == min->Tag) | 
					
						
							|  |  |  |  |       max++; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (min != max) { | 
					
						
							|  |  |  |  |       if (sreg != NULL) { | 
					
						
							| 
									
										
										
										
											2006-11-08 01:53:08 +00:00
										 |  |  |  | 	if (ap->PredFlags & LogUpdatePredFlag && max > min) { | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  | 	  ics->u.Label = suspend_indexing(min, max, ap, cint); | 
					
						
							| 
									
										
										
										
											2006-11-08 01:53:08 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	    ics->u.Label = do_compound_index(min, max, sreg, cint, compound_term, arity, argno, nxtlbl, first, last_arg, clleft, top, TRUE); | 
					
						
							| 
									
										
										
										
											2006-11-08 01:53:08 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  | 	ics->u.Label = suspend_indexing(min, max, cint->CurrentPred, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	ics->u.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       ics->u.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     grp->FirstClause = min = max+1; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return lbl; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_blobs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, UInt nxtlbl, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT n; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   ClauseDef *min = grp->FirstClause; | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT i; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* generate a switch */ | 
					
						
							|  |  |  |  |   AtomSwiEntry *cs; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   n = count_blobs(grp); | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |   cs = emit_cswitch(n, (yamop *)nxtlbl, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   for (i = 0; i < n; i++) { | 
					
						
							|  |  |  |  |     AtomSwiEntry *ics; | 
					
						
							|  |  |  |  |     ClauseDef *max = min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ics = fetch_centry(cs, min->Tag, i, n); | 
					
						
							|  |  |  |  |     ics->Tag = min->Tag; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     while (max != grp->LastClause && | 
					
						
							|  |  |  |  | 	   (max+1)->Tag == min->Tag) max++; | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  |     if (min != max && | 
					
						
							|  |  |  |  | 	(ap->PredFlags & LogUpdatePredFlag)) { | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  |       ics->u.Label = suspend_indexing(min, max, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       ics->u.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     grp->FirstClause = min = max+1; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_funcs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT n = count_funcs(grp); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   ClauseDef *min = grp->FirstClause; | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  |   COUNT i; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   FuncSwiEntry *fs; | 
					
						
							|  |  |  |  |   UInt lbl; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   if (min > grp->LastClause || n == 0) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* no clauses, just skip */ | 
					
						
							|  |  |  |  |     return nxtlbl; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   lbl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   Yap_emit(label_op, lbl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   /* generate a switch */ | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |   fs = emit_fswitch(n, FAILCODE, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   for (i = 0; i < n ; i++) { | 
					
						
							|  |  |  |  |     Functor f = (Functor)RepAppl(min->Tag); | 
					
						
							|  |  |  |  |     FuncSwiEntry *ifs; | 
					
						
							|  |  |  |  |     ClauseDef *max = min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ifs = fetch_fentry(fs, f, i, n); | 
					
						
							|  |  |  |  |     ifs->Tag = f; | 
					
						
							| 
									
										
										
										
											2010-04-08 00:52:59 +01:00
										 |  |  |  |     while (max != grp->LastClause && (max+1)->Tag == min->Tag) | 
					
						
							|  |  |  |  |       max++;  | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* delay non-trivial indexing  
 | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |        if (min != max && | 
					
						
							|  |  |  |  |        !IsExtensionFunctor(f)) { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |        ifs->u.Label = suspend_indexing(min, max, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |        } else  | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2008-01-30 10:35:43 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     if (IsExtensionFunctor(f)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (f == FunctorDBRef)  | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	ifs->u.Label = do_dbref_index(min, max, t, cint, argno, nxtlbl, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       else if (f == FunctorLongInt || f == FunctorBigInt)  | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | 	ifs->u.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, clleft, top, FALSE); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | 	ifs->u.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, clleft, top, TRUE); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       CELL *sreg; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       if (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == f) { | 
					
						
							|  |  |  |  | 	sreg = RepAppl(t)+1; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	sreg = NULL; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       ifs->u.Label = do_compound_index(min, max, sreg, cint, 0, ArityOfFunctor(f), argno, nxtlbl, first, last_arg, clleft, top, TRUE); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     grp->FirstClause = min = max+1; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return lbl; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_pair(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   ClauseDef *min = grp->FirstClause; | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   ClauseDef *max = grp->FirstClause; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   while (IsPairTerm(max->Tag) && max != grp->LastClause) { | 
					
						
							|  |  |  |  |     max++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-02-21 16:50:21 +00:00
										 |  |  |  |   if (!IsPairTerm(max->Tag)) { | 
					
						
							|  |  |  |  |     max--; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   if (min > grp->LastClause) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* no clauses, just skip */ | 
					
						
							|  |  |  |  |     return nxtlbl; | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   grp->FirstClause = max+1; | 
					
						
							|  |  |  |  |   if (min == max) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* single clause, no need to do indexing, but we do know it is a list */  | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |     if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       return (UInt)(min->Code); | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       return (UInt)(min->CurrentCode); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (min != max && !IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  |     return suspend_indexing(min, max, cint->CurrentPred, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  |   return do_compound_index(min, max, (IsPairTerm(t) ? RepPair(t) : NULL), cint, 0, 2, argno, nxtlbl, first, last_arg, clleft, top, TRUE); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | group_prologue(int compound_term, UInt argno, int first, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (compound_term) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(cache_sub_arg_op, compound_term-1, compound_term-1, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     if (!first || argno != 1) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(cache_arg_op, argno, argno, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* make sure that we can handle failure correctly */ | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | emit_protection_choicepoint(int first, int clleft, UInt nxtlbl, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (first) { | 
					
						
							|  |  |  |  |     if (clleft) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  | 	UInt labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | 	Yap_emit_4ops(enter_lu_op, labl, labl, 0, Zero, cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	Yap_emit(label_op, labl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(tryme_op, nxtlbl, (clleft << 1), cint); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* !first */ | 
					
						
							|  |  |  |  |     if (clleft) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(retryme_op, nxtlbl, (clleft << 1), cint); | 
					
						
							| 
									
										
										
										
											2003-12-18 17:36:54 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(trustme_op, 0, 0, cint); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static ClauseDef * | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | cls_move(ClauseDef *min, PredEntry *ap, ClauseDef *max, int compound_term, UInt argno, int last_arg) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   ClauseDef *cl=min; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   cl = min; | 
					
						
							|  |  |  |  |   if (compound_term) { | 
					
						
							|  |  |  |  |     while (cl <= max) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       skip_to_arg(cl, ap, compound_term, last_arg ); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     while (cl <= max) { | 
					
						
							|  |  |  |  |       if (cl->Tag == (_var+1)*sizeof(CELL)) { | 
					
						
							|  |  |  |  | 	ClauseDef *cli = cl; | 
					
						
							|  |  |  |  | 	while (cli < max) { | 
					
						
							|  |  |  |  | 	  clcpy(cli,cli+1); | 
					
						
							|  |  |  |  | 	  cli++; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	max--; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	move_next(cl, argno); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return max; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | purge_pvar(GroupDef *group) { | 
					
						
							|  |  |  |  |   ClauseDef *max = group->LastClause; | 
					
						
							|  |  |  |  |   ClauseDef *cl = group->FirstClause; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (cl <= max) { | 
					
						
							|  |  |  |  |     if (cl->Tag == (_var+1)*sizeof(CELL)) { | 
					
						
							|  |  |  |  |       ClauseDef *cli = cl; | 
					
						
							|  |  |  |  |       while (cli < max) { | 
					
						
							|  |  |  |  | 	clcpy(cli,cli+1); | 
					
						
							|  |  |  |  | 	cli++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       group->VarClauses--; | 
					
						
							|  |  |  |  |       max--; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     cl++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   group->LastClause = max; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static UInt * | 
					
						
							| 
									
										
										
										
											2004-11-19 17:14:15 +00:00
										 |  |  |  | do_nonvar_group(GroupDef *grp, Term t, UInt compound_term, CELL *sreg, UInt arity, UInt labl, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   TypeSwitch *type_sw; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  |    | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   /* move cl pointer */ | 
					
						
							|  |  |  |  |   if (grp->AtomClauses + grp->PairClauses + grp->StructClauses > 1) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op, labl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (argno == 1 && !compound_term) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       emit_protection_choicepoint(first, clleft, nxtlbl, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     group_prologue(compound_term, argno, first, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     if (grp->LastClause < grp->FirstClause) { /* only tests */ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     type_sw = emit_type_switch(switch_on_type_op, cint); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     /* have these first so that we will have something initialised here */ | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |     type_sw->ConstEntry =  | 
					
						
							|  |  |  |  |       type_sw->FuncEntry =  | 
					
						
							|  |  |  |  |       type_sw->PairEntry =  | 
					
						
							| 
									
										
										
										
											2006-05-02 16:44:11 +00:00
										 |  |  |  |       type_sw->VarEntry = | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |       nxtlbl; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     type_sw->VarEntry = do_var_entries(grp, t, cint, argno, first, clleft, nxtlbl); | 
					
						
							|  |  |  |  |     grp->LastClause = cls_move(grp->FirstClause, ap, grp->LastClause, compound_term, argno, last_arg); | 
					
						
							|  |  |  |  |     sort_group(grp,top,cint); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |     while (grp->FirstClause <= grp->LastClause) { | 
					
						
							|  |  |  |  |       if (IsAtomOrIntTerm(grp->FirstClause->Tag)) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	type_sw->ConstEntry = do_consts(grp, t, cint, compound_term, sreg, arity, last_arg, argno, first, nxtlbl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |       } else if (IsApplTerm(grp->FirstClause->Tag)) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	type_sw->FuncEntry = do_funcs(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	type_sw->PairEntry = do_pair(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return &(type_sw->VarEntry); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op,labl,Zero, cint); | 
					
						
							|  |  |  |  |     do_var_group(grp, cint, TRUE, first, clleft, nxtlbl, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_optims(GroupDef *group, int ngroups, UInt fail_l, ClauseDef *min, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (ngroups==2 && group[0].FirstClause ==  group[0].LastClause && | 
					
						
							|  |  |  |  |       group[0].AtomClauses == 1 && group[1].VarClauses == 1) { | 
					
						
							|  |  |  |  |     CELL *sp; | 
					
						
							|  |  |  |  |     UInt labl; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     sp = Yap_emit_extra_size(if_not_op, Zero, 4*CellSize, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     sp[0] = (CELL)(group[0].FirstClause->Tag); | 
					
						
							|  |  |  |  |     sp[1] = (CELL)(group[1].FirstClause->Code); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     sp[2] = do_var_clauses(group[0].FirstClause, group[1].LastClause, FALSE, cint, TRUE, 0, (CELL)FAILCODE, cint->CurrentPred->ArityOfPE+1);       | 
					
						
							|  |  |  |  |     sp[3] = do_var_clauses(min, group[1].LastClause, FALSE, cint, TRUE, 0, (CELL)FAILCODE, cint->CurrentPred->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     return labl; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return fail_l; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static int | 
					
						
							|  |  |  |  | cls_info(ClauseDef *min, ClauseDef *max, UInt argno) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   ClauseDef *cl=min; | 
					
						
							|  |  |  |  |   int found_pvar = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (cl <= max) { | 
					
						
							|  |  |  |  |     add_info(cl, argno); | 
					
						
							|  |  |  |  |     if (cl->Tag == (_var+1)*sizeof(CELL)) { | 
					
						
							|  |  |  |  |       found_pvar = TRUE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /*    if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */ | 
					
						
							|  |  |  |  |     cl++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   return found_pvar; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |  | cls_head_info(ClauseDef *min, ClauseDef *max, UInt argno, int in_idb) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   ClauseDef *cl=min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |  |   if (in_idb) { | 
					
						
							|  |  |  |  |     if (argno != 2) { | 
					
						
							|  |  |  |  |       while (cl <= max) { | 
					
						
							|  |  |  |  | 	cl->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	cl++; | 
					
						
							|  |  |  |  |       }  | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       while (cl <= max) { | 
					
						
							|  |  |  |  | 	LogUpdClause *lcl = ClauseCodeToLogUpdClause(cl->CurrentCode); | 
					
						
							|  |  |  |  | 	Term t = lcl->ClSource->Entry; | 
					
						
							|  |  |  |  |        | 
					
						
							|  |  |  |  | 	if (IsVarTerm(t)) { | 
					
						
							|  |  |  |  | 	  cl->Tag = (CELL)NULL; | 
					
						
							|  |  |  |  | 	} else if (IsApplTerm(t)) { | 
					
						
							|  |  |  |  | 	  CELL *pt = RepAppl(t); | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	  cl->Tag = AbsAppl((CELL *)pt[0]); | 
					
						
							|  |  |  |  | 	  if (IsExtensionFunctor(FunctorOfTerm(t))) { | 
					
						
							|  |  |  |  | 	    cl->u.t_ptr = t; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    cl->u.c_sreg = pt; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	  CELL *pt = RepPair(t); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	  cl->Tag = AbsPair(NULL); | 
					
						
							|  |  |  |  | 	  cl->u.c_sreg = pt-1; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  cl->Tag = t; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	cl++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |       while (cl <= max) { | 
					
						
							|  |  |  |  | 	add_head_info(cl, argno); | 
					
						
							|  |  |  |  | 	/*    if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */ | 
					
						
							|  |  |  |  | 	cl++; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   UInt ngroups, found_pvar = FALSE; | 
					
						
							|  |  |  |  |   UInt i = 0; | 
					
						
							|  |  |  |  |   GroupDef *group = (GroupDef *)top; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |   UInt labl, labl0, lablx; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   Term t; | 
					
						
							|  |  |  |  |   /* remember how we entered here */ | 
					
						
							|  |  |  |  |   UInt argno0 = argno; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   yamop *eblk = cint->expand_block; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (min == max) { | 
					
						
							|  |  |  |  |     /* base case, just commit to the current code */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return emit_single_switch_case(min, cint, first, clleft, fail_l); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  |   if ((argno > 1 && yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_SINGLE && ap->PredFlags & LogUpdatePredFlag) || | 
					
						
							| 
									
										
										
										
											2005-10-29 02:21:47 +00:00
										 |  |  |  |       yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_OFF || | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |       ap->ArityOfPE < argno) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   t = Deref(XREGS[argno]); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |  |     found_pvar = cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE)); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     found_pvar = cls_info(min, max, argno); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |   ngroups = groups_in(min, max, group, cint); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     lablx = new_label(cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op, lablx, Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |     while (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |       if (ngroups > 1 || !group->VarClauses) { | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | 	UInt susp_lab = suspend_indexing(min, max, ap, cint); | 
					
						
							|  |  |  |  | 	if (!cint->expand_block) { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  | 	  cint->expand_block = (yamop *)susp_lab; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	Yap_emit(jump_nv_op, susp_lab, argno, cint); | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2005-07-18 17:41:16 +00:00
										 |  |  |  |       if (argno == ap->ArityOfPE || | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  | 	  (yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_SINGLE && | 
					
						
							|  |  |  |  | 	   ap->PredFlags & LogUpdatePredFlag)) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, argno0); | 
					
						
							| 
									
										
										
										
											2004-04-27 15:03:43 +00:00
										 |  |  |  | 	cint->expand_block = eblk; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  | 	return lablx; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       argno++; | 
					
						
							|  |  |  |  |       t = Deref(XREGS[argno]); | 
					
						
							|  |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |  | 	found_pvar = cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE) ); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	found_pvar = cls_info(min, max, argno); | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |       ngroups = groups_in(min, max, group, cint); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     labl0 = labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     lablx = labl0 = labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   cint->expand_block = eblk; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   top = (CELL *)(group+ngroups); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (argno > 1) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* don't try being smart for other arguments than the first */ | 
					
						
							|  |  |  |  |     if (ngroups > 1 || group->VarClauses != 0 || found_pvar) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (ap->ArityOfPE == argno) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       ClauseDef *cl = min; | 
					
						
							|  |  |  |  |       /*
 | 
					
						
							|  |  |  |  | 	need to reset the code pointer, otherwise I could be in | 
					
						
							|  |  |  |  | 	the middle of a compound term. | 
					
						
							|  |  |  |  |        */ | 
					
						
							|  |  |  |  |       while (cl <= max) { | 
					
						
							|  |  |  |  | 	cl->CurrentCode = cl->Code; | 
					
						
							|  |  |  |  | 	cl++; | 
					
						
							|  |  |  |  |       }     | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     UInt special_options; | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if ((ap->PredFlags & LogUpdatePredFlag) && ngroups > 1) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       if (ngroups > 1) { | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  | 	group[0].VarClauses = ap->cs.p_code.NOfClauses; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	group[0].AtomClauses = | 
					
						
							|  |  |  |  | 	  group[0].PairClauses =  | 
					
						
							|  |  |  |  | 	  group[0].StructClauses =  | 
					
						
							|  |  |  |  | 	  group[0].TestClauses = 0; | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  | 	group[0].LastClause = group[ngroups-1].LastClause; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	ngroups = 1;	 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     } else if ((special_options = do_optims(group, ngroups, fail_l, min, cint)) != fail_l) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       return special_options; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (ngroups == 1 && group->VarClauses && !found_pvar) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  |     } else if (found_pvar || | 
					
						
							|  |  |  |  | 	       (ap->PredFlags & LogUpdatePredFlag && group[0].VarClauses)) { | 
					
						
							|  |  |  |  |       /* make sure we know where to suspend */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(label_op, labl0, Zero, cint); | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |       labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2006-03-20 19:51:44 +00:00
										 |  |  |  |       Yap_emit(jump_v_op, suspend_indexing(min, max, ap, cint), Zero, cint);  | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   for (i=0; i < ngroups; i++) { | 
					
						
							|  |  |  |  |     UInt nextlbl; | 
					
						
							|  |  |  |  |     int left_clauses = clleft+(max-group->LastClause); | 
					
						
							|  |  |  |  |     /* a group may end up not having clauses*/ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (i < ngroups-1) { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |       nextlbl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } else { | 
					
						
							|  |  |  |  |       nextlbl = fail_l; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (found_pvar && argno == 1) { | 
					
						
							|  |  |  |  |       purge_pvar(group); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (group->FirstClause==group->LastClause && first && left_clauses == 0) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       Yap_emit(jumpi_op, (CELL)(group->FirstClause->Code), Zero, cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     } else { | 
					
						
							|  |  |  |  |       if (group->VarClauses) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	Yap_emit(label_op,labl,Zero, cint); | 
					
						
							|  |  |  |  | 	do_var_group(group, cint, argno == 1, first, left_clauses, nextlbl, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	do_nonvar_group(group, t, 0, NULL, 0, labl, cint, argno, first, TRUE, nextlbl, left_clauses, top); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     first = FALSE; | 
					
						
							|  |  |  |  |     group++; | 
					
						
							|  |  |  |  |     labl = nextlbl; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |   return lablx; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static ClauseDef * | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   UInt sz = ((max0+1)-min0)*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   if ((char *)top + sz >= LOCAL_TrailTop-4096) { | 
					
						
							|  |  |  |  |     LOCAL_Error_Size = sz; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     /* grow stack */ | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   memcpy((void *)top, (void *)min0, sz); | 
					
						
							|  |  |  |  |   return (ClauseDef *)top; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-05 00:12:13 +01:00
										 |  |  |  | /* make sure that it is worth it to generate indexing code at that point */ | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | several_tags(ClauseDef *min, ClauseDef *max) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   CELL tag = min->Tag; | 
					
						
							|  |  |  |  |   while (min < max) { | 
					
						
							|  |  |  |  |     min++; | 
					
						
							| 
									
										
										
										
											2012-06-05 08:04:22 +01:00
										 |  |  |  |     if (!IsAtomOrIntTerm(min->Tag) || min->Tag != tag) | 
					
						
							| 
									
										
										
										
											2012-06-05 00:12:13 +01:00
										 |  |  |  |       return TRUE; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | /* execute an index inside a structure */ | 
					
						
							|  |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermediates *cint, UInt i, UInt arity, UInt argno, UInt fail_l, int first, int last_arg, int clleft, CELL *top, int done_work) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-02-21 16:50:21 +00:00
										 |  |  |  |   UInt ret_lab = 0, *newlabp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   CELL *top0 = top; | 
					
						
							|  |  |  |  |   ClauseDef *min, *max; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2003-12-27 00:38:53 +00:00
										 |  |  |  |   int found_index = FALSE, lu_pred = ap->PredFlags & LogUpdatePredFlag; | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   UInt old_last_depth, old_last_depth_size; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   newlabp = & ret_lab; | 
					
						
							|  |  |  |  |   if (min0 == max0) { | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* base case, just commit to the current code */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return emit_single_switch_case(min0, cint, first, clleft, fail_l); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-01 13:16:29 +01:00
										 |  |  |  |   if ((yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_SINGLE && ap->PredFlags & LogUpdatePredFlag) || | 
					
						
							|  |  |  |  |       (yap_flags[INDEXING_TERM_DEPTH_FLAG] && cint->term_depth - cint->last_index_new_depth > yap_flags[INDEXING_TERM_DEPTH_FLAG])) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     *newlabp =  | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       do_var_clauses(min0, max0, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2012-06-01 13:16:29 +01:00
										 |  |  |  |    return ret_lab; | 
					
						
							| 
									
										
										
										
											2003-06-06 11:54:02 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-01 13:16:29 +01:00
										 |  |  |  |   if (sreg == NULL) { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     return suspend_indexing(min0, max0, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   cint->term_depth++; | 
					
						
							|  |  |  |  |   old_last_depth = cint->last_index_new_depth; | 
					
						
							|  |  |  |  |   old_last_depth_size = cint->last_depth_size; | 
					
						
							|  |  |  |  |   if (cint->last_depth_size != max0-min0) { | 
					
						
							|  |  |  |  |     cint->last_index_new_depth = cint->term_depth; | 
					
						
							|  |  |  |  |     cint->last_depth_size = max0-min0; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   while (i < arity && !found_index) {  | 
					
						
							|  |  |  |  |     ClauseDef *cl; | 
					
						
							|  |  |  |  |     GroupDef *group; | 
					
						
							|  |  |  |  |     UInt ngroups; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |     int isvt = IsVarTerm(Deref(sreg[i])); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     min = copy_clauses(max0, min0, top, cint); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     max = min+(max0-min0); | 
					
						
							|  |  |  |  |     top = (CELL *)(max+1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     cl = min; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* search for a subargument */ | 
					
						
							|  |  |  |  |     while (cl <= max) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       add_arg_info(cl, ap, i+1); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |       cl++; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     group = (GroupDef *)top; | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |     ngroups = groups_in(min, max, group, cint);     | 
					
						
							| 
									
										
										
										
											2012-06-05 08:04:22 +01:00
										 |  |  |  |     if (ngroups == 1 && group->VarClauses == 0 && (i < 8 || several_tags(min,max))) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* ok, we are doing a sub-argument */ | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |       /* process group */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       found_index = TRUE; | 
					
						
							|  |  |  |  |       ret_lab = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       top = (CELL *)(group+1); | 
					
						
							| 
									
										
										
										
											2009-02-10 22:35:54 +00:00
										 |  |  |  |       if (do_nonvar_group(group, (sreg == NULL ? 0L : Deref(sreg[i])), i+1, (isvt ? NULL : sreg), arity, *newlabp, cint, argno, first, (last_arg && i+1 == arity), fail_l, clleft, top) == NULL) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	top = top0; | 
					
						
							|  |  |  |  | 	break; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     top = top0; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     i++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (!found_index) { | 
					
						
							| 
									
										
										
										
											2003-09-15 19:06:55 +00:00
										 |  |  |  |     if (!lu_pred || !done_work) | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |       *newlabp = do_index(min0, max0, cint, argno+1, fail_l, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     else | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |       *newlabp = suspend_indexing(min0, max0, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   cint->last_index_new_depth = old_last_depth; | 
					
						
							|  |  |  |  |   cint->last_depth_size = old_last_depth_size; | 
					
						
							|  |  |  |  |   cint->term_depth--; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return ret_lab; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | do_dbref_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   UInt ngroups; | 
					
						
							|  |  |  |  |   GroupDef *group; | 
					
						
							|  |  |  |  |   ClauseDef *cl = min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   group = (GroupDef *)top; | 
					
						
							|  |  |  |  |   cl = min; | 
					
						
							|  |  |  |  |    | 
					
						
							|  |  |  |  |   while (cl <= max) { | 
					
						
							|  |  |  |  |     cl->Tag = cl->u.t_ptr; | 
					
						
							|  |  |  |  |     cl++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |   ngroups = groups_in(min, max, group, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (ngroups > 1 || group->VarClauses) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     int labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op, labl, Zero, cint); | 
					
						
							|  |  |  |  |     Yap_emit(index_dbref_op, Zero, Zero, cint); | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     sort_group(group,(CELL *)(group+1),cint); | 
					
						
							| 
									
										
										
										
											2011-01-20 12:01:18 -06:00
										 |  |  |  |     do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group+1)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return labl; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  | do_blob_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top, int blob) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   UInt ngroups; | 
					
						
							|  |  |  |  |   GroupDef *group; | 
					
						
							|  |  |  |  |   ClauseDef *cl = min; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   group = (GroupDef *)top; | 
					
						
							|  |  |  |  |   cl = min; | 
					
						
							|  |  |  |  |    | 
					
						
							|  |  |  |  |   while (cl <= max) { | 
					
						
							| 
									
										
										
										
											2003-09-23 15:14:56 +00:00
										 |  |  |  |     if (cl->u.t_ptr == (CELL)NULL) { /* check whether it is a builtin */ | 
					
						
							|  |  |  |  |       cl->Tag = Zero; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     } else if (blob) { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cl->Tag = Yap_Double_key(cl->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cl->Tag = Yap_Int_key(cl->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2003-09-23 15:14:56 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     cl++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-22 08:38:05 +00:00
										 |  |  |  |   ngroups = groups_in(min, max, group, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (ngroups > 1 || group->VarClauses) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     int labl = new_label(cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_emit(label_op, labl, Zero, cint); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     if (blob) | 
					
						
							|  |  |  |  |       Yap_emit(index_blob_op, Zero, Zero, cint); | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |       Yap_emit(index_long_op, Zero, Zero, cint); | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     sort_group(group,(CELL *)(group+1),cint); | 
					
						
							| 
									
										
										
										
											2011-01-20 12:01:18 -06:00
										 |  |  |  |     do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group+1)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return labl; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | init_clauses(ClauseDef *cl, PredEntry *ap) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); | 
					
						
							| 
									
										
										
										
											2011-08-31 21:13:29 -07:00
										 |  |  |  |     UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; | 
					
						
							|  |  |  |  |     yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     yamop *cd = mcl->ClCode; | 
					
						
							|  |  |  |  |     while (cd < end) { | 
					
						
							|  |  |  |  |       cl->Code = cl->CurrentCode = cd; | 
					
						
							|  |  |  |  |       cd = (yamop *)((char *)cd+mcl->ClItemSize); | 
					
						
							|  |  |  |  |       cl++; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |     StaticClause *scl; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |     scl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     do { | 
					
						
							|  |  |  |  |       cl->Code = cl->CurrentCode = scl->ClCode; | 
					
						
							|  |  |  |  |       cl++; | 
					
						
							|  |  |  |  |       if (scl->ClCode == ap->cs.p_code.LastClause) | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       scl = scl->ClNext; | 
					
						
							|  |  |  |  |     } while (TRUE); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | init_log_upd_clauses(ClauseDef *cl, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   LogUpdClause *lcl = ClauseCodeToLogUpdClause(ap->cs.p_code.FirstClause); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   do { | 
					
						
							|  |  |  |  |     cl->Code = cl->CurrentCode = lcl->ClCode; | 
					
						
							|  |  |  |  |     cl++; | 
					
						
							|  |  |  |  |     lcl = lcl->ClNext; | 
					
						
							|  |  |  |  |   } while (lcl != NULL); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | static UInt | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | compile_index(struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   int NClauses = ap->cs.p_code.NOfClauses; | 
					
						
							|  |  |  |  |   CELL *top = (CELL *) TR; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   UInt res; | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   /* only global variable I use directly */ | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   cint->i_labelno = 1; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_Error_Size = 0; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   if (!cint->cls) { | 
					
						
							|  |  |  |  |     cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); | 
					
						
							|  |  |  |  |     if (!cint->cls) { | 
					
						
							|  |  |  |  |       /* tell how much space we need */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size += NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       /* grow stack */ | 
					
						
							|  |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   cint->freep = (char *)H; | 
					
						
							|  |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |  |   /* reserve double the space for compiler */ | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   cint->cls = (ClauseDef *)H; | 
					
						
							|  |  |  |  |   if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |  |     /* tell how much space we need */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     LOCAL_Error_Size += NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |     /* grow stack */ | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,3); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   cint->freep = (char *)(cint->cls+NClauses); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     /* throw away a label */ | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |     new_label(cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     init_log_upd_clauses(cint->cls,ap); | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |   } else if (ap->PredFlags & UDIPredFlag) { | 
					
						
							|  |  |  |  |     UInt lbl = new_label(cint); | 
					
						
							|  |  |  |  |     Yap_emit(user_switch_op, Unsigned(ap), Unsigned(&(ap->cs.p_code.ExpandCode)), cint); | 
					
						
							|  |  |  |  |     return lbl; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     /* prepare basic data structures */  | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     init_clauses(cint->cls,ap); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   res = do_index(cint->cls, cint->cls+(NClauses-1), cint, 1, (UInt)FAILCODE, TRUE, 0, top); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   return res; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | CleanCls(struct intermediates *cint) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							|  |  |  |  |   if (cint->cls) { | 
					
						
							|  |  |  |  |     Yap_FreeCodeSpace((ADDR)cint->cls); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   cint->cls = NULL; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-27 16:53:09 +00:00
										 |  |  |  | yamop * | 
					
						
							| 
									
										
										
										
											2010-01-29 15:21:00 +00:00
										 |  |  |  | Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   yamop *indx_out; | 
					
						
							| 
									
										
										
										
											2003-10-02 18:20:11 +00:00
										 |  |  |  |   int setjres; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   struct intermediates cint; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-27 14:05:27 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   cint.CurrentPred = ap; | 
					
						
							| 
									
										
										
										
											2009-03-27 14:05:27 +00:00
										 |  |  |  |   cint.code_addr = NULL; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   cint.blks = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   cint.cls = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_Error_Size = 0; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |   if ((setjres = sigsetjmp(cint.CompilerBotch, 0)) == 3) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     recover_from_failed_susp_on_cls(&cint, 0); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     if (!Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+NSlots, ENV, next_pc)) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2008-01-24 00:11:59 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-10-02 18:20:11 +00:00
										 |  |  |  |   } else if (setjres == 2) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size); | 
					
						
							|  |  |  |  |     if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else if (setjres == 4) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     recover_from_failed_susp_on_cls(&cint, 0); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2003-10-02 18:20:11 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else if (setjres != 0) { | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     recover_from_failed_susp_on_cls(&cint, 0); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { | 
					
						
							|  |  |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-10-02 18:20:11 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |  restart_index: | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   Yap_BuildMegaClause(ap); | 
					
						
							|  |  |  |  |   cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL; | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |   cint.expand_block = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:49:25 +01:00
										 |  |  |  |   cint.label_offset = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   if (compile_index(&cint) == (UInt)FAILCODE) { | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-10-02 18:20:11 +00:00
										 |  |  |  |     return FAILCODE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |  |   if (GLOBAL_Option['i' - 'a' + 1]) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_ShowCode(&cint); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |  |   /* globals for assembler */ | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |   LOCAL_IPredArity = ap->ArityOfPE; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   if (cint.CodeStart) { | 
					
						
							| 
									
										
										
										
											2010-04-15 11:37:39 +01:00
										 |  |  |  |     if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  | 	Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  | 	Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       goto restart_index; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |   Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     LogUpdIndex *cl = ClauseCodeToLogUpdIndex(indx_out); | 
					
						
							|  |  |  |  |     cl->ClFlags |= SwitchRootMask; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  |   return(indx_out); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static istack_entry * | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   if (sp+1 > (istack_entry *)LOCAL_TrailTop) { | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,4);     | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   sp->pos = arg; | 
					
						
							|  |  |  |  |   sp->val = Tag; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |   sp->extra = extra; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   sp++; | 
					
						
							|  |  |  |  |   sp->pos = 0; | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static istack_entry * | 
					
						
							|  |  |  |  | install_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							|  |  |  |  |   while (sp->pos) { | 
					
						
							|  |  |  |  |     if ((Int)(sp->pos) > 0) { | 
					
						
							|  |  |  |  |       add_info(cls, sp->pos); | 
					
						
							|  |  |  |  |     } else if (sp->pos) { | 
					
						
							|  |  |  |  |       UInt argno = -sp->pos; | 
					
						
							|  |  |  |  |       add_arg_info(cls, ap, argno); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* if we are not talking about a variable */ | 
					
						
							|  |  |  |  |     if (cls->Tag != sp->val) { | 
					
						
							|  |  |  |  |       if (sp->val == 0L) { | 
					
						
							|  |  |  |  | 	sp++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	Functor f = (Functor)RepAppl(cls->Tag); | 
					
						
							|  |  |  |  | 	if (IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |  | 	  if (f == FunctorDBRef) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	    if (cls->u.t_ptr != sp->extra) break; | 
					
						
							| 
									
										
										
										
											2010-03-12 18:03:15 +00:00
										 |  |  |  | 	  } else if (f == FunctorDouble) { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  | 	    if (cls->u.t_ptr && | 
					
						
							|  |  |  |  | 		Yap_Double_key(sp->extra) != Yap_Double_key(cls->u.t_ptr)) | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-03-12 18:03:15 +00:00
										 |  |  |  | 	  } else { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  | 	    if (cls->u.t_ptr &&  | 
					
						
							|  |  |  |  | 		Yap_Int_key(sp->extra) != Yap_Int_key(cls->u.t_ptr)) | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if ((Int)(sp->pos) > 0) { | 
					
						
							|  |  |  |  | 	move_next(cls, sp->pos); | 
					
						
							|  |  |  |  |       } else if (sp->pos) { | 
					
						
							|  |  |  |  | 	UInt argno = -sp->pos; | 
					
						
							|  |  |  |  | 	skip_to_arg(cls, ap, argno, FALSE); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     sp++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							| 
									
										
										
										
											2003-06-06 13:16:40 +00:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static ClauseDef * | 
					
						
							|  |  |  |  | install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, yamop *end) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     MegaClause *mcl = ClauseCodeToMegaClause(beg); | 
					
						
							| 
									
										
										
										
											2011-08-31 21:13:29 -07:00
										 |  |  |  |     UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; | 
					
						
							|  |  |  |  |     yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     yamop *cd = mcl->ClCode; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     if (stack[0].pos == 0) { | 
					
						
							|  |  |  |  |       while (TRUE) { | 
					
						
							|  |  |  |  | 	cls->Code =  cls->CurrentCode = cd; | 
					
						
							|  |  |  |  | 	cls->Tag =  0; | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  | 	cd = (yamop *)((char *)cd+mcl->ClItemSize); | 
					
						
							|  |  |  |  | 	if (cd == end) { | 
					
						
							|  |  |  |  | 	  return cls-1; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     while (TRUE) { | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       cls->Code =  cls->CurrentCode = cd; | 
					
						
							|  |  |  |  |       sp = install_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |       /* we reached a matching clause */ | 
					
						
							|  |  |  |  |       if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       cd = (yamop *)((char *)cd+mcl->ClItemSize); | 
					
						
							|  |  |  |  |       if (cd == end) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	return cls-1; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     StaticClause *cl = ClauseCodeToStaticClause(beg); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (stack[0].pos == 0) { | 
					
						
							|  |  |  |  |       while (TRUE) { | 
					
						
							|  |  |  |  | 	cls->Code =  cls->CurrentCode = cl->ClCode; | 
					
						
							|  |  |  |  | 	cls->Tag =  0; | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  | 	if (cl->ClCode == end) { | 
					
						
							|  |  |  |  | 	  return cls-1; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	cl = cl->ClNext; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     while (TRUE) { | 
					
						
							|  |  |  |  |       cls->Code =  cls->CurrentCode = cl->ClCode; | 
					
						
							|  |  |  |  |       sp = install_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |       /* we reached a matching clause */ | 
					
						
							|  |  |  |  |       if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       if (cl->ClCode == end || cl->ClCode == NULL) { | 
					
						
							|  |  |  |  | 	return cls-1; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       cl = cl->ClNext; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | static ClauseDef * | 
					
						
							|  |  |  |  | install_clauseseq(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop **beg, yamop **end) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (stack[0].pos == 0) { | 
					
						
							|  |  |  |  |     while (TRUE) { | 
					
						
							|  |  |  |  |       if (*beg) {  | 
					
						
							|  |  |  |  | 	cls->Code =  cls->CurrentCode = *beg; | 
					
						
							|  |  |  |  | 	cls->Tag =  0; | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       beg++; | 
					
						
							|  |  |  |  |       if (beg == end) { | 
					
						
							|  |  |  |  | 	return cls-1; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |  |     if (*beg) { | 
					
						
							|  |  |  |  |       cls->Code =  cls->CurrentCode = *beg; | 
					
						
							|  |  |  |  |       sp = install_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |       /* we reached a matching clause */ | 
					
						
							|  |  |  |  |       if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     beg++; | 
					
						
							|  |  |  |  |     if (beg == end) { | 
					
						
							|  |  |  |  |       return cls-1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | reinstall_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, istack_entry *stack) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   do { | 
					
						
							|  |  |  |  |     cls->CurrentCode = cls->Code; | 
					
						
							|  |  |  |  |     install_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |   } while (cls++ != end); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static istack_entry * | 
					
						
							|  |  |  |  | install_log_upd_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							|  |  |  |  |   while (sp->pos) { | 
					
						
							|  |  |  |  |     if ((Int)(sp->pos) > 0) { | 
					
						
							|  |  |  |  |       add_head_info(cls, sp->pos); | 
					
						
							|  |  |  |  |     } else if (sp->pos) { | 
					
						
							|  |  |  |  |       UInt argno = -sp->pos; | 
					
						
							|  |  |  |  |       add_arg_info(cls, ap, argno); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* if we are not talking about a variable */ | 
					
						
							|  |  |  |  |     if (cls->Tag != sp->val) { | 
					
						
							|  |  |  |  |       if (sp->val == 0L) { | 
					
						
							|  |  |  |  | 	sp++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	Functor f = (Functor)RepAppl(cls->Tag); | 
					
						
							|  |  |  |  | 	if (IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |  | 	  if (f == FunctorDBRef) { | 
					
						
							|  |  |  |  | 	    if (cls->u.t_ptr != sp->extra) break; | 
					
						
							| 
									
										
										
										
											2010-03-12 18:03:15 +00:00
										 |  |  |  | 	  } else if (f == FunctorDouble) { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  | 	    if (cls->u.t_ptr &&   | 
					
						
							|  |  |  |  | 		Yap_Double_key(sp->extra) != Yap_Double_key(cls->u.t_ptr)) | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-03-12 18:03:15 +00:00
										 |  |  |  | 	  } else { | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  | 	    if (cls->u.t_ptr &&  | 
					
						
							|  |  |  |  | 		Yap_Int_key(sp->extra) != Yap_Int_key(cls->u.t_ptr)) | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if ((Int)(sp->pos) > 0) { | 
					
						
							|  |  |  |  | 	move_next(cls, sp->pos); | 
					
						
							|  |  |  |  |       } else if (sp->pos) { | 
					
						
							|  |  |  |  | 	UInt argno = -sp->pos; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	skip_to_arg(cls, ap, argno, FALSE); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     sp++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static ClauseDef * | 
					
						
							|  |  |  |  | install_log_upd_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, yamop *end) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (stack[0].pos == 0) { | 
					
						
							|  |  |  |  |     while (TRUE) { | 
					
						
							|  |  |  |  |       cls->Code =  cls->CurrentCode = beg; | 
					
						
							|  |  |  |  |       cls->Tag =  0; | 
					
						
							|  |  |  |  |       cls++; | 
					
						
							|  |  |  |  |       if (beg == end || beg == NULL) { | 
					
						
							|  |  |  |  | 	return cls-1; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |  |     cls->Code =  cls->CurrentCode = beg; | 
					
						
							|  |  |  |  |     sp = install_log_upd_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |     /* we reached a matching clause */ | 
					
						
							|  |  |  |  |     if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { | 
					
						
							|  |  |  |  |       cls++; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (beg == end || beg == NULL) { | 
					
						
							|  |  |  |  |       return cls-1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | static ClauseDef * | 
					
						
							|  |  |  |  | install_log_upd_clauseseq(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop **beg, yamop **end) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   istack_entry *sp = stack; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (stack[0].pos == 0) { | 
					
						
							|  |  |  |  |     while (TRUE) { | 
					
						
							|  |  |  |  |       if (beg) { | 
					
						
							|  |  |  |  | 	cls->Code = cls->CurrentCode = *beg; | 
					
						
							|  |  |  |  | 	cls->Tag = 0; | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       beg++; | 
					
						
							|  |  |  |  |       if (beg == end) { | 
					
						
							|  |  |  |  | 	return cls-1; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |  |     if (*beg) { | 
					
						
							|  |  |  |  |       cls->Code =  cls->CurrentCode = *beg; | 
					
						
							|  |  |  |  |       sp = install_log_upd_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |       /* we reached a matching clause */ | 
					
						
							|  |  |  |  |       if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { | 
					
						
							|  |  |  |  | 	cls++; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     beg++; | 
					
						
							|  |  |  |  |     if (beg == end) { | 
					
						
							|  |  |  |  |       return cls-1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | reinstall_log_upd_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, istack_entry *stack) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   do { | 
					
						
							|  |  |  |  |     cls->CurrentCode = cls->Code; | 
					
						
							|  |  |  |  |     install_log_upd_clause(cls, ap, stack); | 
					
						
							|  |  |  |  |   } while (cls++ != end); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #if PRECOMPUTE_REGADDRESS
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #define arg_from_x(I)		(((CELL *)(I))-XREGS)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #else
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #define arg_from_x(I)		(I)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #endif /* ALIGN_LONGS */
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static AtomSwiEntry * | 
					
						
							|  |  |  |  | lookup_c(Term t, yamop *tab, COUNT entries) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   AtomSwiEntry *cebase = (AtomSwiEntry *)tab; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (cebase->Tag != t) { | 
					
						
							|  |  |  |  |     entries--; | 
					
						
							|  |  |  |  |     cebase++; | 
					
						
							|  |  |  |  |     if (entries == 0) | 
					
						
							|  |  |  |  |       return cebase; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return cebase; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static FuncSwiEntry * | 
					
						
							|  |  |  |  | lookup_f(Functor f, yamop *tab, COUNT entries) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   FuncSwiEntry *febase = (FuncSwiEntry *)tab; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |                                                  | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   while (febase->Tag != f) { | 
					
						
							|  |  |  |  |     entries--; | 
					
						
							|  |  |  |  |     febase++; | 
					
						
							|  |  |  |  |     if (entries == 0) | 
					
						
							|  |  |  |  |       return febase; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return febase; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static COUNT | 
					
						
							|  |  |  |  | count_clauses_left(yamop *cl, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     LogUpdClause *c = ClauseCodeToLogUpdClause(cl); | 
					
						
							|  |  |  |  |     COUNT i = 0; | 
					
						
							|  |  |  |  |   | 
					
						
							|  |  |  |  |     while (c != NULL) { | 
					
						
							|  |  |  |  |       i++; | 
					
						
							|  |  |  |  |       c = c->ClNext; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return i; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   } else if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); | 
					
						
							| 
									
										
										
										
											2011-08-31 21:13:29 -07:00
										 |  |  |  |     UInt ncls = mcl->ClPred->cs.p_code.NOfClauses; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     return (ncls-1)-((char *)cl-(char *)mcl->ClCode)/mcl->ClItemSize; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     yamop *last = ap->cs.p_code.LastClause; | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |     StaticClause *c; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     COUNT i = 1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |     c = ClauseCodeToStaticClause(cl); | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  |     while (c->ClCode != last) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       i++; | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  |       c = c->ClNext; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     return i; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |   We have jumped across indexing code. Check if we jumped within the current | 
					
						
							|  |  |  |  |   indexing block, if we moved back to a parent, or if we jumped to a child. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | static ClausePointer | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | index_jmp(ClausePointer cur, ClausePointer parent, yamop *ipc, int is_lu, yamop *e_code) | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |   if (cur.lui == NULL || | 
					
						
							|  |  |  |  |       ipc == FAILCODE || | 
					
						
							|  |  |  |  |       ipc == e_code || | 
					
						
							|  |  |  |  |       ipc->opc == Yap_opcode(_expand_clauses) | 
					
						
							|  |  |  |  |       ) | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     return cur; | 
					
						
							|  |  |  |  |   if (is_lu) { | 
					
						
							|  |  |  |  |     LogUpdIndex *lcur = cur.lui, *ncur; | 
					
						
							|  |  |  |  |     /* check myself */ | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  |     if (ipc >= lcur->ClCode && ipc < (yamop *)((CODEADDR)lcur+lcur->ClSize)) | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |       return cur; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |     /* check if I am returning back to a parent, eg 
 | 
					
						
							|  |  |  |  |        switch with intermediate node */ | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     if (lcur->ParentIndex) { | 
					
						
							|  |  |  |  |       LogUpdIndex *pcur = lcur->ParentIndex; | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  |       if (ipc >= pcur->ClCode && ipc < (yamop *)((CODEADDR)pcur+pcur->ClSize)) { | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  | 	cur.lui = pcur; | 
					
						
							| 
									
										
										
										
											2006-03-21 19:20:35 +00:00
										 |  |  |  | 	return cur; | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* maybe I am a new group */ | 
					
						
							|  |  |  |  |     ncur = ClauseCodeToLogUpdIndex(ipc); | 
					
						
							|  |  |  |  |     if (ncur->ParentIndex != lcur) { | 
					
						
							|  |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |       fprintf(stderr,"OOPS, bad parent in lu index\n"); | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |       cur.lui = NULL; | 
					
						
							|  |  |  |  |       return cur; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-03-21 17:11:39 +00:00
										 |  |  |  |     cur.lui = ncur; | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     return cur;     | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-04-05 00:16:55 +00:00
										 |  |  |  |     StaticIndex *scur = parent.si, *ncur; | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     /* check myself */ | 
					
						
							| 
									
										
										
										
											2006-04-05 00:16:55 +00:00
										 |  |  |  |     if (!scur) | 
					
						
							|  |  |  |  |       return cur; | 
					
						
							|  |  |  |  |     if (ipc >= scur->ClCode && | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  | 	ipc < (yamop *)((CODEADDR)scur+scur->ClSize))    | 
					
						
							| 
									
										
										
										
											2006-04-05 00:16:55 +00:00
										 |  |  |  |       return cur; | 
					
						
							|  |  |  |  |     ncur = ClauseCodeToStaticIndex(ipc); | 
					
						
							|  |  |  |  |     if (ncur->ClPred == scur->ClPred) { | 
					
						
							|  |  |  |  |       cur.si = ncur; | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |       return cur; | 
					
						
							| 
									
										
										
										
											2006-04-05 00:16:55 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |     /*
 | 
					
						
							|  |  |  |  |     if (parent.si != cur.si) { | 
					
						
							|  |  |  |  |       if (parent.si) { | 
					
						
							|  |  |  |  | 	StaticIndex *pcur = parent.si; | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  | 	if (ipc >= pcur->ClCode && ipc < (yamop *)((CODEADDR)pcur+pcur->ClSize)) | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  return parent; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     cur.si = ncur; | 
					
						
							|  |  |  |  |     return cur; | 
					
						
							|  |  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     cur.si = NULL; | 
					
						
							|  |  |  |  |     return cur; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static ClausePointer | 
					
						
							|  |  |  |  | code_to_indexcl(yamop *ipc, int is_lu) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   ClausePointer ret; | 
					
						
							|  |  |  |  |   if (is_lu) | 
					
						
							|  |  |  |  |     ret.lui = ClauseCodeToLogUpdIndex(ipc); | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     ret.si = ClauseCodeToStaticIndex(ipc); | 
					
						
							|  |  |  |  |   return ret;     | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | /* CALLED by expand when entering sub_arg */ | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | increase_expand_depth(yamop *ipc, struct intermediates *cint) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   yamop *ncode; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   cint->term_depth++; | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  |   if (ipc->opc == Yap_opcode(_switch_on_sub_arg_type) &&  | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  |       (ncode = ipc->u.sllll.l4)->opc == Yap_opcode(_expand_clauses)) { | 
					
						
							|  |  |  |  |     if (ncode->u.sssllp.s2 != cint->last_depth_size) { | 
					
						
							|  |  |  |  |       cint->last_index_new_depth = cint->term_depth; | 
					
						
							|  |  |  |  |       cint->last_depth_size = ncode->u.sssllp.s2;   | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | zero_expand_depth(PredEntry *ap, struct intermediates *cint) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   cint->term_depth = cint->last_index_new_depth; | 
					
						
							|  |  |  |  |   cint->last_depth_size = ap->cs.p_code.NOfClauses;   | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static yamop ** | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | expand_index(struct intermediates *cint) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* first clause */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   yamop *first, *last = NULL, *alt = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   istack_entry *stack, *sp; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   ClauseDef *max; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   int NClauses; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* last clause to experiment with */ | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   yamop *ipc; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* labp should point at the beginning of the sequence */ | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |   yamop **labp = NULL; | 
					
						
							|  |  |  |  |   ClausePointer parentcl; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   Term t = TermNil, *s_reg = NULL; | 
					
						
							|  |  |  |  |   int is_last_arg = TRUE; | 
					
						
							|  |  |  |  |   int argno = 1; | 
					
						
							|  |  |  |  |   int isfirstcl = TRUE; | 
					
						
							|  |  |  |  |   /* this is will be used as a new PC */ | 
					
						
							|  |  |  |  |   CELL *top = (CELL *) TR; | 
					
						
							|  |  |  |  |   UInt arity = 0; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |   UInt lab, fail_l, clleft, i = 0; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   int is_lu = ap->PredFlags & LogUpdatePredFlag; | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |   yamop *e_code = (yamop *)&(ap->cs.p_code.ExpandCode); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							|  |  |  |  |   first = ap->cs.p_code.FirstClause; | 
					
						
							|  |  |  |  |   NClauses = ap->cs.p_code.NOfClauses; | 
					
						
							| 
									
										
										
										
											2003-09-15 19:06:55 +00:00
										 |  |  |  |   sp = stack = (istack_entry *)top; | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  |  |   cint->i_labelno = 1; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   stack[0].pos = 0; | 
					
						
							|  |  |  |  |   /* try to refine the interval using the indexing code */ | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  |   cint->term_depth = cint->last_index_new_depth = cint->last_depth_size = 0L; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |   parentcl = code_to_indexcl(ipc,is_lu); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   while (ipc != NULL) { | 
					
						
							|  |  |  |  |     op_numbers op; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  |     switch(op) { | 
					
						
							|  |  |  |  |     case _try_clause: | 
					
						
							|  |  |  |  |     case _retry: | 
					
						
							|  |  |  |  |       /* this clause had no indexing */ | 
					
						
							|  |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	first = ClauseCodeToLogUpdClause(ipc->u.Otapl.d)->ClNext->ClCode; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  | 	MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	first = (yamop *)((char *)ipc->u.Otapl.d)+mcl->ClItemSize; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	first = ClauseCodeToStaticClause(ipc->u.Otapl.d)->ClNext->ClCode; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       isfirstcl = FALSE; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_try: | 
					
						
							|  |  |  |  |     case _table_retry: | 
					
						
							|  |  |  |  |       /* this clause had no indexing */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       first = ClauseCodeToStaticClause(PREVOP(ipc->u.Otapl.d,Otapl))->ClNext->ClCode; | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |       isfirstcl = FALSE; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |       break;       | 
					
						
							|  |  |  |  | #endif /* TABLING */
 | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _try_clause2: | 
					
						
							|  |  |  |  |     case _try_clause3: | 
					
						
							|  |  |  |  |     case _try_clause4: | 
					
						
							|  |  |  |  |     case _retry2: | 
					
						
							|  |  |  |  |     case _retry3: | 
					
						
							|  |  |  |  |     case _retry4: | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |     case _try_in: | 
					
						
							|  |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	first = ClauseCodeToLogUpdClause(ipc->u.l.l)->ClNext->ClCode; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  | 	MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	first = (yamop *)((char *)ipc->u.Otapl.d)+mcl->ClItemSize; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  | 	first = ClauseCodeToStaticClause(ipc->u.l.l)->ClNext->ClCode; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       isfirstcl = FALSE; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _retry_me: | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							|  |  |  |  |     case _table_retry_me: | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       isfirstcl = FALSE; | 
					
						
							|  |  |  |  |     case _try_me: | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							|  |  |  |  |     case _table_try_me: | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* ok, we found the start for an indexing block,
 | 
					
						
							|  |  |  |  | 	 but we don't if we are going to operate here or not */ | 
					
						
							|  |  |  |  |       /* if we are to commit here, alt will tell us where */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       alt = ipc->u.Otapl.d; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |       /* start of a group, reset stack */ | 
					
						
							|  |  |  |  |       sp = stack; | 
					
						
							|  |  |  |  |       stack[0].pos = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _profiled_trust_me: | 
					
						
							|  |  |  |  |     case _trust_me: | 
					
						
							|  |  |  |  |     case _count_trust_me: | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							|  |  |  |  |     case _table_trust_me: | 
					
						
							|  |  |  |  | #endif /* TABLING */
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* we will commit to this group for sure */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-11-29 23:41:28 +00:00
										 |  |  |  |       alt = NULL; | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |       /* start of a group, reset stack */ | 
					
						
							|  |  |  |  |       sp = stack; | 
					
						
							|  |  |  |  |       stack[0].pos = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _trust: | 
					
						
							|  |  |  |  |       /* we should never be here */ | 
					
						
							| 
									
										
										
										
											2005-05-31 02:15:53 +00:00
										 |  |  |  |       Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "found trust in expand_index"); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       labp =  NULL; | 
					
						
							|  |  |  |  |       ipc = NULL; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       /* should we ever be here ? I think not */ | 
					
						
							|  |  |  |  |     case _try_logical: | 
					
						
							|  |  |  |  |     case _retry_logical: | 
					
						
							|  |  |  |  |     case _count_retry_logical: | 
					
						
							|  |  |  |  |     case _profiled_retry_logical: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = ipc->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _trust_logical: | 
					
						
							|  |  |  |  |     case _count_trust_logical: | 
					
						
							|  |  |  |  |     case _profiled_trust_logical: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = ipc->u.OtILl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     case _enter_lu_pred: | 
					
						
							|  |  |  |  |       /* no useful info */ | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       ipc = ipc->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _retry_profiled: | 
					
						
							|  |  |  |  |     case _count_retry: | 
					
						
							|  |  |  |  |       /* no useful info */ | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump: | 
					
						
							|  |  |  |  |       /* just skip for now, but should worry about memory management */ | 
					
						
							|  |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |       /* I don't know how up I will go */ | 
					
						
							|  |  |  |  |       parentcl.si = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _lock_lu: | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     case _procceed: | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-09 14:19:05 +00:00
										 |  |  |  |     case _unlock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _jump_if_var: | 
					
						
							|  |  |  |  |       if (IsVarTerm(Deref(ARG1))) { | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  | 	labp = &(ipc->u.l.l); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.l.l; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |     case _jump_if_nonvar: | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       argno = arg_from_x(ipc->u.xll.x); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       t = Deref(XREGS[argno]); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       i = 0; | 
					
						
							|  |  |  |  |       /* expand_index expects to find the new argument */ | 
					
						
							|  |  |  |  |       if (!IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  | 	argno--; | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | 	labp = &(ipc->u.xll.l1); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.xll.l1; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | 	ipc = NEXTOP(ipc,xll); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type EC */ | 
					
						
							|  |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _index_dbref: | 
					
						
							|  |  |  |  |       t = AbsAppl(s_reg-1); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       sp[-1].extra = t; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       s_reg = NULL; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_blob: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       t = Yap_DoubleP_key(s_reg); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       sp[-1].extra = AbsAppl(s_reg-1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       s_reg = NULL; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     case _index_long: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       t = Yap_IntP_key(s_reg); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |       sp[-1].extra = AbsAppl(s_reg-1); | 
					
						
							|  |  |  |  |       s_reg = NULL; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |     case _user_switch: | 
					
						
							| 
									
										
										
										
											2009-02-20 11:42:48 +00:00
										 |  |  |  |       labp = &(ipc->u.lp.l); | 
					
						
							| 
									
										
										
										
											2009-02-12 21:45:41 +00:00
										 |  |  |  |       ipc = ipc->u.lp.l; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _switch_on_type: | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  |       zero_expand_depth(ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       t = Deref(ARG1); | 
					
						
							|  |  |  |  |       argno = 1; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       i = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.llll.l4); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.llll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	s_reg = RepPair(t); | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.llll.l1); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.llll.l1;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (IsApplTerm(t)) { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l3;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, argno, t, TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l2;	 | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |       parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_list_nl: | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  |       zero_expand_depth(ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       t = Deref(ARG1); | 
					
						
							|  |  |  |  |       argno = 1; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       i = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) {	 | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.ollll.l4); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.ollll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	s_reg = RepPair(t); | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.ollll.l1); | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l1;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  |       } else if (t == TermNil) { | 
					
						
							|  |  |  |  | 	sp = push_stack(sp, 1, t, TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l2;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Term tn; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (IsApplTerm(t)) { | 
					
						
							|  |  |  |  | 	  tn = AbsAppl((CELL *)FunctorOfTerm(t)); | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  tn = t; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	sp = push_stack(sp, argno, tn, TermNil, cint); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.ollll.l3;	 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |       parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_arg_type: | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  |       zero_expand_depth(ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       argno = arg_from_x(ipc->u.xllll.x); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       i = 0; | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       t = Deref(XREGS[argno]); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.xllll.l4); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.xllll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, argno, AbsPair(NULL), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	labp = &(ipc->u.xllll.l1); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.xllll.l1;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (IsApplTerm(t)) { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l3;	 | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, argno, t, TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l2;	 | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |       parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_sub_arg_type: | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       i = ipc->u.sllll.s; | 
					
						
							|  |  |  |  |       t = Deref(s_reg[i]); | 
					
						
							|  |  |  |  |       if (i != arity-1) is_last_arg = FALSE; | 
					
						
							|  |  |  |  |       t = Deref(s_reg[i]); | 
					
						
							|  |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							|  |  |  |  | 	labp = &(ipc->u.sllll.l4); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.sllll.l4; | 
					
						
							|  |  |  |  | 	i++; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, -i-1, AbsPair(NULL), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  | 	labp = &(ipc->u.sllll.l1); | 
					
						
							|  |  |  |  | 	ipc = ipc->u.sllll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	i = 0; | 
					
						
							| 
									
										
										
										
											2012-06-04 16:29:56 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  |       } else if (IsApplTerm(t)) { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, -i-1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	ipc = ipc->u.sllll.l3; | 
					
						
							|  |  |  |  | 	i = 0; | 
					
						
							| 
									
										
										
										
											2012-06-04 18:21:34 +01:00
										 |  |  |  | 	increase_expand_depth(ipc, cint); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2003-09-23 02:19:37 +00:00
										 |  |  |  | 	/* We don't push stack here, instead we go over to next argument
 | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	   sp = push_stack(sp, -i-1, t, cint); | 
					
						
							| 
									
										
										
										
											2003-09-23 02:19:37 +00:00
										 |  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | 	sp = push_stack(sp, -i-1, t, TermNil, cint); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  | 	ipc = ipc->u.sllll.l2;	 | 
					
						
							|  |  |  |  | 	i++; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  |       parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _if_not_then: | 
					
						
							|  |  |  |  |       labp = NULL; | 
					
						
							|  |  |  |  |       ipc = NULL; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |       /* instructions type ollll */ | 
					
						
							|  |  |  |  |     case _switch_on_func: | 
					
						
							|  |  |  |  |     case _if_func: | 
					
						
							|  |  |  |  |     case _go_on_func: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	FuncSwiEntry *fe; | 
					
						
							|  |  |  |  | 	yamop *newpc; | 
					
						
							|  |  |  |  | 	Functor f; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	s_reg = RepAppl(t); | 
					
						
							|  |  |  |  | 	f = (Functor)(*s_reg++); | 
					
						
							|  |  |  |  | 	if (op == _switch_on_func) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f_hash(f,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f(f,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	newpc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	labp = &(fe->u.labp); | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  | 	if (newpc == e_code) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* we found it */ | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  parentcl = code_to_indexcl(ipc->u.sssl.l,is_lu); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = NULL; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  ClausePointer npar = code_to_indexcl(ipc->u.sssl.l,is_lu); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = newpc; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_cons: | 
					
						
							|  |  |  |  |     case _if_cons: | 
					
						
							|  |  |  |  |     case _go_on_cons: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	AtomSwiEntry *ae; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (op == _switch_on_cons) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c_hash(t,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c(t,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	labp = &(ae->u.labp); | 
					
						
							|  |  |  |  | 	if (ae->u.labp == e_code) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* we found it */ | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  parentcl = code_to_indexcl(ipc->u.sssl.l,is_lu); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = NULL; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  ClausePointer npar = code_to_indexcl(ipc->u.sssl.l,is_lu); | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  ipc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2006-03-21 21:30:54 +00:00
										 |  |  |  | 	  parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _expand_index: | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     case _expand_clauses: | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |       if (alt != NULL && ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	op_numbers fop = Yap_op_from_opcode(alt->opc); | 
					
						
							|  |  |  |  | 	if (fop == _enter_lu_pred)  | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	  alt = alt->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       ipc = NULL; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |     case _op_fail: | 
					
						
							|  |  |  |  |       ipc = alt; | 
					
						
							|  |  |  |  |       alt = NULL; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     default: | 
					
						
							|  |  |  |  |       if (alt == NULL) { | 
					
						
							| 
									
										
										
										
											2005-05-31 02:15:53 +00:00
										 |  |  |  | 	Yap_Error(INTERNAL_COMPILER_ERROR,t,"unexpected instruction %d at expand_index ", op); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	labp = NULL; | 
					
						
							|  |  |  |  | 	ipc = NULL; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* backtrack */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	first = alt->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = alt; | 
					
						
							|  |  |  |  | 	alt = NULL; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  |   /* if there was an overflow while generating the code, make sure
 | 
					
						
							|  |  |  |  |      S is still correct */ | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   if (is_lu) { | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     cint->current_cl.lui = parentcl.lui; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-03-21 15:06:36 +00:00
										 |  |  |  |     cint->current_cl.si = parentcl.si; | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  |   if (s_reg != NULL) | 
					
						
							|  |  |  |  |     S = s_reg; | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							|  |  |  |  |   /* handle tabling hack that insertes a failcode, 
 | 
					
						
							|  |  |  |  |      this really corresponds to not having any more clauses */ | 
					
						
							|  |  |  |  |   if (alt == TRUSTFAILCODE) | 
					
						
							|  |  |  |  |     alt = NULL; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (alt == NULL) { | 
					
						
							|  |  |  |  |     /* oops, we are at last clause */ | 
					
						
							|  |  |  |  |     fail_l = (UInt)FAILCODE; | 
					
						
							|  |  |  |  |     clleft = 0; | 
					
						
							|  |  |  |  |     last = ap->cs.p_code.LastClause; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |       op_numbers op = Yap_op_from_opcode(alt->opc); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       /* can we be here */ | 
					
						
							|  |  |  |  | 	if (op >= _retry2 && op <= _retry4) { | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	last = alt->u.l.l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	last = alt->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |       op_numbers op = Yap_op_from_opcode(alt->opc); | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |       if (op == _retry || op == _trust) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	last = alt->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #ifdef TABLING
 | 
					
						
							| 
									
										
										
										
											2005-05-31 04:46:06 +00:00
										 |  |  |  |       } else if (op == _table_retry || op == _table_trust) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	last = PREVOP(alt->u.Otapl.d,Otapl); | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | #endif /* TABLING */
 | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else if (op >= _retry2 && op <= _retry4) { | 
					
						
							|  |  |  |  | 	last = alt->u.l.l; | 
					
						
							| 
									
										
										
										
											2003-09-23 12:41:31 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     fail_l = (UInt)alt; | 
					
						
							|  |  |  |  |     clleft = count_clauses_left(last,ap); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   if (Yap_op_from_opcode((*labp)->opc) == _expand_clauses) { | 
					
						
							|  |  |  |  |     /* ok, we know how many clauses */ | 
					
						
							|  |  |  |  |     yamop *ipc = *labp; | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |     /* check all slots, not just the ones with values */ | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |     COUNT nclauses = ipc->u.sssllp.s1; | 
					
						
							|  |  |  |  |     yamop **clp = (yamop **)NEXTOP(ipc,sssllp); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |     cint->expand_block = ipc; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     if (!cint->cls) { | 
					
						
							|  |  |  |  |       cint->cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses*sizeof(ClauseDef)); | 
					
						
							|  |  |  |  |       if (!cint->cls) { | 
					
						
							|  |  |  |  | 	/* tell how much space we need */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  | 	LOCAL_Error_Size += NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	/* grow stack */ | 
					
						
							|  |  |  |  | 	save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  | 	siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     cint->cls = (ClauseDef *)H; | 
					
						
							|  |  |  |  |     if (cint->cls+2*nclauses > (ClauseDef *)(ASP-4096)) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       /* tell how much space we need (worst case) */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       /* grow stack */ | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,3); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       max = install_log_upd_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       max = install_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     }     | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |     cint->expand_block = NULL; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     if (!cint->cls) { | 
					
						
							|  |  |  |  |       cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); | 
					
						
							|  |  |  |  |       if (!cint->cls) { | 
					
						
							|  |  |  |  | 	/* tell how much space we need */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  | 	LOCAL_Error_Size += NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	/* grow stack */ | 
					
						
							|  |  |  |  | 	save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  | 	siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     cint->cls = (ClauseDef *)H; | 
					
						
							|  |  |  |  |     if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       /* tell how much space we need (worst case) */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef); | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |       siglongjmp(cint->CompilerBotch,3); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       max = install_log_upd_clauses(cint->cls, ap, stack, first, last); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       max = install_clauses(cint->cls, ap, stack, first, last); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  | #if DEBUG_EXPAND
 | 
					
						
							|  |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |       fprintf(stderr,"vsc +"); | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       fprintf(stderr,"vsc "); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     fprintf(stderr,"  : expanding %d out of %d\n", (max-cls)+1,NClauses); | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |   /* don't count last clause if you don't have to */ | 
					
						
							|  |  |  |  |   if (alt && max->Code == last) max--; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   if (max < cint->cls && labp != NULL) { | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |       *labp = FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     return labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							|  |  |  |  |   cint->freep = (char *)H; | 
					
						
							|  |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   cint->freep = (char *)(max+1); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-01-26 12:41:06 +00:00
										 |  |  |  |   cint->CodeStart = cint->BlobsStart = cint->cpc = cint->icpc = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |    | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |   if (!IsVarTerm(sp[-1].val)  && sp > stack) { | 
					
						
							|  |  |  |  |     if (IsAtomOrIntTerm(sp[-1].val)) { | 
					
						
							|  |  |  |  |       if (s_reg == NULL) { /* we have not yet looked into terms */ | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	UInt arity = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	  reinstall_log_upd_clauses(cint->cls, max, ap, stack); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	  reinstall_clauses(cint->cls, max, ap, stack); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	sp--; | 
					
						
							|  |  |  |  | 	while (sp > stack) { | 
					
						
							|  |  |  |  | 	  Term t = sp[-1].val; | 
					
						
							|  |  |  |  | 	  if (IsApplTerm(t)) { | 
					
						
							|  |  |  |  | 	    Functor f = (Functor)RepAppl(t); | 
					
						
							|  |  |  |  | 	    if (!IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |  | 	      arity = ArityOfFunctor(f); | 
					
						
							|  |  |  |  | 	      break; | 
					
						
							|  |  |  |  | 	    } else { | 
					
						
							|  |  |  |  | 	      sp--; | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	  } else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |  | 	    arity = 2; | 
					
						
							|  |  |  |  | 	    break; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    sp--; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	lab = do_compound_index(cint->cls, max, s_reg, cint, i, arity, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else if (IsPairTerm(sp[-1].val) && sp > stack) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       lab = do_compound_index(cint->cls, max, s_reg, cint, i, 2, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       Functor f = (Functor)RepAppl(sp[-1].val); | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       /* we are continuing within a compound term */ | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       if (IsExtensionFunctor(f)) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	lab = do_compound_index(cint->cls, max, s_reg, cint, i, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     if (argno == ap->ArityOfPE) { | 
					
						
							|  |  |  |  |       lab =  | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	do_var_clauses(cint->cls, max, FALSE, cint, isfirstcl, clleft, fail_l, ap->ArityOfPE+1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   if (labp && !(lab & 1)) { | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  |     *labp = (yamop *)lab; /* in case we have a single clause */ | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return labp; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static yamop * | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |   yamop *indx_out, *expand_clauses; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   yamop **labp; | 
					
						
							|  |  |  |  |   int cb; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   struct intermediates cint; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |   cint.blks = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   cint.cls = NULL; | 
					
						
							| 
									
										
										
										
											2009-03-27 14:05:27 +00:00
										 |  |  |  |   cint.code_addr = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:49:25 +01:00
										 |  |  |  |   cint.label_offset = NULL; | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |   if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |     CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     /* grow stack */ | 
					
						
							|  |  |  |  |     recover_from_failed_susp_on_cls(&cint, 0); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+ExtraArgs, ENV, nextop); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else if (cb == 2) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size); | 
					
						
							|  |  |  |  |     if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							|  |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	StaticIndex *cl; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	Yap_kill_iblock((ClauseUnion *)cl,NULL, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00: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->cs.p_code.TrueCodeOfPred = ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));  | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 	ap->OpcodeOfPred = INDEX_OPCODE; | 
					
						
							|  |  |  |  | 	ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));  | 
					
						
							|  |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   } else if (cb == 4) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) { | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |       save_machine_regs(); | 
					
						
							|  |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	StaticIndex *cl; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); | 
					
						
							|  |  |  |  | 	Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |       CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  |       return FAILCODE; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |  restart_index: | 
					
						
							| 
									
										
										
										
											2004-01-29 13:37:10 +00:00
										 |  |  |  |   cint.CodeStart = cint.cpc = cint.BlobsStart = cint.icpc = NIL; | 
					
						
							|  |  |  |  |   cint.CurrentPred = ap; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_ErrorMessage = NULL; | 
					
						
							|  |  |  |  |   LOCAL_Error_Size = 0; | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |   if (P->opc == Yap_opcode(_expand_clauses)) { | 
					
						
							|  |  |  |  |     expand_clauses = P; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     expand_clauses = NULL; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  |     Yap_DebugPlWrite(MkIntegerTerm(worker_id)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,' '); | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'>'); | 
					
						
							|  |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\t'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05: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 13:30:50 +00:00
										 |  |  |  |       Term t = Deref(ARG1); | 
					
						
							|  |  |  |  |       if (IsAtomTerm(t)) { | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(t); | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |       } else if (IsIntegerTerm(t)) { | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = FunctorOfTerm(t); | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       if (ap->ArityOfPE == 0) { | 
					
						
							|  |  |  |  | 	Atom At = (Atom)ap->FunctorOfPred; | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = ap->FunctorOfPred; | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\n'); | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  |     Yap_DebugPlWrite(MkIntegerTerm(worker_id)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,' '); | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   if ((labp = expand_index(&cint)) == NULL) { | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (expand_clauses) { | 
					
						
							|  |  |  |  |       P = FAILCODE; | 
					
						
							|  |  |  |  |       recover_ecls_block(expand_clauses); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  |     return FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-12-01 17:27:42 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   if (*labp == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (expand_clauses) { | 
					
						
							|  |  |  |  |       P = FAILCODE; | 
					
						
							|  |  |  |  |       recover_ecls_block(expand_clauses); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |     return FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-12-01 17:27:42 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |  |   if (GLOBAL_Option['i' - 'a' + 1]) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |     Yap_ShowCode(&cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   /* globals for assembler */ | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |   LOCAL_IPredArity = ap->ArityOfPE; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   if (cint.CodeStart) { | 
					
						
							| 
									
										
										
										
											2010-04-15 11:37:39 +01:00
										 |  |  |  |     if ((indx_out = Yap_assemble(ASSEMBLING_EINDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |       if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { | 
					
						
							|  |  |  |  | 	Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  | 	Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  | 	CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  | 	return FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       goto restart_index; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     /* single case */ | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (expand_clauses) { | 
					
						
							|  |  |  |  |       P = *labp; | 
					
						
							|  |  |  |  |       recover_ecls_block(expand_clauses); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     return *labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-12-01 17:27:42 +00:00
										 |  |  |  |   if (indx_out == NULL) { | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (expand_clauses) { | 
					
						
							|  |  |  |  |       P = FAILCODE; | 
					
						
							|  |  |  |  |       recover_ecls_block(expand_clauses); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |     Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |     CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-12-01 17:27:42 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-09 17:02:24 +01:00
										 |  |  |  |   Yap_ReleaseCMem(&cint); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |  |   CleanCls(&cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   *labp = indx_out; | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     /* add to head of current code children */ | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     LogUpdIndex *ic = cint.current_cl.lui, | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       *nic = ClauseCodeToLogUpdIndex(indx_out); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     if (ic == NULL) | 
					
						
							|  |  |  |  |       ic = (LogUpdIndex *)Yap_find_owner_index((yamop *)labp, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* insert myself in the indexing code chain */  | 
					
						
							|  |  |  |  |     nic->SiblingIndex = ic->ChildIndex; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     nic->PrevSiblingIndex = NULL; | 
					
						
							|  |  |  |  |     if (ic->ChildIndex) { | 
					
						
							|  |  |  |  |       ic->ChildIndex->PrevSiblingIndex = nic; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     nic->ParentIndex = ic; | 
					
						
							| 
									
										
										
										
											2003-10-31 00:20:52 +00:00
										 |  |  |  |     nic->ClFlags &= ~SwitchRootMask; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     ic->ChildIndex = nic; | 
					
						
							|  |  |  |  |     ic->ClRefCount++; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     /* add to head of current code children */ | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     StaticIndex *ic = cint.current_cl.si, | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       *nic = ClauseCodeToStaticIndex(indx_out); | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |  |     if (ic == NULL) | 
					
						
							|  |  |  |  |       ic = (StaticIndex *)Yap_find_owner_index((yamop *)labp, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* insert myself in the indexing code chain */  | 
					
						
							|  |  |  |  |     nic->SiblingIndex = ic->ChildIndex; | 
					
						
							|  |  |  |  |     ic->ChildIndex = nic; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |   if (expand_clauses) { | 
					
						
							|  |  |  |  |     P = indx_out; | 
					
						
							|  |  |  |  |     recover_ecls_block(expand_clauses); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return indx_out; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | yamop * | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  | Yap_ExpandIndex(PredEntry *ap, UInt nargs) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |  |   return ExpandIndex(ap, nargs, CP PASS_REGS); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static path_stack_entry * | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | push_path(path_stack_entry *sp, yamop **pipc, ClauseDef *clp, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) { | 
					
						
							| 
									
										
										
										
											2005-12-23 00:20:14 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,4);     | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   sp->flag = pc_entry; | 
					
						
							|  |  |  |  |   sp->u.pce.pi_pc = pipc; | 
					
						
							|  |  |  |  |   sp->u.pce.code = clp->Code; | 
					
						
							|  |  |  |  |   sp->u.pce.current_code = clp->CurrentCode; | 
					
						
							|  |  |  |  |   sp->u.pce.work_pc = clp->u.WorkPC; | 
					
						
							|  |  |  |  |   sp->u.pce.tag = clp->Tag; | 
					
						
							|  |  |  |  |   return sp+1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 		  | 
					
						
							|  |  |  |  | static path_stack_entry * | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | fetch_new_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) { | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,4);     | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* add current position */ | 
					
						
							|  |  |  |  |   sp->flag = block_entry; | 
					
						
							|  |  |  |  |   sp->u.cle.entry_code = pipc; | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     sp->u.cle.block = (ClauseUnion *)ClauseCodeToLogUpdIndex(*pipc); | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     sp->u.cle.block = (ClauseUnion *)ClauseCodeToStaticIndex(*pipc); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return sp+1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 		  | 
					
						
							|  |  |  |  | static path_stack_entry * | 
					
						
							|  |  |  |  | init_block_stack(path_stack_entry *sp, yamop *ipc, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   /* add current position */ | 
					
						
							|  |  |  |  |    | 
					
						
							|  |  |  |  |   sp->flag = block_entry; | 
					
						
							|  |  |  |  |   sp->u.cle.entry_code = NULL; | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     sp->u.cle.block = (ClauseUnion *)ClauseCodeToLogUpdIndex(ipc); | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     sp->u.cle.block = (ClauseUnion *)ClauseCodeToStaticIndex(ipc); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return sp+1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static path_stack_entry  * | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | cross_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   yamop *ipc = *pipc; | 
					
						
							|  |  |  |  |   path_stack_entry *tsp = sp; | 
					
						
							|  |  |  |  |   ClauseUnion *block; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   do { | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     UInt bsize; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     while ((--tsp)->flag != block_entry); | 
					
						
							|  |  |  |  |     block = tsp->u.cle.block; | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     if (block->lui.ClFlags & LogUpdMask) | 
					
						
							|  |  |  |  |       bsize = block->lui.ClSize; | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |       bsize = block->si.ClSize; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (ipc > (yamop *)block && | 
					
						
							| 
									
										
										
										
											2006-04-27 17:04:08 +00:00
										 |  |  |  | 	ipc < (yamop *)((CODEADDR)block + bsize)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       path_stack_entry *nsp = tsp+1; | 
					
						
							|  |  |  |  |       for (;tsp<sp;tsp++) { | 
					
						
							|  |  |  |  | 	if (tsp->flag == pc_entry) { | 
					
						
							|  |  |  |  | 	  if (nsp != tsp) { | 
					
						
							|  |  |  |  | 	    nsp->flag = pc_entry; | 
					
						
							|  |  |  |  | 	    nsp->u.pce.pi_pc = tsp->u.pce.pi_pc; | 
					
						
							|  |  |  |  | 	    nsp->u.pce.code = tsp->u.pce.code; | 
					
						
							|  |  |  |  | 	    nsp->u.pce.current_code = tsp->u.pce.current_code; | 
					
						
							|  |  |  |  | 	    nsp->u.pce.work_pc = tsp->u.pce.work_pc; | 
					
						
							|  |  |  |  | 	    nsp->u.pce.tag = tsp->u.pce.tag; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	  nsp++; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       return nsp; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } while (tsp->u.cle.entry_code != NULL); | 
					
						
							|  |  |  |  |   /* moved to a new block */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |   return fetch_new_block(sp, pipc, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static yamop * | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | pop_path(path_stack_entry **spp, ClauseDef *clp, PredEntry *ap, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   path_stack_entry *sp = *spp; | 
					
						
							|  |  |  |  |   yamop *nipc; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while ((--sp)->flag != pc_entry); | 
					
						
							|  |  |  |  |   *spp = sp; | 
					
						
							|  |  |  |  |   clp->Code = sp->u.pce.code; | 
					
						
							|  |  |  |  |   clp->CurrentCode = sp->u.pce.current_code; | 
					
						
							|  |  |  |  |   clp->u.WorkPC = sp->u.pce.work_pc; | 
					
						
							|  |  |  |  |   clp->Tag = sp->u.pce.tag; | 
					
						
							|  |  |  |  |   if (sp->u.pce.pi_pc == NULL) { | 
					
						
							|  |  |  |  |     *spp = sp; | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   nipc = *(sp->u.pce.pi_pc); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |   *spp = cross_block(sp, sp->u.pce.pi_pc, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return nipc; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | table_fe_overflow(yamop *pc, Functor f) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   if (pc->u.sssl.s <= MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* we cannot expand otherwise */ | 
					
						
							|  |  |  |  |     COUNT i; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     FuncSwiEntry *csw = (FuncSwiEntry *)pc->u.sssl.l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     for (i=0; i < pc->u.sssl.s; i++,csw++) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (csw->Tag == f) return FALSE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     COUNT free = pc->u.sssl.s-pc->u.sssl.e; | 
					
						
							|  |  |  |  |     return (!free || pc->u.sssl.s/free > 4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | table_ae_overflow(yamop *pc, Term at) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   if (pc->u.sssl.s <= MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* check if we are already there */ | 
					
						
							|  |  |  |  |     COUNT i; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     AtomSwiEntry *csw = (AtomSwiEntry *)pc->u.sssl.l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     for (i=0; i < pc->u.sssl.s; i++,csw++) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (csw->Tag == at) return FALSE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     COUNT free = pc->u.sssl.s-pc->u.sssl.e; | 
					
						
							|  |  |  |  |     return (!free || pc->u.sssl.s/free > 4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     LogUpdIndex | 
					
						
							|  |  |  |  |       *cl = ClauseCodeToLogUpdIndex(cod), | 
					
						
							|  |  |  |  |       *ncl = ClauseCodeToLogUpdIndex(ncod), | 
					
						
							|  |  |  |  |       *c = parent_block->lui.ChildIndex; | 
					
						
							|  |  |  |  |     ncl->SiblingIndex = cl->SiblingIndex; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     ncl->PrevSiblingIndex = cl->PrevSiblingIndex; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     ncl->ClRefCount = cl->ClRefCount; | 
					
						
							|  |  |  |  |     ncl->ChildIndex = cl->ChildIndex; | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     ncl->ParentIndex = cl->ParentIndex; | 
					
						
							|  |  |  |  |     ncl->ClPred = cl->ClPred; | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  |  |     //    INIT_LOCK(ncl->ClLock);
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (c == cl) { | 
					
						
							|  |  |  |  |       parent_block->lui.ChildIndex = ncl; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |       if (cl->PrevSiblingIndex) | 
					
						
							|  |  |  |  | 	cl->PrevSiblingIndex->SiblingIndex = ncl; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (cl->SiblingIndex) { | 
					
						
							|  |  |  |  |       cl->SiblingIndex->PrevSiblingIndex = ncl; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     c = cl->ChildIndex; | 
					
						
							|  |  |  |  |     while (c != NULL) { | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |       c->ParentIndex = ncl; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       c = c->SiblingIndex; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_InformOfRemoval(cl); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     Yap_LUIndexSpace_SW -= cl->ClSize; | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  |     Yap_FreeCodeSpace((char *)cl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     StaticIndex | 
					
						
							|  |  |  |  |       *cl = ClauseCodeToStaticIndex(cod), | 
					
						
							|  |  |  |  |       *ncl = ClauseCodeToStaticIndex(ncod), | 
					
						
							|  |  |  |  |       *c = parent_block->si.ChildIndex; | 
					
						
							|  |  |  |  |     ncl->SiblingIndex = cl->SiblingIndex; | 
					
						
							| 
									
										
										
										
											2005-12-17 03:25:39 +00:00
										 |  |  |  |     ncl->ClPred = cl->ClPred; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     if (c == cl) { | 
					
						
							|  |  |  |  |       parent_block->si.ChildIndex = ncl; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       while (c->SiblingIndex != cl) { | 
					
						
							|  |  |  |  | 	c = c->SiblingIndex; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       c->SiblingIndex = ncl; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |  |     Yap_InformOfRemoval(cl); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     Yap_IndexSpace_SW -= cl->ClSize; | 
					
						
							| 
									
										
										
										
											2005-07-05 18:32:32 +00:00
										 |  |  |  |     Yap_FreeCodeSpace((char *)cl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 		  | 
					
						
							|  |  |  |  | static AtomSwiEntry * | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | expand_ctable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Term at) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   int n = pc->u.sssl.s, i, i0 = n; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   UInt fail_l = Zero; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   AtomSwiEntry *old_ae = (AtomSwiEntry *)(pc->u.sssl.l), *target; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							|  |  |  |  |     AtomSwiEntry *tmp = old_ae; | 
					
						
							|  |  |  |  |     int i; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |     n = 1; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     for (i = 0; i < pc->u.sssl.s; i++,tmp++) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (tmp->Tag != Zero) n++; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       else fail_l = tmp->u.Label; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     fail_l = old_ae[n].u.Label; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     n++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							|  |  |  |  |     int cases = MIN_HASH_ENTRIES, i, n0; | 
					
						
							|  |  |  |  |     n0 = n+1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n0) cases *= 2; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     if (cases == pc->u.sssl.s) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       return fetch_centry(old_ae, at, n-1, n); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     /* initialise */ | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (AtomSwiEntry *)emit_switch_space(cases, sizeof(AtomSwiEntry), cint, 0); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     pc->opc = Yap_opcode(_switch_on_cons); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     pc->u.sssl.s = cases; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     for (i=0; i<cases; i++) { | 
					
						
							|  |  |  |  |       target[i].Tag = Zero; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.Label = fail_l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     pc->opc = Yap_opcode(_if_cons); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     pc->u.sssl.s = n; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (AtomSwiEntry *)emit_switch_space(n+1, sizeof(AtomSwiEntry), cint, 0); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     target[n].Tag = Zero; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     target[n].u.Label = fail_l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   for (i = 0; i < i0; i++,old_ae++) { | 
					
						
							|  |  |  |  |     Term tag = old_ae->Tag; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (tag != Zero) { | 
					
						
							|  |  |  |  |       AtomSwiEntry *ics = fetch_centry(target, tag, i, n); | 
					
						
							|  |  |  |  |       ics->Tag = tag; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       ics->u.Label = old_ae->u.Label;     | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   /* support for threads */ | 
					
						
							|  |  |  |  |   if (blk) | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     replace_index_block(blk, pc->u.sssl.l, (yamop *)target, ap); | 
					
						
							|  |  |  |  |   pc->u.sssl.l = (yamop *)target; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return fetch_centry(target, at, n-1, n); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static FuncSwiEntry * | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | expand_ftable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Functor f) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   int n = pc->u.sssl.s, i, i0 = n; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   UInt fail_l =  Zero; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   FuncSwiEntry *old_fe = (FuncSwiEntry *)(pc->u.sssl.l), *target; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							|  |  |  |  |     FuncSwiEntry *tmp = old_fe; | 
					
						
							|  |  |  |  |     int i; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |     n = 1; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     for (i = 0; i < pc->u.sssl.s; i++,tmp++) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (tmp->Tag != Zero) n++; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       else fail_l = tmp->u.Label; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     fail_l = old_fe[n].u.Label; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     n++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							|  |  |  |  |     int cases = MIN_HASH_ENTRIES, i, n0; | 
					
						
							|  |  |  |  |     n0 = n+1+n/4; | 
					
						
							|  |  |  |  |     while (cases < n0) cases *= 2; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     if (cases == pc->u.sssl.s) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       return fetch_fentry(old_fe, f, n-1, n); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     pc->opc = Yap_opcode(_switch_on_func); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     pc->u.sssl.s = cases; | 
					
						
							|  |  |  |  |     pc->u.sssl.e = n; | 
					
						
							|  |  |  |  |     pc->u.sssl.w = 0; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     /* initialise */ | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (FuncSwiEntry *)emit_switch_space(cases, sizeof(FuncSwiEntry), cint, FuncSwitchMask); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     for (i=0; i<cases; i++) { | 
					
						
							|  |  |  |  |       target[i].Tag = NULL; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       target[i].u.Label = fail_l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     pc->opc = Yap_opcode(_if_func); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     pc->u.sssl.s = n; | 
					
						
							|  |  |  |  |     pc->u.sssl.e = n; | 
					
						
							|  |  |  |  |     pc->u.sssl.w = 0; | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     target = (FuncSwiEntry *)emit_switch_space(n+1, sizeof(FuncSwiEntry), cint, FuncSwitchMask); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     target[n].Tag = Zero; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |     target[n].u.Label = fail_l; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   for (i = 0; i < i0; i++,old_fe++) { | 
					
						
							|  |  |  |  |     Functor f = old_fe->Tag; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (f != NULL) { | 
					
						
							|  |  |  |  |       FuncSwiEntry *ifs = fetch_fentry(target, f, i, n); | 
					
						
							|  |  |  |  |       ifs->Tag = old_fe->Tag; | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |       ifs->u.Label = old_fe->u.Label;     | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   replace_index_block(blk, pc->u.sssl.l, (yamop *)target, ap); | 
					
						
							|  |  |  |  |   pc->u.sssl.l = (yamop *)target; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   return fetch_fentry(target, f, n-1, n); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | clean_ref_to_clause(LogUpdClause *tgl) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   tgl->ClRefCount--; | 
					
						
							|  |  |  |  |   if ((tgl->ClFlags & ErasedMask) && | 
					
						
							|  |  |  |  |       !(tgl->ClRefCount) && | 
					
						
							|  |  |  |  |       !(tgl->ClFlags & InUseMask)) { | 
					
						
							|  |  |  |  |     /* last ref to the clause */ | 
					
						
							|  |  |  |  |     Yap_ErLogUpdCl(tgl); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | static ClauseUnion * | 
					
						
							|  |  |  |  | current_block(path_stack_entry *sp) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |   return sp->u.cle.block; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static path_stack_entry * | 
					
						
							|  |  |  |  | kill_block(path_stack_entry *sp, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |   if (sp->u.cle.entry_code == NULL) { | 
					
						
							|  |  |  |  |     Yap_kill_iblock(sp->u.cle.block, NULL, ap); | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     path_stack_entry *nsp = sp; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |     while ((--nsp)->flag != block_entry); | 
					
						
							|  |  |  |  |     Yap_kill_iblock(sp->u.cle.block, nsp->u.cle.block, ap); | 
					
						
							|  |  |  |  |     *sp->u.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static LogUpdClause * | 
					
						
							|  |  |  |  | find_last_clause(yamop *start) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   while (start->u.OtaLl.d->ClFlags & ErasedMask)  | 
					
						
							|  |  |  |  |     start = start->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   /* this should be the available clause */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   return start->u.OtaLl.d; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | remove_clause_from_index(yamop *header, LogUpdClause *cl) | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   yamop **prevp = &(header->u.Illss.l1); | 
					
						
							|  |  |  |  |   yamop *curp = header->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   if (curp->u.OtaLl.d == cl) { | 
					
						
							|  |  |  |  |     yamop *newp = curp->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     newp->opc = curp->opc; | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     *prevp = newp; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  |  |     yamop *ocurp = NULL, *ocurp0 = curp; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     while (curp->u.OtaLl.d != cl) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       ocurp = curp; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       curp = curp->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     /* in case we were the last */ | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |     if (curp == header->u.Illss.l2) | 
					
						
							|  |  |  |  |       header->u.Illss.l2 = ocurp; | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |     if (ocurp != ocurp0) | 
					
						
							|  |  |  |  |       ocurp->opc = curp->opc; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     ocurp->u.OtILl.n = curp->u.OtaLl.n; | 
					
						
							|  |  |  |  |     ocurp->u.OtILl.block = curp->u.OtILl.block; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   header->u.Illss.e--; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |   Yap_DirtyCps--; | 
					
						
							|  |  |  |  |   Yap_FreedCps++; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   clean_ref_to_clause(cl); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtILl); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   Yap_FreeCodeSpace((ADDR)curp); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | remove_dirty_clauses_from_index(yamop *header) | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   LogUpdClause *cl; | 
					
						
							|  |  |  |  |   yamop *previouscurp; | 
					
						
							|  |  |  |  |   OPCODE endop = Yap_opcode(_trust_logical); | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   yamop **prevp= &(header->u.Illss.l1), *curp = header->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  |   OPCODE startopc = curp->opc; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   PredEntry *ap = curp->u.OtaLl.d->ClPred; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (ap->PredFlags & CountPredFlag) | 
					
						
							|  |  |  |  |     endop = Yap_opcode(_count_trust_logical); | 
					
						
							|  |  |  |  |   else if (ap->PredFlags & ProfiledPredFlag) | 
					
						
							|  |  |  |  |     endop = Yap_opcode(_profiled_trust_logical); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   while ((cl = curp->u.OtaLl.d)->ClFlags & ErasedMask) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     yamop *ocurp = curp; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |     header->u.Illss.e--; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |     Yap_DirtyCps--; | 
					
						
							|  |  |  |  |     Yap_FreedCps++; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     clean_ref_to_clause(cl); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     curp = curp->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2008-09-14 05:11:51 +01:00
										 |  |  |  |     Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtaLl); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     Yap_FreeCodeSpace((ADDR)ocurp); | 
					
						
							|  |  |  |  |   }  | 
					
						
							|  |  |  |  |   *prevp = curp; | 
					
						
							|  |  |  |  |   curp->opc = startopc; | 
					
						
							|  |  |  |  |   if (curp->opc == endop) | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   if (!header->u.Illss.e) | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   previouscurp = curp; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   curp = curp->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   while (TRUE) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     if ((cl = curp->u.OtaLl.d)->ClFlags & ErasedMask) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       yamop *ocurp = curp; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       header->u.Illss.e--; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |       Yap_DirtyCps--; | 
					
						
							|  |  |  |  |       Yap_FreedCps++; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       clean_ref_to_clause(cl); | 
					
						
							|  |  |  |  |       if (curp->opc == endop) { | 
					
						
							|  |  |  |  | 	previouscurp->opc = endop; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	previouscurp->u.OtILl.block = curp->u.OtILl.block; | 
					
						
							|  |  |  |  | 	previouscurp->u.OtILl.n = NULL; | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	header->u.Illss.l2 = previouscurp; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtILl); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	Yap_FreeCodeSpace((ADDR)curp); | 
					
						
							|  |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       previouscurp->u.OtaLl.n = curp->u.OtaLl.n; | 
					
						
							|  |  |  |  |       curp = curp->u.OtaLl.n; | 
					
						
							|  |  |  |  |       Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtaLl); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       Yap_FreeCodeSpace((ADDR)ocurp); | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       if (!header->u.Illss.e) | 
					
						
							|  |  |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     } else { | 
					
						
							|  |  |  |  |       previouscurp = curp; | 
					
						
							|  |  |  |  |       if (curp->opc == endop) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	curp->u.OtILl.n = NULL; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       curp = curp->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | static path_stack_entry * | 
					
						
							| 
									
										
										
										
											2004-06-17 22:07:23 +00:00
										 |  |  |  | kill_clause(yamop *ipc, yamop *bg, yamop *lt, path_stack_entry *sp0, PredEntry *ap) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   LogUpdIndex *blk; | 
					
						
							|  |  |  |  |   yamop *start; | 
					
						
							|  |  |  |  |   op_numbers op0; | 
					
						
							| 
									
										
										
										
											2004-06-17 22:07:23 +00:00
										 |  |  |  |   path_stack_entry *sp = sp0; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |   blk = (LogUpdIndex *)(sp->u.cle.block); | 
					
						
							|  |  |  |  |   start = blk->ClCode; | 
					
						
							|  |  |  |  |   op0 = Yap_op_from_opcode(start->opc); | 
					
						
							| 
									
										
										
										
											2006-10-16 17:12:48 +00:00
										 |  |  |  |   while (op0 == _lock_lu) { | 
					
						
							|  |  |  |  |     start = NEXTOP(start, p); | 
					
						
							|  |  |  |  |     op0 = Yap_op_from_opcode(start->opc); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |   while (op0 == _jump_if_nonvar) { | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |     start = NEXTOP(start, xll); | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |     op0 = Yap_op_from_opcode(start->opc); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (op0 != _enter_lu_pred) { | 
					
						
							|  |  |  |  |     /* static code */ | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     return kill_block(sp+1, ap); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  |   /* weird case ????? */ | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   if (!start->u.Illss.s){ | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     /* ERROR */ | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |     Yap_Error(INTERNAL_ERROR, TermNil, "Illss.s == 0 %p", ipc); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     return sp; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |   if (start->u.Illss.s == 1) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     /* we need to discover which clause is left and then die */ | 
					
						
							|  |  |  |  |     path_stack_entry *nsp; | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |     LogUpdClause *tgl = find_last_clause(start->u.Illss.l1); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     nsp = sp; | 
					
						
							|  |  |  |  |     while ((--nsp)->flag != block_entry); | 
					
						
							|  |  |  |  |     /* make us point straight at clause */ | 
					
						
							|  |  |  |  |     *sp->u.cle.entry_code = tgl->ClCode; | 
					
						
							|  |  |  |  |     Yap_kill_iblock(sp->u.cle.block, nsp->u.cle.block, ap); | 
					
						
							|  |  |  |  |     return sp; | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     if ( | 
					
						
							| 
									
										
										
										
											2011-04-14 18:51:11 +01:00
										 |  |  |  | #if MULTIPLE_STACKS
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	blk->ClRefCount == 0 | 
					
						
							|  |  |  |  | #else
 | 
					
						
							|  |  |  |  | 	!(blk->ClFlags & InUseMask) | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  |       remove_clause_from_index(start, | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 			       ClauseCodeToLogUpdClause(bg)); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       blk->ClFlags |= DirtyMask; | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     return sp; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static path_stack_entry * | 
					
						
							|  |  |  |  | expanda_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, yamop *alt, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |   Yap_kill_iblock(sp->u.cle.block, NULL, ap); | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static path_stack_entry * | 
					
						
							|  |  |  |  | expandz_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, yamop *alt, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |   Yap_kill_iblock(sp->u.cle.block, NULL, ap); | 
					
						
							|  |  |  |  |   return sp; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static LogUpdClause * | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | lu_clause(yamop *ipc, PredEntry *ap) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (ipc == FAILCODE) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |   if (ipc == (yamop *)(&(ap->OpcodeOfPred))) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							|  |  |  |  |   return ClauseCodeToLogUpdClause(ipc); | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static StaticClause * | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | find_static_clause(PredEntry *ap, yamop *ipc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   StaticClause *cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause); | 
					
						
							|  |  |  |  |   while (ipc < cl->ClCode || | 
					
						
							|  |  |  |  | 	 ipc > (yamop *)((char *)cl+ cl->ClSize)) { | 
					
						
							|  |  |  |  |     cl = cl->ClNext; | 
					
						
							|  |  |  |  |     if (!cl) | 
					
						
							|  |  |  |  |       return NULL; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return cl; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static StaticClause * | 
					
						
							|  |  |  |  | static_clause(yamop *ipc, PredEntry *ap, int trust) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-03-26 15:18:43 +00:00
										 |  |  |  |   CELL *p; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (ipc == FAILCODE) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |   if (ipc == (yamop*)(&(ap->OpcodeOfPred))) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (ap->PredFlags & MegaClausePredFlag) | 
					
						
							|  |  |  |  |     return (StaticClause *)ipc; | 
					
						
							| 
									
										
										
										
											2007-03-26 15:18:43 +00:00
										 |  |  |  |   if (ap->PredFlags & TabledPredFlag) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |     ipc = PREVOP(ipc,Otapl);  | 
					
						
							| 
									
										
										
										
											2007-03-26 15:18:43 +00:00
										 |  |  |  |   p = (CELL *)ipc; | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  |   if (trust) { | 
					
						
							|  |  |  |  |     return ClauseCodeToStaticClause(p);  | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  |     UInt j; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* unbound call, so we cannot optimise instructions */ | 
					
						
							|  |  |  |  |     switch (op) { | 
					
						
							|  |  |  |  |     case _p_db_ref_x: | 
					
						
							|  |  |  |  |     case _p_float_x: | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       j = Yap_regnotoreg(ipc->u.xl.x); | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _get_list: | 
					
						
							|  |  |  |  |       j = Yap_regnotoreg(ipc->u.x.x); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _get_atom: | 
					
						
							|  |  |  |  |       j = Yap_regnotoreg(ipc->u.xc.x); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _get_float: | 
					
						
							|  |  |  |  |       j = Yap_regnotoreg(ipc->u.xd.x); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _get_struct: | 
					
						
							|  |  |  |  |       j = Yap_regnotoreg(ipc->u.xd.x); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _get_2atoms: | 
					
						
							|  |  |  |  |     case _get_3atoms: | 
					
						
							|  |  |  |  |     case _get_4atoms: | 
					
						
							|  |  |  |  |     case _get_5atoms: | 
					
						
							|  |  |  |  |     case _get_6atoms: | 
					
						
							|  |  |  |  |       return ClauseCodeToStaticClause(p); | 
					
						
							|  |  |  |  |     default: | 
					
						
							|  |  |  |  |       return find_static_clause(ap, ipc); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  |     if (j == 1) /* must be the first instruction */ | 
					
						
							|  |  |  |  |       return ClauseCodeToStaticClause(p); | 
					
						
							|  |  |  |  |     return find_static_clause(ap, ipc); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static StaticClause * | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | simple_static_clause(yamop *ipc, PredEntry *ap) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |   if (ipc == (yamop*)(&(ap->OpcodeOfPred))) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (ipc == FAILCODE) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   return ClauseCodeToStaticClause(ipc); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | /* this code should be called when we jumped to clauses */ | 
					
						
							|  |  |  |  | static path_stack_entry * | 
					
						
							|  |  |  |  | kill_unsafe_block(path_stack_entry *sp, op_numbers op, PredEntry *ap, int first, int remove, ClauseDef *cls) | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   yamop *ipc; | 
					
						
							|  |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							| 
									
										
										
										
											2011-02-15 20:24:48 +00:00
										 |  |  |  |   if (sp->u.cle.entry_code == NULL) { | 
					
						
							|  |  |  |  |     /* we have reached the top */ | 
					
						
							|  |  |  |  |     Yap_RemoveIndexation(ap); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     return sp; | 
					
						
							| 
									
										
										
										
											2011-02-15 20:24:48 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   ipc = *sp->u.cle.entry_code; | 
					
						
							|  |  |  |  |   if (Yap_op_from_opcode(ipc->opc) == op) { | 
					
						
							|  |  |  |  |     /* the new block was the current clause */ | 
					
						
							|  |  |  |  |     ClauseDef cld[2]; | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     if (remove) { | 
					
						
							|  |  |  |  |       *sp->u.cle.entry_code = FAILCODE; | 
					
						
							|  |  |  |  |       return sp; | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       struct intermediates intrs; | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |       LogUpdClause *lc = lu_clause(ipc, ap); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       if (first) { | 
					
						
							|  |  |  |  | 	cld[0].Code = cls[0].Code; | 
					
						
							|  |  |  |  | 	cld[1].Code = lc->ClCode; | 
					
						
							| 
									
										
										
										
											2004-10-04 18:56:20 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	cld[0].Code = lc->ClCode; | 
					
						
							|  |  |  |  | 	cld[1].Code = cls[0].Code; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       intrs.expand_block = NULL; | 
					
						
							|  |  |  |  |       *sp->u.cle.entry_code = (yamop *)suspend_indexing(cld, cld+1, ap, &intrs); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       /* static predicate, shouldn't do much, just suspend the code here */ | 
					
						
							|  |  |  |  |       *sp->u.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); | 
					
						
							|  |  |  |  |       return sp; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return sp; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   /* we didn't have protection, should kill now */ | 
					
						
							|  |  |  |  |   return kill_block(sp+1, ap); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | static int | 
					
						
							|  |  |  |  | compacta_expand_clauses(yamop *ipc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   /* expand clauses so that you have a hole at the beginning */ | 
					
						
							|  |  |  |  |   /* we know that there is at least one element here */ | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   yamop **start = (yamop **)(NEXTOP(ipc,sssllp)); | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |   yamop **ptr, **end; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   ptr = end = start+ipc->u.sssllp.s1; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 20:04:17 +00:00
										 |  |  |  |   while (ptr > start) { | 
					
						
							|  |  |  |  |     yamop *next = *--ptr; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     if (next) *--end = next; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-05-31 20:04:17 +00:00
										 |  |  |  |   if (ptr != end) { | 
					
						
							|  |  |  |  |     while (end > start) { | 
					
						
							|  |  |  |  |       *--end = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | compactz_expand_clauses(yamop *ipc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   /* expand clauses so that you have a hole at the beginning */ | 
					
						
							|  |  |  |  |   /* we know that there is at least one element here */ | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   yamop **start = (yamop **)(NEXTOP(ipc,sssllp)); | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |   yamop **ptr, **end; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   end = start+ipc->u.sssllp.s1; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |   ptr = start; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while (ptr < end) { | 
					
						
							|  |  |  |  |     yamop *next = *ptr++; | 
					
						
							|  |  |  |  |     if (next) *start++ = next; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-05-31 20:04:17 +00:00
										 |  |  |  |   /* reset empty slots at end */ | 
					
						
							|  |  |  |  |   if (start != end) { | 
					
						
							|  |  |  |  |     while (start < end) { | 
					
						
							|  |  |  |  |       *start++ = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | /* this code should be called when we jumped to clauses */ | 
					
						
							|  |  |  |  | static yamop * | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | add_to_expand_clauses(path_stack_entry **spp, yamop *ipc, ClauseDef *cls, PredEntry *ap, int first, struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   path_stack_entry *sp = *spp; | 
					
						
							| 
									
										
										
										
											2005-08-17 18:48:35 +00:00
										 |  |  |  |   yamop **clar; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (first) { | 
					
						
							| 
									
										
										
										
											2005-08-17 18:48:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     do { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       clar = (yamop **)NEXTOP(ipc,sssllp); | 
					
						
							| 
									
										
										
										
											2005-08-17 18:48:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |       if (*clar == NULL || clar[0] == cls->Code) { | 
					
						
							|  |  |  |  | 	while (*clar == NULL) clar++; | 
					
						
							|  |  |  |  | 	if (clar[0] != cls->Code) { | 
					
						
							|  |  |  |  | 	  clar[-1] = cls->Code; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	  ipc->u.sssllp.s2++; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	return pop_path(spp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     } while (compacta_expand_clauses(ipc)); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     do { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       clar = (yamop **)NEXTOP(ipc,sssllp) + ipc->u.sssllp.s1; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |       if (clar[-1] == NULL  || clar[-1] == cls->Code) { | 
					
						
							|  |  |  |  | 	while (*--clar == NULL); | 
					
						
							|  |  |  |  | 	if (clar[0] != cls->Code) { | 
					
						
							|  |  |  |  | 	  clar[1] = cls->Code; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  | 	  ipc->u.sssllp.s2++; | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	return pop_path(spp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2005-05-31 19:42:28 +00:00
										 |  |  |  |     } while (compactz_expand_clauses(ipc)); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-27 15:03:43 +00:00
										 |  |  |  |   while ((--sp)->flag != block_entry); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   if (sp->u.cle.entry_code) { | 
					
						
							|  |  |  |  |     *sp->u.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |   recover_ecls_block(ipc); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |   return pop_path(spp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /* this code should be called when we jumped to clauses */ | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | nullify_expand_clause(yamop *ipc, path_stack_entry *sp, ClauseDef *cls) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   yamop **st = (yamop **)NEXTOP(ipc,sssllp); | 
					
						
							|  |  |  |  |   yamop **max = st+ipc->u.sssllp.s1; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-22 03:24:17 +00:00
										 |  |  |  |   /* make sure we get rid of the reference */ | 
					
						
							|  |  |  |  |   while (st < max) { | 
					
						
							|  |  |  |  |     if (*st && *st == cls->Code) { | 
					
						
							|  |  |  |  |       *st = NULL; | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |       ipc->u.sssllp.s2--; | 
					
						
							| 
									
										
										
										
											2004-04-22 03:24:17 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     st++; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   /* if the block has a single element */ | 
					
						
							| 
									
										
										
										
											2008-08-21 13:38:25 +01:00
										 |  |  |  |   if (ipc->u.sssllp.s2 == 1) { | 
					
						
							|  |  |  |  |     yamop **st = (yamop **)NEXTOP(ipc,sssllp); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |     while (TRUE) { | 
					
						
							|  |  |  |  |       if (*st && *st != cls->Code) { | 
					
						
							| 
									
										
										
										
											2004-04-22 03:24:17 +00:00
										 |  |  |  | 	*sp->u.cle.entry_code = *st; | 
					
						
							|  |  |  |  | 	recover_ecls_block(ipc); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       st++; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | static yamop * | 
					
						
							|  |  |  |  | add_try(PredEntry *ap, ClauseDef *cls, yamop *next, struct intermediates *cint) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   yamop *newcp; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   UInt size = (UInt)NEXTOP((yamop *)NULL,OtaLl); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if ((newcp = (yamop *)Yap_AllocCodeSpace(size)) == NULL) { | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     /* OOOPS, got in trouble, must do a siglongjmp and recover space */ | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   Yap_LUIndexSpace_CP += size; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |   Yap_NewCps++; | 
					
						
							|  |  |  |  |   Yap_LiveCps++; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   newcp->opc = Yap_opcode(_try_logical); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   newcp->u.OtaLl.s = ap->ArityOfPE; | 
					
						
							|  |  |  |  |   newcp->u.OtaLl.n = next; | 
					
						
							|  |  |  |  |   newcp->u.OtaLl.d = lcl; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   lcl->ClRefCount++; | 
					
						
							|  |  |  |  |   return newcp; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static yamop * | 
					
						
							|  |  |  |  | add_trust(LogUpdIndex *icl, ClauseDef *cls, struct intermediates *cint) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   yamop *newcp; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   UInt size = (UInt)NEXTOP((yamop *)NULL,OtILl); | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   PredEntry *ap =  lcl->ClPred; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if ((newcp = (yamop *)Yap_AllocCodeSpace(size)) == NULL) { | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     /* OOOPS, got in trouble, must do a siglongjmp and recover space */ | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |     siglongjmp(cint->CompilerBotch,2); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-06 18:35:05 +00:00
										 |  |  |  |   Yap_LUIndexSpace_CP += size; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |   Yap_NewCps++; | 
					
						
							|  |  |  |  |   Yap_LiveCps++; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   if (ap->PredFlags & CountPredFlag) | 
					
						
							|  |  |  |  |     newcp->opc = Yap_opcode(_count_trust_logical); | 
					
						
							|  |  |  |  |   else if (ap->PredFlags & ProfiledPredFlag) | 
					
						
							|  |  |  |  |     newcp->opc = Yap_opcode(_profiled_trust_logical); | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     newcp->opc = Yap_opcode(_trust_logical); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |   newcp->u.OtILl.block = icl; | 
					
						
							|  |  |  |  |   newcp->u.OtILl.n = NULL; | 
					
						
							|  |  |  |  |   newcp->u.OtILl.d = lcl; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   lcl->ClRefCount++; | 
					
						
							|  |  |  |  |   return newcp; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, ClauseDef *cls) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* last clause to experiment with */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   PredEntry *ap = cint->CurrentPred; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   yamop *ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   int group1 = TRUE; | 
					
						
							|  |  |  |  |   yamop *alt = NULL; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |   UInt current_arity = 0; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   LogUpdIndex *icl = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-15 19:06:55 +00:00
										 |  |  |  |   sp = init_block_stack(sp, ipc, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* try to refine the interval using the indexing code */ | 
					
						
							|  |  |  |  |   while (ipc != NULL) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     switch(op) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _try_logical: | 
					
						
							|  |  |  |  |     case _retry_logical: | 
					
						
							|  |  |  |  |     case _count_retry_logical: | 
					
						
							|  |  |  |  |     case _profiled_retry_logical: | 
					
						
							|  |  |  |  |     case _trust_logical: | 
					
						
							|  |  |  |  |     case _count_trust_logical: | 
					
						
							|  |  |  |  |     case _profiled_trust_logical: | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  |       /* ERROR */ | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _enter_lu_pred: | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       ipc->u.Illss.s++; | 
					
						
							|  |  |  |  |       icl = ipc->u.Illss.I; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       if (first) { | 
					
						
							|  |  |  |  | 	if (ap->PredFlags & CountPredFlag) | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	  ipc->u.Illss.l1->opc = Yap_opcode(_count_retry_logical); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	else if (ap->PredFlags & ProfiledPredFlag) | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	  ipc->u.Illss.l1->opc = Yap_opcode(_profiled_retry_logical); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	  ipc->u.Illss.l1->opc = Yap_opcode(_retry_logical); | 
					
						
							|  |  |  |  | 	ipc->u.Illss.l1 = add_try(ap, cls, ipc->u.Illss.l1, cint); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | 	yamop *end = add_trust(icl, cls, cint), | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	  *old = ipc->u.Illss.l2; | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  | 	 | 
					
						
							|  |  |  |  | 	/* we used to have two clauses */ | 
					
						
							|  |  |  |  | 	if (ap->PredFlags & CountPredFlag) | 
					
						
							|  |  |  |  | 	  old->opc = Yap_opcode(_count_retry_logical); | 
					
						
							|  |  |  |  | 	else if (ap->PredFlags & ProfiledPredFlag) | 
					
						
							|  |  |  |  | 	  old->opc = Yap_opcode(_profiled_retry_logical); | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	  old->opc = Yap_opcode(_retry_logical); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	old->u.OtaLl.n = end; | 
					
						
							|  |  |  |  | 	old->u.OtaLl.s = ap->ArityOfPE; | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	ipc->u.Illss.l2 = end; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _try_clause: | 
					
						
							|  |  |  |  |       /* I cannot expand a predicate that starts on a variable,
 | 
					
						
							|  |  |  |  |          have to expand the index. | 
					
						
							|  |  |  |  |       */ | 
					
						
							|  |  |  |  |       if (first) { | 
					
						
							| 
									
										
										
										
											2004-02-17 16:27:22 +00:00
										 |  |  |  | 	sp = expanda_block(sp, ap, cls, group1, alt, cint); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _try_clause2: | 
					
						
							|  |  |  |  |     case _try_clause3: | 
					
						
							|  |  |  |  |     case _try_clause4: | 
					
						
							|  |  |  |  |       /* I cannot expand a predicate that starts on a variable,
 | 
					
						
							|  |  |  |  |          have to expand the index. | 
					
						
							|  |  |  |  |       */ | 
					
						
							|  |  |  |  |       if (first) { | 
					
						
							|  |  |  |  | 	sp = expanda_block(sp, ap, cls, group1, alt, cint); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							|  |  |  |  | 	ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _retry: | 
					
						
							|  |  |  |  |       /* this clause had no indexing */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _retry2: | 
					
						
							|  |  |  |  |     case _retry3: | 
					
						
							|  |  |  |  |     case _retry4: | 
					
						
							|  |  |  |  |       /* this clause had no indexing */ | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type l */ | 
					
						
							|  |  |  |  |     case _retry_me: | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       /* should never be reached both for asserta */ | 
					
						
							|  |  |  |  |       group1 = FALSE; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = ipc->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _try_me: | 
					
						
							|  |  |  |  |       if (first) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	ipc = NEXTOP(ipc,Otapl); | 
					
						
							|  |  |  |  | 	alt = ipc->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	ipc = ipc->u.Otapl.d; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 	group1 = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _retry_profiled: | 
					
						
							|  |  |  |  |     case _count_retry: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _profiled_trust_me: | 
					
						
							|  |  |  |  |     case _trust_me: | 
					
						
							|  |  |  |  |     case _count_trust_me: | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       group1 = FALSE; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _trust: | 
					
						
							| 
									
										
										
										
											2004-02-17 16:27:22 +00:00
										 |  |  |  |       sp = expandz_block(sp, ap, cls, group1, alt, cint); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       sp = cross_block(sp, &ipc->u.l.l, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* just skip for now, but should worry about memory management */ | 
					
						
							|  |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump_if_var: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.l.l), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |     case _jump_if_nonvar: | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.xll.l2), cls, cint); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       sp = cross_block(sp, &ipc->u.xll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       ipc = ipc->u.xll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type EC */ | 
					
						
							|  |  |  |  |     case _try_in: | 
					
						
							|  |  |  |  |       /* we are done */ | 
					
						
							|  |  |  |  |       if (first) { | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |     case _user_switch: | 
					
						
							| 
									
										
										
										
											2009-02-12 21:45:41 +00:00
										 |  |  |  |       ipc = ipc->u.lp.l; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _switch_on_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.llll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	add_head_info(cls, 1); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	add_info(cls, 1); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	current_arity = 2; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	move_next(cls, 1); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							|  |  |  |  | 	  /* jump straight to clause */ | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	  if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	    ipc->u.llll.l1 = cls->Code; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    ipc->u.llll.l1 = cls->CurrentCode; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.llll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l2; | 
					
						
							|  |  |  |  | 	move_next(cls, 1); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l3; | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_list_nl: | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  |       sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_arg_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.xllll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	add_head_info(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	add_info(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	current_arity = 2; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	move_next(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							|  |  |  |  | 	  /* jump straight to clause */ | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	  if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	    ipc->u.xllll.l1 = cls->Code; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    ipc->u.xllll.l1 = cls->CurrentCode; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.xllll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l2; | 
					
						
							|  |  |  |  | 	move_next(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l3; | 
					
						
							|  |  |  |  | 	move_next(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_sub_arg_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.sllll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       add_arg_info(cls, ap, ipc->u.sllll.s+1); | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	current_arity = 2; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	skip_to_arg(cls, ap, ipc->u.sllll.s, current_arity); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							|  |  |  |  | 	  /* jump straight to clause */ | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	  if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	    ipc->u.sllll.l1 = cls->Code; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    ipc->u.sllll.l1 = cls->CurrentCode; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.sllll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l2; | 
					
						
							|  |  |  |  | 	skip_to_arg(cls, ap, ipc->u.sllll.s, current_arity); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l3; | 
					
						
							|  |  |  |  | 	skip_to_arg(cls, ap, ipc->u.sllll.s, current_arity); | 
					
						
							|  |  |  |  | 	if (nipc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2003-12-05 15:18:08 +00:00
										 |  |  |  | 	  /* need to expand the block */ | 
					
						
							|  |  |  |  | 	  sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _if_not_then: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |       /* instructions type ollll */ | 
					
						
							|  |  |  |  |     case _switch_on_func: | 
					
						
							|  |  |  |  |     case _if_func: | 
					
						
							|  |  |  |  |     case _go_on_func: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	FuncSwiEntry *fe; | 
					
						
							|  |  |  |  | 	yamop *newpc; | 
					
						
							|  |  |  |  | 	Functor f = (Functor)RepAppl(cls->Tag); | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	if (op == _switch_on_func) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f_hash(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (!IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |  | 	  current_arity = ArityOfFunctor(f); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	newpc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { | 
					
						
							|  |  |  |  | 	  /* we found it */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else if (newpc == FAILCODE) { | 
					
						
							|  |  |  |  | 	  /* oops, nothing there */ | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	  if (fe->Tag != f) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	    if (IsExtensionFunctor(f)) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	      sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	      ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	      break; | 
					
						
							|  |  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	    if (table_fe_overflow(ipc, f)) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	      fe = expand_ftable(ipc, current_block(sp), cint, f); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	    fe->Tag = f; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	    ipc->u.sssl.e++; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	  if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	     fe->u.labp = cls->Code; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    fe->u.labp = cls->CurrentCode; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  yamop *newpc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = fetch_new_block(sp, &(ipc->u.sssl.l), ap, cint); | 
					
						
							|  |  |  |  | 	  sp = cross_block(sp, &(fe->u.labp), ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = newpc; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_dbref: | 
					
						
							|  |  |  |  |       cls->Tag = cls->u.t_ptr; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_blob: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cls->Tag = Yap_Double_key(cls->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     case _index_long: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cls->Tag = Yap_Int_key(cls->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _switch_on_cons: | 
					
						
							|  |  |  |  |     case _if_cons: | 
					
						
							|  |  |  |  |     case _go_on_cons: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	AtomSwiEntry *ae; | 
					
						
							|  |  |  |  | 	yamop *newpc; | 
					
						
							|  |  |  |  | 	Term at = cls->Tag; | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	if (op == _switch_on_cons) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c_hash(at,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c(at, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	newpc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { | 
					
						
							|  |  |  |  | 	  /* nothing more to do */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else if (newpc == FAILCODE) { | 
					
						
							|  |  |  |  | 	  /* oops, nothing there */ | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	  if (ae->Tag != at) { | 
					
						
							|  |  |  |  | 	    if (table_ae_overflow(ipc, at)) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  | 	      ae = expand_ctable(ipc, current_block(sp), cint, at); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	    ae->Tag = at; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	    ipc->u.sssl.e++; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	  if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	    ae->u.labp = cls->Code; | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    ae->u.labp = cls->CurrentCode; | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  yamop *newpc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = fetch_new_block(sp, &(ipc->u.sssl.l), ap, cint); | 
					
						
							|  |  |  |  | 	  sp = cross_block(sp, &(ae->u.labp), ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = newpc; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     case _expand_clauses: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = add_to_expand_clauses(&sp, ipc, cls, ap, first, cint); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _expand_index: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _lock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-09 14:19:05 +00:00
										 |  |  |  |     case _unlock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-04-20 22:08:57 +00:00
										 |  |  |  |     case _op_fail: | 
					
						
							|  |  |  |  |       while ((--sp)->flag != block_entry); | 
					
						
							|  |  |  |  |       *sp->u.cle.entry_code = cls->Code; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-04-20 22:08:57 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | Yap_AddClauseToIndex(PredEntry *ap, yamop *beg, int first) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   ClauseDef cl; | 
					
						
							|  |  |  |  |   /* first clause */ | 
					
						
							|  |  |  |  |   path_stack_entry *stack, *sp; | 
					
						
							|  |  |  |  |   int cb; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   struct intermediates cint; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-24 23:53:48 +00:00
										 |  |  |  |   if (!(ap->PredFlags & LogUpdatePredFlag)) { | 
					
						
							| 
									
										
										
										
											2003-10-14 18:37:56 +00:00
										 |  |  |  |     if (ap->PredFlags & IndexedPredFlag) | 
					
						
							|  |  |  |  |       Yap_RemoveIndexation(ap); | 
					
						
							| 
									
										
										
										
											2003-09-24 23:53:48 +00:00
										 |  |  |  |     return; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   cint.CurrentPred = ap; | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |   cint.expand_block = NULL; | 
					
						
							| 
									
										
										
										
											2004-04-29 03:44:04 +00:00
										 |  |  |  |   cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NIL; | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L; | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |   if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE, ENV, CP); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else if (cb == 2) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_growheap(FALSE, LOCAL_Error_Size, NULL); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   } else if (cb == 4) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_growtrail(LOCAL_Error_Size, FALSE); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   if (cb) { | 
					
						
							|  |  |  |  |     Yap_RemoveIndexation(ap); | 
					
						
							|  |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_Error_Size = 0; | 
					
						
							|  |  |  |  |   LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											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,'+'); | 
					
						
							|  |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\t'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05: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 13:30:50 +00:00
										 |  |  |  |       Term t = Deref(ARG1); | 
					
						
							|  |  |  |  |       if (IsAtomTerm(t)) { | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(t); | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |       } else if (IsIntegerTerm(t)) { | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = FunctorOfTerm(t); | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       if (ap->ArityOfPE == 0) { | 
					
						
							|  |  |  |  | 	Atom At = (Atom)ap->FunctorOfPred; | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = ap->FunctorOfPred; | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\n'); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   stack = (path_stack_entry *)TR; | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  |   cl.Code =  cl.CurrentCode = beg; | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |   sp = push_path(stack, NULL, &cl, &cint); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   add_to_index(&cint, first, sp, &cl);  | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 		  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | contract_ftable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Functor f) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   int n = ipc->u.sssl.s; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   FuncSwiEntry *fep; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     fep = lookup_f_hash(f, ipc->u.sssl.l, n); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     fep = (FuncSwiEntry *)(ipc->u.sssl.l); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     while (fep->Tag != f) fep++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |   fep->u.labp = FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | contract_ctable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Term at) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |   int n = ipc->u.sssl.s; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   AtomSwiEntry *cep; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (n > MIN_HASH_ENTRIES) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     cep = lookup_c_hash(at, ipc->u.sssl.l, n); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     cep = (AtomSwiEntry *)(ipc->u.sssl.l); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     while (cep->Tag != at) cep++; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  |   cep->u.labp = FAILCODE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  | remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg, yamop *lt, struct intermediates *cint) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* last clause to experiment with */ | 
					
						
							|  |  |  |  |   yamop *ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |   if (ap->cs.p_code.NOfClauses == 1) { | 
					
						
							|  |  |  |  |     if (ap->PredFlags & IndexedPredFlag) { | 
					
						
							|  |  |  |  |       Yap_RemoveIndexation(ap); | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause; | 
					
						
							| 
									
										
										
										
											2009-06-22 11:12:56 -05:00
										 |  |  |  |     if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |       ap->OpcodeOfPred = Yap_opcode(_spy_pred); | 
					
						
							|  |  |  |  |       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->cs.p_code.TrueCodeOfPred = FAILCODE; | 
					
						
							|  |  |  |  |       ap->OpcodeOfPred = LOCKPRED_OPCODE; | 
					
						
							|  |  |  |  |       ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));  | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |     } else { | 
					
						
							|  |  |  |  |       ap->OpcodeOfPred = ap->cs.p_code.FirstClause->opc; | 
					
						
							|  |  |  |  |       ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     return; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |   sp = init_block_stack(sp, ipc, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   /* try to refine the interval using the indexing code */ | 
					
						
							|  |  |  |  |   while (ipc != NULL) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     switch(op) { | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     case _retry_profiled: | 
					
						
							|  |  |  |  |     case _count_retry: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc, p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _try_in: | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       /* I cannot expand a predicate that starts on a variable,
 | 
					
						
							|  |  |  |  |          have to expand the index. | 
					
						
							|  |  |  |  |       */ | 
					
						
							|  |  |  |  |       if (IN_BETWEEN(bg,ipc->u.l.l,lt)) { | 
					
						
							|  |  |  |  | 	sp = kill_clause(ipc, bg, lt, sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							|  |  |  |  | 	ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _try_clause: | 
					
						
							|  |  |  |  |     case _retry: | 
					
						
							|  |  |  |  |       /* I cannot expand a predicate that starts on a variable,
 | 
					
						
							|  |  |  |  |          have to expand the index. | 
					
						
							|  |  |  |  |       */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       if (IN_BETWEEN(bg,ipc->u.Otapl.d,lt)) { | 
					
						
							| 
									
										
										
										
											2003-10-06 13:49:38 +00:00
										 |  |  |  | 	sp = kill_clause(ipc, bg, lt, sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _try_clause2: | 
					
						
							|  |  |  |  |     case _try_clause3: | 
					
						
							|  |  |  |  |     case _try_clause4: | 
					
						
							|  |  |  |  |     case _retry2: | 
					
						
							|  |  |  |  |     case _retry3: | 
					
						
							|  |  |  |  |     case _retry4: | 
					
						
							|  |  |  |  |       /* I cannot expand a predicate that starts on a variable,
 | 
					
						
							|  |  |  |  |          have to expand the index. | 
					
						
							|  |  |  |  |       */ | 
					
						
							|  |  |  |  |       if (IN_BETWEEN(bg,ipc->u.l.l,lt)) { | 
					
						
							|  |  |  |  | 	sp = kill_clause(ipc, bg, lt, sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* just go to next instruction */ | 
					
						
							|  |  |  |  | 	ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _trust: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       if (IN_BETWEEN(bg,ipc->u.Otapl.d,lt)) { | 
					
						
							| 
									
										
										
										
											2003-10-06 13:49:38 +00:00
										 |  |  |  | 	sp = kill_clause(ipc, bg, lt, sp, ap); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |     case _enter_lu_pred: | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       ipc->u.Illss.s--; | 
					
						
							|  |  |  |  |       ipc->u.Illss.e++; | 
					
						
							| 
									
										
										
										
											2006-10-11 14:53:57 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |  |       Yap_DirtyCps++; | 
					
						
							|  |  |  |  |       Yap_LiveCps--; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  |  |       sp = kill_clause(ipc, bg, lt, sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |       /* instructions type l */ | 
					
						
							|  |  |  |  |     case _try_me: | 
					
						
							|  |  |  |  |     case _retry_me: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.Otapl.d), cls, cint); | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     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 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       sp = cross_block(sp, &ipc->u.l.l, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* just skip for now, but should worry about memory management */ | 
					
						
							|  |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump_if_var: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.l.l), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |     case _jump_if_nonvar: | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.xll.l2), cls, cint); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       sp = cross_block(sp, &ipc->u.xll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       ipc = ipc->u.xll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |     case _user_switch: | 
					
						
							| 
									
										
										
										
											2009-02-12 21:45:41 +00:00
										 |  |  |  |       ipc = ipc->u.lp.l; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _switch_on_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.llll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	add_head_info(cls, 1); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	add_info(cls, 1); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.llll.l1 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.llll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l2; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.llll.l2 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.llll.l3; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.llll.l3 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_list_nl: | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  |       sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_arg_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.xllll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  | 	add_head_info(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	add_info(cls, Yap_regtoregno(ipc->u.xllll.x)); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.xllll.l1 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.xllll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l2; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.xllll.l2 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.xllll.l3; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.xllll.l3 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_sub_arg_type: | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |       sp = push_path(sp, &(ipc->u.sllll.l4), cls, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       add_arg_info(cls, ap, ipc->u.sllll.s+1); | 
					
						
							|  |  |  |  |       if (IsPairTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.sllll.l1 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* go on */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = cross_block(sp, &ipc->u.sllll.l1, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsAtomOrIntTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l2; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.sllll.l2 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else if (IsApplTerm(cls->Tag)) { | 
					
						
							|  |  |  |  | 	yamop *nipc = ipc->u.sllll.l3; | 
					
						
							| 
									
										
										
										
											2003-10-02 16:04:20 +00:00
										 |  |  |  | 	if (IN_BETWEEN(bg,nipc,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* jump straight to clause */ | 
					
						
							|  |  |  |  | 	  ipc->u.sllll.l3 = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  /* I do not have to worry about crossing a block here */ | 
					
						
							|  |  |  |  | 	  ipc = nipc;	 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	/* we can't separate into four groups,
 | 
					
						
							|  |  |  |  | 	   need to restart. | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							|  |  |  |  | 	sp = kill_block(sp, ap); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _if_not_then: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |       /* instructions type ollll */ | 
					
						
							|  |  |  |  |     case _switch_on_func: | 
					
						
							|  |  |  |  |     case _if_func: | 
					
						
							|  |  |  |  |     case _go_on_func: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	FuncSwiEntry *fe; | 
					
						
							|  |  |  |  | 	yamop *newpc; | 
					
						
							|  |  |  |  | 	Functor f = (Functor)RepAppl(cls->Tag); | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	if (op == _switch_on_func) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f_hash(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	newpc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { | 
					
						
							|  |  |  |  | 	  /* we found it */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else if (newpc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	} else if (IN_BETWEEN(bg,fe->u.Label,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* oops, nothing there */ | 
					
						
							|  |  |  |  | 	  contract_ftable(ipc, current_block(sp), ap, f); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  yamop *newpc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = fetch_new_block(sp, &(ipc->u.sssl.l), ap, cint); | 
					
						
							|  |  |  |  | 	  sp = cross_block(sp, &(fe->u.labp), ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = newpc; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_dbref: | 
					
						
							|  |  |  |  |       cls->Tag = cls->u.t_ptr; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_blob: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cls->Tag = Yap_Double_key(cls->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     case _index_long: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       cls->Tag = Yap_Int_key(cls->u.t_ptr); | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _switch_on_cons: | 
					
						
							|  |  |  |  |     case _if_cons: | 
					
						
							|  |  |  |  |     case _go_on_cons: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	AtomSwiEntry *ae; | 
					
						
							|  |  |  |  | 	yamop *newpc; | 
					
						
							|  |  |  |  | 	Term at = cls->Tag; | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	if (op == _switch_on_cons) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c_hash(at,ipc->u.sssl.l,ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c(at, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	newpc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { | 
					
						
							|  |  |  |  | 	  /* we found it */ | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else if (newpc == FAILCODE) { | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	} else if (IN_BETWEEN(bg,ae->u.Label,lt)) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  /* oops, nothing there */ | 
					
						
							|  |  |  |  | 	  contract_ctable(ipc, current_block(sp), ap, at); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	  yamop *newpc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  | 	  sp = fetch_new_block(sp, &(ipc->u.sssl.l), ap, cint); | 
					
						
							|  |  |  |  | 	  sp = cross_block(sp, &(ae->u.labp), ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = newpc; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _expand_index: | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     case _expand_clauses: | 
					
						
							|  |  |  |  |       nullify_expand_clause(ipc, sp, cls); | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _lock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     default: | 
					
						
							|  |  |  |  |       if (IN_BETWEEN(bg,ipc,lt)) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	sp = kill_unsafe_block(sp, op, ap, TRUE, TRUE, cls); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-03-24 01:02:44 +00:00
										 |  |  |  |       ipc = pop_path(&sp, cls, ap, cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  | /* clause is locked */ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | void | 
					
						
							|  |  |  |  | Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   ClauseDef cl; | 
					
						
							|  |  |  |  |   /* first clause */ | 
					
						
							|  |  |  |  |   path_stack_entry *stack, *sp; | 
					
						
							|  |  |  |  |   int cb; | 
					
						
							|  |  |  |  |   yamop *last; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |  |   struct intermediates cint;  | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-04-14 19:10:40 +00:00
										 |  |  |  |   cint.expand_block = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL; | 
					
						
							| 
									
										
										
										
											2010-12-16 01:22:10 +00:00
										 |  |  |  |   if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) { | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE, ENV, CP); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else if (cb == 2) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_growheap(FALSE, LOCAL_Error_Size, NULL); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |   } else if (cb == 4) { | 
					
						
							|  |  |  |  |     restore_machine_regs(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |     Yap_growtrail(LOCAL_Error_Size, FALSE); | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |  |   LOCAL_Error_Size = 0; | 
					
						
							|  |  |  |  |   LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2012-05-28 20:40:12 +01:00
										 |  |  |  |   cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L; | 
					
						
							| 
									
										
										
										
											2004-10-22 16:53:20 +00:00
										 |  |  |  |   if (cb) { | 
					
						
							|  |  |  |  |     /* cannot rely on the code */ | 
					
						
							|  |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |       Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |       StaticIndex *cl; | 
					
						
							|  |  |  |  |        | 
					
						
							|  |  |  |  |       cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); | 
					
						
							|  |  |  |  |       Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |  |     if (!tmod) tmod = TermProlog; | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'-'); | 
					
						
							|  |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\t'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05: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 13:30:50 +00:00
										 |  |  |  |       if (ap->ArityOfPE == 0) { | 
					
						
							|  |  |  |  | 	Atom At = (Atom)ap->FunctorOfPred; | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = ap->FunctorOfPred; | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |     } else { | 
					
						
							|  |  |  |  |       if (ap->PredFlags & NumberDBPredFlag) { | 
					
						
							|  |  |  |  | 	Int id = ap->src.IndxId; | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(id)); | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |       } else if (ap->PredFlags & AtomDBPredFlag) { | 
					
						
							|  |  |  |  | 	Atom At = (Atom)ap->FunctorOfPred; | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	Functor f = ap->FunctorOfPred; | 
					
						
							|  |  |  |  | 	Atom At = NameOfFunctor(f); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkAtomTerm(At)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  | 	Yap_DebugPutc(LOCAL_c_error_stream,'/'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:23:51 -05:00
										 |  |  |  | 	Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); | 
					
						
							| 
									
										
										
										
											2003-10-14 00:53:10 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |  |     Yap_DebugPutc(LOCAL_c_error_stream,'\n'); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   stack = (path_stack_entry *)TR; | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) { | 
					
						
							|  |  |  |  |     LogUpdClause *c = ClauseCodeToLogUpdClause(beg); | 
					
						
							|  |  |  |  |     cl.Code =  cl.CurrentCode = beg; | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     last = (yamop *)((CODEADDR)c+c->ClSize); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } else { | 
					
						
							|  |  |  |  |     StaticClause *c = ClauseCodeToStaticClause(beg); | 
					
						
							| 
									
										
										
										
											2003-11-26 18:36:35 +00:00
										 |  |  |  |     cl.Code =  cl.CurrentCode = beg; | 
					
						
							| 
									
										
										
										
											2004-03-05 15:26:33 +00:00
										 |  |  |  |     last = (yamop *)((CODEADDR)c+c->ClSize); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |   sp = push_path(stack, NULL, &cl, &cint); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   if (ap->cs.p_code.NOfClauses == 0) { | 
					
						
							|  |  |  |  |     /* there was no indexing code */ | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							|  |  |  |  |     if (ap->PredFlags & LogUpdatePredFlag && | 
					
						
							|  |  |  |  | 	ap->ModuleOfPred != IDB_MODULE) { | 
					
						
							|  |  |  |  |       ap->cs.p_code.TrueCodeOfPred = FAILCODE; | 
					
						
							|  |  |  |  |       ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));  | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |       ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = FAILCODE; | 
					
						
							|  |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  |     ap->OpcodeOfPred = Yap_opcode(_op_fail); | 
					
						
							| 
									
										
										
										
											2011-08-31 13:57:10 -07:00
										 |  |  |  |   } else if (ap->PredFlags & IndexedPredFlag)  { | 
					
						
							| 
									
										
										
										
											2004-09-14 03:30:06 +00:00
										 |  |  |  |     remove_from_index(ap, sp, &cl, beg, last, &cint);  | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 	      | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | store_clause_choice_point(Term t1, Term tb, Term tr, yamop *ipc, PredEntry *pe, yamop *ap_pc, yamop *cp_pc USES_REGS) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   Term tpc = MkIntegerTerm((Int)ipc); | 
					
						
							|  |  |  |  |   Term tpe = MkIntegerTerm((Int)pe); | 
					
						
							|  |  |  |  |   CELL *tsp = ASP-5; | 
					
						
							|  |  |  |  |   choiceptr bptr = ((choiceptr)tsp)-1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   tsp[0] = tpe; | 
					
						
							|  |  |  |  |   tsp[1] = tpc; | 
					
						
							|  |  |  |  |   tsp[2] = t1; | 
					
						
							|  |  |  |  |   tsp[3] = tb; | 
					
						
							|  |  |  |  |   tsp[4] = tr; | 
					
						
							|  |  |  |  |   bptr->cp_tr = TR; | 
					
						
							|  |  |  |  |   HB = bptr->cp_h = H; | 
					
						
							|  |  |  |  | #ifdef DEPTH_LIMIT
 | 
					
						
							|  |  |  |  |   bptr->cp_depth = DEPTH; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |   bptr->cp_b = B; | 
					
						
							|  |  |  |  |   bptr->cp_cp = cp_pc; | 
					
						
							|  |  |  |  |   bptr->cp_ap = ap_pc; | 
					
						
							|  |  |  |  |   bptr->cp_env = ENV; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   /* now, install the new YREG */ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   ASP = (CELL *)bptr; | 
					
						
							|  |  |  |  |   ASP[E_CB] = (CELL)bptr; | 
					
						
							|  |  |  |  |   B = bptr; | 
					
						
							|  |  |  |  | #ifdef YAPOR
 | 
					
						
							|  |  |  |  |   SCH_set_load(B); | 
					
						
							|  |  |  |  | #endif	/* YAPOR */
 | 
					
						
							|  |  |  |  |   SET_BB(bptr); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | update_clause_choice_point(yamop *ipc, yamop *ap_pc USES_REGS) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   Term tpc = MkIntegerTerm((Int)ipc); | 
					
						
							|  |  |  |  |   B->cp_args[1] = tpc; | 
					
						
							|  |  |  |  |   B->cp_h = H; | 
					
						
							|  |  |  |  |   B->cp_ap = ap_pc; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | static LogUpdClause * | 
					
						
							|  |  |  |  | to_clause(yamop *ipc, PredEntry *ap) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (ap->PredFlags & LogUpdatePredFlag) | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |     return lu_clause(ipc, ap); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |   else if (ap->PredFlags & MegaClausePredFlag) | 
					
						
							|  |  |  |  |     return (LogUpdClause *)ipc; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |   else | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  |     return (LogUpdClause *)simple_static_clause(ipc, ap); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | LogUpdClause * | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, yamop *cp_pc) | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   CELL *s_reg = NULL; | 
					
						
							|  |  |  |  |   Term t = TermNil; | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |   int blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   choiceptr b0 = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2003-09-23 15:14:56 +00:00
										 |  |  |  |   yamop **jlbl = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |   int lu_pred = ap->PredFlags & LogUpdatePredFlag; | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  |   int unbounded = TRUE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |  |   if (ap->ModuleOfPred != IDB_MODULE) { | 
					
						
							| 
									
										
										
										
											2003-12-02 01:15:50 +00:00
										 |  |  |  |     if (ap->ArityOfPE) { | 
					
						
							| 
									
										
										
										
											2005-04-28 14:50:45 +00:00
										 |  |  |  |       CELL *tar = RepAppl(Deref(Terms[0])); | 
					
						
							| 
									
										
										
										
											2003-12-02 01:15:50 +00:00
										 |  |  |  |       UInt i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       for (i = 1; i <= ap->ArityOfPE; i++) { | 
					
						
							|  |  |  |  | 	XREGS[i] = tar[i]; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |   /* try to refine the interval using the indexing code */ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |   while (ipc != NULL) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  |     switch(op) { | 
					
						
							|  |  |  |  |     case _try_in: | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       update_clause_choice_point(NEXTOP(ipc,l), ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	return lu_clause(ipc->u.l.l, ap); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.l.l, ap, unbounded); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _try_clause: | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_try: | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       if (b0 == NULL) | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	store_clause_choice_point(Terms[0], Terms[1], Terms[2], NEXTOP(ipc,Otapl), ap, ap_pc, cp_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       else { | 
					
						
							|  |  |  |  | 	B = b0; | 
					
						
							| 
									
										
										
										
											2006-04-20 15:28:08 +00:00
										 |  |  |  | 	b0 = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	update_clause_choice_point(NEXTOP(ipc,Otapl), ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return lu_clause(ipc->u.Otapl.d, ap); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.Otapl.d, ap, unbounded); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _try_clause2: | 
					
						
							|  |  |  |  |     case _try_clause3: | 
					
						
							|  |  |  |  |     case _try_clause4: | 
					
						
							|  |  |  |  |       if (b0 == NULL) | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	store_clause_choice_point(Terms[0], Terms[1], Terms[2], NEXTOP(ipc,l), ap, ap_pc, cp_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       else { | 
					
						
							|  |  |  |  | 	B = b0; | 
					
						
							| 
									
										
										
										
											2006-04-20 15:28:08 +00:00
										 |  |  |  | 	b0 = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	update_clause_choice_point(NEXTOP(ipc,l), ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	return lu_clause(ipc->u.l.l, ap); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.l.l, ap, unbounded); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _try_me: | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_try_me: | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       if (b0 == NULL) | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	store_clause_choice_point(Terms[0], Terms[1], Terms[2], ipc->u.Otapl.d, ap, ap_pc, cp_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       else { | 
					
						
							|  |  |  |  | 	B = b0; | 
					
						
							| 
									
										
										
										
											2006-04-20 15:28:08 +00:00
										 |  |  |  | 	b0 = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	update_clause_choice_point(ipc->u.Otapl.d, ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _retry_profiled: | 
					
						
							|  |  |  |  |     case _count_retry: | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _retry: | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_retry: | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       update_clause_choice_point(NEXTOP(ipc,Otapl),ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return lu_clause(ipc->u.Otapl.d, ap); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.Otapl.d, ap, TRUE); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _retry2: | 
					
						
							|  |  |  |  |     case _retry3: | 
					
						
							|  |  |  |  |     case _retry4: | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       update_clause_choice_point(NEXTOP(ipc,l),ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	return lu_clause(ipc->u.l.l, ap); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.l.l, ap, TRUE); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _retry_me: | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       update_clause_choice_point(ipc->u.Otapl.d,ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _trust: | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_trust: | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |  | 	  { | 
					
						
							|  |  |  |  | 	    POP_EXECUTE(); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  |       { | 
					
						
							|  |  |  |  | 	choiceptr cut_pt; | 
					
						
							|  |  |  |  | 	cut_pt = B->cp_b; | 
					
						
							|  |  |  |  | 	CUT_prune_to(cut_pt); | 
					
						
							|  |  |  |  | 	B = cut_pt; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  |       B = B->cp_b; | 
					
						
							|  |  |  |  | #endif /* YAPOR */
 | 
					
						
							|  |  |  |  |       b0 = B; | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return lu_clause(ipc->u.Otapl.d, ap); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc->u.Otapl.d, ap, TRUE); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _profiled_trust_me: | 
					
						
							|  |  |  |  |     case _trust_me: | 
					
						
							|  |  |  |  |     case _count_trust_me: | 
					
						
							| 
									
										
										
										
											2007-03-21 23:23:46 +00:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_trust_me: | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-04-12 18:56:50 +00:00
										 |  |  |  |       b0 = B; | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |  | 	  { | 
					
						
							|  |  |  |  | 	    POP_EXECUTE(); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2005-02-24 21:46:40 +00:00
										 |  |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  |       { | 
					
						
							|  |  |  |  | 	choiceptr cut_pt; | 
					
						
							|  |  |  |  | 	cut_pt = B->cp_b; | 
					
						
							|  |  |  |  | 	CUT_prune_to(cut_pt); | 
					
						
							|  |  |  |  | 	B = cut_pt; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2005-02-24 21:46:40 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  |       B = B->cp_b; | 
					
						
							|  |  |  |  | #endif /* YAPOR */
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _enter_lu_pred: | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  | 	LogUpdIndex *cl = ipc->u.Illss.I; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	PredEntry *ap = cl->ClPred; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (ap->LastCallOfPred != LUCALL_EXEC) { | 
					
						
							|  |  |  |  | 	  /*
 | 
					
						
							|  |  |  |  | 	    only increment time stamp if we are working on current time | 
					
						
							|  |  |  |  | 	    stamp | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  */ | 
					
						
							| 
									
										
										
										
											2006-11-15 00:13:37 +00:00
										 |  |  |  | 	  if (ap->TimeStampOfPred >= TIMESTAMP_RESET) | 
					
						
							|  |  |  |  | 	    Yap_UpdateTimestamps(ap); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  ap->TimeStampOfPred++; | 
					
						
							|  |  |  |  | 	  /*	  fprintf(stderr,"R %x--%d--%ul\n",ap,ap->TimeStampOfPred,ap->ArityOfPE);*/ | 
					
						
							|  |  |  |  | 	  ap->LastCallOfPred = LUCALL_EXEC; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	*--ASP = MkIntegerTerm(ap->TimeStampOfPred); | 
					
						
							|  |  |  |  | 	/* indicate the indexing code is being used */ | 
					
						
							| 
									
										
										
										
											2011-04-14 18:51:11 +01:00
										 |  |  |  | #if MULTIPLE_STACKS
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	/* just store a reference */ | 
					
						
							|  |  |  |  | 	INC_CLREF_COUNT(cl); | 
					
						
							|  |  |  |  | 	TRAIL_CLREF(cl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	if (!(cl->ClFlags & InUseMask)) { | 
					
						
							|  |  |  |  | 	  cl->ClFlags |= InUseMask; | 
					
						
							|  |  |  |  | 	  TRAIL_CLREF(cl); | 
					
						
							|  |  |  |  | 	}	 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #endif
 | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       ipc = ipc->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _try_logical: | 
					
						
							|  |  |  |  |       if (b0 == NULL) | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	store_clause_choice_point(Terms[0], Terms[1], Terms[2], ipc->u.OtaLl.n, ap, ap_pc, cp_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       else { | 
					
						
							|  |  |  |  | 	B = b0; | 
					
						
							|  |  |  |  | 	b0 = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  | 	update_clause_choice_point(ipc->u.OtaLl.n, ap_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2004-02-18 01:43:32 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | 	UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	if (!VALID_TIMESTAMP(timestamp, ipc->u.OtaLl.d)) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  /* jump to next instruction */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  ipc = ipc->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2004-02-17 16:27:22 +00:00
										 |  |  |  | 	  break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       return ipc->u.OtaLl.d; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _retry_logical: | 
					
						
							|  |  |  |  |     case _profiled_retry_logical: | 
					
						
							|  |  |  |  |     case _count_retry_logical: | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2008-01-23 17:57:56 +00:00
										 |  |  |  | 	UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	if (!VALID_TIMESTAMP(timestamp, ipc->u.OtaLl.d)) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  /* jump to next instruction */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  ipc = ipc->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-04-30 01:08:48 +01:00
										 |  |  |  |       update_clause_choice_point(ipc->u.OtaLl.n,ap_pc PASS_REGS); | 
					
						
							|  |  |  |  |       return ipc->u.OtaLl.d; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:54:09 -05:00
										 |  |  |  | #if TABLING
 | 
					
						
							|  |  |  |  |     case _table_try_single: | 
					
						
							|  |  |  |  |       return (LogUpdClause *)ClauseCodeToStaticClause(ipc); | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _trust_logical: | 
					
						
							|  |  |  |  |     case _count_trust_logical: | 
					
						
							|  |  |  |  |     case _profiled_trust_logical: | 
					
						
							|  |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2011-04-30 01:08:48 +01:00
										 |  |  |  | 	UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	LogUpdIndex *cl = ipc->u.OtILl.block; | 
					
						
							| 
									
										
										
										
											2006-10-25 02:31:07 +00:00
										 |  |  |  | 	LogUpdClause *newpc; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	if (!VALID_TIMESTAMP(timestamp, ipc->u.OtILl.d)) { | 
					
						
							| 
									
										
										
										
											2006-10-25 02:31:07 +00:00
										 |  |  |  | 	  /* jump to next instruction */ | 
					
						
							|  |  |  |  | 	  newpc = NULL; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  newpc = ipc->u.OtILl.d; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-14 18:51:11 +01:00
										 |  |  |  | #if MULTIPLE_STACKS
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  | 	B->cp_tr--; | 
					
						
							|  |  |  |  | 	TR--; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	DEC_CLREF_COUNT(cl); | 
					
						
							|  |  |  |  | 	/* actually get rid of the code */ | 
					
						
							|  |  |  |  | 	if (cl->ClRefCount == 0 && cl->ClFlags & (ErasedMask|DirtyMask)) { | 
					
						
							|  |  |  |  | 	  /* I am the last one using this clause, hence I don't need a lock
 | 
					
						
							| 
									
										
										
										
											2012-07-18 14:32:53 -05:00
										 |  |  |  | 	     to dispose of it. But on the other hand I need to make sure | 
					
						
							|  |  |  |  | 	     the clause is still there when I am back. | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  */ | 
					
						
							| 
									
										
										
										
											2012-07-18 14:32:53 -05:00
										 |  |  |  | 	  LogUpdClause *lcl = ipc->u.OtILl.d; | 
					
						
							|  |  |  |  | 	  if (newpc) { | 
					
						
							|  |  |  |  | 	    /* I am the last one using this clause, hence I don't need a lock
 | 
					
						
							|  |  |  |  | 	       to dispose of it  | 
					
						
							|  |  |  |  | 	    */ | 
					
						
							|  |  |  |  | 	    /* make sure the clause isn't destroyed */ | 
					
						
							|  |  |  |  | 	    /* always add an extra reference */ | 
					
						
							|  |  |  |  | 	    INC_CLREF_COUNT(lcl); | 
					
						
							|  |  |  |  | 	    TRAIL_CLREF(lcl); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  if (cl->ClFlags & ErasedMask) { | 
					
						
							|  |  |  |  | 	    Yap_ErLogUpdIndex(cl); | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    Yap_CleanUpIndex(cl); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2012-07-18 14:32:53 -05:00
										 |  |  |  | 	  if (newpc) { | 
					
						
							|  |  |  |  | 	    DEC_CLREF_COUNT(lcl);	   | 
					
						
							|  |  |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) && | 
					
						
							|  |  |  |  | 	    B->cp_tr != B->cp_b->cp_tr) { | 
					
						
							|  |  |  |  | 	   | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |  | 	  B->cp_tr--; | 
					
						
							|  |  |  |  | 	  TR--; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	  cl->ClFlags &= ~InUseMask; | 
					
						
							|  |  |  |  | 	  /* next, recover space for the indexing code if it was erased */ | 
					
						
							|  |  |  |  | 	  if (cl->ClFlags & (ErasedMask|DirtyMask)) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	    LogUpdClause *lcl = ipc->u.OtILl.d; | 
					
						
							| 
									
										
										
										
											2012-07-18 14:32:53 -05:00
										 |  |  |  | 	    /* make sure we don't erase the clause we are jumping to, notice that
 | 
					
						
							|  |  |  |  | 	       ErLogUpdIndex may remove several references in one go. | 
					
						
							|  |  |  |  | 	       Notice we only need to do this if we<EFBFBD> re jumping to the clause. | 
					
						
							|  |  |  |  | 	     */ | 
					
						
							|  |  |  |  | 	    if (newpc && !(lcl->ClFlags & (DirtyMask|InUseMask))) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	      lcl->ClFlags |= InUseMask; | 
					
						
							|  |  |  |  | 	      TRAIL_CLREF(lcl); | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	    if (cl->ClFlags & ErasedMask) { | 
					
						
							|  |  |  |  | 	      Yap_ErLogUpdIndex(cl); | 
					
						
							|  |  |  |  | 	    } else { | 
					
						
							|  |  |  |  | 	      Yap_CleanUpIndex(cl); | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-10-25 02:31:07 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	  while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |  | 	    { | 
					
						
							|  |  |  |  | 	      POP_EXECUTE(); | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | #endif /* CUT_C */
 | 
					
						
							|  |  |  |  | #ifdef YAPOR
 | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	  choiceptr cut_pt; | 
					
						
							|  |  |  |  | 	  cut_pt = B->cp_b; | 
					
						
							|  |  |  |  | 	  CUT_prune_to(cut_pt); | 
					
						
							|  |  |  |  | 	  B = cut_pt; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-10-25 02:31:07 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  | 	B = B->cp_b; | 
					
						
							|  |  |  |  | #endif /* YAPOR */
 | 
					
						
							|  |  |  |  | 	b0 = B; | 
					
						
							|  |  |  |  | 	return newpc; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     case _jump: | 
					
						
							|  |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump_if_var: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	Term t = Deref(ARG1); | 
					
						
							|  |  |  |  | 	if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	  SET_JLBL(l.l); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	  ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  |     case _jump_if_nonvar: | 
					
						
							|  |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | 	Term t = Deref(XREGS[arg_from_x(ipc->u.xll.x)]); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	if (!IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	  SET_JLBL(xll.l1); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | 	  ipc = ipc->u.xll.l1; | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  | 	  ipc = NEXTOP(ipc,xll); | 
					
						
							| 
									
										
										
										
											2003-10-28 01:16:03 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |     case _user_switch: | 
					
						
							| 
									
										
										
										
											2009-02-12 21:45:41 +00:00
										 |  |  |  |       ipc = ipc->u.lp.l; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _switch_on_type: | 
					
						
							|  |  |  |  |       t = Deref(ARG1); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(llll.l4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(llll.l1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l1; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (IsAtomOrIntTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(llll.l2); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l2; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(llll.l3); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.llll.l3; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = RepAppl(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_list_nl: | 
					
						
							|  |  |  |  |       t = Deref(ARG1); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(ollll.l4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(ollll.l1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l1; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2005-06-01 16:42:30 +00:00
										 |  |  |  |       } else if (t == TermNil) { | 
					
						
							| 
									
										
										
										
											2010-01-25 10:21:40 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(ollll.l2); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l2; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(ollll.l3); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.ollll.l3; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = RepAppl(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_arg_type: | 
					
						
							| 
									
										
										
										
											2003-11-12 12:33:31 +00:00
										 |  |  |  |       t = Deref(XREGS[arg_from_x(ipc->u.xllll.x)]); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(xllll.l4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(xllll.l1); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l1; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (IsAtomOrIntTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(xllll.l2); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l2; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(xllll.l3); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.xllll.l3; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = RepAppl(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_sub_arg_type: | 
					
						
							|  |  |  |  |       t = Deref(s_reg[ipc->u.sllll.s]); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(sllll.l4); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.sllll.l4; | 
					
						
							|  |  |  |  |       } else if (IsPairTerm(t)) { | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(sllll.l1); | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = s_reg = RepPair(t); | 
					
						
							| 
									
										
										
										
											2012-06-14 17:21:46 -05:00
										 |  |  |  | 	ipc = ipc->u.sllll.l1; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } else if (IsAtomOrIntTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(sllll.l2); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.sllll.l2; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(sllll.l3); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	ipc = ipc->u.sllll.l3; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = RepAppl(t); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _if_not_then: | 
					
						
							|  |  |  |  |       t = Deref(ARG1); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  |       if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(clll.l3); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	ipc = ipc->u.clll.l3; | 
					
						
							|  |  |  |  |       } else if (!IsVarTerm(t) && t != ipc->u.clll.c) { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(clll.l1); | 
					
						
							| 
									
										
										
										
											2003-10-02 12:59:05 +00:00
										 |  |  |  | 	ipc = ipc->u.clll.l1; | 
					
						
							| 
									
										
										
										
											2005-01-15 05:21:36 +00:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | 	SET_JLBL(clll.l2); | 
					
						
							| 
									
										
										
										
											2005-01-15 05:21:36 +00:00
										 |  |  |  | 	ipc = ipc->u.clll.l2; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |       /* instructions type ollll */ | 
					
						
							|  |  |  |  |     case _switch_on_func: | 
					
						
							|  |  |  |  |     case _if_func: | 
					
						
							|  |  |  |  |     case _go_on_func: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	FuncSwiEntry *fe; | 
					
						
							|  |  |  |  | 	Functor f; | 
					
						
							|  |  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	s_reg = RepAppl(t); | 
					
						
							|  |  |  |  | 	f = (Functor)s_reg[0]; | 
					
						
							|  |  |  |  | 	s_reg++; | 
					
						
							| 
									
										
										
										
											2007-06-20 13:48:45 +00:00
										 |  |  |  | 	S = s_reg; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	if (op == _switch_on_func) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f_hash(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  fe = lookup_f(f, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	jlbl = &(fe->u.labp); | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	ipc = fe->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_dbref: | 
					
						
							|  |  |  |  |       t = AbsAppl(s_reg-1); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _index_blob: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       t = Yap_DoubleP_key(s_reg); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = TRUE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |     case _index_long: | 
					
						
							| 
									
										
										
										
											2010-05-14 12:42:30 +01:00
										 |  |  |  |       t = Yap_IntP_key(s_reg); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       blob_term = TRUE; | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,e); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _switch_on_cons: | 
					
						
							|  |  |  |  |     case _if_cons: | 
					
						
							|  |  |  |  |     case _go_on_cons: | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	AtomSwiEntry *ae; | 
					
						
							|  |  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	unbounded = FALSE; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	if (op == _switch_on_cons) { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c_hash(t, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  | 	  ae = lookup_c(t, ipc->u.sssl.l, ipc->u.sssl.s); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	jlbl = &(ae->u.labp); | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-05-02 11:01:41 +00:00
										 |  |  |  | 	ipc = ae->u.labp; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _expand_index: | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     case _expand_clauses: | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       if (blob_term) { /* protect garbage collector */ | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+1] = (CELL)&XREGS[ap->ArityOfPE+1]; | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+2] = TermNil; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+1] = (CELL)s_reg; | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+2] = t; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  |       XREGS[ap->ArityOfPE+3] = Terms[0]; | 
					
						
							|  |  |  |  |       XREGS[ap->ArityOfPE+4] = Terms[1]; | 
					
						
							|  |  |  |  |       XREGS[ap->ArityOfPE+5] = Terms[2]; | 
					
						
							|  |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  |  |       if (!same_lu_block(jlbl, ipc)) { | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  | 	ipc = *jlbl; | 
					
						
							| 
									
										
										
										
											2004-02-18 01:43:32 +00:00
										 |  |  |  | 	break; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       ipc = ExpandIndex(ap, 5, cp_pc PASS_REGS); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       if (!blob_term) { /* protect garbage collector */ | 
					
						
							|  |  |  |  | 	s_reg = (CELL *)XREGS[ap->ArityOfPE+1]; | 
					
						
							|  |  |  |  | 	t = XREGS[ap->ArityOfPE+2]; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       blob_term = FALSE; | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  |       Terms[0] = XREGS[ap->ArityOfPE+3]; | 
					
						
							|  |  |  |  |       Terms[1] = XREGS[ap->ArityOfPE+4]; | 
					
						
							|  |  |  |  |       Terms[2] = XREGS[ap->ArityOfPE+5]; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:06:15 +00:00
										 |  |  |  |     case _undef_p: | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _lock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-11 01:20:56 +00:00
										 |  |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-02-11 16:18:16 +00:00
										 |  |  |  |     case _thread_local: | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       ap = Yap_GetThreadPred(ap PASS_REGS); | 
					
						
							| 
									
										
										
										
											2004-02-11 01:20:56 +00:00
										 |  |  |  |       ipc = ap->CodeOfPred; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-11 16:18:16 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     case _spy_pred: | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  |     case _lock_pred: | 
					
						
							| 
									
										
										
										
											2006-11-21 16:21:33 +00:00
										 |  |  |  |       if ((ap->PredFlags & IndexedPredFlag) || | 
					
						
							|  |  |  |  | 	      ap->cs.p_code.NOfClauses <= 1) { | 
					
						
							|  |  |  |  | 	ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							|  |  |  |  | 	break; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  |     case _index_pred: | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       if (blob_term) { /* protect garbage collector */ | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+1] = (CELL)&XREGS[ap->ArityOfPE+1]; | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+2] = TermNil; | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+1] = (CELL)s_reg; | 
					
						
							|  |  |  |  | 	XREGS[ap->ArityOfPE+2] = t; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  |       XREGS[ap->ArityOfPE+3] = Terms[0]; | 
					
						
							|  |  |  |  |       XREGS[ap->ArityOfPE+4] = Terms[1]; | 
					
						
							|  |  |  |  |       XREGS[ap->ArityOfPE+5] = Terms[2]; | 
					
						
							| 
									
										
										
										
											2010-01-29 15:21:00 +00:00
										 |  |  |  |       Yap_IPred(ap, 5, cp_pc); | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							| 
									
										
										
										
											2011-05-09 19:13:10 +01:00
										 |  |  |  |       if (!blob_term) { /* protect garbage collector */ | 
					
						
							|  |  |  |  | 	s_reg = (CELL *)XREGS[ap->ArityOfPE+1]; | 
					
						
							|  |  |  |  | 	t = XREGS[ap->ArityOfPE+2]; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2004-09-30 19:51:54 +00:00
										 |  |  |  |       Terms[0] = XREGS[ap->ArityOfPE+3]; | 
					
						
							|  |  |  |  |       Terms[1] = XREGS[ap->ArityOfPE+4]; | 
					
						
							|  |  |  |  |       Terms[2] = XREGS[ap->ArityOfPE+5]; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-10-27 15:56:34 +00:00
										 |  |  |  |     case _op_fail: | 
					
						
							|  |  |  |  |       if (ipc == FAILCODE) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |       if (b0) { | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |  | 	  { | 
					
						
							|  |  |  |  | 	    POP_EXECUTE(); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	  choiceptr cut_pt; | 
					
						
							|  |  |  |  | 	  cut_pt = B->cp_b; | 
					
						
							|  |  |  |  | 	  CUT_prune_to(cut_pt); | 
					
						
							|  |  |  |  | 	  B = cut_pt; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  | 	B = B->cp_b; | 
					
						
							|  |  |  |  | #endif /* YAPOR */
 | 
					
						
							|  |  |  |  | 	/* I did a trust */ | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-01-24 10:20:42 +00:00
										 |  |  |  |       if (op == _op_fail) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       if (lu_pred) | 
					
						
							| 
									
										
										
										
											2008-05-10 23:24:13 +00:00
										 |  |  |  | 	return lu_clause(ipc, ap); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-04-16 17:16:47 +00:00
										 |  |  |  | 	return (LogUpdClause *)static_clause(ipc, ap, unbounded); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:30:50 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   if (b0) { | 
					
						
							|  |  |  |  |     /* I did a trust */ | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |  |       { | 
					
						
							|  |  |  |  | 	while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |  | 	  { | 
					
						
							|  |  |  |  | 	    POP_EXECUTE(); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2005-04-07 17:56:58 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       choiceptr cut_pt; | 
					
						
							|  |  |  |  |       cut_pt = B->cp_b; | 
					
						
							|  |  |  |  |       CUT_prune_to(cut_pt); | 
					
						
							|  |  |  |  |       B = cut_pt; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  |     B = B->cp_b; | 
					
						
							|  |  |  |  | #endif /* YAPOR */
 | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  |   return NULL; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | LogUpdClause * | 
					
						
							|  |  |  |  | Yap_NthClause(PredEntry *ap, Int ncls) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |   yamop | 
					
						
							|  |  |  |  |     *ipc = ap->cs.p_code.TrueCodeOfPred, | 
					
						
							|  |  |  |  |     *alt = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |   yamop **jlbl = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   /* search every clause */ | 
					
						
							| 
									
										
										
										
											2009-11-18 13:06:37 +00:00
										 |  |  |  |   if (ncls > ap->cs.p_code.NOfClauses) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							|  |  |  |  |   else if (ncls == 1) | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     return to_clause(ap->cs.p_code.FirstClause,ap); | 
					
						
							| 
									
										
										
										
											2012-02-14 18:57:39 +00:00
										 |  |  |  |   else if (ap->PredFlags & MegaClausePredFlag) { | 
					
						
							|  |  |  |  |     MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); | 
					
						
							|  |  |  |  |     /* fast access to nth element, all have same size */ | 
					
						
							|  |  |  |  |     return (LogUpdClause *)((char *)mcl->ClCode+(ncls-1)*mcl->ClItemSize); | 
					
						
							|  |  |  |  |   } else if (ncls == ap->cs.p_code.NOfClauses) { | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     return to_clause(ap->cs.p_code.LastClause,ap); | 
					
						
							| 
									
										
										
										
											2012-02-14 18:57:39 +00:00
										 |  |  |  |   } else if (ncls < 0) | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     return NULL; | 
					
						
							|  |  |  |  |    | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |  |   if (ap->ModuleOfPred != IDB_MODULE) { | 
					
						
							| 
									
										
										
										
											2003-12-02 01:15:50 +00:00
										 |  |  |  |     if (ap->ArityOfPE) { | 
					
						
							|  |  |  |  |       UInt i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       for (i = 1; i <= ap->ArityOfPE; i++) { | 
					
						
							|  |  |  |  | 	XREGS[i] = MkVarTerm(); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } else { | 
					
						
							|  |  |  |  |     ARG2 = MkVarTerm(); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |  |     op_numbers op = Yap_op_from_opcode(ipc->opc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     switch(op) { | 
					
						
							|  |  |  |  |     case _try_in: | 
					
						
							|  |  |  |  |       if (ncls == 1) | 
					
						
							|  |  |  |  | 	return to_clause(ipc->u.l.l, ap); | 
					
						
							|  |  |  |  |       ncls--; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _retry_profiled: | 
					
						
							|  |  |  |  |     case _count_retry: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |     case _try_clause: | 
					
						
							|  |  |  |  |     case _retry: | 
					
						
							|  |  |  |  |       if (ncls == 1) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return to_clause(ipc->u.Otapl.d, ap); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       else if (alt == NULL) { | 
					
						
							| 
									
										
										
										
											2005-05-25 18:58:38 +00:00
										 |  |  |  | 	ncls --; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 	/* get there in a fell swoop */ | 
					
						
							|  |  |  |  | 	if (ap->PredFlags & ProfiledPredFlag) { | 
					
						
							|  |  |  |  | 	  if (ap->PredFlags & CountPredFlag) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	    ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP(NEXTOP((yamop *)NULL,Otapl),p),p)); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 	  } else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	    ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,Otapl),p)); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} else if (ap->PredFlags & CountPredFlag) { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,Otapl),p)); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP((yamop *)NULL,Otapl)); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	return to_clause(ipc->u.Otapl.d, ap); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	ncls--; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |     case _try_clause2: | 
					
						
							|  |  |  |  |     case _try_clause3: | 
					
						
							|  |  |  |  |     case _try_clause4: | 
					
						
							|  |  |  |  |     case _retry2: | 
					
						
							|  |  |  |  |     case _retry3: | 
					
						
							|  |  |  |  |     case _retry4: | 
					
						
							|  |  |  |  |       if (ncls == 1) | 
					
						
							|  |  |  |  | 	return to_clause(ipc->u.l.l, ap); | 
					
						
							|  |  |  |  |       else if (alt == NULL) { | 
					
						
							| 
									
										
										
										
											2005-05-25 18:58:38 +00:00
										 |  |  |  | 	ncls --; | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  | 	/* get there in a fell swoop */ | 
					
						
							|  |  |  |  | 	if (ap->PredFlags & ProfiledPredFlag) { | 
					
						
							|  |  |  |  | 	  if (ap->PredFlags & CountPredFlag) { | 
					
						
							|  |  |  |  | 	    ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP(NEXTOP((yamop *)NULL,l),p),p)); | 
					
						
							|  |  |  |  | 	  } else { | 
					
						
							|  |  |  |  | 	    ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,l),p)); | 
					
						
							|  |  |  |  | 	  } | 
					
						
							|  |  |  |  | 	} else if (ap->PredFlags & CountPredFlag) { | 
					
						
							|  |  |  |  | 	  ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,l),p)); | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							|  |  |  |  | 	  ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP((yamop *)NULL,l)); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-05-25 18:58:38 +00:00
										 |  |  |  | 	return to_clause(ipc->u.l.l, ap); | 
					
						
							| 
									
										
										
										
											2004-09-27 20:45:04 +00:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  | 	ncls--; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,l); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     case _trust: | 
					
						
							|  |  |  |  |       if (ncls == 1) | 
					
						
							|  |  |  |  | 	return to_clause(ipc->u.l.l,ap); | 
					
						
							|  |  |  |  |       ncls--; | 
					
						
							|  |  |  |  |       ipc = alt; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _try_me: | 
					
						
							|  |  |  |  |     case _retry_me: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       alt = ipc->u.Otapl.d; | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _profiled_trust_me: | 
					
						
							|  |  |  |  |     case _trust_me: | 
					
						
							|  |  |  |  |     case _count_trust_me: | 
					
						
							|  |  |  |  |       alt = NULL; | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = NEXTOP(ipc,Otapl); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _try_logical: | 
					
						
							|  |  |  |  |     case _retry_logical: | 
					
						
							|  |  |  |  |     case _count_retry_logical: | 
					
						
							|  |  |  |  |     case _profiled_retry_logical: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->u.OtaLl.d)) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	if (ncls == 1) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  return ipc->u.OtaLl.d; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	ncls--; | 
					
						
							| 
									
										
										
										
											2004-02-17 16:27:22 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       ipc = ipc->u.OtaLl.n; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |     case _trust_logical: | 
					
						
							|  |  |  |  |     case _count_trust_logical: | 
					
						
							|  |  |  |  |     case _profiled_trust_logical: | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  |       if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->u.OtILl.d)) { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | 	if (ncls == 1) | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |  | 	  return ipc->u.OtILl.d; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     case _enter_lu_pred: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(Illss.l1); | 
					
						
							| 
									
										
										
										
											2011-06-24 21:08:22 +01:00
										 |  |  |  |       ipc = ipc->u.Illss.l1; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _lock_lu: | 
					
						
							|  |  |  |  |       ipc = NEXTOP(ipc,p); | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     case _jump: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(l.l); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump_if_var: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(l.l); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.l.l; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _jump_if_nonvar: | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |  |       ipc = NEXTOP(ipc,xll); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |     case _user_switch: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(l.l); | 
					
						
							| 
									
										
										
										
											2009-02-12 21:45:41 +00:00
										 |  |  |  |       ipc = ipc->u.lp.l; | 
					
						
							| 
									
										
										
										
											2009-02-12 21:35:31 +00:00
										 |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       /* instructions type e */ | 
					
						
							|  |  |  |  |     case _switch_on_type: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(llll.l4); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.llll.l4; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_list_nl: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(ollll.l4); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.ollll.l4; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_arg_type: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(xllll.l4); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.xllll.l4; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _switch_on_sub_arg_type: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(sllll.l4); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.sllll.l4; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _if_not_then: | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |       SET_JLBL(clll.l3); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ipc->u.clll.l3; | 
					
						
							|  |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _expand_index: | 
					
						
							| 
									
										
										
										
											2004-03-31 01:02:18 +00:00
										 |  |  |  |     case _expand_clauses: | 
					
						
							| 
									
										
										
										
											2004-02-18 01:43:32 +00:00
										 |  |  |  | #if defined(YAPOR) || defined(THREADS)
 | 
					
						
							| 
									
										
										
										
											2004-02-19 19:24:46 +00:00
										 |  |  |  |       if (*jlbl != (yamop *)&(ap->cs.p_code.ExpandCode)) { | 
					
						
							|  |  |  |  | 	ipc = *jlbl; | 
					
						
							| 
									
										
										
										
											2004-02-18 01:43:32 +00:00
										 |  |  |  | 	break; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |  |       ipc = ExpandIndex(ap, 0, CP PASS_REGS); | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       break; | 
					
						
							|  |  |  |  |     case _op_fail: | 
					
						
							|  |  |  |  |       ipc = alt; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  |  |     case _lock_pred: | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     case _index_pred: | 
					
						
							|  |  |  |  |     case _spy_pred: | 
					
						
							| 
									
										
										
										
											2010-01-29 15:21:00 +00:00
										 |  |  |  |       Yap_IPred(ap, 0, CP); | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |       ipc = ap->cs.p_code.TrueCodeOfPred; | 
					
						
							|  |  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  |     case _undef_p: | 
					
						
							| 
									
										
										
										
											2003-12-01 19:22:01 +00:00
										 |  |  |  |     default: | 
					
						
							|  |  |  |  |       return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  | void | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | Yap_CleanUpIndex(LogUpdIndex *blk) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   /* just compact the code */ | 
					
						
							| 
									
										
										
										
											2012-02-17 15:04:25 +00:00
										 |  |  |  |   yamop *start = blk->ClCode; | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   op_numbers op = Yap_op_from_opcode(start->opc); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   blk->ClFlags &= ~DirtyMask; | 
					
						
							| 
									
										
										
										
											2006-10-16 17:12:48 +00:00
										 |  |  |  |   while (op == _lock_lu) { | 
					
						
							|  |  |  |  |     start = NEXTOP(start, p); | 
					
						
							|  |  |  |  |     op = Yap_op_from_opcode(start->opc); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-10-10 14:08:17 +00:00
										 |  |  |  |   while (op == _jump_if_nonvar) { | 
					
						
							|  |  |  |  |     start = NEXTOP(start, xll); | 
					
						
							|  |  |  |  |     op = Yap_op_from_opcode(start->opc); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-12-27 01:32:38 +00:00
										 |  |  |  |   remove_dirty_clauses_from_index(start); | 
					
						
							| 
									
										
										
										
											2003-09-15 01:25:29 +00:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |  | 
 |