Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!apple!netcom!schang From: schang@netcom.UUCP (Sehyo Chang) Newsgroups: comp.lang.smalltalk Subject: Re: How does the Smalltalk compiler work? Message-ID: <5478@netcom.UUCP> Date: 8 Jan 90 17:31:45 GMT References: <1340@mit-amt.MEDIA.MIT.EDU> Organization: NetCom- The Bay Area's Public Access Unix System {408 249-0290 guest} Lines: 58 In article <1340@mit-amt.MEDIA.MIT.EDU> adamk@media-lab.media.mit.edu.UUCP (Adam Kao) writes: >I'm trying to understand the Smalltalk compiler and Goldberg and >Robson are almost no help. Is the Smalltalk compiler a traditional >compiler with a yaccable grammar? If not, what steps does it go Smalltalk is recursive-descent parser(at least in the VM). >through in translating source to bytecodes? How do object-orientation >and message passing change the way expressions are parsed? Smalltalk expression directly compiled one-to-one into bytecodes. For example, in the back of the blue book, under section "The Implementation" smalltalk expression "origin + corner / 2" would translated into something like following bytecodes, 0 "push value of 'origin' instance value onto stack 1 "push value of 'corner' instance value onto stack 176 "send binary message with the selector +" 119 "push the SmallInteger 2 onto the stack" 185 "push a binary message with the selector /" 124 "return the object on the top of the stack" Remember, Smalltalk VM is stack-orienteted architecture interpterter,thus all operation is done through stack manipulation and it's language syntax reflects through left-right expression syntax(with some sugar coating). > >In a yacc grammar for C I would find separate rules for if-then, >while, etc. I notice in the back of Goldberg and Robson there is only >one track diagram for blocks. Where is the information on how to >generate code for control structures? because, there are not control structure built into smalltalk, all condition evaluation are done through polymorphosim(hard to spell, yeh?) evaluation. Obviously, you havn't fully understood basic concepts of smalltalk. For example, expression 'x > 1 ifTrue: [exp1] ifFalse: [exp2]' are normal smalltalk expression with no control structure. Both 'ifTrue' and 'ifFalse' methods are in implemented in 'Boolean' class, but differently in 'True' and 'False' class. For reference, read 1981 Byte articles on smalltalk. >Basically I just need to know how the Smalltalk compiler is similar to >(for example) an ordinary C compiler, and how it is different. I also It is not matter of difference in compliler, it is matter of difference between compiler(source-host machine) to interpreter(source-VM bytecodes), In Smalltalk, you don't just consider language, you have to consider more than 300 library classes(some are more important than others). > >Please excuse my naive questions; I don't have access to a Smalltalk >system and learning from the book is frustrating. There are no naive questions, we all learn from simple questions. But you should play with smalltalk to really appreciate power and simplicity of Smalltalk system. There are two cheap ways to do it. (1) Get "little Smalltalk ", or (2) Smalltalk/V from Digitalk. But if you have some money, get a ParcPlace's Smalltalk, they are more true to the original smalltalk-80. -------------- Sehyo Chang Ascent Logic Corp. 180 Rose Orchard Way San Jose, CA 95134 (408) 943-0630 schang@netcom.uucp