Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!pasteur!ucbvax!decwrl!sun!aeras!elxsi!beatnix!corbett From: corbett@beatnix.UUCP (Bob Corbett) Newsgroups: comp.lang.pascal Subject: Modules and separate compilation Keywords: Extended Pascal, modules, separate compilation Message-ID: <2483@elxsi.UUCP> Date: 15 Feb 89 03:04:56 GMT Sender: news@elxsi.UUCP Reply-To: uunet!elxsi!corbett (Bob Corbett) Distribution: usa Organization: ELXSI Super Computers, San Jose Lines: 76 In an earlier posting, I described a scheme for implementing separate compilation for Extended Pascal. My proposal was based on having the compiler maintain catalogue files. Catalogue files would contain the names of files submitted to and created by the compiler. The response to my proposal has been overwhelmingly negative. I am now formulating new proposals for separate compilation. Few of the people who have written or spoken to me have read the proposed standard. Most of the schemes that have been offered in opposition to my proposals violate the proposed standard. If anyone feels that he or she knows the right way to implement separate compilation, he or she should let the standards committee know about it. Otherwise, he or she is likely to find that his or her method is prohibited by the new standard. I am exploring a way of making separate compilation for Extended Pascal look as much as possible like separate compilation for languages such as C and Fortran. Under this scheme, each source file consists of zero or more program components (a program component is either a module-declaration or a main-program-declaration). When a source file is compiled, the compiler will produce an object file. The object file will contain an abstract syntax tree (AST) for each program component in the source file. Semantic information will be maintained separately. Both source and object files may be submitted to the compiler. If one of the files contains a main- program-declaration and all names referenced directly or indirectly from the main program can be resolved, an executable file will be generated. A drawback of this scheme is that it is impossible complete semantic checking until link time. When a program component that imports an interface is compiled, the compiler does not have access to the declarations of the imported names unless the module declaration containing the interface is contained in the source file. The compiler may not even know which names have been imported. I fear that users will be upset when they get what appear to be compilation errors at link time. The problem can be avoided by requiring each source file to be compiled in sequence and having the resulting object file retain information about previously compiled files. Suppose a programmer is writing a linear algebra program. He might write a source file main.p containing his main program. The main program might import an interface dgemat contained in a module in a file named linpack.p. The module containing the declaration of the interface dgemat may itself import an interface named dblas1 contained in a file named blas.p. Then the programmer could compile his program using the command pascal blas.p linpack.p main.p Assuming all references could be resolved, the compiler would produce an executable file named a.out. If some references could not be resolved, it would produce a file main.o, which would contain compiled code for blas.p, linpack.p, and main.p. If the programmmer wished use separate compilation, he could first use the command pascal blas.p to produce an object file blas.o. Next he could use the command pascal blas.o linpack.p to produce an object file for blas.p and linpack.p. Finally, he could complete the compilation with the command pascal linpack.o main.p. However, he could not compile linpack.p without blas.o or blas.p, and he could not compile main.p without linpack.o or linpack.p. This approach eliminates the need to store abstract syntax trees, since code can be generated at each stage of compilation. I welcome comments and suggestions regarding separate compilation for Extended Pascal in general or my scheme in particular. Yours truly, Bob Corbett