mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-16 19:58:46 +00:00
cur
This commit is contained in:
parent
985ad50813
commit
94327b7921
2 changed files with 196 additions and 26 deletions
|
|
@ -7,19 +7,127 @@ printf_format5: .string "LOL\n"
|
||||||
__gc_stack_bottom: .long 0
|
__gc_stack_bottom: .long 0
|
||||||
__gc_stack_top: .long 0
|
__gc_stack_top: .long 0
|
||||||
|
|
||||||
|
.globl __set_w2
|
||||||
|
.globl __alloc_w1
|
||||||
|
.globl __alloc_w2
|
||||||
.globl __pre_gc
|
.globl __pre_gc
|
||||||
.globl L__gc_init
|
.globl L__gc_init
|
||||||
.globl __gc_root_scan_stack
|
.globl __gc_root_scan_stack
|
||||||
.extern init_pool
|
.extern init_pool
|
||||||
.extern __gc_test_and_copy_root
|
.extern __gc_test_and_copy_root
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
__set_w2:
|
||||||
|
pushl %ebp
|
||||||
|
movl %esp, %ebp
|
||||||
|
pushl %ecx
|
||||||
|
pushl %edx
|
||||||
|
|
||||||
|
movl 8(%ebp), %ecx
|
||||||
|
movl 12(%ebp), %edx
|
||||||
|
subl $8, %ecx
|
||||||
|
movl %edx, (%ecx)
|
||||||
|
|
||||||
|
movl $0, %eax
|
||||||
|
pushl %ecx
|
||||||
|
pushl %edx
|
||||||
|
|
||||||
|
movl %ebp, %esp
|
||||||
|
popl %ebp
|
||||||
|
ret
|
||||||
|
|
||||||
|
__alloc_w2:
|
||||||
|
pushl %ebp
|
||||||
|
movl %esp, %ebp
|
||||||
|
pushl %ebx
|
||||||
|
pushl %ecx
|
||||||
|
pushl %edx
|
||||||
|
pushl %esi
|
||||||
|
pushl %edi
|
||||||
|
|
||||||
|
movl 8(%ebp), %edx
|
||||||
|
|
||||||
|
pushl %edx
|
||||||
|
call alloc
|
||||||
|
addl $4, %esp
|
||||||
|
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
addl $20, %esp
|
||||||
|
|
||||||
|
movl 12(%ebp), %ecx
|
||||||
|
addl $4, %eax
|
||||||
|
movl %ecx, (%eax)
|
||||||
|
addl $4, %eax
|
||||||
|
|
||||||
|
popl %ebx
|
||||||
|
popl %ecx
|
||||||
|
popl %edx
|
||||||
|
popl %esi
|
||||||
|
popl %edi
|
||||||
|
|
||||||
|
movl %ebp, %esp
|
||||||
|
popl %ebp
|
||||||
|
ret
|
||||||
|
|
||||||
|
__alloc_w1:
|
||||||
|
pushl %ebp
|
||||||
|
movl %esp, %ebp
|
||||||
|
pushl %ebx
|
||||||
|
pushl %ecx
|
||||||
|
pushl %edx
|
||||||
|
pushl %esi
|
||||||
|
pushl %edi
|
||||||
|
|
||||||
|
movl 4(%ebp), %edx
|
||||||
|
|
||||||
|
pushl %edx
|
||||||
|
call alloc
|
||||||
|
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
pushl $1
|
||||||
|
addl $20, %esp
|
||||||
|
|
||||||
|
movl 8(%ebp), %ecx
|
||||||
|
movl %ecx, (%eax)
|
||||||
|
addl $4, %eax
|
||||||
|
|
||||||
|
popl %ebx
|
||||||
|
popl %ecx
|
||||||
|
popl %edx
|
||||||
|
popl %esi
|
||||||
|
popl %edi
|
||||||
|
|
||||||
|
movl %ebp, %esp
|
||||||
|
popl %ebp
|
||||||
|
ret
|
||||||
|
|
||||||
L__gc_init: movl %esp, __gc_stack_bottom
|
L__gc_init: movl %esp, __gc_stack_bottom
|
||||||
addl $4, __gc_stack_bottom
|
addl $4, __gc_stack_bottom
|
||||||
call init_pool
|
call init_pool
|
||||||
ret
|
ret
|
||||||
|
|
||||||
__pre_gc:
|
__pre_gc:
|
||||||
movl %ebp, __gc_stack_top
|
// movl %ebp, __gc_stack_top
|
||||||
|
// ret
|
||||||
|
|
||||||
|
// pushl %eax
|
||||||
|
// movl (%ebp), %eax
|
||||||
|
// movl %eax, __gc_stack_top
|
||||||
|
// popl %eax
|
||||||
|
|
||||||
|
pushl %eax
|
||||||
|
movl (%ebp), %eax
|
||||||
|
addl $4, %eax
|
||||||
|
movl %eax, __gc_stack_top
|
||||||
|
popl %eax
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
__gc_root_scan_stack:
|
__gc_root_scan_stack:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
# include <assert.h>
|
# include <assert.h>
|
||||||
|
|
||||||
// # define DEBUG_PRINT 1
|
# define DEBUG_PRINT 1
|
||||||
|
|
||||||
# define STRING_TAG 0x00000001
|
# define STRING_TAG 0x00000001
|
||||||
# define ARRAY_TAG 0x00000003
|
# define ARRAY_TAG 0x00000003
|
||||||
|
|
@ -34,17 +34,20 @@ typedef struct {
|
||||||
data contents;
|
data contents;
|
||||||
} sexp;
|
} sexp;
|
||||||
|
|
||||||
static void* alloc (size_t);
|
extern void* alloc (size_t);
|
||||||
|
|
||||||
extern int Blength (void *p) {
|
extern int Blength (void *p) {
|
||||||
data *a = TO_DATA(p);
|
data *a = (char*) BOX (NULL);
|
||||||
|
a = TO_DATA(p);
|
||||||
return BOX(LEN(a->tag));
|
return BOX(LEN(a->tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
char* de_hash (int n) {
|
char* de_hash (int n) {
|
||||||
static char *chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNJPQRSTUVWXYZ";
|
static char *chars = (char*) BOX (NULL);
|
||||||
static char buf[6];
|
static char buf[6] = {0,0,0,0,0,0};
|
||||||
char *p = &buf[5];
|
char *p = (char*) BOX (NULL);
|
||||||
|
chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNJPQRSTUVWXYZ";
|
||||||
|
p = &buf[5];
|
||||||
|
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
printf ("de_hash: tag: %d\n", n);
|
printf ("de_hash: tag: %d\n", n);
|
||||||
|
|
@ -161,10 +164,21 @@ extern void* Belem (void *p, int i) {
|
||||||
return (void*) ((int*) a->contents)[i];
|
return (void*) ((int*) a->contents)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern void* __alloc_w1 (size_t size, int tag);
|
||||||
|
extern void* __alloc_w2 (size_t size, int tag);
|
||||||
|
extern void* __set_w2 (void *p , int tag);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern void* Bstring (void *p) {
|
extern void* Bstring (void *p) {
|
||||||
int n = BOX(0);
|
int n = BOX(0);
|
||||||
data *r = NULL;
|
data *r = NULL;
|
||||||
|
|
||||||
|
__pre_gc () ;
|
||||||
|
|
||||||
n = strlen (p);
|
n = strlen (p);
|
||||||
r = (data*) alloc (n + 1 + sizeof (int));
|
r = (data*) alloc (n + 1 + sizeof (int));
|
||||||
|
|
||||||
|
|
@ -173,6 +187,19 @@ extern void* Bstring (void *p) {
|
||||||
|
|
||||||
return r->contents;
|
return r->contents;
|
||||||
}
|
}
|
||||||
|
/* extern void* Bstring (void *p) { */
|
||||||
|
/* int n = BOX(0); */
|
||||||
|
/* void *r = NULL; */
|
||||||
|
|
||||||
|
/* printf ("BSTRING!\n"); */
|
||||||
|
|
||||||
|
/* n = strlen (p); */
|
||||||
|
/* r = __alloc_w1 (n + 1 + sizeof (int), STRING_TAG | (n << 3)); */
|
||||||
|
|
||||||
|
/* strncpy (r, p, n + 1); */
|
||||||
|
|
||||||
|
/* return r; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
extern void* Bstringval (void *p) {
|
extern void* Bstringval (void *p) {
|
||||||
void *s = BOX(NULL);
|
void *s = BOX(NULL);
|
||||||
|
|
@ -192,6 +219,9 @@ extern void* Barray (int n, ...) {
|
||||||
int i = BOX(0),
|
int i = BOX(0),
|
||||||
ai = BOX(0);
|
ai = BOX(0);
|
||||||
data *r = (data*) BOX (NULL);
|
data *r = (data*) BOX (NULL);
|
||||||
|
|
||||||
|
__pre_gc () ;
|
||||||
|
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
printf ("Barray: create n = %d\n", n);
|
printf ("Barray: create n = %d\n", n);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
@ -212,32 +242,62 @@ extern void* Barray (int n, ...) {
|
||||||
return r->contents;
|
return r->contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* extern void* Bsexp (int n, ...) { */
|
||||||
|
/* va_list args = (va_list) BOX (NULL); */
|
||||||
|
/* int i = BOX(0); */
|
||||||
|
/* int ai = BOX(0); */
|
||||||
|
/* sexp *r = (sexp*) BOX (NULL); */
|
||||||
|
/* data *d = (sexp*) BOX (NULL); */
|
||||||
|
|
||||||
|
/* __pre_gc () ; */
|
||||||
|
|
||||||
|
/* #ifdef DEBUG_PRINT */
|
||||||
|
/* printf("Bsexp: allocate %zu!\n",sizeof(int) * (n+1)); */
|
||||||
|
/* #endif */
|
||||||
|
/* r = (sexp*) alloc (sizeof(int) * (n+1)); */
|
||||||
|
/* d = &(r->contents); */
|
||||||
|
|
||||||
|
/* d->tag = SEXP_TAG | ((n-1) << 3); */
|
||||||
|
|
||||||
|
/* va_start(args, n); */
|
||||||
|
|
||||||
|
/* for (i=0; i<n-1; i++) { */
|
||||||
|
/* ai = va_arg(args, int); */
|
||||||
|
/* ((int*)d->contents)[i] = ai; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* r->tag = va_arg(args, int); */
|
||||||
|
/* va_end(args); */
|
||||||
|
|
||||||
|
/* return d->contents; */
|
||||||
|
/* } */
|
||||||
extern void* Bsexp (int n, ...) {
|
extern void* Bsexp (int n, ...) {
|
||||||
va_list args = (va_list) BOX (NULL);
|
va_list args = (va_list) BOX (NULL);
|
||||||
int i = BOX(0);
|
int i = BOX(0);
|
||||||
int ai = BOX(0);
|
int ai = BOX(0), tag = BOX(0);
|
||||||
sexp *r = (sexp*) BOX (NULL);
|
void *r = (void*) BOX (NULL);
|
||||||
data *d = (sexp*) BOX (NULL);
|
size_t size = sizeof(int) * (n+1);
|
||||||
|
// printf("Bsexp: allocate %zu!\n", size);
|
||||||
|
|
||||||
#ifdef DEBUG_PRINT
|
__pre_gc ();
|
||||||
printf("Bsexp: allocate %zu!\n",sizeof(int) * (n+1));
|
|
||||||
#endif
|
tag = SEXP_TAG | ((n-1) << 3);
|
||||||
r = (sexp*) alloc (sizeof(int) * (n+1));
|
r = __alloc_w2 (size, tag);
|
||||||
d = &(r->contents);
|
// Lwrite(r);
|
||||||
|
// d = &(r->contents);
|
||||||
d->tag = SEXP_TAG | ((n-1) << 3);
|
// d->tag = SEXP_TAG | ((n-1) << 3);
|
||||||
|
|
||||||
va_start(args, n);
|
va_start(args, n);
|
||||||
|
|
||||||
for (i=0; i<n-1; i++) {
|
for (i = 0; i < n-1; i++) {
|
||||||
ai = va_arg(args, int);
|
ai = va_arg(args, int);
|
||||||
((int*)d->contents)[i] = ai;
|
((int*)r)[i] = ai;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->tag = va_arg(args, int);
|
__set_w2 (r, va_arg(args, int));
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return d->contents;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int Btag (void *d, int t, int n) {
|
extern int Btag (void *d, int t, int n) {
|
||||||
|
|
@ -333,6 +393,8 @@ extern void* Lstrcat (void *a, void *b) {
|
||||||
da = TO_DATA(a);
|
da = TO_DATA(a);
|
||||||
db = TO_DATA(b);
|
db = TO_DATA(b);
|
||||||
|
|
||||||
|
__pre_gc () ;
|
||||||
|
|
||||||
d = (data *) alloc (sizeof(int) + LEN(da->tag) + LEN(db->tag) + 1);
|
d = (data *) alloc (sizeof(int) + LEN(da->tag) + LEN(db->tag) + 1);
|
||||||
|
|
||||||
d->tag = LEN(da->tag) + LEN(db->tag);
|
d->tag = LEN(da->tag) + LEN(db->tag);
|
||||||
|
|
@ -550,7 +612,7 @@ extern size_t * gc_copy (size_t *obj) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IN_PASSIVE_SPACE(current)) {
|
if (!IN_PASSIVE_SPACE(current) && current != to_space.end) {
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
printf("ERROR: gc_copy: out-of-space %x %x %x\n", current, to_space.begin, to_space.end);
|
printf("ERROR: gc_copy: out-of-space %x %x %x\n", current, to_space.begin, to_space.end);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
@ -705,11 +767,11 @@ static void * gc (size_t size) {
|
||||||
|
|
||||||
__gc_swap_spaces ();
|
__gc_swap_spaces ();
|
||||||
from_space.current = current + size;
|
from_space.current = current + size;
|
||||||
return current;
|
return (void *) current;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * alloc (size_t size) {
|
extern void * alloc (size_t size) {
|
||||||
void * p = BOX(NULL);
|
void * p = (void*)BOX(NULL);
|
||||||
if (from_space.current + size < from_space.end) {
|
if (from_space.current + size < from_space.end) {
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
printf("alloc: current: %x %zu", from_space.current, size);
|
printf("alloc: current: %x %zu", from_space.current, size);
|
||||||
|
|
@ -724,6 +786,6 @@ static void * alloc (size_t size) {
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
printf("alloc: call gc: %zu\n", size);
|
printf("alloc: call gc: %zu\n", size);
|
||||||
#endif
|
#endif
|
||||||
__pre_gc () ;
|
// __pre_gc () ;
|
||||||
return gc (size);
|
return gc (size);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue