improve SWI console

This commit is contained in:
Vitor Santos Costa 2012-06-22 03:56:01 -05:00
parent b15c9f5655
commit a9d1bd788e
8 changed files with 46 additions and 549 deletions

View File

@ -1048,7 +1048,7 @@ X_API int
PL_raise(int sig)
{
if (sig < SIG_PROLOG_OFFSET) {
Yap_signal(YAP_FAIL_SIGNAL);
Yap_signal(YAP_INT_SIGNAL);
return 1;
} else if (sig == SIG_PLABORT) {
YAP_signal(0x40); /* YAP_INT_SIGNAL */

View File

@ -262,6 +262,7 @@ C_SOURCES= \
$(srcdir)/packages/udi/rtree.c \
$(srcdir)/packages/udi/rtree_udi.c \
$(srcdir)/C/utilpreds.c $(srcdir)/C/write.c $(srcdir)/console/yap.c \
$(srcdir)/C/yap-args.c \
$(srcdir)/C/ypstdio.c \
$(srcdir)/BEAM/eam_am.c $(srcdir)/BEAM/eam_showcode.c \
$(srcdir)/BEAM/eamindex.c $(srcdir)/BEAM/eamamasm.c \
@ -367,7 +368,7 @@ ENGINE_OBJECTS = \
sysbits.o threads.o tracer.o \
udi.o rtree.o rtree_udi.o\
unify.o userpreds.o utilpreds.o \
write.o \
yap-args.o write.o \
blobs.o swi.o ypstdio.o $(IOLIB_OBJECTS) @MPI_OBJS@
LIBTAI_OBJECTS = \
@ -442,6 +443,9 @@ parms.h: Makefile
c_interface.o: $(srcdir)/C/c_interface.c $(srcdir)/include/c_interface.h config.h
$(CC) $(C_INTERF_FLAGS) -c $(srcdir)/C/c_interface.c -o c_interface.o
yap-argss.o: $(srcdir)/C/yap-args.c $(srcdir)/include/c_interface.h config.h
$(CC) $(C_INTERF_FLAGS) -c $(srcdir)/C/yap-args.c -o yap-args.o
clause_list.o: $(srcdir)/C/clause_list.c $(srcdir)/include/clause_list.h config.h
$(CC) $(C_INTERF_FLAGS) -c $(srcdir)/C/clause_list.c -o clause_list.o
@ -581,7 +585,7 @@ pl-nt.o: $(srcdir)/os/pl-nt.c config.h
$(CC) -c $(CFLAGS) -I$(srcdir)/include -I$(srcdir)/os @EXTRA_INCLUDES_FOR_WIN32@ $(srcdir)/os/pl-nt.c -o $@
pl-ntcon.o: $(srcdir)/console/LGPL/pl-ntcon.c config.h
$(CC) -municode -DUNICODE -D_UNICODE -c $(CFLAGS) -DPL_CONSOLE=1 -I$(srcdir)/include $(srcdir)/console/LGPL/pl-ntcon.c -o $@
$(CC) -c $(CFLAGS) -DPL_CONSOLE=1 -I$(srcdir)/include $(srcdir)/console/LGPL/pl-ntcon.c -o $@
pl-ntconsole.o: $(srcdir)/console/LGPL/pl-ntconsole.c config.h
$(CC) -municode -DUNICODE -D_UNICODE -c $(CFLAGS) -DPL_CONSOLE=1 -I$(srcdir) -I$(srcdir)/include -I$(srcdir)/os @EXTRA_INCLUDES_FOR_WIN32@ $(srcdir)/console/LGPL/pl-ntconsole.c -o $@

0
console/LGPL/pl-ntcon.c Normal file → Executable file
View File

View File

@ -1005,8 +1005,25 @@ win32main(rlc_console c, int argc, TCHAR **argv)
set_window_title(c);
rlc_bind_terminal(c);
/* YAP has to initialize before doing anything else */
#ifdef _YAP_NOT_INSTALLED_
if ( argc > MAX_ARGC )
argc = MAX_ARGC;
for(i=0; i<argc; i++)
{ char *s;
TCHAR *q;
av[i] = alloca(utf8_required_len(argv[i])+1);
for(s=av[i], q=argv[i]; *q; q++)
{ s = utf8_put_char(s, *q);
}
*s = '\0';
}
av[i] = NULL;
if ( !PL_initialise(argc, av) )
PL_halt(1);
#endif
PL_register_extensions_in_module("system", extensions);
install_readline(c);
@ -1029,20 +1046,6 @@ win32main(rlc_console c, int argc, TCHAR **argv)
PL_register_foreign_in_module("prolog", "win_open_console", 5,
pl_win_open_console, 0);
if ( argc > MAX_ARGC )
argc = MAX_ARGC;
for(i=0; i<argc; i++)
{ char *s;
TCHAR *q;
av[i] = alloca(utf8_required_len(argv[i])+1);
for(s=av[i], q=argv[i]; *q; q++)
{ s = utf8_put_char(s, *q);
}
*s = '\0';
}
av[i] = NULL;
rlc_bind_terminal(c);
PL_halt(PL_toplevel() ? 0 : 1);

View File

@ -23,26 +23,6 @@
#include "cut_c.h"
#endif
#if (DefTrailSpace < MinTrailSpace)
#undef DefTrailSpace
#define DefTrailSpace MinTrailSpace
#endif
#if (DefStackSpace < MinStackSpace)
#undef DefStackSpace
#define DefStackSpace MinStackSpace
#endif
#if (DefHeapSpace < MinHeapSpace)
#undef DefHeapSpace
#define DefHeapSpace MinHeapSpace
#endif
#define DEFAULT_NUMBERWORKERS 1
#define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
#ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H
@ -94,13 +74,6 @@ static int output_msg;
long _stksize = 32000;
#endif
/* nf: Begin preprocessor code */
#define MAXDEFS 100
static char *def_var[MAXDEFS];
static char *def_value[MAXDEFS];
static int def_c=0;
/* End preprocessor code */
#ifdef USE_MYPUTC
static void
myputc (int ch)
@ -119,512 +92,12 @@ do_top_goal (YAP_Term Goal)
YAP_RunGoalOnce(Goal);
}
static void
print_usage(void)
{
fprintf(stderr,"\n[ Valid switches for command line arguments: ]\n");
fprintf(stderr," -? Shows this screen\n");
fprintf(stderr," -b Boot file \n");
fprintf(stderr," -dump-runtime-variables\n");
fprintf(stderr," -f initialization file or \"none\"\n");
fprintf(stderr," -g Run Goal Before Top-Level \n");
fprintf(stderr," -z Run Goal Before Top-Level \n");
fprintf(stderr," -q start with informational messages off\n");
fprintf(stderr," -l load Prolog file\n");
fprintf(stderr," -L run Prolog file and exit\n");
fprintf(stderr," -p extra path for file-search-path\n");
fprintf(stderr," -hSize Heap area in Kbytes (default: %d, minimum: %d)\n",
DefHeapSpace, MinHeapSpace);
fprintf(stderr," -sSize Stack area in Kbytes (default: %d, minimum: %d)\n",
DefStackSpace, MinStackSpace);
fprintf(stderr," -tSize Trail area in Kbytes (default: %d, minimum: %d)\n",
DefTrailSpace, MinTrailSpace);
fprintf(stderr," -GSize Max Area for Global Stack\n");
fprintf(stderr," -LSize Max Area for Local Stack (number must follow L)\n");
fprintf(stderr," -TSize Max Area for Trail (number must follow L)\n");
fprintf(stderr,"\n[Execution Modes]\n");
fprintf(stderr," -J0 Interpreted mode (default)\n");
fprintf(stderr," -J1 Mixed mode only for user predicates\n");
fprintf(stderr," -J2 Mixed mode for all predicates\n");
fprintf(stderr," -J3 Compile all user predicates\n");
fprintf(stderr," -J4 Compile all predicates\n");
#ifdef TABLING
fprintf(stderr," -ts Maximum table space area in Mbytes (default: unlimited)\n");
#endif /* TABLING */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
fprintf(stderr," -w Number of workers (default: %d)\n",
DEFAULT_NUMBERWORKERS);
fprintf(stderr," -sl Loop scheduler executions before look for hiden shared work (default: %d)\n",
DEFAULT_SCHEDULERLOOP);
fprintf(stderr," -d Value of delayed release of load (default: %d)\n",
DEFAULT_DELAYEDRELEASELOAD);
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
/* nf: Preprocessor */
/* fprintf(stderr," -DVar=Name Persistent definition\n"); */
fprintf(stderr,"\n");
}
static int
myisblank(int c)
{
switch (c) {
case ' ':
case '\t':
case '\n':
case '\r':
return TRUE;
default:
return FALSE;
}
}
static char *
add_end_dot(char arg[])
{
int sz = strlen(arg), i;
i = sz;
while (i && myisblank(arg[--i]));
if (i && arg[i] != ',') {
char *p = (char *)malloc(sz+2);
if (!p)
return NULL;
strncpy(p,arg,sz);
p[sz] = '.';
p[sz+1] = '\0';
return p;
}
return arg;
}
static int
dump_runtime_variables(void)
{
fprintf(stdout,"CC=\"%s\"\n",YAP_CC);
fprintf(stdout,"YAP_ROOTDIR=\"%s\"\n",YAP_ROOTDIR);
fprintf(stdout,"YAP_LIBS=\"%s\"\n",YAP_LIBS);
fprintf(stdout,"YAP_SHLIB_SUFFIX=\"%s\"\n",YAP_SHLIB_SUFFIX);
fprintf(stdout,"YAP_VERSION=%d\n",YAP_VERSION);
exit(0);
return 1;
}
/*
* proccess command line arguments: valid switches are: -b boot -s
* stack area size (K) -h heap area size -a aux stack size -e
* emacs_mode -m -DVar=Value reserved memory for alloc IF DEBUG -p if you
* want to check out startup IF MAC -mpw if we are using the mpw
* shell
*/
static int
parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
{
char *p;
#ifdef USE_SYSTEM_MALLOC
int BootMode = YAP_FULL_BOOT_FROM_PROLOG;
#else
int BootMode = YAP_BOOT_FROM_SAVED_CODE;
#endif
#ifdef MYDDAS_MYSQL
char *myddas_temp;
#endif
unsigned long int *ssize;
while (--argc > 0)
{
p = *++argv;
if (*p == '-')
switch (*++p)
{
case 'b':
BootMode = YAP_BOOT_FROM_PROLOG;
iap->YapPrologBootFile = *++argv;
argc--;
break;
case '?':
print_usage();
exit(EXIT_SUCCESS);
case 'q':
iap->QuietMode = TRUE;
break;
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
case 'w':
ssize = &(iap->NumberWorkers);
goto GetSize;
case 'd':
if (!strcmp("dump-runtime-variables",p))
return dump_runtime_variables();
ssize = &(iap->DelayedReleaseLoad);
goto GetSize;
#else
case 'd':
if (!strcmp("dump-runtime-variables",p))
return dump_runtime_variables();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
case 'F':
/* just ignore for now */
argc--;
argv++;
break;
case 'f':
if (argc > 1 && argv[1][0] != '-') {
argc--;
argv++;
if (!strcmp(*argv,"none")) {
iap->FastBoot = TRUE;
} else {
iap->YapPrologRCFile = *argv;
}
break;
}
iap->FastBoot = TRUE;
break;
#ifdef MYDDAS_MYSQL
case 'm':
if (strncmp(p,"myddas_",7) == 0)
{
iap->myddas = 1;
if ((*argv)[0] == '\0')
myddas_temp = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing file name with option 'l' ]\n");
exit(EXIT_FAILURE);
}
argv++;
myddas_temp = *argv;
}
if (strstr(p,"user") != NULL)
iap->myddas_user = myddas_temp;
else if (strstr(p,"pass") != NULL)
iap->myddas_pass = myddas_temp;
else if (strstr(p,"db") != NULL)
iap->myddas_db = myddas_temp;
else if (strstr(p,"host") != NULL)
iap->myddas_host = myddas_temp;
else
goto myddas_error_print;
break;
}
#endif
// execution mode
case 'J':
switch (p[1]) {
case '0':
iap->ExecutionMode = YAPC_INTERPRETED;
break;
case '1':
iap->ExecutionMode = YAPC_MIXED_MODE_USER;
break;
case '2':
iap->ExecutionMode = YAPC_MIXED_MODE_ALL;
break;
case '3':
iap->ExecutionMode = YAPC_COMPILE_USER;
break;
case '4':
iap->ExecutionMode = YAPC_COMPILE_ALL;
break;
default:
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c%c ]\n", *p, p[1]);
exit(EXIT_FAILURE);
}
p++;
break;
case 'G':
ssize = &(iap->MaxGlobalSize);
goto GetSize;
break;
case 's':
case 'S':
ssize = &(iap->StackSize);
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
if (p[1] == 'l') {
p++;
ssize = &(iap->SchedulerLoop);
}
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
goto GetSize;
case 'a':
case 'A':
ssize = &(iap->AttsSize);
goto GetSize;
case 'T':
ssize = &(iap->MaxTrailSize);
goto get_trail_size;
case 't':
ssize = &(iap->TrailSize);
#ifdef TABLING
if (p[1] == 's') {
p++;
ssize = &(iap->MaxTableSpaceSize);
}
#endif /* TABLING */
get_trail_size:
if (*++p == '\0')
{
if (argc > 1)
--argc, p = *++argv;
else
{
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
print_usage();
exit(EXIT_FAILURE);
}
}
{
unsigned long int i = 0, ch;
while ((ch = *p++) >= '0' && ch <= '9')
i = i * 10 + ch - '0';
switch(ch) {
case 'M':
case 'm':
i *= 1024;
ch = *p++;
break;
case 'g':
i *= 1024*1024;
ch = *p++;
break;
case 'k':
case 'K':
ch = *p++;
break;
}
if (ch) {
iap->YapPrologTopLevelGoal = add_end_dot(*argv);
} else {
*ssize = i;
}
}
break;
case 'h':
case 'H':
ssize = &(iap->HeapSize);
GetSize:
if (*++p == '\0')
{
if (argc > 1)
--argc, p = *++argv;
else
{
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
print_usage();
exit(EXIT_FAILURE);
}
}
{
unsigned long int i = 0, ch;
while ((ch = *p++) >= '0' && ch <= '9')
i = i * 10 + ch - '0';
switch(ch) {
case 'M':
case 'm':
i *= 1024;
ch = *p++;
break;
case 'g':
case 'G':
i *= 1024*1024;
ch = *p++;
break;
case 'k':
case 'K':
ch = *p++;
break;
}
if (ch)
{
fprintf(stderr,"[ YAP unrecoverable error: illegal size specification %s ]", argv[-1]);
YAP_Exit(1);
}
*ssize = i;
}
break;
#ifdef DEBUG
case 'P':
YAP_SetOutputMessage();
output_msg = TRUE;
break;
#endif
case 'L':
if (p[1] && p[1] >= '0' && p[1] <= '9') /* hack to emulate SWI's L local option */
{
ssize = &(iap->MaxStackSize);
goto GetSize;
}
iap->QuietMode = TRUE;
iap->HaltAfterConsult = TRUE;
case 'l':
p++;
if (!*++argv) {
fprintf(stderr,"%% YAP unrecoverable error: missing load file name\n");
exit(1);
} else if (!strcmp("--",*argv)) {
/* shell script, the next entry should be the file itself */
iap->YapPrologRCFile = argv[1];
argc = 1;
break;
} else {
iap->YapPrologRCFile = *argv;
argc--;
}
if (*p) {
/* we have something, usually, of the form:
-L --
FileName
ExtraArgs
*/
/* being called from a script */
while (*p && (*p == ' ' || *p == '\t'))
p++;
if (p[0] == '-' && p[1] == '-') {
/* ignore what is next */
argc = 1;
}
}
break;
/* run goal before top-level */
case 'g':
if ((*argv)[0] == '\0')
iap->YapPrologGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing initialization goal for option 'g' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologGoal = *argv;
}
break;
/* run goal as top-level */
case 'z':
if ((*argv)[0] == '\0')
iap->YapPrologTopLevelGoal = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing goal for option 'z' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologTopLevelGoal = add_end_dot(*argv);
}
break;
case 'p':
if ((*argv)[0] == '\0')
iap->YapPrologAddPath = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing paths for option 'p' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologAddPath = *argv;
}
break;
/* nf: Begin preprocessor code */
case 'D':
{
char *var, *value;
++p;
var = p;
if (var == NULL || *var=='\0')
break;
while(*p!='=' && *p!='\0') ++p;
if ( *p=='\0' ) break;
*p='\0';
++p;
value=p;
if ( *value == '\0' ) break;
++def_c;
def_var[def_c-1]=var;
def_value[def_c-1]=value;
break;
}
/* End preprocessor code */
case '-':
/* skip remaining arguments */
argc = 1;
break;
default:
{
#ifdef MYDDAS_MYSQL
myddas_error_print :
#endif
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p);
#ifdef MYDDAS_MYSQL
myddas_error :
#endif
print_usage();
exit(EXIT_FAILURE);
}
}
else {
iap->SavedState = p;
}
}
#ifdef MYDDAS_MYSQL
/* Check MYDDAS Arguments */
if (iap->myddas_user != NULL || iap->myddas_pass != NULL
|| iap->myddas_db != NULL || iap->myddas_host != NULL)
if (iap->myddas_user == NULL || iap->myddas_db == NULL){
fprintf(stderr,"[ YAP unrecoverable error: Missing Mandatory Arguments for MYDDAS ]\n");
goto myddas_error;
}
#endif
return BootMode;
}
static int
init_standard_system(int argc, char *argv[], YAP_init_args *iap)
{
int BootMode;
iap->SavedState = NULL;
iap->HeapSize = 0;
iap->StackSize = 0;
iap->TrailSize = 0;
iap->AttsSize = 0;
iap->MaxAttsSize = 0;
iap->MaxHeapSize = 0;
iap->MaxStackSize = 0;
iap->MaxGlobalSize = 0;
iap->MaxTrailSize = 0;
iap->YapLibDir = NULL;
iap->YapPrologBootFile = NULL;
iap->YapPrologInitFile = NULL;
iap->YapPrologRCFile = NULL;
iap->YapPrologGoal = NULL;
iap->YapPrologTopLevelGoal = NULL;
iap->YapPrologAddPath = NULL;
iap->HaltAfterConsult = FALSE;
iap->FastBoot = FALSE;
iap->MaxTableSpaceSize = 0;
iap->NumberWorkers = DEFAULT_NUMBERWORKERS;
iap->SchedulerLoop = DEFAULT_SCHEDULERLOOP;
iap->DelayedReleaseLoad = DEFAULT_DELAYEDRELEASELOAD;
iap->PrologShouldHandleInterrupts = TRUE;
iap->ExecutionMode = YAPC_INTERPRETED;
iap->Argc = argc;
iap->Argv = argv;
#ifdef MYDDAS_MYSQL
iap->myddas = 0;
iap->myddas_user = NULL;
iap->myddas_pass = NULL;
iap->myddas_db = NULL;
iap->myddas_host = NULL;
#endif
iap->ErrorNo = 0;
iap->ErrorCause = NULL;
iap->QuietMode = FALSE;
BootMode = parse_yap_arguments(argc,argv,iap);
BootMode = YAP_parse_yap_arguments(argc,argv,iap);
/* init memory */
if (BootMode == YAP_BOOT_FROM_PROLOG ||
@ -693,10 +166,10 @@ main (int argc, char **argv)
mod_arg[0] = YAP_MkAtomTerm(YAP_LookupAtom("ypp"));
YAP_RunGoalOnce(YAP_MkApplTerm(YAP_MkFunctor(YAP_LookupAtom("use_module"),1), 1, mod_arg));
// process the definitions
for(i=0;i<def_c;++i) {
for(i=0;i<init_args.def_c;++i) {
YAP_Term t_args[2],t_goal;
t_args[0] = YAP_MkAtomTerm(YAP_LookupAtom(def_var[i]));
t_args[1] = YAP_MkAtomTerm(YAP_LookupAtom(def_value[i]));
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);
}

3
include/YapInterface.h Normal file → Executable file
View File

@ -601,6 +601,9 @@ extern X_API YAP_Term PROTO(YAP_ImportTerm,(char *));
extern X_API int PROTO(YAP_RequiresExtraStack,(size_t));
extern X_API int
YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap);
#define YAP_InitCPred(N,A,F) YAP_UserCPredicate(N,F,A)
__END_DECLS

8
include/yap_structs.h Normal file → Executable file
View File

@ -186,6 +186,14 @@ typedef struct {
char **Argv;
/* QuietMode */
int QuietMode;
/* nf: Begin ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS];
char *def_value[YAP_MAX_YPP_DEFS];
int def_c;
/* End preprocessor code */
#ifdef MYDDAS_MYSQL
/* If any myddas option was given */
short myddas;

View File

@ -2037,6 +2037,8 @@ PL_initialise(int myargc, char **myargv)
init_args.SchedulerLoop = 10;
init_args.DelayedReleaseLoad = 3;
YAP_parse_yap_arguments(myargc,myargv,&init_args);
GLOBAL_PL_Argc = myargc;
GLOBAL_PL_Argv = myargv;
GLOBAL_InitialisedFromPL = TRUE;
@ -2354,7 +2356,11 @@ X_API int PL_call_predicate(module_t ctx, int flags, predicate_t p, term_t t0)
X_API int PL_toplevel(void)
{
return YAP_RunGoal(MkAtomTerm(Yap_FullLookupAtom("$live")));
while (TRUE) {
if (YAP_RunGoal(MkAtomTerm(Yap_FullLookupAtom("$live")))) {
return TRUE;
}
}
}
X_API int PL_call(term_t tp, module_t m)