From: Samuel Williams Date: 2010-10-05T21:31:25+09:00 Subject: Re: how can we make a ruby compiler Dear Ryan, Thanks for your comments. In this discussion there are many opinions, so please keep in mind this is simply my perspective based on my experience. On 5/10/2010, at 11:01 PM, Ryan Davis wrote: > On Oct 5, 2010, at 02:49 , Samuel Williams wrote: > >> If you have a truly dynamic language (like Ruby), it is almost impossible to compile it adequately. This is because compilation is all about making assumptions. A dynamic language makes it very hard to make assumptions (there is quite a bit of research in this area, it is worth reading about it). > > Well this just isn't true (or is overly vague and my tired brain is reading more into it than it should). Look at anything written by David Ungar, or the research done on self, smalltalk, the latest javascript engines, etc... I'm aware of most of this work, however I don't consider many of these languages to be completely dynamic. By dynamic, I mean that it is not possible to make an assumption about the result of an expression unless it is executed. If you can make an assumption about an expression, I don't consider it to be dynamic. For example, in most of those languages, the name of a function is specified explicitly and can't change due to the environment or scope of execution. We also know that all arguments to a function will be evaluated in the current scope. We can do some analysis and determine that an expression won't change in a loop, and then optimise for this case. Many of these languages provide some semantic models which allow the interpreter to make assumptions. A good indication of a non-dynamic programming language is the presence of semantically meaningful keywords, especially those that have fixed behaviour. Examples include "def", "if", "while", "switch" and "try". These expressions can all be analysed with the knowledge of a given semantic model. A truly dynamic language has no such luxury... In the case of a dynamic language we are reduced to statistical analysis at run time. Compilation becomes a method of speeding up the interpreter execution rather than optimising based on assumptions in the code itself. Few, if any, programming languages are completely dynamic. Scheme would be one language that I would consider very dynamic, as an example. An interpreter is simply a high level processor (i.e. CPU). However, there are intrinsic semantic structures which cannot be lowered. "Sufficiently smart compilers", and all that. Programming languages range from completely dynamic to completely static, depending on the semantic and execution model. Kind regards, Samuel