Path: utzoo!attcan!uunet!mcvax!ukc!warwick!cvaxa!aarons From: aarons@cvaxa.sussex.ac.uk (Aaron Sloman) Newsgroups: comp.arch Subject: Re: Machine-independent intermediate languages (two in Poplog) Keywords: incremental compilers, portability, multi-language, AI Message-ID: <527@cvaxa.sussex.ac.uk> Date: 10 Nov 88 02:51:01 GMT Organization: School of Cognitive Sciences, Univ of Sussex, Brighton, UK Lines: 131 If you want to design a machine-independent intermediate language (or target virtual machine for compilers) you are pulled in two directions:- a. Make it a high level VM so that compiling to it from high level programming languages is relatively easy. b. Make it a low level VM so that translating to machine code is relatively easy, making porting to new machines easy etc. Poplog solves the dilemma by providing both, with a machine- independent, language-independent optimising compiler going from the high level to the low level. So adding a new language (producing a new "front end") is relatively easy using tools provided for compiling to the high level. And porting to a new machine (producing a new "back end") is relatively easy. This architecture, designed and implemented mostly by John Gibson at Sussex University, has been used to implement portable INCREMENTAL compilers for a collection of interactive languages, which can then be mixed if necessary for solving problems that require different languages for different sub problems. {POP-11, COMMON LISP, PROLOG, ML, SYSPOP} | (used to implement Poplog) (Machine independent)Compile to | V [High level VM (PVM)] \ (extended for SYSPOP) | machine and language | | independent Optimise & compile to | | | V | [Low level VM (PIM)] | (modified for SYSPOP) / | (Language indepdendent) Compile (translate) to | V [Native machine instructions] [or assembler - for SYSPOP] So Poplog has two machine independent virtual machines (or if you like intermediate languages). The high level Poplog Virtual Machine (PVM) is suitable as a target for (incremental) compilers and has been used for Prolog, Common Lisp, Pop-11 (a lisp like language with a Pascal like syntax) Standard ML (version 1) and other simpler special purpose languages. Syspop is an extended dialect of Pop-11 enhanced with C-like facilities for pointer manipulation, etc. Syspop is used to implement the core of Poplog. E.g. the garbage collector is implemented in Syspop. The low level Poplog Implementation Machine (PIM) is a convenient virtual architecture with instructions that translate without too much trouble to instructions for a typical general purpose computer. The level is about the same as that of VAX. There is a machine independent and language independent intermediate compiler which compiles from the high level PVM to the low level PIM, optimising on the way. A machine-specific back-end then translates the low-level VM to native machine code, except when porting or re-building the system. In the latter case the final stage is translation to assembly language. (See diagram above.) Poplog was originally implemented on a VAX running VMS(tm), but has since been ported to a range computers with versions of Unix(tm), e.g. VAX + Berkeley Unix, Sun-2, Sun-3, Sun-4, Sun-386i, Hewlett Packard M680?0 + Unix workstations, Apollo + Unix, GEC-63, Sequent Symmetry (multiple 80386 + Unix), Orion 1/05 (Clipper processor + Unix). To illustrate, porting to Sun-4 took two people, not working full time, about 6 weeks. A programmer who had never ported Poplog previously, nor worked with Intel 80386 processors previously, took about four and a half months to port it to Sequent Symmetry (much of the time without a sequent computer to check things out). Then porting to Sun386i took under two weeks. If a user implements a "front-end" compiler from a new language to the PVM then that language automatically runs on all the machines supporting Poplog, and inherits an integrated editor, rich development environment, indefinite precision arithmetic, window manager, etc. One user claimed it took him about three weeks in his spare time to produce a Poplog compiler for Scheme. Once he had Scheme being translated to the PVM, he did not need to bother about getting it to translate to machine code on the machines running Poplog. NOTE The comilers in Poplog are incremental in that you can compile or recompile individual procedures in the process in which previously compiled procedures are or have been running. New procedure records are created in the heap, and linked in to the rest of the system via identifier records, without having to go through a separate linking process. Interactive commands given in the language are compiled, then run, and the compiled procedure is then discarded. This use of incremental compilation is fairly common with Lisp or Prolog systems. It gives almost as much flexibility as using an interpreter, but programs generally run much faster, as they are compiled to machine code. POPLOG provides an extensive kit of tools that can be used by languages that need them including a lightweight process mechanism, extendable record and vector classes, hash-tables, ratios, complex numbers, floating point numbers, arrays, an extensive set of procedures for interacting with the operating system, an object oriented library, list processing, a pattern matcher, etc. Some of these are built in whilst others are autoloaded on demand. Not all the functionality is provided directly by virtual machine (intermediate language) instructions. Instead utilities are provided that are themselves defined (e.g. in Syspop) and then compiled through the two intermediate stages. We have not (yet) tried using Poplog to implement a compiler for a non-interactive language like C or Pascal. In principle it should be possible, at a cost in efficiency. Instead Poplog allows procedures written in these languages to be linked in for use as subroutines. Aaron Sloman, School of Cognitive and Computing Sciences, Univ of Sussex, Brighton, BN1 9QN, England ARPANET : aarons%uk.ac.sussex.cvaxa@nss.cs.ucl.ac.uk aarons%uk.ac.sussex.cvaxa%nss.cs.ucl.ac.uk@relay.cs.net JANET aarons@cvaxa.sussex.ac.uk BITNET: aarons%uk.ac.sussex.cvaxa@uk.ac or aarons%uk.ac.sussex.cvaxa%ukacrl.bitnet@cunyvm.cuny.edu UUCP: ...mcvax!ukc!cvaxa!aarons or aarons@cvaxa.uucp