types and operators

Nathan Hawkins utsl@one.net
Mon, 29 Apr 1996 05:39:50 -0400 (EDT)


A revised version of this:

Types:

1. integer
2. character
3. pointer
4. double-integer
5. float (optional)

Now I would say that characters and double-integers don't need to be very 
strongly distinguished from integers, except that characters and integers 
do bring up a few portability issues. I _would_ like to deal with this 
sort of portability problem, since it isn't that hard or costly to deal 
with, and would help with distributed objects, anyway.

I propose to distinguish pointers and integers (all three kinds), on the 
stack in in memory by the top or bottom two bits. We can simply shift these 
bits away, and mask them off for pointers.
Pointers should probably always be dword aligned, so two bits will not 
lose any address space for us. Strings will need special handling, 
anyway, so we shouldn't worry too much about them.

I would define the following distinguished types (which may be on the stack):

0 - pointer to integer
1 - pointer to character/string
2 - integer
3 - undefined (poss. pointer to pointer)

(Note that these numbers aren't important, it's just to give you the 
general idea.)

By having a separate pointer type for strings, the GC would be able to 
tell which memory objects it needs to search for pointers and which ones 
it doesn't. The only problem with this is that it would forbid embedding 
strings within other structures, but that isn't that great of a hardship.

Double ints would lose a little, but could still be handled as two 
integers treated together. (On x86, we could use SHRD and SHLD to fix it...)

I don't think we can deal with floats very well. Therefore, to implement 
floats, I would forbid them on the stack, but permit a "string" to be a 
float. This would be type-safe enough for the GC, I think.


I believe this design would remove the need for stack frames, as well as 
mandate that stack and heap storage of a type be the same.

The only catch is we might also want pointers to code and to other 
pointers to be types as well. Or to define not "pointer to int" or 
"pointer to char/string" but rather "pointer to GC-searchable" vs. 
"pointer to non-GC-searchable". We may need to use a 3rd bit, but I'd 
prefer not to if possible.

*utsl*