I've been able to create a basic like language without local variables support. I understand that I cant return a address to a local variable specifically a string or a struct. What are my options, can you give an example?

Posted on 2005-11-22 18:18:33 by Re_Boot
Do you have string types? If so, how do you handle string assignment and string concatenation?
Posted on 2005-11-22 20:03:30 by tenkey
currently Im using a null terminated string ie: mystring db "hello world",0
or mystring db 11 dup(0),0 depending on wether Im defining a buffer initialized with a value or zerofilled

as far as string concatenation, hasnt been dealt with yet. I have it being parsed but no really functionality other than a block of memory, static.
Until I have local variables handled I figured Id add functionality later.
Posted on 2005-11-22 22:43:55 by Re_Boot
Here is the reason I asked about strings.

If you had handled strings using homebrew "heap" storage, the answer would be to use the strings as is.

If you want to return the address of a string, the string data must not be in stack (local) storage. Local string variables would actually be implemented as local string pointer variables, and you let your language hide that fact.
Posted on 2005-11-24 01:45:34 by tenkey
yeah, kinda thought you were going there. I have several books on compiler design, but nothing clearly describes how to implement a heap manager or implemnting one. This is ultimately what Id like, to be able to use stackframes for locals, and ptrs to a heap. Any idea on how to implement say a mark and sweep GC. Or, any links on the subject?
Posted on 2005-11-24 04:10:47 by Re_Boot
For string storage, most people want a compactor for the memory block you are using as the storage "pool". You can, of course, "cheat" and use the Windows CString/BSTR interfaces to handle the string management for you.

If you are compacting, you can either use mark and sweep, copy collection, reference counting, or you can compact using sorted string addresses. You need to know where all of the string addresses are. If you like, you can check address ranges so that you do not copy constant strings.

If you don't mind the extra overhead, you can use double indirection to simplify compaction. The variables point to the string addresses, so that the compactor can change string addresses without changing the values stored in variables. If you don't like double indirection, you'll need a way to know where all the string variables are.

Unfortunately, I don't have any links that show memory management schemes for strings. There are many solutions. It's basically keeping track of what string memory is still available, and discovering what data is no longer in use (and therefore is contained in recoverable memory). The various solutions optimize the storage, allocation, or collection in different ways.

Here are some links for general purpose GC...

If you are interested in books, Garbage Collection by Jones & Lin is very comprehensive.
Posted on 2005-11-25 01:26:06 by tenkey