|
From: Vitor S. C. <vi...@bi...> - 2001-11-09 20:05:43
|
Hi Erick,
>=20
> I have both prolog code and external predicates written in C++.
>=20
ok.
> I would like to know if there is a way to produce one single executable
> file with yap 4.3.19. Otherwise, could someone tell me a convenient way
> to compile my project?
>=20
Yap is compiled as follows: first we create a libYap.a library with
the files in the C directory. Then we link this library with the
console/yap.c file. yap.c sets up the system and then calls the
top-level.
To change the top-level you likely want to hack over yap.c. yap.c
essentially initialises everything and then calls the predicate $live
over and over again. You can change your top-level by editing $live.
To extend Yap with new builtins one solution is to add files in the C
directory. In this case you will have functions of the form
/* returns either TRUE or FALSE */
static Int
p_whatever(void)
{
/* get input args */
Term t1 =3D Deref(ARG1);
Term t2 =3D Deref(ARG2);
/* check possible typing errors */
if (IsVarTerm(t1)) {
/* set up an error */
Error(INSTANTIATION_ERROR, t1, "my message";
/* fail */
return(FALSE);
}
/* do something useful and place the result in term tf */
tf =3D something_really_nice(t1, t2);
/* we're done */
return(unify(tf,ARG3));
}
at the end of the file you need to add your new predicates, which is
quite simple:
/* this is not static */
InitMyStuff()
{=20
/* first argument is the name, second is arity, third is C-function,
last is flags (0 is safe) */
InitCPred("whatever", 3, p_whatever, 0);
}
last, you need to call InitMyStuff from somewhere. A good place is
C/stdpreds.c in the function
InitCPreds();
> Thanks in advance for your help,
> Regards,
> Erick.
>=20
Hope this helps and feel free to ask more questions,
Regards,
V=EDtor
|