Loads paxcompilerlib.dllHMODULE LoadPaxCompilerLib()
Example
#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", "begin"); PaxCompiler_AddCode(hc, "1", " writeln('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { 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; }
Unloads paxcompilerlib.dlllong FreePaxCompilerLib(HMODULE h_lib);Arguments
h_libHandle of library.
paxCompiler constructor. Returns handle of paxCompiler object.DWORD __stdcall PaxCompiler_Create();
paxCompiler destructor. Destroyes paxCompiler object.void __stdcall PaxCompiler_Destroy(DWORD HCompiler);
Removes all source code modules and registered items from compiler.void __stdcall PaxCompiler_Reset(DWORD HCompiler);
Adds source code module to compiler.void __stdcall PaxCompiler_AddModule(DWORD HCompiler, char * Name, char * LanguageName);Arguments
HCompilerHandle of compiler.NameName of module.LanguageNameName of programming language supported by compiler.
Example
DWORD hc = PaxCompiler_Create(); PaxCompiler_AddModule(hc, "1", "Pascal");
Adds source code to source code module.void __stdcall PaxCompiler_AddCode(DWORD HCompiler, char * ModuleName, char * Text);Arguments
HCompilerHandle of compiler.ModuleNameName of module.TextSource code added to module.
Example
DWORD hc = PaxCompiler_Create(); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " MyPoint.Y := 8;"); PaxCompiler_AddCode(hc, "1", "end.");
Adds source code from text file to module.void __stdcall PaxCompiler_AddCodeFromFile(DWORD HCompiler, char * ModuleName, char * FileName);Arguments
HCompilerHandle of compiler.ModuleNameName of module.FileNameName of text file.
Example
DWORD hc = PaxCompiler_Create(); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCodeFromFile(hc, "1", "MyFile.pas");
Registeres paxCompiler language object for compiler.void __stdcall PaxCompiler_RegisterLanguage(DWORD HCompiler, DWORD HLanguage);Arguments
HCompilerHandle of compiler.HLanguageHandle of paxCompiler language.
Example
DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); PaxCompiler_RegisterLanguage(hc, hl);
Registeres host-defined namespace for compiler. Returns id of namespace.DWORD __stdcall PaxCompiler_RegisterNamespace(DWORD HCompiler, DWORD LevelId, char * NamespaceName);Arguments
HCompilerHandle of compiler.LevelIdId of owner namespace. If LevelId = 0, the owner is root namespace.
Registeres a record type (structure type) for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterRecordType(DWORD HCompiler, DWORD LevelId, char * TypeName);Arguments
HCompilerHandle of compiler.LevelIdId of owner namespace or owner record type.TypeNameName of type.
Example
struct TMyPoint { long x; long y; }; ..................................... DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); PaxCompiler_RegisterLanguage(hc, hl); // register host-defined type DWORD H_TMyPoint = PaxCompiler_RegisterRecordType(hc, 0, "TMyPoint"); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "X", PaxTypeLONG); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "Y", PaxTypeLONG);
Registeres field of record (structure) type. Returns id of type.DWORD __stdcall PaxCompiler_RegisterRecordTypeField(DWORD HCompiler, DWORD RecordTypeId, char * FieldName, DWORD FieldTypeID);Arguments
HCompilerHandle of compiler.RecordTypeIdId of record type.FieldNameName of field.FieldTypeIDId of type of field.
Example
struct TMyPoint { long x; long y; }; ..................................... DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); PaxCompiler_RegisterLanguage(hc, hl); // register host-defined type DWORD H_TMyPoint = PaxCompiler_RegisterRecordType(hc, 0, "TMyPoint"); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "X", PaxTypeLONG); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "Y", PaxTypeLONG);
Registeres a subrange type for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterSubrangeType(DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD TypeBaseId, long B1, long B2);Arguments
HCompilerHandle of compiler.LevelIdId of namespace or owner record type.TypeNameName of type.B1Low bound of the subrange type.B2High bound of the subrange type.
Example
DWORD h_subrange = PaxCompiler_RegisterSubrangeType(hc, 0, "Subrange", PaxTypeLONG, 0, 9);
Registeres an array type for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterArrayType(DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD RangeTypeId, DWORD ElemTypeId);Arguments
HCompilerHandle of compiler.LevelIdId of namespace or owner record type.TypeNameName of type.RangeTypeIdId of subrange type.ElemTypeIdId of array element type.
Example
typedef double MyArray[10]; ...................................................... DWORD h_subrange = PaxCompiler_RegisterSubrangeType(hc, 0, "Subrange", PaxTypeLONG, 0, 9); DWORD h_arr = PaxCompiler_RegisterArrayType) (hc, 0, "MyArray", h_subrange, PaxTypeDOUBLE);
Registeres a pointer type for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterPointerType(DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD OriginTypeId);Arguments
HCompilerHandler of compiler.LevelIdId of namespace or owner record type.TypeNameName of type.OriginTypeIdId of origin type.
Example
struct TMyPoint { long x; long y; }; typedef struct TMyPoint * PMyPoint; ..................................... DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); PaxCompiler_RegisterLanguage(hc, hl); // register host-defined type DWORD H_TMyPoint = PaxCompiler_RegisterRecordType(hc, 0, "TMyPoint"); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "X", PaxTypeLONG); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "Y", PaxTypeLONG); DWORD P_TMyPoint = PaxCompiler_RegisterPointerType(hc, 0, "PMyPoint", H_TMyPoint);
Registeres a set type for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterSetType(DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD OriginTypeId);Arguments
HCompilerHandle of compiler.LevelIdId of namespace or owner record type.TypeNameName of type.OriginTypeIdId of origin type.
Example
DWORD h_myset = PaxCompiler_RegisterSetType(hc, 0, "MySet", PaxTypeCHAR);
Registeres a set type for compiler. Returns id of type.DWORD __stdcall PaxCompiler_RegisterProceduralType (DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD SubId);Arguments
HCompilerHandle of compiler.LevelIdId of namespace or owner record type.TypeNameName of type.SubIdId of registered subroutine.
Registeres a host-defined variable for compiler. Returns id of the variable.DWORD __stdcall PaxCompiler_RegisterVariable(DWORD HCompiler, DWORD LevelId, char * Name, DWORD TypeId);Arguments
HCompilerHandle of compiler.LevelIdId of namespace or owner record type.NameName of variable.TypeIdId of type of the variable.
Example
#include "stdafx.h" #include "paxcompilerlib.h" struct TMyPoint { long x; long y; }; int main(int argc, char* argv[]) { HMODULE h_lib = LoadPaxCompilerLib(); if (h_lib != 0) { TMyPoint MyPoint; MyPoint.x = 60; MyPoint.y = 23; DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); // register host-defined type DWORD H_TMyPoint = PaxCompiler_RegisterRecordType(hc, 0, "TMyPoint"); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "X", PaxTypeLONG); PaxCompiler_RegisterRecordTypeField(hc, H_TMyPoint, "Y", PaxTypeLONG); // register host-defined variable DWORD H_MyPoint = PaxCompiler_RegisterVariable(hc, 0, "MyPoint", H_TMyPoint); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " MyPoint.Y := 8;"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { // set address of the variable PaxProgram_SetAddress(hp, H_MyPoint, &MyPoint); PaxProgram_Run(hp); printf("MyPoint.y = %d\n", MyPoint.y); } 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; }
Registeres a host-defined routine for compiler. Returns id of routine.DWORD __stdcall PaxCompiler_RegisterRoutine(DWORD HCompiler, WORD LevelId, char * Name, DWORD ResultTypeID);Arguments
HCompilerHandle of compiler.LevelIdId of namespace.NameName of routine.ResultTypeIdId of result type.The registered routine must have __stdcall calling convention. Use PaxCompiler_RegisterRoutineEx to register routine with __cdecl calling convention.
Example
void __stdcall show_message(char * s) { printf(s); } ............................................ DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); DWORD h_show_message = PaxCompiler_RegisterRoutine(hc, 0, "ShowMessage", PaxTypeVOID); PaxCompiler_RegisterParameter(hc, h_show_message, PaxTypePCHAR, false); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " ShowMessage('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_SetAddress(hp, h_show_message, & show_message); PaxProgram_Run(hp); }
Registeres a host-defined routine for compiler.DWORD __stdcall PaxCompiler_RegisterRoutineEx(DWORD HCompiler, DWORD LevelId, char * Name, DWORD ResultTypeID, long CallConvention);Arguments
HCompilerHandle of compiler.LevelIdId of namespace.NameName of routine.ResultTypeIdId of result type.CallingConventionCallingConvention: ccSTDCALL = 1; ccCDECL = 3;
Example
void show_message(char * s) { printf(s); } ............................................ DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); DWORD h_show_message = PaxCompiler_RegisterRoutineEx(hc, 0, "ShowMessage", PaxTypeVOID, ccCDECL); PaxCompiler_RegisterParameter(hc, h_show_message, PaxTypePCHAR, false); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " ShowMessage('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_SetAddress(hp, h_show_message, & show_message); PaxProgram_Run(hp); }
Registeres parameter for compiler.DWORD __stdcall PaxCompiler_RegisterParameter(DWORD HCompiler, DWORD HSub, DWORD ParamTypeID, bool ByRef);Arguments
HCompilerHandle of compiler.HSubId of routine.ParamTypeIdId of type of the parameter.ByRefIf 'true', this is a 'byref' parameter, otherwise, this is a 'byval' parameter.
Creates compiled program.DWORD __stdcall PaxCompiler_Compile(DWORD HCompiler, DWORD HProgram);Arguments
HCompilerHandle of compiler.HProgramHandle of compiled program.
Example
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", "begin"); PaxCompiler_AddCode(hc, "1", " writeln('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); }
Returns number of compile-time error count.DWORD __stdcall PaxCompiler_GetErrorCount(DWORD HCompiler);Arguments
HCompilerHandle of compiler.
Example
if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf(PaxCompiler_GetErrorMessage(hc, i)); } }
Returns error message of i-th compile-time error in the error list.char * __stdcall PaxCompiler_GetErrorMessage(DWORD HCompiler, long i);Arguments
HCompilerHandle of compiler.iIndex of error.
Example
if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf(PaxCompiler_GetErrorMessage(hc, i)); } }
Returns name of module which contains i-th error in the error list.char * __stdcall PaxCompiler_GetErrorModuleName (DWORD HCompiler, long i);Arguments
HCompilerHandle of compiler.iIndex of error.
Example
if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf("Message: %s\n", PaxCompiler_GetErrorMessage(hc, i)); printf("Module: %s\n", PaxCompiler_GetErrorModuleName(hc, i)); } }
Returns line of source code module which contains i-th error in the error list.char * __stdcall PaxCompiler_GetErrorLine(DWORD HCompiler, long i);Arguments
HCompilerHandle of compiler.iIndex of error.
Example
if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf("Message: %s\n", PaxCompiler_GetErrorMessage(hc, i)); printf("Module: %s\n", PaxCompiler_GetErrorModuleName(hc, i)); printf("Line: %s\n", PaxCompiler_GetErrorLine(hc, i)); } }
Returns line number of source code module which contains i-th error in the error list.DWORD __stdcall PaxCompiler_GetErrorLineNumber(DWORD HCompiler, long i);Arguments
HCompilerHandle of compiler.iIndex of error.
Example
if (PaxCompiler_Compile(hc, hp)) { PaxProgram_Run(hp); } else { printf("there are errors:\n"); for (int i = 0; i < PaxCompiler_GetErrorCount(hc); i++) { printf("Message: %s\n", PaxCompiler_GetErrorMessage(hc, i)); printf("Module: %s\n", PaxCompiler_GetErrorModuleName(hc, i)); printf("Line: %s\n", PaxCompiler_GetErrorLine(hc, i)); printf("Line number: %d\n", PaxCompiler_GetErrorLineNumber(hc, i)); } }
Returnd id of script-defined routine or variable.DWORD __stdcall PaxCompiler_GetHandle(DWORD HCompiler, DWORD LevelId, char * Name, DWORD Upcase);Arguments
HCompilerHandle of compiler.NameName of variable or routine.UpcaseIf 'false', the search of id will case sensitive.
Example
#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; }
Constructor of compiled program object. Returns handle of the compiled program.DWORD __stdcall PaxProgram_Create();
Destructor of compiled program.void __stdcall PaxProgram_Destroy(DWORD HProgram);Arguments
HProgramHandle of compiled program.
Executes compiled program.void __stdcall PaxProgram_Run(DWORD HProgram);Arguments
HProgramHandle of compiled program.
Example
DWORD hp = PaxProgram_Create(); PaxProgram_LoadFromFile(hp, "1.bin"); PaxProgram_Run(hp); PaxProgram_Destroy(hp);
Saves compiled program to file.void __stdcall PaxProgram_SaveToFile(DWORD HProgram, char * Path);Arguments
HProgramHandle of compiled program.PathFile name.
Example
DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); h_show_message = PaxCompiler_RegisterRoutineEx(hc, 0, "ShowMessage", PaxTypeVOID, ccCDECL); PaxCompiler_RegisterParameter(hc, h_show_message, PaxTypePCHAR, false); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " ShowMessage('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_SaveToFile(hp, "1.bin"); printf("Compiled script has been created!\n"); }
Loads compiled program from file.void __stdcall PaxProgram_LoadFromFile(DWORD HProgram, char * Path);Arguments
HProgramHandle of compiled program.PathFile name.
Example
DWORD hp = PaxProgram_Create(); PaxProgram_LoadFromFile(hp, "1.bin"); PaxProgram_Run(hp); PaxProgram_Destroy(hp);
Returns address of script-defined variable or routine.void __stdcall PaxProgram_GetAddress(DWORD HProgram, DWORD Handle);Arguments
HProgramHandle of compiled program.HandleId of script-defined variable or routine.
Example
#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; }
Sets address of host-defined variable or routine.void __stdcall PaxProgram_SetAddress(DWORD HProgram, DWORD Handle, void * p);Arguments
HProgramHandle of compiled program.HandleHandle of host-defined variable or routine.pAddress of host-defined variable or routine.
Example
void __stdcall show_message(char * s) { printf(s); } ............................................ DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); DWORD hp = PaxProgram_Create(); PaxCompiler_Reset(hc); PaxCompiler_RegisterLanguage(hc, hl); DWORD h_show_message = PaxCompiler_RegisterRoutine(hc, 0, "ShowMessage", PaxTypeVOID); PaxCompiler_RegisterParameter(hc, h_show_message, PaxTypePCHAR, false); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " ShowMessage('Hello');"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { PaxProgram_SetAddress(hp, h_show_message, & show_message); PaxProgram_Run(hp); }
Returns address of data segment of compiled program.void * __stdcall PaxProgram_GetDataPtr(DWORD HProgram);Arguments
HProgramHandle of compiled program.
Example
#include "stdafx.h" #include "paxcompilerlib.h" long y = 5; 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); DWORD h_y = PaxCompiler_RegisterVariable(hc, 0, "Y", PaxTypeLONG); PaxCompiler_AddModule(hc, "1", "Pascal"); PaxCompiler_AddCode(hc, "1", "procedure ScriptProc(X: Integer);"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", " Y := Y + X;"); PaxCompiler_AddCode(hc, "1", "end;"); PaxCompiler_AddCode(hc, "1", "begin"); PaxCompiler_AddCode(hc, "1", "end."); if (PaxCompiler_Compile(hc, hp)) { DWORD h_ScriptProc = PaxCompiler_GetHandle(hc, 0, "ScriptProc", true); void * p = PaxProgram_GetAddress(hp, h_ScriptProc); // get address of script-defined procedure PaxProgram_SetAddress(hp, h_y, &y); void * data_ptr = PaxProgram_GetDataPtr(hp); void * code_ptr = PaxProgram_GetCodePtr(hp); __asm { // save registers push esi push edi push ebp // push data & code segment pointers push data_ptr push code_ptr push 10 // push parameter call p // call script-defined procedure pop eax // pop code segment pointer pop eax // pop data segment pointer // restore registers pop ebp pop edi pop esi } printf("y = %d", y); } 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; }
Returns address of data segment of compiled program.void * __stdcall PaxProgram_GetCodePtr(DWORD HProgram);Arguments
HProgramHandle of compiled program.
Constructor of PaxPascal language object. Returns handle of object.DWORD __stdcall PaxPascalLanguage_Create();
Example
DWORD hc = PaxCompiler_Create(); DWORD hl = PaxPascalLanguage_Create(); PaxCompiler_RegisterLanguage(hc, hl);
Destructor of PaxPascal language object.void __stdcall PaxPascalLanguage_Destroy(DWORD HPaxPascalLanguage);Arguments
HPaxPascalLanguageHandle of PaxPascal language object.