|
1 " |
|
2 COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 All Rights Reserved |
|
4 |
|
5 This software is furnished under a license and may be used |
|
6 only in accordance with the terms of that license and with the |
|
7 inclusion of the above copyright notice. This software may not |
|
8 be provided or otherwise made available to, or used by, any |
|
9 other person. No title to or ownership of the software is |
|
10 hereby transferred. |
|
11 " |
|
12 |
|
13 WriteStream subclass:#CodeStream |
|
14 instanceVariableNames:'class scope requestor' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'System-Compiler ST-80- compatibility' |
|
18 ! |
|
19 |
|
20 CodeStream comment:' |
|
21 COPYRIGHT (c) 1995 by Claus Gittinger |
|
22 All Rights Reserved |
|
23 |
|
24 $Header: /cvs/stx/stx/libcomp/CodeStream.st,v 1.1 1995-07-23 02:23:10 claus Exp $ |
|
25 '! |
|
26 |
|
27 !CodeStream class methodsFor:'documentation'! |
|
28 |
|
29 copyright |
|
30 " |
|
31 COPYRIGHT (c) 1995 by Claus Gittinger |
|
32 All Rights Reserved |
|
33 |
|
34 This software is furnished under a license and may be used |
|
35 only in accordance with the terms of that license and with the |
|
36 inclusion of the above copyright notice. This software may not |
|
37 be provided or otherwise made available to, or used by, any |
|
38 other person. No title to or ownership of the software is |
|
39 hereby transferred. |
|
40 " |
|
41 ! |
|
42 |
|
43 version |
|
44 " |
|
45 $Header: /cvs/stx/stx/libcomp/CodeStream.st,v 1.1 1995-07-23 02:23:10 claus Exp $ |
|
46 " |
|
47 ! |
|
48 |
|
49 documentation |
|
50 " |
|
51 This is a pure mimicri class. |
|
52 It is not used by ST/X, but provided to support limited |
|
53 compatibility for applications which build up codetrees, |
|
54 knowing internals of ST-80's compiler class hierarchy. |
|
55 This classes protocol is not (not meant to be) fully covering |
|
56 the corresponding ST-80's classes protocol. It maps ST-80 messages |
|
57 to corresponding ST/X messages (as far as possible). |
|
58 |
|
59 NO WARRANTY and GUARANTEE; this class may be removed without notice. |
|
60 " |
|
61 ! ! |
|
62 |
|
63 !CodeStream class methodsFor:'instance creation'! |
|
64 |
|
65 new |
|
66 ^ super on:(OrderedCollection new:100) |
|
67 ! ! |
|
68 |
|
69 !CodeStream methodsFor:'accessing'! |
|
70 |
|
71 class:aClass outerScope:aScope |
|
72 class := aClass. |
|
73 scope := aScope |
|
74 ! |
|
75 |
|
76 requestor:someOne |
|
77 requestor := someOne |
|
78 ! ! |
|
79 |
|
80 !CodeStream methodsFor:'code generation'! |
|
81 |
|
82 makeMethod:aMethodNode |
|
83 "mhmh - kludge-create a compiler and let it generate code" |
|
84 |
|
85 |compiler symbolicCodeArray newMethod lits| |
|
86 |
|
87 compiler := ByteCodeCompiler new. |
|
88 compiler notifying:requestor. |
|
89 compiler targetClass:class. |
|
90 |
|
91 symbolicCodeArray := self contents. |
|
92 (compiler genByteCodeFrom:symbolicCodeArray) == #Error ifTrue:[ |
|
93 self halt |
|
94 ]. |
|
95 |
|
96 newMethod := Method new. |
|
97 newMethod byteCode:(compiler code). |
|
98 lits := compiler literalArray. |
|
99 lits notNil ifTrue:[ |
|
100 "literals MUST be an array - not just any Collection" |
|
101 lits := Array withAll:lits. |
|
102 newMethod literals:lits |
|
103 ]. |
|
104 newMethod numberOfMethodVars:(compiler numberOfMethodVars). |
|
105 newMethod numberOfMethodArgs:(compiler numberOfMethodArgs). |
|
106 newMethod stackSize:(compiler maxStackDepth). |
|
107 |
|
108 Project notNil ifTrue:[ |
|
109 newMethod package:(Project currentPackageName) |
|
110 ]. |
|
111 |
|
112 class addSelector:aMethodNode selector withMethod:newMethod. |
|
113 ^ newMethod |
|
114 ! ! |