87 lines
3.2 KiB
HTML
87 lines
3.2 KiB
HTML
<html>
|
|
<head>
|
|
<link rel=stylesheet type="text/css" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<H2>
|
|
paxCompiler for MS VC++. Call a script-defined procedure.
|
|
</H2>
|
|
<hr>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
#<font color="blue"><b>include</b></font> <font color="Red">"stdafx.h"</font>
|
|
#<font color="blue"><b>include</b></font> <font color="Red">"paxcompilerlib.h"</font>
|
|
|
|
<font color="blue"><b>long</b></font> y = 5;
|
|
|
|
<font color="blue"><b>int</b></font> main(<font color="blue"><b>int</b></font> argc, <font color="blue"><b>char</b></font>* argv[])
|
|
{
|
|
HMODULE h_lib = LoadPaxCompilerLib();
|
|
<font color="blue"><b>if</b></font> (h_lib != 0)
|
|
{
|
|
DWORD hc = PaxCompiler_Create();
|
|
DWORD hl = PaxPascalLanguage_Create();
|
|
DWORD hp = PaxProgram_Create();
|
|
|
|
PaxCompiler_Reset(hc);
|
|
PaxCompiler_RegisterLanguage(hc, hl);
|
|
|
|
DWORD h_y = PaxCompiler_RegisterVariable(hc, 0, <font color="Red">"Y"</font>, PaxTypeLONG);
|
|
|
|
PaxCompiler_AddModule(hc, <font color="Red">"1"</font>, <font color="Red">"Pascal"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">"procedure ScriptProc(X: Integer);"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">"begin"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">" Y := Y + X;"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">"end;"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">"begin"</font>);
|
|
PaxCompiler_AddCode(hc, <font color="Red">"1"</font>, <font color="Red">"end."</font>);
|
|
|
|
<font color="blue"><b>if</b></font> (PaxCompiler_Compile(hc, hp))
|
|
{
|
|
|
|
DWORD h_ScriptProc = PaxCompiler_GetHandle(hc, 0, <font color="Red">"ScriptProc"</font>, <font color="blue"><b>true</b></font>);
|
|
<font color="blue"><b>void</b></font> * p = PaxProgram_GetAddress(hp, h_ScriptProc); // get address of script-defined procedure
|
|
|
|
PaxProgram_SetAddress(hp, h_y, &y);
|
|
|
|
__<font color="blue"><b>asm</b></font>
|
|
{
|
|
<font color="green"><b>push</b></font> 10 // push parameter
|
|
<font color="green"><b>call</b></font> p // call script-defined procedure
|
|
}
|
|
|
|
printf(<font color="Red">"y = %d"</font>, y);
|
|
|
|
}
|
|
<font color="blue"><b>else</b></font>
|
|
{
|
|
printf(<font color="Red">"there are errors:\n"</font>);
|
|
<font color="blue"><b>for</b></font> (<font color="blue"><b>int</b></font> 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();
|
|
<font color="blue"><b>return</b></font> 0;
|
|
}
|
|
</pre>
|
|
</blockquote>
|
|
|
|
|
|
<p>
|
|
<HR>
|
|
<font size = 1 color ="gray">
|
|
Copyright © 2006-2009
|
|
VIRT Laboratory. All rights reserved.
|
|
</font>
|
|
</body>
|
|
</html>
|