But all Lisps I've seen have garbage collectors. If I could find a Lisp with manual memory management, I could ditch C++ in favor of that Lisp. Is there one?
But all Lisps I've seen have garbage collectors. If I could find a Lisp with manual memory management, I could ditch C++ in favor of that Lisp. Is there one?
(defvar *heap* (make-array 1024 :element-type '(unsigned-byte 8)))
which is just a 1k bag of bytes. Then write some functions to allocate from it, keep track of it, etc. A typical Common Lisp implementation will make a "specialized array" when it does this - that is, the array is not filled with a bunch of pointers to individually-allocated bytes.There are other ways you could do it - for example (I don't know if this would be efficient):
(defvar *heap* (make-array 0 :element-type '(vector (unsigned-byte 8))
:adjustable t :fill-pointer t))
(defun malloc (bytes)
(let ((result (make-array bytes :element-type '(unsigned-byte 8))))
(vector-push-extend result *heap*)
result))
and there are ways you can write a FREE function to release these allocations or mark them for re-use.These methods would not really release memory back to the OS. However, C malloc and free typically do not really free memory back to the OS either. You can easily do something in Common Lisp that's on equal footing with C in that regard.
Edi Weitz in "Common Lisp Recipes" points out that when you're doing something like this you're "pooling" memory, and in effect you're replacing automatic memory management with your own hand-rolled memory manager, and chances are it's not going to be as good as an automatic memory manager. But certainly it's doable.
Any by a "compiler" I'm talking doing something simply like taking Pascal, converting it to an s-expr grammar, and going to town.
Scheme can be a simple algol style language. Using s-expr syntax just made your lexer/parser much simpler. And (simple) compilation is really not that hard (just compile it to C for your first crack if you want).
I bet you could get quite far quite quickly.
If it doesn't exist, you could try modifying one of the listed implementations.