diff --git a/C/heapgc.c b/C/heapgc.c index 15fb10ffc..c3585f093 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -35,7 +35,7 @@ static #endif unsigned int gc_calls = 0; /* number of times GC has been called */ -static CELL tot_gc_time = 0; /* total time spent in GC */ +static Int tot_gc_time = 0; /* total time spent in GC */ /* in a single gc */ UInt total_marked; /* number of heap objects marked */ @@ -2600,7 +2600,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop) } #endif #ifdef DEBUG - // check_global(); + check_global(); #endif if (GetValue(AtomGcTrace) != TermNil) gc_trace = 1; @@ -2672,14 +2672,14 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop) } gc_time += (c_time-time_start); tot_gc_time += gc_time; - tot_gc_recovered += (H-H0)-total_marked; + tot_gc_recovered += heap_cells-total_marked; if (gc_verbose) { YP_fprintf(YP_stderr, "[GC] GC %d took %g sec, total of %g sec doing GC so far.\n", gc_calls, (double)gc_time/1000, (double)tot_gc_time/1000); YP_fprintf(YP_stderr, "[GC] Left %ld cells free in stacks.\n", (unsigned long int)(ASP-H)); } #ifdef DEBUG - // check_global(); + check_global(); #endif return(effectiveness); } @@ -2706,8 +2706,8 @@ static Int p_inform_gc(void) { Term tn = MkIntegerTerm(tot_gc_time); - Term tt = MkIntTerm(gc_calls); - Term ts = MkIntTerm((total_marked*sizeof(CELL))); + Term tt = MkIntegerTerm(gc_calls); + Term ts = MkIntegerTerm((tot_gc_recovered*sizeof(CELL))); return(unify(tn, ARG2) && unify(tt, ARG1) && unify(ts, ARG3)); @@ -2757,7 +2757,7 @@ gc(Int predarity, CELL *current_env, yamop *nextop) while (gc_margin >= gap && !growstack(gc_margin)) gc_margin = gc_margin/2; #ifdef DEBUG - // check_global(); + check_global(); #endif return(gc_margin >= gap); } diff --git a/C/sysbits.c b/C/sysbits.c index b5b5f40de..e16d9be77 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1871,6 +1871,33 @@ static Int p_putenv(void) #endif } +/* set a variable in YAP's environment */ +static Int p_file_age(void) +{ +#if HAVE_LSTAT + struct stat buf; + char *file_name = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE; + + if (lstat(file_name, &buf) == -1) { + /* file does not exist, but was opened? Return -1 */ + return(unify(ARG2, MkIntTerm(-1))); + } + return(unify(ARG2, MkIntegerTerm(buf.st_mtime))); +#elif defined(__MINGW32__) || _MSC_VER + /* for some weird reason _stat did not work with mingw32 */ + struct _stat buf; + char *file_name = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE; + + if (_stat(file_name, &buf) != 0) { + /* return an error number */ + return(unify(ARG2, MkIntTerm(-1))); + } + return(unify(ARG2, MkIntegerTerm(buf.st_mtime))); +#else + return(unify(ARG2, MkIntTerm(0))); +#endif +} + /* wrapper for alarm system call */ #if defined(_WIN32) static VOID CALLBACK HandleTimer(LPVOID v, DWORD d1, DWORD d2) { @@ -1998,6 +2025,7 @@ InitSysPreds(void) InitCPred ("$alarm", 2, p_alarm, SafePredFlag|SyncPredFlag); InitCPred ("$getenv", 2, p_getenv, SafePredFlag); InitCPred ("$putenv", 2, p_putenv, SafePredFlag|SyncPredFlag); + InitCPred ("$file_age", 2, p_file_age, SafePredFlag|SyncPredFlag); } diff --git a/C/write.c b/C/write.c index 671ffe8db..8ecc16cfa 100644 --- a/C/write.c +++ b/C/write.c @@ -123,7 +123,7 @@ wrputf(Float f) /* writes a float */ wrputc(' '); } lastw = alphanum; - sprintf(s, "%.6g", f); + sprintf(s, "%.15g", f); while (*pt == ' ') pt++; if (*pt == 'i' || *pt == 'n') /* inf or nan */ diff --git a/TO_DO b/TO_DO index 3bb0a6a92..caf8936ad 100644 --- a/TO_DO +++ b/TO_DO @@ -3,12 +3,9 @@ BEFORE 4.4: - write infinite terms - constraints in DB. - non-void temporaries going to global -- timestamps on files. - warnings in documentation file. - fix restore when code is moved around. - document new interface functions. -- add more precision when outputting floats. -- make statistics/0 better looking. - mask when installing. TO CHECK: @@ -82,6 +79,9 @@ DONE: - ^C can break code. - system library - library(system) for WIN32 +- timestamps on files. +- add more precision when outputting floats. +- make statistics/0 better looking. TO DO (tabling) - make gc work after mutable var changes. diff --git a/changes4.3.html b/changes4.3.html index d818aaadb..b241437e2 100644 --- a/changes4.3.html +++ b/changes4.3.html @@ -16,6 +16,10 @@

Yap-4.3.19: