This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/console/yap.c

156 lines
3.6 KiB
C
Raw Normal View History

/*************************************************************************
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 *
* *
*************************************************************************/
/* static char SccsId[] = "X 4.3.3"; */
2018-11-04 10:55:58 +00:00
#include "YapConfig.h"
#include "YapInterface.h"
#include "cut_c.h"
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
#undef HAVE_UNISTD_H
#endif
#ifdef _WIN32 /* Microsoft's Visual C++ Compiler */
#include <io.h>
#include <windows.h>
#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
#if HAVE_STRING_H
#include <string.h>
#endif
2012-03-27 14:20:34 +01:00
#if HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
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);
#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); }
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;
/* init memory */
2018-03-14 00:41:05 +00:00
iap->boot_file_type = BootMode;
YAP_Init(iap);
if (iap->ErrorNo) {
/* boot failed */
YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause);
}
return BootMode;
}
2018-01-19 14:38:26 +00:00
static bool exec_top_level(int BootMode, YAP_init_args *iap) {
YAP_Term atomfalse;
YAP_Atom livegoal;
2018-01-27 10:17:27 +00:00
if (iap->install)
return true;
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");
/* the top-level is now ready */
/* 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"));
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);
}
// FILE *debugf;
#ifdef LIGHT
2018-11-04 10:55:58 +00:00
int _main(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
int BootMode;
int i;
YAP_init_args init_args;
BootMode = init_standard_system(argc, argv, &init_args);
2018-11-04 10:55:58 +00:00
if (BootMode == YAP_BOOT_ERROR) {
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
exit(1);
}
/* Begin preprocessor code */
if (BootMode != YAP_BOOT_FROM_SAVED_STACKS) {
// process the definitions
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]));
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);
YAP_RunGoalOnce(t_goal);
}
}
2016-04-12 16:22:53 +01:00
2018-01-18 14:47:27 +00:00
YAP_Reset(YAP_FULL_RESET, false);
/* End preprocessor code */
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;
}