-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opaque types #70
Comments
I'm not familiar with the concept of opaque types. I'll have to read up about it. What are they useful for? |
Oops, sorry about that. I meant to write that but I never finished my sentence. The idea is that if you have some objects that aren't primitive values, but it wouldn't make sense to have them available in a context-manager |
Combined with #71, I think I figured it out -- the only time that memory needs to be freed is when a garbage collection occurs. So here is my solution: Each extension could keep references to all its opaque pointers, and designate a garbage collector hook function ( |
OK, so I think I get it. Opaque types are a way of having Lisp objects that point to memory that's not in Lisp's workspace. For example, you might want to write a Lisp extension that has Lisp symbols that point to C structs.
Couldn't it still use Lisp's garbage collector to decide whether the object is accessible, and then call a garbage collector hook function to actually reclaim the storage, such as with free if it was allocated with malloc. |
Well, C++ complicates this in its use of I think it would best be left up to extension authors to deal with this by sweeping their own arrays, marking their own objects, etc. p.s. in Lisp contexts is it more appropriate to mark code using |
I've seen both used. I always use bold for in-line Lisp words because I think monospaced text looks ugly in the middle of a sentence in a proportional font. |
To be realistic, I don't think I'm going to get around to implementing opaque types - I think they go a bit beyond what I'm intending for uLisp - but if you decide to have a go at implementing them on your fork of uLisp I'd be very interested to see how they work and try them out. |
I think the new streams idea and opaque objects are very similar in some respects, so I'll hold off on trying opaque objects until I see your new streams version. |
I had another idea: user-definable opaque types. You could add a
void*
pointer to the car and cdr of the object union, and then have a variableOpaqueCounter
which is the highest registered opaque type which must be less than the start of the workspace to avoid confusing it with a cons cell.You would have to fix the markobject routine so it wouldn't start marking wild pointers into out-of-workspace memory -- a simple fix would be to, before marking or recursing on a pointer, check to see if
(obj >= &Workspace[0] && object <= &Workspace[WORKSPACESIZE-1])
. That way, the opaque type could use Lisp lists/trees to store garbage-collected variable-size data structures.The idea of this is that you could implement a
I probably haven't thought of the rest of it (edits to the printobject() routine, etc) or how to display a pretty name for the type, but I am open to suggestions.
The one big problem with this is I can't figure out a simple API for how an extension should be notified when an opaque object is garbage collected and the external memory should be freed, to avoid memory leaks. You could just put a big warning that your program needs to keep its own references and free them later somehow, or allocate objects statically or on the stack, but that doesn't sit quite right with me.
The text was updated successfully, but these errors were encountered: