fix ! in debugger (execute_clause)

improve system/1 and execute/1


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1610 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2006-04-25 03:23:40 +00:00
parent 1265946374
commit b9e5416355
5 changed files with 55 additions and 47 deletions

View File

@ -42,7 +42,7 @@ cp_as_integer(choiceptr cp)
static choiceptr static choiceptr
cp_from_integer(Term cpt) cp_from_integer(Term cpt)
{ {
return (choiceptr)(LCL0-(CELL *)IntegerOfTerm(cpt)); return (choiceptr)(LCL0-IntegerOfTerm(cpt));
} }
Term Term
@ -82,7 +82,7 @@ CallPredicate(PredEntry *pen, choiceptr cut_pt, yamop *code) {
ENV = YENV; ENV = YENV;
YENV = ASP; YENV = ASP;
YENV[E_CB] = (CELL) cut_pt; YENV[E_CB] = (CELL) cut_pt;
return (TRUE); return TRUE;
} }
inline static Int inline static Int
@ -422,7 +422,7 @@ p_execute_clause(void)
{ /* '$execute_clause'(Goal) */ { /* '$execute_clause'(Goal) */
Term t = Deref(ARG1); Term t = Deref(ARG1);
Term mod = Deref(ARG2); Term mod = Deref(ARG2);
choiceptr cp = cp_from_integer(Deref(ARG4)); choiceptr cut_cp = cp_from_integer(Deref(ARG4));
unsigned int arity; unsigned int arity;
Prop pe; Prop pe;
yamop *code; yamop *code;
@ -478,7 +478,7 @@ p_execute_clause(void)
} else { } else {
code = Yap_ClauseFromTerm(clt)->ClCode; code = Yap_ClauseFromTerm(clt)->ClCode;
} }
return CallPredicate(RepPredProp(pe), cp, code); return CallPredicate(RepPredProp(pe), cut_cp, code);
} }
static Int static Int

View File

@ -1783,19 +1783,19 @@ p_shell (void)
bourne = TRUE; bourne = TRUE;
/* Yap_CloseStreams(TRUE); */ /* Yap_CloseStreams(TRUE); */
if (bourne) if (bourne)
return (system (RepAtom(AtomOfTerm(t1))->StrOfAE) == 0); return system(RepAtom(AtomOfTerm(t1))->StrOfAE) == 0;
else { else {
int status = -1; int status = -1;
int child = fork (); int child = fork ();
if (child == 0)
{ /* let the children go */ if (child == 0) { /* let the children go */
if (!execl (shell, shell, "-c", RepAtom(AtomOfTerm(t1))->StrOfAE , NULL)) { if (!execl (shell, shell, "-c", RepAtom(AtomOfTerm(t1))->StrOfAE , NULL)) {
exit(-1); exit(-1);
} }
exit(TRUE); exit(TRUE);
} }
{ /* put the father on wait */ { /* put the father on wait */
int result = child < 0 || int result = child < 0 ||
/* vsc:I am not sure this is used, Stevens say wait returns an integer. /* vsc:I am not sure this is used, Stevens say wait returns an integer.
#if NO_UNION_WAIT #if NO_UNION_WAIT
*/ */
@ -1815,10 +1815,10 @@ p_shell (void)
shell = "msh -i"; shell = "msh -i";
/* Yap_CloseStreams(); */ /* Yap_CloseStreams(); */
system (shell); system (shell);
return (TRUE); return TRUE;
#else #else
Yap_Error (SYSTEM_ERROR,TermNil,"shell not available in this configuration"); Yap_Error (SYSTEM_ERROR,TermNil,"shell not available in this configuration");
return(FALSE); return FALSE;
#endif #endif
#endif /* HAVE_SYSTEM */ #endif /* HAVE_SYSTEM */
#endif /* _MSC_VER */ #endif /* _MSC_VER */

View File

@ -16,6 +16,10 @@
<h2>Yap-5.1.2:</h2> <h2>Yap-5.1.2:</h2>
<ul> <ul>
<li> FIXED: ! was not pruning right in p_execute_clause (obs Nicos
Angelopoulos).</li>
<li> FIXED: system/1 and shell/1 should check return code (obs Nicos
Angelopoulos).</li>
<li> FIXED: thread_peek_message should use aliases (obs Paulo Moura).</li> <li> FIXED: thread_peek_message should use aliases (obs Paulo Moura).</li>
<li> FIXED: garbage collector should no rewrite cp_tr fields until <li> FIXED: garbage collector should no rewrite cp_tr fields until
after marking (obs Paulo Moura).</li> after marking (obs Paulo Moura).</li>

View File

@ -374,7 +374,8 @@ shell(Command) :-
G = shell(Command), G = shell(Command),
check_command(Command, G), check_command(Command, G),
get_shell(Shell,Opt), get_shell(Shell,Opt),
do_shell(Shell, Opt, Command, _, Error), do_shell(Shell, Opt, Command, Status, Error),
Status = 0,
handle_system_error(Error, off, G). handle_system_error(Error, off, G).
shell(Command, Status) :- shell(Command, Status) :-
@ -416,6 +417,7 @@ system(Command, Status) :-
G = system(Command, Status), G = system(Command, Status),
check_command(Command, G), check_command(Command, G),
do_system(Command, Status, Error), do_system(Command, Status, Error),
Status = 0,
handle_system_error(Error, off, G). handle_system_error(Error, off, G).
sleep(Interval) :- var(Interval), !, sleep(Interval) :- var(Interval), !,

View File

@ -8,8 +8,13 @@
* * * *
************************************************************************** **************************************************************************
* * * *
* $Id: sys.c,v 1.25 2006-01-17 14:10:42 vsc Exp $ * * $Id: sys.c,v 1.26 2006-04-25 03:23:40 vsc Exp $ *
* mods: $Log: not supported by cvs2svn $ * mods: $Log: not supported by cvs2svn $
* mods: Revision 1.25 2006/01/17 14:10:42 vsc
* mods: YENV may be an HW register (breaks some tabling code)
* mods: All YAAM instructions are now brackedted, so Op introduced an { and EndOp introduces an }. This is because Ricardo assumes that.
* mods: Fix attvars when COROUTING is undefined.
* mods:
* mods: Revision 1.24 2006/01/08 23:01:48 vsc * mods: Revision 1.24 2006/01/08 23:01:48 vsc
* mods: *** empty log message *** * mods: *** empty log message ***
* mods: * mods:
@ -52,9 +57,7 @@
#include "config.h" #include "config.h"
#include "YapInterface.h" #include "YapInterface.h"
#if STDC_HEADERS
#include <stdlib.h> #include <stdlib.h>
#endif
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -687,12 +690,12 @@ do_system(void)
#if HAVE_SYSTEM #if HAVE_SYSTEM
int sys = system(command); int sys = system(command);
if (sys < 0) { if (sys < 0) {
return(YAP_Unify(YAP_ARG3,YAP_MkIntTerm(errno))); return YAP_Unify(YAP_ARG3,YAP_MkIntTerm(errno));
} }
return(YAP_Unify(YAP_ARG2, YAP_MkIntTerm(sys))); return YAP_Unify(YAP_ARG2, YAP_MkIntTerm(sys));
#else #else
YAP_Error(0,0L,"system not available in this configuration"); YAP_Error(0,0L,"system not available in this configuration");
return(FALSE); return FALSE;
#endif #endif
} }
@ -703,6 +706,9 @@ static int
do_shell(void) do_shell(void)
{ {
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
YAP_Error(0,0L,"system not available in this configuration");
return(FALSE);
#elif HAVE_SYSTEM
char *buf = YAP_AllocSpaceFromYap(BUF_SIZE); char *buf = YAP_AllocSpaceFromYap(BUF_SIZE);
int sys; int sys;
@ -711,29 +717,23 @@ do_shell(void)
return(FALSE); return(FALSE);
} }
#if HAVE_STRNCPY #if HAVE_STRNCPY
strncpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)), buf, BUF_SIZE); strncpy(buf, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)), BUF_SIZE);
strncpy(" ", buf, BUF_SIZE); strncpy(buf, " ", BUF_SIZE);
strncpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG2)), buf, BUF_SIZE); strncpy(buf, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG2)), BUF_SIZE);
strncpy(" ", buf, BUF_SIZE); strncpy(buf, " ", BUF_SIZE);
strncpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3)), buf, BUF_SIZE); strncpy(buf, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3)), BUF_SIZE);
#else #else
strcpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)), buf); strcpy(buf, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)));
strcpy(" ", buf); strcpy(buf, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG2)));
strcpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG2)), buf); strcpy(buf, " ");
strcpy(" ", buf); strcpy(bug, YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3)));
strcpy(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3)), buf);
#endif #endif
#if HAVE_SYSTEM
sys = system(buf); sys = system(buf);
YAP_FreeSpaceFromYap(buf); YAP_FreeSpaceFromYap(buf);
if (sys < 0) { if (sys < 0) {
return(YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno))); return YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno));
} }
return(YAP_Unify(YAP_ARG4, YAP_MkIntTerm(sys))); return YAP_Unify(YAP_ARG4, YAP_MkIntTerm(sys));
#else
YAP_Error(0,0L,"system not available in this configuration");
return(FALSE);
#endif
#else #else
char *cptr[4]; char *cptr[4];
int t; int t;
@ -745,17 +745,19 @@ do_shell(void)
cptr[3]= NULL; cptr[3]= NULL;
t = fork(); t = fork();
if (t < 0) { if (t < 0) {
return(YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno))); return YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno));
} else if (t == 0) { } else if (t == 0) {
t = execvp(YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)),cptr); t = execvp(cptr[0],cptr);
return(t); return t;
} else { } else {
t = wait(&sys); t = wait(&sys);
fprintf(stderr,"after wait %x:%x\n",t,sys);
if (t < 0) { if (t < 0) {
return(YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno))); return YAP_Unify(YAP_ARG5,YAP_MkIntTerm(errno));
} }
} }
return(YAP_Unify(YAP_ARG4, YAP_MkIntTerm(sys))); fprintf(stderr,"after wait %x\n", sys);
return YAP_Unify(YAP_ARG4, YAP_MkIntTerm(sys));
#endif #endif
} }