mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-15 19:28:47 +00:00
Cyclic equal (alpha)
This commit is contained in:
parent
c73f43e817
commit
c29ab4901f
13 changed files with 402 additions and 18 deletions
|
|
@ -43,4 +43,8 @@ F,s__Infix_42;
|
|||
F,s__Infix_47;
|
||||
F,s__Infix_37;
|
||||
L,"++",T,"+";
|
||||
|
||||
F,enableGC;
|
||||
F,disableGC;
|
||||
F,random;
|
||||
F,time;
|
||||
F,rawTag;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ __gc_stack_top: .long 0
|
|||
|
||||
.globl __pre_gc
|
||||
.globl __post_gc
|
||||
.globl L__gc_init
|
||||
.globl __gc_init
|
||||
.globl __gc_root_scan_stack
|
||||
.globl __gc_stack_top
|
||||
.globl __gc_stack_bottom
|
||||
|
|
@ -17,9 +17,9 @@ __gc_stack_top: .long 0
|
|||
.extern gc_test_and_copy_root
|
||||
.text
|
||||
|
||||
L__gc_init: movl %ebp, __gc_stack_bottom
|
||||
__gc_init: movl %ebp, __gc_stack_bottom
|
||||
addl $4, __gc_stack_bottom
|
||||
call init_pool
|
||||
call __init
|
||||
ret
|
||||
|
||||
// if __gc_stack_top is equal to 0
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
# include <assert.h>
|
||||
# include <errno.h>
|
||||
# include <regex.h>
|
||||
# include <time.h>
|
||||
# include <limits.h>
|
||||
|
||||
# define __ENABLE_GC__
|
||||
|
|
@ -172,6 +173,13 @@ extern void* Bsexp (int n, ...);
|
|||
|
||||
void *global_sysargs;
|
||||
|
||||
// Gets a raw tag
|
||||
extern int LrawTag (void *p) {
|
||||
ASSERT_UNBOXED ("rawTag, 0", p);
|
||||
|
||||
return TAG(TO_DATA(p)->tag);
|
||||
}
|
||||
|
||||
// Functional synonym for built-in operator ":";
|
||||
void* Ls__Infix_58 (void *p, void *q) {
|
||||
void *res;
|
||||
|
|
@ -1374,6 +1382,24 @@ extern int Lwrite (int n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern int Lrandom (int n) {
|
||||
ASSERT_UNBOXED("Lrandom, 0", n);
|
||||
|
||||
if (UNBOX(n) <= 0) {
|
||||
failure ("invalid range in random: %d\n", UNBOX(n));
|
||||
}
|
||||
|
||||
return BOX (random () % UNBOX(n));
|
||||
}
|
||||
|
||||
extern int Ltime () {
|
||||
struct timespec t;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC_RAW, &t);
|
||||
|
||||
return BOX(t.tv_sec * 1000000 + t.tv_nsec / 1000);
|
||||
}
|
||||
|
||||
extern void set_args (int argc, char *argv[]) {
|
||||
data *a;
|
||||
int n = argc, *p = NULL;
|
||||
|
|
@ -1418,15 +1444,25 @@ extern void set_args (int argc, char *argv[]) {
|
|||
|
||||
/* GC starts here */
|
||||
|
||||
static int enable_GC = 1;
|
||||
|
||||
extern void LenableGC () {
|
||||
enable_GC = 1;
|
||||
}
|
||||
|
||||
extern void LdisableGC () {
|
||||
enable_GC = 0;
|
||||
}
|
||||
|
||||
extern const size_t __start_custom_data, __stop_custom_data;
|
||||
|
||||
# ifdef __ENABLE_GC__
|
||||
|
||||
extern void L__gc_init ();
|
||||
extern void __gc_init ();
|
||||
|
||||
# else
|
||||
|
||||
# define L__gc_init __gc_init_subst
|
||||
# define __gc_init __gc_init_subst
|
||||
void __gc_init_subst () {}
|
||||
|
||||
# endif
|
||||
|
|
@ -1737,8 +1773,11 @@ static inline void init_extra_roots (void) {
|
|||
extra_roots.current_free = 0;
|
||||
}
|
||||
|
||||
extern void init_pool (void) {
|
||||
extern void __init (void) {
|
||||
size_t space_size = SPACE_SIZE * sizeof(size_t);
|
||||
|
||||
srandom (time (NULL));
|
||||
|
||||
from_space.begin = mmap (NULL, space_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
|
||||
to_space.begin = NULL;
|
||||
|
|
@ -1756,6 +1795,10 @@ extern void init_pool (void) {
|
|||
}
|
||||
|
||||
static void* gc (size_t size) {
|
||||
if (! enable_GC) {
|
||||
Lfailure ("GC disabled");
|
||||
}
|
||||
|
||||
current = to_space.begin;
|
||||
#ifdef DEBUG_PRINT
|
||||
print_indent ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue