. , , ,

,,,

Prolog — ,

Prolog .

Dll.

DOS. 2 : . , .

, , , .. . (. . 1).

1.

DLL ( ) , , . Prolog DLL, DLL .

VP .

, , . :

GLOBAL PREDICATES

procedure add(integer A, integer B, integer C) (i,i,o) language pascal

: , VP

/ .

. 32 , .

, Pascal , C - ( , , ).

.

VP / , . , Prolog + _X, X ( , 0). , . :

GLOBAL PREDICATES

subtraction(integer, integer, integer) (i,i,o), (i,o,i), (o,i,i), (i,i,i) language C

change(integer, integer) (i,o) language C

GOAL

subtraction(2,2,X), write(2-2=,X), nl,

subtraction(2,Y,5), write(2-5=,Y), nl,

subtraction(Z,5,4), write(5-4=,X), nl,

subtraction(2,2,5), write(2-2 5), nl,

change(5, Ch), write(Ch).

, :

subtraction_0 (int x, int y, int *z)

{*z=x-y;}

subtraction_1 (int x, int *y, int z)

{*y=x-z;}

subtraction_2 (int *x, int y, int z)

{*x=y-z;}

subtraction_3 (int x, int y, int z)

{if ((x-y)!=z)RUN_Fail();}

change(int a, int *b)

{*b=a;}

: C, ( VP), , (. 1).

Win32.

Win32 2 : OMF (- , , Borland C++ ) COFF ( - , , , Visual C++ ).

1.      OMF .

2.      COFF, , @ , (, name 2 , _name@8 (. 1)).

.

: . , Pascal , (. 1).

.

.

.

COFF.

C

-

-

-

pascal

+

+

+

stdcall

+

-

+

syscall

+

+

-

1: VP.

.

VP . :

GLOBAL PREDICATES

add(integer, integer, integer) (i,o) language c as _myadd@12

.

VP , (. 2).

(Win32).

char, byte

1

short, word

2

long, dword

4

unsigned, integer

4

Real

8

Ref

4

2: VP.

.

, , .

ListToArray , ( ).

2 :

1.     

2.     

/* Program lstar_p.pro */

project "lstar"

global domains

ilist = integer*

global predicates

inclist(ilist,ilist) - (i,o) language c

goal

inclist([1,2,3,4,5,6,7],L), write(L).

/* Program lstar_c.c */

#define listfno 1

#define nilfno 2

typedef unsigned char BYTE;

void *MEM_AllocGStack(unsigned);

typedef struct ilist {

BYTE Functor;

int Value;

struct ilist *Next;

} INTLIST;

int ListToArray(INTLIST *List,int **ResultArray)

{

INTLIST *SaveList = List;

int *Array, len;

register int *ArrP;

register int i;

/* */

i = 0;

while ( List->Functor == listfno ) {

i++;

List = List->Next;

}

len = i;

Array = MEM_AllocGStack(i*sizeof(int));

ArrP = Array;

/* */

List = SaveList;

while ( i != 0 ) {

*ArrP++ = List->Value;

List = List->Next;

i--;

}

*ResultArray = Array;

return(len);

}

void ArrayToList(register int *ArrP,register int n,
register INTLIST **ListPP)

{

while ( n != 0 ) {

*ListPP = MEM_AllocGStack(sizeof(INTLIST));

(*ListPP)->Functor = listfno;

(*ListPP)->Value = *ArrP++;

ListPP = &(*ListPP)->Next;

n--;

}

*ListPP = MEM_AllocGStack(sizeof((*ListPP)->Functor));
/* */

(*ListPP)->Functor = nilfno;

}

void inclist(INTLIST *InList,INTLIST **OutList)

{

register int *ArrP, i, len;

int *Array;

len = ListToArray(InList,&Array);

ArrP = Array;

for ( i = 0; i < len; i++)

++*ArrP++;

ArrayToList(Array,len,OutList);

}

VP.

VP , . prowin_msg :

/* Program hello_p.pro */

global predicates

char prowin_msg(string) - (i) language c

hello_c - language c

clauses

prowin_msg(S,C) :-

write(S," (press any key)"), readchar(C).

goal

prowin_msg("Hello from PDC Prolog"),

hello_c.

/* Program hello_c.c */

char prowin_msg(char *);

void hello_c()

{

while ( prowin_msg("Hello from C (press 'C')") != 'C' )

;

}

2003 Pechenkin

pechenkin@pochtamt.ru

www.cs.vsu.ru/~pechenkin

Prolog . Dll. DOS. 2 : .

 

 

 

! , , , .
. , :