2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
2018-11-04 10:55:58 +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 *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2001-04-09 20:54:03 +01:00
|
|
|
/* static char SccsId[] = "X 4.3.3"; */
|
|
|
|
|
2018-11-04 10:55:58 +00:00
|
|
|
#include "YapConfig.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
|
|
|
#include "cut_c.h"
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
|
2016-02-29 03:13:23 +00:00
|
|
|
#undef HAVE_UNISTD_H
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2016-02-28 19:32:55 +00:00
|
|
|
#ifdef _WIN32 /* Microsoft's Visual C++ Compiler */
|
|
|
|
#include <io.h>
|
2016-02-29 03:13:23 +00:00
|
|
|
#include <windows.h>
|
2001-04-09 20:54:03 +01:00
|
|
|
#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
|
|
|
|
2018-01-19 14:38:26 +00:00
|
|
|
static bool do_top_goal(YAP_Term Goal);
|
|
|
|
static bool 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
|
|
|
|
|
2018-01-19 14:38:26 +00:00
|
|
|
static bool do_top_goal(YAP_Term Goal) { return YAP_RunGoalOnce(Goal); }
|
2016-02-28 19:32:55 +00:00
|
|
|
|
2016-02-29 03:13:23 +00:00
|
|
|
static int init_standard_system(int argc, char *argv[], YAP_init_args *iap) {
|
2016-04-18 16:41:30 +01:00
|
|
|
|
2016-07-31 16:21:45 +01:00
|
|
|
YAP_file_type_t BootMode;
|
|
|
|
|
|
|
|
BootMode = YAP_parse_yap_arguments(argc, argv, iap);
|
2016-12-16 08:54:54 +00:00
|
|
|
iap->Embedded = false;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* init memory */
|
2018-03-14 00:41:05 +00:00
|
|
|
iap->boot_file_type = BootMode;
|
|
|
|
YAP_Init(iap);
|
2005-03-02 18:35:49 +00:00
|
|
|
if (iap->ErrorNo) {
|
|
|
|
/* boot failed */
|
2016-02-29 03:13:23 +00:00
|
|
|
YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause);
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
2005-03-09 06:35:52 +00:00
|
|
|
return BootMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 14:38:26 +00:00
|
|
|
static bool exec_top_level(int BootMode, YAP_init_args *iap) {
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Term atomfalse;
|
|
|
|
YAP_Atom livegoal;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2018-01-27 10:17:27 +00:00
|
|
|
if (iap->install)
|
|
|
|
return true;
|
2016-02-29 03:13:23 +00:00
|
|
|
if (BootMode == YAP_BOOT_FROM_SAVED_STACKS) {
|
|
|
|
/* continue executing from the frozen stacks */
|
|
|
|
YAP_ContinueGoal();
|
|
|
|
}
|
2018-01-19 14:38:26 +00:00
|
|
|
livegoal = YAP_FullLookupAtom("live");
|
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 ;-).
|
|
|
|
*/
|
2018-01-19 14:38:26 +00:00
|
|
|
atomfalse = YAP_MkAtomTerm(YAP_FullLookupAtom("false"));
|
2016-02-29 03:13:23 +00:00
|
|
|
while (YAP_GetValue(livegoal) != atomfalse) {
|
2018-01-18 14:47:27 +00:00
|
|
|
YAP_Reset(YAP_FULL_RESET, false);
|
2018-01-19 14:38:26 +00:00
|
|
|
if (!do_top_goal(YAP_MkAtomTerm(livegoal))) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
livegoal = YAP_FullLookupAtom("live");
|
|
|
|
}
|
|
|
|
return true;
|
2018-11-04 10:55:58 +00:00
|
|
|
// YAP_Exit(EXIT_SUCCESS);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2016-02-29 03:13:23 +00:00
|
|
|
// FILE *debugf;
|
2014-04-23 22:41:12 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef LIGHT
|
2018-11-04 10:55:58 +00:00
|
|
|
|
2016-02-29 03:13:23 +00:00
|
|
|
int _main(int argc, char **argv)
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2016-02-29 03:13:23 +00:00
|
|
|
int main(int argc, char **argv)
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int BootMode;
|
2005-06-06 06:08:14 +01:00
|
|
|
int i;
|
2016-02-29 03:13:23 +00:00
|
|
|
YAP_init_args init_args;
|
2002-10-30 17:27:19 +00:00
|
|
|
BootMode = init_standard_system(argc, argv, &init_args);
|
2018-11-04 10:55:58 +00:00
|
|
|
|
2005-03-02 18:35:49 +00:00
|
|
|
if (BootMode == YAP_BOOT_ERROR) {
|
2016-02-29 03:13:23 +00:00
|
|
|
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
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
|
|
|
// process the definitions
|
2016-02-29 03:13:23 +00:00
|
|
|
for (i = 0; i < init_args.def_c; ++i) {
|
|
|
|
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]));
|
2016-02-29 03:13:23 +00:00
|
|
|
t_args[1] = YAP_MkAtomTerm(YAP_LookupAtom(init_args.def_value[i]));
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-04-12 16:22:53 +01:00
|
|
|
|
2018-01-18 14:47:27 +00:00
|
|
|
YAP_Reset(YAP_FULL_RESET, false);
|
2005-06-06 06:08:14 +01:00
|
|
|
/* End preprocessor code */
|
2003-11-05 18:31:49 +00:00
|
|
|
|
2019-04-03 15:46:47 +01:00
|
|
|
//mtrace();
|
2018-01-19 14:38:26 +00:00
|
|
|
bool rc = exec_top_level(BootMode, &init_args);
|
2018-01-27 10:17:27 +00:00
|
|
|
if (!rc)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|