Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!goya!esink@turia.dit.upm.es From: esink@turia.dit.upm.es (Eric W. Sink) Newsgroups: comp.lang.objective-c Subject: Implementation of Objective C Message-ID: <1991May27.073640.13936@dit.upm.es> Date: 27 May 91 07:36:40 GMT Sender: @dit.upm.es Reply-To: esink@turia.dit.upm.es (Eric W. Sink) Followup-To: comp.lang.objective-c Organization: Dept. Ingenieria de Sistemas Telematicos, dit, upm, Madrid, Spain Lines: 128 Nntp-Posting-Host: turia.dit.upm.es Greetings all ! I recently posted a request for an Objective C grammar to c.l.objective-c. Well, I should have phrased my question better, and I've come up with a few more. I'm toying around with the idea of implementing an ObjC compiler, but I currently know little about the language. I haven't had a chance to buy Cox's book yet. I do have ``Intro to Objective C on the NeXT Machine'', by Gerrit Huizenga. The information I'm looking for needs to be a bit more precise. Anyone willing to give answers to the following : ? 1. What new keywords (in the ANSI C sense of a keyword) are added to ANSI C ? Which of the following are keywords, and which are not : @interface, @implementation, @end, @selector, self, super, id, SEL, nil, Object, new, free 2. Is Object (the class) declared somewhere, or does the compiler simply recognize it as already existent ? If it is declared and implemented somewhere using Objective C, why can't other root classes exist ? What does its declaration look like (I want to know how to parse a class declaration which has no super class) 3. I assume that a 'message send' is a primary expression, as it appears in the ANSI C grammar. In other words, the following expressions are all possible : [ obj msg][12] = 33; /* assume the method returns (int *) */ [ obj msg](); /* assume the method returns a func ptr */ x = a + *([obj msg]); /* again, method returns (int *) */ I also assume that the id and SEL elements of a message send are postfix expressions, so the following is legal : id foo(); SEL bar(); [foo() bar()]; 4. Is a class (factory) object represented differently than an instance ? Are messages to a class object dispatched differently ? How is new implemented ? What other factory methods are implemented by Object ? isa (what does isa return, a factory object ? )? 5. My biggest question : How exactly does dispatching work ? I assume that every instance is a dynamically allocated region of memory which contains all the instance variables PLUS a pointer to some data structure. I assume for now that this data structure is in fact the factory object for the class of the instance, and that factory objects contain the 1. dispatch table as well as a pointer to the 2. super class, but it doesn't matter, as long as those two items are available to each instance. The dispatch table associates message selectors with methods for the given class, so we take the message being sent, convert it to a SEL, use the SEL as the index into the table and get the address of the method. Arguments have to get pushed onto the stack (right to left ?), and the receiving object gets pushed (first or last ?), and we call the method. My questions : how do we convert the method name to a SEL ? The manner in which this conversion occurs is very important, because every source file which uses this class must arrive at the same SEL for the same method name, and most importantly, that SEL must be the same as the one calculated during the actual genertion of the dispatch table, which I assume is generated while compiling the @implementation of the class. (sentence way to long, sorry) What happens if the source file we are compiling, uses many classes, and a given method foo: appears in more than one place in the class hierarchy (assume that the various uses of foo: are not inherited versions of the same method, but are quite distinct methods along totally different lines of inheritance, but simply happen to have the same name). Now, how do we know which foo: to use ? How do we map to a SEL ? How to we type check arguments ? How do we know the type of the resulting message send ? Is SEL of type int (a table index requiring scaling) or of type char *, (a table offset requiring no scaling). Consider the following example : Is this code legal Objective C ? Since I see so many problems with it, I'm beginning to speculate that ObjC simply prohibits behavior like this... @interface classone : Object { int x,y; } - (long *) foo:(int) v1 :(short) v2; /* This is foo:: */ @end @interface classtwo : Object { long a,b,c,d,e,f,g; } - bar; - qwerty:vary; - (short) foo:(int) a1 :(short) a2; /* This is a distinct foo:: */ @end @interface classthree : classone - (short) foo:(short) v1 : (long) v2; /* Can I override a method with a new method of different type ? */ @end int main() { id objekt; int k; k = [objekt foo:11:22]; /* What is the type of the rhs of this assignment ? What is the SEL ? To what do we convert the arguments for pushing onto the stack ? */ } I plead for patience with respect to my terribly trivial questions. BTW, the few ObjC features exemplified in Huizenga's notes appear to be enough for a usable language. I speculate that ObjC doesn't contain that much more (or else it would be the melting pot that C++ is). Am I right ? I really like the looks of Objective C. I have some experience implementing oo languages, but not compiled ones. Separate compilation does seem to offer some problems. I was considering implementing a subset of C++, but I'm leaning towards Objective C instead. Thanks in advance for any replies ! Eric Eric W. Sink | "If no one is criticizing |Opinions Departamento de Telematica | your work, it is possible |mine - Universidad Politecnica de Madrid| that you are not doing |all of esink@turia.dit.upm.es | anything." -George Verwer |them.