* tests/base.scm: add two tests for issue #556
The two tests are adapted from issue #556 (originally from r7rs).
The tests currently fail because errors and raised objects are
treated in the same way.
* Use different tags for raised objects and raised errors
The behaviour for raising an error (error message irritants) and
objects (raise object) are different in r7rs. So tag error objects
differently, and adjust the raised object handling to handle
the raised object instead of a list containing the raised object.
This should resolve issue #556.
* runtime: use the correct string length for comparison
Fix for the pull request adressing issue #556.
* runtime: distinguish exceptions and errors in default handler
* repl: use error-object? to decide whether an error or an exception was raised
This makes error messages a bit more informative. Also, if error objects become
a distinct type, then the repl implementation will continue to be correct. The
(deleted) second cond clause seemed to be bit redundant - I am not sure what the
original intent was.
* tests/base.scm: revert accidental deletion of else clause
* Display exceptions as errors for consistency
* gc: add a function to force the collector to run
This requires adding a "forced" stage for the collector,
which is the initial stage for a forced collection.
Thereafter, the collector continues to the usual stages
of collection.
* runtime: force the garbage collector to run when a thread exits
This is a first attempt to improve the memory usage reported in
issue #534.
* srfi-18: call Cyc_end_thread on thread exits
This ensures that the collector has a chance to run whenever
a thread exits. Attempts to partially address issue #534.
* gc: free unused parts of the heap before merging
When a thread exits, the heap is merged into the main thread.
Before doing so, free any unused parts of the heap to reduce
memory usage. Attempts to partially address issue #534.
* srfi-18: thread-terminate! takes a thread as argument
* gc: revert adding STAGE_FORCING
Use gc_start_major_collection() instead. Partial work towards
addressing issue #534.
* gc: free empty pages in gc_heap_merge()
Moving the code from gc_merge_all_heaps to gc_heap_merge removes
special handling of the start of the list and is (hopefully)
easier to read.
Partial work towards addressing issue #534.
* gc: oops, forgot the "freed" count
Partial work towards addressing issue #534.
* gc: oops, forgot the "freed" count (again)
Partial work towards addressing issue #534.
* types: update forward declaration of gc_heap_merge()
Partial work towards addressing issue #534.
* gc: remove accidental double counting
* runtime: small (cosmetic) simplification
* srfi-18: add a slot for thread context in the thread object
Partial work towards addressing issue #534.
* srfi-18: do a minor gc when terminating a thread
This ensures that any objects which are part of the
thread context are transferred to the heap.
Partial work towards addressing issue #534.
* types.h: make gc_alloc_pair public
This will be used to create the thread context.
Partial work towards addressing issue #534.
* gc: prepare heap objects for sweeping
Also introduce a global variable to track whether merged
heaps need to be swept.
Partial work towards addressing issue #534.
* gc: create a context for terminated thread objects
The context ensures that parametrised objects, continuations
and exception handlers can still be traced but are no longer
root objects (after thread terminations) and can be GCd eventually.
Partial work towards addressing issue #534.
* gc: sweep and free empty heaps for the primordial thread
The primordial thread may not have an opportunity to sweep
heap pages which have been merged from terminated threads.
So sweep any unswept pages during the cooperation phase.
Partial work towards addressing issue #534.
* srfi-18: revert thread-terminate! changes
These changes need to be revisited, and are not suitable for
the threads garbage collection pull request.
* srfi-18: define all of the components of the *primordial-thread* thread object
* srfi-18: pthread-terminate! takes a thread object as argument
Handle this by checking if the argument is the primordial thread,
current thread or another thread.
The first two cases remain almost identical to the previous implementation.
To terminate a thread (which is not the caller) we use a pthread key
which contains the thread data. The destructor is set to Cyc_end_thread
and will terminate the thread when pthread_cancel is called. This ensures
that Cyc_end_thread is called with the correct thread data by the thread
which will be terminated.
* runtime: cast to the required type for pthread_key_create
* runtime: clear the thread_key before exiting the thread
* runtime: handle cancelled threads separately
We probably don't want to call pthread_exit in the destructor.
Similarly, we don't want to perform a longjmp (i.e. GC(...))
in the desctructor.
* runtime: do a minor GC for cancelled threads
The main idea is to avoid a longjmp and return to the destructor
for the cancelled thread. So, adjust GC and gc_minor to allow
for a NULL continuation.
This changes the behaviour to match r7rs (round x) instead of C round(x).
An answer to https://stackoverflow.com/questions/32746523/ieee-754-compliant-round-half-to-even
suggests using remainder(). The following will work if FE_TONEAREST is defined, but C11
requires FE_TONEAREST to be defined if and only if the implemenetation supports it in
fegetround() and fesetround() [Draft N1570]. On the other hand, remainder() must be defined.
C23 will have roundeven(), but this is not yet available on all platforms.
The behaviour of remainder is described in Draft N1570, page 254, footnote 239.
Alternative implementation:
double round_to_nearest_even(double x)
{
#pragma STDC FENV_ACCESS ON
int mode;
double nearest;
mode = fegetround();
fesetround(FE_TONEAREST);
nearest = nearbyint(x);
fesetround(mode);
#pragma STDC FENV_ACCESS OFF
return nearest;
}
Enforce a maximum C recursion depth when printing data structures. This protects against cases where a circular data structure may produce infinite output, blowing the stack. The recursive limit is sufficiently large such that a non-circular structure should not be impacted.
To fixes:
- Prevent segfault setting a global variable to itself
- Do not throw an error when exporting a primitive that is not defined in the current module, as built-ins are always available in any context.