-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathInterprt.inl
232 lines (186 loc) · 5.6 KB
/
Interprt.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/******************************************************************************
File: Interprt.Inl
Description:
Public inlines for the interpreter bodules
******************************************************************************/
#pragma once
#ifndef CHECKREFERENCES
#error You'll need to include interprt.h
#endif
#include "STString.h"
#include "STExternal.h"
#include "STFloat.h"
#include "STInteger.h"
#define primitiveSuccess(argCount) (Interpreter::m_registers.m_stackPointer - argCount)
inline void Interpreter::GrabAsyncProtect()
{
::EnterCriticalSection(&m_csAsyncProtect);
}
inline void Interpreter::RelinquishAsyncProtect()
{
::LeaveCriticalSection(&m_csAsyncProtect);
}
//=============
//Stack Inlines
//=============
inline void Interpreter::push(LPCSTR pStr)
{
if (pStr)
pushNewObject((OTE*)AnsiString::New(pStr));
else
pushNil();
}
inline void Interpreter::pushHandle(HANDLE h)
{
if (h)
pushNewObject((OTE*)ExternalHandle::New(h));
else
pushNil();
}
inline void Interpreter::push(double d)
{
pushNewObject((OTE*)Float::New(d));
}
inline void Interpreter::pushNil()
{
push(Oop(Pointers.Nil));
}
inline void Interpreter::pushSmallInteger(SMALLINTEGER n)
{
push(ObjectMemoryIntegerObjectOf(n));
}
inline void Interpreter::pushUnsigned32(DWORD dwValue)
{
pushNewObject(Integer::NewUnsigned32(dwValue));
}
inline void Interpreter::pushUIntPtr(UINT_PTR uptrValue)
{
pushNewObject(Integer::NewUIntPtr(uptrValue));
}
inline void Interpreter::pushSigned32(SDWORD lValue)
{
pushNewObject(Integer::NewSigned32(lValue));
}
inline void Interpreter::pushIntPtr(INT_PTR ptrValue)
{
pushNewObject(Integer::NewIntPtr(ptrValue));
}
inline void Interpreter::pushBool(BOOL bValue)
{
push(Oop(bValue == 0 ? Pointers.False : Pointers.True));
}
inline void Interpreter::pushNewObject(Oop oop)
{
if (ObjectMemoryIsIntegerObject(oop))
push(oop);
else
pushNewObject(reinterpret_cast<OTE*>(oop));
}
inline void Interpreter::push(Oop object)
{
// Unfortunately the Compiler generate code with an AGI penalty for this by
// performing the +1 before writing through the new SP, and I can't persuade
// it to use an instruction with an offset
Oop* const sp = m_registers.m_stackPointer;
sp[1] = object;
m_registers.m_stackPointer = sp+1;
}
inline Oop Interpreter::popAndCountUp()
{
Oop top = *m_registers.m_stackPointer--;
ObjectMemory::countUp(top);
return top;
}
///////////////////////////////////////////////////////////////////////////////
// Object field access
#ifndef _M_IX86
// Intel version in assembler (see primitiv.cpp)
inline int __fastcall smalltalkMod(int numerator, int denominator)
{
SMALLINTEGER quotient = numerator/denominator;
quotient = quotient - (quotient < 0 && quotient*denominator!=numerator);
return numerator - (quotient * denominator);
}
#else
// See primasm.asm
extern int __fastcall smalltalkMod(int numerator, int denominator);
#endif
inline bool Interpreter::IsShuttingDown()
{
return m_bShutDown;
}
inline DWORD Interpreter::MainThreadId()
{
return m_dwThreadId;
}
inline HANDLE Interpreter::MainThreadHandle()
{
return m_hThread;
}
inline InterpreterRegisters& Interpreter::GetRegisters()
{
return m_registers;
}
inline BOOL Interpreter::isAFloat(Oop objectPointer)
{
return ObjectMemory::fetchClassOf(objectPointer) == Pointers.ClassFloat;
}
#ifdef PROFILING
#define STARTPROFILING() Interpreter::StartProfiling()
#define STOPPROFILING() Interpreter::StopProfiling()
#else
#define STARTPROFILING()
#define STOPPROFILING()
#endif
inline void Interpreter::sendSelectorArgumentCount(SymbolOTE* selector, unsigned argCount)
{
m_oopMessageSelector = selector;
sendSelectorToClass(ObjectMemory::fetchClassOf(*(m_registers.m_stackPointer - argCount)), argCount);
}
inline void Interpreter::sendSelectorToClass(BehaviorOTE* classPointer, unsigned argCount)
{
MethodCacheEntry* pEntry = findNewMethodInClass(classPointer, argCount);
executeNewMethod(pEntry->method, argCount);
}
inline void Interpreter::NotifyAsyncPending()
{
InterlockedExchange(m_pbAsyncPending, TRUE);
}
///////////////////////////////////////////////////////////////////////////////
// Finalization/Bereavement
// The argument has had a temporary reprieve; we place it on the finalization queue to permit it to
// fulfill its last requests. At the moment the queue is FILO.
inline void Interpreter::basicQueueForFinalization(OTE* ote)
{
ASSERT(!isIntegerObject(ote));
ASSERT(!ObjectMemory::isPermanent(ote));
// Must keep the OopsPerEntry constant in sync. with num objects pushed here
m_qForFinalize.Push(ote);
}
inline void Interpreter::queueForFinalization(OTE* ote, int highWater)
{
basicQueueForFinalization(ote);
asynchronousSignal(Pointers.FinalizeSemaphore);
unsigned count = m_qForFinalize.Count();
// Only raise interrupt when high water mark is hit!
if (count == static_cast<unsigned>(highWater))
queueInterrupt(VMI_HOSPICECRISIS, ObjectMemoryIntegerObjectOf(count));
}
inline void Interpreter::queueForBereavementOf(OTE* ote, Oop argPointer)
{
ASSERT(ote->isWeak());
ASSERT(ObjectMemoryIsIntegerObject(argPointer));
// Must keep the OopsPerEntry constant in sync. with num objects pushed here
m_qBereavements.Push(reinterpret_cast<Oop>(ote));
m_qBereavements.Push(argPointer);
}
///////////////////////////////////////////////////////////////////////////////
// FFI support
inline AddressOTE* ST::ExternalAddress::New(void* ptr)
{
return reinterpret_cast<AddressOTE*>(Interpreter::NewDWORD(DWORD(ptr), Pointers.ClassExternalAddress));
}
inline HandleOTE* ST::ExternalHandle::New(HANDLE hValue)
{
return reinterpret_cast<HandleOTE*>(Interpreter::NewDWORD(DWORD(hValue), Pointers.ClassExternalHandle));
}