home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pop / 194 < prev    next >
Encoding:
Internet Message Format  |  1993-01-10  |  7.9 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!bhamcs!axs
  2. From: axs@cs.bham.ac.uk (Aaron Sloman)
  3. Newsgroups: comp.lang.pop
  4. Subject: Why Poplog Pop-11 was never implemented in C
  5. Message-ID: <C0n1rK.214@cs.bham.ac.uk>
  6. Date: 10 Jan 93 12:38:08 GMT
  7. References: <C07Bop.DwH@cs.bham.ac.uk> <1993Jan7.154850.16982@syma.sussex.ac.uk> <KERS.93Jan8082322@cdollin.hpl.hp.com> <1993Jan9.013923.5116@philmtl.philips.ca>
  8. Sender: news@cs.bham.ac.uk
  9. Organization: School of Computer Science, University of Birmingham, UK
  10. Lines: 154
  11. Nntp-Posting-Host: emotsun
  12.  
  13. ray@philmtl.philips.ca (Ray Dunn) writes:
  14.  
  15. > Date: 9 Jan 93 01:39:23 GMT
  16. > Organization: Not Philips.
  17.  
  18. > ....
  19.  
  20. > Having been hacking in 'C' for the last ..cough.. years I can't understand
  21. > why there wasn't a 'C' implementation of POP done a long time ago.
  22.  
  23. > I hope the work on Pepper is being done in a portable fashion.
  24.  
  25. The Mac Alphapop implementation was done in C by Cognitive
  26. Applications Ltd in the mid eighties, but it turned out not to be
  27. easily portable because it was too dependent on idiosyncratic
  28. features of the C compiler used, and perhaps too closely tied to the
  29. Mac operating system. It was very well integrated with Mac graphics,
  30. menus, etc., I believe. (I've never used it.)
  31.  
  32. Alphapop compiled to an intermediate code which was then
  33. interpreted, as was also true of the DEC PDP-11/40 version of Pop-11
  34. implemented a decade earlier by Steve Hardy in PDP11 assembler.
  35.  
  36. Using an interpreted intermediate level makes porting very much
  37. easier, but the cost is speed of execution.
  38.  
  39. By contrast Poplog Pop-11 compiles all the way to machine code,
  40. making porting to a new machine non-trivial.
  41.  
  42. Most of Poplog Pop-11 is implemented in Pop-11, so that porting is a
  43. bootstrapping operation. Some bits are implemented in C. The rest
  44. uses assembler for efficiency. E.g. the stack pointer, which is used
  45. all over the place, should be in a global register and you can't
  46. have global register variables in C (or couldn't when I last heard
  47. this point discussed -- I am not a C programmer.)
  48.  
  49. The main obstacle to portability is not the language used: it's the
  50. fact that Poplog Pop-11 is compiled to machine code for maximum
  51. speed of execution. In particular it has an incremental compiler
  52. which has to generate machine code for the current machine at "run
  53. time", i.e. when user procedures are compiled.
  54.  
  55. The compiler itself (actually a family of compilers, as explained
  56. below) is written in a special extended "system" dialect of Pop-11
  57. with C-like pointer manipulation facilities and other extensions for
  58. efficiency. It would be much harder to implement such a
  59. sophisticated compiler in C, which is a far less rich language.
  60.  
  61. Most of the Poplog compiler is machine-independent. Source code (in
  62. any of the Poplog languages, i.e. Pop-11, Prolog, Lisp, ML, or
  63. user-defined languages) is first compiled to a "high level" Poplog
  64. virtual machine (PVM), using a language-specific compiler (often
  65. implemented in a mixture of Pop-11 compiler routines and a parser
  66. written in the source language, e.g. Prolog). This bit is
  67. language-specific, but machine independent. Porting the Poplog
  68. languages therefore requires porting the Poplog virtual machine.
  69.  
  70. That does not need to be done explicitly, because a
  71. language-independent and machine-independent compiler (implemented
  72. in extended Pop-11) compiles from the PVM to a low level Poplog
  73. Implementation Machine (PIM), which is roughly at the level of a VAX
  74. instruction set. This means that only the PIM has to be ported to
  75. each new machine, which is not very hard.
  76.  
  77. For each machine a machine-specific "translator" generates machine
  78. code to go into procedure records. This has to be architecture
  79. specific, and is one of three main components that has to be re-done
  80. for each architecture, Modifying that translator for a new machine
  81. can take about a month's work if done by an expert.
  82.  
  83. In theory that back-end compiler could be produced automatically
  84. from a specification of the target machine. In practice that`s a
  85. very hard problem because of the variety of machine architectures
  86. (numbers and types of registers, addressing modes, types of cache,
  87. etc.) so porting well requires some creativity.
  88.  
  89. The Poplog system sources written in extended Pop-11 are compiled
  90. using a slightly different route from user procedures, because the
  91. system can't assume there's already a working Poplog running on the
  92. target machine. Nevertheless most of the compilation process is the
  93. same though there's more optimisation between the PVM and the PIM
  94. because system procedures can make assumptions that would not be
  95. applicable to user procedures. But that's all machine independent.
  96. However, instead of generating machine code directly from the PIM
  97. level, the final stage of the compiler generates assembler for the
  98. machine, so that the system can be built on one type of machine to
  99. be run on another. The assembler files are then assembled, linked
  100. and run on the target machine. (Occasionally there are unimaginative
  101. manufacturers who won't release an assembler, even when they use one
  102. in-house, because they think only high level languages should be
  103. used by their customers!)
  104.  
  105. The second back-end compiler, which outputs assembler, is also
  106. written in extended Pop-11, and should not normally take more than a
  107. month or so to re-target for a new machine.
  108.  
  109. As I said before, there are also some hand-coded assembler files,
  110. mainly to do with control of the stack and also providing some
  111. frequently used routines that have to be very fast. The assembler
  112. files can usually be rewritten for a new machine in a few weeks.
  113.  
  114. The other component that's host-specific and has to be changed for
  115. each port is the interface with the operating system, which is very
  116. rich in Poplog, including system calls, procedures for creating,
  117. reading and writing files and directories, object file formats,
  118. dynamic linking of "external" programs (e.g. object files produced
  119. by C, Fortran, etc.), access to system libraries, spawning
  120. sub-processes, pipes or mailboxes, etc. etc. Porting the operating
  121. system interface can be a matter of a few days, if it's to a new
  122. dialect of Unix close to one that's been done before, or it can take
  123. several weeks.
  124.  
  125. Thus, where all goes well a complete port, including modifying
  126. run-time code generator, assembler generator and OS interface, and
  127. re-writing a few assembler files, requires only three to four person
  128. months, and that work then ports all the Poplog languages (including
  129. any languages users have implemented in Poplog), the editor and,
  130. with luck, the X interface.
  131.  
  132. Unfortunately it can take longer where there are bugs in the target
  133. host's linker, assembler, operating system, or hardware.
  134.  
  135. Such bugs have caused delays since Poplog ports began in the early
  136. 80s. Trouble arose with various systems (including Apollo, HP,
  137. GEC-63 (now defunct) Fairchild Clipper, DEC RISC+Ultrix and MIPS)
  138. causing what should have taken little more than three months to be
  139. drawn out over a longer period, the original RISC DECstation being
  140. one of the worst. Poplog finds the bugs other applications don't,
  141. apparently.
  142.  
  143. Poplog used to be much harder to port. The increase in portability
  144. is due to work by John Gibson at Sussex University, especially
  145. separating the PVM and the PIM so that the bulk of the translation
  146. between them is both language and machine independent, and also
  147. extending the Pop-11 system dialect to provide very efficient
  148. mechanisms in a portable fashion, so that less and less machine
  149. specific stuff had to be written in assembler or C (which is not
  150. always fully portable).
  151.  
  152. For more information see:
  153. R. Smith, A. Sloman, J. Gibson `POPLOG's two-level virtual machine
  154. support for interactive languages' in
  155.     Research Directions in Cognitive Science Volume 5: Artificial
  156.     Intelligence,
  157. eds D. Sleeman and N. Bernsen, Lawrence Earlbaum Associates, 1992
  158. (Also Cognitive Science Research Paper 153, University of Sussex,
  159. Jan 1990).
  160.  
  161. Aaron
  162. -- 
  163. Aaron Sloman,
  164. School of Computer Science, The University of Birmingham, B15 2TT, England
  165. EMAIL   A.Sloman@cs.bham.ac.uk  OR A.Sloman@bham.ac.uk
  166. Phone: +44-(0)21-414-3711       Fax:   +44-(0)21-414-4281
  167.