874 temporaries |
874 temporaries |
875 "return an array filled with the temporaries of this context" |
875 "return an array filled with the temporaries of this context" |
876 |
876 |
877 |nonTemps mySize| |
877 |nonTemps mySize| |
878 |
878 |
879 nonTemps := self numArgs + self numVars. |
879 nonTemps := self argumentCount + self numVars. |
880 mySize := self numTemps. |
880 mySize := self numTemps. |
881 mySize == 0 ifTrue:[ |
881 mySize == 0 ifTrue:[ |
882 "/ little optimization here - avaoid creating empty containers |
882 "/ little optimization here - avaoid creating empty containers |
883 ^ #() |
883 ^ #() |
884 ]. |
884 ]. |
885 ^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
885 ^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
886 |
886 |
887 "Modified: 23.10.1996 / 16:20:00 / cg" |
887 "Modified: 23.10.1996 / 16:20:00 / cg" |
888 ! |
888 ! |
889 |
889 |
890 varAt:n |
890 varAt:n |
891 "return the n'th local variable" |
891 "return the n'th local variable" |
892 |
892 |
893 ^ self at:(n + self numArgs) |
893 ^ self at:(n + self argumentCount) |
894 ! |
894 ! |
895 |
895 |
896 varAt:n put:value |
896 varAt:n put:value |
897 "set the n'th local variable - useful when the receiver should be restarted |
897 "set the n'th local variable - useful when the receiver should be restarted |
898 or continued" |
898 or continued" |
899 |
899 |
900 self at:(n + self numArgs) put:value |
900 self at:(n + self argumentCount) put:value |
901 ! |
901 ! |
902 |
902 |
903 vars |
903 vars |
904 "return an array filled with the local variables of this context" |
904 "return an array filled with the local variables of this context" |
905 |
905 |
906 |nonVars mySize| |
906 |nonVars mySize| |
907 |
907 |
908 nonVars := self numArgs. |
908 nonVars := self argumentCount. |
909 mySize := self numVars. |
909 mySize := self numVars. |
910 mySize == 0 ifTrue:[ |
910 mySize == 0 ifTrue:[ |
911 "/ little optimization here - avaoid creating empty containers |
911 "/ little optimization here - avaoid creating empty containers |
912 ^ #() |
912 ^ #() |
913 ]. |
913 ]. |
914 ^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
914 ^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
915 |
915 |
916 "Modified: 23.10.1996 / 16:20:06 / cg" |
916 "Modified: 23.10.1996 / 16:20:06 / cg" |
917 ! ! |
917 ! ! |
2531 "helper: given a context, return a collection of arg&var names" |
2531 "helper: given a context, return a collection of arg&var names" |
2532 |
2532 |
2533 |homeContext homeMethod block numArgs numVars m src |
2533 |homeContext homeMethod block numArgs numVars m src |
2534 sel isDoIt blocksLineNr extractFromBlock sender| |
2534 sel isDoIt blocksLineNr extractFromBlock sender| |
2535 |
2535 |
2536 numArgs := self numArgs. |
2536 numArgs := self argumentCount. |
2537 numVars := self numVars. |
2537 numVars := self numVars. |
2538 (numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()]. |
2538 (numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()]. |
2539 |
2539 |
2540 homeContext := self methodHome. |
2540 homeContext := self methodHome. |
2541 homeContext notNil ifTrue:[ |
2541 homeContext notNil ifTrue:[ |
2542 sel := homeContext selector. |
2542 sel := homeContext selector. |
2543 homeMethod := homeContext method. |
2543 homeMethod := homeContext method. |
2544 ]. |
2544 ]. |
2545 |
2545 |
2546 extractFromBlock := |
2546 extractFromBlock := |
2547 [ |
2547 [ |
2548 |blockNode argNames varNames vars args blocksHome| |
2548 |blockNode argNames varNames vars args blocksHome| |
2549 |
2549 |
2550 blockNode := Compiler |
2550 blockNode := Compiler |
2551 blockAtLine:blocksLineNr |
2551 blockAtLine:blocksLineNr |
2552 in:m |
2552 in:m |
2553 orSource:src |
2553 orSource:src |
2554 numArgs:numArgs |
2554 numArgs:numArgs |
2555 numVars:numVars. |
2555 numVars:numVars. |
2556 |
2556 |
2557 blockNode notNil ifTrue:[ |
2557 blockNode notNil ifTrue:[ |
2558 "/ a kludge |
2558 "/ a kludge |
2559 blockNode lineNumber == blocksLineNr ifTrue:[ |
2559 blockNode lineNumber == blocksLineNr ifTrue:[ |
2560 blocksHome := blockNode home. |
2560 blocksHome := blockNode home. |
2561 (blocksHome notNil and:[blocksHome isBlock]) ifTrue:[ |
2561 (blocksHome notNil and:[blocksHome isBlock]) ifTrue:[ |
2562 (blocksHome numArgs == numArgs |
2562 (blocksHome numArgs == numArgs |
2563 and:[ blocksHome numVars == numVars ]) ifTrue:[ |
2563 and:[ blocksHome numVars == numVars ]) ifTrue:[ |
2564 blockNode := blocksHome |
2564 blockNode := blocksHome |
2565 ]. |
2565 ]. |
2566 ]. |
2566 ]. |
2567 ]. |
2567 ]. |
2568 |
2568 |
2569 argNames := #(). |
2569 argNames := #(). |
2570 varNames := #(). |
2570 varNames := #(). |
2571 |
2571 |
2572 numArgs > 0 ifTrue:[ |
2572 numArgs > 0 ifTrue:[ |
2573 vars := blockNode arguments. |
2573 vars := blockNode arguments. |
2574 vars notEmptyOrNil ifTrue:[ |
2574 vars notEmptyOrNil ifTrue:[ |
2575 argNames := vars collect:[:var | var name] |
2575 argNames := vars collect:[:var | var name] |
2576 ] |
2576 ] |
2577 ]. |
2577 ]. |
2578 numVars > 0 ifTrue:[ |
2578 numVars > 0 ifTrue:[ |
2579 vars := blockNode variablesIncludingInlined: (homeMethod code notNil and:[homeMethod byteCode isNil]). |
2579 vars := blockNode variablesIncludingInlined: (homeMethod code notNil and:[homeMethod byteCode isNil]). |
2580 vars notEmptyOrNil ifTrue:[ |
2580 vars notEmptyOrNil ifTrue:[ |
2581 varNames := vars collect:[:var | var name]. |
2581 varNames := vars collect:[:var | var name]. |
2582 ] |
2582 ] |
2583 ]. |
2583 ]. |
2584 ^ argNames , varNames |
2584 ^ argNames , varNames |
2585 ]. |
2585 ]. |
2586 ]. |
2586 ]. |
2587 |
2587 |
2588 "/ #doIt needs special handling below |
2588 "/ #doIt needs special handling below |
2589 isDoIt := (sel == #'doIt') or:[sel == #'doIt:']. |
2589 isDoIt := (sel == #'doIt') or:[sel == #'doIt:']. |
2590 self isBlockContext ifFalse:[ |
2590 self isBlockContext ifFalse:[ |
2591 isDoIt ifTrue:[ |
2591 isDoIt ifTrue:[ |
2592 homeMethod notNil ifTrue:[ |
2592 homeMethod notNil ifTrue:[ |
2593 "/ special for #doIt |
2593 "/ special for #doIt |
2594 m := nil. |
2594 m := nil. |
2595 src := ('[' , homeMethod source , '\]') withCRs. |
2595 src := ('[' , homeMethod source , '\]') withCRs. |
2596 "/ blocksLineNr := self lineNumber. |
2596 "/ blocksLineNr := self lineNumber. |
2597 blocksLineNr := (self home ? self) lineNumber. |
2597 blocksLineNr := (self home ? self) lineNumber. |
2598 extractFromBlock value. |
2598 extractFromBlock value. |
2599 ] |
2599 ] |
2600 ]. |
2600 ]. |
2601 |
2601 |
2602 homeMethod notNil ifTrue:[ |
2602 homeMethod notNil ifTrue:[ |
2603 ^ homeMethod methodArgAndVarNamesInContext: self. |
2603 ^ homeMethod methodArgAndVarNamesInContext: self. |
2604 ]. |
2604 ]. |
2605 ^ #() |
2605 ^ #() |
2606 ]. |
2606 ]. |
2607 |
2607 |
2608 homeMethod notNil ifTrue:[ |
2608 homeMethod notNil ifTrue:[ |
2609 isDoIt ifTrue:[ |
2609 isDoIt ifTrue:[ |
2610 "/ special for #doIt |
2610 "/ special for #doIt |
2611 "/ my source is found in the method. |
2611 "/ my source is found in the method. |
2612 m := nil. |
2612 m := nil. |
2613 src := ('[' , homeMethod source , '\]') withCRs. |
2613 src := ('[' , homeMethod source , '\]') withCRs. |
2614 ] ifFalse:[ |
2614 ] ifFalse:[ |
2615 m := homeMethod. |
2615 m := homeMethod. |
2616 src := nil. |
2616 src := nil. |
2617 ]. |
2617 ]. |
2618 blocksLineNr := self lineNumber. |
2618 blocksLineNr := self lineNumber. |
2619 extractFromBlock value. |
2619 extractFromBlock value. |
2620 blocksLineNr := self home lineNumber. |
2620 blocksLineNr := self home lineNumber. |
2621 extractFromBlock value. |
2621 extractFromBlock value. |
2622 ]. |
2622 ]. |
2623 |
2623 |
2624 blocksLineNr isNil ifTrue:[ |
2624 blocksLineNr isNil ifTrue:[ |
2625 self isBlockContext ifTrue:[ |
2625 self isBlockContext ifTrue:[ |
2626 sender := self sender. |
2626 sender := self sender. |
2627 (sender notNil |
2627 (sender notNil |
2628 and:[sender receiver isBlock |
2628 and:[sender receiver isBlock |
2629 and:[sender selector startsWith:'value']]) |
2629 and:[sender selector startsWith:'value']]) |
2630 ifTrue:[ |
2630 ifTrue:[ |
2631 block := sender receiver. |
2631 block := sender receiver. |
2632 src := block source. |
2632 src := block source. |
2633 src isNil ifTrue:[ |
2633 src isNil ifTrue:[ |
2634 self error:'no source'. |
2634 self error:'no source'. |
2635 ]. |
2635 ]. |
2636 blocksLineNr := 1. |
2636 blocksLineNr := 1. |
2637 extractFromBlock value. |
2637 extractFromBlock value. |
2638 ]. |
2638 ]. |
2639 sender := nil. |
2639 sender := nil. |
2640 ]. |
2640 ]. |
2641 ]. |
2641 ]. |
2642 |
2642 |
2643 ^ #() |
2643 ^ #() |
2644 |
2644 |
2645 "Modified: / 19-08-2013 / 12:13:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2645 "Modified: / 19-08-2013 / 12:13:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2845 |
2845 |
2846 count := 0. |
2846 count := 0. |
2847 |
2847 |
2848 c := self findNextContextWithSelector:selector or:nil or:nil. |
2848 c := self findNextContextWithSelector:selector or:nil or:nil. |
2849 [c notNil] whileTrue:[ |
2849 [c notNil] whileTrue:[ |
2850 (c receiver == receiver) ifTrue:[ |
2850 (c receiver == receiver) ifTrue:[ |
2851 c method == self method ifTrue:[ |
2851 c method == self method ifTrue:[ |
2852 sameArgs := true. |
2852 sameArgs := true. |
2853 1 to:self numArgs do:[:i | |
2853 1 to:self argumentCount do:[:i | |
2854 (c argAt:1) ~~ (self argAt:i)ifTrue:[ |
2854 (c argAt:1) ~~ (self argAt:i)ifTrue:[ |
2855 sameArgs := false |
2855 sameArgs := false |
2856 ] |
2856 ] |
2857 ]. |
2857 ]. |
2858 sameArgs ifTrue:[^ true]. |
2858 sameArgs ifTrue:[^ true]. |
2859 ] |
2859 ] |
2860 ]. |
2860 ]. |
2861 c := c findNextContextWithSelector:selector or:nil or:nil. |
2861 c := c findNextContextWithSelector:selector or:nil or:nil. |
2862 |
2862 |
2863 " |
2863 " |
2864 this special test was added to get out after a while |
2864 this special test was added to get out after a while |
2865 if the sender chain is corrupt - this gives us at least |
2865 if the sender chain is corrupt - this gives us at least |
2866 a chance to find those errors. |
2866 a chance to find those errors. |
2867 " |
2867 " |
2868 count := count + 1. |
2868 count := count + 1. |
2869 count >= 100000 ifTrue:[ |
2869 count >= 100000 ifTrue:[ |
2870 'Context [warning]: bad context chain' errorPrintCR. |
2870 'Context [warning]: bad context chain' errorPrintCR. |
2871 ^ true |
2871 ^ true |
2872 ] |
2872 ] |
2873 ]. |
2873 ]. |
2874 ^ false |
2874 ^ false |
2875 ! |
2875 ! |
2876 |
2876 |
2877 isRecursive |
2877 isRecursive |