From 2cf9902dfe8614a419cb7933cea02670764194cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 6 Jul 2015 11:53:50 +0100 Subject: [PATCH] module specific flags --- C/flags.c | 84 +++++++++++++++++++++++++++++++----------------- H/YapFlags.h | 10 ++++++ H/YapGFlagInfo.h | 14 +++++--- H/YapLFlagInfo.h | 16 +++++---- 4 files changed, 85 insertions(+), 39 deletions(-) diff --git a/C/flags.c b/C/flags.c index 7ebaf0332..88d79fe0e 100644 --- a/C/flags.c +++ b/C/flags.c @@ -592,25 +592,40 @@ static bool setYapFlagInModule( Term tflag, Term t2, Term mod ) } Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option for %s:character_escapes flag", RepAtom(AtomOfTerm(tflag))->StrOfAE); return false; - } else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) { - new->flags &= ~(DBLQ_CHARS|DBLQ_CODES|DBLQ_ATOM|DBLQ_STRING); - if (t2 == TermString) { - new->flags |= DBLQ_STRING; - return true; - } else if (t2 == TermAtom) { - new->flags |= DBLQ_ATOM; - return true; - } else if (t2 == TermCodes) { - new->flags |= DBLQ_CODES; - return true; - } else if (t2 == TermChars) { - new->flags |= DBLQ_CHARS; - return true; - } + } else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) { + new->flags &= ~(BCKQ_CHARS|BCKQ_CODES|BCKQ_ATOM|BCKQ_STRING); + if (t2 == TermString) { + new->flags |= BCKQ_STRING; + return true; + } else if (t2 == TermAtom) { + new->flags |= BCKQ_ATOM; + return true; + } else if (t2 == TermCodes) { + new->flags |= BCKQ_CODES; + return true; + } else if (t2 == TermChars) { + new->flags |= BCKQ_CHARS; + return true; + } + } else if (fv->FlagOfVE == DOUBLE_QUOTES_FLAG) { + new->flags &= ~(DBLQ_CHARS|DBLQ_CODES|DBLQ_ATOM|DBLQ_STRING); + if (t2 == TermString) { + new->flags |= DBLQ_STRING; + return true; + } else if (t2 == TermAtom) { + new->flags |= DBLQ_ATOM; + return true; + } else if (t2 == TermCodes) { + new->flags |= DBLQ_CODES; + return true; + } else if (t2 == TermChars) { + new->flags |= DBLQ_CHARS; + return true; + } Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option for %s:backquoted_string flag", RepAtom(AtomOfTerm(tflag))->StrOfAE); return false; } - Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "flag %s is not module-scoped", RepAtom(AtomOfTerm(tflag))->StrOfAE); +Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "flag %s is not module-scoped", RepAtom(AtomOfTerm(tflag))->StrOfAE); return FALSE; } @@ -637,15 +652,23 @@ static Term getYapFlagInModule( Term tflag, Term mod ) if (new->flags & M_CHARESCAPE) return TermTrue; } else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) { - if (new->flags & DBLQ_CHARS) - return TermChars; - if (new->flags & DBLQ_CODES) - return TermCodes; - if (new->flags & DBLQ_ATOM) - return TermAtom; - return TermString; - } - Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, tflag, "flag %s is not module-scoped", RepAtom(AtomOfTerm(tflag))->StrOfAE); + if (new->flags & BCKQ_CHARS) + return TermChars; + if (new->flags & BCKQ_CODES) + return TermCodes; + if (new->flags & BCKQ_ATOM) + return TermAtom; + return TermString; + } else if (fv->FlagOfVE == DOUBLE_QUOTES_FLAG) { + if (new->flags & DBLQ_CHARS) + return TermChars; + if (new->flags & DBLQ_CODES) + return TermCodes; + if (new->flags & DBLQ_ATOM) + return TermAtom; + return TermString; + } + Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, tflag, "flag %s is not module-scoped", RepAtom(AtomOfTerm(tflag))->StrOfAE); return 0L; } @@ -822,10 +845,10 @@ void Yap_setModuleFlags(ModEntry *new, ModEntry *cme) Atom at = new->AtomOfME; new->flags = 0; if (at == AtomProlog ) { - new->flags = UNKNOWN_FAIL | M_SYSTEM | M_CHARESCAPE; + new->flags = UNKNOWN_FAIL | M_SYSTEM | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING; return; } else if (cme == NULL) { - new->flags = UNKNOWN_ERROR | M_SYSTEM | M_CHARESCAPE; + new->flags = UNKNOWN_ERROR | M_SYSTEM | M_CHARESCAPE| DBLQ_CODES | BCKQ_STRING; return; } else new->flags = cme->flags; @@ -912,7 +935,8 @@ Term getYapFlag( Term tflag ) } else if (fl == TermWarning) { Yap_Warning("Flag ~s does not exist", RepAtom(AtomOfTerm(fl))->StrOfAE); } else { - Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, fl, "trying to read unknown flag"); + Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, fl, "trying to read unknown flag %s", + RepAtom(AtomOfTerm(fl))->StrOfAE); } return FALSE; } @@ -1348,7 +1372,8 @@ do_create_prolog_flag( USES_REGS1 ) void Yap_InitFlags( bool bootstrap) { CACHE_REGS - flag_info *f = + tr_fr_ptr tr0 = TR; + flag_info *f = global_flags_setup; GLOBAL_flagCount = 0; if (bootstrap) { @@ -1379,6 +1404,7 @@ Yap_InitFlags( bool bootstrap) { } if (!bootstrap) { Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag, cont_yap_flag, 0); + TR = tr0; /** @pred prolog_flag(? _Flag_,- _Value__) Obtain the value for a YAP Prolog flag, same as current_prolog_flag/2_. diff --git a/H/YapFlags.h b/H/YapFlags.h index 564d0fab5..4e6633f5d 100644 --- a/H/YapFlags.h +++ b/H/YapFlags.h @@ -68,6 +68,16 @@ INLINE_ONLY inline EXTERN bool ro( Term inp ) { return false; } + +INLINE_ONLY inline EXTERN bool aro( Term inp ) { + if (IsVarTerm(inp)) { + Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag in 0..."); + return false; + } + Yap_Error( PERMISSION_ERROR_READ_ONLY_FLAG, inp, "set_prolog_flag."); + return false; +} + //INLINE_ONLY inline EXTERN bool boolean( Term inp ); static inline bool boolean( Term inp ) { diff --git a/H/YapGFlagInfo.h b/H/YapGFlagInfo.h index 52bbae536..26b306193 100644 --- a/H/YapGFlagInfo.h +++ b/H/YapGFlagInfo.h @@ -73,7 +73,13 @@ running on an Apple machine. YAP_FLAG( ARCH_FLAG, "arch", false, isatom, YAP_ARCH , NULL ), YAP_FLAG( ARGV_FLAG, "argv", false, isatom, "[]" , argv ), YAP_FLAG( ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true, boolean, "true" , NULL ), -YAP_FLAG( BACKQUOTED_STRING_FLAG, "backquoted_string", true, isatom, "string" , ), +YAP_FLAG( BACKQUOTED_STRING_FLAG, "backquoted_string", true, isatom, "string" , ), /**> +If _Value_ is unbound, tell whether a double quoted list of characters +token is converted to a list of atoms, `chars`, to a list of integers, +`codes`, or to a single atom, `atom`. If _Value_ is bound, set to +the corresponding behavior. The default value is `string` +*/ + YAP_FLAG( BOUNDED_FLAG, "bounded", false, boolean, "false" , NULL ), /**< `bounded` is iso Read-only flag telling whether integers are bounded. The value depends @@ -114,7 +120,7 @@ it is bound to `false` disable debugging. debugger uses to write terms. If unbound, show the current options. */ YAP_FLAG( DEBUGGER_SHOW_CONTEXT_FLAG, "debugger_show_context", true, boolean, "false" , NULL ), -YAP_FLAG( DIALECT_FLAG, "dialect", true, ro, "yap" , NULL ), /**< `dialect ` +YAP_FLAG( DIALECT_FLAG, "dialect", false, ro, "yap" , NULL ), /**< `dialect ` Read-only flag that always returns `yap`. */ @@ -164,7 +170,7 @@ YAP_FLAG( GC_MARGIN_FLAG, "gc_margin", true, nat, "0" , gc_margin ), /**< `gc_m collection. The default depends on total stack size. */ -YAP_FLAG( GC_TRACE_FLAG, "gc_trace", true, boolean, "off" , NULL ), /**< `gc_trace ` +YAP_FLAG( GC_TRACE_FLAG, "gc_trace", true, isatom, "off" , NULL ), /**< `gc_trace ` If `off` (default) do not show information on garbage collection and stack shifts, if `on` inform when a garbage collection or stack @@ -340,7 +346,7 @@ YAP_FLAG( UNIX_FLAG, "unix", false, ro, "true" , NULL ), /**< `unix` running on an Unix system. Defined if the C-compiler used to compile this version of YAP either defines `__unix__` or `unix`. */ -YAP_FLAG( UPDATE_SEMANTICS_FLAG, "update_semantics", false, ro, "logical" , NULL ), /**< `update_semantics ` +YAP_FLAG( UPDATE_SEMANTICS_FLAG, "update_semantics", true, isatom, "logical" , NULL ), /**< `update_semantics ` Define whether YAP should follow `immediate` update semantics, as in C-Prolog (default), `logical` update semantics, diff --git a/H/YapLFlagInfo.h b/H/YapLFlagInfo.h index d9fc4416d..640a30a92 100644 --- a/H/YapLFlagInfo.h +++ b/H/YapLFlagInfo.h @@ -24,10 +24,14 @@ YAP_FLAG( AUTOLOAD_FLAG, "autoload", true, boolean, "false" , NULL ), YAP_FLAG( BREAK_LEVEL_FLAG, "break_level", true, nat, "0" , NULL ), YAP_FLAG( ENCODING_FLAG, "encoding", true, isatom, "text" , getenc ), YAP_FLAG( FILEERRORS_FLAG, "fileerrors", true, boolean, "true" , NULL ), /**< `fileerrors` - - If `on` `fileerrors` is `on`, if `off` (default) -`fileerrors` is disabled. - */ + + If `on` `fileerrors` is `on`, if `off` (default) + `fileerrors` is disabled. + */ +YAP_FLAG( LANGUAGE_MODE_FLAG, "language_mode", true, isatom, "yap" , NULL ), /**< `lamguage_mode` + + wweter native mode or trying to emulate a different Prolog. + */ YAP_FLAG( REDEFINE_WARNINGS_FLAG, "redefine_warnings", true, boolean, "true" , NULL ), /**< `redefine_warnings ` If _Value_ is unbound, tell whether warnings for procedures defined @@ -53,9 +57,9 @@ YAP_FLAG( SYNTAX_ERRORS_FLAG, "syntax_errors", true, isatom, "error" , synerr ) + `dec10` Report the syntax error and retry reading the term. + `fail` -Report the syntax error and fail (default). +Report the syntax error and fail. + `error` -Report the syntax error and generate an error. +Report the syntax error and generate an error (default). + `quiet` Just fail */