home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / modula2 / 1573 < prev    next >
Encoding:
Text File  |  1992-12-15  |  4.7 KB  |  94 lines

  1. Newsgroups: comp.lang.modula2
  2. Path: sparky!uunet!munnari.oz.au!metro!seagoon.newcastle.edu.au!wombat.newcastle.edu.au!eepjm
  3. From: eepjm@wombat.newcastle.edu.au (Peter Moylan)
  4. Subject: Re: Generic stack implementation
  5. Message-ID: <1992Dec16.104728.1@wombat.newcastle.edu.au>
  6. Lines: 82
  7. Sender: news@seagoon.newcastle.edu.au
  8. Organization: University of Newcastle, AUSTRALIA
  9. References: <9212091316.AA14856@elg> <911288c.32.724187845@ace.acadiau.ca> <1992Dec14.133750.1@wombat.newcastle.edu.au> <1992Dec14.193901.28257@psg.com>
  10. Date: Tue, 15 Dec 1992 23:47:28 GMT
  11.  
  12. I wrote:
  13.  
  14. > TopSpeed Modula-2 won't let you do arithmetic on addresses.  And a
  15. > good thing, too, in my opinion.  Address arithmetic is one of the
  16. > most non-portable things you can do, and I'm a little shocked to
  17. > see an example of it in a textbook.
  18.  
  19. Randy Bush wrote:
  20.  
  21. > Hmmm.  As one of M2's stated design goals was to be able to write the entire
  22. > operating system in M2.  Hence, one wants to write storage [de]allocators,
  23. > device drivers for devices that use multiple addresses, ...
  24. > So, the issue is what is a reasonable zero-cost safety to put around the
  25. > mechanism so it is not accidentally misused?
  26.  
  27. As someone who has written an OS in M2, I think I have a good answer
  28. to this.  To handle those _very rare_ occasions where doing funny things
  29. with addresses is necessary, I've written a module MemoryModel which
  30. does things like
  31.  - define a type PhysicalAddress (which is a LONGCARD in my current
  32.    implementation, but could be other things on other machines);
  33.  - add a CARDINAL to an address, producing another address where
  34.    possible;
  35.  - subtract a CARDINAL from an address, producing another address where
  36.    possible;
  37.  - convert a virtual address to a physical address;
  38.  - convert a physical address to a virtual address, if possible.
  39. and so on.  The "if possible" conditions here refer to the fact that
  40. an error condition should be raised for things like running off the
  41. end of a segment in a segmented architecture, comparing addresses in
  42. different segments, etc.
  43.  
  44. The implementation I've done is for the 80x86 variety of processor,
  45. and is of course very machine-dependent; but I was careful to set up
  46. the definition module so that the caller did not have to know things
  47. like whether memory was segmented.
  48.  
  49. The idea here was that it should be very unusual to import from
  50. MemoryModel, so that uses of it stand out.  (From memory, I think
  51. my software imports from MemoryModel in only three places: in the
  52. storage allocator, in the module which sets up DMA transfers, and
  53. in the screen I/O module (which, for the IBM-PC type of machine, needs
  54. some initialisation code which works out what sort of screen adaptor
  55. is present and from that works out where the memory-mapped screen
  56. segment is).  Furthermore, I make sure that I don't use address
  57. arithmetic anywhere else.
  58.  
  59. I know that Wirth's original idea was that uses of SYSTEM should be
  60. rare, so that importation of SYSTEM should act as a marker that
  61. something suspect is being done; but IMO this has failed because:
  62.  (a) there are some non-portable features which were (accidentally?)
  63.      left out of SYSTEM - e.g. address arithmetic, type BITSET,
  64.      type casting - so that it's possible to write non-portable code
  65.      without ever importing from SYSTEM.  This is especially evident
  66.      among programmers who learnt C before learning Modula-2.
  67.  (b) SYSTEM is too big, and contains some things that don't belong
  68.      there.  Every man and his dog ends up importing from SYSTEM,
  69.      so that uses of SYSTEM no longer stand out as being something
  70.      unusual.
  71.  
  72. The solution, I believe, is to break up SYSTEM into a set of smaller
  73. low-level modules, to give the reader of a source listing a better
  74. idea of what low-level features are being used.  (Many M2 implementations
  75. already do this to a limited extent.  For example, it's become common
  76. to put TRANSFER/IOTRANSFER in a module other than SYSTEM.  This is a
  77. good example of something which didn't belong in SYSTEM in the first
  78. place.)  The low-level features of Modula-2 are certainly worth
  79. keeping (otherwise you drive people like me towards C and possible
  80. suicide), but their uses need to be flagged in a more visible way.
  81.  
  82. One obvious approach, by the way, is to have a compiler option to
  83. generate warning messages for things which might be non-portable
  84. - e.g. type-casting.  Strangely, I've never seen a M2 compiler
  85. which does this.  The TopSpeed compiler, which is good in many other
  86. ways, is especially bad in this respect; one gets the impression that
  87. the people who wrote the compiler didn't understand the difference
  88. between type-casting and assignment compatibility, and/or thought
  89. they were writing a C compiler.
  90.  
  91. -- 
  92. Peter Moylan                      eepjm@wombat.newcastle.edu.au
  93.