Welcome to the perspective unit on cogeneration in which we're going to answer some frequently asked questions as usual. So Let's see. You mentioned several times in the course that Jack is a relatively simple language. What would it take to generate code for a more realistically complex language. Indeed, very simple. To begin with, it doesn't really have a type system. All the data values are 16-bit, and the data value of any type can be signed to a variable of any other type. This allows compilers To almost completely sidestep all the headache that is associated with handling typing issues. For example, when compiling and evaluating expressions, jet compilers don't have to bother about determining. The type of the expression according to the types of the constituent's elements of these expressions. Likewise, array entries are also untyped in Jack. In contrast, most programming languages feature rich and versatile Typing systems. So different amounts of memory must be allocated for different types of variables, 16 bits, 32 bits, 64 bits and so on. The conversion from one type into another requires specific casting and language operations. The compilation of expressions like x plus y depends strongly on the types of x and y and so on and so forth. All these requirements make compilation much more challenging Another significant simplification is that Jack does not support inheritance. This implies that all method calls can be handled by the compiler statically during compile time. In languages that do have inheritance like Java Compilers must read method calls during runtime because they have to determine to which class the method belongs according to the object on which the method was called to operate. You know this method is somewhere. Along the inheritance hierarchy, and this determines which methods we have to invoke. This is sometimes called late binding. And also, and this is completely unrelated to what we discussed before, Jack has now public fields The only way to access a field from outside the class is through accessor methods that the programmer must write. If you look at all these things, the lack of a typing system, the lack of inheritance, the lack of public fields, all these simplifications make co generation Far simpler in Jack compared to compilers of industrial strength languages. With that, let's move on to the next question. Well this question is actually related to the first one, how difficult will it be to close the gaps between Jack In languages like Java or Python. [COUGH] Well, some extensions like handling inheritance as I just discussed, well these extensions require significant code generation efforts. You know supporting inheritance, polymorphism, late binding, that's a lot of compilation work. And yet other simplifications of the Jack language can be easily relaxed. Well I shouldn't say easily, but they can be relaxed with relatively little effort. And that's because they are quite straight forward. For example, we can easily add the control structures like for and switch. That's not such a big deal in terms of extending our compiler. And adding more data types aside of the three types we have now, requires more effort but Once again the extension is relatively straightforward. Another limitation of Jack is that you can not assign character constants to variables of type char, C-H-A-R. In order to bypass this limitation, the Jack programmer must use all sorts of string functions which is kind of tedious. Well once again that's an example of a feature that can be easily fixed in the Jack language. Using some, we have to both extend the grammar as well as the compiler. And indeed I would like to observe that Each of the language extensions that we discuss in general, well, each of these activities, extending the language, requires two very separate activities. First af all, the language designer has to sensibly extend the language grammar. In syntax, and this is something that must be done with great care. And then, once the specifications have been extended, the compiler writer must extend the parser and the code generator in order to accommodate these changes in the language So altogether, these are big time changes that must be done with great care, as the language evolves from one version to the other, as programming languages normally do. Now, Once again, there are many things that can be implemented and improved in Jack. Most of these extensions, that's the good news is that most of these extensions are independent of each other. And in that respect, they can be implemented by making relatively local and simple extensions To the parser and code generator that we're already developed. So with that, let's move on to the next question. [COUGH] Which is, What is the meaning of compiler optimization? Well, it's not terribly important that the compiler itself will be efficient at optimizing. What's important is that. The compiler will generate low level code, which is efficient and optimized. And I hope you understand this distinction. For example, consider high level statement like X++ in, say, Java. And a Java compiler may translate this statement into Push x, push one add and pop x, x plus plus. And then the VN translator will kick in and translate each one of these four VN commands into several machine level instructions. We'll end up with something like 50 lines of code. And so the result would be a considerable chunk of code. At the same time, an optimized compiler may notice that what we have here is simply a variable incrementing the operation. And with that in mind, the compiler or the optimized compiler Will translate X plus plus into two machine instructions only et x followed by m equals m plus 1. That's at least what we could have done in the Jack hack platform. Of course this is just one example of many optimization tricks that are expected From a full service compiler. In general the ability to generate compact code that uses as few cycles and as little hardware resources as possible well this ability is very attractive, very attractive feature Of code generation and compilers in general. Well, none of this optimization was done in the VM translator that we developed in this module. So to wrap up my answer to this question, I would like to comment that Even though the code generator that we developed is un-optimized it's still represents a sophisticated and substantial piece of engineering. Once you complete developing this co generator, you should feel very proud of your accomplishment. You've just finished developing a compiler, a compiler for an object based Java-like language. So Mazel tov And with that, that's the end of our module. Module five. And in the next module we're going to develop and operating system. And this operating system will be developed using Jack language.