Commit graph

588 commits

Author SHA1 Message Date
Justin Ethier
d42eb974ef Formatting 2025-01-20 18:58:17 -08:00
Justin Ethier
13dd25f01b Formatting 2025-01-20 18:57:17 -08:00
Justin Ethier
f59ce9999e Formatting 2025-01-20 18:57:04 -08:00
Justin Ethier
62250cf5d7 Run formatting job 2025-01-20 18:54:18 -08:00
yorickhardy
71e5aa2dd6
Improve garbage collection for terminated threads (#550)
* 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.
2025-01-20 21:10:49 -05:00
Yorick Hardy
4bbceeb4d6 round half-integers to even instead of away from zero
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;
  }
2024-02-01 22:25:47 +02:00
Justin Ethier
3b921e7389 Re-format code 2024-01-17 19:43:47 -08:00
Justin Ethier
abaed9f6f2 Issue #510 - Implement exact using runtime functions 2023-09-12 19:20:38 -07:00
Justin Ethier
7dc1f9e179 Issue #510 - Exact support for complex nums
Allow `exact` to properly handle complex numbers
2023-09-11 19:02:28 -07:00
Justin Ethier
e8ba3f1c1b Issue #510 - Exact conversion of large doubles
Allow `exact` to convert large double values to bignums.
2023-09-11 18:24:33 -07:00
Justin Ethier
f8fbb9ad7d WIP, fixing bugs with double ops
Allow round/ceil/floor/truncate to properly handle doubles.

Need to handle more edge cases with (exact).
2023-09-06 19:41:57 -07:00
Justin Ethier
cc5d1d5d65 WIP 2023-09-05 19:04:18 -07:00
Justin Ethier
ad1ac3a135 Issue #490 - Proper assv and memv implementations
Both were previously implemented in terms of `assq` and `memq`, respectively.
2022-07-24 10:56:41 -04:00
Justin Ethier
6ffd229dcd Add memory-streams to list of features 2022-05-28 08:21:11 -07:00
Justin Ethier
5101de1547 Issue #143 - Track recursion depth of equalp
This prevents the possibility of segfaulting when traversing arbitrarily complex circular structures.
2022-05-26 13:02:24 -04:00
Justin Ethier
bb861334f6 Simplify heap type definitions
This is the first step in making it easier to change the number and/or size of heap pages.
2021-08-17 15:03:53 -04:00
Justin Ethier
227861cb2e Use smaller datatype for ttl 2021-08-17 07:42:39 -04:00
Justin Ethier
f17102178b Continue building-out new numerator/denominator 2021-07-21 19:47:42 -07:00
Justin Ethier
d3ab710bb4 Issue #466 - Prevent compiler warnings regarding Cyc_st_add and string comparisons
Were seeing newer versions of clang spamming warnings due to how we were comparing strings here.
2021-07-16 13:02:50 -07:00
Justin Ethier
e21735512e Attempt to avoid compilation warnings on clang 2021-07-15 20:00:33 -07:00
Justin Ethier
358fe01fc2 Issue #211 - production version of (char-ready?) 2021-06-08 13:38:33 -04:00
Justin Ethier
100c9c50ab Fix primitive_type declarations so module compiles 2021-05-24 18:49:45 -07:00
Justin Ethier
6ac96ea5c2 Simplify num argument checks for apply
Avoid calling (length) twice, cleanup, and simplify related code.
2021-05-24 12:41:19 -04:00
Justin Ethier
8526a0676f Require num_args for primitive_type
This will allow us to use the same validation code as for closures.
2021-05-24 12:35:50 -04:00
Justin Ethier
a05959cb90 Converted primitive functions to new calling conventions 2021-05-22 19:45:52 -07:00
Justin Ethier
c44f7fcc0b WIP conversion 2021-05-20 19:58:14 -07:00
Justin Ethier
b8ed157105 Added init_polyfills() 2021-05-02 19:30:11 -07:00
Justin Ethier
81d9410395 Document macros, remove dead code 2021-04-06 19:51:45 -07:00
Justin Ethier
2c66875899 Update C macro docs 2021-04-06 19:01:37 -07:00
Justin Ethier
5c113c0303 Issu3 #421 - Add missing docs 2021-04-05 18:36:50 -04:00
Justin Ethier
6edbd8cd57 Prevent compilation warninG 2021-03-14 21:22:14 -04:00
Justin Ethier
b507485f55 Port dispatch_apply to new calling convention 2021-03-06 22:07:11 -05:00
Justin Ethier
d590904894 Porting function callling conventions 2021-02-26 22:31:02 -05:00
Justin Ethier
93310be845 Convert C function calls 2021-02-21 11:24:08 -05:00
Justin Ethier
d06dbcb64a Remove dispatch.c, port Cyc_apply 2021-02-21 10:53:16 -05:00
Justin Ethier
5ff682a592 Remove Cyc-list, seems unused 2021-02-19 10:19:32 -05:00
Justin Ethier
c839edb5e2 Cleanup, convert CPS function sigs 2021-02-18 22:59:03 -05:00
Justin Ethier
24bbc2e39d Converting function calls 2021-02-16 22:55:40 -05:00
Justin Ethier
d5ba874ae2 WIP, updating function calling conventions 2021-02-16 22:42:36 -05:00
Justin Ethier
2de1eb9e7f WIP, changing CPS calling conventions 2021-02-15 22:47:33 -05:00
Justin Ethier
496387293f Merge branch 'cargs-dev' into cargs2-dev 2021-02-15 21:21:15 -05:00
Justin Ethier
b6c2a353a8 Compilation fixes 2021-02-11 22:27:50 -05:00
Justin Ethier
c77cfcd6f7 unpack varargs 2021-02-10 22:28:21 -05:00
Justin Ethier
7974ce9da2 Issue #370 - add type checking for doubles 2021-01-30 17:43:38 -05:00
Justin Ethier
23249133af Added Cyc_check_argc macro to help w/new functions 2021-01-21 23:03:55 -05:00
Justin Ethier
d2b500278c Bug fixes 2021-01-07 10:10:25 -08:00
Justin Ethier
abe4e31d05 Added hashset_to_array 2021-01-06 19:58:25 -08:00
Justin Ethier
a5fb3b1b14 Allow (vector?) to recognize and disregard record types 2020-12-21 23:00:43 -05:00
Justin Ethier
c3075a6396 Added record_tag 2020-12-20 22:39:28 -05:00
Justin Ethier
937f6b61c2 Added ffi module 2020-08-14 14:37:19 -04:00