From 7037b38fa7d2c26a371877770ffcf81e107f3b42 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sun, 28 Feb 2010 00:57:29 +0000 Subject: [PATCH] make nb_ undefined variable return an error, as SWI does. --- C/errors.c | 15 +++++++++++++++ C/globals.c | 16 ++++++++++++---- H/Yap.h | 1 + pl/boot.yap | 2 ++ pl/messages.yap | 2 ++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/C/errors.c b/C/errors.c index bf4c34857..3d6c857bb 100644 --- a/C/errors.c +++ b/C/errors.c @@ -902,6 +902,21 @@ Yap_Error(yap_error_number type, Term where, char *format,...) serious = TRUE; } break; + case EXISTENCE_ERROR_VARIABLE: + { + int i; + Term ti[2]; + + i = strlen(tmpbuf); + ti[0] = MkAtomTerm(AtomVariable); + ti[1] = where; + nt[0] = Yap_MkApplTerm(FunctorExistenceError, 2, ti); + tp = tmpbuf+i; + psize -= i; + fun = FunctorError; + serious = TRUE; + } + break; case EVALUATION_ERROR_FLOAT_OVERFLOW: { int i; diff --git a/C/globals.c b/C/globals.c index f1c79ccdc..cefa30833 100644 --- a/C/globals.c +++ b/C/globals.c @@ -1285,8 +1285,10 @@ p_nb_getval(void) return FALSE; } ge = FindGlobalEntry(AtomOfTerm(t)); - if (!ge) + if (!ge) { + Yap_Error(EXISTENCE_ERROR_VARIABLE,t,"nb_getval"); return FALSE; + } READ_LOCK(ge->GRWLock); to = ge->global; if (IsVarTerm(to) && IsUnboundVar(VarOfTerm(to))) { @@ -1309,8 +1311,10 @@ nbdelete(Atom at) Prop gp, g0; ge = FindGlobalEntry(at); - if (!ge) + if (!ge) { + Yap_Error(EXISTENCE_ERROR_VARIABLE,MkAtomTerm(at),"nb_delete"); return FALSE; + } WRITE_LOCK(ge->GRWLock); ae = ge->AtomOfGE; if (GlobalVariables == ge) { @@ -1375,8 +1379,10 @@ p_nb_create(void) return FALSE; } ge = GetGlobalEntry(AtomOfTerm(t)); - if (!ge) + if (!ge) { + Yap_Error(EXISTENCE_ERROR_VARIABLE,t,"nb_create"); return FALSE; + } if (IsVarTerm(tarity)) { Yap_Error(INSTANTIATION_ERROR,tarity,"nb_create"); return FALSE; @@ -1418,8 +1424,10 @@ p_nb_create2(void) return FALSE; } ge = GetGlobalEntry(AtomOfTerm(t)); - if (!ge) + if (!ge) { + Yap_Error(EXISTENCE_ERROR_VARIABLE,t,"nb_create"); return FALSE; + } if (IsVarTerm(tarity)) { Yap_Error(INSTANTIATION_ERROR,tarity,"nb_create"); return FALSE; diff --git a/H/Yap.h b/H/Yap.h index c3d104992..f8870dd2d 100644 --- a/H/Yap.h +++ b/H/Yap.h @@ -464,6 +464,7 @@ typedef enum EXISTENCE_ERROR_KEY, EXISTENCE_ERROR_SOURCE_SINK, EXISTENCE_ERROR_STREAM, + EXISTENCE_ERROR_VARIABLE, INSTANTIATION_ERROR, INTERRUPT_ERROR, OPERATING_SYSTEM_ERROR, diff --git a/pl/boot.yap b/pl/boot.yap index d805300d1..74e78bc8c 100755 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -75,6 +75,8 @@ true :- true. nb_setval('$open_expands_filename',true), '$debug_on'(false), nb_setval('$trace',off), + nb_setval('$assert_all',off), + nb_setval('$if_skip_mode',no_skip), b_setval('$spy_glist',[]), % simple trick to find out if this is we are booting from Prolog. get_value('$user_module',V), diff --git a/pl/messages.yap b/pl/messages.yap index 6024d6dee..85fd9df4a 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -166,6 +166,8 @@ system_message(error(existence_error(key,Key), Where)) --> [ 'EXISTENCE ERROR- ~w: ~w not an existing key' - [Where,Key] ]. system_message(error(existence_error(thread,Thread), Where)) --> [ 'EXISTENCE ERROR- ~w: ~w not a running thread' - [Where,Thread] ]. +system_message(error(existence_error(variable,Var), Where)) --> + [ 'EXISTENCE ERROR- ~w: variable ~w does not exist' - [Where,Var] ]. system_message(error(existence_error(Name,F), W)) --> { object_name(Name, ObjName) }, [ 'EXISTENCE ERROR- ~w could not open ~a ~w' - [W,ObjName,F] ].