Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.misc Subject: How to make a language downward-extensible? Message-ID: <28750:Sep2402:58:2290@kramden.acf.nyu.edu> Date: 24 Sep 90 02:58:22 GMT References: <2581@l.cc.purdue.edu> <1990Sep22.061027.9223@d.cs.okstate.edu> Organization: IR Lines: 40 In article pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: > Maybe Rubin is a bit rough in expression, but I think that he is trying > to say that he would dearly love to have extensible compilers, I'd like to focus on this point. Upward extensibility through macros and functions is pretty well understood. Its syntax may not be as well understood, but that's not a serious problem. What would it take to make a realistic language downward-extensible? For example, many computers have a way to multiply 32 bits by 32 bits and get each word of the 64-bit result, even if they don't have 64-bit types. How can I take advantage of this in a program? The simplest answer is to settle on a standard way of escaping to the lowest levels of the machine. C has asm(), for example. But this isn't enough. I have to explicitly define a compile-time symbol to choose between the assembler version and the slower, high-level version. I have to learn a new language and write a new routine for every computer where I want a speedup. And if the compiler learns some new optimization tricks or the CPU is upgraded, my ``fast'' code may be worthless. It isn't hard to solve the last problem. The language just needs some construct to say ``compile either this code or that code, whichever you think will come out faster.'' I may want to reorganize the flow of my program if one alternative is better, so the language should also define a compile-time symbol for me saying which alternative it picked. This also solves the first problem. What's tricky is the second problem. How can downward extensions be portable? A sufficiently weird hardware operation may not have any sensible language equivalent, but most of the time it will. So the problem reduces to teaching the compiler to recognize *something* in the langauge that takes advantage of any given instruction. Then programmers use the ``compile this or that'' form mentioned above; the more forms they use, the better chance they'll have of matching the hardware on any given computer. And their programs will still be portable. Comments? ---Dan