Method.st
changeset 1087 6cb00ecfbc6d
parent 1037 4488f834cb6b
child 1093 1e742016eea0
equal deleted inserted replaced
1086:7b0641a2e1ef 1087:6cb00ecfbc6d
   947      Can be used to compile lazy methods down to executable ones."
   947      Can be used to compile lazy methods down to executable ones."
   948 
   948 
   949     |temporaryMethod cls sourceString silent lazy|
   949     |temporaryMethod cls sourceString silent lazy|
   950 
   950 
   951     byteCode notNil ifTrue:[
   951     byteCode notNil ifTrue:[
   952 	"
   952         "
   953 	 is already a bytecoded method
   953          is already a bytecoded method
   954 	"
   954         "
   955 	^ self
   955         ^ self
   956     ].
   956     ].
   957 
   957 
   958     cls := self containingClass.
   958     cls := self containingClass.
   959     cls isNil ifTrue:[
   959     cls isNil ifTrue:[
   960 	'cannot generate bytecode (no class for compilation)' errorPrintNL.
   960         'METHOD: cannot generate bytecode (no class for compilation)' errorPrintNL.
   961 	^ nil
   961         ^ nil
   962     ].
   962     ].
   963     sourceString := self source.
   963     sourceString := self source.
   964     sourceString isNil ifTrue:[
   964     sourceString isNil ifTrue:[
   965 	'cannot generate bytecode (no source for compilation)' errorPrintNL.
   965         'METHOD: cannot generate bytecode (no source for compilation)' errorPrintNL.
   966 	^ nil
   966         ^ nil
   967     ].
   967     ].
   968 
   968 
   969     "
   969     "
   970      dont want this to go into the changes file,
   970      dont want this to go into the changes file,
   971      dont want output on Transcript and definitely 
   971      dont want output on Transcript and definitely 
   972      dont want a lazy method ...
   972      dont want a lazy method ...
   973     "
   973     "
   974     Class withoutUpdatingChangesDo:[
   974     Class withoutUpdatingChangesDo:[
   975 	silent := Smalltalk silentLoading:true.
   975         silent := Smalltalk silentLoading:true.
   976 	lazy := Compiler compileLazy:false.
   976         lazy := Compiler compileLazy:false.
   977 
   977 
   978 	[
   978         [
   979 	    |compiler|
   979             |compiler|
   980 
   980 
   981 	    compiler := cls compilerClass.
   981             compiler := cls compilerClass.
   982 
   982 
   983 	    "/
   983             "/
   984 	    "/ kludge - have to make ST/X's compiler protocol
   984             "/ kludge - have to make ST/X's compiler protocol
   985 	    "/ be compatible to ST-80's
   985             "/ be compatible to ST-80's
   986 	    "/
   986             "/
   987 	    (compiler respondsTo:#compile:forClass:inCategory:notifying:install:skipIfSame:)
   987             (compiler respondsTo:#compile:forClass:inCategory:notifying:install:skipIfSame:)
   988 	    ifTrue:[
   988             ifTrue:[
   989 		temporaryMethod := compiler
   989                 temporaryMethod := compiler
   990 				     compile:sourceString
   990                                      compile:sourceString
   991 				     forClass:cls
   991                                      forClass:cls
   992 				     inCategory:(self category)
   992                                      inCategory:(self category)
   993 				     notifying:nil
   993                                      notifying:nil
   994 				     install:false.
   994                                      install:false.
   995 	    ] ifFalse:[
   995             ] ifFalse:[
   996 		temporaryMethod := compiler new
   996                 temporaryMethod := compiler new
   997 				     compile:sourceString 
   997                                      compile:sourceString 
   998 				     in:cls 
   998                                      in:cls 
   999 				     notifying:nil 
   999                                      notifying:nil 
  1000 				     ifFail:nil
  1000                                      ifFail:nil
  1001 	    ].
  1001             ].
  1002 	] valueNowOrOnUnwindDo:[
  1002         ] valueNowOrOnUnwindDo:[
  1003 	    Compiler compileLazy:lazy.
  1003             Compiler compileLazy:lazy.
  1004 	    Smalltalk silentLoading:silent.
  1004             Smalltalk silentLoading:silent.
  1005 	]
  1005         ]
  1006     ].
  1006     ].
  1007     (temporaryMethod isNil or:[temporaryMethod == #Error]) ifTrue:[
  1007     (temporaryMethod isNil or:[temporaryMethod == #Error]) ifTrue:[
  1008 	'cannot generate bytecode (contains primitive code or error)' errorPrintNL.
  1008         'METHOD: cannot generate bytecode (contains primitive code or error)' errorPrintNL.
  1009 	^ nil.
  1009         ^ nil.
  1010     ].
  1010     ].
  1011     "
  1011     "
  1012      try to save a bit of memory, by sharing the source (whatever it is)
  1012      try to save a bit of memory, by sharing the source (whatever it is)
  1013     "
  1013     "
  1014     temporaryMethod sourceFilename:source position:sourcePosition. 
  1014     temporaryMethod sourceFilename:source position:sourcePosition. 
  1015     ^ temporaryMethod
  1015     ^ temporaryMethod
  1016 
  1016 
  1017     "Created: 24.10.1995 / 14:02:30 / cg"
  1017     "Created: 24.10.1995 / 14:02:30 / cg"
       
  1018     "Modified: 7.3.1996 / 19:19:12 / cg"
  1018 !
  1019 !
  1019 
  1020 
  1020 readBinaryContentsFrom: stream manager: manager
  1021 readBinaryContentsFrom: stream manager: manager
  1021     "tell the newly restored Font about restoration"
  1022     "tell the newly restored Font about restoration"
  1022 
  1023 
  1982 ! !
  1983 ! !
  1983 
  1984 
  1984 !Method class methodsFor:'documentation'!
  1985 !Method class methodsFor:'documentation'!
  1985 
  1986 
  1986 version
  1987 version
  1987     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.76 1996-02-28 23:25:21 cg Exp $'
  1988     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.77 1996-03-07 18:34:00 cg Exp $'
  1988 ! !
  1989 ! !
  1989 Method initialize!
  1990 Method initialize!