MessageNd.st
changeset 817 8de90dbed4bb
parent 812 367d2e8eb499
child 843 522c116f86d9
equal deleted inserted replaced
816:8af2f8b5f6fc 817:8de90dbed4bb
  1894     "Modified: 19.10.1997 / 01:31:40 / cg"
  1894     "Modified: 19.10.1997 / 01:31:40 / cg"
  1895 !
  1895 !
  1896 
  1896 
  1897 codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
  1897 codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
  1898     "generate code for
  1898     "generate code for
  1899 	[...] whileXXX:[ ... ] 
  1899         [...] whileXXX:[ ... ] 
  1900      and also 
  1900      and also 
  1901 	[...] whileXXX
  1901         [...] whileXXX
  1902     "
  1902     "
  1903 
  1903 
  1904     |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
  1904     |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
  1905      hasLoopBlock fastReceiver|
  1905      hasLoopBlock fastReceiver|
  1906 
  1906 
  1907     hasLoopBlock := true.
  1907     hasLoopBlock := true.
  1908     (selector == #whileTrue:) ifTrue:[
  1908     (selector == #whileTrue:) ifTrue:[
  1909 	theByteCode := #falseJump.
  1909         theByteCode := #falseJump.
  1910     ] ifFalse:[
  1910     ] ifFalse:[
  1911 	(selector == #whileFalse:) ifTrue:[
  1911         (selector == #whileFalse:) ifTrue:[
  1912 	    theByteCode := #trueJump
  1912             theByteCode := #trueJump
  1913 	] ifFalse:[
  1913         ] ifFalse:[
  1914 	    hasLoopBlock := false.
  1914             hasLoopBlock := false.
  1915 	    (selector == #whileTrue) ifTrue:[
  1915             (selector == #whileTrue) ifTrue:[
  1916 		theByteCode := #trueJump
  1916                 theByteCode := #trueJump
  1917 	    ] ifFalse:[
  1917             ] ifFalse:[
  1918 		theByteCode := #falseJump
  1918                 theByteCode := #falseJump
  1919 	    ].
  1919             ].
  1920 	]
  1920         ]
  1921     ].
  1921     ].
  1922 
  1922 
  1923     theReceiver := receiver.
  1923     theReceiver := receiver.
  1924 
  1924 
  1925 (receiver isBlock
  1925 (receiver isBlock
  1926 and:[receiver statements notNil
  1926 and:[receiver statements notNil
  1927 and:[receiver statements nextStatement isNil
  1927 and:[receiver statements nextStatement isNil
  1928 and:[receiver statements expression notNil]]])
  1928 and:[receiver statements expression notNil]]])
  1929     ifTrue:[
  1929     ifTrue:[
  1930 	fastReceiver := receiver statements expression.
  1930         fastReceiver := receiver statements expression.
  1931 	optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode.
  1931         optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode.
  1932     ] ifFalse:[
  1932     ] ifFalse:[
  1933 	optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
  1933         optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
  1934     ].
  1934     ].
  1935 
  1935 
  1936     optByteCode notNil ifTrue:[
  1936     optByteCode notNil ifTrue:[
  1937 	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
  1937         ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
  1938 	    theArg := receiver statements expression arg1
  1938             theArg := receiver statements expression arg1
  1939 	].
  1939         ].
  1940 	theReceiver := receiver statements expression receiver.
  1940         theReceiver := receiver statements expression receiver.
  1941 	theByteCode := optByteCode
  1941         theByteCode := optByteCode
  1942     ].
  1942     ].
  1943 
  1943 
  1944 "/ OLD:
  1944 "/ OLD:
  1945 "/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
  1945 "/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
  1946 "/
  1946 "/
  1947     needLineNr := true.
  1947     needLineNr := true.
  1948 
  1948 
  1949     pos := aStream position.
  1949     pos := aStream position.
  1950 
  1950 
  1951 "/    aCompiler lineNumberInfo == #full ifTrue:[
  1951 "/    aCompiler lineNumberInfo == #full ifTrue:[
  1952 	ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
  1952         self codeLineNumber:lineNr on:aStream for:aCompiler.
  1953 	needLineNr := false.
  1953         needLineNr := false.
  1954 "/    ].
  1954 "/    ].
  1955 
  1955 
  1956     optByteCode notNil ifTrue:[
  1956     optByteCode notNil ifTrue:[
  1957 	theReceiver codeOn:aStream inBlock:b for:aCompiler.
  1957         theReceiver codeOn:aStream inBlock:b for:aCompiler.
  1958 	theArg notNil ifTrue:[
  1958         theArg notNil ifTrue:[
  1959 	    theArg codeOn:aStream inBlock:b for:aCompiler
  1959             theArg codeOn:aStream inBlock:b for:aCompiler
  1960 	]
  1960         ]
  1961     ] ifFalse:[
  1961     ] ifFalse:[
  1962 	fastReceiver notNil ifTrue:[
  1962         fastReceiver notNil ifTrue:[
  1963 	    theByteCode == #trueJump ifTrue:[
  1963             theByteCode == #trueJump ifTrue:[
  1964 		fastReceiver isConstant ifTrue:[
  1964                 fastReceiver isConstant ifTrue:[
  1965 		    fastReceiver evaluate == true ifTrue:[
  1965                     fastReceiver evaluate == true ifTrue:[
  1966 			theByteCode := #jump
  1966                         theByteCode := #jump
  1967 		    ] ifFalse:[
  1967                     ] ifFalse:[
  1968 			fastReceiver evaluate == false ifTrue:[
  1968                         fastReceiver evaluate == false ifTrue:[
  1969 			    theByteCode := #never
  1969                             theByteCode := #never
  1970 			]
  1970                         ]
  1971 		    ]
  1971                     ]
  1972 		]
  1972                 ]
  1973 	    ] ifFalse:[
  1973             ] ifFalse:[
  1974 		theByteCode == #falseJump ifTrue:[
  1974                 theByteCode == #falseJump ifTrue:[
  1975 		    fastReceiver isConstant ifTrue:[
  1975                     fastReceiver isConstant ifTrue:[
  1976 			fastReceiver evaluate == false ifTrue:[
  1976                         fastReceiver evaluate == false ifTrue:[
  1977 			    theByteCode := #jump
  1977                             theByteCode := #jump
  1978 			] ifFalse:[
  1978                         ] ifFalse:[
  1979 			    fastReceiver evaluate == true ifTrue:[
  1979                             fastReceiver evaluate == true ifTrue:[
  1980 				theByteCode := #never
  1980                                 theByteCode := #never
  1981 			    ]
  1981                             ]
  1982 			]
  1982                         ]
  1983 		    ]
  1983                     ]
  1984 		]
  1984                 ]
  1985 	    ]
  1985             ]
  1986 	].
  1986         ].
  1987 
  1987 
  1988 	(theByteCode ~~ #jump
  1988         (theByteCode ~~ #jump
  1989 	and:[theByteCode ~~ #never]) ifTrue:[
  1989         and:[theByteCode ~~ #never]) ifTrue:[
  1990 	    theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
  1990             theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
  1991 	].
  1991         ].
  1992 
  1992 
  1993 	"/
  1993         "/
  1994 	"/ cannot enable code below 
  1994         "/ cannot enable code below 
  1995 	"/ (tiny loops would not be debuggable with next, since lineNo remains the same)
  1995         "/ (tiny loops would not be debuggable with next, since lineNo remains the same)
  1996 	"/ think about it ...
  1996         "/ think about it ...
  1997 	"/
  1997         "/
  1998 	blockExpr := theReceiver simpleSendBlockExpression.
  1998         blockExpr := theReceiver simpleSendBlockExpression.
  1999 	blockExpr notNil ifTrue:[
  1999         blockExpr notNil ifTrue:[
  2000 	    blockExpr isMessage ifTrue:[
  2000             blockExpr isMessage ifTrue:[
  2001 		(aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
  2001                 (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
  2002 		    blockExpr lineNumber == lineNr ifTrue:[
  2002                     blockExpr lineNumber == lineNr ifTrue:[
  2003 			needLineNr := false
  2003                         needLineNr := false
  2004 		    ]
  2004                     ]
  2005 		]
  2005                 ]
  2006 	    ]
  2006             ]
  2007 	].
  2007         ].
  2008     ].
  2008     ].
  2009 
  2009 
  2010     needLineNr ifTrue:[
  2010     needLineNr ifTrue:[
  2011 	ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
  2011         ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
  2012     ].
  2012     ].
  2013 
  2013 
  2014     hasLoopBlock ifFalse:[
  2014     hasLoopBlock ifFalse:[
  2015 	"/ simple [...] whileXXX
  2015         "/ simple [...] whileXXX
  2016 	theByteCode ~~ #never ifTrue:[
  2016         theByteCode ~~ #never ifTrue:[
  2017 	    aStream nextPut:theByteCode; nextPut:pos.
  2017             aStream nextPut:theByteCode; nextPut:pos.
  2018 	].
  2018         ].
  2019 
  2019 
  2020 	valueNeeded ifTrue:[aStream nextPut:#pushNil].
  2020         valueNeeded ifTrue:[aStream nextPut:#pushNil].
  2021 	^ self
  2021         ^ self
  2022     ].
  2022     ].
  2023 
  2023 
  2024     "/ [...] whileXXX:[...]
  2024     "/ [...] whileXXX:[...]
  2025 
  2025 
  2026     theByteCode ~~ #never ifTrue:[
  2026     theByteCode ~~ #never ifTrue:[
  2027 	aStream nextPut:theByteCode.
  2027         aStream nextPut:theByteCode.
  2028 	pos2 := aStream position.
  2028         pos2 := aStream position.
  2029 	aStream nextPut:0.
  2029         aStream nextPut:0.
  2030     ].
  2030     ].
  2031 
  2031 
  2032     (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
  2032     (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
  2033     aStream nextPut:#jump; nextPut:pos.
  2033     aStream nextPut:#jump; nextPut:pos.
  2034     theByteCode ~~ #never ifTrue:[
  2034     theByteCode ~~ #never ifTrue:[
  2035 	(aStream contents) at:pos2 put:(aStream position).
  2035         (aStream contents) at:pos2 put:(aStream position).
  2036     ].
  2036     ].
  2037 
  2037 
  2038     valueNeeded ifTrue:[aStream nextPut:#pushNil].
  2038     valueNeeded ifTrue:[aStream nextPut:#pushNil].
  2039 
  2039 
  2040     "Modified: 22.10.1996 / 21:34:37 / cg"
  2040     "Modified: 22.10.1996 / 21:34:37 / cg"
  2350 ! !
  2350 ! !
  2351 
  2351 
  2352 !MessageNode class methodsFor:'documentation'!
  2352 !MessageNode class methodsFor:'documentation'!
  2353 
  2353 
  2354 version
  2354 version
  2355     ^ '$Header: /cvs/stx/stx/libcomp/Attic/MessageNd.st,v 1.89 1999-02-17 19:35:07 cg Exp $'
  2355     ^ '$Header: /cvs/stx/stx/libcomp/Attic/MessageNd.st,v 1.90 1999-02-25 14:49:10 cg Exp $'
  2356 ! !
  2356 ! !