mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 02:27:10 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
55 lines
1.3 KiB
Ada
55 lines
1.3 KiB
Ada
with Ada.Unchecked_Deallocation;
|
|
|
|
package body Garbage_Collected is
|
|
|
|
procedure Free is new Ada.Unchecked_Deallocation (Class, Link);
|
|
|
|
Top : Link := null;
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
procedure Clean is
|
|
Current : Link := Top;
|
|
Previous : Link;
|
|
begin
|
|
while Current /= null and then not Current.all.Kept loop
|
|
Previous := Current;
|
|
Current := Current.all.Next;
|
|
Free (Previous);
|
|
end loop;
|
|
Top := Current;
|
|
while Current /= null loop
|
|
if Current.all.Kept then
|
|
Current.all.Kept := False;
|
|
Previous := Current;
|
|
else
|
|
Previous.all.Next := Current.all.Next;
|
|
Free (Current);
|
|
end if;
|
|
Current := Previous.all.Next;
|
|
end loop;
|
|
end Clean;
|
|
|
|
procedure Keep (Object : in out Class) is
|
|
begin
|
|
if not Object.Kept then
|
|
Object.Kept := True;
|
|
Object.Keep_References; -- dispatching
|
|
end if;
|
|
end Keep;
|
|
|
|
procedure Check_Allocations is
|
|
begin
|
|
pragma Assert (Top = null);
|
|
end Check_Allocations;
|
|
|
|
procedure Register (Ref : in Pointer) is
|
|
begin
|
|
pragma Assert (Ref.all.Kept = False);
|
|
pragma Assert (Ref.all.Next = null);
|
|
Ref.all.Next := Top;
|
|
Top := Ref;
|
|
end Register;
|
|
|
|
end Garbage_Collected;
|