-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDolphinIF.cpp
210 lines (167 loc) · 4.86 KB
/
DolphinIF.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
/*
============
DolphinIF.cpp
============
Interface to the Dolphin interpreter for use from external DLLs
*/
#include "Ist.h"
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#pragma code_seg(XIF_SEG)
#include "Interprt.h"
#include "ObjMem.h"
#include <stdarg.h>
#include <wtypes.h>
#include "rc_vm.h"
#include "InterprtPrim.inl"
#include "InterprtProc.inl"
// Smalltalk classes
#include "STByteArray.h"
#include "STString.h" // For instantiating new strings
#include "STInteger.h" // NewDWORD uses to create new integer, also for winproc return
#include "STArray.h"
#include "STCharacter.h"
#include "STFloat.h"
#if 1
// Boot version combines compiler into VM
#define _DOLPHINAPI(x) x __stdcall
#else
#define _DOLPHINAPI(x) __declspec(dllexport) x __stdcall
#endif
extern VMPointers _Pointers;
#undef POTE
namespace DolphinIF
{
struct VMPointers;
typedef void* POTE;
_DOLPHINAPI(DolphinIF::VMPointers&) __stdcall GetVMPointers()
{
return *(DolphinIF::VMPointers*)&_Pointers;
}
_DOLPHINAPI(void) AddReference(Oop objectPointer)
{
ObjectMemory::countUp(objectPointer);
}
_DOLPHINAPI(void) RemoveReference(Oop objectPointer)
{
ObjectMemory::countDown(objectPointer);
}
_DOLPHINAPI(POTE) FetchClassOf(Oop objectPointer)
{
return ObjectMemory::fetchClassOf(objectPointer);
}
_DOLPHINAPI(bool) InheritsFrom(const POTE behaviorPointer, const POTE classPointer)
{
return ObjectMemory::inheritsFrom((const BehaviorOTE*)behaviorPointer, (const BehaviorOTE*)classPointer);
}
_DOLPHINAPI(bool) IsBehavior(Oop objectPointer)
{
return ObjectMemory::isBehavior(objectPointer);
}
_DOLPHINAPI(bool) IsAMetaclass(const POTE ote)
{
return ObjectMemory::isAMetaclass(reinterpret_cast<OTE*>(ote));
}
_DOLPHINAPI(bool) IsAClass(const POTE ote)
{
return IsAMetaclass(FetchClassOf(Oop(ote)));
}
_DOLPHINAPI(Oop) Perform(Oop receiver, POTE selector)
{
return Interpreter::perform(receiver, reinterpret_cast<SymbolOTE*>(selector));
}
_DOLPHINAPI(Oop) PerformWith(Oop receiver, POTE selector, Oop arg)
{
return Interpreter::performWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg);
}
_DOLPHINAPI(Oop) PerformWithWith(Oop receiver, POTE selector, Oop arg1, Oop arg2)
{
return Interpreter::performWithWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg1, arg2);
}
_DOLPHINAPI(Oop) PerformWithWithWith(Oop receiver, POTE selector, Oop arg1, Oop arg2, Oop arg3)
{
return Interpreter::performWithWithWith(receiver, reinterpret_cast<SymbolOTE*>(selector), arg1, arg2, arg3);
}
_DOLPHINAPI(Oop) PerformWithArguments(Oop receiver, POTE selector, Oop argArray)
{
return Interpreter::performWithArguments(receiver, reinterpret_cast<SymbolOTE*>(selector), argArray);
}
_DOLPHINAPI(POTE) NewObject(POTE classPointer)
{
return ObjectMemory::newPointerObject(reinterpret_cast<BehaviorOTE*>(classPointer));
}
_DOLPHINAPI(POTE) NewObjectWithPointers(POTE classPointer, unsigned size)
{
return ObjectMemory::newPointerObject(reinterpret_cast<BehaviorOTE*>(classPointer), size);
}
_DOLPHINAPI(POTE) NewByteArray(unsigned len)
{
return ByteArray::New(len);
}
_DOLPHINAPI(POTE) NewStringWithLen(const char* value, unsigned len)
{
return String::NewWithLen(value, len);
}
_DOLPHINAPI(Oop) NewSignedInteger(SDWORD value)
{
return Integer::NewSigned32(value);
}
//_DOLPHINAPI(Oop) NewSignedInteger(SQWORD value);
_DOLPHINAPI(Oop) NewUnsignedInteger(DWORD value)
{
return Integer::NewUnsigned32(value);
}
//_DOLPHINAPI(Oop) NewUnsignedInteger(QWORD value);
_DOLPHINAPI(POTE) NewCharacter(unsigned char value)
{
return Character::New(value);
}
_DOLPHINAPI(POTE) NewArray(unsigned size)
{
return Array::New(size);
}
_DOLPHINAPI(POTE) NewFloat(double fValue)
{
return Float::New(fValue);
}
_DOLPHINAPI(POTE) InternSymbol(const char* name)
{
return Interpreter::NewSymbol(name);
}
_DOLPHINAPI(void) StorePointerWithValue(Oop& oopSlot, Oop oopValue)
{
ObjectMemory::storePointerWithValue(oopSlot, oopValue);
}
_DOLPHINAPI(BOOL) DisableInterrupts(BOOL bDisable)
{
return Interpreter::disableInterrupts(bDisable?true:false);
}
_DOLPHINAPI(int) CallbackExceptionFilter(LPEXCEPTION_POINTERS info)
{
return Interpreter::callbackExceptionFilter(info);
}
#ifdef _DEBUG
_DOLPHINAPI(void) DecodeMethod(POTE methodPointer, void* stream)
{
Interpreter::decodeMethod(static_cast<CompiledMethod*>(static_cast<OTE*>(methodPointer)->m_location),
static_cast<ostream*>(stream));
}
#endif
_DOLPHINAPI(BOOL) DisableAsyncGC(BOOL bDisable)
{
return Interpreter::disableAsyncGC(bDisable?true:false);
}
_DOLPHINAPI(VOID) MakeImmutable(POTE ote, BOOL bImmutable)
{
if (bImmutable)
static_cast<OTE*>(ote)->beImmutable();
else
static_cast<OTE*>(ote)->beMutable();
}
_DOLPHINAPI(BOOL) IsImmutable(Oop oop)
{
return isIntegerObject(oop) || (reinterpret_cast<OTE*>(oop)->isImmutable());
}
};