|
|
@@ -100,6 +100,20 @@ namespace Slime::Memory { |
|
|
proc free_everything() -> void { |
|
|
proc free_everything() -> void { |
|
|
object_memory.for_each([](Lisp_Object* lo){ |
|
|
object_memory.for_each([](Lisp_Object* lo){ |
|
|
switch (lo->type) { |
|
|
switch (lo->type) { |
|
|
|
|
|
case Lisp_Object_Type::Continuation: { |
|
|
|
|
|
lo->value.continuation->cs.dealloc(); |
|
|
|
|
|
lo->value.continuation->pcs.dealloc(); |
|
|
|
|
|
lo->value.continuation->ams.dealloc(); |
|
|
|
|
|
lo->value.continuation->ats.dealloc(); |
|
|
|
|
|
lo->value.continuation->mes.dealloc(); |
|
|
|
|
|
lo->value.continuation->envi_stack.dealloc(); |
|
|
|
|
|
for (auto it : lo->value.continuation->nass) { |
|
|
|
|
|
it.dealloc(); |
|
|
|
|
|
} |
|
|
|
|
|
lo->value.continuation->nass.dealloc(); |
|
|
|
|
|
free(lo->value.continuation); |
|
|
|
|
|
|
|
|
|
|
|
} break; |
|
|
case Lisp_Object_Type::Function: { |
|
|
case Lisp_Object_Type::Function: { |
|
|
lo->value.function->args.positional.symbols.dealloc(); |
|
|
lo->value.function->args.positional.symbols.dealloc(); |
|
|
lo->value.function->args.keyword.keywords.dealloc(); |
|
|
lo->value.function->args.keyword.keywords.dealloc(); |
|
|
@@ -140,6 +154,9 @@ namespace Slime::Memory { |
|
|
Globals::Current_Execution.ams.dealloc(); |
|
|
Globals::Current_Execution.ams.dealloc(); |
|
|
Globals::Current_Execution.pcs.dealloc(); |
|
|
Globals::Current_Execution.pcs.dealloc(); |
|
|
Globals::Current_Execution.nass.dealloc(); |
|
|
Globals::Current_Execution.nass.dealloc(); |
|
|
|
|
|
for (auto it: Globals::Current_Execution.nass) { |
|
|
|
|
|
it.dealloc(); |
|
|
|
|
|
} |
|
|
Globals::Current_Execution.ats.dealloc(); |
|
|
Globals::Current_Execution.ats.dealloc(); |
|
|
Globals::Current_Execution.mes.dealloc(); |
|
|
Globals::Current_Execution.mes.dealloc(); |
|
|
|
|
|
|
|
|
@@ -278,24 +295,28 @@ namespace Slime::Memory { |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline proc full_clone_continuation(Continuation* c) -> Continuation* { |
|
|
|
|
|
Continuation* res = (Continuation*)malloc(sizeof(Continuation)); |
|
|
|
|
|
res->cs = c->cs.clone(); |
|
|
|
|
|
res->pcs = c->pcs.clone(); |
|
|
|
|
|
res->ams = c->ams.clone(); |
|
|
|
|
|
res->ats = c->ats.clone(); |
|
|
|
|
|
res->mes = c->mes.clone(); |
|
|
|
|
|
res->envi_stack = c->envi_stack.clone(); |
|
|
|
|
|
res->nass = c->nass.clone(); |
|
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < res->nass.next_index; ++i) { |
|
|
|
|
|
res->nass.data[i] = c->nass.data[i].clone(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
proc create_lisp_object_continuation() -> Lisp_Object* { |
|
|
proc create_lisp_object_continuation() -> Lisp_Object* { |
|
|
using Globals::Current_Execution; |
|
|
|
|
|
Lisp_Object* node; |
|
|
Lisp_Object* node; |
|
|
try node = create_lisp_object(); |
|
|
try node = create_lisp_object(); |
|
|
node->type = Lisp_Object_Type::Continuation; |
|
|
node->type = Lisp_Object_Type::Continuation; |
|
|
node->value.continuation = (Continuation*)malloc(sizeof(Continuation)); |
|
|
|
|
|
node->value.continuation->cs = Current_Execution.cs.clone(); |
|
|
|
|
|
node->value.continuation->pcs = Current_Execution.pcs.clone(); |
|
|
|
|
|
node->value.continuation->ams = Current_Execution.ams.clone(); |
|
|
|
|
|
node->value.continuation->ats = Current_Execution.ats.clone(); |
|
|
|
|
|
node->value.continuation->mes = Current_Execution.mes.clone(); |
|
|
|
|
|
node->value.continuation->envi_stack = Current_Execution.envi_stack.clone(); |
|
|
|
|
|
|
|
|
|
|
|
node->value.continuation->nass = Current_Execution.nass.clone(); |
|
|
|
|
|
for (u32 i = 0; i < node->value.continuation->nass.next_index; ++i) { |
|
|
|
|
|
node->value.continuation->nass.data[i] = node->value.continuation->nass.data[i].clone(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
node->value.continuation = full_clone_continuation(&Globals::Current_Execution); |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -454,25 +475,32 @@ namespace Slime::Memory { |
|
|
if (n == Memory::nil || n == Memory::t) { |
|
|
if (n == Memory::nil || n == Memory::t) { |
|
|
return n; |
|
|
return n; |
|
|
} else { |
|
|
} else { |
|
|
Lisp_Object_Type type = n->type; |
|
|
|
|
|
if (type == Lisp_Object_Type::Symbol || |
|
|
|
|
|
type == Lisp_Object_Type::Keyword || |
|
|
|
|
|
type == Lisp_Object_Type::Function) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
switch(n->type) { |
|
|
|
|
|
case Lisp_Object_Type::Symbol: |
|
|
|
|
|
case Lisp_Object_Type::Keyword: |
|
|
|
|
|
case Lisp_Object_Type::Function: |
|
|
return n; |
|
|
return n; |
|
|
} else if (type == Lisp_Object_Type::String) { |
|
|
|
|
|
|
|
|
case Lisp_Object_Type::String: { |
|
|
Lisp_Object* target; |
|
|
Lisp_Object* target; |
|
|
try target = create_lisp_object(); |
|
|
try target = create_lisp_object(); |
|
|
*target = *n; |
|
|
*target = *n; |
|
|
target->value.string = create_string(target->value.string.data); |
|
|
target->value.string = create_string(target->value.string.data); |
|
|
return target; |
|
|
return target; |
|
|
} else { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
case Lisp_Object_Type::Continuation: |
|
|
|
|
|
Lisp_Object* target; |
|
|
|
|
|
try target = create_lisp_object(); |
|
|
|
|
|
*target = *n; |
|
|
|
|
|
target->value.continuation = full_clone_continuation(n->value.continuation); |
|
|
|
|
|
return target; |
|
|
|
|
|
default: { |
|
|
Lisp_Object* target; |
|
|
Lisp_Object* target; |
|
|
try target = create_lisp_object(); |
|
|
try target = create_lisp_object(); |
|
|
*target = *n; |
|
|
*target = *n; |
|
|
|
|
|
|
|
|
return target; |
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|