982 doMachineCode := Compiler stcCompilation:#never. |
982 doMachineCode := Compiler stcCompilation:#never. |
983 [ |
983 [ |
984 mthd := self asExecutableMethod. |
984 mthd := self asExecutableMethod. |
985 ] valueNowOrOnUnwindDo:[ |
985 ] valueNowOrOnUnwindDo:[ |
986 Compiler stcCompilation:doMachineCode. |
986 Compiler stcCompilation:doMachineCode. |
|
987 ]. |
|
988 ^ mthd |
|
989 |
|
990 "Created: 24.10.1995 / 14:02:32 / cg" |
|
991 "Modified: 5.1.1997 / 01:01:53 / cg" |
|
992 ! |
|
993 |
|
994 asByteCodeMethodWithSource:newSource |
|
995 "if the receiver has no bytecodes, create & return a method having |
|
996 the same semantics as the receiver, but uses interpreted bytecodes. |
|
997 Otherwise, return the receiver. The new method is not installed in |
|
998 the methodDictionary of any class - just returned. |
|
999 If the method contains primitive code, this may return a method |
|
1000 without bytecode. |
|
1001 Can be used to obtain a bytecode version of a machine-code method, |
|
1002 for binary storage or dynamic recompilation (which is not yet finished) |
|
1003 or to compile lazy methods down to executable ones." |
|
1004 |
|
1005 |doMachineCode mthd| |
|
1006 |
|
1007 byteCode notNil ifTrue:[ |
|
1008 " |
|
1009 is already a bytecoded method |
|
1010 " |
|
1011 ^ self |
|
1012 ]. |
|
1013 doMachineCode := Compiler stcCompilation:#never. |
|
1014 [ |
|
1015 mthd := self asExecutableMethodWithSource:newSource. |
|
1016 ] valueNowOrOnUnwindDo:[ |
|
1017 Compiler stcCompilation:doMachineCode. |
987 ]. |
1018 ]. |
988 ^ mthd |
1019 ^ mthd |
989 |
1020 |
990 "Created: 24.10.1995 / 14:02:32 / cg" |
1021 "Created: 24.10.1995 / 14:02:32 / cg" |
991 "Modified: 5.1.1997 / 01:01:53 / cg" |
1022 "Modified: 5.1.1997 / 01:01:53 / cg" |
1084 temporaryMethod mclass:mclass. |
1115 temporaryMethod mclass:mclass. |
1085 ^ temporaryMethod |
1116 ^ temporaryMethod |
1086 |
1117 |
1087 "Created: 24.10.1995 / 14:02:30 / cg" |
1118 "Created: 24.10.1995 / 14:02:30 / cg" |
1088 "Modified: 10.1.1997 / 17:55:33 / cg" |
1119 "Modified: 10.1.1997 / 17:55:33 / cg" |
|
1120 ! |
|
1121 |
|
1122 asExecutableMethodWithSource:newSource |
|
1123 |temporaryMethod cls silent lazy| |
|
1124 |
|
1125 cls := self containingClass. |
|
1126 cls isNil ifTrue:[ |
|
1127 'Method [warning]: cannot generate bytecode (no class for compilation)' errorPrintCR. |
|
1128 ^ nil |
|
1129 ]. |
|
1130 |
|
1131 "we have to sequentialize this using a lock-semaphore, |
|
1132 to make sure only one method is compiled at a time. |
|
1133 Otherwise, we might get into trouble, if (due to a timeout) |
|
1134 another recompile is forced while compiling this one ... |
|
1135 (happened when autoloading animation demos) |
|
1136 " |
|
1137 CompilationLock critical:[ |
|
1138 " |
|
1139 dont want this to go into the changes file, |
|
1140 dont want output on Transcript and definitely |
|
1141 dont want a lazy method ... |
|
1142 " |
|
1143 Class withoutUpdatingChangesDo:[ |
|
1144 silent := Smalltalk silentLoading:true. |
|
1145 lazy := Compiler compileLazy:false. |
|
1146 |
|
1147 [ |
|
1148 |compiler| |
|
1149 |
|
1150 Class nameSpaceQuerySignal answer:(cls nameSpace) |
|
1151 do:[ |
|
1152 compiler := cls compilerClass. |
|
1153 |
|
1154 "/ |
|
1155 "/ kludge - have to make ST/X's compiler protocol |
|
1156 "/ be compatible to ST-80's |
|
1157 "/ |
|
1158 (compiler respondsTo:#compile:forClass:inCategory:notifying:install:) |
|
1159 ifTrue:[ |
|
1160 temporaryMethod := compiler |
|
1161 compile:newSource |
|
1162 forClass:cls |
|
1163 inCategory:(self category) |
|
1164 notifying:nil |
|
1165 install:false. |
|
1166 ] ifFalse:[ |
|
1167 temporaryMethod := compiler new |
|
1168 compile:newSource |
|
1169 in:cls |
|
1170 notifying:nil |
|
1171 ifFail:nil |
|
1172 ]. |
|
1173 ]. |
|
1174 ] valueNowOrOnUnwindDo:[ |
|
1175 Compiler compileLazy:lazy. |
|
1176 Smalltalk silentLoading:silent. |
|
1177 ] |
|
1178 ]. |
|
1179 ]. |
|
1180 (temporaryMethod isNil or:[temporaryMethod == #Error]) ifTrue:[ |
|
1181 'Method [warning]: cannot generate bytecode (contains primitive code or error)' errorPrintCR. |
|
1182 ^ nil. |
|
1183 ]. |
|
1184 "/ |
|
1185 "/ try to save a bit of memory, by sharing the source (whatever it is) |
|
1186 "/ |
|
1187 temporaryMethod source:newSource. |
|
1188 "/ |
|
1189 "/ dont forget the methods class & package ... |
|
1190 "/ |
|
1191 temporaryMethod setPackage:package. |
|
1192 temporaryMethod mclass:mclass. |
|
1193 ^ temporaryMethod |
1089 ! |
1194 ! |
1090 |
1195 |
1091 readBinaryContentsFrom: stream manager: manager |
1196 readBinaryContentsFrom: stream manager: manager |
1092 self hasCode ifTrue:[ |
1197 self hasCode ifTrue:[ |
1093 "built-in method - already complete" |
1198 "built-in method - already complete" |
1757 "Modified: 1.11.1996 / 16:27:04 / cg" |
1862 "Modified: 1.11.1996 / 16:27:04 / cg" |
1758 ! ! |
1863 ! ! |
1759 |
1864 |
1760 !Method methodsFor:'private-compiler interface'! |
1865 !Method methodsFor:'private-compiler interface'! |
1761 |
1866 |
|
1867 primitiveNumber |
|
1868 "for stx rel >= 5.x only: |
|
1869 return the primitive number." |
|
1870 |
|
1871 %{ /* NOCONTEXT */ |
|
1872 |
|
1873 #ifdef F_PRIMITIVE |
|
1874 INT f = __intVal(__INST(flags)); |
|
1875 INT nr = nil; |
|
1876 |
|
1877 if (f & F_PRIMITIVE) { |
|
1878 nr = __INST(code_); |
|
1879 } |
|
1880 RETURN (nr); |
|
1881 #endif |
|
1882 %}. |
|
1883 self primitiveFailed |
|
1884 |
|
1885 |
|
1886 |
|
1887 ! |
|
1888 |
|
1889 setPrimitiveNumber:aNumber |
|
1890 "for stx rel >= 5.x only: |
|
1891 mark the method as having primitive code." |
|
1892 |
|
1893 %{ /* NOCONTEXT */ |
|
1894 |
|
1895 #ifdef F_PRIMITIVE |
|
1896 INT f = __intVal(__INST(flags)); |
|
1897 |
|
1898 f |= F_PRIMITIVE; |
|
1899 __INST(flags) = __MKSMALLINT(f); |
|
1900 __INST(code_) = aNumber; |
|
1901 RETURN (self); |
|
1902 #endif |
|
1903 %}. |
|
1904 self primitiveFailed |
|
1905 |
|
1906 |
|
1907 |
|
1908 ! |
|
1909 |
1762 setResourceFlag |
1910 setResourceFlag |
1763 "mark the method as having a <resource> definition in its |
1911 "mark the method as having a <resource> definition in its |
1764 source. |
1912 source. |
1765 These resource definitions were found in ST-80 methods, and are |
1913 These resource definitions were found in ST-80 methods, and are |
1766 currently not supported by ST/X (except for remembering this flag). |
1914 currently not supported by ST/X (except for remembering this flag). |