-
Notifications
You must be signed in to change notification settings - Fork 23
/
CompilePrims.cpp
80 lines (63 loc) · 2.11 KB
/
CompilePrims.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
#include "ist.h"
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#pragma code_seg(XIF_SEG)
#include "Compiler_i.h"
#include "DolphinSmalltalk_i.h"
IDolphin* GetVM();
_COM_SMARTPTR_TYPEDEF(ICompiler, __uuidof(ICompiler));
typedef HRESULT (STDAPICALLTYPE *GETCLASSOBJPROC)(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
static HINSTANCE LoadCompiler()
{
static HINSTANCE hCompiler = NULL;
if (hCompiler == NULL)
hCompiler = ::LoadLibraryW(L"DolphinCR7.DLL");
return hCompiler;
}
static IClassFactoryPtr piFactory;
static ICompilerPtr NewCompiler()
{
ICompilerPtr piCompiler;
HRESULT hr = S_OK;
if (!piFactory)
{
hr = CoGetClassObject(__uuidof(DolphinCompiler), CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (void**)&piFactory);
if (FAILED(hr))
{
HINSTANCE hLib = LoadCompiler();
if (hLib)
{
// It loaded, now try invoking the class factory entry point
GETCLASSOBJPROC pfnFactory = (GETCLASSOBJPROC)::GetProcAddress(HMODULE(hLib), "DllGetClassObject");
if (pfnFactory)
{
// Found the entry point, try retrieving the factory
hr = (*pfnFactory)(__uuidof(DolphinCompiler), IID_IClassFactory, (void**)&piFactory);
}
}
}
}
if (SUCCEEDED(hr))
{
// Directly invoke the factory to instantiate a compiler instance
hr = piFactory->CreateInstance(NULL, __uuidof(ICompiler), (void**)&piCompiler);
}
return piCompiler;
}
extern "C" Oop __stdcall PrimCompileForClass(Oop compilerOop, const char* szSource, Oop aClass, int flags, Oop notifier)
{
ICompilerPtr piCompiler = NewCompiler();
if (piCompiler == NULL)
return Oop(GetVM()->NilPointer());
return (Oop)piCompiler->CompileForClass(GetVM(), compilerOop, szSource, (POTE)aClass, FLAGS(flags), notifier);
}
extern "C" Oop __stdcall PrimCompileForEval(Oop compilerOop, const char* szSource, Oop aClass, Oop aWorkspacePool, int flags, Oop notifier)
{
ICompilerPtr piCompiler = NewCompiler();
if (piCompiler == NULL)
return Oop(GetVM()->NilPointer());
return (Oop)piCompiler->CompileForEval(GetVM(), compilerOop, szSource, (POTE)aClass, (POTE)aWorkspacePool, FLAGS(flags), notifier);
}
#include "Compiler_i.c"