From a79644ec43363206844f51e25706a7522ac889b3 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Sun, 16 Mar 2025 11:09:50 +0300 Subject: [PATCH] [TMP] run mods --- Lama.opam | 2 +- performance/{dune => _dune} | 0 runtime/gc.c | 7 ++++- runtime/gc.h | 2 +- runtime/runtime.c | 53 +++++++++++++++++++++++++++++++++++++ runtime32/{dune => _dune} | 0 6 files changed, 61 insertions(+), 3 deletions(-) rename performance/{dune => _dune} (100%) rename runtime32/{dune => _dune} (100%) diff --git a/Lama.opam b/Lama.opam index f0852421d..2de3a899a 100644 --- a/Lama.opam +++ b/Lama.opam @@ -8,7 +8,7 @@ license: "GPL-3.0-only" homepage: "https://github.com/PLTools/Lama" bug-reports: "https://github.com/PLTools/Lama/issues" depends: [ - "dune" {>= "3.3"} + "dune" {>= "3.11"} "posix-uname" "GT" "ostap" {>= "0.6"} diff --git a/performance/dune b/performance/_dune similarity index 100% rename from performance/dune rename to performance/_dune diff --git a/runtime/gc.c b/runtime/gc.c index 15159bd3c..4695896e5 100644 --- a/runtime/gc.c +++ b/runtime/gc.c @@ -56,6 +56,8 @@ void handler (int sig) { } void *alloc (size_t size) { + // return malloc(size); + // FIXME, disable gc #ifdef DEBUG_VERSION ++cur_id; #endif @@ -247,6 +249,7 @@ static void gc_root_scan_stack () { } void mark_phase (void) { + // FIXME, disable gc #if defined(DEBUG_VERSION) && defined(DEBUG_PRINT) fprintf(stderr, "marking has started\n"); fprintf(stderr, @@ -620,7 +623,8 @@ extern void __shutdown (void) { void clear_extra_roots (void) { extra_roots.current_free = 0; } void push_extra_root (void **p) { - if (extra_roots.current_free >= MAX_EXTRA_ROOTS_NUMBER) { + // FIXME, disable gc + if (extra_roots.current_free > MAX_EXTRA_ROOTS_NUMBER) { perror("ERROR: push_extra_roots: extra_roots_pool overflow\n"); exit(1); } @@ -630,6 +634,7 @@ void push_extra_root (void **p) { } void pop_extra_root (void **p) { + // FIXME, disable gc if (extra_roots.current_free == 0) { perror("ERROR: pop_extra_root: extra_roots are empty\n"); exit(1); diff --git a/runtime/gc.h b/runtime/gc.h index 2cf7131d6..54fc148e9 100644 --- a/runtime/gc.h +++ b/runtime/gc.h @@ -37,7 +37,7 @@ #define SET_FORWARD_ADDRESS(x, addr) (x = ((x & 3) | ((ptrt)(addr)))) // if heap is full after gc shows in how many times it has to be extended #define EXTRA_ROOM_HEAP_COEFFICIENT 2 -#define MINIMUM_HEAP_CAPACITY (64) +#define MINIMUM_HEAP_CAPACITY (64000000) #include #include diff --git a/runtime/runtime.c b/runtime/runtime.c index 9134853f8..8abfddf6d 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -845,6 +845,30 @@ extern void *Barray (aint* args, aint bn) { return r->contents; } +extern void *Barray_rev (aint* args, aint bn) { + data *r; + aint n = UNBOX(bn); + + PRE_GC(); + + for (aint i = 0; i < n; i++) { + push_extra_root((void**)&args[i]); + } + + r = (data *)alloc_array(n); + + for (int i = 0; i < n; i++) { + ((aint *)r->contents)[i] = args[n - i - 1]; + } + + for (aint i = n - 1; i >= 0; --i) { + pop_extra_root((void**)&args[i]); + } + + POST_GC(); + return r->contents; +} + #ifdef DEBUG_VERSION extern memory_chunk heap; #endif @@ -878,6 +902,35 @@ extern void *Bsexp (aint* args, aint bn) { return (void *)((data *)r)->contents; } +extern void *Bsexp_rev (aint* args, aint bn) { + sexp *r; + aint n = UNBOX(bn); + + PRE_GC(); + + aint fields_cnt = n - 1; + + for (aint i = 0; i < fields_cnt; i++) { + push_extra_root((void**)&args[i]); + } + + r = alloc_sexp(fields_cnt); + r->tag = 0; + + for (int i = 0; i < fields_cnt; i++) { + ((auint *)r->contents)[i] = args[fields_cnt - i]; + } + + r->tag = UNBOX(args[0]); + + for (aint i = fields_cnt - 1; i >= 0; --i) { + pop_extra_root((void**)&args[i]); + } + + POST_GC(); + return (void *)((data *)r)->contents; +} + extern aint Btag (void *d, aint t, aint n) { data *r; diff --git a/runtime32/dune b/runtime32/_dune similarity index 100% rename from runtime32/dune rename to runtime32/_dune