-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathCompilePrims.cpp
80 lines (63 loc) · 2.09 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"
#include <comdef.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 = ::LoadLibrary("DolphinCR7.DLL");
return hCompiler;
}
static ICompilerPtr NewCompiler()
{
ICompilerPtr piCompiler;
HRESULT hr = piCompiler.CreateInstance(__uuidof(DolphinCompiler));
if (SUCCEEDED(hr))
return piCompiler;
if (hr == REGDB_E_CLASSNOTREG)
{
// Try and register it
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
IClassFactoryPtr piFactory;
hr = (*pfnFactory)(__uuidof(DolphinCompiler), IID_IClassFactory, (void**)&piFactory);
if (SUCCEEDED(hr))
{
// Now try creating the VM object directly
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"