Message.st
changeset 17523 d921c9ecef2f
parent 14287 d172b79d6ebb
child 18120 e3a375d5f6a8
child 19888 1e9b0fd58bc9
equal deleted inserted replaced
17522:eea77b0b2c82 17523:d921c9ecef2f
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
    13 
    13 
       
    14 "{ NameSpace: Smalltalk }"
       
    15 
    14 Object subclass:#Message
    16 Object subclass:#Message
    15 	instanceVariableNames:'selector args'
    17 	instanceVariableNames:'selector args'
    16 	classVariableNames:''
    18 	classVariableNames:''
    17 	poolDictionaries:''
    19 	poolDictionaries:''
    18 	category:'Kernel-Methods'
    20 	category:'Kernel-Methods'
    34 "
    36 "
    35 !
    37 !
    36 
    38 
    37 documentation
    39 documentation
    38 "
    40 "
    39     Instances of Message represent a message being sent.
    41     Instances of Message represent a message being sent, consisting of
       
    42     the message selector and the message arguments.
       
    43 
    40     During normal execution, message objects are NEVER used -
    44     During normal execution, message objects are NEVER used -
    41     instead, argument passing is done more performant via the stack
    45     instead, argument passing is done more performant via the stack
    42     or in registers (depends on how your C compiler passes arguments).
    46     or in registers (depends on how your C compiler passes arguments).
    43 
    47 
    44     However, messageObjects ARE created, when a message send fails 
    48     However, messageObjects ARE created, when a message send fails 
    45     (i.e. some message is not understood).
    49     (i.e. some message is not understood).
    46     In this case, the selector and arguments of the failing messare
    50     In this case, the selector and arguments of the failing message
    47     are squashed into a new instance of Message, and a #doesNotUnderstand: 
    51     are squashed into a new instance of Message, and a #doesNotUnderstand: 
    48     message is sent to the original receiver, passing the message object
    52     message is sent to the original receiver, passing the message object
    49     as argument.
    53     as argument.
    50 
    54 
    51     Typically, #doesNotUnderstand: is not redefined in the receivers class,
    55     Typically, #doesNotUnderstand: is not redefined in the receiver's class,
    52     therefore Object>>doesNotUnderstand: gets evaluated.
    56     so the lookup finds Object>>doesNotUnderstand: and this is evaluated.
    53     There, a debugger is opened and the thread is suspended.
    57     There, a debugger is opened on the suspended thread (actually, it is a little
    54     However, it is possible to redefine this method, which
    58     more complicated: actually a MessageNotUnderstood exception is raised there,
    55     allows for re-evaluation of the failed send (after some cleanup),
    59     which - if not handled by an exception handler - opens the debugger).
    56     to upload some code or to simply ignore the error.
    60 
       
    61     However, it is possible and common to redefine the doesNotUnderstand method, 
       
    62     which allows for re-evaluation of the failed send (after some cleanup),
       
    63     to upload some code, to forward the message to another destination,
       
    64     or to simply ignore the error.
    57 
    65 
    58     As an example of its use, see the implementation of the Autoload-class,
    66     As an example of its use, see the implementation of the Autoload-class,
    59     or how ScrollableView forwards unknown messages to its slave-view.
    67     or how ScrollableView forwards unknown messages to its slave-view.
    60 
    68 
    61     Elegance hint: actually, Object>>doesNotUnderstand: raises an exception
    69     Elegance hint: as mentioned above, Object>>doesNotUnderstand: actually
    62     which can be handled - in most situations, providing an exception handler 
    70     raises an exception which can be handled. In many situations, providing 
    63     instead of redefining #doesNotUnderstand is the better way to do things.
    71     an exception handler instead of redefining #doesNotUnderstand is the 
       
    72     better way to do things.
    64 
    73 
    65 
    74 
    66     Notice:
    75     Notice:
    67     Since the layout of Message-objects is known by the runtime system
    76     The layout of Message-objects is known by the runtime system (VM)
    68     (it has to create those objects in case of a failure)
    77     (it has to create those objects in case of a failure)
    69     it is not allowed to change the definition of this class.
    78     so it is not allowed to change the definition of this class.
    70 
    79 
    71     [See also:]
    80     [See also:]
    72         Signal  Exception  MessageSend
    81         Signal  Exception  MessageSend
    73 
    82 
    74     [author:]
    83     [author:]
   261 ! !
   270 ! !
   262 
   271 
   263 !Message methodsFor:'sending'!
   272 !Message methodsFor:'sending'!
   264 
   273 
   265 sendTo:aReceiver
   274 sendTo:aReceiver
   266     "send the selector with argument to aReceiver"
   275     "send the selector with argument(s) to aReceiver"
   267 
   276 
   268     ^ aReceiver perform:selector withArguments:args
   277     ^ aReceiver perform:selector withArguments:args
   269 ! !
   278 ! !
   270 
   279 
   271 !Message class methodsFor:'documentation'!
   280 !Message class methodsFor:'documentation'!
   272 
   281 
   273 version
   282 version
   274     ^ '$Header: /cvs/stx/stx/libbasic/Message.st,v 1.34 2012-08-03 15:52:57 stefan Exp $'
   283     ^ '$Header: /cvs/stx/stx/libbasic/Message.st,v 1.35 2015-02-20 21:27:06 cg Exp $'
   275 ! !
   284 ! !
       
   285