Routines exported by paxcompilerlib.dll


LoadPaxCompilerLib

Loads paxcompilerlib.dll
HMODULE 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;
}

FreePaxCompilerLib

Unloads paxcompilerlib.dll
long FreePaxCompilerLib(HMODULE h_lib);

Arguments

h_lib
Handle of library.

PaxCompiler_Create

paxCompiler constructor. Returns handle of paxCompiler object.
DWORD __stdcall PaxCompiler_Create();

PaxCompiler_Destroy

paxCompiler destructor. Destroyes paxCompiler object.
void __stdcall PaxCompiler_Destroy(DWORD HCompiler);

PaxCompiler_Reset

Removes all source code modules and registered items from compiler.
void __stdcall PaxCompiler_Reset(DWORD HCompiler);

PaxCompiler_AddModule

Adds source code module to compiler.
void __stdcall PaxCompiler_AddModule(DWORD HCompiler, char * Name, char * LanguageName);

Arguments

HCompiler
Handle of compiler.
Name
Name of module.
LanguageName
Name of programming language supported by compiler.

Example

DWORD hc = PaxCompiler_Create();
PaxCompiler_AddModule(hc, "1", "Pascal");

PaxCompiler_AddCode

Adds source code to source code module.
void __stdcall PaxCompiler_AddCode(DWORD HCompiler, char * ModuleName, char * Text);

Arguments

HCompiler
Handle of compiler.
ModuleName
Name of module.
Text
Source 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.");

PaxCompiler_AddCodeFromFile

Adds source code from text file to module.
void __stdcall PaxCompiler_AddCodeFromFile(DWORD HCompiler, char * ModuleName, char * FileName);

Arguments

HCompiler
Handle of compiler.
ModuleName
Name of module.
FileName
Name of text file.

Example

DWORD hc = PaxCompiler_Create();
PaxCompiler_AddModule(hc, "1", "Pascal");
PaxCompiler_AddCodeFromFile(hc, "1", "MyFile.pas");

PaxCompiler_RegisterLanguage

Registeres paxCompiler language object for compiler.
void __stdcall PaxCompiler_RegisterLanguage(DWORD HCompiler, DWORD HLanguage);

Arguments

HCompiler
Handle of compiler.
HLanguage
Handle of paxCompiler language.

Example

DWORD hc = PaxCompiler_Create();
DWORD hl = PaxPascalLanguage_Create();
PaxCompiler_RegisterLanguage(hc, hl);

PaxCompiler_RegisterNamespace

Registeres host-defined namespace for compiler. Returns id of namespace.
DWORD __stdcall PaxCompiler_RegisterNamespace(DWORD HCompiler, DWORD LevelId, char * NamespaceName);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of owner namespace. If LevelId = 0, the owner is root namespace.

PaxCompiler_RegisterRecordType

Registeres a record type (structure type) for compiler. Returns id of type.
DWORD __stdcall PaxCompiler_RegisterRecordType(DWORD HCompiler, DWORD LevelId, char * TypeName);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of owner namespace or owner record type.
TypeName
Name 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);

PaxCompiler_RegisterRecordTypeField

Registeres field of record (structure) type. Returns id of type.
DWORD __stdcall PaxCompiler_RegisterRecordTypeField(DWORD HCompiler, DWORD RecordTypeId, char * FieldName, DWORD FieldTypeID);

Arguments

HCompiler
Handle of compiler.
RecordTypeId
Id of record type.
FieldName
Name of field.
FieldTypeID
Id 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);

PaxCompiler_RegisterSubrangeType

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

HCompiler
Handle of compiler.
LevelId
Id of namespace or owner record type.
TypeName
Name of type.
B1
Low bound of the subrange type.
B2
High bound of the subrange type.

Example

DWORD h_subrange = PaxCompiler_RegisterSubrangeType(hc, 0, "Subrange", PaxTypeLONG, 0, 9);

PaxCompiler_RegisterArrayType

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

HCompiler
Handle of compiler.
LevelId
Id of namespace or owner record type.
TypeName
Name of type.
RangeTypeId
Id of subrange type.
ElemTypeId
Id 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);

PaxCompiler_RegisterPointerType

Registeres a pointer type for compiler. Returns id of type.
DWORD __stdcall PaxCompiler_RegisterPointerType(DWORD HCompiler,
DWORD LevelId, char * TypeName, DWORD OriginTypeId);

Arguments

HCompiler
Handler of compiler.
LevelId
Id of namespace or owner record type.
TypeName
Name of type.
OriginTypeId
Id 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);

PaxCompiler_RegisterSetType

Registeres a set type for compiler. Returns id of type.
DWORD __stdcall PaxCompiler_RegisterSetType(DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD OriginTypeId);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of namespace or owner record type.
TypeName
Name of type.
OriginTypeId
Id of origin type.

Example

DWORD h_myset = PaxCompiler_RegisterSetType(hc, 0, "MySet", PaxTypeCHAR);

PaxCompiler_RegisterProceduralType

Registeres a set type for compiler. Returns id of type.
DWORD __stdcall PaxCompiler_RegisterProceduralType (DWORD HCompiler, DWORD LevelId, char * TypeName, DWORD SubId);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of namespace or owner record type.
TypeName
Name of type.
SubId
Id of registered subroutine.

PaxCompiler_RegisterVariable

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

HCompiler
Handle of compiler.
LevelId
Id of namespace or owner record type.
Name
Name of variable.
TypeId
Id 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;
}

PaxCompiler_RegisterRoutine

Registeres a host-defined routine for compiler. Returns id of routine.
DWORD __stdcall PaxCompiler_RegisterRoutine(DWORD HCompiler, WORD LevelId, char * Name, DWORD ResultTypeID);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of namespace.
Name
Name of routine.
ResultTypeId
Id 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);
}

PaxCompiler_RegisterRoutineEx

Registeres a host-defined routine for compiler.
DWORD __stdcall PaxCompiler_RegisterRoutineEx(DWORD HCompiler, DWORD LevelId, char * Name, DWORD ResultTypeID, long CallConvention);

Arguments

HCompiler
Handle of compiler.
LevelId
Id of namespace.
Name
Name of routine.
ResultTypeId
Id of result type.
CallingConvention
CallingConvention: 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);
}

PaxCompiler_RegisterParameter

Registeres parameter for compiler.
DWORD __stdcall PaxCompiler_RegisterParameter(DWORD HCompiler,
DWORD HSub, DWORD ParamTypeID, bool ByRef);

Arguments

HCompiler
Handle of compiler.
HSub
Id of routine.
ParamTypeId
Id of type of the parameter.
ByRef
If 'true', this is a 'byref' parameter, otherwise, this is a 'byval' parameter.

PaxCompiler_Compile

Creates compiled program.
DWORD __stdcall PaxCompiler_Compile(DWORD HCompiler, DWORD HProgram);

Arguments

HCompiler
Handle of compiler.
HProgram
Handle 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);
}

PaxCompiler_GetErrorCount

Returns number of compile-time error count.
DWORD __stdcall PaxCompiler_GetErrorCount(DWORD HCompiler);

Arguments

HCompiler
Handle 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));
     }
}

PaxCompiler_GetErrorMessage

Returns error message of i-th compile-time error in the error list.
char * __stdcall PaxCompiler_GetErrorMessage(DWORD HCompiler, long i);

Arguments

HCompiler
Handle of compiler.
i
Index 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));
     }
}

PaxCompiler_GetErrorModuleName

Returns name of module which contains i-th error in the error list.
char * __stdcall PaxCompiler_GetErrorModuleName (DWORD HCompiler, long i);

Arguments

HCompiler
Handle of compiler.
i
Index 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));
     }
}

PaxCompiler_GetErrorLine

Returns line of source code module which contains i-th error in the error list.
char * __stdcall PaxCompiler_GetErrorLine(DWORD HCompiler, long i);

Arguments

HCompiler
Handle of compiler.
i
Index 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));
     }
}

PaxCompiler_GetErrorLineNumber

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

HCompiler
Handle of compiler.
i
Index 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));
     }
}

PaxCompiler_GetHandle

Returnd id of script-defined routine or variable.
DWORD __stdcall PaxCompiler_GetHandle(DWORD HCompiler, DWORD LevelId, char * Name, DWORD Upcase);

Arguments

HCompiler
Handle of compiler.
Name
Name of variable or routine.
Upcase
If '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;
}

PaxProgram_Create

Constructor of compiled program object. Returns handle of the compiled program.
DWORD __stdcall PaxProgram_Create();

PaxProgram_Destroy

Destructor of compiled program.
void __stdcall PaxProgram_Destroy(DWORD HProgram);

Arguments

HProgram
Handle of compiled program.

PaxProgram_Run

Executes compiled program.
void __stdcall PaxProgram_Run(DWORD HProgram);

Arguments

HProgram
Handle of compiled program.

Example

DWORD hp = PaxProgram_Create();
PaxProgram_LoadFromFile(hp, "1.bin");
PaxProgram_Run(hp);
PaxProgram_Destroy(hp);

PaxProgram_SaveToFile

Saves compiled program to file.
void __stdcall PaxProgram_SaveToFile(DWORD HProgram, char * Path);

Arguments

HProgram
Handle of compiled program.
Path
File 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");
}

PaxProgram_LoadFromFile

Loads compiled program from file.
void __stdcall PaxProgram_LoadFromFile(DWORD HProgram, char * Path);

Arguments

HProgram
Handle of compiled program.
Path
File name.

Example

DWORD hp = PaxProgram_Create();
PaxProgram_LoadFromFile(hp, "1.bin");
PaxProgram_Run(hp);
PaxProgram_Destroy(hp);

PaxProgram_GetAddress

Returns address of script-defined variable or routine.
void __stdcall PaxProgram_GetAddress(DWORD HProgram, DWORD Handle);

Arguments

HProgram
Handle of compiled program.
Handle
Id 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;
}

PaxProgram_SetAddress

Sets address of host-defined variable or routine.
void __stdcall PaxProgram_SetAddress(DWORD HProgram, DWORD Handle, void * p);

Arguments

HProgram
Handle of compiled program.
Handle
Handle of host-defined variable or routine.
p
Address 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);
}

PaxProgram_GetDataPtr

Returns address of data segment of compiled program.
void * __stdcall PaxProgram_GetDataPtr(DWORD HProgram);

Arguments

HProgram
Handle 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;
}

PaxProgram_GetCodePtr

Returns address of data segment of compiled program.
void * __stdcall PaxProgram_GetCodePtr(DWORD HProgram);

Arguments

HProgram
Handle of compiled program.

PaxPascalLanguage_Create

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);

PaxPascalLanguage_Destroy

Destructor of PaxPascal language object.
void __stdcall PaxPascalLanguage_Destroy(DWORD HPaxPascalLanguage);

Arguments

HPaxPascalLanguage
Handle of PaxPascal language object.


Copyright © 2006-2017 Alexander Baranovsky. All rights reserved.