win version was broken because wchar_t is unsigned in WIN32.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2070 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
c567a5aeb1
commit
4a07cd99a5
@ -12,7 +12,7 @@
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: allocating space *
|
||||
* version:$Id: alloc.c,v 1.88 2008-01-23 18:25:19 vsc Exp $ *
|
||||
* version:$Id: alloc.c,v 1.89 2008-01-28 23:35:03 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
@ -752,7 +752,7 @@ InitWorkSpace(Int s)
|
||||
|
||||
GetSystemInfo(&si);
|
||||
Yap_page_size = si.dwPageSize;
|
||||
s = ((s+ (ALLOC_SIZE-1))/ALLOC_SIZE)*ALLOC_SIZE;
|
||||
s = ((s+ (YAP_ALLOC_SIZE-1))/YAP_ALLOC_SIZE)*YAP_ALLOC_SIZE;
|
||||
brk = (LPVOID)Yap_page_size;
|
||||
if (!ExtendWorkSpace(s,0))
|
||||
return FALSE;
|
||||
|
13
C/iopreds.c
13
C/iopreds.c
@ -691,12 +691,6 @@ Yap_DebugPutc(int sno, wchar_t ch)
|
||||
return (putc(ch, Yap_stderr));
|
||||
}
|
||||
|
||||
void
|
||||
Yap_DebugPlWrite(Term t)
|
||||
{
|
||||
Yap_plwrite(t, Yap_DebugPutc, 0);
|
||||
}
|
||||
|
||||
void
|
||||
Yap_DebugErrorPutc(int c)
|
||||
{
|
||||
@ -1423,12 +1417,13 @@ ConsolePipeGetc(int sno)
|
||||
static int
|
||||
PlGetc (int sno)
|
||||
{
|
||||
register StreamDesc *s = &Stream[sno];
|
||||
register Int ch;
|
||||
StreamDesc *s = &Stream[sno];
|
||||
Int ch;
|
||||
|
||||
ch = YP_getc (s->u.file.file);
|
||||
if (ch == EOF)
|
||||
if (ch == EOF) {
|
||||
return post_process_eof(s);
|
||||
}
|
||||
return post_process_read_char(ch, s);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ typedef struct FREEB {
|
||||
#if _WIN32
|
||||
/* in WIN32 VirtualAlloc works in multiples of 64K */
|
||||
#define YAP_ALLOC_SIZE (64*1024)
|
||||
#define LG_PAGE_SIZE ALLOC_SIZE
|
||||
#define LGPAGE_SIZE YAP_ALLOC_SIZE
|
||||
|
||||
#else
|
||||
#define YAP_ALLOC_SIZE Yap_page_size
|
||||
|
@ -264,10 +264,10 @@ typedef enum {
|
||||
#define NUMBER_OF_CHARS 256
|
||||
extern char *Yap_chtype;
|
||||
|
||||
EXTERN inline int STD_PROTO(chtype,(wchar_t));
|
||||
EXTERN inline int STD_PROTO(chtype,(int));
|
||||
|
||||
EXTERN inline int
|
||||
chtype(wchar_t ch)
|
||||
chtype(int ch)
|
||||
{
|
||||
if (ch < 256)
|
||||
return Yap_chtype[ch];
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
<h2>Yap-5.1.3:</h2>
|
||||
<ul>
|
||||
<li> FIXED: always remember wchar_t is unsigned in WIN32.</li>
|
||||
<li> FIXED: more BOM trouble (obs from P Moura).</li>
|
||||
<li> FIXED: testing for BOM forced incorrect execution of gets (obs
|
||||
from A N Saravanaraj), also fixed stup call to Ungetc in getc and
|
||||
|
@ -130,7 +130,7 @@ mygetc (void)
|
||||
{
|
||||
int ch;
|
||||
if (eof_found)
|
||||
return (EOF);
|
||||
return EOF;
|
||||
ch = getc (bootfile);
|
||||
if (ch == EOF)
|
||||
eof_found = TRUE;
|
||||
@ -140,7 +140,7 @@ mygetc (void)
|
||||
#endif
|
||||
yap_lineno++;
|
||||
}
|
||||
return (ch);
|
||||
return ch;
|
||||
}
|
||||
|
||||
static void
|
||||
|
157
docs/yap.tex
157
docs/yap.tex
@ -6306,6 +6306,162 @@ Unify the current value of mutable term @var{M} with term @var{D}.
|
||||
Set the current value of mutable term @var{M} to term @var{D}.
|
||||
@end table
|
||||
|
||||
<<<<<<< yap.tex
|
||||
@node Global Variables, Profiling, Profiling, Term Modification, Top
|
||||
@section Global Variables
|
||||
|
||||
@cindex global variables
|
||||
|
||||
Global variables are associations between names (atoms) and
|
||||
terms. They differ in various ways from storing information using
|
||||
@node{assert/1} or @node{recorda/3}.
|
||||
|
||||
@itemize @bullet
|
||||
@item The value lives on the Prolog (global) stack. This implies that
|
||||
lookup time is independent from the size of the term. This is
|
||||
particularly interesting for large data structures such as parsed XML
|
||||
documents or the CHR global constraint store.
|
||||
|
||||
@item They support both global assignment using nb_setval/2 and
|
||||
backtrackable assignment using b_setval/2.
|
||||
|
||||
@item Only one value (which can be an arbitrary complex Prolog term) can be associated to a variable at a time.
|
||||
|
||||
@item Their value cannot be shared among threads. Each thread has its own
|
||||
namespace and values for global variables.
|
||||
@end itemize
|
||||
|
||||
Currently global variables are scoped globally. We may consider module
|
||||
scoping in future versions. Both @code{b_setval/2} and
|
||||
@code{nb_setval/2} implicitly create a variable if the referenced name
|
||||
does not already refer to a variable.
|
||||
|
||||
Global variables may be initialised from directives to make them
|
||||
available during the program lifetime, but some considerations are
|
||||
necessary for saved-states and threads. Saved-states to not store
|
||||
global variables, which implies they have to be declared with
|
||||
@code{initialization/1} to recreate them after loading the saved
|
||||
state. Each thread has its own set of global variables, starting with
|
||||
an empty set. Using @code{thread_initialization/1} to define a global
|
||||
variable it will be defined, restored after reloading a saved state
|
||||
and created in all threads that are created after the
|
||||
registration. Finally, global variables can be initialised using the
|
||||
exception hook called @code{exception/3}. The latter technique is by
|
||||
CHR.
|
||||
|
||||
@table @code
|
||||
@item b_setval(+@var{Name}, +@var{Value})
|
||||
@findex b_setval/2
|
||||
@snindex b_setval/2
|
||||
@cnindex b_setval/2
|
||||
Associate the term @var{Value} with the atom @var{Name} or replaces
|
||||
the currently associated value with @var{Value}. If @var{Name} does
|
||||
not refer to an existing global variable a variable with initial value
|
||||
[] is created (the empty list). On backtracking the assignment is
|
||||
reversed.
|
||||
|
||||
@item b_getval(+@var{Name}, -@var{Value})
|
||||
@findex b_getval/2
|
||||
@snindex b_getval/2
|
||||
@cnindex b_getval/2
|
||||
Get the value associated with the global variable @var{Name} and unify
|
||||
it with @var{Value}. Note that this unification may further
|
||||
instantiate the value of the global variable. If this is undesirable
|
||||
the normal precautions (double negation or @var{copy_term/2}) must be
|
||||
taken. The @var{b_getval/2} predicate generates errors if @var{Name} is not
|
||||
an atom or the requested variable does not exist.
|
||||
|
||||
@item nb_setval(+@var{Name}, +@var{Value})
|
||||
@findex nb_setval/2
|
||||
@snindex nb_setval/2
|
||||
@cnindex nb_setval/2
|
||||
Associates a copy of @var{Value} created with @var{duplicate_term/2} with
|
||||
the atom @var{Name}. Note that this can be used to set an initial
|
||||
value other than @code{[]} prior to backtrackable assignment.
|
||||
|
||||
@item nb_getval(+@var{Name}, -@var{Value})
|
||||
@findex nb_getval/2
|
||||
@snindex nb_getval/2
|
||||
@cnindex nb_getval/2
|
||||
The @code{nb_getval/2} predicate is a synonym for @code{b_getval/2},
|
||||
introduced for compatibility and symmetry. As most scenarios will use
|
||||
a particular global variable either using non-backtracable or
|
||||
backtrackable assignment, using @code{nb_getval/2} can be used to
|
||||
document that the variable is used non-backtracable.
|
||||
|
||||
@item nb_linkval(+@var{Name}, +@var{Value})
|
||||
@findex nb_linkval/2
|
||||
@snindex nb_linkval/2
|
||||
@cnindex nb_linkval/2
|
||||
Associates the term @var{Value} with the atom @var{Name} without
|
||||
copying it. This is a fast special-purpose variation of @code{nb_setval/2}
|
||||
intended for expert users only because the semantics on backtracking
|
||||
to a point before creating the link are poorly defined for compound
|
||||
terms. The principal term is always left untouched, but backtracking
|
||||
behaviour on arguments is undone if the original assignment was
|
||||
trailed and left alone otherwise, which implies that the history that
|
||||
created the term affects the behaviour on backtracking. Please
|
||||
consider the following example:
|
||||
|
||||
@example
|
||||
demo_nb_linkval :-
|
||||
T = nice(N),
|
||||
( N = world,
|
||||
nb_linkval(myvar, T),
|
||||
fail
|
||||
; nb_getval(myvar, V),
|
||||
writeln(V)
|
||||
).
|
||||
@end example
|
||||
|
||||
@item nb_set_shared_val(+@var{Name}, +@var{Value})
|
||||
@findex nb_set_shared_val/2
|
||||
@snindex nb_set_shared_val/2
|
||||
@cnindex nb_set_shared_val/2
|
||||
Associates the term @var{Value} with the atom @var{Name}, but sharing
|
||||
non-backtrackable terms. This may be useful if you want to rewrite a
|
||||
global variable so that the new copy will survive backtracking, but
|
||||
you want to share structure with the previous term.
|
||||
|
||||
The next example shows the differences between the three built-ins:
|
||||
@example
|
||||
demo_nb_linkval :-
|
||||
T = nice(N),
|
||||
( N = world,
|
||||
nb_linkval(myvar, T),
|
||||
fail
|
||||
; nb_getval(myvar, V),
|
||||
writeln(V)
|
||||
).
|
||||
@end example
|
||||
|
||||
|
||||
@item nb_current(?@var{Name}, ?@var{Value})
|
||||
@findex nb_current/2
|
||||
@snindex nb_current/2
|
||||
@cnindex nb_current/2
|
||||
Enumerate all defined variables with their value. The order of
|
||||
enumeration is undefined.
|
||||
|
||||
@item nb_delete(+@var{Name})
|
||||
@findex nb_delete/2
|
||||
@snindex nb_delete/2
|
||||
@cnindex nb_delete/2
|
||||
Delete the named global variable.
|
||||
@end table
|
||||
|
||||
Global variables have been introduced by various Prolog
|
||||
implementations recently. We follow the implementation of them in
|
||||
SWI-Prolog, itself based on hProlog by Bart Demoen.
|
||||
|
||||
GNU-Prolog provides a rich set of global variables, including
|
||||
arrays. Arrays can be implemented easily in YAP and SWI-Prolog using
|
||||
@code{functor/3} and @code{setarg/3} due to the unrestricted arity of
|
||||
compound terms.
|
||||
|
||||
|
||||
@node Profiling, Call Counting, Global Variables, Top
|
||||
=======
|
||||
@node Global Variables, Profiling, Term Modification, Top
|
||||
@section Global Variables
|
||||
|
||||
@ -6511,6 +6667,7 @@ compound terms.
|
||||
|
||||
|
||||
@node Profiling, Call Counting, Global Variables, Top
|
||||
>>>>>>> 1.222
|
||||
@section Profiling Prolog Programs
|
||||
|
||||
@cindex profiling
|
||||
|
Reference in New Issue
Block a user