Context.st
changeset 216 a8abff749575
parent 212 3edd10edefaf
child 282 94f5c3a6230d
--- a/Context.st	Thu Feb 02 13:13:16 1995 +0100
+++ b/Context.st	Thu Feb 02 13:23:05 1995 +0100
@@ -22,7 +22,7 @@
 COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Context.st,v 1.22 1994-11-22 23:02:55 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Context.st,v 1.23 1995-02-02 12:20:59 claus Exp $
 '!
 
 !Context class methodsFor:'documentation'!
@@ -43,7 +43,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Context.st,v 1.22 1994-11-22 23:02:55 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Context.st,v 1.23 1995-02-02 12:20:59 claus Exp $
 "
 !
 
@@ -74,30 +74,52 @@
     field for the method/block, and set it in the VM during program execution.
     (there may be some small performance penalty for this, though).
 
+    Notice: due to the compilation to machine code, methods and/or block do not
+    always (actually: do seldom) contain bytecodes. Thus, there is no such concept
+    as a bytecode p-counter. To support debugging, the linenumber within the
+    original source is instead remembered when a send or loop entry is performed.
+    Since linenumbers are not always sufficient for debugging (multiple sends in one
+    line), this will be changed in future versions to a character offset, giving
+    the position of the selector in the source.
 
     instance variables:
-	flags       <SmallInteger>          - used by the VM; never touch.
-					      contains info about number of args, locals and
-					      temporaries.
-	sender      <Context>               - the 'calling' context
-	home        <Context>               - the context, where this block was created, or nil
-	receiver    <Object>                - the receiver of this message
-	selector    <Symbol>                - the selector of this message
-	searchClass <Class>                 - the class, where the message lookup started
-					      (for super sends) or nil, for regular sends.
+	flags       <SmallInteger>          used by the VM; never touch.
+					    contains info about number of args, 
+					    locals and temporaries.
+
+	sender      <Context>               the 'calling / sending' context
+
+	home        <Context>               the context, where this block was 
+					    created, or nil if its a method context
+					    There are also cheap blocks, which do
+					    not need a reference to the home context,
+					    for those, its nil too.
+
+	receiver    <Object>                the receiver of this message
+
+	selector    <Symbol>                the selector of this message
+
+	searchClass <Class>                 the class, where the message lookup started
+					    (for super sends) or nil, for regular sends.
 
-	lineNr      <SmallInteger>          - the position where the context left off
-					      (kind of p-counter)
+	lineNr      <SmallInteger>          the position where the context left off
+					    (kind of p-counter)
 
-	retValTemp  nil                     - temporary - always nil, when you see the context
-					      (used in the VM as temporary)
+	retValTemp  nil                     temporary - always nil, when you see the context
+					    (used in the VM as temporary)
+
+	handle      *noObject*              used by the VM; not accessable, not an object
 
-	handle      *noObject*              - used by the VM; not accessable, not an object
+	<indexed>                           arguments of the send followed by
+					    locals of the method/block followed by
+					    temporaries.
 
-	<indexed>                           - arguments of the send followed by
-					      locals of the method/block followed by
-					      temporaries
-
+    class variables:
+	InvalidReturnSignal                 signal raised when a block tries
+					    to return ('^') from a method context
+					    which itself has already returned
+					    (i.e. there is no place to return to)
+        
     WARNING: layout and size known by the compiler and runtime system - do not change.
 "
 ! !
@@ -245,6 +267,16 @@
     c notNil ifTrue:[
 	^ c compiledMethodAt:selector
     ].
+
+    "mhmh - seems to be a context for an unbound method;
+     look in the senders context. Consider this a kludge.
+     (maybe it was not too good of an idea to not keep the current
+      method in the context ....)
+    "
+    (sender notNil and:[sender selector startsWith:'valueWithReceiver:']) ifTrue:[
+	^ sender receiver
+    ].
+
     ^ nil
 !
 
@@ -467,7 +499,13 @@
 	    self searchClass ~~ receiverClass ifTrue:[
 		newString := newString , '>>>' , self searchClass name
 	    ].
-	    newString := newString , '>>>**NONE**'
+	    "
+	     kludge for doIt - these unbound methods are not
+	     found in the classes methodDictionary
+	    "
+	    selector ~~ #doIt ifTrue:[
+		newString := newString , '>>>**NONE**'
+	    ]
 	]
     ].
 
@@ -644,9 +682,15 @@
      starting with this context, find the one below and return from it
     "
     con := thisContext.
-    [con notNil and:[con sender ~~ self]] whileTrue:[
-	con := con sender
-    ].
+%{
+    while ((con != nil) && (_ContextInstPtr(con)->c_sender != self)) {
+	con = _ContextInstPtr(con)->c_sender;
+    }
+%}.
+"/    [con notNil and:[con sender ~~ self]] whileTrue:[
+"/        con := con sender
+"/    ].
+
     con isNil ifTrue:[
 	"
 	 debugging ...
@@ -689,7 +733,7 @@
 	 currently a context can only be unwound by
 	 the owning process - not from outside."
 
-    |con sel|
+    |con sel unwindBlock|
 
     sender isNil ifTrue:[
 	"
@@ -715,7 +759,8 @@
 		"
 		 ... the way we evaluate the unwind blocks too
 		"
-		(con argAt:1) value
+		unwindBlock := con argAt:1.
+		unwindBlock value
 	    ]
 	].
 	con := con sender
@@ -758,7 +803,7 @@
 	 currently a context can only be restarted by
 	 the owning process - not from outside."
 
-    |con sel|
+    |con sel unwindBlock|
 
     "
      start with this context, moving up, looking for unwind actions
@@ -774,7 +819,8 @@
 		"
 		 ... the way we evaluate the unwind blocks too
 		"
-		(con argAt:1) value
+		unwindBlock := con argAt:1.
+		unwindBlock value
 	    ]
 	].
 	con := con sender