Skip to content

Commit

Permalink
Merge pull request #8 from vscosta/master
Browse files Browse the repository at this point in the history
Catchup to Vitor
  • Loading branch information
TeamSPoon committed Feb 22, 2016
2 parents 2808ff7 + 3af377d commit cb01e3e
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 136 deletions.
8 changes: 5 additions & 3 deletions C/absmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,10 @@ static void
undef_goal( USES_REGS1 )
{
PredEntry *pe = PredFromDefCode(P);
if (Yap_UnknownFlag(CurrentModule) == TermFail) {
P = FAILCODE;
return;
}
BEGD(d0);
/* avoid trouble with undefined dynamic procedures */
/* I assume they were not locked beforehand */
Expand All @@ -1373,9 +1377,7 @@ undef_goal( USES_REGS1 )
PP = pe;
}
#endif
if ((pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MultiFileFlag)) ||
CurrentModule == PROLOG_MODULE ||
(UndefCode->OpcodeOfPred == UNDEF_OPCODE)) {
if (pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MultiFileFlag)) {
#if defined(YAPOR) || defined(THREADS)
UNLOCKPE(19,PP);
PP = NULL;
Expand Down
6 changes: 4 additions & 2 deletions C/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ Yap_ArgKey(Atom key, const param_t *def, int n)
return -1;
}

#define failed(e, t, a) failed__(e, t, a PASS_REGS)

static xarg *
failed( yap_error_number e, Term t, xarg *a)
failed__( yap_error_number e, Term t, xarg *a USES_REGS)
{
free( a );
LOCAL_Error_TYPE = e;
Expand All @@ -70,7 +72,7 @@ Yap_ArgListToVector (Term listl, const param_t *def, int n)
if (IsAtomTerm(listl) ) {
xarg *na = matchKey( AtomOfTerm(listl), a, n, def);
if (!na) {
return failed( TYPE_ERROR_LIST, listl, a);
return failed( TYPE_ERROR_LIST, listl, a );
}
} else if (IsApplTerm(listl)) {
Functor f = FunctorOfTerm( listl );
Expand Down
5 changes: 3 additions & 2 deletions C/c_interface.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/************************************************************************* *
* YAP Prolog *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
Expand Down Expand Up @@ -2348,7 +2349,7 @@ X_API Int YAP_Init(YAP_init_args *yap_init) {
int restore_result;
int do_bootstrap = (yap_init->YapPrologBootFile != NULL);
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
char boot_file[256];
char boot_file[YAP_FILENAME_MAX+1];
static int initialized = FALSE;

/* ignore repeated calls to YAP_Init */
Expand All @@ -2367,7 +2368,7 @@ X_API Int YAP_Init(YAP_init_args *yap_init) {
GLOBAL_argc = yap_init->Argc;
#if BOOT_FROM_SAVED_STATE
if (!yap_init->SavedState) {
yap_init->SavedState = Yap_locateFile(YAP_STARTUP, LOCAL_FileNameBuf, sizeof(LOCAL_FileNameBuf)-1);
yap_init->SavedState = Yap_locateFile(YAP_STARTUP, boot_file, sizeof(boot_file)-1);
}

#else
Expand Down
1 change: 1 addition & 0 deletions C/dbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,7 @@ static PredEntry *new_lu_int_key(Int key) {
}

static PredEntry *new_lu_entry(Term t) {
CACHE_REGS
Prop p0;
PredEntry *pe;

Expand Down
59 changes: 37 additions & 22 deletions C/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ static bool sys_thread_id(Term inp) {
static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
CACHE_REGS
FlagEntry *fv;
ModEntry *new = Yap_GetModuleEntry(mod);
if (!new)
ModEntry *me = Yap_GetModuleEntry(mod);
if (!me)
return false;
fv = GetFlagProp(AtomOfTerm(tflag));
if (!fv && !fv->global) {
Expand All @@ -641,18 +641,18 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
// module specific stuff now

if (fv->FlagOfVE == UNKNOWN_FLAG) {
new->flags &= ~(UNKNOWN_MASK);
me->flags &= ~(UNKNOWN_MASK);
if (t2 == TermError) {
new->flags |= (UNKNOWN_ERROR);
me->flags |= (UNKNOWN_ERROR);
return true;
} else if (t2 == TermFail) {
new->flags |= (UNKNOWN_FAIL);
me->flags |= (UNKNOWN_FAIL);
return true;
} else if (t2 == TermWarning) {
new->flags |= (UNKNOWN_WARNING);
me->flags |= (UNKNOWN_WARNING);
return true;
} else if (t2 == TermFastFail) {
new->flags |= (UNKNOWN_FAST_FAIL);
me->flags |= (UNKNOWN_FAST_FAIL);
return true;
}
Yap_Error(
Expand All @@ -661,21 +661,21 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
RepAtom(AtomOfTerm(tflag))->StrOfAE);
return false;
} else if (fv->FlagOfVE == DOUBLE_QUOTES_FLAG) {
return dqf1(new, t2 PASS_REGS);
return dqf1(me, t2 PASS_REGS);
} else if (fv->FlagOfVE == CHARACTER_ESCAPES_FLAG) {
if (t2 == TermTrue) {
new->flags |= M_CHARESCAPE;
me->flags |= M_CHARESCAPE;
return true;
} else if (t2 == TermFalse) {
new->flags &= ~(M_CHARESCAPE);
me->flags &= ~(M_CHARESCAPE);
return true;
}
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2,
"bad option %s for character_escapes flag, use true or false",
RepAtom(AtomOfTerm(tflag))->StrOfAE);
return false;
} else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) {
return bqf1(new, t2 PASS_REGS);
return bqf1(me, t2 PASS_REGS);
;
}
// bad key?
Expand All @@ -684,7 +684,7 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {

static Term getYapFlagInModule(Term tflag, Term mod) {
FlagEntry *fv;
ModEntry *new = Yap_GetModuleEntry(mod);
ModEntry *me = Yap_GetModuleEntry(mod);
if (!mod)
return false;
fv = GetFlagProp(AtomOfTerm(tflag));
Expand All @@ -695,28 +695,28 @@ static Term getYapFlagInModule(Term tflag, Term mod) {
// module specific stuff now

if (fv->FlagOfVE == UNKNOWN_FLAG) {
if (new->flags & UNKNOWN_ERROR)
if (me->flags & UNKNOWN_ERROR)
return TermError;
if (new->flags & UNKNOWN_WARNING)
if (me->flags & UNKNOWN_WARNING)
return TermWarning;
return TermFail;
} else if (fv->FlagOfVE == CHARACTER_ESCAPES_FLAG) {
if (new->flags & M_CHARESCAPE)
if (me->flags & M_CHARESCAPE)
return TermTrue;
} else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) {
if (new->flags & BCKQ_CHARS)
if (me->flags & BCKQ_CHARS)
return TermChars;
if (new->flags & BCKQ_CODES)
if (me->flags & BCKQ_CODES)
return TermCodes;
if (new->flags & BCKQ_ATOM)
if (me->flags & BCKQ_ATOM)
return TermAtom;
return TermString;
} else if (fv->FlagOfVE == DOUBLE_QUOTES_FLAG) {
if (new->flags & DBLQ_CHARS)
if (me->flags & DBLQ_CHARS)
return TermChars;
if (new->flags & DBLQ_CODES)
if (me->flags & DBLQ_CODES)
return TermCodes;
if (new->flags & DBLQ_ATOM)
if (me->flags & DBLQ_ATOM)
return TermAtom;
return TermString;
}
Expand Down Expand Up @@ -1012,6 +1012,21 @@ bool setYapFlag(Term tflag, Term t2) {
return true;
}


Term Yap_UnknownFlag(Term mod) {
if (mod == PROLOG_MODULE)
mod = TermProlog;

ModEntry *fv = Yap_GetModuleEntry(mod);
if (fv == NULL)
fv = Yap_GetModuleEntry(AtomUser);
if (fv->flags & UNKNOWN_ERROR)
return TermError;
if (fv->flags & UNKNOWN_WARNING)
return TermWarning;
return TermFail;
}

Term getYapFlag(Term tflag) {
FlagEntry *fv;
flag_term *tarr;
Expand Down Expand Up @@ -1043,7 +1058,7 @@ Term getYapFlag(Term tflag) {
Yap_Error(DOMAIN_ERROR_PROLOG_FLAG, fl, "trying to read unknown flag %s",
RepAtom(AtomOfTerm(fl))->StrOfAE);
}
return FALSE;
return false;
}
if (fv->global)
tarr = GLOBAL_Flags;
Expand Down
14 changes: 8 additions & 6 deletions C/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static Int current_module(USES_REGS1);
static Int current_module1(USES_REGS1);
static ModEntry *LookupModule(Term a);
static ModEntry *LookupSystemModule(Term a);
static ModEntry *GetModuleEntry(Atom at);
static ModEntry *GetModuleEntry(Atom at USES_REGS);
static ModEntry *FetchModuleEntry(Atom at);

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ initMod( AtomEntry *toname, AtomEntry *ae) {
*
* @return module descriptorxs
*/
static ModEntry *GetModuleEntry(Atom at)
static ModEntry *GetModuleEntry(Atom at USES_REGS)
{
Prop p0;
AtomEntry *ae = RepAtom(at);
Expand Down Expand Up @@ -126,8 +126,9 @@ bool Yap_getUnknown ( Term mod) {


bool Yap_CharacterEscapes(Term mt) {
CACHE_REGS
if (mt == PROLOG_MODULE) mt = TermProlog;
return GetModuleEntry(AtomOfTerm(mt))->flags & M_CHARESCAPE;
return GetModuleEntry(AtomOfTerm(mt) PASS_REGS)->flags & M_CHARESCAPE;
}


Expand Down Expand Up @@ -163,7 +164,7 @@ static ModEntry *LookupSystemModule(Term a) {
a = TermProlog;
}
at = AtomOfTerm(a);
me = GetModuleEntry(at);
me = GetModuleEntry(at PASS_REGS);
if (!me)
return NULL;
me->flags |= M_SYSTEM;
Expand All @@ -173,15 +174,16 @@ static ModEntry *LookupSystemModule(Term a) {


static ModEntry *LookupModule(Term a) {
CACHE_REGS
Atom at;
ModEntry *me;

/* prolog module */
if (a == 0) {
return GetModuleEntry(AtomProlog);
return GetModuleEntry(AtomProlog PASS_REGS);
}
at = AtomOfTerm(a);
me = GetModuleEntry(at);
me = GetModuleEntry(at PASS_REGS);
return me;
}

Expand Down
6 changes: 3 additions & 3 deletions C/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void restore_heap(void);
static void ShowAtoms(void);
static void ShowEntries(PropEntry *);
#endif
static int OpenRestore(char *, char *, CELL *, CELL *, CELL *, CELL *, FILE **);
static int OpenRestore(const char *, char *, CELL *, CELL *, CELL *, CELL *, FILE **);
static void CloseRestore(void);
#ifndef _WIN32
static int check_opcodes(OPCODE []);
Expand Down Expand Up @@ -1435,7 +1435,7 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
}

static int
OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp)
OpenRestore(const char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp)
{
CACHE_REGS

Expand Down Expand Up @@ -1550,7 +1550,7 @@ RestoreHeap(OPCODE old_ops[] USES_REGS)
* state
*/
int
Yap_SavedInfo(char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
Yap_SavedInfo(const char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
{
return DO_ONLY_CODE;

Expand Down
9 changes: 6 additions & 3 deletions C/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ typedef struct scanner_extra_alloc {
void *filler;
} ScannerExtraBlock;

static TokEntry *CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l) {
#define CodeSpaceError(t, p, l) CodeSpaceError__(t, p, l PASS_REGS)
static TokEntry *CodeSpaceError__(TokEntry *t, TokEntry *p, TokEntry *l USES_REGS) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
LOCAL_ErrorMessage = "Code Space Overflow";
if (t) {
Expand All @@ -574,7 +575,8 @@ static TokEntry *CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l) {
return l;
}

static TokEntry *TrailSpaceError(TokEntry *t, TokEntry *l) {
#define TrailSpaceError(t, l) TrailSpaceError__(t, l PASS_REGS)
static TokEntry *TrailSpaceError__(TokEntry *t, TokEntry *l USES_REGS) {
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL;
if (t) {
Expand All @@ -584,7 +586,8 @@ static TokEntry *TrailSpaceError(TokEntry *t, TokEntry *l) {
return l;
}

static TokEntry *AuxSpaceError(TokEntry *p, TokEntry *l, const char *msg) {
#define AuxSpaceError(p, l, msg) AuxSpaceError__(p, l, msg PASS_REGS)
static TokEntry *AuxSpaceError__(TokEntry *p, TokEntry *l, const char *msg USES_REGS) {
/* huge atom or variable, we are in trouble */
LOCAL_ErrorMessage = (char *)msg;
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK;
Expand Down
2 changes: 2 additions & 0 deletions H/YapFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ static inline Term gcTrace(void) {
return GLOBAL_Flags[GC_TRACE_FLAG].at;
}

Term Yap_UnknownFlag(Term mod);

bool rmdot(Term inp);

xarg *Yap_ArgListToVector(Term listl, const param_t *def, int n);
Expand Down
2 changes: 1 addition & 1 deletion H/Yapproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void Yap_InitQLYR(void);
void Yap_InitRange(void);

/* save.c */
int Yap_SavedInfo(char *, char *, CELL *, CELL *, CELL *);
int Yap_SavedInfo(const char *, char *, CELL *, CELL *, CELL *);
int Yap_SavedStateRestore(char *, char *);
FILE *Yap_OpenRestore(const char *, char *);
void Yap_InitSavePreds(void);
Expand Down
1 change: 1 addition & 0 deletions os/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Yap_GetCharForSIGINT(void)


void Yap_InitConsole(void) {
CACHE_REGS
LOCAL_newline = true;
Yap_InitCPred ("prompt", 1, prompt1, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("prompt1", 1, prompt1, SafePredFlag|SyncPredFlag);
Expand Down
5 changes: 5 additions & 0 deletions os/iopreds.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ FILE *Yap_stdout;
FILE *Yap_stderr;

static Term gethdir(Term t) {
CACHE_REGS
Atom aref = AtomOfTerm(t);
char *s = RepAtom(aref)->StrOfAE;
size_t nsz;
Expand Down Expand Up @@ -189,7 +190,9 @@ static bool is_file_errors(Term t) {
}

void Yap_DefaultStreamOps(StreamDesc *st) {
CACHE_REGS
st->stream_wputc = put_wchar;
st->stream_wgetc = get_wchar;
if (st->status & (Promptable_Stream_f)) {
st->stream_wgetc = get_wchar;
Yap_ConsoleOps(st, true);
Expand Down Expand Up @@ -265,6 +268,7 @@ static void unix_upd_stream_info(StreamDesc *s) {


static void InitFileIO(StreamDesc *s) {
CACHE_REGS
if (s->status & Socket_Stream_f) {
/* Console is a socket and socket will prompt */
Yap_ConsoleSocketOps(s);
Expand Down Expand Up @@ -1354,6 +1358,7 @@ int PlGetc(int sno) {
st->encoding = enc_id( s_encoding, st->encoding);
else
st->encoding = encoding;
Yap_DefaultStreamOps( st);
if (script)
open_header(sno, open_mode);

Expand Down
1 change: 1 addition & 0 deletions os/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ static bool getLine(int inp, int out) {
}

static int ReadlinePutc(int sno, int ch) {
CACHE_REGS
StreamDesc *s = &GLOBAL_Stream[sno];
#if MAC || _MSC_VER || defined(__MINGW32__)
if (ch == 10) {
Expand Down
Loading

0 comments on commit cb01e3e

Please sign in to comment.