fix restore

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@498 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-05-28 16:26:00 +00:00
parent 85f1080071
commit b58dbff727
13 changed files with 282 additions and 194 deletions

View File

@ -714,7 +714,7 @@ a_p(op_numbers opcode)
int comit_ok = (comit_lab == 0);
Prop fe = (Prop) (cpc->rnd1);
CELL Flags = RepPredProp(fe)->PredFlags;
if (Flags & BasicPredFlag) {
if (Flags & AsmPredFlag) {
op_numbers op;
check_alloc();

View File

@ -1632,7 +1632,7 @@ p_undefined(void)
if (pe == RepPredProp(NIL))
return (TRUE);
READ_LOCK(pe->PRWLock);
if (pe->PredFlags & (CPredFlag|UserCPredFlag|TestPredFlag|BasicPredFlag|DynamicPredFlag)) {
if (pe->PredFlags & (CPredFlag|UserCPredFlag|TestPredFlag|AsmPredFlag|DynamicPredFlag)) {
READ_UNLOCK(pe->PRWLock);
return(FALSE);
}
@ -2258,7 +2258,7 @@ p_system_pred(void)
return (FALSE);
if (EndOfPAEntr(pe))
return(FALSE);
return(pe->ModuleOfPred == 0 || pe->PredFlags & (UserCPredFlag|CPredFlag|BinaryTestPredFlag|BasicPredFlag|TestPredFlag));
return(pe->ModuleOfPred == 0 || pe->PredFlags & (UserCPredFlag|CPredFlag|BinaryTestPredFlag|AsmPredFlag|TestPredFlag));
}
static Int /* $cut_transparent(P) */

View File

@ -1453,7 +1453,7 @@ c_goal(Term Goal, int mod)
#endif
}
return;
} else if (p->PredFlags & BasicPredFlag) {
} else if (p->PredFlags & AsmPredFlag) {
int op = p->PredFlags & 0x7f;
if (profiling)
emit(enter_profiling_op, (CELL)p, Zero);
@ -1600,7 +1600,7 @@ c_goal(Term Goal, int mod)
}
}
else {
if (p->PredFlags & (CPredFlag | BasicPredFlag)) {
if (p->PredFlags & (CPredFlag | AsmPredFlag)) {
#ifdef YAPOR
if (p->PredFlags & SyncPredFlag)
emit(sync_op, (CELL)p, (CELL)(p->ArityOfPE));

View File

@ -1111,7 +1111,7 @@ RunTopGoal(Term t)
}
if (pe == NIL ||
ppe->OpcodeOfPred == UNDEF_OPCODE ||
ppe->PredFlags & (UserCPredFlag|CPredFlag|BasicPredFlag) )
ppe->PredFlags & (UserCPredFlag|CPredFlag|AsmPredFlag) )
{
if (pe != NIL) {
READ_UNLOCK(ppe->PRWLock);

View File

@ -513,7 +513,13 @@ InitCPred(char *Name, int Arity, CPredicate code, int flags)
{
Atom atom = LookupAtom(Name);
PredEntry *pe;
yamop *p_code = (yamop *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)NULL),sla),e));
yamop *p_code = ((Clause *)NULL)->ClCode;
Clause *cl = (Clause *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)p_code),sla),e));
cl->u.ClValue = 0;
cl->ClFlags = 0;
cl->Owner = LookupAtom("user");
p_code = cl->ClCode;
if (Arity)
pe = RepPredProp(PredPropByFunc(MkFunctor(atom, Arity),CurrentModule));
@ -548,8 +554,13 @@ InitCmpPred(char *Name, int Arity, CmpPredicate cmp_code, CPredicate code, int f
{
Atom atom = LookupAtom(Name);
PredEntry *pe;
yamop *p_code = (yamop *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)NULL),sla),e));
yamop *p_code = ((Clause *)NULL)->ClCode;
Clause *cl = (Clause *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)p_code),sla),e));
cl->u.ClValue = 0;
cl->ClFlags = 0;
cl->Owner = LookupAtom("user");
p_code = cl->ClCode;
if (Arity)
pe = RepPredProp(PredPropByFunc(MkFunctor(atom, Arity),CurrentModule));
else
@ -589,10 +600,15 @@ InitAsmPred(char *Name, int Arity, int code, CPredicate def, int flags)
pe = RepPredProp(PredPropByFunc(MkFunctor(atom, Arity),CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
pe->PredFlags = flags | StandardPredFlag | (code);
pe->PredFlags = flags | AsmPredFlag | StandardPredFlag | (code);
if (def != NULL) {
yamop *p_code = (yamop *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)NULL),sla),e));
yamop *p_code = ((Clause *)NULL)->ClCode;
Clause *cl = (Clause *)AllocCodeSpace((CELL)NEXTOP(NEXTOP(((yamop *)p_code),sla),e));
cl->u.ClValue = 0;
cl->ClFlags = 0;
cl->Owner = LookupAtom("user");
p_code = cl->ClCode;
p_code->u.sla.l = pe->TrueCodeOfPred = (CODEADDR) def;
pe->CodeOfPred = pe->FirstClause = pe->LastClause = (CODEADDR) p_code;
pe->ModuleOfPred = CurrentModule;
@ -606,7 +622,7 @@ InitAsmPred(char *Name, int Arity, int code, CPredicate def, int flags)
pe->StateOfPred = NUMBER_OF_CPREDS;
NUMBER_OF_CPREDS++;
} else {
pe->FirstClause = pe->LastClause = NIL;
pe->FirstClause = pe->LastClause = NULL;
pe->OpcodeOfPred = opcode(_undef_p);
pe->TrueCodeOfPred = pe->CodeOfPred =
(CODEADDR)(&(pe->OpcodeOfPred));

View File

@ -28,7 +28,7 @@ static char SccsId[] = "%W% %G%";
#include "Yatom.h"
#include "Heap.h"
#include "yapio.h"
#include "iopreds.h"
#include <stdlib.h>
#if HAVE_STDARG_H
#include <stdarg.h>
@ -80,57 +80,6 @@ static char SccsId[] = "%W% %G%";
#endif
#endif
/* if we botched in a LongIO operation */
jmp_buf IOBotch;
#if HAVE_LIBREADLINE
#if _MSC_VER || defined(__MINGW32__)
FILE *rl_instream, *rl_outstream;
#endif
#endif
typedef struct
{
union {
struct {
Atom name;
Term user_name;
YP_File file;
} file;
struct {
char *buf; /* where the file is being read from/written to */
Int max_size; /* maximum buffer size (may be changed dynamically) */
Int pos;
} mem_string;
struct {
#if defined(__MINGW32__) || _MSC_VER
HANDLE hdl;
#else
int fd;
#endif
} pipe;
#if USE_SOCKET
struct {
socket_domain domain;
socket_info flags;
int fd;
} socket;
#endif
} u;
int (* stream_putc)(int, int); /* function the stream uses for writing */
int (* stream_getc)(int); /* function the stream uses for reading */
/* function the stream uses for parser. It may be different if the ISO
character conversion is on */
int (* stream_getc_for_read)(int);
Int charcount, linecount, linepos;
Int status;
Int och;
}
StreamDesc;
STATIC_PROTO (void InitStdStream, (int, SMALLUNSGN, YP_File, Atom));
STATIC_PROTO (Int PlIOError, (yap_error_number, Term, char *));
STATIC_PROTO (int FilePutc, (int, int));
STATIC_PROTO (int MemPutc, (int, int));
@ -220,35 +169,12 @@ STATIC_PROTO (Int p_type_of_char, (void));
STATIC_PROTO (Int GetArgSizeFromChar, (Term *));
#define YAP_ERROR NIL
static int parser_error_style = FAIL_ON_PARSER_ERROR;
#define MaxStreams 32
StreamDesc Stream[MaxStreams];
#define Free_Stream_f 0x000001
#define Output_Stream_f 0x000002
#define Input_Stream_f 0x000004
#define Append_Stream_f 0x000008
#define Eof_Stream_f 0x000010
#define Null_Stream_f 0x000020
#define Tty_Stream_f 0x000040
#define Socket_Stream_f 0x000080
#define Binary_Stream_f 0x000100
#define Eof_Error_Stream_f 0x000200
#define Reset_Eof_Stream_f 0x000400
#define Past_Eof_Stream_f 0x000800
#define Push_Eof_Stream_f 0x001000
#define Seekable_Stream_f 0x002000
#define Promptable_Stream_f 0x004000
#if USE_SOCKET
#define Client_Socket_Stream_f 0x008000
#define Server_Socket_Stream_f 0x010000
#if EMACS
static int first_char;
#endif
#define InMemory_Stream_f 0x020000
#define Pipe_Stream_f 0x040000
#define Popen_Stream_f 0x080000
int YP_stdin = 0;
int YP_stdout = 1;
@ -256,27 +182,6 @@ int YP_stderr = 2;
int c_input_stream, c_output_stream;
#if EMACS
static int first_char;
#endif
#define FAIL_ON_PARSER_ERROR 0
#define QUIET_ON_PARSER_ERROR 1
#define CONTINUE_ON_PARSER_ERROR 2
#define EXCEPTION_ON_PARSER_ERROR 3
static int parser_error_style = FAIL_ON_PARSER_ERROR;
#define StdInStream 0
#define StdOutStream 1
#define StdErrStream 2
#define ALIASES_BLOCK_SIZE 8
#if USE_SOCKET
extern int YP_sockets_io;
#endif
/* note: fprintf may be called from anywhere, so please don't try
to be smart and allocate stack from somewhere else */
int
@ -426,6 +331,15 @@ p_always_prompt_user(void)
return(TRUE);
}
static int
is_same_tty(YP_File f1, YP_File f2)
{
#if HAVE_TTYNAME
return(ttyname(YP_fileno(f1)) == ttyname(YP_fileno(f1)));
#else
return(TRUE);
#endif
}
static void
InitStdStream (int sno, SMALLUNSGN flags, YP_File file, Atom name)
@ -463,7 +377,7 @@ InitStdStream (int sno, SMALLUNSGN flags, YP_File file, Atom name)
#if HAVE_LIBREADLINE
if (s->status & Tty_Stream_f) {
if (Stream[0].status & Tty_Stream_f &&
s->u.file.name == Stream[0].u.file.name)
is_same_tty(s->u.file.file,Stream[0].u.file.file))
s->stream_putc = ReadlinePutc;
s->stream_getc = ReadlineGetc;
} else
@ -498,7 +412,7 @@ InitStdStream (int sno, SMALLUNSGN flags, YP_File file, Atom name)
s->status |= Tty_Stream_f|Promptable_Stream_f;
#endif
#if HAVE_SETBUF
if ((s->status & Tty_Stream_f) && file == stdin)
if (s->status & Tty_Stream_f)
/* make sure input is unbuffered if it comes from stdin, this
makes life simpler for interrupt handling */
YP_setbuf (stdin, NULL);
@ -508,19 +422,13 @@ InitStdStream (int sno, SMALLUNSGN flags, YP_File file, Atom name)
void
InitPlIO (void)
InitStdStreams (void)
{
Int i;
for (i = 0; i < MaxStreams; ++i)
Stream[i].status = Free_Stream_f;
InitStdStream (StdInStream, Input_Stream_f, stdin, AtomUsrIn);
InitStdStream (StdOutStream, Output_Stream_f, stdout, AtomUsrOut);
InitStdStream (StdErrStream, Output_Stream_f, stderr, AtomUsrErr);
c_input_stream = StdInStream;
c_output_stream = StdOutStream;
/* alloca alias array */
FileAliases = (AliasDesc)AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE);
/* init standard aliases */
FileAliases[0].name = AtomUsrIn;
FileAliases[0].alias_stream = 0;
@ -532,6 +440,18 @@ InitPlIO (void)
SzOfFileAliases = ALIASES_BLOCK_SIZE;
}
void
InitPlIO (void)
{
Int i;
for (i = 0; i < MaxStreams; ++i)
Stream[i].status = Free_Stream_f;
/* alloca alias array */
FileAliases = (AliasDesc)AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE);
InitStdStreams();
}
static Int
PlIOError (yap_error_number type, Term culprit, char *who)
{
@ -1006,7 +926,7 @@ EOFGetc(int sno)
if (s->status & Tty_Stream_f) {
s->stream_getc = ReadlineGetc;
if (Stream[0].status & Tty_Stream_f &&
s->u.file.name == Stream[0].u.file.name)
is_same_tty(s->u.file.file,Stream[0].u.file.file))
s->stream_putc = ReadlinePutc;
} else
#endif
@ -1349,7 +1269,7 @@ PlUnGetc (int sno)
if (s->status & Tty_Stream_f) {
s->stream_getc = ReadlineGetc;
if (Stream[0].status & Tty_Stream_f &&
s->u.file.name == Stream[0].u.file.name)
is_same_tty(s->u.file.file,Stream[0].u.file.file))
s->stream_putc = ReadlinePutc;
} else
#endif

100
C/save.c
View File

@ -23,6 +23,7 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
#include "yapio.h"
#include "sshift.h"
#include "Foreign.h"
#include "iopreds.h"
#if HAVE_STRING_H
#include <string.h>
#endif
@ -59,11 +60,11 @@ static char end_msg[256] ="*** End of YAP saved state *****";
#ifdef DEBUG
/*
* FOR DEBUGGING define DEBUG_RESTORE0 to check the file stuff,
define DEBUG_RESTORE1 to see if it is able to prepare the chain,
define DEBUG_RESTORE2 to see how things are going,
define DEBUG_RESTORE3 to check if the atom chain is still a working
* chain,
*
#FOR DEBUGGING define DEBUG_RESTORE0 to check the file stuff,
#define DEBUG_RESTORE1 to see if it is able to prepare the chain,
#define DEBUG_RESTORE2 to see how things are going,
#define DEBUG_RESTORE3 to check if the atom chain is still a working chain,
* define DEBUG_RESTORE4 if you want to set the output for some
* particular file,
* define DEBUG_RESTORE5 if you want to see how the stacks are being
@ -75,8 +76,6 @@ define DEBUG_RESTORE3 to check if the atom chain is still a working
* Good Luck
*/
#define DEBUG_RESTORE2 1
#endif
STATIC_PROTO(void myread, (int, char *, Int));
@ -999,6 +998,7 @@ restore_codes(void)
for (i = 0; i < heap_regs->no_of_modules; i++) {
heap_regs->module_name[i] = AtomTermAdjust(heap_regs->module_name[i]);
heap_regs->module_pred[i] = PtoPredAdjust(heap_regs->module_pred[i]);
}
}
heap_regs->atom_abol = AtomAdjust(heap_regs->atom_abol);
@ -1116,10 +1116,14 @@ restore_codes(void)
#endif
heap_regs->term_prolog = AtomTermAdjust(heap_regs->term_prolog);
heap_regs->term_refound_var = AtomTermAdjust(heap_regs->term_refound_var);
heap_regs->dyn_array_list =
(struct array_entry *)AddrAdjust((ADDR)heap_regs->dyn_array_list);
heap_regs->file_aliases =
(struct AliasDescS *)AddrAdjust((ADDR)heap_regs->file_aliases);
if (heap_regs->dyn_array_list != NULL) {
heap_regs->dyn_array_list =
(struct array_entry *)AddrAdjust((ADDR)heap_regs->dyn_array_list);
}
if (heap_regs->file_aliases != NULL) {
heap_regs->file_aliases =
(struct AliasDescS *)AddrAdjust((ADDR)heap_regs->file_aliases);
}
heap_regs->yap_lib_dir =
(char *)AddrAdjust((ADDR)heap_regs->yap_lib_dir);
heap_regs->pred_goal_expansion =
@ -1132,6 +1136,8 @@ restore_codes(void)
(PredEntry *)AddrAdjust((ADDR)heap_regs->pred_throw);
heap_regs->pred_handle_throw =
(PredEntry *)AddrAdjust((ADDR)heap_regs->pred_handle_throw);
if (heap_regs->dyn_array_list != NULL)
heap_regs->dyn_array_list = PtoArrayEAdjust(heap_regs->dyn_array_list);
if (heap_regs->undef_code != NULL)
heap_regs->undef_code = (PredEntry *)PtoHeapCellAdjust((CELL *)(heap_regs->undef_code));
if (heap_regs->creep_code != NULL)
@ -1266,11 +1272,12 @@ AdjustDBTerm(Term trm)
if (IsApplTerm(trm)) {
Functor f;
Term *p0 = p = PtoHeapCellAdjust(RepAppl(trm));
f = FuncAdjust((Functor)(*p));
*p = (Term)f ;
f = (Functor)*p;
if (!IsExtensionFunctor(f)) {
int Arity, i;
f = FuncAdjust(f);
*p = (Term)f;
Arity = ArityOfFunctor(f);
p++;
for (i = 0; i < Arity; ++i) {
@ -1553,15 +1560,24 @@ RestoreClause(Clause *Cl)
{
yamop *pc;
OPREG cl_type = Cl->ClFlags;
OPREG cl_type = FirstArgOfClType(Cl->ClFlags);
if (cl_type == ApplCl ||
(cl_type == ListCl && HeadOfClType(cl_type) == ApplCl))
(cl_type == ListCl && HeadOfClType(cl_type) == ApplCl)) {
#ifdef DEBUG_RESTORE2
YP_fprintf(errout, "at %p, appl: %lx -> %lx", Cl, Cl->u.ClValue,
(CELL)FuncAdjust((Functor)(Cl->u.ClValue)));
#endif
Cl->u.ClValue = (CELL)FuncAdjust((Functor)(Cl->u.ClValue));
else if ((cl_type == AtCl ||
} else if ((cl_type == AtCl ||
(cl_type == ListCl && HeadOfClType(cl_type) == AtCl)) &&
IsAtomTerm(Cl->u.ClValue))
IsAtomTerm(Cl->u.ClValue)) {
#ifdef DEBUG_RESTORE2
YP_fprintf(errout, "at %p, atom: %lx -> %lx", Cl, Cl->u.ClValue,
(CELL)FuncAdjust((Functor)(Cl->u.ClValue)));
#endif
Cl->u.ClValue = AtomTermAdjust(Cl->u.ClValue);
}
/* TO DO: log update semantics */
/* Get the stored operator */
pc = Cl->ClCode;
@ -2436,22 +2452,26 @@ CleanCode(PredEntry *pp)
if (pp->OwnerFile)
pp->OwnerFile = AtomAdjust(pp->OwnerFile);
pp->OpcodeOfPred = opcode(op_from_opcode(pp->OpcodeOfPred));
if (pp->PredFlags & (CPredFlag|BasicPredFlag)) {
if (pp->CodeOfPred != NULL) {
if (pp->CodeOfPred == pp->TrueCodeOfPred) {
if (pp->PredFlags & CPredFlag)
/* C, assembly + C */
pp->CodeOfPred = pp->TrueCodeOfPred = CCodeAdjust(pp);
else
/* assembly */
pp->CodeOfPred = (CODEADDR)AddrAdjust((ADDR)(pp->CodeOfPred));
} else {
/* comparison */
if (pp->PredFlags & BinaryTestPredFlag) {
pp->CodeOfPred = CCodeAdjust(pp);
pp->TrueCodeOfPred = DirectCCodeAdjust(pp);
}
}
if (pp->PredFlags & CPredFlag) {
if (pp->PredFlags & BinaryTestPredFlag) {
pp->TrueCodeOfPred = DirectCCodeAdjust(pp);
} else {
/* C, assembly + C */
pp->CodeOfPred = pp->TrueCodeOfPred = CCodeAdjust(pp);
}
pp->CodeOfPred = pp->FirstClause = pp->LastClause =
(CODEADDR)AddrAdjust((ADDR)(pp->LastClause));
CleanClauses(pp->FirstClause, pp->FirstClause);
} else if (pp->PredFlags & AsmPredFlag) {
/* assembly */
if (pp->FirstClause) {
pp->CodeOfPred = (CODEADDR)AddrAdjust((ADDR)(pp->CodeOfPred));
pp->FirstClause = (CODEADDR)AddrAdjust((ADDR)(pp->FirstClause));
pp->LastClause = (CODEADDR)AddrAdjust((ADDR)(pp->LastClause));
CleanClauses(pp->FirstClause, pp->FirstClause);
} else {
pp->TrueCodeOfPred = pp->CodeOfPred =
(CODEADDR)(&(pp->OpcodeOfPred));
}
} else {
if (pp->FirstClause)
@ -2460,6 +2480,8 @@ CleanCode(PredEntry *pp)
pp->LastClause = CodeAddrAdjust(pp->LastClause);
pp->CodeOfPred = CodeAddrAdjust(pp->CodeOfPred);
pp->TrueCodeOfPred = CodeAddrAdjust(pp->TrueCodeOfPred);
if (pp->NextPredOfModule)
pp->NextPredOfModule = PtoPredAdjust(pp->NextPredOfModule);
flag = pp->PredFlags;
FirstC = pp->FirstClause;
LastC = pp->LastClause;
@ -2525,6 +2547,8 @@ RestoreEntries(PropEntry *pp)
if (ae->ArrayEArity < 0) {
restore_static_array((StaticArrayEntry *)ae);
} else {
if (ae->NextArrayE != NULL)
ae->NextArrayE = PtoArrayEAdjust(ae->NextArrayE);
if (IsVarTerm(ae->ValueOfVE))
RESET_VARIABLE(&(ae->ValueOfVE));
else {
@ -2659,6 +2683,13 @@ RestoreForeignCodeStructure(void)
}
}
/* restore the atom entries which are invisible for the user */
static void
RestoreIOStructures(void)
{
InitStdStreams();
}
/* restores the list of free space, with its curious structure */
static void
RestoreFreeSpace(void)
@ -2713,6 +2744,7 @@ restore_heap(void)
}
RestoreInvisibleAtoms();
RestoreForeignCodeStructure();
RestoreIOStructures();
}
@ -2952,7 +2984,7 @@ UnmarkTrEntries(void)
if (IsVarTerm(entry)) {
RESET_VARIABLE((CELL *)entry);
} else if (IsPairTerm(entry)) {
CODEADDR ent = (CODEADDR)RepPair(entry);
CODEADDR ent = CodeAddrAdjust((CODEADDR)RepPair(entry));
register CELL flags;
flags = Flags(ent);

View File

@ -113,7 +113,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
vsc_count++;
/* if (vsc_count < 618000) return; */
if (vsc_count == 131) {
if (vsc_count == 64) {
printf("Here I go\n");
}
/* if (vsc_count > 500000) exit(0); */

View File

@ -1718,31 +1718,31 @@ InitUnify(void)
InitCPred("unify_with_occurs_check", 2, p_ocunify, SafePredFlag);
InitCPred("cyclic_term", 1, p_cyclic, SafePredFlag|TestPredFlag);
InitCPred("acyclic_term", 1, p_acyclic, SafePredFlag|TestPredFlag);
InitAsmPred("$$cut_by", 1, _cut_by, p_cut_by, SafePredFlag | BasicPredFlag);
InitAsmPred("$$cut_by", 1, _cut_by, p_cut_by, SafePredFlag);
InitAsmPred("atom", 1, _atom, p_atom, SafePredFlag | BasicPredFlag);
InitAsmPred("atomic", 1, _atomic, p_atomic, SafePredFlag | BasicPredFlag);
InitAsmPred("integer", 1, _integer, p_integer, SafePredFlag | BasicPredFlag);
InitAsmPred("nonvar", 1, _nonvar, p_nonvar, SafePredFlag | BasicPredFlag);
InitAsmPred("number", 1, _number, p_number, SafePredFlag | BasicPredFlag);
InitAsmPred("var", 1, _var, p_var, SafePredFlag | BasicPredFlag);
InitAsmPred("db_reference", 1, _db_ref, p_db_ref, SafePredFlag | BasicPredFlag);
InitAsmPred("primitive", 1, _primitive, p_primitive, SafePredFlag | BasicPredFlag);
InitAsmPred("compound", 1, _compound, p_compound, SafePredFlag | BasicPredFlag);
InitAsmPred("float", 1, _float, p_float, SafePredFlag | BasicPredFlag);
InitAsmPred("=", 2, _equal, p_equal, SafePredFlag | BasicPredFlag);
InitAsmPred("\\=", 2, _dif, p_dif, SafePredFlag | BasicPredFlag);
InitAsmPred("==", 2, _eq, p_eq, SafePredFlag | BasicPredFlag);
InitAsmPred("arg", 3, _arg, p_arg, SafePredFlag | BasicPredFlag);
InitAsmPred("functor", 3, _functor, p_functor, SafePredFlag | BasicPredFlag);
InitAsmPred("$plus", 3, _plus, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$minus", 3, _minus, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$times", 3, _times, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$div", 3, _div, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$and", 3, _and, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$or", 3, _or, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$sll", 3, _sll, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("$slr", 3, _slr, p_erroneous_call, SafePredFlag | BasicPredFlag);
InitAsmPred("atom", 1, _atom, p_atom, SafePredFlag);
InitAsmPred("atomic", 1, _atomic, p_atomic, SafePredFlag);
InitAsmPred("integer", 1, _integer, p_integer, SafePredFlag);
InitAsmPred("nonvar", 1, _nonvar, p_nonvar, SafePredFlag);
InitAsmPred("number", 1, _number, p_number, SafePredFlag);
InitAsmPred("var", 1, _var, p_var, SafePredFlag);
InitAsmPred("db_reference", 1, _db_ref, p_db_ref, SafePredFlag);
InitAsmPred("primitive", 1, _primitive, p_primitive, SafePredFlag);
InitAsmPred("compound", 1, _compound, p_compound, SafePredFlag);
InitAsmPred("float", 1, _float, p_float, SafePredFlag);
InitAsmPred("=", 2, _equal, p_equal, SafePredFlag);
InitAsmPred("\\=", 2, _dif, p_dif, SafePredFlag);
InitAsmPred("==", 2, _eq, p_eq, SafePredFlag);
InitAsmPred("arg", 3, _arg, p_arg, SafePredFlag);
InitAsmPred("functor", 3, _functor, p_functor, SafePredFlag);
InitAsmPred("$plus", 3, _plus, p_erroneous_call, SafePredFlag);
InitAsmPred("$minus", 3, _minus, p_erroneous_call, SafePredFlag);
InitAsmPred("$times", 3, _times, p_erroneous_call, SafePredFlag);
InitAsmPred("$div", 3, _div, p_erroneous_call, SafePredFlag);
InitAsmPred("$and", 3, _and, p_erroneous_call, SafePredFlag);
InitAsmPred("$or", 3, _or, p_erroneous_call, SafePredFlag);
InitAsmPred("$sll", 3, _sll, p_erroneous_call, SafePredFlag);
InitAsmPred("$slr", 3, _slr, p_erroneous_call, SafePredFlag);
}

122
H/iopreds.h Normal file
View File

@ -0,0 +1,122 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: iopreds.c *
* Last rev: 5/2/88 *
* mods: *
* comments: Input/Output C implemented predicates *
* *
*************************************************************************/
#ifdef SCCS
static char SccsId[] = "%W% %G%";
#endif
/*
* This file defines main data-structure for stream management,
*
*/
/* if we botched in a LongIO operation */
jmp_buf IOBotch;
#if HAVE_LIBREADLINE
#if _MSC_VER || defined(__MINGW32__)
FILE *rl_instream, *rl_outstream;
#endif
#endif
typedef struct
{
union {
struct {
Atom name;
Term user_name;
YP_File file;
} file;
struct {
char *buf; /* where the file is being read from/written to */
Int max_size; /* maximum buffer size (may be changed dynamically) */
Int pos;
} mem_string;
struct {
#if defined(__MINGW32__) || _MSC_VER
HANDLE hdl;
#else
int fd;
#endif
} pipe;
#if USE_SOCKET
struct {
socket_domain domain;
socket_info flags;
int fd;
} socket;
#endif
} u;
int (* stream_putc)(int, int); /* function the stream uses for writing */
int (* stream_getc)(int); /* function the stream uses for reading */
/* function the stream uses for parser. It may be different if the ISO
character conversion is on */
int (* stream_getc_for_read)(int);
Int charcount, linecount, linepos;
Int status;
Int och;
}
StreamDesc;
#define YAP_ERROR NIL
#define MaxStreams 32
StreamDesc Stream[MaxStreams];
#define Free_Stream_f 0x000001
#define Output_Stream_f 0x000002
#define Input_Stream_f 0x000004
#define Append_Stream_f 0x000008
#define Eof_Stream_f 0x000010
#define Null_Stream_f 0x000020
#define Tty_Stream_f 0x000040
#define Socket_Stream_f 0x000080
#define Binary_Stream_f 0x000100
#define Eof_Error_Stream_f 0x000200
#define Reset_Eof_Stream_f 0x000400
#define Past_Eof_Stream_f 0x000800
#define Push_Eof_Stream_f 0x001000
#define Seekable_Stream_f 0x002000
#define Promptable_Stream_f 0x004000
#if USE_SOCKET
#define Client_Socket_Stream_f 0x008000
#define Server_Socket_Stream_f 0x010000
#endif
#define InMemory_Stream_f 0x020000
#define Pipe_Stream_f 0x040000
#define Popen_Stream_f 0x080000
#define FAIL_ON_PARSER_ERROR 0
#define QUIET_ON_PARSER_ERROR 1
#define CONTINUE_ON_PARSER_ERROR 2
#define EXCEPTION_ON_PARSER_ERROR 3
#define StdInStream 0
#define StdOutStream 1
#define StdErrStream 2
#define ALIASES_BLOCK_SIZE 8
#if USE_SOCKET
extern int YP_sockets_io;
#endif
void STD_PROTO (InitStdStreams, (void));

View File

@ -102,13 +102,15 @@ INTERFACE_HEADERS = $(srcdir)/include/c_interface.h $(srcdir)/include/yap_struct
HEADERS = \
$(GHEADERS) $(INTERFACE_HEADERS) \
$(srcdir)/H/Heap.h \
$(srcdir)/H/Regs.h $(srcdir)/H/Yapproto.h \
$(srcdir)/H/absmi.h $(srcdir)/H/alloc.h $(srcdir)/H/Heap.h \
$(srcdir)/H/absmi.h $(srcdir)/H/alloc.h \
$(srcdir)/H/amidefs.h $(srcdir)/H/amiops.h $(srcdir)/H/arrays.h \
$(srcdir)/H/arith2.h $(srcdir)/H/attvar.h \
$(srcdir)/H/clause.h $(srcdir)/H/compile.h \
$(srcdir)/H/corout.h $(srcdir)/H/eval.h $(srcdir)/H/heapgc.h \
$(srcdir)/H/index.h $(srcdir)/H/yapio.h $(srcdir)/H/tracer.h \
$(srcdir)/H/attvar.h $(srcdir)/H/arith2.h \
$(srcdir)/H/index.h $(srcdir)/H/iopreds.h \
$(srcdir)/H/tracer.h $(srcdir)/H/yapio.h \
$(srcdir)/OPTYap/opt.config.h \
$(srcdir)/OPTYap/opt.proto.h $(srcdir)/OPTYap/opt.structs.h \
$(srcdir)/OPTYap/opt.macros.h $(srcdir)/OPTYap/or.macros.h \

View File

@ -154,7 +154,7 @@ Constructor(Prop,AbsVal,ValEntry *,p,p)
Inline(IsValProperty, PropFlags, int, flags, (flags == ValProperty) )
/* predicate property entry structure */
/* BasicPreds are things like var, nonvar, atom ...which are implemented
/* AsmPreds are things like var, nonvar, atom ...which are implemented
through dedicated machine instructions. In this case the 8 lower
bits of PredFlags are used to hold the machine instruction code
for the pred.
@ -171,7 +171,7 @@ typedef enum {
MultiFileFlag = 0x040000L, /* is multi-file */
FastPredFlag = 0x020000L, /* is "compiled" */
TestPredFlag = 0x010000L, /* is a test (optim. comit) */
BasicPredFlag = 0x008000L, /* inline */
AsmPredFlag = 0x008000L, /* inline */
StandardPredFlag= 0x004000L, /* system predicate */
DynamicPredFlag= 0x002000L, /* dynamic predicate */
CPredFlag = 0x001000L, /* written in C */

View File

@ -60,17 +60,12 @@ Inline(FuncAdjust, Functor, Functor, f, (Functor)(CharP(f)+HDiff) )
Inline(CellPtoHeapAdjust, CELL *, CELL *, ptr, ((CELL *)(CharP(ptr) + HDiff)) )
#if USE_OFFSETS
Inline(AtomAdjust, Atom, Atom, at, (at) )
Inline(AtomTermAdjust, Term, Term, at, (at) )
Inline(PropAdjust, Prop, Prop, p, (p) )
#else
Inline(AtomAdjust, Atom, Atom, at, (Atom)(CharP(at)+HDiff) )
#if MMAP_ADDR >= 0x40000000
Inline(AtomAdjust, Atom, Atom, at, (at == NULL ? (at) : (Atom)(CharP(at)+HDiff) ))
Inline(PropAdjust, Prop, Prop, p, (p == NULL ? (p) : (Prop)(CharP(p)+HDiff)) )
#endif
Inline(AtomTermAdjust, Term, Term, at, (at) )
#else
Inline(AtomTermAdjust, Term, Term, at, MkAtomTerm((Atom)(CharP(AtomOfTerm(at)+HDiff))) )
#endif
Inline(PropAdjust, Prop, Prop, p, (Prop)(CharP(p)+HDiff) )
#endif
#if TAGS_FAST_OPS
Inline(BlobTermAdjust, Term, Term, t, (t-HDiff) )
#else
@ -85,7 +80,8 @@ Inline(CodeAddrAdjust, CODEADDR, CODEADDR, addr, (CODEADDR)(CharP(addr)+HDiff) )
Inline(BlockAdjust, BlockHeader *, BlockHeader *, addr, (BlockHeader *)(CharP(addr)+HDiff) )
Inline(PtoOpAdjust, yamop *, yamop *, ptr, ((yamop *)(CharP(ptr) + HDiff)) )
Inline(PtoHeapCellAdjust, CELL *, CELL *, ptr, ((CELL *)(CharP(ptr) + HDiff)) )
Inline(PtoPredAdjust, PredEntry *, PredEntry *, ptr, ((CELL *)(CharP(ptr) + HDiff)) )
Inline(PtoPredAdjust, PredEntry *, PredEntry *, ptr, ((PredEntry *)(CharP(ptr) + HDiff)) )
Inline(PtoArrayEAdjust, ArrayEntry *, ArrayEntry *, ptr, ((ArrayEntry *)(CharP(ptr) + HDiff)) )
#if PRECOMPUTE_REGADDRESS
Inline(XAdjust, AREG, AREG, reg, (AREG)((reg)+XDiff) )
#else