| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	 Yap Prolog 							 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	Yap Prolog Was Developed At Nccup - Universidade Do Porto	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | ************************************************************************** | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * File:		Yap.C							 * | 
					
						
							|  |  |  | * Last Rev:								 * | 
					
						
							|  |  |  | * Mods:									 * | 
					
						
							|  |  |  | * Comments:	Yap's Main File						 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *************************************************************************/ | 
					
						
							|  |  |  | /* static char SccsId[] = "X 4.3.3"; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | #include "YapInterface.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-18 18:52:41 +00:00
										 |  |  | #include "cut_c.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
 | 
					
						
							|  |  |  | #ifdef  HAVE_UNISTD_H
 | 
					
						
							|  |  |  | #undef  HAVE_UNISTD_H
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #if HAVE_SYS_TYPES_H
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #if HAVE_SYS_STAT_H
 | 
					
						
							|  |  |  | #include <sys/stat.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #if HAVE_FCNTL_H
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #if HAVE_STDARG_H
 | 
					
						
							|  |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #if HAVE_UNISTD_H
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #if HAVE_ERRNO_H
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-10-16 17:19:14 +01:00
										 |  |  | #if HAVE_CTYPE_H
 | 
					
						
							|  |  |  | #include <ctype.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #if HAVE_STRING_H
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-03-27 14:20:34 +01:00
										 |  |  | #if HAVE_IEEEFP_H
 | 
					
						
							|  |  |  | #include <ieeefp.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:14:56 -05:00
										 |  |  | static void do_top_goal(YAP_Term Goal); | 
					
						
							|  |  |  | static void exec_top_level(int BootMode, YAP_init_args *iap); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef lint
 | 
					
						
							|  |  |  | /* VARARGS1 */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef M_WILLIAMS
 | 
					
						
							|  |  |  | long _stksize = 32000; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-25 22:03:14 +00:00
										 |  |  | #ifdef USE_MYPUTC
 | 
					
						
							| 
									
										
										
										
											2003-05-20 19:11:59 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | myputc (int ch) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   putc(ch,stderr); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-05-14 16:34:49 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  | do_top_goal (YAP_Term Goal) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |   YAP_RunGoalOnce(Goal); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  | init_standard_system(int argc, char *argv[], YAP_init_args *iap) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int BootMode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 03:56:01 -05:00
										 |  |  |   BootMode = YAP_parse_yap_arguments(argc,argv,iap); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* init memory */ | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   if (BootMode == YAP_BOOT_FROM_PROLOG || | 
					
						
							|  |  |  |       BootMode == YAP_FULL_BOOT_FROM_PROLOG) { | 
					
						
							| 
									
										
										
										
											2005-03-09 06:35:52 +00:00
										 |  |  |     int NewBootMode = YAP_Init(iap); | 
					
						
							|  |  |  |     if (NewBootMode != YAP_BOOT_FROM_PROLOG && BootMode != YAP_FULL_BOOT_FROM_PROLOG) | 
					
						
							|  |  |  |       BootMode = NewBootMode; | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     BootMode = YAP_Init(iap); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |   if (iap->ErrorNo) { | 
					
						
							|  |  |  |     /* boot failed */ | 
					
						
							|  |  |  |     YAP_Error(iap->ErrorNo,0L,iap->ErrorCause); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-03-09 06:35:52 +00:00
										 |  |  |   return BootMode; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  | exec_top_level(int BootMode, YAP_init_args *iap) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |   YAP_Term atomfalse; | 
					
						
							|  |  |  |   YAP_Atom livegoal; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (BootMode == YAP_BOOT_FROM_SAVED_STACKS) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       /* continue executing from the frozen stacks */ | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |       YAP_ContinueGoal(); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-03-22 11:12:22 +00:00
										 |  |  |   /* the top-level is now ready */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* read it before case someone, that is, Ashwin, hides
 | 
					
						
							|  |  |  |      the atom false away ;-). | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2009-10-23 16:50:43 +01:00
										 |  |  |   livegoal = YAP_FullLookupAtom("$live"); | 
					
						
							| 
									
										
										
										
											2003-02-19 16:43:24 +00:00
										 |  |  |   atomfalse = YAP_MkAtomTerm (YAP_FullLookupAtom("$false")); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |   while (YAP_GetValue (livegoal) != atomfalse) { | 
					
						
							| 
									
										
										
										
											2014-09-22 18:13:35 +01:00
										 |  |  |     YAP_Reset( YAP_FULL_RESET ); | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |     do_top_goal (YAP_MkAtomTerm (livegoal)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2002-09-09 17:40:12 +00:00
										 |  |  |   YAP_Exit(EXIT_SUCCESS); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-19 01:30:13 +01:00
										 |  |  | //FILE *debugf;
 | 
					
						
							| 
									
										
										
										
											2014-04-23 22:41:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef LIGHT
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | _main (int argc, char **argv) | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | main (int argc, char **argv) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int BootMode; | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  |   YAP_init_args init_args; | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-23 22:41:12 +01:00
										 |  |  | #if DEBUG_LOCKS
 | 
					
						
							|  |  |  |   char buf[1024]; | 
					
						
							|  |  |  |   sprintf(buf, "/tmp/yap%d", getpid()); | 
					
						
							|  |  |  |   debugf= fopen(buf, "w"); | 
					
						
							|  |  |  |   if (!debugf) fprintf(stderr,"ERROR %s\n", strerror(errno)); | 
					
						
							|  |  |  |   setvbuf( debugf,NULL, _IOLBF, 1024); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  |   BootMode = init_standard_system(argc, argv, &init_args); | 
					
						
							| 
									
										
										
										
											2005-03-02 18:35:49 +00:00
										 |  |  |   if (BootMode == YAP_BOOT_ERROR) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n"); | 
					
						
							|  |  |  |     exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |   /* Begin preprocessor code */ | 
					
						
							| 
									
										
										
										
											2010-11-26 18:02:44 +00:00
										 |  |  |   if (BootMode != YAP_BOOT_FROM_SAVED_STACKS) { | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |     // process the definitions
 | 
					
						
							| 
									
										
										
										
											2012-06-22 03:56:01 -05:00
										 |  |  |     for(i=0;i<init_args.def_c;++i) { | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |       YAP_Term t_args[2],t_goal; | 
					
						
							| 
									
										
										
										
											2012-06-22 03:56:01 -05:00
										 |  |  |       t_args[0] = YAP_MkAtomTerm(YAP_LookupAtom(init_args.def_var[i])); | 
					
						
							|  |  |  |       t_args[1] = YAP_MkAtomTerm(YAP_LookupAtom(init_args.def_value[i]));  | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |       t_goal  = YAP_MkApplTerm(YAP_MkFunctor(YAP_LookupAtom("ypp_define"),2), 2, t_args);  | 
					
						
							| 
									
										
										
										
											2008-06-04 13:58:42 +00:00
										 |  |  |       YAP_RunGoalOnce(t_goal); | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-12-14 12:05:43 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-22 18:13:35 +01:00
										 |  |  |   YAP_Reset( YAP_FULL_RESET ); | 
					
						
							| 
									
										
										
										
											2005-06-06 05:08:14 +00:00
										 |  |  |   /* End preprocessor code */ | 
					
						
							| 
									
										
										
										
											2003-11-05 18:31:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-30 17:27:19 +00:00
										 |  |  |   exec_top_level(BootMode, &init_args); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |