AHelper, how are you planing to handle running the GC system. Will it be entirely random or will it be run automatically at times or what?
This will depend on how it runs. In interactive mode, it should run after evaluation. In bulk execution mode, it should run whenever low on resources.

Now, I could set object freeing to free up memory once all references on an object are cleared. However, by freeing later, I could utilize a system to remove duplicate objects (2+2+2 keeps duplicating '2' objects).

I realize I can't simply call the GC any time I want as unowned nodes created in function execution would be incorrectly freed. To be honest, right now, not 100% sure. I could abort the current expression being evaluated (given the source text is available), free it, run the GC, and try one more time. There really won't be a case where the textual form of the lisp expression isn't available any more.
Changed up ownership to a stricter reference counting system and I have no memory leaks (besides not being able to delete variables which I haven't found possible in Lisp so far). Deletion is performed upon freeing an object rather than waiting for a garbage collection pass. Below is a demo of print (multiargument print command), add (simple integer addition), setf (Similar to setq in Lisp), and mem (Gets RAM usage for global table and all objects, dumps the table showing reference counts as well as associated object).

Code:
==30191== Memcheck, a memory error detector
==30191== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30191== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==30191== Command: ./gcas3
==30191==
:print("Hello World!")
Hello World!
:print("Automatic symbol creation:",msg)
Automatic symbol creation: msg
:setf(msg,"Hello World!")
"Hello World!"
:print(msg)
Hello World!
:print("x=",x,"y=",y,"1+x+y=",add(1,x,y))
x= x y= y 1+x+y= add(1,x,y)
:setf(y,1)
1
:print("x=",x,"y=",y,"1+x+y=",add(1,x,y))
x= x y= 1 1+x+y= add(2,x)
:setf(y,x)
x
:print("x=",x,"y=",y,"1+x+y=",add(1,x,y))
x= x y= x 1+x+y= add(1,x,x)
:setf(x,2)
2
:print("x=",x,"y=",y,"1+x+y=",add(1,x,y))
x= 2 y= 2 1+x+y= 5
:mem()
--- Table ---
1       NUM
700
---
1       NUM
2
---
2       SYM     x
x
---
1       SYM     y
y
---
1       STR
"Hello World!"
---
1       SYM     msg
msg
---
255     SP      setf
<PRIM:setf>
---
255     SP      lambda
<PRIM:lambda>
---
255     PRIM    mem
<PRIM:mem>
---
255     PRIM    gc
<PRIM:gc>
---
255     PRIM    add
<PRIM:add>
---
255     PRIM    print
<PRIM:print>
---
255     SP      nil
<PRIM:nil>
---
---
700
:setf(y,nil)
:setf(msg,nil)
:mem()
--- Table ---
1       NUM
658
---
1       NUM
2
---
1       SYM     x
x
---
1       SYM     y
y
---
1       SYM     msg
msg
---
255     SP      setf
<PRIM:setf>
---
255     SP      lambda
<PRIM:lambda>
---
255     PRIM    mem
<PRIM:mem>
---
255     PRIM    gc
<PRIM:gc>
---
255     PRIM    add
<PRIM:add>
---
255     PRIM    print
<PRIM:print>
---
255     SP      nil
<PRIM:nil>
---
---
658
:setf(x,nil)
:print("A possible garbage collector/optimizer could be used\nto clean up defined symbols")
A possible garbage collector/optimizer could be used
to clean up defined symbols
:mem()
--- Table ---
1       NUM
601
---
1       SYM     x
x
---
1       SYM     y
y
---
1       SYM     msg
msg
---
255     SP      setf
<PRIM:setf>
---
255     SP      lambda
<PRIM:lambda>
---
255     PRIM    mem
<PRIM:mem>
---
255     PRIM    gc
<PRIM:gc>
---
255     PRIM    add
<PRIM:add>
---
255     PRIM    print
<PRIM:print>
---
255     SP      nil
<PRIM:nil>
---
---
601
:exit

Done
==30191==
==30191== HEAP SUMMARY:
==30191==     in use at exit: 0 bytes in 0 blocks
==30191==   total heap usage: 508 allocs, 508 frees, 10,689 bytes allocated
==30191==
==30191== All heap blocks were freed -- no leaks are possible
==30191==
==30191== For counts of detected and suppressed errors, rerun with: -v
==30191== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
setf polished some more and let has a basic implementation. Currently having problems with setf inside of let, such as let((a),setf(a,123),print(a)). This runs, but memory is not being free'd properly.
a) How are you avoiding/finding cycles?
b) Are you doing any sort of compaction?
a) What do you mean by cycles? Infinite loops? Nothing yet, will worry about that once a more complete set of operations is done. For thoughts on that right now, most likely I will monitor depth and limit it based on stack size (GlassOS is limited, Linux here is >8MB).
b) Compaction is planned in terms of combining duplicate nodes. This will most likely be done after string evaluation. There are still more optimizations that can be done, such as merging the globals table into individual nodes (globals table holds object pointer, ref. count, and name as a linked list. Merging would drop 1 pointer.) and specialized nodes (NUM objects have unused car and cdr pointers, cons has unused integer value, etc.).
No, I mean pointer cycles. You're doing garbage collection based on reference counting, but if you have a cycle of references that point to each other, but no longer have an active reference in user-accessible code, the whole cycle should be collected, but won't be in pure reference-counting scenario. This is how Firefox used to leak oodles of memory.
Work has begun again on a tiny BCD floating point number library in C that will be used for floats in lisp. I so far have addition and subtraction, will work on mult. and division soon.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement