2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* Yap Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: Yap.C *
|
|
|
|
* Last Rev: *
|
|
|
|
* Mods: *
|
|
|
|
* Comments: Yap's Main File *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
/* static char SccsId[] = "X 4.3.3"; */
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-09-09 18:40:12 +01:00
|
|
|
#include "YapInterface.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
#include "cut_c.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01: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 20:54:03 +01: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 20:54:03 +01:00
|
|
|
|
2012-04-18 20:14:56 +01:00
|
|
|
static void do_top_goal(YAP_Term Goal);
|
|
|
|
static void exec_top_level(int BootMode, YAP_init_args *iap);
|
2001-04-09 20:54:03 +01: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 20:11:59 +01:00
|
|
|
static void
|
|
|
|
myputc (int ch)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
putc(ch,stderr);
|
|
|
|
}
|
2004-05-14 17:34:49 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
static void
|
2002-09-09 18:40:12 +01:00
|
|
|
do_top_goal (YAP_Term Goal)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-06-04 14:58:42 +01:00
|
|
|
YAP_RunGoalOnce(Goal);
|
2001-04-09 20:54:03 +01: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 20:54:03 +01:00
|
|
|
{
|
|
|
|
int BootMode;
|
|
|
|
|
2012-06-22 09:56:01 +01:00
|
|
|
BootMode = YAP_parse_yap_arguments(argc,argv,iap);
|
2001-04-09 20:54:03 +01: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 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-30 17:27:19 +00:00
|
|
|
exec_top_level(int BootMode, YAP_init_args *iap)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Term atomfalse;
|
|
|
|
YAP_Atom livegoal;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (BootMode == YAP_BOOT_FROM_SAVED_STACKS)
|
|
|
|
{
|
|
|
|
/* continue executing from the frozen stacks */
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_ContinueGoal();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-03-22 11:12:22 +00:00
|
|
|
/* the top-level is now ready */
|
2001-04-09 20:54:03 +01: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 18:40:12 +01:00
|
|
|
while (YAP_GetValue (livegoal) != atomfalse) {
|
2002-10-08 15:32:42 +01:00
|
|
|
YAP_Reset();
|
2002-09-09 18:40:12 +01:00
|
|
|
do_top_goal (YAP_MkAtomTerm (livegoal));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Exit(EXIT_SUCCESS);
|
2001-04-09 20:54:03 +01: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 06:08:14 +01:00
|
|
|
int i;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
|
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 20:54:03 +01:00
|
|
|
fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-06-06 06:08:14 +01:00
|
|
|
/* Begin preprocessor code */
|
2010-11-26 18:02:44 +00:00
|
|
|
if (BootMode != YAP_BOOT_FROM_SAVED_STACKS) {
|
2005-06-06 06:08:14 +01:00
|
|
|
// load the module
|
|
|
|
YAP_Term mod_arg[1];
|
|
|
|
mod_arg[0] = YAP_MkAtomTerm(YAP_LookupAtom("ypp"));
|
2008-06-04 14:58:42 +01:00
|
|
|
YAP_RunGoalOnce(YAP_MkApplTerm(YAP_MkFunctor(YAP_LookupAtom("use_module"),1), 1, mod_arg));
|
2005-06-06 06:08:14 +01:00
|
|
|
// process the definitions
|
2012-06-22 09:56:01 +01:00
|
|
|
for(i=0;i<init_args.def_c;++i) {
|
2005-06-06 06:08:14 +01:00
|
|
|
YAP_Term t_args[2],t_goal;
|
2012-06-22 09:56:01 +01: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 06:08:14 +01:00
|
|
|
t_goal = YAP_MkApplTerm(YAP_MkFunctor(YAP_LookupAtom("ypp_define"),2), 2, t_args);
|
2008-06-04 14:58:42 +01:00
|
|
|
YAP_RunGoalOnce(t_goal);
|
2005-06-06 06:08:14 +01:00
|
|
|
}
|
|
|
|
}
|
2013-02-08 16:35:40 +00:00
|
|
|
YAP_Reset();
|
2005-06-06 06:08:14 +01: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 20:54:03 +01:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|