| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  | *	 YAP Prolog 							 * | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | *	Yap Prolog was developed at NCCUP - Universidade do Porto	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  | * Copyright L.Damas, V.Santos Costa and Universidade do Porto 1985--	 * | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | *									 * | 
					
						
							|  |  |  | ************************************************************************** | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * File:		c_interface.c						 * | 
					
						
							|  |  |  | * comments:	c_interface primitives definition 			 * | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  | * Last rev:	$Date: 2008-08-07 20:51:21 $,$Author: vsc $						 * | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | * $Log: not supported by cvs2svn $ | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  | * Revision 1.122  2008/08/01 21:44:24  vsc | 
					
						
							|  |  |  | * swi compatibility support | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-08-01 21:44:25 +00:00
										 |  |  | * Revision 1.121  2008/07/24 16:02:00  vsc | 
					
						
							|  |  |  | * improve C-interface and SWI comptaibility a bit. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | * Revision 1.120  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.119  2008/06/17 13:37:48  vsc | 
					
						
							|  |  |  | * fix c_interface not to crash when people try to recover slots that are | 
					
						
							|  |  |  | * not there. | 
					
						
							|  |  |  | * fix try_logical and friends to handle case where predicate has arity 0. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-06-17 13:37:51 +00:00
										 |  |  | * Revision 1.118  2008/06/04 14:47:18  vsc | 
					
						
							|  |  |  | * make sure we do trim_trail whenever we mess with B! | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-06-04 14:47:18 +00:00
										 |  |  | * Revision 1.117  2008/06/04 13:58:36  vsc | 
					
						
							|  |  |  | * more fixes to C-interface | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  | * Revision 1.116  2008/04/28 23:02:32  vsc | 
					
						
							|  |  |  | * fix bug in current_predicate/2 | 
					
						
							|  |  |  | * fix bug in c_interface. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-28 23:02:32 +00:00
										 |  |  | * Revision 1.115  2008/04/11 16:30:27  ricroc | 
					
						
							|  |  |  | * *** empty log message *** | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-11 16:30:28 +00:00
										 |  |  | * Revision 1.114  2008/04/04 13:35:41  vsc | 
					
						
							|  |  |  | * fix duplicate dependency frame at entry | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-04 13:35:41 +00:00
										 |  |  | * Revision 1.113  2008/04/04 09:10:02  vsc | 
					
						
							|  |  |  | * restore was restoring twice | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-04 09:10:02 +00:00
										 |  |  | * Revision 1.112  2008/04/03 13:26:38  vsc | 
					
						
							|  |  |  | * protect signal handling with locks for threaded version. | 
					
						
							|  |  |  | * fix close/1 entry in manual (obs from Nicos). | 
					
						
							|  |  |  | * fix -f option in chr Makefile. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-03 13:26:38 +00:00
										 |  |  | * Revision 1.111  2008/04/02 21:44:07  vsc | 
					
						
							|  |  |  | * threaded version should ignore saved states (for now). | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-02 21:44:07 +00:00
										 |  |  | * Revision 1.110  2008/04/02 17:37:06  vsc | 
					
						
							|  |  |  | * handle out of memory error at thread creation (obs from Paulo Moura). | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-02 17:37:07 +00:00
										 |  |  | * Revision 1.109  2008/04/01 15:31:41  vsc | 
					
						
							|  |  |  | * more saved state fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-04-01 15:31:43 +00:00
										 |  |  | * Revision 1.108  2008/03/22 23:35:00  vsc | 
					
						
							|  |  |  | * fix bug in all_calls | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-03-22 23:35:00 +00:00
										 |  |  | * Revision 1.107  2008/03/13 18:41:50  vsc | 
					
						
							|  |  |  | * -q flag | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-03-13 18:41:52 +00:00
										 |  |  | * Revision 1.106  2008/02/12 17:03:50  vsc | 
					
						
							|  |  |  | * SWI-portability changes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-02-12 17:03:59 +00:00
										 |  |  | * Revision 1.105  2008/01/28 10:42:19  vsc | 
					
						
							|  |  |  | * fix BOM trouble | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2008-01-28 10:42:20 +00:00
										 |  |  | * Revision 1.104  2007/12/05 12:17:23  vsc | 
					
						
							|  |  |  | * improve JT | 
					
						
							|  |  |  | * fix graph compatibility with SICStus | 
					
						
							|  |  |  | * re-export declaration. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | * Revision 1.103  2007/11/16 14:58:40  vsc | 
					
						
							|  |  |  | * implement sophisticated operations with matrices. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-16 14:58:41 +00:00
										 |  |  | * Revision 1.102  2007/11/01 20:50:31  vsc | 
					
						
							|  |  |  | * fix YAP_LeaveGoal (again) | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-01 20:50:31 +00:00
										 |  |  | * Revision 1.101  2007/10/29 22:48:54  vsc | 
					
						
							|  |  |  | * small fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-29 22:48:54 +00:00
										 |  |  | * Revision 1.100  2007/10/28 00:54:09  vsc | 
					
						
							|  |  |  | * new version of viterbi implementation | 
					
						
							|  |  |  | * fix all:atvars reporting bad info | 
					
						
							|  |  |  | * fix bad S info in x86_64 | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  | * Revision 1.99  2007/10/16 18:57:17  vsc | 
					
						
							|  |  |  | * get rid of debug statement. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-16 18:57:17 +00:00
										 |  |  | * Revision 1.98  2007/10/15 23:48:46  vsc | 
					
						
							|  |  |  | * unset var | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-15 23:48:46 +00:00
										 |  |  | * Revision 1.97  2007/10/05 18:24:30  vsc | 
					
						
							|  |  |  | * fix garbage collector and fix LeaveGoal | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-10-05 18:24:30 +00:00
										 |  |  | * Revision 1.96  2007/09/04 10:34:54  vsc | 
					
						
							|  |  |  | * Improve SWI interface emulation. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | * Revision 1.95  2007/06/04 12:28:01  vsc | 
					
						
							|  |  |  | * interface speedups | 
					
						
							|  |  |  | * bad error message in X is foo>>2. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | * Revision 1.94  2007/05/15 11:33:51  vsc | 
					
						
							|  |  |  | * fix min list | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-05-15 11:33:51 +00:00
										 |  |  | * Revision 1.93  2007/05/14 16:44:11  vsc | 
					
						
							|  |  |  | * improve external interface | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | * Revision 1.92  2007/04/18 23:01:16  vsc | 
					
						
							|  |  |  | * fix deadlock when trying to create a module with the same name as a | 
					
						
							|  |  |  | * predicate (for now, just don't lock modules). obs Paulo Moura. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-04-18 23:01:16 +00:00
										 |  |  | * Revision 1.91  2007/03/30 16:47:22  vsc | 
					
						
							|  |  |  | * fix gmpless blob handling | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-03-30 16:47:22 +00:00
										 |  |  | * Revision 1.90  2007/03/22 11:12:20  vsc | 
					
						
							|  |  |  | * make sure that YAP_Restart does not restart a failed goal. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  | * Revision 1.89  2007/01/28 14:26:36  vsc | 
					
						
							|  |  |  | * WIN32 support | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  | * Revision 1.88  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.87  2006/12/13 16:10:14  vsc | 
					
						
							|  |  |  | * several debugger and CLP(BN) improvements. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  | * Revision 1.86  2006/11/27 17:42:02  vsc | 
					
						
							|  |  |  | * support for UNICODE, and other bug fixes. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | * Revision 1.85  2006/05/16 18:37:30  vsc | 
					
						
							|  |  |  | * WIN32 fixes | 
					
						
							|  |  |  | * compiler bug fixes | 
					
						
							|  |  |  | * extend interface | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | * Revision 1.84  2006/03/09 15:52:04  tiagosoares | 
					
						
							|  |  |  | * CUT_C and MYDDAS support for 64 bits architectures | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-09 15:52:06 +00:00
										 |  |  | * Revision 1.83  2006/02/08 17:29:54  tiagosoares | 
					
						
							|  |  |  | * MYDDAS: Myddas Top Level for MySQL and Datalog | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  | * Revision 1.82  2006/01/18 15:34:53  vsc | 
					
						
							|  |  |  | * avoid sideffects from MkBigInt | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-01-18 15:34:54 +00:00
										 |  |  | * Revision 1.81  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.80  2006/01/02 03:35:44  vsc | 
					
						
							|  |  |  | * fix interface and docs | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-01-02 03:35:45 +00:00
										 |  |  | * Revision 1.79  2006/01/02 02:25:44  vsc | 
					
						
							|  |  |  | * cannot release space from external GMPs. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-01-02 02:25:45 +00:00
										 |  |  | * Revision 1.78  2006/01/02 02:16:18  vsc | 
					
						
							|  |  |  | * support new interface between YAP and GMP, so that we don't rely on our own | 
					
						
							|  |  |  | * allocation routines. | 
					
						
							|  |  |  | * Several big fixes. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | * Revision 1.77  2005/11/18 18:48:51  tiagosoares | 
					
						
							|  |  |  | * support for executing c code when a cut occurs | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | * Revision 1.76  2005/11/03 18:49:26  vsc | 
					
						
							|  |  |  | * fix bignum conversion | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-11-03 18:49:26 +00:00
										 |  |  | * Revision 1.75  2005/10/28 17:38:49  vsc | 
					
						
							|  |  |  | * sveral updates | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-28 17:38:50 +00:00
										 |  |  | * Revision 1.74  2005/10/21 16:07:07  vsc | 
					
						
							|  |  |  | * fix tabling | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  | * Revision 1.73  2005/10/18 17:04:43  vsc | 
					
						
							|  |  |  | * 5.1: | 
					
						
							|  |  |  | * - improvements to GC | 
					
						
							|  |  |  | *    2 generations | 
					
						
							|  |  |  | *    generic speedups | 
					
						
							|  |  |  | * - new scheme for attvars | 
					
						
							|  |  |  | *    - hProlog like interface also supported | 
					
						
							|  |  |  | * - SWI compatibility layer | 
					
						
							|  |  |  | *    - extra predicates | 
					
						
							|  |  |  | *    - global variables | 
					
						
							|  |  |  | *    - moved to Prolog module | 
					
						
							|  |  |  | * - CLP(R) by Leslie De Koninck, Tom Schrijvers, Cristian Holzbaur, Bart | 
					
						
							|  |  |  | * Demoen and Jan Wielemacker | 
					
						
							|  |  |  | * - load_files/2 | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * from 5.0.1 | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * - WIN32 missing include files (untested) | 
					
						
							|  |  |  | * - -L trouble (my thanks to Takeyuchi Shiramoto-san)! | 
					
						
							|  |  |  | * - debugging of backtrable user-C preds would core dump. | 
					
						
							|  |  |  | * - redeclaring a C-predicate as Prolog core dumps. | 
					
						
							|  |  |  | * - badly protected  YapInterface.h. | 
					
						
							|  |  |  | * - break/0 was failing at exit. | 
					
						
							|  |  |  | * - YAP_cut_fail and YAP_cut_succeed were different from manual. | 
					
						
							|  |  |  | * - tracing through data-bases could core dump. | 
					
						
							|  |  |  | * - cut could break on very large computations. | 
					
						
							|  |  |  | * - first pass at BigNum issues (reported by Roberto). | 
					
						
							|  |  |  | * - debugger could get go awol after fail port. | 
					
						
							|  |  |  | * - weird message on wrong debugger option. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-18 17:04:43 +00:00
										 |  |  | * Revision 1.72  2005/10/15 02:42:57  vsc | 
					
						
							|  |  |  | * fix interface | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-15 02:42:57 +00:00
										 |  |  | * Revision 1.71  2005/08/17 13:35:51  vsc | 
					
						
							|  |  |  | * YPP would leave exceptions on the system, disabling Yap-4.5.7 | 
					
						
							|  |  |  | * message. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-08-17 13:35:52 +00:00
										 |  |  | * Revision 1.70  2005/08/04 15:45:51  ricroc | 
					
						
							|  |  |  | * TABLING NEW: support to limit the table space size | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-08-04 15:45:56 +00:00
										 |  |  | * Revision 1.69  2005/07/19 17:12:18  rslopes | 
					
						
							|  |  |  | * fix for older compilers that do not support declaration of vars | 
					
						
							|  |  |  | * in the middle of the function code. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-07-19 17:12:18 +00:00
										 |  |  | * Revision 1.68  2005/05/31 00:23:47  ricroc | 
					
						
							|  |  |  | * remove abort_yapor function | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-05-31 00:23:47 +00:00
										 |  |  | * Revision 1.67  2005/04/10 04:35:19  vsc | 
					
						
							|  |  |  | * AllocMemoryFromYap should now handle large requests the right way. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-10 04:35:19 +00:00
										 |  |  | * Revision 1.66  2005/04/10 04:01:10  vsc | 
					
						
							|  |  |  | * bug fixes, I hope! | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  | * Revision 1.65  2005/03/15 18:29:23  vsc | 
					
						
							|  |  |  | * fix GPL | 
					
						
							|  |  |  | * fix idb: stuff in coroutines. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-15 18:29:25 +00:00
										 |  |  | * Revision 1.64  2005/03/13 06:26:10  vsc | 
					
						
							|  |  |  | * fix excessive pruning in meta-calls | 
					
						
							|  |  |  | * fix Term->int breakage in compiler | 
					
						
							|  |  |  | * improve JPL (at least it does something now for amd64). | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-13 06:26:13 +00:00
										 |  |  | * Revision 1.63  2005/03/04 20:30:10  ricroc | 
					
						
							|  |  |  | * bug fixes for YapTab support | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-04 20:30:14 +00:00
										 |  |  | * Revision 1.62  2005/03/02 18:35:44  vsc | 
					
						
							|  |  |  | * try to make initialisation process more robust | 
					
						
							|  |  |  | * try to make name more robust (in case Lookup new atom fails) | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  | * Revision 1.61  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.60  2005/02/08 18:04:47  vsc | 
					
						
							|  |  |  | * library_directory may not be deterministic (usually it isn't). | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-02-08 18:05:21 +00:00
										 |  |  | * Revision 1.59  2004/12/08 00:56:35  vsc | 
					
						
							|  |  |  | * missing ; | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-12-08 00:56:35 +00:00
										 |  |  | * Revision 1.58  2004/11/19 22:08:41  vsc | 
					
						
							|  |  |  | * replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-11-19 22:08:43 +00:00
										 |  |  | * Revision 1.57  2004/11/18 22:32:31  vsc | 
					
						
							|  |  |  | * fix situation where we might assume nonextsing double initialisation of C predicates (use | 
					
						
							|  |  |  | * Hidden Pred Flag). | 
					
						
							|  |  |  | * $host_type was double initialised. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-11-18 22:32:40 +00:00
										 |  |  | * Revision 1.56  2004/10/31 02:18:03  vsc | 
					
						
							|  |  |  | * fix bug in handling Yap heap overflow while adding new clause. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-31 02:18:04 +00:00
										 |  |  | * Revision 1.55  2004/10/28 20:12:20  vsc | 
					
						
							|  |  |  | * Use Doug Lea's malloc as an alternative to YAP's standard malloc | 
					
						
							|  |  |  | * don't use TR directly in scanner/parser, this avoids trouble with ^C while | 
					
						
							|  |  |  | * consulting large files. | 
					
						
							|  |  |  | * pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should | 
					
						
							|  |  |  | * compile out of the box now). | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-28 20:12:23 +00:00
										 |  |  | * Revision 1.54  2004/10/06 16:55:46  vsc | 
					
						
							|  |  |  | * change configure to support big mem configs | 
					
						
							|  |  |  | * get rid of extra globals | 
					
						
							|  |  |  | * fix trouble with multifile preds | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-10-06 16:55:48 +00:00
										 |  |  | * Revision 1.53  2004/08/11 16:14:51  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.52  2004/07/23 03:37:16  vsc | 
					
						
							|  |  |  | * fix heap overflow in YAP_LookupAtom | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-07-23 03:37:17 +00:00
										 |  |  | * Revision 1.51  2004/07/22 21:32:20  vsc | 
					
						
							|  |  |  | * debugger fixes | 
					
						
							|  |  |  | * initial support for JPL | 
					
						
							|  |  |  | * bad calls to garbage collector and gc | 
					
						
							|  |  |  | * debugger fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | * Revision 1.50  2004/06/29 19:04:41  vsc | 
					
						
							|  |  |  | * fix multithreaded version | 
					
						
							|  |  |  | * include new version of Ricardo's profiler | 
					
						
							|  |  |  | * new predicat atomic_concat | 
					
						
							|  |  |  | * allow multithreaded-debugging | 
					
						
							|  |  |  | * small fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  | * Revision 1.49  2004/06/09 03:32:02  vsc | 
					
						
							|  |  |  | * fix bugs | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-09 03:32:03 +00:00
										 |  |  | * Revision 1.48  2004/06/05 03:36:59  vsc | 
					
						
							|  |  |  | * coroutining is now a part of attvars. | 
					
						
							|  |  |  | * some more fixes. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-05 03:37:01 +00:00
										 |  |  | * Revision 1.47  2004/05/17 21:42:08  vsc | 
					
						
							|  |  |  | * misc fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-05-17 21:42:12 +00:00
										 |  |  | * Revision 1.46  2004/05/14 17:56:45  vsc | 
					
						
							|  |  |  | * Yap_WriteBuffer | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-05-14 17:56:47 +00:00
										 |  |  | * Revision 1.45  2004/05/14 17:11:30  vsc | 
					
						
							|  |  |  | * support BigNums in interface | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | * Revision 1.44  2004/05/14 16:33:44  vsc | 
					
						
							|  |  |  | * add Yap_ReadBuffer | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | *************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define Bool int
 | 
					
						
							|  |  |  | #define flt double
 | 
					
						
							|  |  |  | #define C_INTERFACE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-22 14:01:22 -05:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #include "Yap.h"
 | 
					
						
							| 
									
										
										
										
											2002-12-27 16:53:09 +00:00
										 |  |  | #include "clause.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #include "yapio.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | #include "attvar.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-25 13:10:39 +01:00
										 |  |  | #include "SWI-Stream.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  | #if HAVE_STDARG_H
 | 
					
						
							|  |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-02-10 21:45:43 +00:00
										 |  |  | #if HAVE_STDINT_H
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | #if HAVE_STRING_H
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-02-24 14:11:54 +00:00
										 |  |  | #if _MSC_VER || defined(__MINGW32__) 
 | 
					
						
							|  |  |  | #include <windows.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-01-08 16:45:35 +00:00
										 |  |  | #include "iopreds.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #include "yap_structs.h"
 | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  | #ifdef TABLING
 | 
					
						
							|  |  |  | #include "tab.macros.h"
 | 
					
						
							|  |  |  | #endif /* TABLING */
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef YAPOR
 | 
					
						
							|  |  |  | #include "or.macros.h"
 | 
					
						
							|  |  |  | #endif	/* YAPOR */
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | #include "threads.h"
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  | #include "cut_c.h"
 | 
					
						
							|  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | #if HAVE_MALLOC_H
 | 
					
						
							|  |  |  | #include <malloc.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  | #if !HAVE_STRNCPY
 | 
					
						
							|  |  |  | #define strncpy(X,Y,Z) strcpy(X,Y)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-03-05 09:51:52 +00:00
										 |  |  | #if !HAVE_STRNCAT
 | 
					
						
							|  |  |  | #define strncat(X,Y,Z) strcat(X,Y)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-04 16:12:54 +00:00
										 |  |  | #if defined(_MSC_VER) && defined(YAP_EXPORTS)
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #define X_API __declspec(dllexport)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define X_API
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_A,(int)); | 
					
						
							| 
									
										
										
										
											2002-09-16 23:25:09 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_Deref,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkVarTerm,(void)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsVarTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsNonVarTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsIntTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2009-11-23 18:46:57 +00:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsLongIntTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsBigNumTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsNumberTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-02-27 02:13:25 -08:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsRationalTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsFloatTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsDbRefTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsAtomTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsPairTerm,(Term)); | 
					
						
							|  |  |  | X_API Bool    STD_PROTO(YAP_IsApplTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsCompoundTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-07-21 06:32:49 -07:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsExternalDataInStackTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-07-22 04:09:33 -07:00
										 |  |  | X_API Bool    STD_PROTO(YAP_IsOpaqueObjectTerm,(Term, int)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkIntTerm,(Int)); | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkBigNumTerm,(void *)); | 
					
						
							| 
									
										
										
										
											2011-02-27 02:13:25 -08:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkRationalTerm,(void *)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_IntOfTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_BigNumOfTerm,(Term, void *)); | 
					
						
							| 
									
										
										
										
											2011-02-27 02:13:25 -08:00
										 |  |  | X_API void    STD_PROTO(YAP_RationalOfTerm,(Term, void *)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkFloatTerm,(flt)); | 
					
						
							|  |  |  | X_API flt     STD_PROTO(YAP_FloatOfTerm,(Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_MkAtomTerm,(Atom)); | 
					
						
							|  |  |  | X_API Atom    STD_PROTO(YAP_AtomOfTerm,(Term)); | 
					
						
							|  |  |  | X_API Atom    STD_PROTO(YAP_LookupAtom,(char *)); | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API Atom    STD_PROTO(YAP_LookupWideAtom,(wchar_t *)); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | X_API size_t  STD_PROTO(YAP_AtomNameLength,(Atom)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Atom    STD_PROTO(YAP_FullLookupAtom,(char *)); | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_IsWideAtom,(Atom)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API char   *STD_PROTO(YAP_AtomName,(Atom)); | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API wchar_t *STD_PROTO(YAP_WideAtomName,(Atom)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkPairTerm,(Term,Term)); | 
					
						
							| 
									
										
										
										
											2011-11-18 16:26:11 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkListFromTerms,(Term *,Int)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkNewPairTerm,(void)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_HeadOfTerm,(Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_TailOfTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_SkipList,(Term *, Term **)); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API Term    STD_PROTO(YAP_MkApplTerm,(Functor,UInt,Term *)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_MkNewApplTerm,(Functor,UInt)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Functor STD_PROTO(YAP_FunctorOfTerm,(Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_ArgOfTerm,(Int,Term)); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | X_API Term   *STD_PROTO(YAP_ArgsOfTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Functor STD_PROTO(YAP_MkFunctor,(Atom,Int)); | 
					
						
							|  |  |  | X_API Atom    STD_PROTO(YAP_NameOfFunctor,(Functor)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_ArityOfFunctor,(Functor)); | 
					
						
							|  |  |  | X_API void   *STD_PROTO(YAP_ExtraSpace,(void)); | 
					
						
							| 
									
										
										
										
											2005-10-18 17:04:43 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_cut_up,(void)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_Unify,(Term,Term)); | 
					
						
							| 
									
										
										
										
											2011-10-27 12:35:40 +02:00
										 |  |  | X_API int     STD_PROTO(YAP_Unifiable,(Term,Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_Reset,(void)); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Int     STD_PROTO(YAP_ListLength,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_Init,(YAP_init_args *)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_FastInit,(char *)); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | X_API PredEntry *STD_PROTO(YAP_FunctorToPred,(Functor)); | 
					
						
							|  |  |  | X_API PredEntry *STD_PROTO(YAP_AtomToPred,(Atom)); | 
					
						
							| 
									
										
										
										
											2012-07-13 14:57:12 -05:00
										 |  |  | X_API PredEntry *STD_PROTO(YAP_FunctorToPredInModule,(Functor, Term)); | 
					
						
							|  |  |  | X_API PredEntry *STD_PROTO(YAP_AtomToPredInModule,(Atom, Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_CallProlog,(Term)); | 
					
						
							|  |  |  | X_API void   *STD_PROTO(YAP_AllocSpaceFromYap,(unsigned int)); | 
					
						
							| 
									
										
										
										
											2009-11-19 21:09:22 +00:00
										 |  |  | X_API void   *STD_PROTO(YAP_ReallocSpaceFromYap,(void*,unsigned int)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_FreeSpaceFromYap,(void *)); | 
					
						
							|  |  |  | X_API int     STD_PROTO(YAP_StringToBuffer, (Term, char *, unsigned int)); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_ReadBuffer, (char *,Term *)); | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_FloatsToList, (double *, size_t)); | 
					
						
							| 
									
										
										
										
											2012-03-14 11:08:28 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_ListToFloats, (Term, double *, size_t)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_IntsToList, (Int *, size_t)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_ListToInts, (Term, Int *, size_t)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_BufferToString, (char *)); | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_NBufferToString, (char *, size_t)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_WideBufferToString, (wchar_t *)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_NWideBufferToString, (wchar_t *, size_t)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_BufferToAtomList, (char *)); | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_NBufferToAtomList, (char *,size_t)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_WideBufferToAtomList, (wchar_t *)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_NWideBufferToAtomList, (wchar_t *, size_t)); | 
					
						
							| 
									
										
										
										
											2008-12-17 14:47:05 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_NWideBufferToAtomDiffList, (wchar_t *, Term, size_t)); | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_BufferToDiffList, (char *, Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_NBufferToDiffList, (char *, Term, size_t)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_WideBufferToDiffList, (wchar_t *, Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_NWideBufferToDiffList, (wchar_t *, Term, size_t)); | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_Error,(int, Term, char *, ...)); | 
					
						
							| 
									
										
										
										
											2011-12-13 23:09:05 +00:00
										 |  |  | X_API Int     STD_PROTO(YAP_RunGoal,(Term)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_RunGoalOnce,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_RestartGoal,(void)); | 
					
						
							| 
									
										
										
										
											2007-05-15 11:33:51 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_ShutdownGoal,(int)); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_EnterGoal,(PredEntry *, Term *, YAP_dogoalinfo *)); | 
					
						
							|  |  |  | X_API int     STD_PROTO(YAP_RetryGoal,(YAP_dogoalinfo *)); | 
					
						
							|  |  |  | X_API int     STD_PROTO(YAP_LeaveGoal,(int, YAP_dogoalinfo *)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_GoalHasException,(Term *)); | 
					
						
							| 
									
										
										
										
											2005-08-17 13:35:52 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_ClearExceptions,(void)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_ContinueGoal,(void)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_PruneGoal,(void)); | 
					
						
							| 
									
										
										
										
											2011-05-25 13:10:39 +01:00
										 |  |  | X_API IOSTREAM   *STD_PROTO(YAP_TermToStream,(Term)); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  | X_API IOSTREAM   *STD_PROTO(YAP_InitConsult,(int, char *)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_EndConsult,(IOSTREAM *)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_Read, (IOSTREAM *)); | 
					
						
							| 
									
										
										
										
											2011-07-22 15:49:40 +01:00
										 |  |  | X_API void    STD_PROTO(YAP_Write, (Term, IOSTREAM *, int)); | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_CopyTerm, (Term)); | 
					
						
							| 
									
										
										
										
											2004-05-14 17:56:47 +00:00
										 |  |  | X_API Term    STD_PROTO(YAP_WriteBuffer, (Term, char *, unsigned int, int)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API char   *STD_PROTO(YAP_CompileClause, (Term)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_PutValue, (Atom,Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_GetValue, (Atom)); | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_CompareTerms, (Term,Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_Exit, (int)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_InitSocks, (char *, long)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_SetOutputMessage, (void)); | 
					
						
							|  |  |  | X_API int     STD_PROTO(YAP_StreamToFileNo, (Term)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_CloseAllOpenStreams,(void)); | 
					
						
							| 
									
										
										
										
											2008-07-11 17:02:10 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_FlushAllStreams,(void)); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API Int     STD_PROTO(YAP_CurrentSlot,(void)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_NewSlots,(int)); | 
					
						
							|  |  |  | X_API Int     STD_PROTO(YAP_InitSlot,(Term)); | 
					
						
							|  |  |  | X_API Term    STD_PROTO(YAP_GetFromSlot,(Int)); | 
					
						
							|  |  |  | X_API Term   *STD_PROTO(YAP_AddressFromSlot,(Int)); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | X_API Term   *STD_PROTO(YAP_AddressOfTermInSlot,(Int)); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API void    STD_PROTO(YAP_PutInSlot,(Int, Term)); | 
					
						
							| 
									
										
										
										
											2008-06-17 13:37:51 +00:00
										 |  |  | X_API int     STD_PROTO(YAP_RecoverSlots,(int)); | 
					
						
							| 
									
										
										
										
											2010-08-04 17:36:20 +01:00
										 |  |  | X_API Int     STD_PROTO(YAP_ArgsToSlots,(int)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_SlotsToArgs,(int, Int)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_Throw,(Term)); | 
					
						
							| 
									
										
										
										
											2010-12-04 19:05:13 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_AsyncThrow,(Term)); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API void    STD_PROTO(YAP_Halt,(int)); | 
					
						
							|  |  |  | X_API Term   *STD_PROTO(YAP_TopOfLocalStack,(void)); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API void   *STD_PROTO(YAP_Predicate,(Atom,UInt,Term)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_PredicateInfo,(void *,Atom *,UInt *,Term *)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_UserCPredicate,(char *,CPredicate,UInt)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_UserBackCPredicate,(char *,CPredicate,CPredicate,UInt,unsigned int)); | 
					
						
							|  |  |  | X_API void    STD_PROTO(YAP_UserCPredicateWithArgs,(char *,CPredicate,UInt,Term)); | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API void    STD_PROTO(YAP_UserBackCutCPredicate,(char *,CPredicate,CPredicate,CPredicate,UInt,unsigned int)); | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | X_API void   *STD_PROTO(YAP_ExtraSpaceCut,(void)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-02-14 14:13:45 -08:00
										 |  |  | X_API Term     STD_PROTO(YAP_SetCurrentModule,(Term)); | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_CurrentModule,(void)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_CreateModule,(Atom)); | 
					
						
							| 
									
										
										
										
											2008-08-01 21:44:25 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_StripModule,(Term, Term *)); | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | X_API int      STD_PROTO(YAP_ThreadSelf,(void)); | 
					
						
							| 
									
										
										
										
											2010-07-23 15:54:13 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_ThreadCreateEngine,(struct thread_attr_struct *)); | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | X_API int      STD_PROTO(YAP_ThreadAttachEngine,(int)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_ThreadDetachEngine,(int)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_ThreadDestroyEngine,(int)); | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_MkBlobTerm,(unsigned int)); | 
					
						
							|  |  |  | X_API void    *STD_PROTO(YAP_BlobOfTerm,(Term)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_TermNil,(void)); | 
					
						
							| 
									
										
										
										
											2011-10-24 22:46:16 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_IsTermNil,(Term)); | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | X_API int      STD_PROTO(YAP_AtomGetHold,(Atom)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_AtomReleaseHold,(Atom)); | 
					
						
							| 
									
										
										
										
											2008-02-12 17:03:59 +00:00
										 |  |  | X_API Agc_hook STD_PROTO(YAP_AGCRegisterHook,(Agc_hook)); | 
					
						
							| 
									
										
										
										
											2010-09-24 14:00:53 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_HaltRegisterHook,(HaltHookFunc, void *)); | 
					
						
							| 
									
										
										
										
											2008-12-17 14:47:05 +00:00
										 |  |  | X_API char    *STD_PROTO(YAP_cwd,(void)); | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_OpenList,(int)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_ExtendList,(Term, Term)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_CloseList,(Term, Term)); | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | X_API int      STD_PROTO(YAP_IsAttVar,(Term)); | 
					
						
							| 
									
										
										
										
											2009-03-14 10:06:55 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_AttsOfVar,(Term)); | 
					
						
							| 
									
										
										
										
											2009-04-22 21:42:15 -05:00
										 |  |  | X_API int      STD_PROTO(YAP_FileNoFromStream,(Term)); | 
					
						
							| 
									
										
										
										
											2009-04-22 16:41:41 -05:00
										 |  |  | X_API void    *STD_PROTO(YAP_FileDescriptorFromStream,(Term)); | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | X_API void    *STD_PROTO(YAP_Record,(Term)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_Recorded,(void *)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_Erase,(void *)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_Variant,(Term, Term)); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Int      STD_PROTO(YAP_NumberVars,(Term, Int)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_UnNumberVars,(Term)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_IsNumberedVariable,(Term)); | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_ExactlyEqual,(Term, Term)); | 
					
						
							|  |  |  | X_API Int      STD_PROTO(YAP_TermHash,(Term, Int, Int, int)); | 
					
						
							| 
									
										
										
										
											2011-02-03 11:26:46 +00:00
										 |  |  | X_API void     STD_PROTO(YAP_signal,(int)); | 
					
						
							| 
									
										
										
										
											2010-08-30 22:25:56 -05:00
										 |  |  | X_API int      STD_PROTO(YAP_SetYAPFlag,(yap_flag_t, int)); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | X_API Int      STD_PROTO(YAP_VarSlotToNumber,(Int)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_ModuleUser,(void)); | 
					
						
							|  |  |  | X_API Int      STD_PROTO(YAP_NumberOfClausesForPredicate,(PredEntry *)); | 
					
						
							| 
									
										
										
										
											2011-02-10 21:14:38 +00:00
										 |  |  | X_API int      STD_PROTO(YAP_MaxOpPriority,(Atom, Term)); | 
					
						
							|  |  |  | X_API int      STD_PROTO(YAP_OpInfo,(Atom, Term, int, int *, int *)); | 
					
						
							| 
									
										
										
										
											2011-07-21 06:32:49 -07:00
										 |  |  | X_API Term     STD_PROTO(YAP_AllocExternalDataInStack,(size_t)); | 
					
						
							|  |  |  | X_API void    *STD_PROTO(YAP_ExternalDataInStackFromTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-07-22 04:09:33 -07:00
										 |  |  | X_API int      STD_PROTO(YAP_NewOpaqueType,(void *)); | 
					
						
							|  |  |  | X_API Term     STD_PROTO(YAP_NewOpaqueObject,(int, size_t)); | 
					
						
							|  |  |  | X_API void    *STD_PROTO(YAP_OpaqueObjectFromTerm,(Term)); | 
					
						
							| 
									
										
										
										
											2011-10-13 16:46:39 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_Argv,(char *** argvp)); | 
					
						
							| 
									
										
										
										
											2012-02-02 09:58:05 +00:00
										 |  |  | X_API YAP_tag_t STD_PROTO(YAP_TagOfTerm,(Term)); | 
					
						
							|  |  |  | X_API size_t   STD_PROTO(YAP_ExportTerm,(Term, char *, size_t)); | 
					
						
							| 
									
										
										
										
											2012-02-03 16:31:49 +00:00
										 |  |  | X_API size_t   STD_PROTO(YAP_SizeOfExportedTerm,(char *)); | 
					
						
							| 
									
										
										
										
											2012-02-01 19:26:28 +00:00
										 |  |  | X_API Term     STD_PROTO(YAP_ImportTerm,(char *)); | 
					
						
							| 
									
										
										
										
											2012-03-30 09:49:36 +01:00
										 |  |  | X_API int      STD_PROTO(YAP_RequiresExtraStack,(size_t)); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  | static UInt | 
					
						
							|  |  |  | current_arity(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-07 15:18:43 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |  if (P && PREVOP(P,Osbpp)->opc == Yap_opcode(_call_usercpred)) { | 
					
						
							|  |  |  |     return PREVOP(P,Osbpp)->u.Osbpp.p->ArityOfPE; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  | dogc( int extra_args, Term *tp USES_REGS ) | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   UInt arity; | 
					
						
							| 
									
										
										
										
											2011-10-01 13:00:00 -07:00
										 |  |  |   yamop *nextpc; | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |   if (P && PREVOP(P,Osbpp)->opc == Yap_opcode(_call_usercpred)) { | 
					
						
							|  |  |  |     arity = PREVOP(P,Osbpp)->u.Osbpp.p->ArityOfPE; | 
					
						
							| 
									
										
										
										
											2011-10-01 13:00:00 -07:00
										 |  |  |     nextpc = P; | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     arity = 0; | 
					
						
							| 
									
										
										
										
											2011-10-01 13:00:00 -07:00
										 |  |  |     nextpc = CP; | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |   for (i=0; i < extra_args; i++) { | 
					
						
							|  |  |  |     XREGS[arity+i+1] = tp[i]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (!Yap_gc(arity+extra_args, ENV, nextpc)) { | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |   for (i=0; i < extra_args; i++) { | 
					
						
							|  |  |  |      tp[i] = XREGS[arity+i+1]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | doexpand(UInt sz) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   UInt arity; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |   if (P && PREVOP(P,Osbpp)->opc == Yap_opcode(_call_usercpred)) { | 
					
						
							|  |  |  |     arity = PREVOP(P,Osbpp)->u.Osbpp.p->ArityOfPE; | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     arity = 0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-08-28 04:43:00 +01:00
										 |  |  |   if (!Yap_gcl(sz, arity, ENV, gc_P(P,CP))) { | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_A(int i) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   return(Deref(XREGS[i])); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-16 23:25:09 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_Deref(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return(Deref(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsIntTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  |   return IsIntegerTerm(t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Bool  | 
					
						
							|  |  |  | YAP_IsNumberTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return IsIntegerTerm(t) || IsIntTerm(t) || IsFloatTerm(t) || IsBigIntTerm(t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 18:46:57 +00:00
										 |  |  | X_API Bool  | 
					
						
							|  |  |  | YAP_IsLongIntTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return IsLongIntTerm(t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | X_API Bool  | 
					
						
							|  |  |  | YAP_IsBigNumTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							| 
									
										
										
										
											2011-02-27 02:13:25 -08:00
										 |  |  |   CELL *pt; | 
					
						
							|  |  |  |   if (IsVarTerm(t)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   if (!IsBigIntTerm(t)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   pt = RepAppl(t); | 
					
						
							|  |  |  |   return pt[1] == BIG_INT; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							|  |  |  | YAP_IsRationalTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							|  |  |  |   CELL *pt; | 
					
						
							|  |  |  |   if (IsVarTerm(t)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   if (!IsBigIntTerm(t)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   pt = RepAppl(t); | 
					
						
							|  |  |  |   return pt[1] == BIG_RATIONAL; | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |   return FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsVarTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsVarTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsNonVarTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsNonVarTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsFloatTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsFloatTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsDbRefTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsDBRefTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsAtomTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsAtomTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsPairTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsPairTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IsApplTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (IsApplTerm(t) && !IsExtensionFunctor(FunctorOfTerm(t))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | X_API Bool  | 
					
						
							|  |  |  | YAP_IsCompoundTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (IsApplTerm(t) && !IsExtensionFunctor(FunctorOfTerm(t))) || | 
					
						
							|  |  |  |     IsPairTerm(t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkIntTerm(Int n) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Term I; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   I = MkIntegerTerm(n); | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2006-01-16 02:57:52 +00:00
										 |  |  |   return I; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Int  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_IntOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (!IsApplTerm(t)) | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  |     return IntOfTerm(t); | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     return LongIntOfTerm(t); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term  | 
					
						
							|  |  |  | YAP_MkBigNumTerm(void *big) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							|  |  |  |   Term I; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:34:54 +00:00
										 |  |  |   I = Yap_MkBigIntTerm((MP_INT *)big); | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return I; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return TermNil; | 
					
						
							|  |  |  | #endif /* USE_GMP */
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | X_API void | 
					
						
							|  |  |  | YAP_BigNumOfTerm(Term t, void *b) | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |   MP_INT *bz = (MP_INT *)b; | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  |   if (IsVarTerm(t)) | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  |   if (!IsBigIntTerm(t)) | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2006-01-02 03:35:45 +00:00
										 |  |  |   mpz_set(bz,Yap_BigIntOfTerm(t)); | 
					
						
							| 
									
										
										
										
											2004-05-14 17:11:32 +00:00
										 |  |  | #endif /* USE_GMP */
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 02:13:25 -08:00
										 |  |  | X_API Term  | 
					
						
							|  |  |  | YAP_MkRationalTerm(void *big) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							|  |  |  |   Term I; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  |   I = Yap_MkBigRatTerm((MP_RAT *)big); | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return I; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return TermNil; | 
					
						
							|  |  |  | #endif /* USE_GMP */
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							|  |  |  | YAP_RationalOfTerm(Term t, void *b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_GMP
 | 
					
						
							|  |  |  |   MP_RAT *br = (MP_RAT *)b; | 
					
						
							|  |  |  |   if (IsVarTerm(t)) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   if (!IsBigIntTerm(t)) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   mpq_set(br,Yap_BigRatOfTerm(t)); | 
					
						
							|  |  |  | #endif /* USE_GMP */
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  | X_API Term  | 
					
						
							|  |  |  | YAP_MkBlobTerm(unsigned int sz) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   Term I; | 
					
						
							|  |  |  |   MP_INT *dst; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   while (H+(sz+sizeof(MP_INT)/sizeof(CELL)+2) > ASP-1024) { | 
					
						
							| 
									
										
										
										
											2008-10-29 18:19:15 +00:00
										 |  |  |     if (!doexpand((sz+sizeof(MP_INT)/sizeof(CELL)+2)*sizeof(CELL))) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       Yap_Error(OUT_OF_STACK_ERROR, TermNil, "YAP failed to grow the stack while constructing a blob: %s", LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |       return TermNil; | 
					
						
							| 
									
										
										
										
											2008-10-29 18:19:15 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-10-28 00:54:09 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-11-16 14:58:41 +00:00
										 |  |  |   I = AbsAppl(H); | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   H[0] = (CELL)FunctorBigInt; | 
					
						
							| 
									
										
										
										
											2011-02-02 19:37:11 +00:00
										 |  |  |   H[1] = ARRAY_INT; | 
					
						
							| 
									
										
										
										
											2008-11-28 15:54:46 +00:00
										 |  |  |   dst = (MP_INT *)(H+2); | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   dst->_mp_size = 0L; | 
					
						
							|  |  |  |   dst->_mp_alloc = sz; | 
					
						
							| 
									
										
										
										
											2009-03-14 10:06:55 +00:00
										 |  |  |   H += (2+sizeof(MP_INT)/sizeof(CELL)); | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   H[sz] = EndSpecials; | 
					
						
							|  |  |  |   H += sz+1; | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return I; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void * | 
					
						
							|  |  |  | YAP_BlobOfTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   MP_INT *src; | 
					
						
							| 
									
										
										
										
											2007-03-30 16:47:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   if (IsVarTerm(t)) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   if (!IsBigIntTerm(t)) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-03-14 10:06:55 +00:00
										 |  |  |   src = (MP_INT *)(RepAppl(t)+2); | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   return (void *)(src+1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkFloatTerm(double n) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = MkFloatTerm(n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API flt  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_FloatOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (FloatOfTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkAtomTerm(Atom n) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = MkAtomTerm(n); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Atom  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_AtomOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (AtomOfTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_IsWideAtom(Atom a) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return IsWideAtom(a); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API char           * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_AtomName(Atom a) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   char *o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   o = AtomName(a); | 
					
						
							|  |  |  |   return(o); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API wchar_t           * | 
					
						
							|  |  |  | YAP_WideAtomName(Atom a) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return RepAtom(a)->WStrOfAE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Atom | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_LookupAtom(char *c) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |   Atom a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |     a = Yap_LookupAtom(c); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     if (a == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) { | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |       if (!Yap_growheap(FALSE, 0, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return a; | 
					
						
							| 
									
										
										
										
											2004-07-23 03:37:17 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | X_API Atom | 
					
						
							|  |  |  | YAP_LookupWideAtom(wchar_t *c) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  |   Atom a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (TRUE) { | 
					
						
							|  |  |  |     a = Yap_LookupWideAtom(c); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     if (a == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) { | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  |       if (!Yap_growheap(FALSE, 0, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return a; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Atom | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_FullLookupAtom(char *c) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   Atom at; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |   while (TRUE) { | 
					
						
							|  |  |  |     at = Yap_FullLookupAtom(c); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     if (at == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) { | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |       if (!Yap_growheap(FALSE, 0, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2005-03-01 22:25:09 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return at; | 
					
						
							| 
									
										
										
										
											2004-07-23 03:37:17 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | X_API size_t | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  | YAP_AtomNameLength(Atom at) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |   if (IsBlob(at)) { | 
					
						
							|  |  |  |     return RepAtom(at)->rep.blob->length; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-04 10:34:55 +00:00
										 |  |  |   if (IsWideAtom(at)) { | 
					
						
							|  |  |  |     wchar_t *c = RepAtom(at)->WStrOfAE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return wcslen(c); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     char *c = RepAtom(at)->StrOfAE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return strlen(c); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkVarTerm(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   CELL t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = MkVarTerm(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkPairTerm(Term t1, Term t2) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |   while (H > ASP-1024) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     Int sl1 = Yap_InitSlot(t1 PASS_REGS); | 
					
						
							|  |  |  |     Int sl2 = Yap_InitSlot(t2 PASS_REGS); | 
					
						
							| 
									
										
										
										
											2011-10-01 13:00:00 -07:00
										 |  |  |     RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							| 
									
										
										
										
											2009-07-13 21:55:57 -05:00
										 |  |  |       return TermNil; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-01 13:00:00 -07:00
										 |  |  |     BACKUP_H(); | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     t1 =  Yap_GetFromSlot(sl1 PASS_REGS); | 
					
						
							|  |  |  |     t2 =  Yap_GetFromSlot(sl2 PASS_REGS); | 
					
						
							|  |  |  |     Yap_RecoverSlots(2 PASS_REGS); | 
					
						
							| 
									
										
										
										
											2009-07-13 21:55:57 -05:00
										 |  |  |   } | 
					
						
							|  |  |  |   t = MkPairTerm(t1, t2); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-18 16:26:11 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_MkListFromTerms(Term *ta, Int sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   CELL *h; | 
					
						
							|  |  |  |   if (sz == 0) | 
					
						
							|  |  |  |     return TermNil; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							| 
									
										
										
										
											2011-11-30 13:02:20 +00:00
										 |  |  |   while (H+sz*2 > ASP-1024) { | 
					
						
							| 
									
										
										
										
											2011-11-18 16:26:11 +00:00
										 |  |  |     Int sl1 = Yap_InitSlot((CELL)ta PASS_REGS); | 
					
						
							|  |  |  |     RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							| 
									
										
										
										
											2011-11-18 16:26:11 +00:00
										 |  |  |       return TermNil; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     BACKUP_H(); | 
					
						
							|  |  |  |     ta =  (CELL *)Yap_GetFromSlot(sl1 PASS_REGS); | 
					
						
							|  |  |  |     Yap_RecoverSlots(1 PASS_REGS); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   h = H; | 
					
						
							|  |  |  |   t = AbsPair(h); | 
					
						
							|  |  |  |   while (sz--) { | 
					
						
							|  |  |  |     Term ti = *ta++; | 
					
						
							|  |  |  |     if (IsVarTerm(ti)) { | 
					
						
							|  |  |  |       RESET_VARIABLE(h); | 
					
						
							|  |  |  |       Yap_unify(ti, h[0]); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       h[0] = ti; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     h[1] = AbsPair(h+2); | 
					
						
							|  |  |  |     h += 2; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   h[-1] = TermNil; | 
					
						
							|  |  |  |   H = h; | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkNewPairTerm() | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-16 14:58:41 +00:00
										 |  |  |   if (H > ASP-1024) | 
					
						
							|  |  |  |     t = TermNil; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     t = Yap_MkNewPairTerm(); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_HeadOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (HeadOfTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_TailOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (TailOfTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | YAP_SkipList(Term *l, Term **tailp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |   return Yap_SkipList(l, tailp); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |   Int length = 0; | 
					
						
							|  |  |  |   Term *s; /* slow */ | 
					
						
							|  |  |  |   Term v; /* temporary */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |   do_derefa(v,l,derefa_unk,derefa_nonvar); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |   s = l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ( IsPairTerm(*l) ) | 
					
						
							|  |  |  |   { intptr_t power = 1, lam = 0; | 
					
						
							|  |  |  |     do | 
					
						
							|  |  |  |     { if ( power == lam ) | 
					
						
							|  |  |  |       { s = l; | 
					
						
							|  |  |  | 	power *= 2; | 
					
						
							|  |  |  | 	lam = 0; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       lam++; | 
					
						
							|  |  |  |       length++; | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |       l = RepPair(*l)+1;  | 
					
						
							|  |  |  |       do_derefa(v,l,derefa2_unk,derefa2_nonvar); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |     } while ( *l != *s && IsPairTerm(*l) ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   *tailp = l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return length; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_MkApplTerm(Functor f,UInt arity, Term args[]) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-16 14:58:41 +00:00
										 |  |  |   if (H+arity > ASP-1024) | 
					
						
							|  |  |  |     t = TermNil; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     t = Yap_MkApplTerm(f, arity, args); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_MkNewApplTerm(Functor f,UInt arity) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-16 14:58:41 +00:00
										 |  |  |   if (H+arity > ASP-1024) | 
					
						
							|  |  |  |     t = TermNil; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     t = Yap_MkNewApplTerm(f, arity); | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Functor  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_FunctorOfTerm(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (FunctorOfTerm(t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_ArgOfTerm(Int n, Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (ArgOfTerm(n, t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | X_API Term * | 
					
						
							|  |  |  | YAP_ArgsOfTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (IsApplTerm(t)) | 
					
						
							|  |  |  |     return RepAppl(t)+1; | 
					
						
							|  |  |  |   else if (IsPairTerm(t)) | 
					
						
							|  |  |  |     return RepPair(t); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | X_API Functor  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_MkFunctor(Atom a, Int n) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   return (Yap_MkFunctor(a, n)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |  } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Atom  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_NameOfFunctor(Functor f) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (NameOfFunctor(f)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Int  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_ArityOfFunctor(Functor f) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return (ArityOfFunctor(f)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  | X_API void * | 
					
						
							|  |  |  | YAP_ExtraSpaceCut(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  |   void *ptr; | 
					
						
							|  |  |  |   BACKUP_B(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |   ptr = (void *)(((CELL *)(Yap_REGS.CUT_C_TOP))-(((yamop *)Yap_REGS.CUT_C_TOP->try_userc_cut_yamop)->u.OtapFs.extra)); | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_B(); | 
					
						
							|  |  |  |   return(ptr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /*CUT_C*/
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API void * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_ExtraSpace(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   void *ptr; | 
					
						
							|  |  |  |   BACKUP_B(); | 
					
						
							| 
									
										
										
										
											2008-01-28 10:42:20 +00:00
										 |  |  |   BACKUP_H(); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* find a pointer to extra space allocable */ | 
					
						
							| 
									
										
										
										
											2008-09-05 05:22:19 +01:00
										 |  |  |   ptr = (void *)((CELL *)(B+1)+P->u.OtapFs.s); | 
					
						
							| 
									
										
										
										
											2008-01-28 10:42:20 +00:00
										 |  |  |   B->cp_h = H; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-28 10:42:20 +00:00
										 |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_B(); | 
					
						
							|  |  |  |   return(ptr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-18 17:04:43 +00:00
										 |  |  | X_API void | 
					
						
							|  |  |  | YAP_cut_up(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_B(); | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  | 	while (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  | 	  {  | 
					
						
							|  |  |  | 	    POP_EXECUTE(); | 
					
						
							|  |  |  | 	  } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | #endif /* CUT_C */
 | 
					
						
							| 
									
										
										
										
											2010-05-04 14:53:34 +01:00
										 |  |  |       /* This is complicated: make sure we can restore the ASP
 | 
					
						
							|  |  |  | 	 pointer back to where cut_up called it. Slots depend on it. */ | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |   if (ENV > B->cp_env) { | 
					
						
							| 
									
										
										
										
											2010-05-04 14:53:34 +01:00
										 |  |  |     ASP = B->cp_env; | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |     Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-10-18 17:04:43 +00:00
										 |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     choiceptr cut_pt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cut_pt = B->cp_b; | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |     /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |     if (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  | 	POP_EXECUTE(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |     CUT_prune_to(cut_pt); | 
					
						
							| 
									
										
										
										
											2010-01-11 15:44:43 +00:00
										 |  |  |     Yap_TrimTrail(); | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |     B = cut_pt; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-11 15:44:43 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |   /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |   if (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       POP_EXECUTE(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-11 15:44:43 +00:00
										 |  |  |   Yap_TrimTrail(); | 
					
						
							| 
									
										
										
										
											2002-01-14 22:26:53 +00:00
										 |  |  |   B = B->cp_b;  /* cut_fail */ | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-14 22:26:53 +00:00
										 |  |  |   HB = B->cp_h; /* cut_fail */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_B(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Unify(Term t1, Term t2) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   out = Yap_unify(t1, t2); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2007-01-08 08:27:19 +00:00
										 |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-27 12:35:40 +02:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_Unifiable(Term t1, Term t2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  |   out = Yap_Unifiable(t1, t2); | 
					
						
							| 
									
										
										
										
											2011-10-27 12:35:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | /* == */ | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_ExactlyEqual(Term t1, Term t2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out = Yap_eq(t1, t2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* =@= */ | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_Variant(Term t1, Term t2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out = Yap_Variant(Deref(t1), Deref(t2)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* =@= */ | 
					
						
							|  |  |  | X_API Int | 
					
						
							|  |  |  | YAP_TermHash(Term t, Int sz, Int depth, int variant) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Int out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out = Yap_TermHash(t, sz, depth, variant); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | YAP_CurrentSlot(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_CurrentSlot( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_NewSlots(int n) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_NewSlots(n PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_InitSlot(Term t) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_InitSlot(t PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-17 13:37:51 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_RecoverSlots(int n) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_RecoverSlots(n PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_GetFromSlot(Int slot) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_GetFromSlot(slot PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term * | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_AddressFromSlot(Int slot) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return Yap_AddressFromSlot(slot PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | X_API Term * | 
					
						
							|  |  |  | YAP_AddressOfTermInSlot(Int slot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Term *b = Yap_AddressFromSlot(slot PASS_REGS); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |   Term a = *b; | 
					
						
							|  |  |  |  restart: | 
					
						
							|  |  |  |   if (!IsVarTerm(a)) { | 
					
						
							|  |  |  |     return(b); | 
					
						
							|  |  |  |   } else if (a == (CELL)b) { | 
					
						
							|  |  |  |     return(b); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     b = (CELL *)a; | 
					
						
							|  |  |  |     a = *b; | 
					
						
							|  |  |  |     goto restart; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_PutInSlot(Int slot, Term t) | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Yap_PutInSlot(slot, t PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-18 04:01:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-22 12:03:14 +00:00
										 |  |  | typedef enum | 
					
						
							|  |  |  | { FRG_FIRST_CALL = 0,		/* Initial call */ | 
					
						
							|  |  |  |   FRG_CUTTED     = 1,		/* Context was cutted */ | 
					
						
							|  |  |  |   FRG_REDO	 = 2		/* Normal redo */ | 
					
						
							|  |  |  | } frg_code; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | typedef  struct foreign_context | 
					
						
							| 
									
										
										
										
											2008-12-22 12:03:14 +00:00
										 |  |  |     { int *		context;	/* context value */ | 
					
						
							|  |  |  |       frg_code		control;	/* FRG_* action */ | 
					
						
							|  |  |  |       struct PL_local_data *engine;		/* invoking engine */ | 
					
						
							|  |  |  | } scontext ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  | typedef Int (*CPredicate0)(void); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | typedef Int (*CPredicate1)(Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate2)(Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate3)(Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate4)(Int,Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate5)(Int,Int,Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate6)(Int,Int,Int,Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate7)(Int,Int,Int,Int,Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate8)(Int,Int,Int,Int,Int,Int,Int,Int); | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  | typedef Int (*CPredicate9)(Int,Int,Int,Int,Int,Int,Int,Int,Int); | 
					
						
							|  |  |  | typedef Int (*CPredicate10)(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | typedef Int (*CPredicateV)(Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Int | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  | execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS) | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (pe->ArityOfPE) { | 
					
						
							|  |  |  |   case 0: | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       CPredicate0 code0 = (CPredicate0)exec_code; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |       return ((code0)()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 1: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate1 code1 = (CPredicate1)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code1)(Yap_InitSlot(Deref(ARG1) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 2: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate2 code2 = (CPredicate2)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code2)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 3: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate3 code3 = (CPredicate3)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code3)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 4: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate4 code4 = (CPredicate4)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code4)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 5: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate5 code5 = (CPredicate5)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code5)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 6: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate6 code6 = (CPredicate6)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code6)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG6) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 7: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate7 code7 = (CPredicate7)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code7)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG6) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG7) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 8: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate8 code8 = (CPredicate8)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code8)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG6) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG7) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG8) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  |   case 9: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate9 code9 = (CPredicate9)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code9)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG6) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG7) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG8) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG9) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 10: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CPredicate10 code10 = (CPredicate10)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       return ((code10)(Yap_InitSlot(Deref(ARG1) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG2) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG3) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG4) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG5) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG6) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG7) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG8) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG9) PASS_REGS), | 
					
						
							|  |  |  | 		      Yap_InitSlot(Deref(ARG10) PASS_REGS))); | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |   default: | 
					
						
							|  |  |  |     return(FALSE); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | typedef Int (*CBPredicate)(struct foreign_context *); | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | typedef Int (*CBPredicate1)(Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate2)(Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate3)(Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate4)(Int,Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate5)(Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate6)(Int,Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate7)(Int,Int,Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate8)(Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  | typedef Int (*CBPredicate9)(Int,Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							|  |  |  | typedef Int (*CBPredicate10)(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static Int | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  | execute_cargs_back(PredEntry *pe, CPredicate exec_code, struct foreign_context *ctx USES_REGS) | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (pe->ArityOfPE) { | 
					
						
							|  |  |  |   case 0: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate code0 = (CBPredicate)exec_code; | 
					
						
							|  |  |  |       return ((code0)(ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 1: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate1 code1 = (CBPredicate1)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code1)(&B->cp_a1-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 2: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate2 code2 = (CBPredicate2)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code2)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 3: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate3 code3 = (CBPredicate3)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code3)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 4: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate4 code4 = (CBPredicate4)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code4)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 5: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate5 code5 = (CBPredicate5)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code5)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      ctx)); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     } | 
					
						
							|  |  |  |   case 6: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate6 code6 = (CBPredicate6)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code6)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a6-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 7: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate7 code7 = (CBPredicate7)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code7)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a6-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a7-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 8: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate8 code8 = (CBPredicate8)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code8)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a6-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a7-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a8-LCL0, | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  |   case 9: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate9 code9 = (CBPredicate9)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code9)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a6-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a7-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a8-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a9-LCL0, | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   case 10: | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       CBPredicate10 code10 = (CBPredicate10)exec_code; | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       return ((code10)(&B->cp_a1-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a2-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a3-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a4-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a5-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a6-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a7-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a8-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a9-LCL0, | 
					
						
							|  |  |  | 		      &B->cp_a10-LCL0, | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  | 		      ctx)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |   default: | 
					
						
							|  |  |  |     return(FALSE); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Execute(PredEntry *pe, CPredicate exec_code) | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |   Int ret; | 
					
						
							| 
									
										
										
										
											2009-03-13 19:36:38 +00:00
										 |  |  |   if (pe->PredFlags & SWIEnvPredFlag) { | 
					
						
							| 
									
										
										
										
											2009-03-26 00:39:44 +00:00
										 |  |  |     CPredicateV codev = (CPredicateV)exec_code; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     struct foreign_context ctx; | 
					
						
							| 
									
										
										
										
											2010-12-30 22:42:30 -06:00
										 |  |  |     UInt i; | 
					
						
							|  |  |  |     Int sl = 0; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-01 15:46:37 -05:00
										 |  |  |     ctx.engine = NULL; | 
					
						
							| 
									
										
										
										
											2010-12-30 22:42:30 -06:00
										 |  |  |     for (i=pe->ArityOfPE; i > 0; i--) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       sl = Yap_InitSlot(XREGS[i] PASS_REGS); | 
					
						
							| 
									
										
										
										
											2010-12-30 22:42:30 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = pe; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |     ret = ((codev)(sl,0,&ctx)); | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |   } else if (pe->PredFlags & CArgsPredFlag) { | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = pe; | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |     ret =  execute_cargs(pe, exec_code PASS_REGS); | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |     PP = pe; | 
					
						
							|  |  |  |     ret = (exec_code)( PASS_REGS1 ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   PP = NULL; | 
					
						
							|  |  |  |   if (!ret) { | 
					
						
							|  |  |  |     Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |     EX = NULL; | 
					
						
							|  |  |  |     if ((t = Yap_GetException())) { | 
					
						
							|  |  |  |       Yap_JumpToEnv(t); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-03-14 20:54:55 +00:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | #define FRG_REDO_MASK	0x00000003L
 | 
					
						
							|  |  |  | #define FRG_REDO_BITS	2
 | 
					
						
							|  |  |  | #define REDO_INT	0x02		/* Returned an integer */
 | 
					
						
							|  |  |  | #define REDO_PTR	0x03		/* returned a pointer */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Int | 
					
						
							|  |  |  | YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |   if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) { | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     Int val; | 
					
						
							|  |  |  |     CPredicateV codev = (CPredicateV)exec_code; | 
					
						
							|  |  |  |     struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     struct open_query_struct *oexec = LOCAL_execution; | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |     extern void PL_close_foreign_frame(struct open_query_struct *); | 
					
						
							| 
									
										
										
										
											2010-11-26 16:21:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = pe; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     ctx->control = FRG_FIRST_CALL; | 
					
						
							|  |  |  |     ctx->engine = NULL; //(PL_local_data *)Yap_regp;
 | 
					
						
							|  |  |  |     ctx->context = NULL; | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     if (pe->PredFlags & CArgsPredFlag) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       val = execute_cargs_back(pe, exec_code, ctx PASS_REGS); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       val = ((codev)(B->cp_args-LCL0,0,ctx)); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     /* make sure we clean up the frames left by the user */ | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     while (LOCAL_execution != oexec) | 
					
						
							|  |  |  |       PL_close_foreign_frame(LOCAL_execution); | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     if (val == 0) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							| 
									
										
										
										
											2011-02-11 17:49:19 +00:00
										 |  |  | 	cut_c_pop(); | 
					
						
							|  |  |  | 	B = B->cp_b; | 
					
						
							|  |  |  | 	Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |       cut_fail(); | 
					
						
							|  |  |  |     } else if (val == 1) { /* TRUE */ | 
					
						
							|  |  |  |       cut_succeed(); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-02-11 01:22:07 +00:00
										 |  |  |       if ((val & REDO_PTR) == REDO_PTR) | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | 	ctx->context = (int *)(val & ~REDO_PTR); | 
					
						
							| 
									
										
										
										
											2011-02-11 01:22:07 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | 	ctx->context = (int *)((val & ~REDO_PTR)>>FRG_REDO_BITS); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |       return TRUE; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     Int ret = (exec_code)( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |     if (!ret) { | 
					
						
							|  |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							|  |  |  | 	  Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	  return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  | Int | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  | YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top) | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |   choiceptr  oB = B; | 
					
						
							|  |  |  |   /* find out where we belong */ | 
					
						
							|  |  |  |   while (B->cp_b < (choiceptr)top) | 
					
						
							|  |  |  |     B = B->cp_b; | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |   if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) { | 
					
						
							|  |  |  |     Int val; | 
					
						
							|  |  |  |     CPredicateV codev = (CPredicateV)exec_code; | 
					
						
							|  |  |  |     struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     struct open_query_struct *oexec = LOCAL_execution; | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |     extern void PL_close_foreign_frame(struct open_query_struct *); | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |     CELL *args = B->cp_args; | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |     B = oB; | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     PP = pe; | 
					
						
							|  |  |  |     ctx->control = FRG_CUTTED; | 
					
						
							|  |  |  |     ctx->engine = NULL; //(PL_local_data *)Yap_regp;
 | 
					
						
							|  |  |  |     ctx->context = NULL; | 
					
						
							|  |  |  |     if (pe->PredFlags & CArgsPredFlag) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       val = execute_cargs_back(pe, exec_code, ctx PASS_REGS); | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |       val = ((codev)(args-LCL0,0,ctx)); | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* make sure we clean up the frames left by the user */ | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     while (LOCAL_execution != oexec) | 
					
						
							|  |  |  |       PL_close_foreign_frame(LOCAL_execution); | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PP = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |     //    B = LCL0-(CELL*)oB;
 | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     if (val == 0) { | 
					
						
							|  |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							|  |  |  | 	cut_c_pop(); | 
					
						
							|  |  |  | 	Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } else { /* TRUE */ | 
					
						
							|  |  |  |       return TRUE; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-03-22 11:07:49 +00:00
										 |  |  |     Int ret; | 
					
						
							|  |  |  |     B = oB; | 
					
						
							|  |  |  |     ret = (exec_code)( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |     if (!ret) { | 
					
						
							|  |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							|  |  |  | 	  Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	  return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | Int | 
					
						
							|  |  |  | YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2010-01-12 14:58:48 +00:00
										 |  |  |   if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) { | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     Int val; | 
					
						
							|  |  |  |     CPredicateV codev = (CPredicateV)exec_code; | 
					
						
							|  |  |  |     struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1)); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     struct open_query_struct *oexec = LOCAL_execution; | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |     extern void PL_close_foreign_frame(struct open_query_struct *); | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = pe; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     ctx->control = FRG_REDO; | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     if (pe->PredFlags & CArgsPredFlag) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       val = execute_cargs_back(pe, exec_code, ctx PASS_REGS); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       val = ((codev)(B->cp_args-LCL0,0,ctx)); | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 06:59:15 -08:00
										 |  |  |     /* make sure we clean up the frames left by the user */ | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     while (LOCAL_execution != oexec) | 
					
						
							|  |  |  |       PL_close_foreign_frame(LOCAL_execution); | 
					
						
							| 
									
										
										
										
											2011-02-11 19:01:18 +00:00
										 |  |  |     PP = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     if (val == 0) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							| 
									
										
										
										
											2011-02-11 17:49:19 +00:00
										 |  |  | 	cut_c_pop(); | 
					
						
							|  |  |  | 	B = B->cp_b; | 
					
						
							|  |  |  | 	Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:17:27 +00:00
										 |  |  |       } else { | 
					
						
							|  |  |  | 	cut_fail(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |     } else if (val == 1) { /* TRUE */ | 
					
						
							|  |  |  |       cut_succeed(); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       if ((val & REDO_PTR) == REDO_PTR) | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | 	ctx->context = (int *)(val & ~REDO_PTR); | 
					
						
							| 
									
										
										
										
											2011-03-15 23:49:28 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  | 	ctx->context = (int *)((val & ~REDO_PTR)>>FRG_REDO_BITS); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-06 11:25:15 -02:00
										 |  |  |     return TRUE; | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     Int ret = (exec_code)( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |     if (!ret) { | 
					
						
							|  |  |  |       Term t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |       EX = NULL; | 
					
						
							|  |  |  |       if ((t = Yap_GetException())) { | 
					
						
							|  |  |  | 	  Yap_JumpToEnv(t); | 
					
						
							|  |  |  | 	  return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2009-06-01 15:32:36 -05:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_CallProlog(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   Int out; | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |   Term mod = CurrentModule; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   while (!IsVarTerm(t) && | 
					
						
							|  |  |  |       IsApplTerm(t) && | 
					
						
							|  |  |  |       FunctorOfTerm(t) == FunctorModule) { | 
					
						
							|  |  |  |     Term tmod = ArgOfTerm(1,t); | 
					
						
							|  |  |  |     if (IsVarTerm(tmod)) return(FALSE); | 
					
						
							|  |  |  |     if (!IsAtomTerm(tmod)) return(FALSE); | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |     mod = tmod; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |     t = ArgOfTerm(2,t); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   out = Yap_execute_goal(t, 0, mod); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return(out); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 21:09:22 +00:00
										 |  |  | X_API void * | 
					
						
							|  |  |  | YAP_ReallocSpaceFromYap(void *ptr,unsigned int size) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2009-11-19 21:09:22 +00:00
										 |  |  |   void *new_ptr; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2009-12-21 10:12:47 -02:00
										 |  |  |   while ((new_ptr = Yap_ReallocCodeSpace(ptr,size)) == NULL) { | 
					
						
							| 
									
										
										
										
											2009-11-19 21:09:22 +00:00
										 |  |  |     if (!Yap_growheap(FALSE, size, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2009-11-19 21:09:22 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return new_ptr; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | X_API void * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_AllocSpaceFromYap(unsigned int size) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS  | 
					
						
							|  |  |  |     void *ptr; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-10 04:35:19 +00:00
										 |  |  |   while ((ptr = Yap_AllocCodeSpace(size)) == NULL) { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |     if (!Yap_growheap(FALSE, size, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:35:19 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:35:19 +00:00
										 |  |  |   return ptr; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_FreeSpaceFromYap(void *ptr) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_FreeCodeSpace(ptr); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   unsigned int j = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (t != TermNil) { | 
					
						
							|  |  |  |     register Term   Head; | 
					
						
							|  |  |  |     register Int    i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Head = HeadOfTerm(t); | 
					
						
							|  |  |  |     if (IsVarTerm(Head)) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Error(INSTANTIATION_ERROR,Head,"user defined procedure"); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       return(FALSE); | 
					
						
							|  |  |  |     } else if (!IsIntTerm(Head)) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure"); | 
					
						
							| 
									
										
										
										
											2011-12-22 11:42:26 +00:00
										 |  |  |       return FALSE;		 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     i = IntOfTerm(Head); | 
					
						
							|  |  |  |     if (i < 0 || i > 255) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure"); | 
					
						
							| 
									
										
										
										
											2011-12-22 11:42:26 +00:00
										 |  |  |       return FALSE;		 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-22 11:42:26 +00:00
										 |  |  |     if (j == bufsize) { | 
					
						
							|  |  |  |       buf[bufsize-1] = '\0'; | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       buf[j++] = i; | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     t = TailOfTerm(t); | 
					
						
							|  |  |  |     if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Error(INSTANTIATION_ERROR,t,"user defined procedure"); | 
					
						
							| 
									
										
										
										
											2011-12-22 11:42:26 +00:00
										 |  |  |       return FALSE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } else if (!IsPairTerm(t) && t != TermNil) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Error(TYPE_ERROR_LIST, t, "user defined procedure"); | 
					
						
							| 
									
										
										
										
											2011-12-22 11:42:26 +00:00
										 |  |  |       return FALSE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   buf[j] = '\0'; | 
					
						
							|  |  |  |   return(TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_BufferToString(char *s) | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   t = Yap_StringToList(s); | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NBufferToString(char *s, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NStringToList(s, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_WideBufferToString(wchar_t *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_WideStringToList(s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NWideBufferToString(wchar_t *s, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NWideStringToList(s, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_ReadBuffer(char *s, Term *tp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 16:46:39 +01:00
										 |  |  |   LOCAL_ErrorMessage=NULL; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   while ((t = Yap_StringToTerm(s,tp)) == 0L) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |     if (LOCAL_ErrorMessage) { | 
					
						
							|  |  |  |       if (!strcmp(LOCAL_ErrorMessage,"Stack Overflow")) { | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  | 	if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  *tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); | 
					
						
							|  |  |  | 	  LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	  RECOVER_H(); | 
					
						
							|  |  |  | 	  return 0L; | 
					
						
							|  |  |  | 	}  | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       } else if (!strcmp(LOCAL_ErrorMessage,"Heap Overflow")) { | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	if (!Yap_growheap(FALSE, 0, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  *tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); | 
					
						
							|  |  |  | 	  LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	  RECOVER_H(); | 
					
						
							|  |  |  | 	  return 0L; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       } else if (!strcmp(LOCAL_ErrorMessage,"Trail Overflow")) { | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	if (!Yap_growtrail (0, FALSE)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  *tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); | 
					
						
							|  |  |  | 	  LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	  RECOVER_H(); | 
					
						
							|  |  |  | 	  return 0L; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); | 
					
						
							|  |  |  | 	LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  | 	RECOVER_H(); | 
					
						
							|  |  |  | 	return 0L; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-26 10:42:19 +00:00
										 |  |  |       continue; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_BufferToAtomList(char *s) | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   t = Yap_StringToListOfAtoms(s); | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | /* copy a string of size len to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NBufferToAtomList(char *s, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NStringToListOfAtoms(s, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_WideBufferToAtomList(wchar_t *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_WideStringToListOfAtoms(s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string of size len to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NWideBufferToAtomList(wchar_t *s, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NWideStringToListOfAtoms(s, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2008-12-17 14:47:05 +00:00
										 |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string of size len to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NWideBufferToAtomDiffList(wchar_t *s, Term t0, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NWideStringToDiffListOfAtoms(s, t0, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_BufferToDiffList(char *s, Term t0) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   t = Yap_StringToDiffList(s, t0 PASS_REGS); | 
					
						
							| 
									
										
										
										
											2008-07-24 16:02:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string of size len to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NBufferToDiffList(char *s, Term t0, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NStringToDiffList(s, t0, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_WideBufferToDiffList(wchar_t *s, Term t0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_WideStringToDiffList(s, t0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* copy a string of size len to a buffer */ | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_NWideBufferToDiffList(wchar_t *s, Term t0, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t;  | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Yap_NWideStringToDiffList(s, t0, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  | YAP_Error(int myerrno, Term t, char *buf,...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #define YAP_BUF_SIZE 512
 | 
					
						
							|  |  |  |   va_list ap; | 
					
						
							|  |  |  |   char tmpbuf[YAP_BUF_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!myerrno) | 
					
						
							|  |  |  |     myerrno = SYSTEM_ERROR; | 
					
						
							|  |  |  |   if (t == 0L) | 
					
						
							|  |  |  |     t = TermNil; | 
					
						
							|  |  |  |   if (buf != NULL) { | 
					
						
							|  |  |  |     va_start (ap, buf); | 
					
						
							|  |  |  | #if   HAVE_VSNPRINTF
 | 
					
						
							|  |  |  |     (void) vsnprintf(tmpbuf, YAP_BUF_SIZE, buf, ap); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     (void) vsprintf(tmpbuf, buf, ap); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     va_end (ap); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     tmpbuf[0] = '\0'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Yap_Error(myerrno,t,tmpbuf); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  | static int myputc (wchar_t ch) | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   putc(ch,stderr); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   return ch; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | X_API PredEntry * | 
					
						
							|  |  |  | YAP_FunctorToPred(Functor func) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   return RepPredProp(PredPropByFunc(func, CurrentModule)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API PredEntry * | 
					
						
							|  |  |  | YAP_AtomToPred(Atom at) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   return RepPredProp(PredPropByAtom(at, CurrentModule));   | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-13 14:57:12 -05:00
										 |  |  | X_API PredEntry * | 
					
						
							|  |  |  | YAP_FunctorToPredInModule(Functor func, Term mod) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return RepPredProp(PredPropByFunc(func, mod)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API PredEntry * | 
					
						
							|  |  |  | YAP_AtomToPredInModule(Atom at, Term mod) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   return RepPredProp(PredPropByAtom(at, mod));   | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | run_emulator(YAP_dogoalinfo *dgi) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   choiceptr myB; | 
					
						
							|  |  |  |   int out; | 
					
						
							| 
									
										
										
										
											2009-06-15 10:29:31 -05:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserMode; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   out = Yap_absmi(0); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserCCallMode; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   myB = (choiceptr)(LCL0-dgi->b); | 
					
						
							|  |  |  |   CP = myB->cp_cp; | 
					
						
							|  |  |  |   if (!out ) { | 
					
						
							|  |  |  |     /* recover stack */ | 
					
						
							|  |  |  |     /* on failed computations */ | 
					
						
							|  |  |  |     TR = B->cp_tr; | 
					
						
							|  |  |  |     H = B->cp_h; | 
					
						
							|  |  |  | #ifdef DEPTH_LIMIT
 | 
					
						
							|  |  |  |     DEPTH = B->cp_depth = DEPTH; | 
					
						
							|  |  |  | #endif /* DEPTH_LIMIT */
 | 
					
						
							|  |  |  |     YENV = ENV = B->cp_env; | 
					
						
							|  |  |  |     ASP = (CELL *)(B+1); | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |     Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |     B = B->cp_b; | 
					
						
							|  |  |  |     HB = B->cp_h; | 
					
						
							| 
									
										
										
										
											2008-04-28 23:02:32 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     Yap_StartSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   P = dgi->p; | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_EnterGoal(PredEntry *pe, Term *ptr, YAP_dogoalinfo *dgi) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   UInt i; | 
					
						
							|  |  |  |   choiceptr myB; | 
					
						
							| 
									
										
										
										
											2007-10-15 23:48:46 +00:00
										 |  |  |   int out; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |   dgi->p = P; | 
					
						
							|  |  |  |   ptr--; | 
					
						
							|  |  |  |   i = pe->ArityOfPE; | 
					
						
							|  |  |  |   while (i>0) { | 
					
						
							|  |  |  |     XREGS[i] = ptr[i]; | 
					
						
							|  |  |  |     i--; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   P = pe->CodeOfPred; | 
					
						
							|  |  |  |   /* create a choice-point to be tag new goal */ | 
					
						
							|  |  |  |   myB = (choiceptr)ASP; | 
					
						
							|  |  |  |   myB--; | 
					
						
							|  |  |  |   dgi->b = LCL0-(CELL *)myB; | 
					
						
							|  |  |  |   myB->cp_tr = TR; | 
					
						
							|  |  |  |   myB->cp_h = HB = H; | 
					
						
							|  |  |  |   myB->cp_b = B; | 
					
						
							|  |  |  | #ifdef DEPTH_LIMIT
 | 
					
						
							|  |  |  |   myB->cp_depth = DEPTH; | 
					
						
							|  |  |  | #endif /* DEPTH_LIMIT */
 | 
					
						
							|  |  |  |   myB->cp_cp = CP; | 
					
						
							|  |  |  |   myB->cp_ap = NOCODE; | 
					
						
							|  |  |  |   myB->cp_env = ENV; | 
					
						
							|  |  |  |   CP = YESCODE; | 
					
						
							|  |  |  |   B = myB; | 
					
						
							|  |  |  |   HB = H; | 
					
						
							|  |  |  |   ASP = YENV = (CELL *)B; | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |   Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-10-15 23:48:46 +00:00
										 |  |  |   YENV[E_CB] = Unsigned (B); | 
					
						
							|  |  |  |   out = run_emulator(dgi); | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_RetryGoal(YAP_dogoalinfo *dgi) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   choiceptr myB; | 
					
						
							| 
									
										
										
										
											2009-06-15 10:29:31 -05:00
										 |  |  |   int out; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |   myB = (choiceptr)(LCL0-dgi->b); | 
					
						
							|  |  |  |   CP = myB->cp_cp; | 
					
						
							|  |  |  |   /* sanity check */ | 
					
						
							|  |  |  |   if (B >= myB) { | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   P = FAILCODE; | 
					
						
							| 
									
										
										
										
											2009-06-15 10:29:31 -05:00
										 |  |  |   out = run_emulator(dgi); | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_LeaveGoal(int backtrack, YAP_dogoalinfo *dgi) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   choiceptr myB; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-15 10:29:31 -05:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   myB = (choiceptr)(LCL0-dgi->b); | 
					
						
							| 
									
										
										
										
											2007-11-01 20:50:31 +00:00
										 |  |  |   if (B > myB) { | 
					
						
							|  |  |  |     /* someone cut us */ | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-11-01 20:50:31 +00:00
										 |  |  |   /* prune away choicepoints */ | 
					
						
							|  |  |  |   if (B != myB) { | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2007-11-01 20:50:31 +00:00
										 |  |  |     CUT_prune_to(myB); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-11-01 20:50:31 +00:00
										 |  |  |     B = myB; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* if backtracking asked for, recover space and bindings */ | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   if (backtrack) { | 
					
						
							|  |  |  |     P = FAILCODE; | 
					
						
							|  |  |  |     Yap_exec_absmi(TRUE); | 
					
						
							|  |  |  |     /* recover stack space */ | 
					
						
							|  |  |  |     H = B->cp_h; | 
					
						
							|  |  |  |     TR = B->cp_tr; | 
					
						
							|  |  |  | #ifdef DEPTH_LIMIT
 | 
					
						
							|  |  |  |     DEPTH = B->cp_depth; | 
					
						
							|  |  |  | #endif /* DEPTH_LIMIT */
 | 
					
						
							|  |  |  |     YENV = ENV = B->cp_env; | 
					
						
							| 
									
										
										
										
											2008-06-04 14:47:18 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     Yap_TrimTrail(); | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   /* recover local stack */ | 
					
						
							|  |  |  |   ASP = (CELL *)(B+1); | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |   Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |   /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |   if (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       POP_EXECUTE(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-06-04 12:28:02 +00:00
										 |  |  |   B = B->cp_b; | 
					
						
							|  |  |  |   HB = B->cp_h; | 
					
						
							|  |  |  |   P = dgi->p; | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-13 23:09:05 +00:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_RunGoal(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-06-05 03:37:01 +00:00
										 |  |  |   Term out; | 
					
						
							| 
									
										
										
										
											2002-06-18 02:27:53 +00:00
										 |  |  |   yamop *old_CP = CP; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   LOCAL_AllowRestart = FALSE; | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserMode; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   out = Yap_RunTopGoal(t); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserCCallMode; | 
					
						
							| 
									
										
										
										
											2002-06-18 02:27:53 +00:00
										 |  |  |   if (out) { | 
					
						
							|  |  |  |     P = (yamop *)ENV[E_CP]; | 
					
						
							|  |  |  |     ENV = (CELL *)ENV[E_E]; | 
					
						
							|  |  |  |     CP = old_CP; | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     LOCAL_AllowRestart = TRUE; | 
					
						
							| 
									
										
										
										
											2002-06-18 02:27:53 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2008-06-17 13:37:51 +00:00
										 |  |  |     ENV = B->cp_env; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |     B = B->cp_b; | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     LOCAL_AllowRestart = FALSE; | 
					
						
							| 
									
										
										
										
											2002-06-18 02:27:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-12-13 23:09:05 +00:00
										 |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-21 06:32:49 -07:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_AllocExternalDataInStack(size_t bytes) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-07-22 04:09:33 -07:00
										 |  |  |   Term t = Yap_AllocExternalDataInStack(EXTERNAL_BLOB, bytes); | 
					
						
							| 
									
										
										
										
											2011-07-21 06:32:49 -07:00
										 |  |  |   if (t == TermNil) | 
					
						
							|  |  |  |     return 0L; | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool | 
					
						
							|  |  |  | YAP_IsExternalDataInStackTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-07-22 04:09:33 -07:00
										 |  |  |   return IsExternalBlobTerm(t, EXTERNAL_BLOB); | 
					
						
							| 
									
										
										
										
											2011-07-21 06:32:49 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void * | 
					
						
							|  |  |  | YAP_ExternalDataInStackFromTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return ExternalBlobFromTerm (t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-22 04:09:33 -07:00
										 |  |  | int YAP_NewOpaqueType(void *f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  |   if (!GLOBAL_OpaqueHandlers) { | 
					
						
							|  |  |  |     GLOBAL_OpaqueHandlers = malloc(sizeof(opaque_handler_t)*(USER_BLOB_END-USER_BLOB_START)); | 
					
						
							|  |  |  |     if (!GLOBAL_OpaqueHandlers) { | 
					
						
							|  |  |  |       /* no room */ | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } else if (GLOBAL_OpaqueHandlersCount == USER_BLOB_END-USER_BLOB_START) { | 
					
						
							|  |  |  |     /* all types used */ | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   i = GLOBAL_OpaqueHandlersCount++; | 
					
						
							|  |  |  |   memcpy(GLOBAL_OpaqueHandlers+i,f,sizeof(opaque_handler_t)); | 
					
						
							|  |  |  |   return i+USER_BLOB_START; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Term YAP_NewOpaqueObject(int tag, size_t bytes) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t = Yap_AllocExternalDataInStack((CELL)tag, bytes); | 
					
						
							|  |  |  |   if (t == TermNil) | 
					
						
							|  |  |  |     return 0L; | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Bool | 
					
						
							|  |  |  | YAP_IsOpaqueObjectTerm(Term t, int tag) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return IsExternalBlobTerm(t, (CELL)tag); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void * | 
					
						
							|  |  |  | YAP_OpaqueObjectFromTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return ExternalBlobFromTerm (t); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-13 23:09:05 +00:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  | YAP_RunGoalOnce(Term t) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   Term out; | 
					
						
							|  |  |  |   yamop *old_CP = CP; | 
					
						
							| 
									
										
										
										
											2011-08-31 13:59:30 -07:00
										 |  |  |   Int oldPrologMode = LOCAL_PrologMode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserMode; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   out = Yap_RunTopGoal(t); | 
					
						
							| 
									
										
										
										
											2011-08-31 13:59:30 -07:00
										 |  |  |   LOCAL_PrologMode = oldPrologMode; | 
					
						
							|  |  |  |   if (!(oldPrologMode & UserCCallMode)) { | 
					
						
							|  |  |  |     /* called from top-level */ | 
					
						
							|  |  |  |     LOCAL_AllowRestart = FALSE; | 
					
						
							|  |  |  |     RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |     return out; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   if (out) { | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |     choiceptr cut_pt, ob; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |     ob = NULL; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |     cut_pt = B; | 
					
						
							|  |  |  |     while (cut_pt-> cp_ap != NOCODE) { | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |       /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |       if (POP_CHOICE_POINT(cut_pt->cp_b)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  POP_EXECUTE(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |       ob = cut_pt; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |       cut_pt = cut_pt->cp_b; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #ifdef YAPOR
 | 
					
						
							|  |  |  |     CUT_prune_to(cut_pt); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-07-11 21:14:26 -07:00
										 |  |  |     if (ob) { | 
					
						
							|  |  |  |       B = ob; | 
					
						
							|  |  |  |       Yap_TrimTrail(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |     B = cut_pt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   ASP = B->cp_env; | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |   Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   ENV = (CELL *)ASP[E_E]; | 
					
						
							|  |  |  |   B = (choiceptr)ASP[E_CB]; | 
					
						
							|  |  |  | #ifdef  DEPTH_LIMIT
 | 
					
						
							|  |  |  |   DEPTH = ASP[E_DEPTH]; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   P = (yamop *)ASP[E_CP]; | 
					
						
							|  |  |  |   CP = old_CP; | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   LOCAL_AllowRestart = FALSE; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-12-13 23:09:05 +00:00
										 |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_RestartGoal(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   if (LOCAL_AllowRestart) { | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |     P = (yamop *)FAILCODE; | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |     LOCAL_PrologMode = UserMode; | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |     out = Yap_exec_absmi(TRUE); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |     LOCAL_PrologMode = UserCCallMode; | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |     if (out == FALSE) { | 
					
						
							|  |  |  |       /* cleanup */ | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       Yap_CloseSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |       Yap_trust_last(); | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       LOCAL_AllowRestart = FALSE; | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } else {  | 
					
						
							|  |  |  |     out = FALSE; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return(out); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2007-05-15 11:33:51 +00:00
										 |  |  | YAP_ShutdownGoal(int backtrack) | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   if (LOCAL_AllowRestart) { | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  |     choiceptr cut_pt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cut_pt = B; | 
					
						
							|  |  |  |     while (cut_pt-> cp_ap != NOCODE) { | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |       /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |       if (POP_CHOICE_POINT(cut_pt->cp_b)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  POP_EXECUTE(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  |       cut_pt = cut_pt->cp_b; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #ifdef YAPOR
 | 
					
						
							|  |  |  |     CUT_prune_to(cut_pt); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     /* just force backtrack */ | 
					
						
							|  |  |  |     B = cut_pt; | 
					
						
							| 
									
										
										
										
											2007-05-15 11:33:51 +00:00
										 |  |  |     if (backtrack) { | 
					
						
							|  |  |  |       P = FAILCODE; | 
					
						
							|  |  |  |       Yap_exec_absmi(TRUE); | 
					
						
							|  |  |  |       /* recover stack space */ | 
					
						
							|  |  |  |       H = cut_pt->cp_h; | 
					
						
							|  |  |  |       TR = cut_pt->cp_tr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* we can always recover the stack */ | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |     ASP = cut_pt->cp_env; | 
					
						
							| 
									
										
										
										
											2011-07-11 22:12:32 -07:00
										 |  |  |     Yap_PopSlots( PASS_REGS1 ); | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  |     ENV = (CELL *)ASP[E_E]; | 
					
						
							|  |  |  |     B = (choiceptr)ASP[E_CB]; | 
					
						
							| 
									
										
										
										
											2008-06-04 14:47:18 +00:00
										 |  |  |     Yap_TrimTrail(); | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | #ifdef  DEPTH_LIMIT
 | 
					
						
							|  |  |  |     DEPTH = ASP[E_DEPTH]; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     LOCAL_AllowRestart = FALSE; | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_ContinueGoal(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   int out; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserMode; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   out = Yap_exec_absmi(TRUE); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode = UserCCallMode; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return(out); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_PruneGoal(void) | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS  | 
					
						
							|  |  |  |  BACKUP_B(); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   while (B->cp_ap != NOCODE) { | 
					
						
							| 
									
										
										
										
											2011-07-09 07:56:11 -04:00
										 |  |  |     /* make sure we prune C-choicepoints */ | 
					
						
							|  |  |  |     if (POP_CHOICE_POINT(B->cp_b)) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  | 	POP_EXECUTE(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |     B = B->cp_b; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-12-04 22:58:46 +00:00
										 |  |  |   Yap_TrimTrail(); | 
					
						
							| 
									
										
										
										
											2010-04-13 00:31:25 +01:00
										 |  |  |   /* make sure that we do not destroy the guard choice-point */ | 
					
						
							|  |  |  |   if (Yap_op_from_opcode(B->cp_ap->opc) != _Nstop) | 
					
						
							|  |  |  |     B = B->cp_b; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_B(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_GoalHasException(Term *t) | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   int out = FALSE; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |   if (EX) { | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  |     do { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  |       *t = Yap_FetchTermFromDB(EX); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       if (LOCAL_Error_TYPE == YAP_NO_ERROR) { | 
					
						
							| 
									
										
										
										
											2010-07-26 12:56:17 +01:00
										 |  |  | 	RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 	return TRUE; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       } else if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) { | 
					
						
							|  |  |  | 	LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  | 	if (!Yap_growglobal(NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  | 	  RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 	  return FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  | 	if (!Yap_growstack(EX->NOfCells*CellSize)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  | 	  RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 	  return FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } while (*t == (CELL)0); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |     out = TRUE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2005-08-17 13:35:52 +00:00
										 |  |  |   return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							|  |  |  | YAP_ClearExceptions(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2009-12-03 17:48:25 +00:00
										 |  |  |   Yap_ResetExceptionTerm(); | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  |   if (EX) { | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     LOCAL_BallTerm = EX; | 
					
						
							| 
									
										
										
										
											2010-07-21 12:49:06 +01:00
										 |  |  |   } | 
					
						
							|  |  |  |   EX = NULL; | 
					
						
							|  |  |  |   Yap_ResetExceptionTerm();     | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   LOCAL_UncaughtThrow = FALSE; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  | X_API IOSTREAM * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_InitConsult(int mode, char *filename) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   IOSTREAM *st; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mode == YAP_CONSULT_MODE) | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     Yap_init_consult(FALSE, filename); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     Yap_init_consult(TRUE, filename); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   st = Sopen_file(filename, "r"); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   return st; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 13:10:39 +01:00
										 |  |  | X_API IOSTREAM * | 
					
						
							|  |  |  | YAP_TermToStream(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   IOSTREAM *s; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-18 11:01:06 +00:00
										 |  |  |   if (IsVarTerm(t) || !IsAtomTerm(t)) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   if ( (s=Yap_GetStreamHandle(AtomOfTerm(t))) ) { | 
					
						
							| 
									
										
										
										
											2011-05-25 13:10:39 +01:00
										 |  |  |     RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |     return s; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  | YAP_EndConsult(IOSTREAM *s) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_end_consult(); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   Sclose(s); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  | YAP_Read(IOSTREAM *inp) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2008-10-23 22:17:45 +01:00
										 |  |  |   Term t, tpos = TermNil; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |   TokEntry *tokstart; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-12 17:23:10 +01:00
										 |  |  |   tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, FALSE, &tpos); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   if (LOCAL_ErrorMessage) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-06-12 17:23:10 +01:00
										 |  |  |       Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); | 
					
						
							| 
									
										
										
										
											2005-04-10 04:01:15 +00:00
										 |  |  |       RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |       return 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   if (inp->flags & (SIO_FEOF|SIO_FEOF2)) { | 
					
						
							| 
									
										
										
										
											2011-06-12 17:23:10 +01:00
										 |  |  |       Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |       RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |       return MkAtomTerm (AtomEof); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   t = Yap_Parse(); | 
					
						
							| 
									
										
										
										
											2011-06-12 17:23:10 +01:00
										 |  |  |   Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2004-05-14 16:33:47 +00:00
										 |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2011-07-22 15:49:40 +01:00
										 |  |  | YAP_Write(Term t, IOSTREAM *stream, int flags) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-14 09:10:07 +00:00
										 |  |  |   Yap_plwrite (t, stream, 0, flags, 1200); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-14 16:44:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_CopyTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term tn; | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tn = Yap_CopyTerm(t); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return tn; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-14 17:56:47 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_WriteBuffer(Term t, char *buf, unsigned int sze, int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |   t = Yap_TermToString(t, buf, sze, flags); | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API char * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_CompileClause(Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-12-27 16:53:09 +00:00
										 |  |  |   yamop *codeaddr; | 
					
						
							| 
									
										
										
										
											2001-11-15 00:01:43 +00:00
										 |  |  |   int mod = CurrentModule; | 
					
						
							| 
									
										
										
										
											2004-12-08 00:56:35 +00:00
										 |  |  |   Term tn = TermNil; | 
					
						
							| 
									
										
										
										
											2001-11-15 00:01:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   /* allow expansion during stack initialization */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   LOCAL_ErrorMessage = NULL; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   ARG1 = t; | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  |   YAPEnterCriticalSection(); | 
					
						
							| 
									
										
										
										
											2003-11-21 16:56:20 +00:00
										 |  |  |   codeaddr = Yap_cclause (t,0, mod, t); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   if (codeaddr != NULL) { | 
					
						
							|  |  |  |     t = Deref(ARG1); /* just in case there was an heap overflow */ | 
					
						
							| 
									
										
										
										
											2004-11-18 22:32:40 +00:00
										 |  |  |     if (!Yap_addclause (t, codeaddr, TRUE, mod, &tn)) { | 
					
						
							|  |  |  |       YAPLeaveCriticalSection(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       return LOCAL_ErrorMessage; | 
					
						
							| 
									
										
										
										
											2004-11-18 22:32:40 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  |   YAPLeaveCriticalSection(); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |   if (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL) { | 
					
						
							| 
									
										
										
										
											2004-07-23 03:37:17 +00:00
										 |  |  |     if (!Yap_growheap(FALSE, 0, NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2004-07-23 03:37:17 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   return(LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | static int eof_found = FALSE; | 
					
						
							|  |  |  | static int yap_lineno = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  | static IOSTREAM *bootfile; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char InitFile[] = "init.yap"; | 
					
						
							|  |  |  | static char BootFile[] = "boot.yap"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* do initial boot by consulting the file boot.yap */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | do_bootfile (char *bootfilename) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  |   Term term_end_of_file = MkAtomTerm(AtomEof); | 
					
						
							|  |  |  |   Term term_true = YAP_MkAtomTerm(AtomTrue); | 
					
						
							|  |  |  |   Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"),1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* consult boot.pl */ | 
					
						
							|  |  |  |   /* the consult mode does not matter here, really */ | 
					
						
							|  |  |  |   /*
 | 
					
						
							|  |  |  |     To be honest, YAP_InitConsult does not really do much, | 
					
						
							|  |  |  |     it's here for the future. It also makes what we want to do clearer. | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   bootfile = YAP_InitConsult(YAP_CONSULT_MODE,bootfilename); | 
					
						
							|  |  |  |   if (bootfile == NULL) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n", bootfilename); | 
					
						
							|  |  |  |       exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |   while (!eof_found) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |       t = YAP_Read(bootfile); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |       if (eof_found) { | 
					
						
							|  |  |  | 	break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (t == 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  | 	  fprintf(stderr, "[ SYNTAX ERROR: while parsing bootfile %s at line %d ]\n", bootfilename, yap_lineno); | 
					
						
							|  |  |  | 	  exit(1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       if (YAP_IsVarTerm (t) || t == TermNil) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  continue; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else if (t == term_true) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  YAP_Exit(0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else if (t == term_end_of_file) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else if (YAP_IsPairTerm (t)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  | 	  fprintf(stderr, "[ SYSTEM ERROR: consult not allowed in boot file ]\n"); | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  | 	  fprintf(stderr, "error found at line %d and pos %d", yap_lineno, Sseek(bootfile,0L,SEEK_CUR)); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |       else if (YAP_IsApplTerm (t) && FunctorOfTerm (t) == functor_query)  | 
					
						
							|  |  |  | 	{  | 
					
						
							|  |  |  | 	  YAP_RunGoalOnce(ArgOfTerm (1, t)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  char *ErrorMessage = YAP_CompileClause(t); | 
					
						
							|  |  |  | 	  if (ErrorMessage) | 
					
						
							|  |  |  | 	    fprintf(stderr, "%s", ErrorMessage); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       /* do backtrack */ | 
					
						
							|  |  |  |       YAP_Reset(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-14 23:39:27 -08:00
										 |  |  |   YAP_EndConsult(bootfile); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2012-03-09 11:46:34 +00:00
										 |  |  |   if (Yap_output_msg) | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |     fprintf(stderr,"Boot loaded\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-05 09:51:52 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | construct_init_file(char *boot_file, char *BootFile) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* trust YAPSHAREDIR over YAP_PL_SRCDIR, and notice that the code is / dependent. */ | 
					
						
							|  |  |  | #if HAVE_GETENV
 | 
					
						
							|  |  |  |   if (getenv("YAPSHAREDIR")) { | 
					
						
							|  |  |  |     strncpy(boot_file, getenv("YAPSHAREDIR"), 256); | 
					
						
							|  |  |  |     strncat(boot_file, "/pl/", 255); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     strncpy(boot_file, YAP_PL_SRCDIR, 256); | 
					
						
							|  |  |  |     strncat(boot_file, "/", 255); | 
					
						
							|  |  |  | #if HAVE_GETENV
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   strncat(boot_file, BootFile, 255); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | /* this routine is supposed to be called from an external program
 | 
					
						
							|  |  |  |    that wants to control Yap */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-31 13:59:30 -07:00
										 |  |  | #if defined(USE_SYSTEM_MALLOC) && FALSE
 | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | #define  BOOT_FROM_SAVED_STATE FALSE
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define  BOOT_FROM_SAVED_STATE TRUE
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Init(YAP_init_args *yap_init) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   int restore_result; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |   int do_bootstrap = (yap_init->YapPrologBootFile != NULL); | 
					
						
							| 
									
										
										
										
											2009-03-27 15:15:54 +00:00
										 |  |  |   CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0; | 
					
						
							| 
									
										
										
										
											2012-04-12 23:25:04 +01:00
										 |  |  |   char boot_file[256]; | 
					
						
							|  |  |  |   static int initialised = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ignore repeated calls to YAP_Init */ | 
					
						
							|  |  |  |   if (initialised) | 
					
						
							|  |  |  |     return YAP_BOOT_DONE_BEFOREHAND; | 
					
						
							|  |  |  |   initialised = TRUE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-01 18:51:12 +01:00
										 |  |  |   Yap_InitPageSize();  /* init memory page size, required by later functions */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
 | 
					
						
							|  |  |  |   Yap_init_yapor_global_local_memory(); | 
					
						
							|  |  |  | #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
 | 
					
						
							| 
									
										
										
										
											2011-07-22 22:48:30 +01:00
										 |  |  |   GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts; | 
					
						
							| 
									
										
										
										
											2011-06-01 18:51:12 +01:00
										 |  |  |   Yap_InitSysbits();  /* init signal handling and time, required by later functions */ | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   GLOBAL_argv = yap_init->Argv; | 
					
						
							|  |  |  |   GLOBAL_argc = yap_init->Argc; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  | #if !BOOT_FROM_SAVED_STATE
 | 
					
						
							| 
									
										
										
										
											2008-04-02 21:44:07 +00:00
										 |  |  |   if (yap_init->SavedState) { | 
					
						
							| 
									
										
										
										
											2010-06-06 23:03:59 +01:00
										 |  |  |     fprintf(stderr,"[ WARNING: threaded YAP will ignore saved state %s ]\n",yap_init->SavedState); | 
					
						
							| 
									
										
										
										
											2008-04-02 21:44:07 +00:00
										 |  |  |     yap_init->SavedState = NULL; | 
					
						
							|  |  |  |   }     | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-08-31 13:59:30 -07:00
										 |  |  |   if (FALSE && BOOT_FROM_SAVED_STATE && !do_bootstrap) { | 
					
						
							|  |  |  |     if (Yap_SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       yap_init->ErrorNo = LOCAL_Error_TYPE; | 
					
						
							|  |  |  |       yap_init->ErrorCause = LOCAL_ErrorMessage; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |       return YAP_BOOT_ERROR; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (yap_init->TrailSize == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-10 13:36:55 -04:00
										 |  |  |     if (yap_init->MaxTrailSize) { | 
					
						
							|  |  |  |       Trail = yap_init->MaxTrailSize; | 
					
						
							|  |  |  |     } else if (Trail == 0) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Trail = DefTrailSpace; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Trail = yap_init->TrailSize; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-03-27 15:15:54 +00:00
										 |  |  |   Atts = yap_init->AttsSize; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   if (yap_init->StackSize == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-10 13:36:55 -04:00
										 |  |  |     if (yap_init->MaxStackSize || yap_init->MaxGlobalSize) { | 
					
						
							|  |  |  |       if (yap_init->MaxStackSize) { | 
					
						
							|  |  |  | 	if (yap_init->MaxGlobalSize) { | 
					
						
							|  |  |  | 	  Stack = yap_init->MaxStackSize+yap_init->MaxGlobalSize; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 	  Stack = yap_init->MaxStackSize+DefStackSpace/2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  | 	Stack = yap_init->MaxGlobalSize+DefStackSpace/2; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else if (Stack == 0) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Stack = DefStackSpace; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Stack = yap_init->StackSize; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (yap_init->HeapSize == 0) { | 
					
						
							|  |  |  |     if (Heap == 0) | 
					
						
							|  |  |  |       Heap = DefHeapSpace;   | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Heap = yap_init->HeapSize; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-03-27 15:15:54 +00:00
										 |  |  |   Yap_InitWorkspace(Heap, Stack, Trail, Atts, | 
					
						
							| 
									
										
										
										
											2005-08-04 15:45:56 +00:00
										 |  |  | 	      yap_init->MaxTableSpaceSize, | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	      yap_init->NumberWorkers, | 
					
						
							|  |  |  | 	      yap_init->SchedulerLoop, | 
					
						
							|  |  |  | 	      yap_init->DelayedReleaseLoad | 
					
						
							|  |  |  | 	      ); | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  | #if THREADS
 | 
					
						
							|  |  |  |   /* make sure we use the correct value of regcache */ | 
					
						
							|  |  |  |   regcache =  ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-04-02 17:37:07 +00:00
										 |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							|  |  |  |   if (Trail < MinTrailSpace) | 
					
						
							|  |  |  |     Trail = MinTrailSpace; | 
					
						
							|  |  |  |   if (Stack < MinStackSpace) | 
					
						
							|  |  |  |     Stack = MinStackSpace; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   if (!(LOCAL_GlobalBase = (ADDR)malloc((Trail+Stack)*1024))) { | 
					
						
							| 
									
										
										
										
											2008-04-02 17:37:07 +00:00
										 |  |  |     yap_init->ErrorNo = RESOURCE_ERROR_MEMORY; | 
					
						
							|  |  |  |     yap_init->ErrorCause = "could not allocate stack space for main thread"; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |     return YAP_BOOT_ERROR; | 
					
						
							| 
									
										
										
										
											2008-04-02 17:37:07 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-14 15:58:19 +00:00
										 |  |  | #if THREADS
 | 
					
						
							|  |  |  |   /* don't forget this is a thread */ | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   LOCAL_ThreadHandle.stack_address =  LOCAL_GlobalBase; | 
					
						
							| 
									
										
										
										
											2011-05-09 19:55:06 +01:00
										 |  |  |   LOCAL_ThreadHandle.ssize =  Trail+Stack; | 
					
						
							| 
									
										
										
										
											2010-01-14 15:58:19 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-04-02 17:37:07 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |   GLOBAL_AllowGlobalExpansion = TRUE; | 
					
						
							|  |  |  |   GLOBAL_AllowLocalExpansion = TRUE; | 
					
						
							|  |  |  |   GLOBAL_AllowTrailExpansion = TRUE; | 
					
						
							| 
									
										
										
										
											2004-02-05 16:57:02 +00:00
										 |  |  |   Yap_InitExStacks (Trail, Stack); | 
					
						
							| 
									
										
										
										
											2008-03-13 18:41:52 +00:00
										 |  |  |   if (yap_init->QuietMode) { | 
					
						
							|  |  |  |     yap_flags[QUIET_MODE_FLAG] = TRUE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-07-19 17:12:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |   { BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |     Yap_InitYaamRegs(); | 
					
						
							| 
									
										
										
										
											2002-02-11 20:46:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-22 14:31:45 +00:00
										 |  |  | #if HAVE_MPE
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |     Yap_InitMPE (); | 
					
						
							| 
									
										
										
										
											2002-02-22 14:31:45 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |      | 
					
						
							|  |  |  |     if (yap_init->YapPrologRCFile != NULL) { | 
					
						
							|  |  |  |       /*
 | 
					
						
							|  |  |  | 	This must be done before restore, otherwise | 
					
						
							|  |  |  | 	restore will print out messages .... | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  |       yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult; | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |     /* tell the system who should cope with interruptions */ | 
					
						
							|  |  |  |     Yap_ExecutionMode = yap_init->ExecutionMode; | 
					
						
							|  |  |  |     if (do_bootstrap) { | 
					
						
							|  |  |  |       restore_result = YAP_BOOT_FROM_PROLOG; | 
					
						
							|  |  |  |     } else if (BOOT_FROM_SAVED_STATE) { | 
					
						
							|  |  |  |       restore_result = Yap_Restore(yap_init->SavedState, yap_init->YapLibDir); | 
					
						
							|  |  |  |       if (restore_result == FAIL_RESTORE) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	yap_init->ErrorNo = LOCAL_Error_TYPE; | 
					
						
							|  |  |  | 	yap_init->ErrorCause = LOCAL_ErrorMessage; | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  | 	/* shouldn't RECOVER_MACHINE_REGS();  be here ??? */ | 
					
						
							|  |  |  | 	return YAP_BOOT_ERROR; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       restore_result = YAP_BOOT_FROM_PROLOG; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     yap_flags[FAST_BOOT_FLAG] = yap_init->FastBoot; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #if defined(YAPOR) || defined(TABLING)
 | 
					
						
							| 
									
										
										
										
											2011-06-01 18:51:12 +01:00
										 |  |  |     Yap_init_root_frames(); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:36:51 +01:00
										 |  |  | #endif /* YAPOR || TABLING */
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2011-06-01 18:51:12 +01:00
										 |  |  |     Yap_init_yapor_workers(); | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |     if (worker_id != 0) { | 
					
						
							| 
									
										
										
										
											2011-05-09 19:36:51 +01:00
										 |  |  | #if defined(YAPOR_COPY) || defined(YAPOR_SBA)
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |       /*
 | 
					
						
							|  |  |  | 	In the SBA we cannot just happily inherit registers | 
					
						
							|  |  |  | 	from the other workers | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  |       Yap_InitYaamRegs(); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:36:51 +01:00
										 |  |  | #endif /* YAPOR_COPY || YAPOR_SBA */
 | 
					
						
							|  |  |  | #ifndef YAPOR_THREADS
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |       Yap_InitPreAllocCodeSpace(); | 
					
						
							| 
									
										
										
										
											2011-05-09 19:36:51 +01:00
										 |  |  | #endif /* YAPOR_THREADS */
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |       /* slaves, waiting for work */ | 
					
						
							|  |  |  |       CurrentModule = USER_MODULE; | 
					
						
							|  |  |  |       P = GETWORK_FIRST_TIME; | 
					
						
							|  |  |  |       Yap_exec_absmi(FALSE); | 
					
						
							|  |  |  |       Yap_Error(INTERNAL_ERROR, TermNil, "abstract machine unexpected exit (YAP_Init)"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif /* YAPOR */
 | 
					
						
							| 
									
										
										
										
											2010-08-17 13:02:28 +01:00
										 |  |  |     RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   /* make sure we do this after restore */ | 
					
						
							|  |  |  |   if (yap_init->MaxStackSize) { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowLocalExpansion = FALSE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowLocalExpansion = TRUE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (yap_init->MaxGlobalSize) { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowGlobalExpansion = FALSE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowGlobalExpansion = TRUE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (yap_init->MaxTrailSize) { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowTrailExpansion = FALSE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |     GLOBAL_AllowTrailExpansion = TRUE; | 
					
						
							| 
									
										
										
										
											2009-05-12 17:01:53 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   if (yap_init->YapPrologRCFile) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomConsultOnBoot, MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologRCFile))); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |       This must be done again after restore, as yap_flags | 
					
						
							|  |  |  |       has been overwritten .... | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  | #ifdef MYDDAS_MYSQL
 | 
					
						
							|  |  |  |   if (yap_init->myddas) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomMyddasGoal,MkIntegerTerm(yap_init->myddas)); | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     /* Mandatory Fields */ | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomMyddasUser,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_user))); | 
					
						
							|  |  |  |     Yap_PutValue(AtomMyddasDB,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_db))); | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     /* Non-Mandatory Fields */ | 
					
						
							|  |  |  |     if (yap_init->myddas_pass != NULL) | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |       Yap_PutValue(AtomMyddasPass,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_pass))); | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  |     if (yap_init->myddas_host != NULL) | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |       Yap_PutValue(AtomMyddasHost,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_host))); | 
					
						
							| 
									
										
										
										
											2006-02-08 17:29:55 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   if (yap_init->YapPrologTopLevelGoal) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomTopLevelGoal, MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologTopLevelGoal))); | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (yap_init->YapPrologGoal) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomInitGoal, MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologGoal))); | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-10-28 17:38:50 +00:00
										 |  |  |   if (yap_init->YapPrologAddPath) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |     Yap_PutValue(AtomExtendFileSearchPath, MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologAddPath))); | 
					
						
							| 
									
										
										
										
											2005-10-28 17:38:50 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-03-13 18:41:52 +00:00
										 |  |  |   if (yap_init->QuietMode) { | 
					
						
							|  |  |  |     yap_flags[QUIET_MODE_FLAG] = TRUE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |   if (BOOT_FROM_SAVED_STATE && !do_bootstrap) { | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |     if (restore_result == FAIL_RESTORE) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       yap_init->ErrorNo = LOCAL_Error_TYPE; | 
					
						
							|  |  |  |       yap_init->ErrorCause = LOCAL_ErrorMessage; | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |       return YAP_BOOT_ERROR; | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-01 12:11:52 -05:00
										 |  |  |     if (Atts && Atts*1024 > 2048*sizeof(CELL)) | 
					
						
							|  |  |  |       Yap_AttsSize = Atts*1024; | 
					
						
							| 
									
										
										
										
											2009-03-27 15:15:54 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       Yap_AttsSize = 2048*sizeof(CELL); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     if (restore_result == DO_ONLY_CODE) { | 
					
						
							| 
									
										
										
										
											2010-12-07 15:06:53 +00:00
										 |  |  |       /* first, initialise the saved state */ | 
					
						
							|  |  |  |       Term t_goal = MkAtomTerm(AtomStartupSavedState); | 
					
						
							|  |  |  |       YAP_RunGoalOnce(t_goal); | 
					
						
							| 
									
										
										
										
											2010-12-14 09:30:40 +00:00
										 |  |  |       Yap_InitYaamRegs(); | 
					
						
							|  |  |  |       /* reset stacks */ | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |       return YAP_BOOT_FROM_SAVED_CODE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |       return YAP_BOOT_FROM_SAVED_STACKS; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* read the bootfile */ | 
					
						
							|  |  |  |     if (!do_bootstrap) { | 
					
						
							| 
									
										
										
										
											2010-03-05 09:51:52 +00:00
										 |  |  |       construct_init_file(boot_file, BootFile); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |       yap_init->YapPrologBootFile = boot_file; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     do_bootfile (yap_init->YapPrologBootFile ? yap_init->YapPrologBootFile : BootFile); | 
					
						
							|  |  |  |     /* initialise the top-level */ | 
					
						
							|  |  |  |     if (!do_bootstrap) { | 
					
						
							|  |  |  |       char init_file[256]; | 
					
						
							|  |  |  |       Atom atfile; | 
					
						
							|  |  |  |       Functor fgoal; | 
					
						
							|  |  |  |       YAP_Term goal, as[2]; | 
					
						
							| 
									
										
										
										
											2010-03-05 09:51:52 +00:00
										 |  |  |       construct_init_file(init_file, InitFile); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |       /* consult init file */ | 
					
						
							|  |  |  |       atfile = Yap_LookupAtom(init_file); | 
					
						
							|  |  |  |       as[0] = MkAtomTerm(atfile); | 
					
						
							|  |  |  |       fgoal = Yap_MkFunctor(Yap_FullLookupAtom("$silent_bootstrap"), 1); | 
					
						
							|  |  |  |       goal = Yap_MkApplTerm(fgoal, 1, as); | 
					
						
							|  |  |  |       /* launch consult */ | 
					
						
							|  |  |  |       YAP_RunGoalOnce(goal); | 
					
						
							|  |  |  |       /* set default module to user */ | 
					
						
							|  |  |  |       as[0] = MkAtomTerm(AtomUser); | 
					
						
							|  |  |  |       fgoal = Yap_MkFunctor(Yap_LookupAtom("module"), 1); | 
					
						
							|  |  |  |       goal = Yap_MkApplTerm(fgoal, 1, as); | 
					
						
							|  |  |  |       YAP_RunGoalOnce(goal); | 
					
						
							| 
									
										
										
										
											2010-12-14 09:30:40 +00:00
										 |  |  |       /* reset stacks */ | 
					
						
							|  |  |  |       Yap_InitYaamRegs(); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     Yap_PutValue(Yap_FullLookupAtom("$live"), MkAtomTerm (Yap_FullLookupAtom("$true"))); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-06 23:03:59 +01:00
										 |  |  |   return YAP_BOOT_FROM_PROLOG; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_FastInit(char saved_state[]) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |   YAP_init_args init_args; | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |   Int out; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   init_args.SavedState = saved_state; | 
					
						
							| 
									
										
										
										
											2009-03-27 15:15:54 +00:00
										 |  |  |   init_args.AttsSize = 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   init_args.HeapSize = 0; | 
					
						
							|  |  |  |   init_args.StackSize = 0; | 
					
						
							|  |  |  |   init_args.TrailSize = 0; | 
					
						
							| 
									
										
										
										
											2009-05-10 13:36:55 -04:00
										 |  |  |   init_args.MaxAttsSize = 0; | 
					
						
							|  |  |  |   init_args.MaxHeapSize = 0; | 
					
						
							|  |  |  |   init_args.MaxStackSize = 0; | 
					
						
							|  |  |  |   init_args.MaxGlobalSize = 0; | 
					
						
							|  |  |  |   init_args.MaxTrailSize = 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   init_args.YapLibDir = NULL; | 
					
						
							|  |  |  |   init_args.YapPrologBootFile = NULL; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   init_args.YapPrologInitFile = NULL; | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  |   init_args.YapPrologRCFile = NULL; | 
					
						
							| 
									
										
										
										
											2005-10-21 16:07:07 +00:00
										 |  |  |   init_args.YapPrologGoal = NULL; | 
					
						
							|  |  |  |   init_args.YapPrologTopLevelGoal = NULL; | 
					
						
							| 
									
										
										
										
											2005-10-28 17:38:50 +00:00
										 |  |  |   init_args.YapPrologAddPath = NULL; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   init_args.HaltAfterConsult = FALSE; | 
					
						
							| 
									
										
										
										
											2002-01-27 20:40:10 +00:00
										 |  |  |   init_args.FastBoot = FALSE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   init_args.NumberWorkers = 1; | 
					
						
							|  |  |  |   init_args.SchedulerLoop = 10; | 
					
						
							|  |  |  |   init_args.DelayedReleaseLoad = 3; | 
					
						
							| 
									
										
										
										
											2004-11-18 22:32:40 +00:00
										 |  |  |   init_args.PrologShouldHandleInterrupts = FALSE; | 
					
						
							| 
									
										
										
										
											2009-04-08 00:32:36 +01:00
										 |  |  |   init_args.ExecutionMode = INTERPRETED; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   init_args.Argc = 0; | 
					
						
							|  |  |  |   init_args.Argv = NULL; | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |   init_args.ErrorNo = 0; | 
					
						
							|  |  |  |   init_args.ErrorCause = NULL; | 
					
						
							| 
									
										
										
										
											2008-03-13 18:41:52 +00:00
										 |  |  |   init_args.QuietMode = FALSE; | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |   out = YAP_Init(&init_args); | 
					
						
							| 
									
										
										
										
											2010-01-26 12:20:46 +00:00
										 |  |  |   if (out == YAP_BOOT_ERROR) { | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |     Yap_Error(init_args.ErrorNo,TermNil,init_args.ErrorCause); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_PutValue(Atom at, Term t) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_PutValue(at, t); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_GetValue(Atom at) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   return(Yap_GetValue(at)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_CompareTerms(Term t1, Term t2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return Yap_compare_terms(t1, t2); | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Reset(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* first, backtrack to the root */ | 
					
						
							|  |  |  |   if (B != NULL) { | 
					
						
							|  |  |  |     while (B->cp_b != NULL) | 
					
						
							|  |  |  |       B = B->cp_b; | 
					
						
							| 
									
										
										
										
											2011-08-31 13:59:30 -07:00
										 |  |  |     P = FAILCODE; | 
					
						
							|  |  |  |     if (Yap_exec_absmi(0) != 0) { | 
					
						
							|  |  |  |       GLOBAL_Initialised = TRUE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Yap_InitYaamRegs(); | 
					
						
							|  |  |  |       RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   /* reinitialise the engine */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_InitYaamRegs(); | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |   GLOBAL_Initialised = TRUE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return(TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Exit(int retval) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_exit(retval); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_InitSocks(char *host, long port) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_SetOutputMessage(void) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if DEBUG
 | 
					
						
							| 
									
										
										
										
											2011-06-20 14:49:24 +01:00
										 |  |  |   Yap_output_msg = TRUE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_StreamToFileNo(Term t) | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   return(Yap_StreamToFileNo(t)); | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_CloseAllOpenStreams(void) | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_CloseStreams(FALSE); | 
					
						
							| 
									
										
										
										
											2001-05-21 20:00:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-11 17:02:10 +00:00
										 |  |  | X_API void | 
					
						
							|  |  |  | YAP_FlushAllStreams(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |   // VSC??  Yap_FlushStreams();
 | 
					
						
							| 
									
										
										
										
											2008-07-11 17:02:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Throw(Term t) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_JumpToEnv(t); | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-04 19:05:13 +00:00
										 |  |  | X_API void | 
					
						
							|  |  |  | YAP_AsyncThrow(Term t) | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  | {  | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2010-12-04 19:05:13 +00:00
										 |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode |= AsyncIntMode; | 
					
						
							| 
									
										
										
										
											2010-12-04 19:05:13 +00:00
										 |  |  |   Yap_JumpToEnv(t); | 
					
						
							| 
									
										
										
										
											2011-05-25 16:40:36 +01:00
										 |  |  |   LOCAL_PrologMode &= ~AsyncIntMode; | 
					
						
							| 
									
										
										
										
											2010-12-04 19:05:13 +00:00
										 |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_Halt(int i) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_exit(i); | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API CELL * | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_TopOfLocalStack(void) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  |   return(ASP); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void * | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_Predicate(Atom a, UInt arity, Term m) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (arity == 0) { | 
					
						
							|  |  |  |     return((void *)RepPredProp(PredPropByAtom(a,m))); | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     Functor f = Yap_MkFunctor(a, arity); | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  |     return((void *)RepPredProp(PredPropByFunc(f,m))); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_PredicateInfo(void *p, Atom* a, UInt* arity, Term* m) | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PredEntry *pd = (PredEntry *)p; | 
					
						
							|  |  |  |   if (pd->ArityOfPE) { | 
					
						
							|  |  |  |     *arity = pd->ArityOfPE; | 
					
						
							|  |  |  |     *a = NameOfFunctor(pd->FunctorOfPred); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     *arity = 0; | 
					
						
							|  |  |  |     *a = (Atom)(pd->FunctorOfPred); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |   if (pd->ModuleOfPred) | 
					
						
							|  |  |  |     *m = pd->ModuleOfPred; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     *m = TermProlog; | 
					
						
							| 
									
										
										
										
											2002-05-06 15:33:05 +00:00
										 |  |  | }  | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | X_API void  | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_UserCPredicate(char *name, CPredicate def, UInt arity) | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_InitCPred(name, arity, def, UserCPredFlag); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void  | 
					
						
							|  |  |  | YAP_UserBackCPredicate(char *name, CPredicate init, CPredicate cont, | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | 		   UInt arity, unsigned int extra) | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  |   Yap_InitCPredBackCut(name, arity, extra, init, cont, NULL ,UserCPredFlag); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   Yap_InitCPredBack(name, arity, extra, init, cont, UserCPredFlag); | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #ifdef CUT_C
 | 
					
						
							|  |  |  | X_API void  | 
					
						
							|  |  |  | YAP_UserBackCutCPredicate(char *name, CPredicate init, CPredicate cont, CPredicate cut, | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | 			  UInt arity, unsigned int extra) | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Yap_InitCPredBackCut(name, arity, extra, init, cont, cut, UserCPredFlag); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  | X_API void | 
					
						
							| 
									
										
										
										
											2010-05-10 10:21:56 +01:00
										 |  |  | YAP_UserCPredicateWithArgs(char *a, CPredicate f, UInt arity, Term mod) | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   PredEntry *pe; | 
					
						
							| 
									
										
										
										
											2004-02-12 12:37:12 +00:00
										 |  |  |   Term cm = CurrentModule; | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   CurrentModule = mod; | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |   YAP_UserCPredicate(a,f,arity); | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   if (arity == 0) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     pe = RepPredProp(PredPropByAtom(Yap_LookupAtom(a),mod)); | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     Functor f = Yap_MkFunctor(Yap_LookupAtom(a), arity); | 
					
						
							| 
									
										
										
										
											2002-05-16 20:33:00 +00:00
										 |  |  |     pe = RepPredProp(PredPropByFunc(f,mod)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   pe->PredFlags |= CArgsPredFlag; | 
					
						
							|  |  |  |   CurrentModule = cm; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | YAP_CurrentModule(void) | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   return(CurrentModule); | 
					
						
							|  |  |  | }  | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 14:13:45 -08:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_SetCurrentModule(Term new) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-02-14 14:13:45 -08:00
										 |  |  |   Term omod = CurrentModule; | 
					
						
							|  |  |  |   CurrentModule = new; | 
					
						
							|  |  |  |   return omod; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_CreateModule(Atom at) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-04-18 23:01:16 +00:00
										 |  |  |   Term t; | 
					
						
							|  |  |  |   WRITE_LOCK(RepAtom(at)->ARWLock);   | 
					
						
							|  |  |  |   t = Yap_Module(MkAtomTerm(at)); | 
					
						
							|  |  |  |   WRITE_UNLOCK(RepAtom(at)->ARWLock);   | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-11 16:14:55 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 21:44:25 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_StripModule(Term t,  Term *modp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-07 20:51:23 +00:00
										 |  |  |   return Yap_StripModule(t, modp); | 
					
						
							| 
									
										
										
										
											2008-08-01 21:44:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_ThreadSelf(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-08 10:40:55 +01:00
										 |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  |   return Yap_thread_self(); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-07-27 23:29:55 +01:00
										 |  |  |   return -2; | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-23 15:54:13 +01:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_ThreadCreateEngine(struct thread_attr_struct * attr) | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-08 10:40:55 +01:00
										 |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  |   return Yap_thread_create_engine(attr); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-07-23 15:54:13 +01:00
										 |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2010-07-23 15:54:13 +01:00
										 |  |  | YAP_ThreadAttachEngine( int wid) | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-08 10:40:55 +01:00
										 |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  |   return Yap_thread_attach_engine(wid); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_ThreadDetachEngine(int wid) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-08 10:40:55 +01:00
										 |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  |   return Yap_thread_detach_engine(wid); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_ThreadDestroyEngine(int wid) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-08 10:40:55 +01:00
										 |  |  | #if THREADS
 | 
					
						
							| 
									
										
										
										
											2004-07-22 21:32:23 +00:00
										 |  |  |   return Yap_thread_destroy_engine(wid); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   return FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | X_API Term | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  | YAP_TermNil(void) | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-12-13 16:10:26 +00:00
										 |  |  |   return TermNil; | 
					
						
							| 
									
										
										
										
											2006-05-16 18:37:31 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 22:46:16 +01:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_IsTermNil(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return t == TermNil; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_AtomGetHold(Atom at) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-21 10:12:47 -02:00
										 |  |  |   return Yap_AtomIncreaseHold(at); | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_AtomReleaseHold(Atom at) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-21 10:12:47 -02:00
										 |  |  |   return Yap_AtomDecreaseHold(at); | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-12 17:03:59 +00:00
										 |  |  | X_API Agc_hook | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | YAP_AGCRegisterHook(Agc_hook hook) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |   Agc_hook old = GLOBAL_AGCHook; | 
					
						
							|  |  |  |   GLOBAL_AGCHook = hook; | 
					
						
							| 
									
										
										
										
											2008-02-12 17:03:59 +00:00
										 |  |  |   return old; | 
					
						
							| 
									
										
										
										
											2007-12-05 12:17:25 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-24 14:00:53 +01:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_HaltRegisterHook(HaltHookFunc hook, void * closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return Yap_HaltRegisterHook(hook, closure); | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  | X_API char * | 
					
						
							|  |  |  | YAP_cwd(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  |   char *buf; | 
					
						
							|  |  |  |   int len; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   if (!Yap_getcwd(LOCAL_FileNameBuf, YAP_FILENAME_MAX)) | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  |     return FALSE; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   len = strlen(LOCAL_FileNameBuf); | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  |   buf = Yap_AllocCodeSpace(len+1); | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  |   if (!buf) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |   strncpy(buf, LOCAL_FileNameBuf, len); | 
					
						
							| 
									
										
										
										
											2008-12-13 16:07:55 +00:00
										 |  |  |   return buf; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_FloatsToList(double *dblp, size_t sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  |   CELL *oldH; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!sz) | 
					
						
							|  |  |  |     return TermNil; | 
					
						
							|  |  |  |   while (ASP-1024 < H + sz*(2+2+SIZEOF_DOUBLE/SIZEOF_LONG_INT)) { | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |     if ((CELL *)dblp > H0 && (CELL *)dblp < H) { | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |       /* we are in trouble */ | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |       LOCAL_OpenArray =  (CELL *)dblp; | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |       RECOVER_H(); | 
					
						
							|  |  |  |       return 0L; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-09 23:29:31 +00:00
										 |  |  |     dblp = (double *)LOCAL_OpenArray; | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |     LOCAL_OpenArray = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   t = AbsPair(H); | 
					
						
							|  |  |  |   while (sz) { | 
					
						
							|  |  |  |     oldH = H; | 
					
						
							|  |  |  |     H +=2; | 
					
						
							|  |  |  |     oldH[0] = MkFloatTerm(*dblp++); | 
					
						
							|  |  |  |     oldH[1] = AbsPair(H); | 
					
						
							|  |  |  |     sz--; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   oldH[1] = TermNil; | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-14 11:08:28 +00:00
										 |  |  | X_API Int | 
					
						
							|  |  |  | YAP_ListToFloats(Term t, double *dblp, size_t sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   size_t i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   do { | 
					
						
							|  |  |  |     Term hd; | 
					
						
							|  |  |  |     if (IsVarTerm(t)) | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  |     if (t == TermNil) | 
					
						
							|  |  |  |       return i; | 
					
						
							|  |  |  |     if (!IsPairTerm(t)) | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     hd = HeadOfTerm(t); | 
					
						
							| 
									
										
										
										
											2012-03-22 21:38:22 +00:00
										 |  |  |     if (IsFloatTerm(hd)) { | 
					
						
							|  |  |  |       dblp[i++] = FloatOfTerm(hd); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       extern double Yap_gmp_to_float(Term hd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (IsIntTerm(hd)) | 
					
						
							|  |  |  | 	dblp[i++] = IntOfTerm(hd); | 
					
						
							|  |  |  |       else if (IsLongIntTerm(hd)) | 
					
						
							|  |  |  | 	dblp[i++] = LongIntOfTerm(hd); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:50:27 +01:00
										 |  |  | #if USE_GMP
 | 
					
						
							| 
									
										
										
										
											2012-03-22 21:38:22 +00:00
										 |  |  |       else if (IsBigIntTerm(hd)) | 
					
						
							|  |  |  | 	dblp[i++] = Yap_gmp_to_float(hd); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:50:27 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-03-22 21:38:22 +00:00
										 |  |  |       else | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-03-14 11:08:28 +00:00
										 |  |  |     if (i == sz) | 
					
						
							|  |  |  |       return sz; | 
					
						
							|  |  |  |     t = TailOfTerm(t); | 
					
						
							|  |  |  |   } while (TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_IntsToList(Int *dblp, size_t sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  |   CELL *oldH; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!sz) | 
					
						
							|  |  |  |     return TermNil; | 
					
						
							|  |  |  |   while (ASP-1024 < H + sz*3) { | 
					
						
							|  |  |  |     if ((CELL *)dblp > H0 && (CELL *)dblp < H) { | 
					
						
							|  |  |  |       /* we are in trouble */ | 
					
						
							|  |  |  |       LOCAL_OpenArray =  (CELL *)dblp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							|  |  |  |       RECOVER_H(); | 
					
						
							|  |  |  |       return 0L; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dblp = (Int *)LOCAL_OpenArray; | 
					
						
							|  |  |  |     LOCAL_OpenArray = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   t = AbsPair(H); | 
					
						
							|  |  |  |   while (sz) { | 
					
						
							|  |  |  |     oldH = H; | 
					
						
							|  |  |  |     H +=2; | 
					
						
							|  |  |  |     oldH[0] = MkIntegerTerm(*dblp++); | 
					
						
							|  |  |  |     oldH[1] = AbsPair(H); | 
					
						
							|  |  |  |     sz--; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   oldH[1] = TermNil; | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Int | 
					
						
							|  |  |  | YAP_ListToInts(Term t, Int *dblp, size_t sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   size_t i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   do { | 
					
						
							|  |  |  |     Term hd; | 
					
						
							|  |  |  |     if (IsVarTerm(t)) | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  |     if (t == TermNil) | 
					
						
							|  |  |  |       return i; | 
					
						
							|  |  |  |     if (!IsPairTerm(t)) | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     hd = HeadOfTerm(t); | 
					
						
							|  |  |  |     if (!IsIntTerm(hd)) | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     dblp[i++] = IntOfTerm(hd); | 
					
						
							|  |  |  |     if (i == sz) | 
					
						
							|  |  |  |       return sz; | 
					
						
							|  |  |  |     t = TailOfTerm(t); | 
					
						
							|  |  |  |   } while (TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  | X_API Term | 
					
						
							|  |  |  | YAP_OpenList(int n) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  |   Term t; | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 16:04:16 +00:00
										 |  |  |   while (H+2*n > ASP-1024) { | 
					
						
							| 
									
										
										
										
											2012-02-02 23:25:09 +00:00
										 |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							| 
									
										
										
										
											2009-06-01 19:28:30 -05:00
										 |  |  |       RECOVER_H(); | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  |       return FALSE; | 
					
						
							| 
									
										
										
										
											2009-06-01 19:28:30 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   t = AbsPair(H); | 
					
						
							|  |  |  |   H += 2*n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_ExtendList(Term t0, Term inp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Term t; | 
					
						
							|  |  |  |   CELL *ptr = RepPair(t0); | 
					
						
							| 
									
										
										
										
											2009-06-15 10:29:31 -05:00
										 |  |  |   BACKUP_H(); | 
					
						
							| 
									
										
										
										
											2008-12-22 13:49:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ptr[0] = inp; | 
					
						
							|  |  |  |   ptr[1] = AbsPair(ptr+2); | 
					
						
							|  |  |  |   t = AbsPair(ptr+2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_CloseList(Term t0, Term tail) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CELL *ptr = RepPair(t0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RESET_VARIABLE(ptr-1); | 
					
						
							|  |  |  |   if (!Yap_unify((Term)(ptr-1), tail)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 14:24:20 +00:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | YAP_IsAttVar(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   if (!IsVarTerm(t)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							| 
									
										
										
										
											2010-03-08 09:19:35 +00:00
										 |  |  |   return IsAttVar(VarOfTerm(t)); | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_AttsOfVar(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   attvar_record *attv; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   if (!IsVarTerm(t)) | 
					
						
							|  |  |  |     return TermNil; | 
					
						
							| 
									
										
										
										
											2012-05-21 17:24:40 +01:00
										 |  |  |   if(!IsAttVar(VarOfTerm(t))) | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  |     return TermNil; | 
					
						
							| 
									
										
										
										
											2012-05-21 17:24:40 +01:00
										 |  |  |   attv = RepAttVar(VarOfTerm(t)); | 
					
						
							| 
									
										
										
										
											2009-02-09 22:45:50 +00:00
										 |  |  |   return attv->Atts; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 21:42:15 -05:00
										 |  |  | X_API int | 
					
						
							| 
									
										
										
										
											2009-04-25 10:28:34 -05:00
										 |  |  | YAP_FileNoFromStream(Term t) | 
					
						
							| 
									
										
										
										
											2009-04-22 21:42:15 -05:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  t = Deref(t); | 
					
						
							|  |  |  |  if (IsVarTerm(t)) | 
					
						
							|  |  |  |    return -1; | 
					
						
							|  |  |  |  return Yap_StreamToFileNo(t); | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |  return -1; | 
					
						
							| 
									
										
										
										
											2009-04-22 21:42:15 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 16:41:41 -05:00
										 |  |  | X_API void * | 
					
						
							|  |  |  | YAP_FileDescriptorFromStream(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   if (IsVarTerm(t)) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   return Yap_FileDescriptorFromStream(t); | 
					
						
							| 
									
										
										
										
											2011-02-15 06:43:28 -08:00
										 |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2009-04-22 16:41:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | X_API void * | 
					
						
							|  |  |  | YAP_Record(Term t) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |   DBTerm *dbterm; | 
					
						
							|  |  |  |   DBRecordList *dbt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   dbterm = Yap_StoreTermInDB(Deref(t), 0); | 
					
						
							|  |  |  |   if (dbterm == NULL) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   dbt = (struct record_list *)Yap_AllocCodeSpace(sizeof(struct record_list)); | 
					
						
							|  |  |  |   while (dbt == NULL) { | 
					
						
							|  |  |  |     if (!Yap_growheap(FALSE, sizeof(struct record_list), NULL)) { | 
					
						
							|  |  |  |       /* be a good neighbor */ | 
					
						
							|  |  |  |       Yap_FreeCodeSpace((void *)dbterm); | 
					
						
							|  |  |  |       Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "using YAP_Record"); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (Yap_Records) { | 
					
						
							|  |  |  |     Yap_Records->prev_rec = dbt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   dbt->next_rec = Yap_Records; | 
					
						
							|  |  |  |   dbt->prev_rec = NULL; | 
					
						
							|  |  |  |   dbt->dbrecord = dbterm; | 
					
						
							|  |  |  |   Yap_Records = dbt; | 
					
						
							|  |  |  |   return dbt; | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_Recorded(void *handle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |   Term t; | 
					
						
							|  |  |  |   DBTerm *dbterm = ((DBRecordList *)handle)->dbrecord; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BACKUP_MACHINE_REGS(); | 
					
						
							|  |  |  |   do { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |     LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |     t = Yap_FetchTermFromDB(dbterm); | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |     if (LOCAL_Error_TYPE == YAP_NO_ERROR) { | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |       RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |       return t; | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |     } else if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) { | 
					
						
							|  |  |  |       LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |       if (!Yap_growglobal(NULL)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  | 	RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  |       LOCAL_Error_TYPE = YAP_NO_ERROR; | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |       if (!Yap_growstack(dbterm->NOfCells*CellSize)) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage); | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  | 	RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } while (t == (CELL)0); | 
					
						
							|  |  |  |   RECOVER_MACHINE_REGS(); | 
					
						
							|  |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API int | 
					
						
							|  |  |  | YAP_Erase(void *handle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |   DBRecordList *dbr = (DBRecordList *)handle; | 
					
						
							|  |  |  |   if (dbr->next_rec)  | 
					
						
							|  |  |  |     dbr->next_rec->prev_rec = dbr->prev_rec; | 
					
						
							|  |  |  |   if (dbr->prev_rec)  | 
					
						
							| 
									
										
										
										
											2011-03-11 23:21:23 +00:00
										 |  |  |     dbr->prev_rec->next_rec = dbr->next_rec; | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |   else if (Yap_Records == dbr) { | 
					
						
							|  |  |  |     Yap_Records = dbr->next_rec; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-03-11 23:21:23 +00:00
										 |  |  |   Yap_ReleaseTermFromDB(dbr->dbrecord); | 
					
						
							| 
									
										
										
										
											2011-01-02 21:16:29 -06:00
										 |  |  |   Yap_FreeCodeSpace(handle); | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-04 17:36:20 +01:00
										 |  |  | X_API Int | 
					
						
							|  |  |  | YAP_ArgsToSlots(int n) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Int slot = Yap_NewSlots(n PASS_REGS); | 
					
						
							| 
									
										
										
										
											2010-08-04 17:36:20 +01:00
										 |  |  |   CELL *ptr0 = LCL0+slot, *ptr1=&ARG1; | 
					
						
							|  |  |  |   while (n--) { | 
					
						
							|  |  |  |     *ptr0++ = *ptr1++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return slot; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API void | 
					
						
							|  |  |  | YAP_SlotsToArgs(int n, Int slot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2010-08-04 17:36:20 +01:00
										 |  |  |   CELL *ptr0 = LCL0+slot, *ptr1=&ARG1; | 
					
						
							|  |  |  |   while (n--) { | 
					
						
							|  |  |  |     *ptr1++ = *ptr0++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 11:26:46 +00:00
										 |  |  | X_API void  | 
					
						
							|  |  |  | YAP_signal(int sig) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Yap_signal(sig); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-30 22:25:56 -05:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_SetYAPFlag(yap_flag_t flag, int val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (flag) { | 
					
						
							|  |  |  |   case YAPC_ENABLE_GC: | 
					
						
							|  |  |  |     if (val) { | 
					
						
							|  |  |  |       Yap_PutValue(AtomGc, MkAtomTerm(AtomTrue)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       Yap_PutValue(AtomGc, TermNil); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return TRUE; | 
					
						
							|  |  |  |   case YAPC_ENABLE_AGC: | 
					
						
							|  |  |  |     if (val) { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |       GLOBAL_AGcThreshold = 10000; | 
					
						
							| 
									
										
										
										
											2010-08-30 22:25:56 -05:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2011-05-10 10:06:51 +01:00
										 |  |  |       GLOBAL_AGcThreshold = 0; | 
					
						
							| 
									
										
										
										
											2010-08-30 22:25:56 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     return TRUE; | 
					
						
							|  |  |  |   default: | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  | /*    Int  YAP_VarSlotToNumber(Int)  */ | 
					
						
							|  |  |  | Int YAP_VarSlotToNumber(Int s) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  |   Term *t = (CELL *)Deref(Yap_GetFromSlot(s PASS_REGS)); | 
					
						
							| 
									
										
										
										
											2011-02-10 00:01:19 +00:00
										 |  |  |   if (t < H) | 
					
						
							|  |  |  |     return t-H0; | 
					
						
							|  |  |  |   return t-LCL0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*    Term  YAP_ModuleUser()  */ | 
					
						
							|  |  |  | Term YAP_ModuleUser(void) { | 
					
						
							|  |  |  |   return MkAtomTerm(AtomUser); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*    int  YAP_PredicateHasClauses()  */ | 
					
						
							|  |  |  | Int YAP_NumberOfClausesForPredicate(PredEntry *pe) { | 
					
						
							|  |  |  |   return pe->cs.p_code.NOfClauses; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-08-02 19:48:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-10 21:14:38 +00:00
										 |  |  | int YAP_MaxOpPriority(Atom at, Term module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   AtomEntry      *ae = RepAtom(at); | 
					
						
							|  |  |  |   OpEntry        *info; | 
					
						
							|  |  |  |   WRITE_LOCK(ae->ARWLock); | 
					
						
							|  |  |  |   info = Yap_GetOpPropForAModuleHavingALock(ae, module); | 
					
						
							|  |  |  |   if (!info) { | 
					
						
							|  |  |  |     WRITE_UNLOCK(ae->ARWLock); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   int ret = info->Prefix; | 
					
						
							|  |  |  |   if (info->Infix > ret) | 
					
						
							|  |  |  |     ret = info->Infix; | 
					
						
							|  |  |  |   if (info->Posfix > ret) | 
					
						
							|  |  |  |     ret = info->Posfix; | 
					
						
							|  |  |  |   WRITE_UNLOCK(ae->ARWLock); | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 16:46:39 +01:00
										 |  |  | int | 
					
						
							|  |  |  | YAP_OpInfo(Atom at, Term module, int opkind, int *yap_type, int *prio) | 
					
						
							| 
									
										
										
										
											2011-02-10 21:14:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   AtomEntry      *ae = RepAtom(at); | 
					
						
							|  |  |  |   OpEntry        *info; | 
					
						
							|  |  |  |   int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   WRITE_LOCK(ae->ARWLock); | 
					
						
							|  |  |  |   info = Yap_GetOpPropForAModuleHavingALock(ae, module); | 
					
						
							|  |  |  |   if (!info) { | 
					
						
							| 
									
										
										
										
											2011-02-15 07:50:55 -08:00
										 |  |  |     /* try system operators */ | 
					
						
							|  |  |  |     info = Yap_GetOpPropForAModuleHavingALock(ae, PROLOG_MODULE); | 
					
						
							|  |  |  |     if (!info) { | 
					
						
							|  |  |  |       WRITE_UNLOCK(ae->ARWLock); | 
					
						
							|  |  |  |       return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-10 21:14:38 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (opkind == PREFIX_OP) { | 
					
						
							|  |  |  |     SMALLUNSGN p = info->Prefix; | 
					
						
							|  |  |  |     if (!p) { | 
					
						
							|  |  |  |       WRITE_UNLOCK(ae->ARWLock); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (p & DcrrpFlag) { | 
					
						
							|  |  |  |       n = 6; | 
					
						
							|  |  |  |       *prio = (p ^ DcrrpFlag); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       n = 7; | 
					
						
							|  |  |  |       *prio = p; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } else if (opkind == INFIX_OP) { | 
					
						
							|  |  |  |     SMALLUNSGN p = info->Infix; | 
					
						
							|  |  |  |     if (!p) { | 
					
						
							|  |  |  |       WRITE_UNLOCK(ae->ARWLock); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((p & DcrrpFlag) && (p & DcrlpFlag)) { | 
					
						
							|  |  |  |       n = 1; | 
					
						
							|  |  |  |       *prio = (p ^ (DcrrpFlag | DcrlpFlag)); | 
					
						
							|  |  |  |     } else if (p & DcrrpFlag) { | 
					
						
							|  |  |  |       n = 3; | 
					
						
							|  |  |  |       *prio = (p ^ DcrrpFlag); | 
					
						
							|  |  |  |     } else if (p & DcrlpFlag) { | 
					
						
							|  |  |  |       n = 2; | 
					
						
							|  |  |  |       *prio = (p ^ DcrlpFlag); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       n = 4; | 
					
						
							|  |  |  |       *prio = p; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     SMALLUNSGN p = info->Posfix; | 
					
						
							|  |  |  |     if (p & DcrlpFlag) { | 
					
						
							|  |  |  |       n = 4; | 
					
						
							|  |  |  |       *prio = (p ^ DcrlpFlag); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       n = 5; | 
					
						
							|  |  |  |       *prio = p; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   *yap_type = n; | 
					
						
							| 
									
										
										
										
											2011-03-01 10:32:25 +00:00
										 |  |  |   WRITE_UNLOCK(ae->ARWLock); | 
					
						
							| 
									
										
										
										
											2011-02-10 21:14:38 +00:00
										 |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 16:46:39 +01:00
										 |  |  | int | 
					
						
							|  |  |  | YAP_Argv(char ***argvp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (argvp) { | 
					
						
							|  |  |  |     *argvp = GLOBAL_argv; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return GLOBAL_argc; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-10-27 12:35:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | YAP_tag_t | 
					
						
							|  |  |  | YAP_TagOfTerm(Term t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (IsVarTerm(t)) { | 
					
						
							|  |  |  |     CELL *pt = VarOfTerm(t); | 
					
						
							|  |  |  |     if (IsUnboundVar(pt)) { | 
					
						
							|  |  |  |       if (IsAttVar(pt)) | 
					
						
							|  |  |  | 	return YAP_TAG_ATT; | 
					
						
							|  |  |  |       return YAP_TAG_UNBOUND; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return YAP_TAG_REF; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (IsPairTerm(t)) | 
					
						
							|  |  |  |     return YAP_TAG_PAIR; | 
					
						
							|  |  |  |   if (IsAtomOrIntTerm(t)) { | 
					
						
							|  |  |  |     if (IsAtomTerm(t)) | 
					
						
							|  |  |  |       return YAP_TAG_ATOM; | 
					
						
							|  |  |  |     return YAP_TAG_INT; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Functor f = FunctorOfTerm(t); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     if (IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |       if (f == FunctorDBRef) { | 
					
						
							|  |  |  | 	return YAP_TAG_DBREF; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (f == FunctorLongInt) { | 
					
						
							|  |  |  | 	return YAP_TAG_LONG_INT; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (f == FunctorBigInt) { | 
					
						
							|  |  |  | 	big_blob_type bt = RepAppl(t)[1]; | 
					
						
							|  |  |  | 	switch (bt) { | 
					
						
							|  |  |  | 	case BIG_INT: | 
					
						
							|  |  |  | 	  return YAP_TAG_BIG_INT; | 
					
						
							|  |  |  | 	case BIG_RATIONAL: | 
					
						
							|  |  |  | 	  return YAP_TAG_RATIONAL; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	  return YAP_TAG_OPAQUE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return YAP_TAG_APPL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | int YAP_BPROLOG_exception; | 
					
						
							|  |  |  | Term YAP_BPROLOG_curr_toam_status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Int | 
					
						
							|  |  |  | YAP_ListLength(Term t) { | 
					
						
							| 
									
										
										
										
											2012-03-14 11:08:28 +00:00
										 |  |  |   Term *aux; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Int n = Yap_SkipList(&t, &aux); | 
					
						
							|  |  |  |   if (IsVarTerm(*aux)) | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   if (*aux == TermNil) | 
					
						
							|  |  |  |     return n; | 
					
						
							|  |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Int | 
					
						
							|  |  |  | YAP_NumberVars(Term t, Int nbv) { | 
					
						
							| 
									
										
										
										
											2012-03-14 22:10:21 +00:00
										 |  |  |   return Yap_NumberVars(t, nbv, FALSE); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Term | 
					
						
							|  |  |  | YAP_UnNumberVars(Term t) { | 
					
						
							| 
									
										
										
										
											2011-11-04 09:28:33 +00:00
										 |  |  |   /* don't allow sharing of ground terms */ | 
					
						
							|  |  |  |   return Yap_UnNumberTerm(t, FALSE); | 
					
						
							| 
									
										
										
										
											2011-11-03 07:52:52 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | YAP_IsNumberedVariable(Term t) { | 
					
						
							|  |  |  |   return IsApplTerm(t) && | 
					
						
							|  |  |  |     FunctorOfTerm(t) == FunctorVar && | 
					
						
							|  |  |  |     IsIntegerTerm(ArgOfTerm(1,t)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 09:58:05 +00:00
										 |  |  | X_API size_t | 
					
						
							| 
									
										
										
										
											2012-02-01 19:26:28 +00:00
										 |  |  | YAP_ExportTerm(Term inp, char * buf, size_t len) { | 
					
						
							| 
									
										
										
										
											2012-02-02 09:58:05 +00:00
										 |  |  |   if (!len) | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2012-02-03 16:31:49 +00:00
										 |  |  |   return Yap_ExportTerm(inp, buf, len, current_arity()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API size_t | 
					
						
							|  |  |  | YAP_SizeOfExportedTerm(char * buf) { | 
					
						
							|  |  |  |   if (!buf) | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   return Yap_SizeOfExportedTerm(buf); | 
					
						
							| 
									
										
										
										
											2012-02-01 19:26:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | X_API Term | 
					
						
							|  |  |  | YAP_ImportTerm(char * buf) { | 
					
						
							|  |  |  |   return Yap_ImportTerm(buf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 09:49:36 +01:00
										 |  |  | X_API int | 
					
						
							|  |  |  | YAP_RequiresExtraStack(size_t sz) { | 
					
						
							| 
									
										
										
										
											2012-04-11 22:08:02 +01:00
										 |  |  |   CACHE_REGS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 09:49:36 +01:00
										 |  |  |   if (sz < 16*1024)  | 
					
						
							|  |  |  |     sz = 16*1024; | 
					
						
							|  |  |  |   if (H <= ASP-sz) { | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   BACKUP_H(); | 
					
						
							|  |  |  |   while (H > ASP-sz) { | 
					
						
							|  |  |  |     CACHE_REGS | 
					
						
							|  |  |  |     RECOVER_H(); | 
					
						
							|  |  |  |     if (!dogc( 0, NULL PASS_REGS )) { | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     BACKUP_H(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   RECOVER_H(); | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } |