Context.st
branchjv
changeset 25392 c52eeea62763
parent 23107 40173e082cbc
child 25395 b5d6963fe4a9
equal deleted inserted replaced
25391:cad52f81f60c 25392:c52eeea62763
     1 "
     1 "
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     3  COPYRIGHT (c) 2009-2011 Jan Vrany
     3  COPYRIGHT (c) 2009-2011 Jan Vrany
     4  COPYRIGHT (c) 2015-2017 Jan Vrany
     4  COPYRIGHT (c) 2015-2017 Jan Vrany
       
     5  COPYRIGHT (c) 2020 LabWare
     5 	      All Rights Reserved
     6 	      All Rights Reserved
     6 
     7 
     7  This software is furnished under a license and may be used
     8  This software is furnished under a license and may be used
     8  only in accordance with the terms of that license and with the
     9  only in accordance with the terms of that license and with the
     9  inclusion of the above copyright notice.   This software may not
    10  inclusion of the above copyright notice.   This software may not
    28 copyright
    29 copyright
    29 "
    30 "
    30  COPYRIGHT (c) 1988 by Claus Gittinger
    31  COPYRIGHT (c) 1988 by Claus Gittinger
    31  COPYRIGHT (c) 2009-2011 Jan Vrany
    32  COPYRIGHT (c) 2009-2011 Jan Vrany
    32  COPYRIGHT (c) 2015-2017 Jan Vrany
    33  COPYRIGHT (c) 2015-2017 Jan Vrany
       
    34  COPYRIGHT (c) 2020 LabWare
    33 	      All Rights Reserved
    35 	      All Rights Reserved
    34 
    36 
    35  This software is furnished under a license and may be used
    37  This software is furnished under a license and may be used
    36  only in accordance with the terms of that license and with the
    38  only in accordance with the terms of that license and with the
    37  inclusion of the above copyright notice.   This software may not
    39  inclusion of the above copyright notice.   This software may not
  2545     ^ nil
  2547     ^ nil
  2546 ! !
  2548 ! !
  2547 
  2549 
  2548 !Context methodsFor:'special accessing'!
  2550 !Context methodsFor:'special accessing'!
  2549 
  2551 
  2550 argAndVarNames
       
  2551     "helper: given a context, return a collection of arg&var names"
       
  2552 
       
  2553     |homeContext homeMethod block numArgs numVars m src
       
  2554      sel isDoIt blocksLineNr extractFromBlock sender|
       
  2555 
       
  2556     numArgs := self argumentCount.
       
  2557     numVars := self numVars.
       
  2558     (numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()].
       
  2559 
       
  2560     homeContext := self methodHome.
       
  2561     homeContext notNil ifTrue:[
       
  2562         sel := homeContext selector.
       
  2563         homeMethod := homeContext method.
       
  2564     ].
       
  2565 
       
  2566     extractFromBlock :=
       
  2567         [
       
  2568             |blockNode argNames varNames vars args blocksHome|
       
  2569 
       
  2570             blockNode := Compiler
       
  2571                             blockAtLine:blocksLineNr
       
  2572                             in:m
       
  2573                             orSource:src
       
  2574                             numArgs:numArgs
       
  2575                             numVars:numVars.
       
  2576 
       
  2577             blockNode notNil ifTrue:[
       
  2578                 "/ a kludge
       
  2579                 blockNode lineNumber == blocksLineNr ifTrue:[
       
  2580                     blocksHome := blockNode home.
       
  2581                     (blocksHome notNil and:[blocksHome isBlock]) ifTrue:[
       
  2582                         (blocksHome numArgs == numArgs
       
  2583                         and:[ blocksHome numVars == numVars ]) ifTrue:[
       
  2584                             blockNode := blocksHome
       
  2585                         ].
       
  2586                     ].
       
  2587                 ].
       
  2588 
       
  2589                 argNames := #().
       
  2590                 varNames := #().
       
  2591 
       
  2592                 numArgs > 0 ifTrue:[
       
  2593                     vars := blockNode arguments.
       
  2594                     vars notEmptyOrNil ifTrue:[
       
  2595                         argNames := vars collect:[:var | var name]
       
  2596                     ]
       
  2597                 ].
       
  2598                 numVars > 0 ifTrue:[
       
  2599                     vars := blockNode variablesIncludingInlined: (homeMethod hasCode and:[homeMethod isDynamic not]).
       
  2600                     vars notEmptyOrNil ifTrue:[
       
  2601                         varNames := vars collect:[:var | var name].
       
  2602                     ]
       
  2603                 ].
       
  2604                 ^ argNames , varNames
       
  2605             ].
       
  2606         ].
       
  2607 
       
  2608     "/ #doIt needs special handling below
       
  2609     isDoIt := (sel == #'doIt') or:[sel == #'doIt:'].
       
  2610     self isBlockContext ifFalse:[
       
  2611         isDoIt ifTrue:[
       
  2612             homeMethod notNil ifTrue:[
       
  2613                 "/ special for #doIt
       
  2614                 m := nil.
       
  2615                 src := ('[' , homeMethod source , '\]') withCRs.
       
  2616                 "/ blocksLineNr := self lineNumber.
       
  2617                 blocksLineNr := (self home ? self) lineNumber.
       
  2618                 extractFromBlock value.
       
  2619             ]
       
  2620         ].
       
  2621 
       
  2622         homeMethod notNil ifTrue:[
       
  2623             ^ homeMethod methodArgAndVarNamesInContext: self.
       
  2624         ].
       
  2625         ^ #()
       
  2626     ].
       
  2627 
       
  2628     homeMethod notNil ifTrue:[
       
  2629         isDoIt ifTrue:[
       
  2630             "/ special for #doIt
       
  2631             "/ my source is found in the method.
       
  2632             m := nil.
       
  2633             src := ('[' , homeMethod source , '\]') withCRs.
       
  2634         ] ifFalse:[
       
  2635             m := homeMethod.
       
  2636             src := nil.
       
  2637         ].
       
  2638         blocksLineNr := self lineNumber.
       
  2639         extractFromBlock value.
       
  2640         blocksLineNr := self home lineNumber.
       
  2641         extractFromBlock value.
       
  2642     ].
       
  2643 
       
  2644     blocksLineNr isNil ifTrue:[
       
  2645         self isBlockContext ifTrue:[
       
  2646             sender := self sender.
       
  2647             (sender notNil
       
  2648             and:[sender receiver isBlock
       
  2649             and:[sender selector startsWith:'value']])
       
  2650             ifTrue:[
       
  2651                 block := sender receiver.
       
  2652                 src := block source.
       
  2653                 src isNil ifTrue:[
       
  2654                     self error:'no source'.
       
  2655                 ].
       
  2656                 blocksLineNr := 1.
       
  2657                 extractFromBlock value.
       
  2658             ].
       
  2659             sender := nil.
       
  2660         ].
       
  2661     ].
       
  2662 
       
  2663     ^ #()
       
  2664 
       
  2665     "Modified: / 26-12-2015 / 08:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  2666 !
       
  2667 
       
  2668 canResume
  2552 canResume
  2669     "return true, if the receiver allows to be resumed.
  2553     "return true, if the receiver allows to be resumed.
  2670      In ST/X, due to the implementation, this requires that the context which
  2554      In ST/X, due to the implementation, this requires that the context which
  2671      is right below the receiver is returnable and still active."
  2555      is right below the receiver is returnable and still active."
  2672 
  2556