-
Notifications
You must be signed in to change notification settings - Fork 23
/
IDolphin.cpp
executable file
·293 lines (246 loc) · 7.25 KB
/
IDolphin.cpp
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#include "ist.h"
#include "rc_vm.h"
#include "DolphinSmalltalk_i.h"
#include "DolphinSmalltalk.h"
#include "ote.h"
#define POTE OTE*
#include "VMPointers.h"
#undef POTE
#undef MinSmallInteger
#undef MaxSmallInteger
#include "ObjMem.h"
#define _STMETHODHEADER_H_
#include "Interprt.h"
#include "STObject.h"
#include "STByteArray.h"
#include "STCharacter.h"
CDolphinSmalltalk::CDolphinSmalltalk()
{
}
CDolphinSmalltalk::~CDolphinSmalltalk()
{
}
static Oop ExternaliseRef(Oop oop)
{
#ifdef _DEBUG
Interpreter::AddVMReference(oop);
ObjectMemory::countDown(oop);
#endif
return oop;
}
/////////////////////////////////////////////////////////////////////
// IDolphin
STDMETHODIMP_(STVarObject*) CDolphinSmalltalk::GetVMPointers()
{
return reinterpret_cast<STVarObject*>(&Pointers);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NilPointer()
{
return (POTE)Pointers.Nil;
}
STDMETHODIMP_(void) CDolphinSmalltalk::AddReference(
/* [in] */ Oop objectPointer)
{
#ifdef _DEBUG
Interpreter::AddVMReference(objectPointer);
#else
ObjectMemory::countUp(objectPointer);
#endif
}
STDMETHODIMP_(void) CDolphinSmalltalk::RemoveReference(
/* [in] */ Oop objectPointer)
{
#ifdef _DEBUG
Interpreter::RemoveVMReference(objectPointer);
#else
ObjectMemory::countDown(objectPointer);
#endif
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::FetchClassOf(Oop objectPointer)
{
return (POTE)ObjectMemory::fetchClassOf(objectPointer);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::InheritsFrom(
const POTE behaviorPointer,
const POTE classPointer)
{
return ObjectMemory::inheritsFrom((const BehaviorOTE*)behaviorPointer, (const BehaviorOTE*)classPointer);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::IsBehavior(
/* [in] */ Oop objectPointer)
{
return ObjectMemory::isBehavior(objectPointer);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::IsAMetaclass(
/* [in] */ const POTE ote)
{
return ObjectMemory::isAMetaclass(reinterpret_cast<OTE*>(ote));
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::IsAClass(
/* [in] */ const POTE ote)
{
return IsAMetaclass(FetchClassOf(reinterpret_cast<Oop>(ote)));
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::Perform(
/* [in] */ Oop receiver,
/* [in] */ POTE selector)
{
return ExternaliseRef(Interpreter::perform(receiver, reinterpret_cast<SymbolOTE*>(selector)));
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::PerformWith(
/* [in] */ Oop receiver,
/* [in] */ POTE selector,
/* [in] */ Oop arg)
{
return ExternaliseRef(Interpreter::performWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg));
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::PerformWithWith(
/* [in] */ Oop receiver,
/* [in] */ POTE selector,
/* [in] */ Oop arg1,
/* [in] */ Oop arg2)
{
return ExternaliseRef(Interpreter::performWithWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg1, arg2));
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::PerformWithWithWith(
/* [in] */ Oop receiver,
/* [in] */ POTE selector,
/* [in] */ Oop arg1,
/* [in] */ Oop arg2,
/* [in] */ Oop arg3)
{
return ExternaliseRef(Interpreter::performWithWithWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg1, arg2, arg3));
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::PerformWithArguments(
/* [in] */ Oop receiver,
/* [in] */ POTE selector,
/* [in] */ Oop argArray)
{
return ExternaliseRef(Interpreter::performWithArguments(receiver, reinterpret_cast<SymbolOTE*>(selector), argArray));
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewObject(
/* [in] */ POTE classPointer)
{
return (POTE)ObjectMemory::newPointerObject(reinterpret_cast<BehaviorOTE*>(classPointer));
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewObjectWithPointers(
/* [in] */ POTE classPointer,
/* [in] */ unsigned int size)
{
return (POTE)ObjectMemory::newPointerObject(reinterpret_cast<BehaviorOTE*>(classPointer), size);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewByteArray(
/* [in] */ unsigned int len)
{
return (POTE)ByteArray::New(len);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewString(
/* [in] */ LPCSTR szValue,
/* [in] */ int len)
{
return (POTE)AnsiString::New(szValue, len=-1?strlen(szValue):len);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewUtf8String(
/* [in] */ LPCSTR szValue,
/* [in] */ int len)
{
return (POTE)Utf8String::New(szValue, len = -1 ? strlen(szValue) : len);
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::NewSignedInteger(
/* [in] */ SDWORD value)
{
return Integer::NewSigned32(value);
}
STDMETHODIMP_(Oop) CDolphinSmalltalk::NewUnsignedInteger(
/* [in] */ DWORD value)
{
return Integer::NewUnsigned32(value);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewCharacter(
/* [in] */ DWORD codePoint)
{
return (POTE)Character::NewUnicode(static_cast<MWORD>(codePoint));
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewArray(
/* [in] */ unsigned int size)
{
return (POTE)Array::New(size);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::NewFloat(
/* [in] */ double fValue)
{
return (POTE)Float::New(fValue);
}
STDMETHODIMP_(POTE) CDolphinSmalltalk::InternSymbol(
/* [in] */ LPCSTR szName)
{
return (POTE)Interpreter::NewSymbol(szName);
}
STDMETHODIMP_(void) CDolphinSmalltalk::StorePointerWithValue(
/* [out][in] */ Oop *poopSlot,
/* [in] */ Oop oopValue)
{
ObjectMemory::storePointerWithValue(*poopSlot, oopValue);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::DisableInterrupts(
/* [in] */ BOOL bDisable)
{
return Interpreter::disableInterrupts(bDisable?true:false);
}
STDMETHODIMP_(int) CDolphinSmalltalk::CallbackExceptionFilter(
/* [in] */ void *info)
{
return Interpreter::callbackExceptionFilter(LPEXCEPTION_POINTERS(info));
}
STDMETHODIMP_(void) CDolphinSmalltalk::DecodeMethod(
POTE methodPointer,
void *pstream)
{
#ifdef _DEBUG
Interpreter::decodeMethod(reinterpret_cast<MethodOTE*>(methodPointer)->m_location,
reinterpret_cast<std::wostream*>(pstream));
#else
UNREFERENCED_PARAMETER(methodPointer);
UNREFERENCED_PARAMETER(pstream);
#endif
}
STDMETHODIMP_(STVarObject*) CDolphinSmalltalk::GetObj(POTE pote)
{
return reinterpret_cast<STVarObject*>(reinterpret_cast<OTE*>(pote)->m_location);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::IsKindOf(Oop objectPointer, const POTE classPointer)
{
POTE behaviorPointer = FetchClassOf(objectPointer);
return InheritsFrom(behaviorPointer, classPointer);
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::DisableAsyncGC(
/* [in] */ BOOL bDisable)
{
return Interpreter::disableAsyncGC(bDisable?true:false);
}
STDMETHODIMP_(VOID) CDolphinSmalltalk::MakeImmutable(
/* [in] */ Oop oop,
/* [in] */ BOOL bImmutable)
{
if (isIntegerObject(oop))
return;
if (bImmutable)
reinterpret_cast<OTE*>(oop)->beImmutable();
else
reinterpret_cast<OTE*>(oop)->beMutable();
}
STDMETHODIMP_(BOOL) CDolphinSmalltalk::IsImmutable(
/* [in] */ Oop oop)
{
return isIntegerObject(oop) || (reinterpret_cast<OTE*>(oop)->isImmutable());
}
STDMETHODIMP_(BSTR) CDolphinSmalltalk::DebugPrintString(
/* [in] */ Oop oop)
{
std::wstring str = Interpreter::PrintString(oop);
return SysAllocString(str.c_str());
}