comp.lang.ada
 help / color / mirror / Atom feed
* Static expressions and using 'Size
@ 1996-03-22  0:00 Geert Bosch
  1996-03-22  0:00 ` Norman H. Cohen
  1996-03-22  0:00 ` Robert A Duff
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Bosch @ 1996-03-22  0:00 UTC (permalink / raw)


Currently I'm writing a GC compatible allocator for GNAT and I found
some Ada-related problems for which I didn't find a nice work-around
yet. Maybe somebody can give some hints.

One part of the allocator (which is working fine BTW) is the Page_Manager
which maintains some administration about the virtual memory that has
been allocated, is behind write-barriers etc. 

Because of some comments from others I try to make the code suitable
for systems that use other page-sizes than 4 kB, 32-bit addresses etc.
One of the problems is that the sizes of some data-structures depend
on sizes of others.

Because of portability, readability and safety I'd like not to calculate
all record-sizes etc. myself, but have the compiler do that for me. The
problem is however that expressions involving the 'Size attribute are
not static and for that reason cannot be used in constants.

This is annoying because I'd rather write
   Page_Info_Bytes     : constant := Page_Info'Size / Byte'Size;
than
   Page_Info_Bytes     : Positive := Page_Info'Size / Byte'Size;
because the value of Page_Info_Bytes is known at compile-time and won't
change during execution of the program (I hope ;-)

Things become worse when I want declare types that depend on these
'constants'. Would I really have to explicitly specify all record-sizes
and stuff myself, with all problems when size of data-structures change?
I *must* overlook something, but I can't think of it. If I indeed need
to specify everything myself, I think this is contrary to the 
'Ada-philosophy'

Thanks in advance for any reactions!

   Geert

--- Here comes some of the relevant Ada-code --------------------------

package Page_Manager is

   -- (Edited, stripped down version)

   -- All XXX_Size identifiers denote sizes in bytes rather than bits

   VM_Size              : constant := 2 ** 29;  -- 512 MB Virtual Memory
   Page_Size            : constant := 2 ** 12;  -- 4 kB VM pages
   
   type Page_Nr is range 0.. VM_Size / Page_Size - 1; -- 2 ** 17 pages

   -- Every VM page has a Page_Info record
   
   type Page_Info is record
      ...
   end record;
   
   -- Here are subprograms for Set_Page_Info, Get_Page_Info etc.
   
end Page_Manager;

package body Page_Manager is

   -- This is illegal Ada'95 code !!!
   Page_Info_Size          : constant := Page_Info'Size / Byte'Size;
   Page_Map_Size           : constant := Page_Map'Size / Byte'Size;
   
   Map_Entries_Per_VM_Page : constant := Page_Size / Page_Info_Size;
   Map_Pages               : constant := Page_Nr'Last / Map_Entries_Per_VM_Page;
   
   type Map_Page_Nr is range 0..Map_Pages - 1;

   -- Rest deleted

end Page_Manager;

-- 
E-Mail: geert@sun3.iaf.nl *** Real programers don't document their code: if ***
 Phone: +31-53-4303054    ** it was hard to write, it should be hard to read **





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-03-22  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-22  0:00 Static expressions and using 'Size Geert Bosch
1996-03-22  0:00 ` Norman H. Cohen
1996-03-22  0:00 ` Robert A Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox