mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 23:07:36 +02:00
Refactoring
This commit is contained in:
parent
372a0a3fed
commit
3adf4d8d32
1 changed files with 26 additions and 68 deletions
90
runtime.c
90
runtime.c
|
@ -2452,20 +2452,9 @@ void gc_mark_globals()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) {
|
char *gc_fixup_moved_obj(gc_thread_data *thd, int *alloci, object hp)
|
||||||
if (!is_object_type(obj)) return obj;
|
{
|
||||||
|
// hp ==> new heap object, point to it from old stack object
|
||||||
|
|
||||||
// !!!
|
|
||||||
// TODO: clean up code below and consolidate with gc_copy_obj in gc.c:
|
|
||||||
// !!!
|
|
||||||
|
|
||||||
|
|
||||||
//gcMoveCountsDEBUG[type_of(obj)]++;
|
|
||||||
//printf("DEBUG gc_move type = %ld\n", type_of(obj)); // JAE DEBUG
|
|
||||||
switch(type_of(obj)){
|
|
||||||
case cons_tag: {
|
|
||||||
list hp = gc_alloc(Cyc_heap, sizeof(cons_type), obj, thd, heap_grown); // hp ==> new heap object
|
|
||||||
forward(obj) = hp;
|
forward(obj) = hp;
|
||||||
type_of(obj) = forward_tag;
|
type_of(obj) = forward_tag;
|
||||||
// keep track of each allocation so we can scan/move
|
// keep track of each allocation so we can scan/move
|
||||||
|
@ -2473,102 +2462,71 @@ char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) {
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) {
|
||||||
|
if (!is_object_type(obj)) return obj;
|
||||||
|
switch(type_of(obj)){
|
||||||
|
case cons_tag: {
|
||||||
|
list hp = gc_alloc(Cyc_heap, sizeof(cons_type), obj, thd, heap_grown);
|
||||||
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
|
}
|
||||||
case macro_tag: {
|
case macro_tag: {
|
||||||
macro_type *hp = gc_alloc(Cyc_heap, sizeof(macro_type), obj, thd, heap_grown);
|
macro_type *hp = gc_alloc(Cyc_heap, sizeof(macro_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closure0_tag: {
|
case closure0_tag: {
|
||||||
closure0_type *hp = gc_alloc(Cyc_heap, sizeof(closure0_type), obj, thd, heap_grown);
|
closure0_type *hp = gc_alloc(Cyc_heap, sizeof(closure0_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closure1_tag: {
|
case closure1_tag: {
|
||||||
closure1_type *hp = gc_alloc(Cyc_heap, sizeof(closure1_type), obj, thd, heap_grown);
|
closure1_type *hp = gc_alloc(Cyc_heap, sizeof(closure1_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closure2_tag: {
|
case closure2_tag: {
|
||||||
closure2_type *hp = gc_alloc(Cyc_heap, sizeof(closure2_type), obj, thd, heap_grown);
|
closure2_type *hp = gc_alloc(Cyc_heap, sizeof(closure2_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closure3_tag: {
|
case closure3_tag: {
|
||||||
closure3_type *hp = gc_alloc(Cyc_heap, sizeof(closure3_type), obj, thd, heap_grown);
|
closure3_type *hp = gc_alloc(Cyc_heap, sizeof(closure3_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closure4_tag: {
|
case closure4_tag: {
|
||||||
closure4_type *hp = gc_alloc(Cyc_heap, sizeof(closure4_type), obj, thd, heap_grown);
|
closure4_type *hp = gc_alloc(Cyc_heap, sizeof(closure4_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case closureN_tag: {
|
case closureN_tag: {
|
||||||
closureN_type *hp = gc_alloc(Cyc_heap,
|
closureN_type *hp = gc_alloc(Cyc_heap,
|
||||||
sizeof(closureN_type) + sizeof(object) * (((closureN) obj)->num_elt),
|
sizeof(closureN_type) + sizeof(object) * (((closureN) obj)->num_elt),
|
||||||
obj, thd, heap_grown);
|
obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case vector_tag: {
|
case vector_tag: {
|
||||||
vector_type *hp = gc_alloc(Cyc_heap,
|
vector_type *hp = gc_alloc(Cyc_heap,
|
||||||
sizeof(vector_type) + sizeof(object) * (((vector) obj)->num_elt),
|
sizeof(vector_type) + sizeof(object) * (((vector) obj)->num_elt),
|
||||||
obj, thd, heap_grown);
|
obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case string_tag: {
|
case string_tag: {
|
||||||
string_type *hp = gc_alloc(Cyc_heap,
|
string_type *hp = gc_alloc(Cyc_heap,
|
||||||
sizeof(string_type) + ((string_len(obj) + 1)),
|
sizeof(string_type) + ((string_len(obj) + 1)),
|
||||||
obj, thd, heap_grown);
|
obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case integer_tag: {
|
case integer_tag: {
|
||||||
integer_type *hp = gc_alloc(Cyc_heap, sizeof(integer_type), obj, thd, heap_grown);
|
integer_type *hp = gc_alloc(Cyc_heap, sizeof(integer_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case double_tag: {
|
case double_tag: {
|
||||||
double_type *hp = gc_alloc(Cyc_heap, sizeof(double_type), obj, thd, heap_grown);
|
double_type *hp = gc_alloc(Cyc_heap, sizeof(double_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case port_tag: {
|
case port_tag: {
|
||||||
port_type *hp = gc_alloc(Cyc_heap, sizeof(port_type), obj, thd, heap_grown);
|
port_type *hp = gc_alloc(Cyc_heap, sizeof(port_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case cvar_tag: {
|
case cvar_tag: {
|
||||||
cvar_type *hp = gc_alloc(Cyc_heap, sizeof(cvar_type), obj, thd, heap_grown);
|
cvar_type *hp = gc_alloc(Cyc_heap, sizeof(cvar_type), obj, thd, heap_grown);
|
||||||
forward(obj) = hp;
|
return gc_fixup_moved_obj(thd, alloci, hp);
|
||||||
type_of(obj) = forward_tag;
|
|
||||||
gc_thr_add_to_move_buffer(thd, alloci, hp);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
}
|
||||||
case forward_tag:
|
case forward_tag:
|
||||||
return (char *)forward(obj);
|
return (char *)forward(obj);
|
||||||
|
|
Loading…
Add table
Reference in a new issue