Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-unix!sri-spam!ames!ucbcad!ucbvax!decvax!decwrl!hplabs!hp-pcd!orstcs!budd From: budd@orstcs.cs.ORST.EDU Newsgroups: comp.lang.smalltalk Subject: Translating Smalltalk Message-ID: <245100008@orstcs> Date: Mon, 8-Jun-87 14:09:00 EDT Article-I.D.: orstcs.245100008 Posted: Mon Jun 8 14:09:00 1987 Date-Received: Fri, 12-Jun-87 04:08:51 EDT Lines: 37 Nf-ID: #N:orstcs:245100008:000:1775 Nf-From: orstcs.cs.ORST.EDU!budd Jun 8 11:09:00 1987 Somebody asked about translating Smalltalk into other code, and how message passing is done. Note that the dynamic message passing portion of smalltalk is not the problem in translating Smalltalk to machine code; I will use C as my target language, as it is more readable; We can easily translate object send: arg1 message: arg2 with: arg3 arguments: arg4 into some C code that looks like: *(FindMethod(object,'send:message:with:arguments))(arg1,arg2,arg3,arg4) That is, we write a little routine that does our message lookup for us, returns a method (function) and then executes it. This is how object oriented programming is done in Scheme, for example. The need for memory management complicates this only slightly. If no method exists FindMethod returns a pointer to an error reporting routine. The real problem in translating Smalltalk is the notion of Blocks. Blocks must carry with them the context in which they were defined, and there is no way to easily simulate this dynamic binding is a staticly scoped language like C. (This is a classic funarg problem). Which leads one to wonder if a language similar to Smalltalk, but without blocks, could be defined. I think yes. And if this were done, could you build interpreters/compilers and generate efficient machine code without sacrificing the nice features of Smalltalk; i.e., experimental programming, rapid prototyping, reusability. I think yes. Finally, if you did this, could you use optional declarations of object class to speed things up by eliminating the method lookup; (the idea being that you produce and debug your code, then insert declarations to speed it up); I think yes. Watch this space for future announcements. --tim budd, oregon state university, budd@oregon-state.csnet