|
The compiler, as specified in the course, doesn't need to know the other class names. It just produces Test2.vm which references Test1 (or any of the standard library classes for that matter). These classes or functions inside them may not exist yet, but the compiler can produce correct code.
What you lose in this scenario is error checking. Maybe you misspelled a class or method name. Or you call it with wrong parameters or a number of other problems which one would expect the compiler to detect and report will be ignored. But you will detect them if and when you translate the .vm files into assembly.
In a way, this is similar to how C compilers work. When you compile test1.c file the compiler produces the so called object file: test1.o. It can reference functions, which are defined in other parts of the program or in external libraries. They may not yet be written, but the compiler can still generate the object file. To produce the executable file, one calls the linker with all the participating object files and libraries. The linker will detect and report any discrepancies like the ones described above.
N.B. There are major differences between the object files and the VM files though. Object files are essentially compiled to machine language, and have additional data about the functions and variables it defines and about the the external ones it need resolved.
|