#include "stdafx.h"
#include "paxcompilerlib.h"
int main(int argc, char* argv[])
{
HMODULE h_lib = LoadPaxCompilerLib();
if (h_lib != 0)
{
DWORD hc = PaxCompiler_Create();
DWORD hl = PaxPascalLanguage_Create();
DWORD hp = PaxProgram_Create();
PaxCompiler_Reset(hc);
PaxCompiler_RegisterLanguage(hc, hl);
PaxCompiler_AddModule(hc, "1", "Pascal");
PaxCompiler_AddCode(hc, "1", "var x: Integer = 5;");
PaxCompiler_AddCode(hc, "1", "begin");
PaxCompiler_AddCode(hc, "1", " writeln('script:', x);");
PaxCompiler_AddCode(hc, "1", "end.");
if (PaxCompiler_Compile(hc, hp))
{
DWORD h_x = PaxCompiler_GetHandle(hc, 0, "x", true);
printf("the first run\n");
PaxProgram_Run(hp);
int * p = (int*) PaxProgram_GetAddress(hp, h_x);
printf("host: %d\n", *p); // show script-defined var
*p = 30; // change script-defind variable
printf("the second run\n");
PaxProgram_Run(hp);
}
else
{
printf("there are errors:\n");
for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++)
{
printf(PaxCompiler_GetErrorMessage(hc, i));
}
}
PaxProgram_Destroy(hp);
PaxPascalLanguage_Destroy(hl);
PaxCompiler_Destroy(hc);
}
FreePaxCompilerLib(h_lib);
getchar();
return 0;
}