Home
The SELF 4.1 Programmer`s Reference Manual
Contents
1. e string specifies that encrypt returns a string argument encrypt name of function we are constructing wrapper for e encrypt_glue name that we want the wrapper function to have An empty argument signifying that encrypt is not to be passed a failure handle explained later e string specifies that the first argument to encrypt is a string 13 e int specifies that the second argument to encrypt is an int Having written this file we now prepare a makefile to compile and link it To do this we can extend the makefile in objects glue sun4 svr4 depending on OS in use and then run make This results in the shared library file encrypt so Finally to try it out we can type these com mands at the SELF prompt or in the UD gt AddSlotsIfAbsent encrypt lobby gt encrypt foreignFct copyName encrypt glue Path encrypt so lobby encrypt Cr function encrypt glue encrypt value Hello Self With 3 KhoorfVhoi gt encrypt value Khoor Vhoi With 3 Hello Self Comparing the signature for the function encrypt with the arguments to the C_func_2 macro it is clear that there is a straightforward mapping between the two One day we hope to find the time to write a SELF program that can parse a C or C header file and generate glue code correspond ing to the definitions in it In the meantime glue code must be handwritten 7
2. The clone s se1 parent slot is initialized to the receiver of the message The clone s argument slots if any are initialized to the values of the corresponding actual arguments The code of the method is executed in the context of this new activation object For example consider the method arg arg arg self slots arg This method has an argument slot arg and returns the square of its argument The SELF World Objects 2 1 7 Blocks Blocks are SELF closures they are used to implement user defined control structures A block lit eral delimited by square brackets defines two objects the block method object containing the block s code and an enclosing block data object The block data object contains a parent pointer pointing to the object containing the shared behavior for block objects and a slot containing the block method object Unlike an ordinary method object the block method object does not contain a self slot Instead it has an anonymous parent slot that is initialized to point to the activation ob ject for the lexically enclosing block or method As a result implicit receiver messages 82 3 4 sent within a block method are lexically scoped The block method object s anonymous parent slot is invisible at the SELF level and cannot be accessed explicitly For example the block 3 4 looks like enclosing method s activation object traits block parent
3. getAnother anUnannotatedSlot A Annotations may nest if so the Virtual Machine concatenates the annotations strings and inserts a separator character 16r7f 2 3 Expressions Expressions in SELF are messages sent to some object the receiver SELF message syntax is sim ilar to Smalltalk s SELF provides three basic kinds of messages unary messages binary messag es and keyword messages Each has its own syntax associativity and precedence Each type of message can be sent either to an explicit or implicit receiver Productions The current programming environment expects a slot annotation to start with one of a number of keywords includ ing Category Comment and ModuleInfo Seethe programming environment manual for more details In order to simplify the presentation this grammar is ambiguous precedence and associativity rules are used to re solve the ambiguities 11 The SELF World Expressions expression gt constant unary message unary send binary message binary send keyword message keyword send receiver resend The table below summarizes SELF s message syntax rules lode eX we deu g constant unary message binary message keyword message C expression Y self number string object receiver unary send resend unary send identifier receiver binary send resend binary send operator expression r
4. In a similar vein blocks inherit default behavior that allows one to provide a block taking fewer arguments than expected For example the collection iteration message do expects a block taking two arguments a collection element and the key at which that element is stored If one is only in 59 SELF Styled Programming nil Considered Naughty terested in the elements not the keys one can provide a block taking only one argument and the second block argument will simply be ignored That is you can write myCollection do el el printLine instead of myCollection do el key el printLine 4 6 nil Considered Naughty As in Lisp SELF has an object called nil which denotes an undefined value The virtual machine initializes any uninitialized slots to this value In Lisp many programs test for nil to find the end of a list or an empty slot in a hash table or any other undefined value There is a better way in SELF Instead of testing an object s identity against nil define a new object with the appropriate behavior and simply send messages to this object SELF s dynamic binding will do the rest For ex ample in a graphical user interface the following object might be used instead of nil nullGlyph display self boundingBox 080 080 mouseSensitive false To make it easier to avoid nil the methods that create new vectors allow you to supply an alterna tive to nil as the initia
5. and can be evaluated by sending it the message value With to produce the sum of its argu ments Blocks are used to implement all control structures in SELF and allow the programmer to easily extend the system with customized control structures In fact all control stuctures in SELF except message sends returns and VM error handling are implemented using blocks 3 3 1 Booleans and Conditionals The fundamental control structure is the conditional In SELF the behavior of conditionals is de fined by two unique boolean objects t rue and false Boolean objects respond to the messages ifTrue ifFalse ifTrue False andifFalse True by evaluating the appropriate ar gument block For example t rue implements ifTrue False as ifTrue b1 False b2 bl value That is when t rue is sent ifTrue False it evaluates the first block and ignores the second For example the following expression evaluates to the absolute value of x x 0 ifTrue x negate False x The booleans also define behavior for the logical operations AND amp amp OR EXCLUSIVE OR and NOT not Because the binary boolean operators all send value to their argument when necessary they can also be used for short circuit evaluation by supplying a block e g 0 lt i amp amp i lt maxByte pred ifTrue Module boolean 3 3 2 Loops The various idioms for constructing loops in SELF are best illustrated by example
6. digit digit digit ome ome comment char ome any character but 25 The SELF World Syntax overview Appendix 2 C Syntax overview expression constant unary message unary send binary message binary send keyword message keyword send receiver resend object regular object block slot list annotated slot list unannotated slot list code slot arg slot data slot unary slot binary slot b 4 L1 d 4 4 4 4 4 4 d 4 4 bv d d 4 constant unary message binary message keyword message C expression Y self number string object receiver unary send resend unary send identifier receiver binary send resend binary send operator expression receiver keyword send resend keyword send small keyword expression cap keyword expression expression resend identifier regular object block CLUE Cp string slot list T code CL slot list code unannotated slot list annotated slot list U string slot list Y slot slot expression expression arg slot data slot binary slot keyword slot argument name slot name slot name lt expression slot name expression slot name regular object operator regular object operator identifier regular object In order to simplify the
7. decimal e E decimal general digit digit letter decimal digit digit base decimal T R Examples 123 16r27fe 1272 34e 15 1e10 2 4 7 Strings String constants are enclosed in single quotes With the exception of single quotes and escape sequences introduced by a backslash all characters including formatting characters like newline and carriage return lying between the delimiting single quotes are included in the string To allow single quotes to appear in a string and to allow non printing control characters in a string to be indicated more visibly SELF provides C like escape sequences Nt tab b backspace Nn newline Nf form feed Nr carriage return v vertical tab Na alert bell NO null character backslash single quote double quote XN question mark A backslash followed by an x d or o specifies the character with the corresponding numeric encoding in the ASCII character set xnn hexadecimal escape dnnn decimal escape onnn octal escape There must be exactly two hexadecimal digits for hexadecimal character escapes and exactly three digits for decimal and octal character escapes Illegal hexadecimal decimal and octal numbers as well as character escapes specifying ASCII values greater than 255 will cause a lexical error For example the following characters all denote the carriage return character ASCII code
8. For example 3 4 44 7 is interpreted as 3 4 7 But 3 4 7 is illegal the associativity must be made explicit by writing either 3t 2 Jor Some Precedence The precedence of binary messages is lower than unary messages but higher than key word messages All binary messages have the same precedence For example 3 factorial pi sine is interpreted as 3 factorial pi sine 2 3 3 Keyword messages A keyword message has a receiver and one or more arguments It is written as a receiver followed by a sequence of one or more keyword argument pairs The first keyword must begin with a lower case letter or underscore _ subsequent keywords must be capitalized An initial underscore de notes that the operation is a primitive A keyword message consists of the longest possible se quence of such keyword argument pairs the message selector is the concatenation of the keywords 13 The SELF World Expressions forming the message Message selectors beginning with an underscore are reserved for primitives 2 3 7 Example 5 min 4 Max 7 is the single message min Max sent to 5 with arguments 4 and 7 whereas 5 min 4 max 7 involves two messages first the message max sent to 4 and taking 7 as its argument and then the message min sent to 5 taking the result of 4 max 7 as its argument Associativity Keyword messages associate from right to left so 5 min 6 min 7 Max 8 Max 9 min 10 Max
9. It is possible however to write non behavioral programs in SELF For example a program that ex amines and manipulates the slots of an object directly rather than via messages is not behavioral since it is sensitive to the internal representation of the object Such programs are called reflective because they are reflecting on the objects and using them as data rather than using the objects to represent something else in the world Reflection is used to talk about an object rather that talking to it In SELF this is done with objects called mirrors There are times when reflection is unavoid able For example the SELF programming environment is reflective since its purpose is to let the programmer examine the structure of objects an inherently reflective activity Whenever possible however reflective techniques should be avoided as a matter of style since a reflective program may fail if the internal structure of its objects changes This places constraints on the situations in which the reflective program can be reused limiting opportunities for reuse and making program evolution more difficult Furthermore reflective programs are not as amenable to automatic anal ysis tools such as application extractors or type inferencers Programs that depend on object identity are also reflective although this may not be entirely obvi ous For example a program that tests to see if an object is identical to the object t rue may not behave as exp
10. SELF world see The SELF World 66 SELF Virtual Machine Reference The initial SELF world lobby snapshotAction snapshotAction postRead nil shell shell systemObjects je parent gt lobby systemObjects nil nil parent m lobby true E true false Eo parent gt lobby vector mW false byteVector RN parent 3M r lobby proxy objVector objVector parent T m T4 parent gt parent gt lobby smiMirror byteVector byteVector parent parent I parent m lobby floatMirror stringMirror proxy proxy parent parent parent M lobby processMirror fctProx fctProxy parent byteVectorMirror y YP parent parent gt lobby vectorMirror assignmentMirror smiMirror mirrorMirror parent _ slotsMirror reflectee 0 blockMirror methodMirror floatMirror blockMeth Mirror parent methodAct Mirror reflectee blockMe A Mirror slotAnnotation objectAnnotation profilerMirror profilerMirror p gt parent rT profiler proxyMirror fctProxyMirror Figure 3 The initial SELF world part 1 67 SELF Virtual Machine Reference The initial SELF world 0 int
11. lexicalParent parent value 344 pcc d p MMC UD PC d block block method The block method s selector is based on the number of arguments If the block takes no arguments the selector is value If it takes one argument the selector is value If it takes two arguments the selector is value With for three the selector is value With With and for more the se lector is just extended by enough With s to match the number of block arguments Block evaluation has two phases In the first phase a block object is created because the block is evaluated e g it is used as an argument to a message send The block is cloned and given a pointer to the activation record for its lexically enclosing scope the current activation record In the second phase the block s method is evaluated as a result of sending the block the appropriate vari ant of the value message The block method is then cloned the argument slots of the clone are filled in the anonymous parent slot of the clone is initialized using the scope pointer determined in phase one and finally the block s code is executed Itis an error to evaluate a block method after the activation record for its lexically enclosing scope has returned Such a block is called a non lifo block because returning from it would violate the last in first out semantics of activation object invocation This restriction is made primarily to allow activation records to be allocated from
12. Eistsand Proonty Queues coh t tet e een e Hr t 39 3 5 6 Constructing and Concatenating Collections eese 39 3 6 PANTS sette tte dab etn tar cit ca el aceasta utr Me soe E Ma ctu dd 40 3 7 MirtOLS 2uenco ha Cale a a a deiade Bk Bk eek es 40 3 8 FOES 123 Cho cu ene eo ee ae een MAU LIE ML DM eee rere 41 3 9 Processes and the PEOHDE see teeth esitare Dido dade A aa uae 41 SLO Eorerem ODIects aseet a aae trae E T o totes EE E 42 ee meee Of Jk UIS ERE SU 43 312 Other CVC ste boc tU a r a a a ct boe og a cl 44 313 How t b ild th world ieee ON n sie i a uns 45 3 14 How to use the low level interrupt facilities seen 46 3 15 Using the textual debugger essere nennen nemen trennen 47 Appendix 3 A Gl ssary or Usehul Selectats un oen c eta ei tu eda e Re adde 48 Introduction A Guide to Programming Style 55 4 1 4 2 4 3 44 4 5 4 6 4 7 4 8 Behaviorism versus Reflection treten teretes 55 Objects Have Many Roles ses ved Ebert aio a es 56 ADA Shared Behavior coe eee eee dete repeti bu 56 4 2 70 One of a kind Objects Oddballs eese esee eene enne nennen 56 42 3 Inhne OD Jectsussu o eh eee o Gere erede eee eee e aere erede eed 57 Naming ard PONUDE siae rte adi etand ae eod Reeth 57 4 3 1 How objects are printed sseni ae ae eene enne rennen eene nennen nenne 57 43 2 Howtomake an obJect prit uec erbe te e e Ee RH 58 How to Re
13. The first argument to the Perform primitive the selector wasn t a canonical string These error messages are just like any other message Therefore it is possible that the object P causing the error which is being sent the appropriate error message does not understand the error message M either If this happens the system sends the first message undefinedSelector to the current process with the error message M as argument If this is not understood then the sys tem suspends the process If the scheduler is running it is notified of the failure The system will also suspend a process if it runs out of stack space too much recursion or if a block is evaluated whose lexically enclosing scope has already returned Since these errors are nonrecoverable they cannot be caught by the same SELF process the scheduler if running is noti fied 5 4 Low level error messages Five kinds of errors can occur during the execution of a SELF program lookup errors primitive er rors programmer defined errors non recoverable errors and fatal VM errors All but the last of these are usually caught and handled by mechanisms in the programming environment resulting in a debugger being presented to the user However if programs are run without the programming 63 SELF Virtual Machine Reference Low level error messages environment or the error handling mechanisms themselves are broken low level error facilities are used This section
14. With And to the fct Proxy representing it Note that fctProxy objects are low level Most if not all uses of foreign routines should use the interface provided by for eignFct objects Proxies and fct Proxies can be freely cloned However a cloned proxy will be dead A dead proxy is revived when it is used by a foreign function to e g return a pointer The return value of the foreign function together with a type seal is stored into the dead proxy which is then revived and returned as the result of the foreign routine call The motivation for this somewhat complicated approach is that there will be several different kinds of proxies in a typical SELF system Different kinds of proxies may have different slots added so rather than having the foreign routine figure out which kind of proxy to clone for the result the SELF code calling the foreign routine must con struct and pass down an empty dead proxy to hold the result This proxy is called a result proxy and it is the last argument supplied to the foreign function 71 SELF Virtual Machine Reference Interfacing with other languages 5 13 2 Glue code Glue code is responsible for the transition from SELF to foreign routines It forms wrappers around foreign routines There is one wrapper per foreign routine A wrapper takes a number of arguments of type oop and returns an oop oop is the C type for reference to SELF object When a wrapper is executed it performs the
15. each co lon terminated identifier in a keyword slot name requires a corresponding argument slot in the key word method object and the argument slots may be specified either all in the method or all interspersed with the selector parts For example an ifTrue False trueBlock falseBlock trueBlock value ifTrue trueBlock False falseBlock trueBlock value produce identical objects 10 The SELF World Expressions 2 2 4 Parent slots A unary slot name followed by an asterisk denotes a parent slot The trailing asterisk is not part of the slot name and is ignored when matching the name against a message Except for their special meaning during the message lookup process 2 3 8 parent slots are exactly like normal unary slots in particular they may be assignable allowing dynamic inheritance Argument slots cannot be parent slots 2 2 5 Annotations In order to provide extra information for the programming environment SELF supports annota tions on either whole objects or individual slots Although any object can be an annotation the SELF syntax only supports the textual definition of string annotations In order to annotate an ob ject use this syntax this object has one slot snort 17 In order to annotate a group of slots surround them with braces and insert the annotation after the opening brace CI Category accessing getOne
16. its parent is switched from traits emptyTrees set which holds behavior for empty sub trees to a new copy of treeSetNode which represents a tree node holding an el ement Thus the treeSet object now behaves as a treeSetNode object with right and left sub trees initially copies of the empty subtree treeSet Dynamic inheritance allows one object to behave modally without using clumsy if tests throughout every method One caveat since these trees are not balanced they can degenerate into lists if their elements are added in sorted order However a more complex tree data structure might obscure the main point of this implementation to provide a canonical example of the use of dynamic inheritance Modules tree 3 5 5 Lists and PriorityQueues collection list priorityQueue A list is an unkeyed circular doubly linked list of objects Additions and removals at either end are efficient but removing an object in the middle is less so as a linear search is involved A priorityQueue is an unkeyed unordered collection with the property that the element with the highest priority is always at the front of the queue Priority queues are useful for sorting heapsort and scheduling The default comparison uses but this can be changed Modules list priorityQueue 3 5 6 Constructing and Concatenating Collections clonable collector Two kinds of objects play supporting roles for collections A collector object is creat
17. parent a parent slot con taining the same object for all canonical strings see parent below All canonical strings share this parent the string traits object Blocks have two slots parent a parent slot containing the same object for all blocks see parent below and value or value or value With etc depending on the number of arguments the block takes which contains the block s deferred method All blocks share this parent the block traits object All of the prototypical mirrors consist of one slot a parent slot named parent Each of these parent slots points to an empty object denoted in Figure 5 by Prototypical mirror on a small integer the reflectee is 0 Prototypical mirror on a float the reflectee is 0 0 Prototypical mirror on a canonical string the reflectee is the empty canonical string Prototypical mirror on a process the reflectee is the initial process Prototypical mirror on a byte vector the reflectee is the prototypical byte vector Prototypical mirror on object vectors the reflectee is the prototypical object vector Mirror on the assignment primitive the actual reflectee is an empty object Prototypical mirror on a mirror the reflectee is sLot sMirror Prototypical mirror on a plain object without code the reflectee is an empty object Prototypical mirror on a block Prototypical mirror on a normal method Prototypical mirror on a block method methodActivationM
18. 3 5 3 Run time message lookup errors If an error occurs during a message send the system sends a message to the receiver of the mes sage Any object can handle these errors by defining or inheriting a slot with the corresponding selector All messages sent by the system in response to a message lookup error have the same ar guments The first argument is the offending message s selector the additional arguments specify the message send type one of normal implicitSelf undirectedResend di rectedResend or delegated the directed resend parent name or the delegatee 0 if not applicable the sending method holder and a vector containing the arguments to the message if any undefinedSelector Type Delegatee MethodHolder Arguments The receiver does not understand the message no slot matching the selector can be found in the receiver or its ancestors ambiguousSelector Type Delegatee MethodHolder Arguments There is more than one slot matching the selector missingParentSelector Type Delegatee MethodHolder Arguments The parent slot through which the resend should have been directed was not found in the send ing method holder mismatchedArgumentCountSelector Type Delegatee MethodHolder Arguments The number of arguments supplied to the Perform primitive does not match the number of arguments required by the selector performTypeErrorSelector Type Delegatee MethodHolder Arguments
19. Put is used to update an element of a mutableIndexable collection other than a sortedSequence Modules indexable abstractString vector sequence sortedSequence 3 5 2 Strings Characters and Paragraphs collection byteVector string mutableString immutableString canonicalString A string is a vector whose elements are character objects There are three kinds of concrete string immutable strings mutable strings and canonical strings traits string defines the behavior shared by all strings A character is a string of length one that references itself in its sole indexable slot Mutable strings can be changed using the message at Put which takes a character argument or at PutByte which takes an integer argument An immutable string cannot be modified but sending it the copyMut able message returns a mutable string containing the same characters Canonical strings are registered in an table inside the virtual machine like Symbol objects in Smalltalk or atoms in LISP The VM guarantees that there is at most one canonical string for any given sequence of bytes so two canonical strings are equal have the same contents if and only if they are identical are the same object This allows efficient equality checks between canonical strings All message selectors and string literals are canonical strings and some primitives require canonical strings as arguments Sending canonicalize to any string returns the corresponding ca
20. World Blocks Booleans and Control Structures the entire system although there are many references to it On the other hand a list object is not unique There may be many lists in the system each containing different elements A unique object responds to the message copy by returning itself and uses identity to test for equality The general rule is unique objects usually inherit from traits oddball non unique objects usually inherit from traits clonable Module rootTraits 3 2 3 Mixins Like traits objects mixin objects encapsulate a bundle of shared behavior Unlike traits objects however mixin objects are generally parentless to allow their behavior to be added to an object without necessarily also adding unwanted behavior such as access to the lobby namespace Mix ins are generally used in objects that also have other parents An example is mixins identity 3 2 4 The Identity Mixin Two objects are usually tested for equality based on whether they have the same value within a common domain For example 3 0 3 within the domain of numbers even though they are not the same object or even the same kind of object In some domains however two objects are equal if and only if they are the exact same object For example even two process objects with the same state are not considered equal unless they are identical In such cases identity comparison is used to implement equality tests and mixins identity can be m
21. a stack A future release of SELF may relax this restriction at least for blocks that do not access variables in enclosing scopes All block objects have the same parent an object containing the shared behavior for blocks The SELF World Slot descriptors 2 1 8 Returns A return is denoted by preceding an expression by the operator A return causes the value of the given expression to be returned as the result of evaluating the method or block Only the last ex pression in an object may be a return The presence or absence of the operator does not effect the behavior of ordinary methods since an ordinary method always returns the value of its final expression anyway In a block however a return causes control to be returned from the ordinary method containing that block immediately terminating that method s activation the block s activation and all activations in between Such a return is called a non local return since it may return through a number of activations The result of the ordinary method s evaluation is the value returned by the non local return For example in the following method assertPositive x x c0 TflIruerz p ook error non positive x the error message will not be sent if x is positive because the non local return of ok causes the assertPositive method to return immediately 2 1 9 Construction of object literals Object literals are constructed during parsing
22. alignment in memory badIndexError The vector index e g in At is out of bounds too large or negative 93 SELF Virtual Machine Reference Primitives badSizeError reflectTypeError outOfMemoryError stackOverflowError slotNameError argumentCountError unassignableSlotError lonelyAssignmentSlotError parallel TWAINSError noProcessError noActivationError noReceiverError noParentSlot noSenderSlot deadProxyError liveProxyError wrongNoOfArgsError nullPointerError nullCharError prematureEndOfInputError noDynamicLinkerError EPERM ENOENT The An invalid size of a vector was specified e g attempting to clone a vector with a negative size see Clone Filler and CloneBytes Filler below A mirror primitive was applied to the wrong kind of slot MirrorParentGroupAt to a slot that isn t a parent slot e g A primitive could not complete because its results would not fit in the existing space The stack overflowed during execution of the primitive or program Illegal slot name Wrong number of arguments This slot is not assignable Assignment slot must have a corresponding data slot Can not invoke TWAINS primitive another process is already using it This process does not exist This method activation does not exist This activation has no receiver This activation has no lexical parent This activation has no sender slot This proxy is dead and can not be used This proxy is live
23. and can not be used to hold a proxy result Wrong number of arguments was supplied with call of foreign function Foreign function returned null pointer Can not pass byte vector containing null char to foreign function expecting a string Premature end of input during parsing Primitive depends on dynamic linker which is not available in this system These errors are returned by a UNIX primitive if a UNIX system call executed by the primitive fails The UNIX error codes are defined in usr include sys errno h see this file for details on the roughly 90 different UNIX error codes _ErrorMessage primitive sent to an error string returned by any primitive returns a more descriptive version of the error message this is especially useful for UNIX errors 5 B 2 Available primitives A complete list of primitives can be obtained by sending primitiveList to primitives Doc umentation for a primitive such as _Clone can be obtained using at thus primitives at Clone A list of primitive names matching a pattern can be obtained thus primitives match Memory Some points to note when browsing primitives 94 SELF Virtual Machine Reference Primitives e Since strings are special kinds of byte vectors primitives taking byte vectors as arguments can usually take strings The exception is that canonical strings cannot be passed to primi tives that modify the object nteger arithmetic primitives take inte
24. criteria Indexable specific firstKey return the first key lastKey return the last key loopFrom Do circularly iterate starting from element n copyAddFirst return a copy of this collection with element added to beginning copyAddLast return a copy of this collection with element added to end copyFrom return a copy of this collection from element n copyFrom UpTo return a copy of this collection from element n up to element m copyWithoutLast return a copy of this collection without the last element copySize copy with size n copySize FillingWith copy with size n filling in any extra elements with second arg Timing realTime elapsed real time to execute a block cpuTime CPU time to execute a block userTime CPU time in user process to execute a block systemTime CPU time in system kernel to execute a block totalTime system user time to execute a block 52 The SELF World Glossary of Useful Selectors Message Sending Sending like Smalltalk perform receiver is a string sendTo With send receiver string as a message sendTo WithArguments indirect send with arguments in a vector sendTo DelegatingTo With indirect delegated send sendTo DelegatingTo WithArguments indirect delegated send with arg vector resendTo With indirect resend resendTo WithArguments indirect resend with arguments in a vector Message object protocol send perform the send described by a message object fork start a
25. defined control structures An object is composed of a possibly empty set of slots and optionally code 2 1 5 A slot is a name value pair slots contain references to other objects When a slot is found during a message lookup 82 3 6 the object in the slot is evaluated Although everything is an object in SELF not all objects serve the same purpose certain kinds of objects occur frequently enough in specialized roles to merit distinct terminology and syntax This chapter introduces two kinds of objects namely data objects plain objects and the two kinds of objects with code ordinary methods and block methods 2 1 1 Syntax Object literals are delimited by parentheses Within the parentheses an object description consists of a list of slots delimited by vertical bars followed by the code to be executed when the ob ject is evaluated For example The SELF World Objects slotl slot2 here is some code printLine Both the slot list and code are optional and each denote an empty object Block objects are written like other objects except that square brackets and are used in place of parentheses slotl slot2 here is some code in a block printLine A slot list consists of a possibly empty sequence of slot descriptors 2 2 separated by periods A period at the end of the slot list is optional The code for an object is a sequence of expressions 2 3 separ
26. detail in the following sections 5 13 1 Proxy and fctProxy objects A foreign object is represented by a proxy object in the SELF world A proxy object is an object that encapsulates a pointer to the foreign object it represents In addition to the pointer to the for eign object the proxy object contains a type seal A type seal is an immutable value that is assigned to the proxy object when it is created The type seal is intended to capture type information about the pointer encapsulated in the proxy For example proxies representing window objects should have a different type seal than proxies representing event objects By checking the type seal against an expected value whenever a proxy is opened many type errors can be caught The last property of proxy objects is that they can be dead or live If an attempt is made to use the pointer in a dead proxy object an error results deadProxyError Proxy objects may be explicitly killed by sending the primitive message _Kil1 to them Furthermore they are automatically killed after reading in a snapshot This way problems with dangling references to foreign objects that were not included in the snapshot are avoided FctProxy objects are similar to proxy objects they have a type seal and are either live or dead However they represent a foreign routine rather than a foreign object A foreign routine can be in voked by sending the primitive messages _Call _Call With _CallAndConvert
27. following steps 1 Check that the arguments supplied have the correct types 2 Convert the arguments from SELF representation to the representation that the foreign routine needs 3 Invoke the foreign routine on the converted arguments 4 Convert the return value of the foreign routine to a SELF object and return this as the SELF level result To make it easier to write glue code a special purpose language has been designed for this The result is that glue for a foreign routine will often consist of only a single line The glue language is implemented as a set of C preprocessor macros Therefore glue code is just a rather peculiar kind of C Glue code can be in a file of its own or if it is glue for calling C routines it can be in the same file as the foreign routines and compiled with them To make the definition of the glue language available the file containing glue code must contain include glueDefs c incl g The file glueDefs c incl includes a bunch of C header files that contain all the definitions necessary for the glue Of the included files glueDefs h is probably the most interesting in this context It defines the glue language and also contains some comments explaining it Since different foreign languages have different type systems and calling conventions the glue lan guage is actually not a single language but one for each supported foreign language Presently C and C are support
28. from other objects is an implementation detail improving scavenging and scanning performance see Lee88 and CUL89 for details 91 SELF Virtual Machine Reference The system monitor Color Meaning black Allocated residing in real memory gray Allocated paged out white Unallocated memory The residency information is updated only once a second for efficiency reasons all other information is updated continuously Also the gray area does not indicate what is paged out only how much 92 SELF Virtual Machine Reference Primitives Appendix 5 B Primitives Primitives are SELF methods implemented by the virtual machine The first character of a primi tive s selector is an underscore _ You cannot define primitives yourself unless you modify the Virtual Machine nor can you define slots beginning with an underscore 5 B 1 Primitive failures Every primitive call can take an optional argument defining how errors should be handled for this call To do this the primitive is extended with an 1 Fail argument For example AsObject becomes _AsObjectIfFail and _IntAdd becomes IntAdd IfFail gt 3 IntAdd a IfFail error name name failed with error printLine 0 IntAdd failed with badTypeError The primitive returns the result of evaluating the failure block Vo When a primitive fails if the primitive call has an 1 Fail part the message value With
29. if D 0 then error missing delegatee one or none M lookup smh del sel do the lookup case IMIzO error message not understood IMI 1 res lt eval rec M args see 2 1 IMI E error ambiguous message send end return res 2 4 Lexical elements This chapter describes the lexical structure of SELF programs how sequences of characters in SELF source code are grouped into lexical tokens In contrast to syntactic elements described by productions in the rest of this document the elements of lexical EBNF productions may not be sep arated by whitespace i e there may not be whitespace within a lexical token Tokens are formed from the longest sequence of characters possible Whitespace may separate any two tokens and must separate tokens that would be treated as one token otherwise 2 4 1 Character set SELF programs are written using the following characters Letters The fifty two upper and lower case letters ABCDEFGHIJKLMNOPQRSTUVWXY Zabcdefghijklmnopqrstuvwxyz Digits The ten numeric digits 0123456789 18 The SELF World Lexical elements Whitespace The formatting characters space horizontal tab ASCII HT newline NL carriage return CR vertical tab VT backspace BS and form feed FF Comments are also treated as whitespace Graphic characters The 32 non alphanumeric characters IG4STo amp N OS lt gt 2 4 2 Identifiers An identifier is a sequence of le
30. integer square square root factorial fibonacci signum 1 0 1 true if receiver is even true if receiver is odd Bitwise operations integers amp amp Il AN complement lt lt gt gt lt gt and or xor bitwise complement logical left shift logical right shift arithmetic left shift arithmetic right shift Logical operations booleans amp amp and I or ahs xor not logical complement Constructing point construction receiver and argument are integers rectangle construction receiver and argument are points THE rectangle construction receiver is a point argument is an extent amp collection construction result can be converted into collection concatenation Printing print print object on stdout printLine print object on stdout with trailing newline printString return a string label 49 The SELF World Glossary of Useful Selectors printStringDepth printStringSize printStringSize Depth Control return a string label with depth limitation request return a string label with number of characters limitation request return a string label with depth and size limitation request Block evaluation value With evaluate a block passing arguments Selection if True evaluate argument if receiver is true ifFalse evaluate argument if receiver is false if Irue False ifFalse True Local exiting evaluate first arg if
31. integer 69 K keyword see message Keywords 19 L ld so 73 Link 71 liveProxyError 94 100 Introduction lobby 67 68 lonelyAssignmentSlotError 94 lookup 24 lookup algorithm 17 M message 23 binary message 13 23 implicit receiver message 14 23 keyword message 10 13 23 message lookup 24 semantics 15 unary message 12 23 method 5 block method see block outer method 23 method activation object 5 method holder 23 sending method holder 23 mirrorMirror 69 mirrors 69 mismatchedArgumentCountSelector Type Delegatee MethodHolder Arguments 63 missingDelegateeSelector Type Delegatee MethodHolder Arguments 63 N nil 24 68 noActivationError 94 noDynamicLinkerError 94 non decimal number 20 non lifo block 6 non local return 7 23 non local return operator 4 noParentSlot 94 noProcessError 94 noReceiverError 94 noSenderSlot 94 nullCharError 94 nullPointerError 94 Numbers 20 o object 3 23 data object 4 23 method object 5 object literals 3 construction of 7 objVector 68 objVectorMirror 69 operator 20 outerActivationMirror 69 outerMethodMirror 69 outOfMemoryError 94 overflowError 93 P parallel TWAINSError 94 parent slot 11 24 performTypeErrorSelector Type Delegatee MethodHolder Arguments 63 precedence of message sends 13 14 prematureEndOfInputError 94 primitive 19 primitive failure codes 93 101 Introduction primitive failures 93 primitive send 16 23 primitive FailedWith
32. is used instead The integer is interpreted as a UNIX error num ber from which a corresponding string is constructed The string is then as for ailure passed to the IfFail block at the call site in SELF A word of warning after calling failure or unix failure a normal return must be done The value returned in the example NULL is ignored The any conversion is the lone exception it takes two SELF objects and produces one C argument 76 SELF Virtual Machine Reference Interfacing with other languages 5 13 7 Reading and assigning global variables Reading the value of a global variable is done using the C get var macro Assigning a value to a global variable is done using C_set_var Both macros expand into a C function that converts between SELF and C representation and reads or assigns the variable Here is the general syntax C_get_var cnvt_res aux_res expr gfname C set var var expr cO expr a0 gfname A concrete example is reading the value of the variable errno which can be done using C get var int errno get errno glue The meaning of the each argument is e cnvt res aux res how to convert the value of the global variable that is being read to a SELF object In the errno example cnvt_res is int and aux res is empty since the type of errno is int The cnvt res aux res can be any one of the result conversions found in Table 3 expr is the variable whose value is being read In the err
33. mirrors on all objects with a parent slot referring to the given object up to the limit implementorsOf Limit returns a vector of mirrors on objects with slots whose names match the given selector up to the limit 53 The SELF World Glossary of Useful Selectors sendersOf Limit returns a vector of mirrors on methods whose selectors match the given selector up to the limit Debugging halt halt the current process halt halt and print a message string error halt print an error message and display the stack warning beep print a warning message and continue Virtual Machine Generated Errors undefinedSelector Type Delegatee MethodHolder Arguments lookup found no matching slot ambiguousSelector Type Delegatee MethodHolder Arguments lookup found more than one matching slot missingParentSelector Type Delegatee MethodHolder Arguments parent slot through which resend was delegated was not found performTypeErrorSelector Type Delegatee MethodHolder Arguments first argument to the _Perform primitive was not a canonical string mismatchedArgumentCountSelector Type Delegatee MethodHolder Arguments number of args supplied to Perform primitive does not match selector primitiveFailedError Name the named primitive failed with given error string Other system triggered messages postRead slot to evaluate after reading a snapshot 54 4 A Guide to Programming Style This section discusses some
34. only use dy namic linking as static linking requires more understanding of the structure of the Virtual Ma chine The choice between dynamic and static linking involves a trade off between safety and flexibility as outlined in the following Dynamic linking has the advantage that it is done on demand so only foreign routines that are ac tually used in a particular session will be loaded and take up space Debugging foreign routines is also easier especially if the dynamic linker supports unlinking The main disadvantages with dy namic linking is that more things can go wrong at run time For example if an object file contain ing a foreign routine can not be found a run time error occurs The Sun OS dynamic linker ld so only handles dynamic libraries which explains why the second stage of glue translation is neces sary Static linking the alternative that was not chosen for SELF has the advantage that it needs to be done only once The statically linked in files will then be available for ever after The main disad vantages are that the linked in files will always take up space whether used or not in a given SELF session that the VM must be completely relinked every time new code is added and that debug ging is harder because there is no way to unlink code with bugs in For these reasons the following examples all use dynamic linking 5 13 4 A simple glue example calling a C function Suppose we have a C function that encrypts te
35. programming idioms and stylistic conventions that have evolved in the SELF group Rather than simply presenting a set of rules an attempt has been made to explain the reasons for each stylistic convention While these conventions have proven useful to the SELF group they should be taken as guidelines not commandments SELF is still a young language and it is likely that its users will continue to discover new and better ways to use it effectively 4 1 Behaviorism versus Reflection One of the central principles of SELF is that an object is completely defined by its behavior that is how it responds to messages This idea which is sometimes called behaviorism allows one ob ject to be substituted for another without ill effect provided of course that the new object s be havior is similar enough to the old object s behavior For example a program that plots points in a plane should not care whether the points being plotted are represented internally in cartesian or po lar coordinates as long as their external behavior is the same Another example arises in program animation One way to animate a sorting algorithm is to replace the collection being sorted with an object that behaves like the original collection but as a side effect updates a picture of itself on the screen each time two elements are swapped behaviorism makes it easier to extend and reuse pro grams perhaps even in ways that were not anticipated by the program s author
36. the option primitives can be thought of as primitive variables Invoking the version of the primitive that doesn t take an argument returns the current setting invoking it with an argument sets the variable to the new value and returns the old value Try running the system monitor with Spy true The system monitor will continuously display various information about the system s activities and your memory usage The bracketed colon indicates that the argument is optional i e there are two versions of the primitive one taking an argument and one not taking an argument The bracket is not part of the primitive name See text for details 70 SELF Virtual Machine Reference Interfacing with other languages 5 13 Interfacing with other languages This chapter describes how to access objects and call routines that are written in other languages than SELF We will refer to such entities as foreign objects and foreign routines A typical use would be to make a function found in a C library accessible in SELF Three steps are necessary to accomplish this Write and compile a piece of glue code that specifies argument and result types for the foreign routine and how to convert between these types and SELF objects Link the resulting object code to the SELF virtual machine Create a function proxy object actually a foreignFct object that represents the routine in the SELF world Each of these steps is described in
37. true second arg if false evaluate first arg if false second arg if true exit exitValue Basic looping exit block and return nil if block s argument is evaluated exit block and return a value if block s argument is evaluated loop loopExit loopExitValue Pre test looping repeat the block forever repeat the block until argument is evaluated then exit and return nil repeat the block until argument is evaluated then exit and return a value whileTrue whileFalse whileTrue whileFalse Post test looping repeat the receiver until it evaluates to true repeat the receiver until it evaluates to false repeat the receiver and argument until receiver evaluates to true repeat the receiver and argument until receiver evaluates to false until True repeat the receiver and argument until argument evaluates to true untilFalse repeat the receiver and argument until argument evaluates to false Iterators do iterate passing each element to the argument block to By Do iterate with stepping to Do iterate forward upTo By Do iterate forward without last element with stepping upTo Do iterate forward without last element downTo By Do reverse iterate with stepping downTo Do reverse iterate 50 The SELF World Glossary of Useful Selectors Collections Sizing isEmpty test if collection is empty size return number of elements in collection Adding add add argument element to collec
38. tup after reading the snapshot and evaluates the contents Useful for set ting options installing personal shortcuts etc Prints a message describing the options Suppresses execution of the expression snapshotAction postRead af ter reading a snapshot Useful if something in the startup sequence causes the system to break Reads initial world from snapshot A snapshot begins with the line exec Self s 0 SQ which causes the Virtual Machine to begin execution with the snapshot Don t print warnings about object code These options are provided for use by SELF VM implementors F logfile r t Discards any machine code saved in the snapshot If the code in a snapshot is for some reason corrupted but the objects are not this option can be used to recover the snapshot Writes a log of events generated by the spy to logfile Disables real timer interrupts Disables all timers Other command line options are ignored by the Virtual Machine but are available at SELF level via the primitive _CommandLine 5 2 System triggered messages Certain events cause the system to automatically send a message to the lobby After reading a snap shot the expression snapshotAction postRead is evaluated This allows the SELF world to reinitialize itself for example to reopen windows 62 SELF Virtual Machine Reference Run time message lookup errors There are other situations in which the system sends messages see section 5
39. type ptr_type proxy a UNIX error 4 5 8 o type_seal n fct_proxy ptr_type ptr_type fctProxy nullPointerError 3 6 8 type seal arg count fct proxy null ptr type ptr type fctProxy 6 8 type seal arg count oop oop corresponding 7 8 object 1 This conversion returns an integer value unless the integer has the value n the second part of the conversion often 1 If the integer is n the conversion interprets the return value as a UNIX error indicator It then constructs a string describing the error by looking at errno and invokes the IfFail block with this string 2 Precision may be lost 3 This conversion fails with nullPointerError if attempting to convert a NULL pointer 4 The ptr type is the C C type of the pointer The type seal is an expression of type int or char The conversion constructs a new proxy object stores the C C pointer in it and sets its type seal to be the value of type seal 5 If the pointer is n often n is NULL the conversion fails with a UNIX error similar to the way int or errno may fail 6 The ct proxy fct proxy null and fct proxy or errno conversions are similar to the corresponding proxy conversions The difference is that they produce a fct Proxy object rath er than a proxy object Also their second part is a triple rather than a pair The extra component specifies how many arguments the function takes if called The special keyword unknownNoO fA
40. with indexable slots vectors via a set of primitives A data object is an object without code A data slot is a slot holding a data object An assignment slot is a slot containing the assignment primitive An assignable data slot is a data slot for which there is a corresponding assignment slot whose name consists of the data slot s name followed by a colon When an assignment slot is evaluated its argument is stored in the corresponding data slot An ordinary method or simply method is an object with code and is stored as the contents of a slot The method s name also called its selector is the name of the slot in which it is stored A block is an object representing a lexically scoped closure similar to a Smalltalk block A block method is the method that is executed when a block is evaluated by sending it value value value With etc A block method is a special kind of method that is evaluated within the scope of its method and any lexically enclosing blocks An activation object records the state of an executing method or block method It is a clone of the method prototype used to store the method s arguments and local slots during execution There are two kinds of activation objects ordinary method activation objects or simply meth od activation objects and block method activation objects A non lifo block is a block that is evaluated after the activation of its lexically enclosing block or method has returned This
41. 11 is interpreted as 5 min 6 min 7 Max 8 Max 9 min 10 Max 11 The association order and capitalization requirements are intended to reduce the number of paren theses necessary in SELF code For example taking the minimum of two slots m and n and storing the result into a data slot i may be written as i m min n Precedence Keyword messages have the lowest precedence For example i 5 factorial pi sine is interpreted as i 5 factorial pi sine 2 3 4 Implicit receiver messages Unary binary and keyword messages are frequently written without an explicit receiver Such messages use the current receiver se1 as the implied receiver The method lookup however be gins at the current activation object rather than the current receiver see 2 1 4 for details on acti vation objects Thus a message sent explicitly to self is not equivalent to an implicit receiver send because the former won t search local slots before searching the receiver Explicitly sending messages to self is considered bad style Examples factorial implicit receiver unary message 3 implicit receiver binary message 14 The SELF World Expressions max 5 implicit receiver keyword message 1 power 3 parsed as 1 power 3 Accesses to slots of the receiver local or inherited are also achieved by implicit message sends to self For an assignable data slot named t the message t returns the contents and t 17 puts 17 in
42. 13 XE x0d d013 o015 A long string may be broken into multiple lines by preceding each newline with a backslash Such escaped newlines are ignored during formation of the string constant When typing strings in the graphical user interface accepts multi line strings but the character based read eval print loop does not 21 The SELF World Lexical elements A backslash followed by any other character than those listed above will cause a lexical error Productions string normal char escape char normal char any character except and escape char Se ONE ala Ne ae LS pap POS Io ee N numeric escape numeric escape x general digit general digit N o digit digit digit 2 4 8 Comments Comments are delimited by double quotes Double quotes may not themselves be embedded in the body of a comment All characters including formatting characters like newline and carriage return are part of the body of a comment Productions en en comment gt comment char en comment char any character except Example this is a comment p 22 The SELF World Glossary Appendix 2 A Glossary A slot is aname value pair The value of a slot is often called its contents An object is composed of a possibly empty set of slots and optionally a series of expressions called code The SELF implementation provides objects
43. 4 SELF Virtual Machine Reference Interfacing with other languages 5 13 5 C glue C glue supports accessing C functions and data from SELF There are three main parts of C glue Calling functions Reading assigning global variables Reading assigning a component in a struct that is represented by a proxy object in SELF In addition C glue for creating objects can be used to create C structs see section 5 13 9 The following sections describe each of these parts of C glue 5 13 6 Calling C functions The macro C func N where N is 0 1 2 is used to glue in a C function The number N denotes the number of arguments that should be given at the SELF level when calling the function This number may be different from the number of arguments that the C function takes since e g some argument conversions see below produce two C arguments from one SELF object Here is the general syntax for C func N C func N res cnv res aux fexp gfname fail opt c0 a0 cN aN Compare this with the glue that was used in the encrypt example in section 5 13 4 C func 2 string encrypt encrypt glue string int The meaning of each argument to C_func_N is as follows e res cnv res aux these two arguments form a conversion pair that specifies how the result that the function returns is converted to a SELF object In the encrypt example where the function returns a null terminated string res cnv has the value stri
44. 93 primitiveFailedError 93 primitiveNotDefinedError 93 primitives 93 processMirror 69 prototype 24 prototypes 1 proxy 42 68 71 R read write variable 9 reflectTypeError 94 resend 15 19 24 result conversion 84 root context 8 24 S selector 23 self 5 9 19 SELF world 1 sending method holder 23 shell 68 slot 3 23 anonymous parent 6 argument slot 5 10 19 24 assignable data slot 9 assignment slot 4 8 data slot 8 23 initialization 8 11 parent slot 11 24 read write slot 8 read only slot 8 self slot 5 9 slot list 4 slotNameError 94 slotsMirror 69 smiMirror 69 snapshot 71 snapshotAction 68 stackOverflowError 94 Static linking 73 String constants 21 string escape sequences 21 strings 69 canonical strings 69 struct 77 system monitor spy 90 systemObjects 68 T traits 1 traits object 6 24 true 68 type seal 71 U unary message see message unassignableSlotError 94 undefinedSelector Type Delegatee MethodHolder Arguments 63 Unix error codes 94 unix_failure glue 76 102 Introduction V variable see slot Virtual Machine see VM VM 1 WwW WHAT_GLUE 74 wrapper 72 wrongNoOfArgsError 94 103
45. Here is an endless loop E loop Here are two loops that test for their termination condition at the beginning of the loop proceed whileTrue ERG quit whileFalse In each case the block that receives the message repeatedly evaluates itself and if the termination condition is not yet met evaluates the argument block The value returned by both loop expres sions is nil It is also possible to put the termination test at the end of the loop ensuring that the loop body is executed at least once 33 The SELF World Blocks Booleans and Control Structures untilTrue quit untilFalse proceed Here is a loop that exits from the middle when quit becomes true exit quit ifTrue exit loopExit For the incurably curious the parameter to the user s block supplied by the LoopExit method is simply a block that does a return from the 1oopExit method Thus the loop terminates when exit value is evaluated The con structs 1oopExitValue exit and exitValue are implemented in a similar manner The value returned by the overall loopExit expression is nil Here is a loop expres sion that exits and evaluates to a value determined by the programmer when quit becomes true exit quit ifTrue exit value expr loopExitValue Module block 3 3 3 Block Exits It is sometimes convenient to exit a block early without execut
46. The SELF 4 1 Programmer s Reference Manual Ole Agesen Lars Bak Craig Chambers Bay Wei Chang Urs H lzle John Maloney Randall B Smith David Ungar Mario Wolczko Copyright c 1995 1999 2000 Sun Microsystems Inc and Stanford University All Rights Reserved Sun Microsystems Inc 901 San Antonio Road Palo Alto CA 94303 USA RESTRICTED RIGHTS LEGEND Use duplication or disclosure by the government is subject to restrictions as set forth in subparagraph c 1 i1 of the Rights in Technical Data and Computer Software Clause at DFARS 252 227 7013 Oct 1988 and FAR 52 227 19 c June 1987 SOFTWARE LICENSE The software described in this manual may be used internally modified copied and distrib uted to third parties provided each copy of the software contains both the copyright notice set forth above and the dis claimer below DISCLAIMER Sun Microsystems Inc makes no representations about the suitability of this software for any pur pose It is provided to you AS IS without express or implied warranties of any kind Sun Microsystems Inc dis claims all implied warranties of merchantability fitness for a particular purpose and non infringement of third party rights Sun Microsystems Inc s liability for claims relating to the software shall be limited to the amount if any of the fees paid by you for the software In no event will Sun Microsystems Inc be liable for any special indirect inciden tal consequential
47. This object is known as the lobby During slot initialization self is bound to the lobby The lobby is also the sending method holder for any sends in the initializ ing expression Nil is the object used to initialize slots without explicit initializers It is intended to indicate not a useful object This object is provided by the SELF implementation 24 The SELF World Lexical overview Appendix 2 B Lexical overview small letter cap letter letter identifier small keyword cap keyword argument name op char operator number integer real fixed point float general digit decimal base string normal char escape char numeric escape comment comment char b 4 4 4d 4 Y od o 4 4 d 4 Lb 4 1 4 o4 d 4 i a pb Lus A 1B 1 12 small letter cap letter small letter letter digit _ identifier cap letter letter digit z identifier Pt RE OB See pe eS psg pss porem pm m ere eep MES op char op char integer real base general digit general digit fixed point float decimal decimal decimal decimal e E decimal digit letter digit digit decimal r R normal char escape char any character except and We bel ns ee a a T SONNSENCVENTM 2 numeric escape x general digit general digit amp o
48. U93 DS84 GR83 HCU91 HCU92 Hoe94 HU94 Lee88 Ung84 Ung86 UCC91 US87 Bay Wei Chang and David Ungar Animation From Cartoons to the User Inter face In UIST 93 Conference Proceedings 1993 L Peter Deutsch and Allan M Schiffman Efficient Implementation of the Small talk 80 System In Proceedings of the 11th Annual ACM Symposium on the Princi ples of Programming Languages Salt Lake City UT 1984 Adele Goldberg and David Robson Smalltalk 80 The Language and Its Imple mentation Addison Wesley Reading MA 1983 Urs H lzle Craig Chambers and David Ungar Optimizing Dynamically Typed Object Oriented Programming Languages with Polymorphic Inline Caches In ECOOP 91 Conference Proceedings Geneva Switzerland July 1991 Published as Springer Verlag LNCS 512 1991 Urs H lzle Craig Chambers and David Ungar Debugging Optimized Code with Dynamic Deoptimization In Proceedings of the ACM SIGPLAN 92 Conference on Programming Language Design and Implementation San Francisco June 1992 Published as SIGPLAN Notices 27 7 July 1992 Urs H lzle Adaptive Optimization for SELF Reconciling High Performance with Exploratory Programming Ph D Thesis Stanford University August 1994 Urs H lzle and David Ungar A Third Generation SELF Implementation Recon ciling Responsiveness with Performance In Proceedings of OOPSLA 94 October 1994 Elgin Lee Object Storage a
49. _seal badTypeSealError deadProxyError any_oop any object oop 10 82 SELF Virtual Machine Reference Interfacing with other languages Table 3 Argument conversions from SELF to C C Second Conversion par SELF type C C type Errors Notes oop oop subtype corresponding oop subtype badTypeError 11 object any C C type int float proxy int float ptr badIndexError 12 byte vector int ptr badTypeError deadProxyError 1 The C type char has a system dependent range Either 0 255 or 128 127 2 The type smi is used internally in the virtual machine a 30 bit integer 3 Precision may be lost in the conversion 4 The second part of the conversion is a C pointer type The address of the first byte in the byte vector cast to this pointer type is passed to the foreign routine It is the responsibility of the for eign routine not to go past the end of the byte vector The foreign routine should not retain pointers into the byte vector after the call has terminated Note canonical strings can not be passed through a bv conversion badTypeError will result This is to ensure that they are not accidentally mod ified by a foreign function 5 This conversion passes two values to the foreign routine a pointer to the first byte in the byte vector and an integer which is the length of the byte vector divided by sizeof ptr_type If the size of the byte vector is not a multiple of s
50. a string The primitive Perform expects a string as its first argument The selector add could not be sent to shell 0 because it does not take 2 arguments The primitive Perform received the wrong number of arguments There are many other kinds of possible primitive errors 5 9 Nonrecoverable process errors Errors that stop a process from continuing execution are referred to as nonrecoverable errors The stack has grown too big Self 4 0 limits stack sizes and cannot resume processes with stack overflows A stack overflow error occurs because the current version of SELF allocates a fixed size stack for each process and the stack cannot be expanded Self 4 0 cannot run a block after its enclosing method has returned Self cannot resume this process either This error occurs if a block is executed after its lexically enclosing method has re turned This is call a non LIFO block Non LIFO blocks are not supported by the current version of SELF 5 10 Fatal errors In rare cases the virtual machine may encounter a fatal error e g a resource limit is exceeded or an internal error is discovered When this happens a short menu is displayed 65 SELF Virtual Machine Reference The initial SELF world VM Version 4 0 5 Tue 27 Jun 95 13 35 49 Solaris 2 x svr4 Internal error signal 11 code 3 addr 4 pc Oxlac768 Do you want to 1 Quit Self optionally attempting to write a snapshot 2 Try to pri
51. ains the header files necessary to write the glue code that allows SELF programs to call C C functions You should not bother with this file unless you plan to ex tend SELF by gluing in external libraries Optional VM tar Z Contains source code for the SELF virtual machine rough ly 80 000 lines of C An installation of GNU g ver sion 2 6 0 is required to compile this code You should not bother with this file unless you want to study or change the virtual machine VM documentation is almost non exis tent 96 APS93 Age94a Age94b Age94b CU89 CU90 CU91 CUC91 CUL89 Cha92 6 References Ole Agesen Jens Palsberg and Michael I Schwartzbach Type Inference of SELF In ECOOP 93 Conference Proceedings Kaiserslautern Germany July 1993 Published as Springer Verlag LNCS 707 1993 Ole Agesen Mango A Parser Generator for SELF Sun Microsystems Labs TR SMLI TR 94 27 1994 Ole Agesen Constraint Based Type Inference and Parametric Polymorphism In Proc International Static Analysis Symposium Sep 28 30 1994 Ole Agesen Concrete Type Inference Delivering Object Oriented Applications Technical Report Sun Microsystems Labs SMLI TR 96 52 1996 Craig Chambers and David Ungar Customization Optimizing Compiler Technol ogy for SELF a Dynamically Typed Object Oriented Programming Language In Proceedings of the SIGPLAN 89 Conference on Programming Language Desi
52. ated by periods A trailing period is optional Each expression consists of a series of message sends and literals The last expression in the code for an object may be preceded by the operator 2 1 8 2 1 2 Data objects Data objects are objects without code Data objects can have any number of slots For example the object has no slots i e it s empty while the object x 17 y 18 hastwo slots x and y X 17 slots a T y A data object returns itself when evaluated 2 1 3 The assignment primitive A slot containing the assignment primitive is called an assignment slot 2 2 2 When an assign ment slot is evaluated the argument to the message is stored in the corresponding data slot 2 2 in the same object the slot whose name is the assignment slot s name minus the trailing colon and the receiver 2 3 is returned as the result Note this means that the value of an assignment statement is the left hand side of the assignment statement not the right hand side as it is in Small talk C and many other languages This is a potential source of confusion for new SELF program mers t Tf you wish to use the empty vertical bar notation to create an empty object note that the parser currently requires a space between the vertical bars But in that case make sure you put a space after the period otherwise you will get an obscure error message from the parser The SELF World Objects 2 1 4 Objec
53. aved as a snapshot and then read in later possibly on some other workstation Using an obsolete reference i e memory address would be disastrous Thus SELF encapsulates such references within the special objects proxy for data references and ct Proxy for function references Such objects are known collectively as proxies A proxy object bundles some extra information along with the memory address of the referenced object and uses this extra information to detect with high prob ability any attempt to use an obsolete proxy An obsolete proxy is called a dead proxy To make it possible to rapidly develop foreign code the virtual machine supports dynamic linking of this code This makes it unnecessary to rebuild the virtual machine each time a small change is made to the foreign code Dynamic linking facilities vary from platform to platform but the SELF interface to the linking facilities is largely system independent The SunOS Solaris dynamic link interface is defined in the sunLinker object However clients should always refer to the dynamic linking facilities by the name linker which will be initialized to point to the dynamic linker in terface appropriate for the current platform The linker proxy and fctProxy objects are rather low level and have only limited functional ity For example a ctProxy does not know which code file it is dependent on The objects foreignFct and foreignCode establish a higher level and easier to use in
54. code sees 72 5 13 4 A simple glue example calling a C function eene 73 52 13 39 gt C gl ezi eom dep aig eke beider eivai 75 2 13 95 CE gue c aoo bI mI DI Der 78 5 13 13 Conversion PAIS vou EU e de ED DR e tpe tied iple 80 5 13 16 A complete application using foreign functions seesseeresssresrsrestsresrerrsreerssrerrsresrsrreeee 86 Appendix 5 A THE systertt HIGPBLOE ri beats seeds As tee ened ek asennad nena andres 90 Appendix 5 B PRUE ELV cto atas dotes tac menm T LU 93 Introduction Appendix 5 C References 97 Index 99 1 Introduction 1 1 Overview of the SELF System This section contains an overview of the system and its implementation it can be skipped if you wish to get started as quickly as possible 1 1 1 The system Although SELF runs as a single UNIX process or a single Macintosh application it really has two parts the virtual machine VM and the SELF world the collection of SELF objects that are the SELF prototypes and programs SELF world SELF virtual machine Figure 1 The SELF system The VM executes SELF programs specified by objects in the SELF world and provides a set of primitives which are methods written in C that can be invoked by SELF methods to carry out basic operations like integer arithmetic object copying and I O The SELF world distributed with the VM is a collection of SELF objects implementing variou
55. ctionary specific operations includesKey and removeKey In order to store an object in a set or use it as a dictionary key the object must understand the messages hash and the latter applying to any pair of items in the collection This is because sets and dic tionaries are implemented as hash tables Derived from set and dictionary are sharedSet and sharedDictionary These provide locking to maintain internal consistency in the presence of concurrency Modules setAndDictionary sharedSetAndDictionary 3 5 4 Tree Based Sets and Dictionaries collection tree treeNodes abstract treeNodes bag treeNodes set emptyTrees abstract emptyTrees bag emptyTrees set treeSet and treeBag implement sorted collections using binary trees The set variant ignores duplicates while the bag variant does not Tree sets and bags allow both explicit and implicit keys that is adding elements can be done with either at Put or add where a tree set that uses ex 38 The SELF World Collections plicit keys behaves like a dictionary Sorting is done on explicit keys if present values otherwise and the objects sorted must be mutually comparable Comparisons between keys are made using compare IfLess Equal Greater The implementation of trees uses dynamic inheritance to distinguish the differing behavior of emp ty and non empty subtrees The prototype t reeset represents an empty sub tree when an ele ment is added to it
56. ctively e An argument slot is a slot in a method filled in with a value when the method is invoked Message lookup is the process by which objects determine how to respond to a message which slot to evaluate by searching objects for slots matching the message Inheritance is the mechanism by which message lookup searches objects for slots when the re ceiver s slots are exhausted An object s parent slots contain objects that it inherits from Dynamic inheritance is the modification of object behavior by setting an assignable parent slot A resend allows a method to invoke the method that the first method the one that invokes the resend is overriding A directed resend constrains the lookup to search a single parent slot Cloning is the primitive operation returning an exact shallow copy a clone of an object i e a new object containing exactly the same slots and code as the original object e A prototype is an object that is used as a template from which new objects are cloned A traits object is a parent object containing shared behavior playing a role somewhat similar to a class in a class based system Any SELF implementation is required to provide traits ob jects for integers floats strings and blocks i e one object which is the parent of all integers another object for floats etc e The root context is the object that provides the context i e set of bindings in which slot initializers are evaluated
57. d focusing primarily on those objects meant for use in SELF programs It does not discuss the objects used to implement system facilities for example there is no discussion of the objects used to implement the graphical user interface nor does it discuss how to use programming support objects such as the command history object such tools are described in The SELF User s Manual The reader is assumed to be acquainted with the SELF language the use of multiple inheritance the use of traits objects and prototype objects and the organizing principles of the SELF world as discussed in UCC91 29 The SELF World World Organization 3 1 World Organization 3 1 1 The Lobby The lobby object is thus named because it is where objects enter the SELF world For example when a script that creates a new object is read into the system all expressions in that script are eval uated in the context of the lobby That is the lobby is the receiver of all messages sent to self by expressions in the script To refer to some existing object in a script the object must be accessible by sending a message to the lobby For example the expression AddSlots newObject entries lt list copy lit li 4 requires that the message 1ist be understood by the lobby the implicit receiver of the message so that the entries slot of the new object can be initialized The lobby slots traits globals and mixins are the roots of the object nam
58. d at the prompt and their results memory memory system interface GC snapshot low space etc monitor system monitor spy control nil indicates an uninitialized value platforms possible hardware platforms preferences user configuration preferences profiling flatProfiling prompt scheduler snapshotAction controls SELF code profiling interactive read eval print loop SELF process scheduler actions to do before after a snapshot thisHost describes the current host platform times reports user system cpu or real time typeSizes bit byte sizes for primitive types vmProfiling virtual machine profiling 44 The SELF World How to build the world 3 13 How to build the world Should you need to reconstruct a world from the source files here s how to do it This section de scribes how to create a default object world by reading in the SELF source code provided with your distribution in Optional SelfSource tar 2Z You can also do this after writing the world out using the transporter transporter fileOut fileOutAll To create the default object world 1 Start the SELF VM Self Self Virtual Machine Version 4 0 2 Thu 09 Feb 95 19 41 30 Copyright 1989 95 The Self Group type Credits for credits VM 2 Optional but recommended Start the spy so you can watch the world fill up with objects VM _Spy true Note that because the world is empty you must use the primitive to do this 3 Read in the default
59. d during the last time interval N is not displayed if N 1 The time interval currently is 1 25 of a second SELF is blocked reading from a slow device e g the keyboard or mouse SELF is blocked writing to a slow device e g the screen SELF is doing disk I O SELF is blocked in some UNIX system call other than read or write SELF has nothing to do shows up only when using processes The middle part of the display contains some information on VM memory usage displayed in tex tual form as described below Table 6 VM memory status information Name RSRC C Heap Description Size and utilization of the resource area an area of memory used for temporary storage by the compiler and by primitives Number of bytes allocated on the C heap by SELF excluding the memory and code spaces and the resource area The memory status portion of the system monitor consists of bars representing memory spaces and their utilization all bars are drawn to scale relative to one another their areas being proportional to the actual sizes of the memory spaces The next table explains the details of this part of the sys tem monitor s display Table7 The system monitor display memory status Space object memory code cache Description The four or more bars represent from top to bottom eden the two survivor spaces and subse quent bars are segments of old space The left and right parts of each bar represent
60. describes the various error messages presented by the low level facilities For each category or error the general layout of error messages in that category will be explained along with the format of the stack trace Then a rogue s gallery of the errors in that category will be shown By default errors are handled by a set of methods defined in module exrorHandling For all er rors except nonrecoverable and fatal VM errors an object can handle errors in its own way by de fining its own error handling methods If the object in which an error occurs neither inherits nor defines error handling behavior the VM prints out a low level error message and a stack trace The system will also resort to this low level message and trace if an error is encountered while trying to handle an error 5 5 An example Here is an expression that produces an error in the current system Self 7 100000 factorial The stack has grown too big Self limits stack sizes and cannot resume processes with stack overflows To debug type attach or to show stack type zombies first printError The error arose because the recursive method factorial exceeded the size allocated for the process stack which resulted in a stack overflow The virtual machine currently allocates a fixed size stack to each process and does not extend the stack on demand 5 6 Lookup errors Lookup errors occur when an object does not understand a message that is sent to i
61. e NU ver a ep PNE epe biete 12 2 3 2 Binaty Messages 2 Ase nle hep hie ad Se ke AGG DUI So dee 13 2 3 3 KEY WOrd messages oe rette pete n donk eek ne e e eite o fps 13 2 3 4 Implicit receiver messages iure eO e RR ER Eb iei ep EEEE E 14 2 3 5 Resending messages ce eee Apt tre ede Su tiere tes on e ESUS SEE SSS 15 2 3 6 Message lookup semantics essesessseseeseeeeee ener ener nennen nennen tenente tene tentent 15 2 945 Message send es aa i EUR ta 16 23 8 Thelookup algorithm ue three tes 17 2 3 90 Undiected Resend ae oue RS I ee en 17 233 10 Directed Resendz isse Re DURER HP 18 Lexical elemefilsos couette a adn LLLA EA hits 18 2 4 Chat cter Stag kiss ote eC eidem OD pee Hp o deep 18 242 Identf ersc i ee a E ERRORI UP RR ER E EEG RR ORU 19 24 3 Keywords iiie e e e ORE OO pir ens 19 2AA Arguments oia ettet te Mole os eite ct tete e a eu odes 19 DAD CODeTatOIS oco eben eor ien er e te e ee ives Pih e de e pr e te 20 241 6 INumbets z ee eb UE So etse 20 241 T SUIBBS aee eee RUE tpe pee ene RUE peat 21 DAB Comments iudei tege oo P e HU n RO HE Eee Er Renee EE 22 Introduction Appendix 2 A RIS AY as 5 Ac a a pU RUM au LO 23 Appendix 2 B Lexical GVOLVIe Wo ob e a uU Du UM eU 25 Appendix 2 C Syntax OVeEVIe Wise oat dedupate bed oe eke mealies 26 Appendix 2 D Built in typesosiesionepe tope tea tat pp opaca fedi ten 28 The SELF World 29 3 1 M Orld Orea
62. e code form In Smalltalk there is only one compiled method per source method but in SELF there may be several different compiled methods for the same source method because of customization 2 Language Reference This chapter specifies SELF s syntax and semantics An early version of the syntax was presented in the original SELF paper by Ungar and Smith US87 this chapter incorporates subsequent changes to the language The presentation assumes a basic understanding of object oriented con cepts The syntax is described using Extended Backus Naur Form EBNF Terminal symbols appear in Courier and are enclosed in single quotes they should appear in code as written not including the single quotes Non terminal symbols are italicized The following table describes the meta symbols META S YMBOL FUNCTION DESCRIPTION and grouping used to group syntactic constructions and option encloses an optional construction and repetition encloses a construction that may be repeated zero or more times alternative separates alternative constructions gt production separates the left and right hand sides of a production A glossary of terms used in this document can be found in Appendix A 2 1 Objects Objects are the fundamental entities in SELF every entity in a SELF program is represented by one or more objects Even control is handled by objects blocks 2 1 7 are SELF closures used to im plement user
63. e three related concepts that are often confused Two objects are equal if they mean the same thing For example 3 3 0 even though they are dif ferent objects and have different representations Two objects are identical if and only if they are the same object Or more precisely two references are identical if they refer to the same object The primitive _Eq tests if two objects are identical Finally two objects are indistinguishable if they have exactly the same behavior for every possible sequence of non reflective messages The binary operator tests for indistinguishability Identity implies indistinguishability which im plies equality It is actually not possible to guarantee that two different objects are indistinguishable since reflec tion could be used to modify one of the objects to behave differently after the indistinguisability test was made Thus is defined to mean identity by default Mirrors however override this de fault behavior m1 m2 if m1 reflectee _Eq m2 reflectee This makes it appear that there is at most one mirror object for each object in the system This illusion would break down however if one added mutable state to mirror objects 61 5 Virtual Machine Reference 5 1 Startup options The following command line options are recognised by the Virtual Machine f filename s snapshot W Reads filename which should contain SELF source immediately after star
64. eceiver keyword send resend keyword send small keyword expression cap keyword expression expression resend identifier MESSAGE unary binary keyword ARGUMENTS PRECEDENCE highest medium lowest ASSOCIATIVITY none none or left to right right to left SYNTAX receiver identifier receiver operator expression receiver small keyword expression cap keyword expression Heterogeneous binary messages have no associativity homogeneous binary messages associate left to right Parentheses can be used to explicitly specify order of evaluation 2 3 1 Unary messages A unary message does not specify any arguments It is written as an identifier following the receiv er Examples of unary messages sent to explicit receivers Associativity Unary messages compose from left to right An expression to print 5 factorial for ex ample is written 17 print 5 factorial 5 factorial print 12 The SELF World Expressions and interpreted as 5 factorial print Precedence Unary messages have higher precedence than binary messages and keyword messages 2 3 2 Binary messages A binary message has a receiver and a single argument separated by a binary operator Examples of binary messages 3 4 7 lt gt 8 Associativity Binary messages have no associativity except between identical operators which associate from left to right
65. ected if the system is later extended to include fuzzy logic objects Thus like reflec tion it is best to avoid using object identity One exception to this guideline is worth mentioning When testing to see if two collections are equal observing that the collections are actually the same object can save a tedious element by element comparison This trick is used in several places in the SELF world Note however that object identity is used only as a hint the correct result will still be computed albeit more slowly if the collections are equal but not identical Sometimes the implementation of a program requires reflection Suppose one wanted to write a program to count the number of unique objects in an arbitrary collection The collection could in 55 SELF Styled Programming Objects Have Many Roles general contain objects of different possibly incomparable types In Smalltalk one would use an IdentitySet to ensure that each object was counted exactly once IdentitySets are reflective since they use identity comparisons In SELF the preferred way to solve this problem is to make the re flection explicit by using mirrors Rather than adding objects to an IdentitySet mirrors on the ob jects would be added to an ordinary set This substitution works because two mirrors are equal if and only if their reflectees are identical In short to maximize the opportunities for code reuse the programmer should avoid reflection when poss
66. ed Section 5 13 5 describes C glue and section 5 13 9 describes C glue 5 13 3 Compiling and linking glue code Since glue code is a special form of C code a C compiler is needed to translate it The way this is done may depend on the computer system and the available C compiler The following description applies to Sun SPARCstations using the GNU g compiler A specific example of how to compile glue code can be found in the directory containing the toself demo see section 5 13 16 for further details The makefile in that directory describes how to translate a c file containing glue into something that can be invoked from SELF This is a two stage process first the c file is compiled into a o file which is then linked perhaps with other o files and libraries that the glue code depends on into a so file a so called dynamic library While the compilation is straightforward several issues concerning the linking must be explained Note that many libraries are already included in the SELF virtual machine e g libc a and hence should not be added to the dynamic library 72 SELF Virtual Machine Reference Interfacing with other languages Linking Before a foreign routine can be called it must be linked to the SELF virtual machine The linking can be done either statically i e before SELF is started or dynamically i e while SELF is running The SELF system employs both dynamic and static linking but users should
67. ed using the amp operator inherited from defaultBehavior and represents a collection under construc tion The amp operator provides a concise syntax for constructing small collections For example 1 amp abc amp x asList constructs a list containing an integer a string and the object x A collector object is not itself a collection it is converted into one using a conversion message such as asList asVector or asString 39 The SELF World Pairs Modules collector 3 6 Pairs pair point rectangle traits pair describes the general behavior for pairs of arithmetic quantities A point is a pair of numbers representing a location on the cartesian plane A rectangle is a pair of points representing the opposing corners of a rectangle whose sides are parallel with the x and y axes Modules pair point rectangle 3 7 Mirrors collection mirror mirrors smallInt mirrors float mirrors vectorish mirrors vector mirrors byteVector mirrors canonicalString mirrors mirror mirrors block mirrors method mirrors blockMethod mirrors activation liveOnes mirrors activation mirrors deadActivation mirrors methodActivation mirrors blockMethodActivation mirrors process mirrors assignment mirrors slots mirrors profiler Mirrors allow programs to examine and manipulate objects Mirrors get their name from the fact that a program can use a mirror to examine that is reflect upon itself A mirror on a
68. egers 0 integer parent parent Pe parent M lobby 0 0 floats 0 0 float parent parent MP parent lobby strings string parent parent L we parent L w lobby blocks block parent parent parent lobby value With L 3 block method Figure 4 The initial SELF world part 2 Table1 Objects in the initial SELF world Object lobby Objects in the lobby shell snapshotAction systemObjects Description The center of the SELF object hierarchy and the context in which expressions typed in at the VM prompt read in via RunScript or used as the initializers of slots are evaluated After reading in the world shell is the context in which expressions typed in at the prompt are evaluated An object with slot for the startup action see section 5 2 postRead This slot initially contains nil This object contains slots containing the general system objects including nil true false and the prototypical vectors and mirrors Objects in systemObjects nil true false vector byteVector proxy fctProxy vector parent byteVector parent The initializer for slots that are not explicitly initialized Indicates not a useful object Boolean true Argument to and returned by some p
69. ementation It is intended to indicate not a useful object i Although a block may be assigned to a slot at any time it is often not useful to do so evaluating the slot may result in an error because the activation record for the block s lexically enclosing scope will have returned see 2 1 7 The SELF World Slot descriptors producing self arg clone x x arg x y y arg y A slot name beginning with a colon indicates an argument slot The prefixed colon is not part of the slot name and is ignored when matching the name against a message Argument slots are al ways read only and no initializer may be specified for them As a syntactic convenience the argu ment name may also be written immediately after the slot name without the prefixed colon thereby implicitly declaring the argument slot Thus the following yields exactly the same object as above arg clone x x arg x y y arg y The slot above is a binary slot 2 3 2 taking one argument and having a name that consists of operator symbols Slots like x or y in a point object are unary slots 82 3 1 which take no argu ments and have simple identifiers for names In addition there are keyword slots 82 3 3 which handle messages that require one or more arguments A keyword slot name is a sequence of iden tifiers each followed by a colon The arguments in keyword methods are handled analogously to those in binary methods
70. ents The object contained in slot s s isParent True iff s is a parent slot General delegation for explicit receiver messages is supported through primitives in the implementation see Ap pendix 5 B 15 The SELF World Expressions s obj pred s The set of all slots of object obj that satisfy predicate pred ISI The cardinality of set S The message sending semantics are decomposed into the following functions send rec sel args The message send function 82 3 7 lookup obj rec sel V The lookup algorithm 2 3 8 undirected_resend The undirected message resend function 2 3 9 directed resend The directed message resend function 82 3 9 eval rec M args The slot evaluation function as described informally throughout 2 1 2 3 7 Message send There are two kinds of message sends a primitive send has a selector beginning with an underscore and calls the corresponding primitive operation Primitives are predefined functions provided by the implementation A normal send does a lookup to obtain the target slot if the lookup was successful the slot is subsequently evaluated If the slot contains a data object then the data object is simply returned If the slot contains the assignment primitive the argument of the message is stored in the corresponding data slot Finally if the slot contains a method an activation is created and run as described in 2 1 6 If the lookup fails the l
71. espaces accessible from the lobby The organization of these namespaces is described in the next section The slot Lobby allows the lobby itself to be re ferred by name The lobby also has a number of other functions it is the location of the default behavior inherited by most objects in the system slot defaultBehavior 3 1 2 Names and Paths For convenience the lobby s namespace is broken into three pieces implemented as separate ob jects rooted at the lobby traits objects that encapsulate shared behavior Typically each prototype object has an associated traits object of the same name that describes the shared part of its behavior e globals prototypical objects and one of a kind objects oddballs e mixins small parentless bundles of behavior designed to be mixed into some other object Each of these namespace objects is categorized to aid navigation For example to find the parent of the prototype list object one could start with the globals slot of the lobby then get the list slot of that object and then the parent slot of the list The se quence of slot names globals list parent is called a path and constitutes the list parent s full name Parent slots can be omitted from an object s full name since the slots in a parent are vis ible in the child via inheritance A path with parent slots omitted forms the short name for an ob ject For example the short name for the list parent is simply list parent N
72. etection else M lt s obj s name sel try local slots if M then M parent_lookup obj sel V end try parent slots end return M Where parent lookup obj sel V 1s defined as follows P s obj s isParent all parents M lt UJ lookup s contents sel V X obj recursively search parents se return M 2 3 9 Undirected Resend An undirected resend ignores the sending method holder the object containing the currently run ning method and continues with its parents The function undirected_resend rec smh sel args is defined as follows Input rec the receiver of the message smh the sending method holder sel the message selector args the actual arguments Output res the result object Algorithm M parent lookup smh sel do the lookup case IMIzO error message not understood IMI 1 res lt eval rec M args see 2 1 17 The SELF World Lexical elements IMI E error ambiguous message send end return res 2 3 10 Directed Resend A directed resend looks only in one slot in the sending method holder The function directed resend rec smh del sel args is defined as follows Input rec the receiver of the message smh the sending method holder del the name of the delegatee sel the message selector args the actual arguments Output res the result object Algorithm D lt amp se smh s name del find delegatee
73. ger receivers and arguments floating point arithmetic primitives take floating point receivers and arguments All comparison primitives return either true or false Integer comparison primitives take in teger receivers and arguments floating point comparison primitives take floating point re ceivers and arguments The receiver of a mirror primitive must be a mirror unless otherwise noted 95 SELF Virtual Machine Reference Getting the optional source files Appendix 5 C Getting the optional source files In addition to the main part of the release there are three other files available for ftp However most users will not need these files and since they will complicate the installation we strongly dis courage getting these files unless you are sure you will need them You will be able to run the SELF system without any of these optional files If you do need any of these files ftp to self smli com and use login name optional and pass word optional do not use anonymous ftp Go to the directory optional 4 0 Archive file Contents Optional Self Contains the default SELF world of objects as emitted by Source tar Z the transporter i e SELF source for all the system ob jects Since these files can be reconstituted by the trans porter you should not bother with this file unless you want to rebuild a SELF world from source code these files are not intended for human consumption Optional Glue tar Z Cont
74. gn and Implementation Portland OR June 1989 Published as SIGPLAN Notices 24 7 July 1989 Craig Chambers and David Ungar Iterative Type Analysis and Extended Message Splitting Optimizing Dynamically Typed Object Oriented Programs In Proceed ings of the SIGPLAN 90 Conference on Programming Language Design and Im plementation White Plains NY June 1990 Published as SIGPLAN Notices 25 6 June 1990 Also published in Lisp and Symbolic Computation 4 3 June 1991 Craig Chambers and David Ungar Making Pure Object Oriented Languages Prac tical In OOPSLA 91 Conference Proceedings Phoenix AZ October 1991 Pub lished as SIGPLAN Notices 26 11 November 1991 Craig Chambers David Ungar Bay Wei Chang and Urs H lzle Parents are Shared Parts of Objects Inheritance and Encapsulation in SELF In Lisp and Sym bolic Computation 4 3 June 1991 Craig Chambers David Ungar and Elgin Lee An Efficient Implementation of SELF a Dynamically Typed Object Oriented Language Based on Prototypes In OOPSLA 89 Conference Proceedings New Orleans LA October 1989 Pub lished as SIGPLAN Notices 24 10 October 1989 Also published in Lisp and Symbolic Computation 4 3 June 1991 Craig Chambers The Design and Implementation of the SELF Compiler an Opti mizing Compiler for Object Oriented Programming Languages Ph D disserta tion Computer Science Department Stanford University March 1992 97 References C
75. gn function They can be encapsulated in a method thus localizing the impact of redesigns The complications of dynamic loading and linking are handled automatically as is the recovery of dead ctProxies 89 SELF Virtual Machine Reference The system monitor Appendix 5 A The system monitor The SELF system contains a system monitor to display information about the internal workings of the system such as memory management and compilation It is invoked with Spy true there is are shortcuts in the shell spyOn and spyOf When it is active the system monitor takes over a portion of your screen with a window that looks like this W Oo lup 3 idle Com L Self C RRE 3712K 140K used CPU MC C Heap 2 308 295 PICs QO i La code deps debug indicators and VM memory display object memory code cache The indicators in the left part of the display correspond to various internal activities and events On the very left are the CPU bars which show how much CPU is used in various parts of the system The following table lists the individual indicators Table 5 The system monitor display indicators CPU Bar What It Means VM CPU time spent executing in the VM i e for primitives garbage collection etc Lkup CPU time used by compile time and run time lookups Comp CPU time spent by the SELF compilers The black part stands for time consumed by the non inling compiler NIC the gray part for the simple in
76. he root con text and the result stored into the data slot at parse time For example an initialized mutable point might be defined as CI parent traits point x 3 wd yes D The SELF World Slot descriptors producing an object with two data slots x and y and two assignment slots x and y containing the assignment primitive depicted with ct point traits parent An identifier by itself specifies an assignable data slot initialized to nil Thus the slot declaration x is a shorthand notation for x nil For example a simple mutable point might be defined as producing 2 2 3 Slots containing methods If the initializing expression is an object literal with code that object is stored into the slot without evaluating the code This allows a slot to be initialized to a method by storing the method itself rather than its result in the slot Methods may only be stored in read only slots A method auto matically receives a parent argument slot named self For example a point addition method can be written as arg clone x x arg x y y arg y In the user interface a read write slot is depicted as a single slot with a colon labelling the button used to access the value of the slot the assignment slot is not shown to save screen space In contrast a read only slot has an equals sign on the button Nilisa predefined object provided by the impl
77. ible avoid depending on object identity except as a hint and use mirrors to make reflection explicit when it is necessary 4 2 Objects Have Many Roles Objects in SELF have many roles Primarily of course they are the elements of data and behavior in programs But objects are also used to factor out shared behavior to represent unique objects to organize objects and behavior and to implement elegant control structures Each of these uses are described below 4 2 1 Shared Behavior Sometimes a set of objects should have the same behavior for a set of messages The slots defining this shared behavior could be replicated in each object but this makes it difficult to ensure the ob jects continue to share the behavior as the program evolves since the programmer must remember to apply the same changes to all the objects sharing the behavior Factoring out the shared behavior into a separate object allows the programmer to change the behavior of the entire set of objects sim ply by changing the one object that implements the shared behavior The objects that share the behavior inherit it via parent slots containing references to the shared behavior object By convention two kinds of objects are used to hold shared behavior traits and mixins A traits object typically has a chain of ancestors rooted in the lobby A mixin object typically has no par ents and is meant to be used as an additional parent for some object that already inherit
78. in that it expects two incoming SELF objects The actions of the conversion depends on the type of the first object in the following way If the first object is an integer the second argument must also be an integer the two integers are converted to C int s the second is shifted 16 bits to the left and they are or ed together to pro 83 SELF Virtual Machine Reference Interfacing with other languages duce the result If the first object is a float it is converted to a C float and the second object is ignored If the first object is a proxy the result is the pointer represented by the proxy and the sec ond argument is ignored If the first object is a byte vector the second object must be an integer which is interpreted as an index into the byte vector the result is a pointer to the indexed byte 5 13 15 Result conversions from C C to SELF A result conversion is given a C or C value of a certain type and performs these actions to pro duce a corresponding SELF object check that the C C value can be converted to a SELF object with no overflow or other er ror occurring If not report the error do the conversion i e construct the SELF object corresponding to the given C C value Table 4 lists all the available result conversions Each row represents one conversion with the first two columns designating the conversion pair The third column lists the type of C or C value that the conversion pair accepts The four
79. in which some of the processes are SELF processes For ex ample in proto cat someFile tokenize sort r capitalize tee lst it may be the case that the filters tokenize and capitalize perform most of their work in SELF Likewise the command proto mail may invoke some fancy mail reader written in SELF rather than the standard UNIX mail reader To see how the above can be accomplished please refer to Figure 5 below The left side of the fig ure shows the external view of a typical UNIX process It has two files stdin and stdout for sim plicity we ignore stderr Stdin is often connected to the keyboard so that characters typed here can be read from the file stdin Likewise stdout is typically connected to the console so that the process can display output by writing it to the file stdout Stdin and stdout can also be connected to regu lar files if the process was started with redirection The right side of Figure 5 shows a two stage pipe line Here stdout of the first process is connected to stdin of the second process Figure 5 A single UNIX process and an pipe line 86 SELF Virtual Machine Reference Interfacing with other languages Figure 5 illustrates a simple trick that in many situations allows SELF processes to behave as if they are full fledged UNIX processes A SELF process is represented by a real UNIX process which transparently communicates with the SELF process over a pair of connected sockets The com
80. include the mirrors prefix Modules mirror slot init 3 8 Messages SELF allows messages to be manipulated as objects when convenient For example if an object fails to understand a message the object is notified of the problem via a message whose arguments include the selector of the message that was not understood While most objects inherit default behavior for handling this situation by halting with an error it is sometimes convenient for an ob ject to handle the situation itself perhaps by resending the message to some other object Objects that do this are called transparent forwarders An example is given in interceptor A string has the basic ability to use itself as a message selector using the messages sendTo nor mal message sends resendTo resends or sendTo DelegatingTo delegated sends Each of these messages has a number of variations based on the number of arguments the message has For example one would used sendTo With With to send a message with at Put as the selector and two arguments at Put sendTo aDict With k With v Note primitives such as _Print cannot be sent in the current system A selector receiver delegatee methodHolder and arguments can be bundled together in a mes sage object The message gets sent when the message object receives the send message Message objects are used to describe delayed actions such as the actions that should occur just before or af ter a snapshot
81. ing its remaining statements The following constructs support this behavior exi exi ifTrue exit exit ifTrue exit value expr exitValue ee Quad P e Epub ct ct The first expression evaluates to nil if the block exits early the second allows the programmer to define the expression s value when the block exits early Note These constructs should not be con fused with their looping counterparts 1oopExit and loopExitValue Module block 3 3 4 Other Block Behavior Blocks have some other useful behavior One can determine the time in milliseconds required to execute a block using various ways of measuring time using the messages userTime systemTime cpuTime and real Time One can profile the execution of a block using the messages profile and flatProfile profile prints out the source level call graph annotated with call site and timing informa tion whereas 1atProfile prints out a flat profile sorted by module The message countSends will collect lookup statistics during a block execution Any object that inherits from the lobby can be passed to a method that expects a block behavior in defaultBehavior makes the object behave like a block that evaluates to that object Module block 34 The SELF World Numbers and Time 3 4 Numbers and Time The SELF number traits form the hierarchy shown below In this and subsequent hierarchy de scriptions indentat
82. intString in descendants e mirror creation reflect support for point and list construction and amp behavior that allows blocks to ignore extra arguments behavior that allows an object to behave like a block that evaluates to that object this per mits a non block object to be passed to a method that expects a block behavior that allows an object to be its own key in a collection key default behavior for doubly dispatched messages behavior for printing error messages and stack dumps error and halt It is important to note that not all objects in the system inherit this default behavior It is entirely permissible to construct objects that do not inherit from the lobby and the SELF world contains quite a few such objects For example the objects used to break a namespace into separate catego ries typically do not inherit from the lobby Any program intended to operate on arbitrary objects such as a debugger must therefore assume that the objects it manipulates do not understand even the messages in defaultBehavior Modules defaultBehavior errorHandling 3 2 2 The Root Traits Traits Clonable and Traits Oddball Most concrete objects in the SELF world are descendants of one of two top level traits objects traits clonableandtraits oddball The distinction between the two is based on whether or not the object is unique For example t rue is a unique object There is only one true object in 31 The SELF
83. ion i e construct the C C value corresponding to the given SELF object Table 3 lists all the available argument conversions Each row represents one conversion with the first two columns designating the conversion pair The third column lists the types of SELF objects that the conversion pair accepts The fourth column lists the C types that it produces The fifth col umn lists the kind of errors that can occur during the conversion Finally the sixth column contains references to numbered notes The notes are found in the paragraphs following the table Table 3 Argument conversions from SELF to C C Second Conversion part SELF type C C type Errors Notes bool boolean int 0 or 1 badTypeError char smallInt char badTypeError overflowError signed char smallInt signed char badTypeError overflowError unsigned char smallInt unsigned char badSignError badTypeError overflowError short smallInt short badTypeError overflowError signed short smallInt signed short badTypeError overflowError unsigned shor smallInt unsigned short badSignError t badTypeError overflowError int smallInt int badTypeError signed int smallInt signed int badTypeError unsigned int smallInt unsigned int badSignError badTypeError long smallInt long badTypeError signed long smallInt signed long badTypeError 81 The any conversion is the only conversion that has more than one incoming object SELF Virt
84. ion indicates that one traits object is a child of another The prefix traits is omitted since these hierarchy descriptions always describe the interrelationship between traits ob jects In most cases leaf traits are concrete and have an associated prototype with the same name orderedOddball number float integer smalllnt bigInt traits number defines behavior common to all numbers such as successor succ prede cessor pred absoluteValue negate double half max andmin traits num ber inherits from traits orderedOddball so sending copy or clone to a number returns the number itself traits integer defines behavior common to all integers such as even odd and factorial There are four division operators for integers that allow the programmer to control how the result is truncated or rounded Integers also include behavior for iterating through a sub range including to Do to By Do to ByNegative Do upTo Do upTo By Do downTo Do downTo By Do Relevant oddballs e infinity IEEE floating point infinity minSmallInt smallest smallInt in this implementation maxSmallInt biggest smallInt in this implementation Modules number float integer smallInt bigInt 3 4 1 Random Numbers clonable random randomLC prototypes random Traits random defines the abstract behavior of random number generators A random number generator can be used to generate random booleans in
85. irror Prototypical mirror on a method activation blockMethodActivationMirror proxyMirror fctProxyMirror profilerMirror Prototypical mirror on a block activation Prototypical mirror on a proxy Prototypical mirror on a fct Proxy Prototypical mirror on a profiler 69 SELF Virtual Machine Reference Option primitives 5 12 Option primitives This section has not been updated to include all options present in SELF 4 0 Option primitives control various aspects of the SELF system and its inner workings Many of them are used to debug or instrument the SELF system and are probably of little interest to users The options most useful for users are listed in Table 2 other option primitives can be found in Ap pendix 5 B and a list of all option primitives and their current settings can be printed with the primitive _PrintOptionPrimitives Table 2 Some useful option primitives Name Description _PrintPeriodf Print a period when reading a script file with _RunScript Default false _PrintScriptName Print the file name when reading a script file Default false _Spyl Start the system monitor see Appendix 5 A for details Default false _StackPrintLimit Controls the number of stack frames printed by PrintProcessStack De fault 20 _DirPath The default directory path for script files Each option primitive controls a variable within the virtual machine containing a boolean integer or string in fact
86. is sent to the T Fail argument passing two strings the name of the primitive and an error string indicating the reason for failure If the failing primitive call does not have an IfFail part the message primitive FailedWith is sent to the receiver of the primitive call with the same two strings as arguments The result returned by the error handler becomes the result of the primitive operation 0 in our ex ample execution then continues normally If you want the program to be aborted you have to do this explicitly within the error handler for example by calling the standard error method de fined in the default world The following table lists the error string prefixes passed by the VM to indicate the reason of the primitive failure If the error string consists of more than the prefix it will reveal more details about the error Table 8 Primitive failures Prefix Description primitiveNotDefinedError Primitive not defined primitiveFailedError General primitive failure for example an argument has an invalid value badTypeError The receiver or an argument has the wrong type badTypeSealError Proxy s type seal did not match expected type seal divisionByZeroError Division by zero overflowError Integer overflow This can occur in integer arithmetic primitives or in UNIX when the result is too large to be represented as an integer badSignError Integer receiver or argument has wrong sign alignmentError Bad word
87. is read They are also used as an argument to new process creation you can create a new process to execute the message by sending it fork Modules sending message selector interceptor 3 9 Processes and the Prompt SELF processes are managed by a simple preemptive round robin scheduler Processes can be stepped suspended resumed terminated or put to sleep for a specified amount of time Also the 41 The SELF World Foreign Objects stack of a suspended process can be examined and the CPU use of a process can be determined A process can be created by sending fork toamessage The prompt object takes input from stdin and spawns a process to evaluate the message Input to the prompt is kept in a history list so that past input can be replayed similar to the history mech anism in manyUnix shells Modules process scheduler semaphore prompt history 3 10 Foreign Objects clonable proxy fctProxy foreignFct foreignCode The low level aspects of interfacing with code written in other languages via C or C glue code are described in the VM Reference Manual A number of objects in the SELF world are used to in terface to foreign data objects and functions These objects are found in the name spaces traits foreign and globals foreign One difficulty in interfacing between SELF and external data and functions is that references to for eign data and functions from within SELF can become obsolete when the SELF world is s
88. ive to copy it It is considered bad style however to send a primitive directly rather than call ing the primitive s wrapper method The sender can extract the various return values from the result object by name The second way is to pass in one block for each value to be returned For example countLines n lines n Words n words n Characters n characters n Each block simply stores its argument into the a local variable for later use The countLines Words Characters method would evaluate each block with the appropriate value to be returned countLines lb Words wb Characters cb lb value lineCount wb value wordCount cb value charCount 4 5 Substituting Values for Blocks The lobby includes behavior for the block evaluation messages Thus any object that inherits from the lobby can be passed as a parameter to a method that expects a block the object behaves like a block that evaluates that object For example one may write x gt 0 ifTrue x False x negate rather than x gt 0 ifTrue x False x negate Note however that SELF evaluates all arguments before sending a message Thus in the first case x negate will be evaluated regardless of the value of x even though that argument will not be used if x is nonnegative In this case it doesn t matter but if x negate had side effects or if it were very expensive it would be better to use the second form
89. ixed in to get the desired behavior Module root Traits 3 3 Blocks Booleans and Control Structures A block is a special kind of object containing a sequence of statements When a block is evaluated by being sent an acceptable value message its statements are executed in the context of the cur rent activation of the method in which the block is declared This allows the statements in the block to access variables local to the block s enclosing method and any enclosing blocks in that method This set of variables comprises the lexical scope of the block It also means that within the block self refers to the receiver of the message that activated the method not to the block object itself A return statement in a block causes a return from the block s enclosing method See the SELF Language Reference for a more thorough discussion of block semantics A block can take an arbitrary number of arguments and can have its own local variables as well as having access to the local variables of its enclosing method The statements in the block are exe cuted when the block is sent a message of the form value With where the number of co lons in the message is at least the same as the number of arguments the block takes extra arguments are ignored but it is an error to provide too few For example the following block takes two arguments 32 The SELF World Blocks Booleans and Control Structures argi arg2 argl arg2
90. izeof ptr type badSizeError results 6 In addition to accepting a byte vector this conversion accepts the integer 0 in which case a NULL pointer is passed to the foreign routine 7 The cbv conversions are like the bv conversions except that canonical strings are allowed as ac tual arguments A cbv conversion should only be used if it is guaranteed that the foreign routine does not modify the bytes it gets a pointer to 8 All the string conversions take an incoming byte vector copy the bytes part add a trailing null char and pass a pointer to this copy to the foreign routine After the call has terminated the copy is discarded If the byte vector contains a null char nul1CharError results 9 The type_seal isan int or char expression that is tested against the type seal value in the proxy If the two are different badTypeSealError results The special value ANY SEAL will match the type seal in any proxy Note that the proxy conversion will fail with nullPointerEr ror ifthe proxy object it is given encapsulates a NULL pointer 10 The any oop conversion is an escape it passes the SELF object unchanged to the foreign rou tine 11 The oop conversion is mainly intended for internal use The second argument is the name of an oop subtype After checking that the incoming argument points to an instance of the subtype the pointer is cast to the subtype 12 The any conversion is different from all other conversions
91. l Unfortunately it is difficult to tell when printString is likely to fail Using reflection the facility can avoid sending printString to objects that do not define printString But that is not the case with traits point The solution taken in this version of the system is to mark printable objects with a special annotation The printing facility sends printString to the object only if the object contains an annotation IsComplete The existence of an isComplete annotation in an object means that the object is prepared to print itself The object agrees to provide behavior for a variety of messages see the programming envi ronment manual for more details 4 4 How to Return Multiple Values Sometimes it is natural to think of a method as returning several values even though SELF only allows a method to return a single object There are two ways to simulate methods that return multiple values The first way is to use an inlined object For example the object p lobby lines words characters 58 SELF Styled Programming Substituting Values for Blocks could be used to package the results of a text processing method into a single result object count r p lobby lines words characters fi rf copy r lines lCount r words wCount r characters cCount r Note that the inline object prototype inherits copy from the lobby If one omitted its parent slot p one would have to send it the _Clone primit
92. l value for the new vector s elements e g copySize FillingWith 4 7 Hash and Sets and dictionaries are implemented using hash tables In order for an object to be eligible for in clusion in a set or used as a key in a dictionary it must implement both and hash hash maps an object to a small Int Further hash must be implemented in such a way that for objects a and b a b implies a hash b hash The behavior that sets disallow duplicates and dictionaries disallow multiple entries with the same key is dependent upon the correct implemen tation of hash for their elements and keys Finally the implementation of sets and dictionaries will only work if the hash value of the objects in the set do not change while the objects are in the set dictionary This may complicate managing sets of mutable objects since if the hash value depends on the mutable state the objects can not be allowed to mutate while in the set Of course a trivial hash function would simply return a constant regardless of the contents of the object However for good hash table performance the hash function should map different objects to different values ideally distributing possible object values as uniformly as possible across the range of small integers 60 SELF Styled Programmin Equality Identity and Indistinguishability y gr g q y y g 4 8 Equality Identity and Indistinguishability Equality identity and indistinguishability ar
93. le socks so 5 13 20 Use of foreign functions in server self The server program is implemented using foreignFct objects There is only a few lines of code directly involved in setting this up First the foreignFct prototype is cloned to obtain a local prototype called socksFct which contains the path for the socks so file socksFct is then cloned each time a foreignFct object for a function defined in socks so is needed For exam ple intraits socket the following method is found copyPort portNumber Create a socket do bind then listen sbl socksFct copyName socket bind listen glue sbl value portNumber With deadCopy This method copies a socket object and returns the copy The local slot sb1 is initialized to a foreignFct object The body of the method simply sends value With to the foreignFct object The first argument is the port number to request for the socket the second argument is a deadCopy of self socket objects are proxies and socket_bind_listen returns a proxy so it must be passed a dead proxy to revive and store the result in see section 5 13 1 There are only three uses of foreignFct objects in the server and in all three cases the for eignFct object is encapsulated in a method as illustrated above In general the design of foreignFct objects has been aimed at making the use of them light weight When cloning them it is only necessary to specify the minimal information the name of the forei
94. lining compiler SIC Self CPU time spent executing compiled SELF code The black part stands for time consumed by unop timized NIC code the gray part for optimized SIC code CPU This bar displays the percentage of the CPU that the SELF process is getting a completely filled bar equals 100 CPU utilization by SELF Black stands for user time gray for system time Dot Below the CPU bar is a small dot which moves whenever a process switch takes place Indicator What It Means X compiling Y The X compiler where X is either nic or sic is compiling the method named Y into machine code scavenge The SELF object memory is being scavenged A scavenge is a fast partial garbage collection see Ung84 Ung86 Lee88 GC The SELF object memory is being fully garbage collected flushing SELF is flushing the code cache compacting SELF is compacting the code cache reclaiming SELF is reclaiming space in the code cache to make room for a new method sec reclaim ic flush LRU sweep SELF is flushing some methods in the code cache because there is not enough room in one of the secondary caches the caches holding the debugging and dependency information SELF is flushing all inline caches SELF is examining methods in the code cache to determine whether they have been used recently 90 SELF Virtual Machine Reference The system monitor page N read write disk in out UNIX idle N page faults occurre
95. macro expands into fail opt whether or not to pass a failure handle to the member function refer to section 5 13 6 for details e ci ai these are argument conversion pairs specifying how to obtain the arguments for the member function Any conversion pair found in Table 3 may be used 5 13 13 Conversion pairs A major function of glue code is to convert between SELF objects and C C values This conver sion is guarded by so called conversion pairs A conversion pair is a pair of arguments given to a glue macro It handles converting one or at most a few types of objects values There are different conversion pairs for converting from SELF objects to C C values called argument conversion pairs and for converting from C C values to SELF objects called result conversion pairs 5 13 14 Argument conversions from SELF to C C An argument conversion is given a SELF object and performs these actions to produce a corre sponding C or C value Tn fact there is no such member function defined on sockaddr_in objects 80 SELF Virtual Machine Reference Interfacing with other languages check that the SELF object it has been given is among the allowed types If not report badTypeError invoke the failure block if present with the argument badTypeEr ror check that the object can be converted to a C C value without overflow or any other error If not report the relevant error e do the convers
96. mer can explore the SELF world down to the bytecode level but no further This pretense ensures that the behavior of a SELF program can be understood by looking only at the SELF source code The second stage of translation is the actual compilation of the bytecodes to machine code This is how the execution of bytecodes is implemented it is totally invisible on the SELF level except for side effects like execution speed and memory usage The compilation takes place the first time a message is actually sent thus the first execution of a program will be slower than subsequent ex ecutions Actually this explanation is not entirely accurate the compiled method is specialized on the type of the receiver If the same message is later sent to a receiver of different type e g a float instead of an integer a new compilation takes place This technique is called customization see CU89 for details Also the compiled methods are placed into a cache from which they can be flushed for various reasons therefore they might be recompiled from time to time Furthermore the current version of the compiler will recompile and reoptimize frequently used code using in formation gathered at run time as to how the code is being used see HCU91 for details Don t be misled by the term compiled method if you are familiar with Smalltalk in Smalltalk terminology it de notes a method in its bytecode form but in SELF it denotes the native machin
97. mu nication is bidirectional input to the UNIX process is relayed to the SELF process over the socket connection and output produced by the SELF process is sent over the same socket connection to the UNIX process which relays it to stdout The right part of Figure 5 shows how the UNIX SELF process pair can fit seamlessly into a pipe line capitalize capitalize stdio stdio Figure 6 A SELF process and how it fits into a pipe line Source code that facilitates setting up such UNIX SELF process pairs is included in the SELF dis tribution The source consists of two parts one being a SELF program called server the other be ing a C program called toself When the server is started it creates a socket binds a name to it and then listens for connections on it toself establishes connections to the server program The first line that is transmitted when a connection has been set up goes from tose1 to the server The line contains a SELF expression Upon receiving it the server forks a new process to evaluate the expression in the context of the lobby augmented with a slot stdio that contains a uni xFile like object that represents the socket connection When the forked process terminates the socket con nection is shut down The tose1f UNIX process then terminates The SELF expression that forms the SELF process is specified on the command line when toself is started For example if the server has been started the following ca
98. n be typed at the UNIX prompt proto toself stdio writeLine 5 factorial printString 120 proto echo something toself capitalize stdio SOMETHING proto toself capitalize stdio Write some text that goes to stdin of the toself program WRITE SOME TEXT THAT GOES TO STDIN OF THE TOSELF PROGRAM More text MORE TEXT D 87 SELF Virtual Machine Reference Interfacing with other languages protos If you want to try out these examples locate the files server self socks soandtoself The path name of the file socks so is hardwired in the file server self so please make sure that it has been set correctly for your system Then file in the world and type server start fork at the SELF prompt Now you can go back to the UNIX prompt and try out the examples shown above 5 13 17 Outline of toself toself is a small C program found in the file toself c It operates in the three phases out lined above 1 Try to connect to a well known port number on a given machine the function estab lishConnection does this 2 Send the command line arguments over the connection established in 1 the sa ewrite call in main does this 3 While there is more input and the SELF process has not shut down the socket connection relay from stdin to the socket connection and from the socket connection to stdout the func tion relay does this 5 13 18 Outline of server The server i
99. n object x is obtained by sending the message reflect x to any object that inherits defaultBehavior The object x is called the mirror s reflectee A mirror behaves like a keyed collection whose keys are slot names and whose values are mirrors on the contents of slots of the reflectee A mirror can be queried to discover the number and names of the slots in its reflectee and which slots are parent slots A mirror can be used to add and remove slots of its reflectee Iterating through a mirror enu merates objects representing slots of the reflected object such facets are called fake slots For 40 The SELF World Messages example a method mirror includes fake slots for the method s byte code and literal vectors and el ements of vectors and byteVectors There is one kind of mirror for each kind of object known to the virtual machine small integers floats canonical strings object and byte vectors mirrors blocks ordinary and block methods or dinary and block method activations processes profilers the assignment primitive and ordinary objects called slots because an ordinary object is just a set of slots The prototypes for these mirrors are part of the initial SELF world that exists before reading in any script files The file init self moves these prototypes to the mirrors subcategory of the prototypes category of the lobby namespace Because mirrors is not a parent slot the names of the mirror prototypes always
100. nd Inheritance for SELF Engineer s thesis Stanford University 1988 David Ungar Generation Scavenging A Non Disruptive High Performance Stor age Reclamation Algorithm In Proceedings of the ACM SIGSOFT SIGPLAN Soft ware Engineering Symposium on Practical Software Development Environments Pittsburgh PA April 1984 Published as SIGPLAN Notices 19 5 May 1984 and Software Engineering Notes 9 3 May 1984 David Ungar The Design and Evaluation of a High Performance Smalltalk Sys tem MIT Press Cambridge MA 1987 David Ungar Craig Chambers Bay Wei Chang and Urs H lzle Organizing Pro grams without Classes In Lisp and Symbolic Computation 4 3 June 1991 David Ungar and Randall B Smith SELF The Power of Simplicity In OOPSLA 87 Conference Proceedings Orlando FL 1987 Published as SIGPLAN Notices 22 12 December 1987 Also published in Lisp and Symbolic Computa tion 4 3 June 1991 and as Sun Microsystems Labs TR SMLI 94 0320 98 Introduction Index operator see non local return operator _Call 71 CallAndConvert 71 DirPath 70 ErrorMessage 94 _glueDefs c incl 72 HistoryIndex 70 Kill 71 Perform 63 PrintOptionPrimitives 70 PrintPeriod 70 _PrintScriptName 70 _SnapshotCode 70 _Spy 70 _Spy 70 _StackPrintLimit 70 A activation object 23 alignmentError 93 ambiguousSelector Type Delegatee MethodHolder Arguments 63 annotation separator 11 Annotations 11 anonymous
101. nds into expr co expr a0 when assigning to a component the value it is assigned is obtained by converting a SELF object to a C value The expr co expr a0 pair which can be any one of the argument conversions listed in Table 3 specifies how to do this conversion 5 13 9 C glue Since C is a superset of C all of C glue can be used with C In addition C glue provides support for e Constructing objects using the new operator Deleting objects using the delete operator Calling member functions on objects Each of these parts will be explained in the following sections 78 SELF Virtual Machine Reference Interfacing with other languages 5 13 10 Constructing objects In C objects are constructed using the new operator Constructors may take arguments The macros CC_new_N where N is a small integer support calling constructors with or without argu ments Calling a constructor is similar to calling a function so for additional explanation please refer to section 5 13 6 Here is the general syntax for constructing objects using C glue CC new N cnvt res aux res class gfname c0 a0 cl al cN aN For example to construct a sockaddr i n object the following glue statement could be used CC new O proxy sockaddr in socks sockaddr in new sockaddr in The meanings of the CC new N arguments are as follows cnvt res aux res the result of calling the constructor is an object pointer The re
102. new process the new process performs the message receiver set receiver selector set selector methodHolder set method holder delegatee set delegatee of the message object arguments set arguments packaged in a vector receiver Selector set receiver and selector receiver Selector Arguments set receiver selector and arguments receiver Selector Type Delegatee MethodHolder Arguments set all components Reflection mirrors reflect returns a mirror on the argument reflectee returns the object the mirror receiver reflects contents At returns a mirror on the contents of slot isAssignableAt tests if slot n is an assignable slot isParentAt tests if slot n is a parent slot isArgumentAt tests if slot n is an argument slot parentPriority At returns the parent priority of slot n slotAt returns a slot object representing slot n contents At returns the contents of the slot named n visibility At returns a visibility object representing visibility of slot n System wide Enumerations messages sent to the oddball object browse all Limit returns a vector of mirrors on all objects in the system up to the limit referencesOf Limit returns a vector of mirrors on all objects referring to arg up to the limit referencesOfReflectee Limit returns a vector of mirrors on all objects referring to argument s reflectee up to the limit allows one to find references to a method childrenOf Limit returns a vector of
103. ng and res aux is empty Table 3 lists all the possible values for the res cnv res aux pair e fexp is aC expression which evaluates to the function that is being glued in In the simplest case such as in the encrypt example the expression is the name of a function but in gen eral it may be any C expression involving function pointers etc which in a global context evaluates to a function gfname the name of the function which the C_func_N macro expands into In the en crypt example the convention of appending _glue to the C function s name was used When accessing a glued in function from SELF the value of gfname is the name that must be used e fail opt there are two possible values for this argument It can be empty as in the exam ple or it can be fail In the latter case the C function being called is passed an additional argument that will be the last argument and have type void Using this argument the C function may abort its execution and raise an exception The result is that the IfFail block in SELF will be invoked 75 SELF Virtual Machine Reference Interfacing with other languages ci ai each of these pairs describes how to convert a SELF level argument to one or more C level arguments For example in the glue for encrypt c0 a0 specifies that the first ar gument to encrypt is a string Likewise c1 a1 specifies that the second argument is an in teger Note that in both these cases the a pa
104. no example it is simply errno but in general it may actually be any expression that is valid in a global context even an ex pression involving function calls e gfname the name of the C function that C get var orC set var expands into e var is the name of a global variable that a value is assigned to In general var may be any expression that in a global context evaluates to an l value e expr cO expr a0 when assigning to a variable the value it is assigned is obtained by converting a SELF object to a C value The expr c0 expr a0 pair which can be any one of the argument conversions listed in Table 3 specifies how to do this conversion 5 13 8 Reading and assigning struct components Reading the value of a struct component or assigning a value to it is similar to doing the same op erations on a global variable The difference is that the struct must somehow be specified This is taken care of by the macros C get comp and C set comp The general syntax is C get comp cnvt res aux res cnvt strc aux strc comp gfname C set comp cnvt strc aux strc comp expr cO0 expr a0 gfname Here is an example assigning to the sin port field of a struct sockaddr_in this struct is de fined in usr include netinet in h struct sockaddr in short sin family u short sin port struct in addr sin addr char sin zero 8 77 SELF Virtual Machine Reference Interfacing with other languages The struct is represented by a p
105. nonical string Character objects behave like immutable strings of length one There are 256 well known charac ter objects in the SELF universe They are stored in a 256 element vector named ascii with each character stored at the location corresponding to its ASCII value Characters respond to the mes 37 The SELF World Collections sage asByte by returning their ASCII value that is their index in ascii The inverse of asBy te asCharacter can be sent to an integer between 0 and 255 to obtain the corresponding character object Module string 3 5 3 Unordered Sets and Dictionaries collection setOrDictionary set sharedSet dictionary sharedDictionary There are two implementations of sets and dictionaries in the system The one described in this section is based on hash tables The one discussed in the following section is based on sorted bina ry trees The hash table implementation has better performance over a wide range of conditions An unfortunate ordering of element addtions can cause the unbalanced trees used in the tree ver sion to degenerate into an ordered lists resulting in linear access times A set behaves like a mathematical set It contains elements without duplication in no particular or der A dictionary implements a mapping from keys to values where both keys and values are arbi trary objects Dictionaries implement the usual collection behavior plus keyed access using at and at Put and the di
106. nt the Self stack 3 Try to return to the Self prompt 4 Force a core dump Your choice The first two lines help the SELF implementors locate the problem Printing the SELF stack may provide more information about the problem but does not always work Returning to the SELF prompt may be successful but the system integrity may have been compromised as a result of the error The safest course is to attempt to write a snapshot if there are unsaved changes and then check the integrity of the snapshot by executing the primitive Verify after starting it If there are any error messages from the primitive do not attempt to continue using the snapshot Since fatal errors usually arise from a bug in the virtual machine please send the SELF group a bug report and include a copy of the error message if possible If the error is reproducible please de scribe how to reproduce it including a snapshot or source files may be helpful 5 11 The initial SELF world The diagram on the following pages shows all objects in the bare SELF world In addition liter als like integers floats and strings are conceptually part of the initial SELF world block and object literals are created by the programmer as needed All the objects in the system are created by add ing slots to these objects or by cloning them Table 1 lists all the initial objects and provides a short description for each Reading in the world rearranges the structure of the bare
107. ntzatiONf oot Nba RON RU MU aed a RO DN Rae 30 Sled TheEObby za tae ertet eoe i e Ret tees 30 3 1 2 Names and Paths eget aves dee sa ate e RR de tee Pe er qae vs 30 3 2 The Roots OM Behavior ou p ad oh a Se E ee es 31 3 2 1 Detault Beh vior iiA ees eR Re aS 31 3 2 2 The Root Traits Traits Clonable and Traits Oddball s sessssess 31 3 2 3 MIXIHS iret ec e ree o edeseeh ete Sous eR es SERERE b ed AT es 32 3 3 Blocks Booleans and Control Structures see 32 3 3 1 Booleans and Conditionals sss esee enne ener enne nnne 33 332 Loops e 33 3 3 3 Block Exits oeste tee epe die i ees ees 34 3 3 Other Block Behavior e aa e ra eee e eene enne enne entere nennen E RE tenen eren nens 34 3 4 Nut bers and ime 3 ieu EID ee toe dip P noH ue teo Rus 35 3 4 1 Random Numbers ee cetee dence codes cde aaie ele eee ec e rriaren dels 35 3412 etenesnescu DURER IND INDE NEN 36 3 5 CollSetOfls us oe eodup ep UU NNNM m A deeds 36 3 5 1 Indexable Collections roimis inireseta eter ertet ederent reine e ei i OR 37 3 5 2 Strings Characters and Paragraphs 0 cece ceceseeesceseeeeceeeeeeceseeeaecseeeeecasesaecsaeaeenees 37 3 5 3 Unordered Sets and Dictionaries cccccesscccesssecesseceeesecenseceecsseceeeaeeceeaaeesseeeeessneeeneaees 38 3 5 4 Tree Based Sets and Dictionaries essere enne enne nnns 38 35 3
108. on parent slots are used when it is desirable to keep a part of the name space distinct For exam ple the traits slot of the lobby is not a parent slot This allows a convention that gives prototypes and their associated traits objects similar names a prototype and its associated traits object have the same local name but the prototype is placed in a slot in the globals object whereas the traits of the prototype is placed in a slot in the traits object Since the traits slot of the lobby is not 30 The SELF World The Roots of Behavior a parent slot the name of the traits object must start with the prefix traits The globals slot on the other hand is a parent slot so the name of a prototype object needs no prefix Thus list refers to the prototype list while traits list refers to its traits object for lists As a matter of style programs should refer to objects by the shortest possible name This makes it easier to re organize the global namespace as the system evolves If programs used full path names then many more names would have to be updated to reflect changes to the namespace or ganization a tedious chore 3 2 The Roots of Behavior 3 2 1 Default Behavior Certain common behavior is shared by nearly all objects in the SELF world This basic behavior is defined in the defaultBehavior slot of the lobby and includes identity comparisons and inequality default behavior for printing reimplement pr
109. ookup error is handled in an implementation defined manner typically a message indicating the type of error is sent to the object which could not handle the message The function send rec sel args is defined as follows Input rec thereceiver of the message sel the message selector args the actual arguments Output res the result object Algorithm if begins with underscore sel then invoke primitive rec sel args primitive call else M lt lookup rec sel do the lookup case M 0 error message not understood M l 1 res lt eval rec M args see 2 1 IMI I error ambiguous message send end end return res 16 The SELF World Expressions 2 3 8 The lookup algorithm The lookup algorithm recursively traverses the inheritance graph which can be an arbitrary graph including cyclic graphs No object is searched twice along any single path The search begins in the object itself and then continues to search every parent Parent slots are not evaluated during the lookup That is if a parent slot contains an object with code the code will not be executed the ob ject will merely be searched for matching slots The function lookup obj sel V is defined as follows Input obj the object being searched for matching slots sel the message selector V the set of objects already visited along this path Output M the set of matching slots Algorithm if obje V then M lt cycle d
110. opies of prototypes and oddballs is purely a matter of convention the SELF language makes no such distinction While this property not having special kinds of objects gives SELF great flexibility and expressive power it leads to an interesting problem the inability to dis tinguish behavior that is ready for immediate use from that which is defined only for the benefit of descendant objects Put another way SELF cannot distinguish those objects playing the role of classes from those playing the role of instances The most prominent manifestation of this problem crops up in object printing Suppose one wishes to provide the following printString method for all point objects printString x printString Q y printString Like other behavior that applies to all points the method should be put in point traits But what happens if printString is sent to the object traits point The printString method is found but it fails when it attempts to send x and y to itself because these slots are only defined in point objects not the traits point object Of course there are many other messages defined in traits point that would also fail if they were sent to traits point rather than to a point object The reason printing is a bigger problem is that it is useful to have a general object printing facility to be used during debugging and system exploration To be as robust as possible this print ing facility should not send printString when it will fai
111. or punitive damages in connection with or arising out of this license including loss of profits use data or other economic advantage however it arises whether for breach of warranty or in tort even if Sun Microsys tems Inc has been advised of the possibility of such damage Introduction Table of Contents Table of Contents 1 Introduction 1 1 1 Overview OF the SELF SySEBHL Lee rci deinen Meson inen ten Ried sp nin 1 NEN EVAIUEETTCE E 1 1 1 2 Th translation process eie eee et chs rr er EDU RES 2 Language Reference 3 2 1 2 2 2 3 2 4 OBJEC a r Mt EM pu MM r eee N 3 Dg Syta a ae ee eb ea pete e qe EPIS 3 2 12 IData obJeGts zu eerte db E e Potente ene pte eee eder edes 4 2 1 3 The assignment primitive eesessesseseeseeeeeeeeennen eene nennen nennen netter ene aE U et enne 4 2 1 4 Objects with code aee Ate eet entere bee f e trees 5 2 1 9 Constr ction of object literals inesse peremit tede ipit 7 SIOLUeSCPIDEOIS S oio os rebas na bee eh onsets negro Br reto pede aoa 7 2 24 Read only SIOS i5 tet oth et eee e nte te tele eq s as esie des 8 22 2 Read Write slots iscing oenetu eniti ees 8 2 2 3 Slots containing methods eese esee eene net net nennen nenne enne 9 2 24b Parent slots iioi tpe E HE em RED ANE Ee signees pias 11 2 2 5 Annotations ic eene dap ERE mem mds 11 EXDIOSSIOBS ubt Mera SU Eee RLS COE th Lp Cet tU e 11 2 3 WHALY messages soient e
112. or with add or addA11 for implicitly keyed collections Iteration can be done with do or with variations that allow the pro grammer to specify special handling of the first and or last element with Do allows pairwise it eration through two collections The includes occurrencesOf and findFirst IfPresent IfAbsent messages test for the presence of particular values in the collection filterBy Into creates a new collection including only those elements that satisfy a predicate block while mapBy Into creates a new collection whose elements are the result of applying the argument block to each element of the original collection Abstract collection behavior is defined in traits collection Only a small handful of operations need be implemented to create a new type of collection the rest can be inherited from traits col lection See the descendantResponsibility slot of traits collection The follow ing sections discuss various kinds of collection in more detail Modules collection abstract collection behavior 36 The SELF World Collections 3 5 1 Indexable Collections collection indexable mutableIndexable byteVector the string hierarchy sequence sortedSequence vector Indexable collections allow random access to their elements via keys that are integers All sequenc es and vectors are indexable The message at is used to retrieve an element of an indexable col lection while at
113. parent slot 6 argument conversion 80 argument conversions 81 argumentCountError 94 assignment primitive 4 assignmentMirror 69 associativity of binary messages 13 of keyword messages 14 of unary messages 12 B badIndexError 93 badSignError 93 badSizeError 94 badTypeError 93 badTypeSealError 93 binary message see message block 4 6 23 69 block data object 6 block method 23 non lifo block 23 non local return 23 blockActivationMirror 69 blockMethodMirror 69 blockMirror 69 bytecodes 2 byteVector 68 69 byteVectorMirror 69 C C glue 75 C glue 78 C_func_N 75 C_get_comp 77 C_get_var 77 C_set_comp 77 99 Introduction C_set_var 77 canonicalStringMirror 69 CC_delete 79 CC_new_N 79 character escapes 21 character set 18 cloning 24 closure 23 code 4 5 comments 22 compilation 2 conversion pair 80 customization 2 D data object 4 deadProxyError 71 94 directed resend 15 divisionByZeroError 93 dynamic inheritance 24 E empty object 4 encrypt c 73 errno 76 errors runtime errors 63 evaluation of arguments 5 of blocks 6 of message sends 5 F failure glue 76 false 68 fatal errors 65 fctProxy 42 68 71 floating point numbers parent of 69 floatMirror 69 foreign routines 71 foreignCode 42 foreignCodeDB 43 foreignFct 42 function proxy object 71 G glue 71 glue code 72 glueDefs c incl 72 I identifier 19 implicit receiver see message inheritance 24 dynamic inheritance 24
114. presentation this grammar is ambiguous precedence and associativity rules are used to re solve the ambiguities 26 The SELF World Syntax overview keyword slot slot name parent name small keyword cap keyword regular object small keyword identifier cap keyword identifier regular object identifier parent name identifier 27 The SELF World Built in types Appendix 2 D Built in types There are a small number of built in types that are directly supported through primitives and syn tax Integers and floats are provided with primitives for performing arithmetic operations comparisons etc Strings have a byte vector part for storing the characters Special string primitives are provided Blocks are objects which combine code with an environment link Used for control structures they are described in section 2 1 7 In addition there are a number of VM supported types described in the sections on the SELF World and the VM reference manual such as mirrors processes vectors proxies and profilers 28 The SELF World 3 The SELF World The default SELF world is a set of useful objects including objects that can be used in application programs e g integers strings and collections objects that support the programming environ ment e g the debugger and objects that simply are used to organize the other objects This doc ument describes how this world is organize
115. ptional initializer The SELF World Slot descriptors 2 2 1 Read only slots A slot name followed by an equals sign and an expression represents a read only slot initial ized to the result of evaluating the expression in the root context For example a constant point might be defined as C parent traits point x 3 4 y 5 ji The resulting point contains three initialized read only slots point traits parent X y 2 2 2 Read write slots There is no separate assignment operation in SELF Instead assignments to data slots are message sends that invoke the assignment primitive For example a data slot x is assignable if and only if there is a slot in the same object with the same name appended with a colon in this case x con taining the assignment primitive Therefore assigning 17 to slot x consists of sending the message x 17 Since this is indistinguishable from a message send that invokes a method clients do not need to know if x and x comprise data slot accesses or method invocations An identifier followed by a left arrow the characters lt and concatenated to form and an expression represents an initialized read write variable assignable data slot The object will contain both a data slot of that name and a corresponding assignment slot whose name is obtained by appending a colon to the data slot name The initializing expression is evaluated in t
116. reak the higher level invariants that foreignFct objects rely on Relevant oddballs linker dynamic linker for current platform sunLinker dynamic linker implementation for SunOS Solaris foreignCodeDB registry for foreignCode objects Modules foreign 3 11 I O and Unix oddball unix clonable proxy unixFile mixes in traits unixFile currentOsVariant The oddball object unix provides access to selected Unix system calls The most common calls are the file operations creat open close read write lseek and un link tcpConnectToHost Port IfFail opens a TCP connection The select call and the indirect system call are also supported taking a variable number of integer float or byte vector arguments the latter being passed as C pointers unixFile provides a higher level inter face to the Unix file operations The oddball object tt y implements terminal control facilities such as cursor positioning and highlighting Relevant oddballs stdin stdout stderr standard Unix streams tty console terminal capabilities Modules unix stdin tty ttySupport termcap 43 The SELF World Other Objects 3 12 Other Objects Here are some interesting oddball objects not discussed elsewhere comparator compilerProfiling an object that can compute diffs between sequences compiler profiling desktop The controlling object for the graphical user interface history A history of commands type
117. results in an error in the current implementation A non local return is a return from a method activation resulting from performing a return i e evaluating an expression preceded by the operator from within a lexically enclosed block A non local return forces returns from all activations between the method activation and the activation of the block performing the return The method holder of a method is the object containing the slot holding that method The sending method holder of a message is the method holder of the method that sent it A message is a request to an object to perform some operation The object to which the request is sent is called the receiver A message send is the action of sending a message to a receiver A primitive send is a message handled by invoking a primitive a predefined function provided by the SELF implementation Messages that do not have an explicit receiver are known as implicit receiver messages The receiver is bound to self A unary message is a message consisting of a single identifier sent to a receiver A binary mes sage is amessage consisting of an operator and a single argument sent to a receiver A keyword message is a message consisting of one or more identifiers with trailing colons each followed by an argument sent to a receiver 23 The SELF World Glossary e Unary binary and keyword slots are slots with selectors that match unary binary and key word messages respe
118. resume execution of the process in the background S to suspend execution of the process for process 25 k Process 25 killed Self 10 In this example the loop was interrupted by typing Control C and the process menu was used to abort the process If the user had typed q to quit the scheduler all current processes would have been aborted along with the scheduler itself Select a process or q to quit scheduler q Scheduler shut down prompt VM The scheduler has been stopped returning the user to the vM prompt The command prompt start restarts the scheduler VM prompt start Self 11 gt Although the vm prompt can be used to evaluate expressions directly the scheduler supports much nicer error messages and debugging so it is usually best to run the scheduler The scheduler is started automatically when the default world is created Certain virtual machine operations like garbage collection reading a snapshot and compilation cannot be interrupted interrupts during these operations will be deferred until the operation is T Normally you would use debugging facilities provided in the programming environment 46 The SELF World How to use the low level interrupt facilities complete As a last resort e g if the system appears to be hung you can force an abort by pressing Control five times in a row 3 15 Using the textual debugger If you are modifying the core of the programming en
119. rgs or any nonnegative integer expression can be used here 85 SELF Virtual Machine Reference Interfacing with other languages 7 This conversion is an escape it passes the C value unchanged to SELF It is an error to use it if the C value is not an oop 8 The proxy fctProxy object that is returned by these conversions is not being created by the glue code Rather a proxy fctProxy must be passed down from the SELF level This proxy ctProxy a result proxy will then be side effected by the glue the value that the foreign func tion returns will be stored in the result proxy together with the requested type seal It is required that the result proxy is dead when passed down else a 1iveProxyError results After being side effected and returned the result proxy is live The result proxy is the last argument of the function that the glue macro expands to 5 13 16 A complete application using foreign functions This section gives a description of a complete application which uses foreign functions The aim is to present a realistic and complete example of how foreign functions may be used The complete source for the example is found in the directory ob jects applications serverDemo in the SELF distribution The example used is an application that allows SELF expressions to be easily evaluated by non SELF processes Having this it then becomes possible to start SELF processes from a UNIX prompt shell or to specify pipe lines
120. rimitives Boolean false Argument to and returned by some primitives The prototype for normal vectors The prototype for byte vectors The prototype for proxy objects The prototype for fct Proxy objects The object that vector inherits from Since all object vectors will inherit from this object because they are cloned from vector this object will be the repository for shared behav ior a traits object for vectors Similar to vector parent the byteVector traits object 68 SELF Virtual Machine Reference The initial SELF world slotAnnotation objectAnnotation profiler mirrors The default slot annotation object The default object annotation object The prototype for profilers See below Literals and their parents integers 0 parent floats 0 0 parent canonical strings parent blocks parent Prototypical mirrors smiMirror floatMirror stringMirror processMirror byteVectorMirror obj VectorMirror assignmentMirror mirrorMirror slotsMirror blockMirror methodMirror blockMethodMirror Integers have one slot a parent slot called parent All integers have the same parent see 0 parent below All integers share this parent the integer traits object Floats have one slot a parent slot called parent AII floats have the same parent see 0 0 parent below All floats share this parent the float traits object In addition to a byte vector part a canonical string has one slot
121. roxy object char socks type seal for sockaddr_in proxies C_set_comp proxy sockaddr_in socks Sin_port short set_sin_port_glue The sockaddr_in example defines a function set sin port glue which can be called from SELF The function takes two arguments the first being a proxy representing a sockaddr in struct the second being a short integer After converting types set sin port glue performs the assignment first converted arg sin port second converted arg In general the meaning of the C get comp and C set comp arguments is cnvt res aux res how to convert the value of the component that is being read to a SELF object Any of the result conversions found in Table 3 may be applied cnvt strc aux strc the conversion that is applied to produce a struct upon which the operation is performed In the sin port example this conversion is a proxy conversion implying that in SELF the struct whose sin port component is assigned is represented by a proxy object In general any of the argument conversions from Table 3 that results in a pointer may be used e comp is the name of the component to be read or assigned In the sin port example this name is sin port Note that it includes a This e g allows handling pointers to int s by pretending that it is a pointer to a struct and operating on a component with an empty name e gfname the name of the C function that C get comp or C set comp expa
122. rt of the conversion is empty Table 3 lists all the possible values for the ci ai pair Handling failures Here is a slight modification of the encryption example to illustrate how the C function can raise an exception that causes the IfFail block to be invoked at the SELF level Make glue available by including it include incls _glueDefs c incl Naive encryption function char encrypt char str int key void FH static char res 1000 inb if key 0 failure FH key 0 is identity map return NULL for i 0 str i i res i str i key res i N0 return res Make glue expand to full functions not just prototypes define WHAT_GLUE FUNCTIONS C_func_2 string encrypt encrypt_glue fail string undef WHAT_GLUE cA int Observe that the ail opt argument now has the value fail and that the encrypt function raises an exception using failure if the key is 0 There are two ways to raise exceptions extern C void failure void FH char msg extern C void unix failure void FH int err 1 In both cases the FH argument is the failure handle that was passed by the C unc N macro The second argument to failure is a string It will be passed to the IfFail block in SELF unix failure takes an optional integer as its second argument If this integer has the value 1 or is missing the value of errno
123. s a SELF program It is found in the file serzver self When the server is started the following happens Create a socket bind a name to it and start listening 2 Loop accept a connection and fork a new process both step 1 and 2 are performed by the method server start The forked process executes the method server handleRequest which a Reads a line from the connection b Sets up a context with a slot stadio referring to the connection c Evaluates the line read in step a in this context d Closes the connection 5 13 19 Foreign functions and glue needed to implement server The server program needs to do a number of UNIX calls to create sockets and bind names to them etc The calls needed are socket bind listen accept and shutdown The first three of these are only called in a fixed sequence so to make things easier a small C function Socket bind listen that bundles them up in the right sequence has been written The ac cept function is more general than what is needed for this application so a wrapper function simple accept has been written The result is that the server needs to call only three foreign functions socket bind listen simple accept and shutdown Glue for these three func 88 SELF Virtual Machine Reference Interfacing with other languages tions and the source for the first two is found in the file socks c This file is compiled and linked using the Makefile The result is a shared object fi
124. s from the lobby 4 2 2 One of a kind Objects Oddballs Some objects such as the object t rue are unique it is only necessary to have one of them in the system It may even be important that the system contain exactly one of some kind of object Ob jects playing the role of unique objects are called oddballs Because there is no need to share the behavior of an oddball among many instances there is no need for an oddball to have separate traits and prototype objects Many oddballs inherit a copy method from traits oddball that returns the object itself rather than a new copy and most oddballs inherit the global namespace and default behavior from the lobby 56 SELF Styled Programming Naming and Printing 4 2 3 Inline Objects An inline object is an object that is nested in the code of a method object The inline object is usu ally intended for localized use within a program For example in a finite state machine implemen tation the state of the machine might be encoded in a selector that would be sent to an inline object to select the behavior for the next state transition state sendTo inComment c c ifTrue state inCode self inCode c c ifTrue state inComment False With nextChar In this case the inline object is playing the role of a case statement Another use of inline objects is to return multiple values from a method as discussed in section 4 4 Yet another u
125. s invocation of CC delete expands into t sockaddr_in is actually not a C class but a C struct However C treats structs and classes the same 79 SELF Virtual Machine Reference Interfacing with other languages 5 13 12 Calling member functions Calling member functions is similar to calling plain functions so please also refer to section 5 13 6 The difference is that an additional object must be specified the object upon which the member function is invoked the receiver in SELF terms Calling a member function is accom plished using one of the macros CC_mber_N cnvt_res aux_res cnvt_rec aux_rec mname gfname fail opt c0 a0 cl al cN aN For example here is how to call the member function zock on a sockaddr_in object given by a zt proxy CC mber O0 bool proxy sockaddr in socks zock zock glue The arguments to CC mber N are cnvt res aux res this pair which can be any of the result conversions from Table 3 specifies how to convert the result of the member function before returning it to SELF For example the zock member function returns a boolean e cnvt rec aux rec the object on which the member function is invoked Often this will be a proxy conversion as in the zock example mname is the name of the member function In general it may be any expression such that receiver mname evaluates to a function e gfname is the name of the C function that the CC mber N
126. s traits and prototypes like cloning traits and dictionaries These objects can be used or changed to implement your own programs transporter SELF Source Code disk file RunScript primitive parser SELF Objects SELF heap C SELF Source Code read eval print loop or ui keyboard di SELF Methods T il Compiled Method Wa with bytecodes when a method ai ti ala machine code SELF heap not in the code cache Compiled code cache is called Figure 2 How SELF programs are compiled UNIX is a trademark of AT amp T Bell Laboratories Introduction Overview of the SELF System 1 1 2 The translation process SELF programs are translated to machine code in a two stage process see Figure 2 Code typed in at the prompt through the user interface or read in from a file is parsed into SELF objects Some of these objects are data objects others are methods Methods have their own behavior which they represent with bytecodes The bytecodes are the instructions for a very simple virtual processor that understands instructions like push receiver or send the x message In fact SELF byte codes correspond much more closely to source code than say Smalltalk 80 bytecodes See CUL89 for a list of the SELF byte codes The raison d tre of the virtual machine is to pretend that these bytecodes are directly executed by the computer the program
127. se of inline objects is to parameterize the behavior of some other object For ex ample the predicate used to order objects in a priorityQueue can be specified using an inline object queue priorityQueue copyRemoveAll queue sorter element el Precedes e2 el gt e2 A block cannot be used here because the current implementation of SELF does not support non LIFO blocks and the sorter object may outlive the method that creates it There are undoubtedly other uses of inline objects Inline objects do not generally inherit from the lobby 4 3 Naming and Printing When debugging or exploring in the SELF world one often wants to answer the question what is that object The SELF environment provides two ways to answer that question First many ob jects respond to the printString message with a textual description of themselves This string is called the object s printString An object s printString can be quite detailed standard protocol allows the desired amount of detail to be specified by the requestor For example the printString for a collection might include the printStrings of all elements or just the first few Not all objects have printStrings only those that satisfy the criteria discussed in section 4 3 2 below The second way to describe an object is to give its path name A path name is a sequence of unary selectors that describes a path from the lobby to the object For example the full path name of the pro
128. sult conversion pair cnvt_res aux_res see Table 3 specifies how this pointer is converted to a SELF object before being returned In the sockaddr example the proxy result conver sion is used class is the name of the class or struct that is being instantiated e gfname the name of the C function that the CC new N macro expands into ci ai ifthe constructor takes arguments these arguments must be converted from SELF representation to C representation The arguments conversion pairs ci ai specify how each argument is converted See Table 3 for a description of all argument conversions In the sockaddr example there are no arguments 5 13 11 Deleting objects C objects can have destructors that are executed when the objects are deleted To ensure that the destructor is called properly the delete operator must know the type of the object being deleted This is ensured by using the CC delete macro which has the following form CC delete cnvt obj aux obj gfname For example to delete sockaddr in objects constructed as in the previous section the CC delete macro should be used in this manner CC delete proxy sockaddr in socks delete sockaddr in In general the meaning of the arguments given to CC delete Is cnvt obj aux obj this pair can be any of the argument conversions found in Table 3 that produces a pointer to the object that will be deleted gfname the name of the C function that thi
129. t How the ac tual message lookup is done is described in the Language Reference Manual No foo slot found in shell 0 The lookup found no slot matching the selector oo More than one system slot was found in shell 0 The matching slots are oddballs 6 and prototypes 7 The lookup found two matching system slots which means the message is ambig uous The error message also says where the matching slots were found Ambiguities can often be resolved by changing parent priorities e No fish delegatee slot was found in lt a child of lobby 12 The lookup found no parent slot ish which was explicitly specified as the dele gatee of the message 5 7 Programmer defined errors These are explicitly raised in the SELF program to report errors e g sending the message first to an empty list will cause such an error 64 SELF Virtual Machine Reference Low level error messages Error first is absent Receiver is list 7 Use the selectors error and error Arguments to raise a programmer defined error 5 8 Primitive errors Primitive failures occur when a primitive cannot perform the requested operation for example be cause of a missing or invalid argument badTypeError the IntAdd primitive failed Its receiver was shell 6 The primitive failed with badTypeError because the shell in not an integer The selector 12 could not be sent to shell because it is not
130. t IfEmpty doFirstLast Middle IfEmpty doFirstMiddle Last IfEmpty reverseDo with Do iterate with special behavior for first and last iterate with special behavior for first iterate with special behavior for ends iterate with special behavior for last iterate backwards through list co iterate passing corresponding elements to block 51 The SELF World Glossary of Useful Selectors Reducing max return maximum element mean return mean of elements min return minimum element sum return sum of elements product return product of elements reduce With evaluate reduction block with elements reduce With IfEmpty evaluate reduction block with elements evaluating block if empty Transforming asByte Vector return a byte vector with same elements asString return a string with same elements as Vector return a vector with same elements asList return a list with the same elements filterBy Into add elements that satisfy filter block to a collection mapBy add result of evaluating map block with each element to this collection mapBy Into add result of evaluating map block with each element to a collection Sorting sort sort receiver in place copySorted copy sorted in ascending order copyReverseSorted copy sorted in descending order copySortedBy copy sorted by custom sort criteria sortedDo iterate in ascending order reverseSortedDo iterate in descending order sortedBy Do iterate in order of custom sort
131. tegers floats characters or strings traits 35 The SELF World Collections randomLc defines a concrete specialization based on a simple linear congruence algorithm For convenience the prototype for randomLC is random not randomLc Modules random 3 4 2 Time clonable time A time object represents a date and time to the nearest millisecond since midnight GMT on Jan uary 1 1970 The message current returns a new time object containing the current time Two times can be compared using the standard comparison operators One time can be subtracted from another to produce a value in milliseconds An offset in milliseconds can be added or subtracted from a time object to produce a new time object However it is an error to add two time objects together Modules time 3 5 Collections clonable collection collection hierarchy Collections are containers that hold zero or more other objects In SELF collections behave as if they have a key associated with each value in the collection Collections without an obvious key such as lists use each element as both key and value Iterations over collections always pass both the value and the key of each element in that order to the iteration block Since SELF blocks ig nore extra arguments this allows applications that don t care about keys to simply provide a block that takes only one argument Collections have a rich protocol Additions are made with at Put
132. terface A foreign Code object represents an object file a file with executable code It defines methods for loading and unloading the object file it represents A foreignFct object represents a foreign routine It understands messages for calling the foreign routine and has associated with it a foreignCode object The foreignFct and foreignCode objects cooperate with the linker to ensure that 42 The SELF World T O and Unix object files are transparently loaded when necessary and that fct Proxies depending on an object file are killed when the object file is unloaded etc The foreignCodeDB object ensures that foreignCode objects are unique given a path It also allows for specifying initializers and finalizers on foreignCode objects An initializer is a foreign routine that is called whenever the object file is loaded Initializers take no arguments and do not return values Typically they initialize global data structures Finalizers are called when an object file is unloaded When debugging foreign routines foreignCodeDB printStatus outputs a useful overview Normal use of a foreign routine simply involves cloning a foreignF ct object to represent the for eign routine When cloning it the name of the function and the path of the object file is specified It is then not necessary to worry about proxy fctProxy and linker objects etc In fact it is recommended not to send messages directly to these objects since this may b
133. tespace is allowed between a minus sign and the digit sequence Real constants may be either written in fixed point or exponential form Integers may be written using bases from 2 to 36 For bases greater than ten the characters a through z case insensitive represent digit values 10 through 35 The default base is decimal A non decimal number is prefixed by its base value specified as a decimal number followed by either r or R Real numbers may be written in decimal only The exponent of a floating point format number in dicates multiplication of the mantissa by 10 raised to the exponent power i e nnnnEddd nnnn x 1044 A number with a digit that is not appropriate for the base will cause a lexical error as will an inte ger constant that is too large to be represented If the absolute value of a real constant is too large or too small to be represented the value of the constant will be infinity or zero respectively Productions number integer real integer base general digit general digit Unlike Smalltalk integer literals are limited in range to smallInts In situations where parsing the minus sign as part of the number would cause a parse error for example in the ex pression a 1 the minus is interpreted as a binary message a 1 20 The SELF World Lexical elements real fixed point float fixed point decimal decimal float decimal
134. th column lists the type of SELF object the conversion produc es The fifth column lists the kind of errors that can occur during the conversion Finally the sixth column contains references to numbered notes The notes are found in the paragraphs following the table Table 4 Result conversions from C C to SELF Conversion pus C C type SELF type Errors Notes void void smallInt 0 bool int boolean char char smallInt signed char signed char smallInt unsigned char unsigned char smallInt short short smallInt signed short signed short smallInt unsigned short unsigned short smallInt int int smallInt overflowError signed int signed int smallInt overflowError unsigned int unsigned int smallInt overflowError long long smallInt overflowError signed long signed long smallInt overflowError unsigned long unsignedlong smallInt overflowError 84 SELF Virtual Machine Reference Interfacing with other languages Table 4 Result conversions from C C to SELF Second Conversion bafi C C type SELF type Errors Notes smi smi smallInt overflowError int or errno n int int a UNIX error 1 float float float 2 double double float 2 long double long double float 2 string char byte vector nullPointerError 3 proxy ptr type ptr type proxy nullPointerError 3 4 8 type_seal proxy_null ptr_type ptr_type proxy 4 8 type_seal proxy_or_errn ptr
135. the parser converts objects in textual form into real SELF objects An object literal is constructed as follows First the slot initializers of every slot are evaluated from left to right If a slot initializer con tains another object literal this literal is constructed before the initializer containing it is evaluated If the initializer is an expression it is evaluated in the context of the lobby Second the object is created and its slots are initialized with the results of the evaluations performed in the first step Slot initializers are not evaluated in the lexical context since none exists at parse time they are evaluated in the context of an object known as the lobby That is the initializers are evaluated as if they were the code of a method in a slot of the 1obby This two phase object construction pro cess implies that slot initializers may not refer to any other slots within the constructed object as with Scheme s let and let rec forms and more generally that a slot initializer may not refer to any textually enclosing object literal 2 2 Slot descriptors An object can have any number of slots Slots can contain data data slots or methods Some slots have special roles argument slots are filled in with the actual arguments during a message send 82 3 3 and parent slots specify inheritance relationships 82 3 8 A slot descriptor consists of an optional privacy specification followed by the slot name and an o
136. the space used by plain objects and byte vectors respectively The above picture shows a situation in which about half of old space is filled with plain objects and about 2596 is filled with byte vectors A frac tion of old space s used portions is currently paged out gray areas Below the old space is a ruler marked in 1Mb intervals showing the total allocated in old space extending line at the left To the right is a red bar representing how much of old space is reserved for use by the Virtual Machine and a yellow bar representing the low space threshold when crossed the scheduler is notified and a garbage colelction may take place These four bars represent the cache holding compiled methods with their associated debugging and dependency information The bar labelled code represents the cache containing the actual machine code for methods including some headers and relocation information it is divided into code generated by the primary non inlining compiler or NIC and code generated by the secondary smarter compiler SIC The cache represented by the bar labelled deps contains dependency information for the compiled methods and the cache represented by the bar labelled debug contains the debugging information The three way split reduces the working set size of the code cache The cache represented by the bar labelled PICs contains polymorphic inline caches The segregation of the vector of bytes in byte vectors
137. tion receiver addAll add all elements of argument to receiver at Put add key value pair at Put If Absent add key value pair evaluating block if key is absent addFirst add element to head of list addLast add element to tail of list copy AddAII return a copy containing the elements of both receiver and argument copyContaining return a copy containing only the elements of the argument Removing remove remove the given element remove IfAbsent remove the given element evaluating block if absent removeAll remove all elements removeFirst remove first element from list removeLast remove last element from list removeAllOccurences remove all occurrences of this element from list removeKey remove element at the given key removeKey IfAbsent remove element at the given key evaluating block if absent copyRemoveAll return an empty copy Accessing first return the first element last return the last element includes test if element is member of the collection occurrencesOf return number of occurences of element in collection findFirst IfPresent IfAbsent evaluate present block on first element found satisfying criteria absent block if no such element at return element at the given key at IfAbsent return element at the given key evaluating block if absent includesKey test if collection contains a given key Iterating do iterate passing each element to argument block doFirst Middle Last IfEmpty doFirst MiddleLas
138. to the slot 2 3 5 Resending messages A resend allows an overridding method to invoke the overridden method Directed resends allow ambiguities among overridden methods to be resolved by constraining the lookup to search a sin gle parent slot Both resends and directed resends may change the name of the message being sent from the name of the current method and may pass different arguments than the arguments passed to the current method The receiver of a resend or a directed resend must be the implicit receiver Intuitively resend is similar to Smalltalk s super send and CLOS call next method A resend is written as an implicit receiver message with the reserved word resend a period and the message name No whitespace may separate resend the period and the message name Examples resend display resend 5 resend min 17 Max 23 A directed resend constrains the resend through a specified parent It is written similar to a normal resend but replaces resend with the name of the parent slot through which the resend is directed Examples listParent height intParent min 17 Max 23 Only implicit receiver messages may be delegated via a resend or a directed resend 2 3 6 Message lookup semantics This section describes the semantics of message lookups in SELF In addition to an informal tex tual description the lookup semantics are presented in pseudo code using the following notation s name The name of slot s s cont
139. totype list is globals list A path name is also an expression that can be evaluated in the con text of the lobby to produce the object Because globals is a parent slots it can be omitted from this path name expression Doing this yields the short path name list Not all objects have path names only those that can be reached from the lobby Such objects are called well known 4 3 1 How objects are printed When an expression is typed at the prompt it is evaluated to produce a result object The prompt then creates a mirror on this result object and asks the mirror to produce a name for the object A 57 SELF Styled Programming How to Return Multiple Values mirror is used because naming is reflective The object s creator path annotation provides a hint about the path from the lobby to either the object itself or its prototype If the object is a clone a or an is prepended to its prototype s creator path In addition to its path the mirror also tries to compute a printString for the object if it is annotated as isComplete Then the two pieces of information are merged For example the name of the prototype list is list but the name of list copy add 17 is a list 17 See the naming category in mirror traits for the details of this pro cess 4 3 2 How to make an object print The distinction between objects that hold shared behavior traits and mixin objects and concrete objects prototypes c
140. ts with code The feature that distinguishes a method object from a data object is that it has code whereas a data object does not Evaluating a method object does not simply return the object itself as with simple data objects rather its code is executed and the resulting value is returned 2 1 5 Code Code is a sequence of expressions 2 3 These expressions are evaluated in order and the result ing values are discarded except for that of the final expression whose value determines the result of evaluating the code The actual arguments in a message send are evaluated from left to right before the message is sent For instance in the expression leto cbe A Byz 2 Sy Do poke p koprint 1 is evaluated first then 5 i then2 j andthen k k print Finally the to By Do message is sent The associativity and precedence of messages is discussed in section 4 2 1 6 Methods Ordinary methods or simply methods are methods that are not embedded in other code A method can have argument slots 2 2 3 and or local slots An ordinary method always has an im plicit parent 82 2 4 argument slot named self Ordinary methods are SELF s equivalent of Smalltalk s methods If a slot contains a method the following steps are performed when the slot is evaluated as the re sult of a message send The method object is cloned creating a new method activation object containing slots for the method s arguments and locals
141. tters digits and underscores _ beginning with a lowercase letter or an underscore Case is significant apoint is not the same as aPoint Productions small letter gt a l b l 1 z cap letter gt A IPI letter small letter cap letter identifier small letter letter digit _ IntAdd cloud9 m a_point Examples i The two identifiers self and resend are reserved Identifiers beginning with underscores are re served for primitives 2 4 3 Keywords Keywords are used as slot names and as message names They consist of an identifier or a capital ized identifier followed by a colon Productions small keyword identifier 6 cap keyword cap letter letter digit Examples at Put IntAdd 2 4 4 Arguments A colon followed by an identifier denotes an argument slot name Production arg name identifier Example name 19 The SELF World Lexical elements 2 4 5 Operators An operator consists of a sequence of one or more of the following characters lo queam pn co em pee L D ee apo AN Two sequences are reserved and are not operators Productions op char SS OOH S rue qos EL EL S pte pee PEL e s bes P di 66 A operator op char op char Examples amp amp lt gt 2 4 6 Numbers Integer literals are written as a sequence of digits optionally prefixed with a minus sign and or a base No whi
142. turn Multiple Valles scien iie che e Lt heb ei tb tet ctis 58 Substituting Values for Blocks edt peperere nee rale re iens rob nra 59 il Considered NAW NOY seo seattle Doanh retta o 60 PEasldHdes bobo eo eoEtte e DIAM Ut Ma aM DELI ver ser 60 Equality Identity and Indistinguishability eee 61 Virtual Machine Reference 62 5 1 STAT Wp OP WON RR c Nr 62 5 2 System triggered Messages sco ORC nadVelidigdvabdtpqetauv aide qut t ebd 62 5 3 Run time message lookup errors aon sein soe emt etd ied e th etd atia dd 63 DAY Low level error Hie SSRES dee tie poete brit eti pensent epp i 63 5 5 Anexample cess Sree te tess eta ett Art i ADR a EERE es EEE N EE as 64 5 6 Lookup Errors ssa ye ee Wea E Um E A E a eee mies 64 5 7 Programmer defined errors esses eere 64 5 8 Primitive errors cedo Re Ree S E Ete RU Neb Horti erbe tet edes 65 5 9 Nonrecoverable process errors sssesessssssssseeseeeeer eren nene nennen tremere nentes 65 5 10 Fatal etfrors IEEE IERI UHR EE NER DER IER UPON 65 Sel Ehednitial SELE WOES ERE OPEM t ubt die teenie UR ertet 66 3 125 Option Pronit V s om ern ood iie patrie eda qu estin arent cd a taa Ri 70 5 13 Interfacing with other languages eese tenente tente tentenntnnes 71 5 13 1 Proxy and fctProxy objects Abbe cance ses ase itte tp e ien t A oe cen det de 71 5 13 2 Glue code 5 iet ee Oeo e ro CURRERE e eR REIR 72 5 13 3 Compiling and linking glue
143. ual Machine Reference Interfacing with other languages Table 3 Argument conversions from SELF to C C Second Conversion part SELF type C C type Errors Notes unsigned_long smallInt unsignedlong badSignError smi smallInt smi badTypeError 2 unsigned smi smallInt smi badSignError 2 badTypeError float float float badTypeError 3 double float double badTypeError 3 long double float long double badTypeError 3 bv ptr type byte vector ptr type badTypeError 4 bv len ptr type byte vector ptr type int badSizeError 4 5 badTypeError bv null ptr type byte vector O ptr type badTypeError 4 6 bv len null ptr type byte vector O ptr type int badSizeError 4 5 6 badTypeError cbv ptr type byte vector ptr type badTypeError 7 cbv len ptr type byte vector ptr type int badSizeError 7 badTypeError cbv null ptr type byte vector O ptr type badTypeError 7 cbv len null ptr type byte vector O ptr type int badSizeError 7 badTypeError string byte vector char badTypeError 8 nullCharError string len byte vector char int badTypeError 5 8 nullCharError string null byte vector O char badTypeError 6 8 nullCharError string len null byte vector O char int badTypeError 5 6 8 nullCharError proxy ptr_type proxy ptr_type badTypeError 9 type_seal NULL badTypeSealError deadProxyError nullPointerError proxy_null ptr_type proxy ptr_type badTypeError 9 type
144. ver possibly with embedded copies or initialization Comparing Equality equal l not equal hash hash value identical the same object this is reflective and should be avoided l not identical Ordered lt less than gt greater than lt less than or equal gt greater than or equal compare IfLess Equal Greater three way comparison compare IfLess Equal Greater Incomparable three way comparison with failure Numeric operations absolute Value inverse negate ceil floor truncate round asFloat asInteger double quadruple add subtract multiply divide divide exactly returns float divide and round to integer tends to round up divide and round up to integer divide and round down to integer modulus absolute value multiplicative inverse additive inverse round towards positive infinity round towards negative infinity truncate towards zero round coerce to float coerce to integer multiply by two multiply by four 48 The SELF World Glossary of Useful Selectors half quarter min max mean pred predecessor succ successor power log square squareRoot factorial fibonacci sign even odd divide by two divide by four minimum of receiver and argument maximum of receiver and argument mean of receiver and argument predecessor predecessor successor successor raise receiver to integer power logarithm of argument base receiver rounded down to
145. vironment or working without the environ ment you may need to use the textual debugger After attaching the aborted process to the debugger using the shell command attach these commands are available Command Description attach n attach the process with object reference number n detach detach the debugged process step n execute n non trivial bytecodes stepi n execute n bytecodes next n execute n non trivial bytecodes in the current activation nexti n execute n bytecodes in the current activation finish finish executing the current activation cont continue execution trace print out a stack trace of the process show display the current activation show n go to and display the nth activation on the stack status display the status of the debugged process up n go up n activation s upLex go up to the lexical enclosing scope of this activation down n go down n activation s lookup lt name gt lookup the given name in the context of the current activation a A bytecode is trivial if it is a push of a literal or a send to a slot residing in the lexical scope of the current activation 47 The SELF World Glossary of Useful Selectors Appendix 3 A Glossary of Useful Selectors This glossary lists some useful selectors It is by no means exhaustive Copying clone shallow copy for use within an object clients should use copy copy copy the recei
146. world To do this ask SELF to read expressions from a file VM all2 self RunScript Various configurations are possible a112 is the released system sma11UI2 is the same but without the various example applications and a11 contains the old release 3 0 experimental user interface Unless you have asked SELF not to print script names you should see something like reading all2 self reading init self 4 After all the files have been read in SELF will start the process scheduler initialize its module cache and print Se LE Q That last line is the SELF prompt indicating that the system is ready to read and evaluate ex pressions 45 The SELF World How to use the low level interrupt facilities 3 14 How to use the low level interrupt facilities There are two low level ways to interrupt a running SELF program Control C and Control The second way works even if the SELF process scheduler is not running In response to the interrupt you will see one of two things If the SELF scheduler is not running you will be returned directly to the vM prompt If the scheduler is running you will be presented with a list of SELF processes the process menu Self 9 gt 100000 100000 do C Interrupt Ready 25 scheduling process 100000 100000 do Select a process or q to quit scheduler 25 Select return for no action p to print the stack k to kill the process b to
147. xt strings in some fancy way It takes two arguments a string to encrypt and a key and returns a string which is the result of the encryption To use this function from SELF we write a line of C glue Here is the entire file encrypt c containing both the encryption function and the glue Make glue available by including it include incls _glueDefs c incl Naive encryption function char encrypt char str int key static char res 1000 INE s for i 0 str i i res i str i key res i 0 return res T Tf you try this example be sure to type in all the double commas they are necessary because of technical details with C macros 73 SELF Virtual Machine Reference Interfacing with other languages Make glue expand to full functions not just prototypes define WHAT_GLUE FUNCTIONS C_func_2 string encrypt encrypt_glue string int undef WHAT_GLUE A few words of explanation the last three lines of this file contain the glue code First defining WHAT_GLUE to be FUNCTIONS makes the following line expand into a full wrapper function de fining WHAT_GLUE to be PROTOTYPES instead will cause the C_func_2 line to produce a func tion prototype only The line containing the macro C_func_2 is the actual wrapper for encrypt The 2 designates that encrypt takes 2 arguments The meaning of the arguments from left to right are
Download Pdf Manuals
Related Search
Related Contents
三菱電機エアコン別売部品一 動昇降パネル取付 ・ 取扱説明書 Wireless Speaker Transmitter 1111 OWNER`S MANUAL Notice d'emploi Sandberg USB 2.0 A-B male 5 m BLACK Gear Head BT3000 4Runner 98 - 11 Land Cruiser 98 - 09 Sequoia 98 Graco Injecto-Flo II User's Manual Copyright © All rights reserved.
Failed to retrieve file