CSc 520 - Principles of Programming Languages
23 : Names, Scope, Bindings -- Modules

Christian Collberg

Department of Computer Science

University of Arizona


Separate Compilation


1 Separate Compilation

2 Separate Compilation...

The specification must provide
  1. to the intended user all the information that he will need to use the program, and nothing more.
  2. to the implementer all the information about the intended use that he needs to complete the program, and no additional information.

3 Separate Compilation -- Problems


Modules in C


4 Inter-module Type Checking in C

#-------- x.h --------
void set();

#-------- x.c --------
int glob;

void set() {
   glob = 1111111199;
}

5 Inter-module Type Checking in C...

6 Inter-module Type Checking in C...

7 .h file hell

#---------- a.h ------
#include "b.h"

#---------- b.h ------
#include "c.h"

#---------- c.h ------
#include "a.h"

#---------- a.c ------
#include "a.h"

int main() {}

8 .h file hell...

> gcc a.c
    ....
                 from b.h:2,
                 from a.h:2,
                 from a.c:2:
a.h:2:15: error: #include nested too deeply

#ifndef _A_H_
#define _A_H_
 ....
#endif

9 Compilation order hell


Module concepts


10 Separate Compilation...

modules

11 Module Concepts

 #specs   #impls language
 one -to- zero Eiffel
 one -to- one Modula-2, Ada
 many -to- many Modula-3, Mesa

12 Module Concepts...

13 Separate Compilation...

14 Separate Compilation...

transsys

15 Separate Compilation...

sepcomp1

16 Separate Compilation...

sepcomp2

17 Separate Compilation...

Time-stamps

18 Encoding the Symbol Table

nr kind mod name type extra
(1) module M 1#1
(2) const (1) C (3) val=45
(3) const (0) int basic
(4) 1#1 1#1 1#1 1#1 1#1

19 Example


2#2

20 Example -- M.sym

nr kind mod name type extra
(1) module M TS="10-06 23:11"
(2) import N TS="10-05 09:24"
(3) import R TS="10-06 14:46"
(4) type_std CHAR
(5) type_std INT
(6) type_equiv (3) T (4)

21 Example -- M.sym...

nr kind mod name type extra
(7) const (3) C (5) val=45
(8) type_range (2) T$1 (5) range=[1, (7)]
(9) type_array (2) T (6) range=(8)
(10) type_rec (1) T
(11) field (1) a (5) record=(10)
(12) field (1) b (9) record=(10)


Information Hiding


22 Information Hiding

23 Modular Languages -- Mesa

24 Modular Languages -- Mesa...


5#5

25 Modular Languages -- Mesa...


6#6

26 Modular Languages -- Ada


7#7

27 Modular Languages -- Ada...


8#8

28 Modular Languages -- Modula-2


9#9

29 Modular Languages -- Modula-2...


10#10

30 Modular Languages -- Modula-2...


11#11

31 Language Comparisons

Ada

32 Language Comparisons...

Modula-2

33 Information Hiding - How?

A separately compiled modular program goes through several processing stages from source code to binary executable program:

Compilation
Check the static semantic correctness of and generate code for each module.
Binding
Combine the code generated for each module into one program. Resolve inter-modular references.
Loading
Load the program generated during binding into the memory of the computer. If we have dynamic linking, then the relevant dynamic libraries must also be loaded.
Execution
Execute any start-up code. Run the loaded program.

34 Information Hiding - How?...

35 Information Hiding - How?...

36 Binding Time

37 Exchanging Information at Binding Time

paster_overview

38 Readings and References

39 Summary



Christian Collberg 2008-03-24