.\" ------------------------- secz.t ------------------------- .bp .uh "Appendix 1: Evaluable Predicates of SB-Prolog" .sp .pp An entry of ``B'' indicates a builtin predicate, ``I'' an inline predicate, and ``L'' a library predicate. A ``P'' indicates that the predicate is handled by the preprocessor during compilation and/or consulting. .sp .2c .lp .xp b .1c .lp .bp .lp .uh "Appendix 2: Adding Builtins to SB-Prolog" .EQ delim @@ .EN .pp Adding a builtin involves writing the C code for the desired case and installing it into the simulator. The files in the irectory \fIsim/builtin\fR contain the C code for the builtin predicates supported by the system. The following procedure is to be followed when adding a builtin to the system: .sp .lp \fII. Installing C Code\fR: .np Go to the directory \fIsim/builtin\fR. .np Look at the \fB#define\fRs in the file \fIbuiltin.h\fR, and choose a number \fIN1\fR (between 0 and 255) which is not in use to be the builtin number for the new builtin. .np Add to the file \fIbuiltin.h\fR the line .(l #define NEWBUILTIN \fIN1\fR .)l .np The convention is that the code for builtin will be in a parameterless procedure named \fIb_\|NEWBUILTIN\fR. Modify the file \fIinit_\|\^branch.c\fR in the directory \fIsim/builtin\fR by adding these lines: .(l extern int b_\|NEWBUILTIN(); and set_\|b_\|inst ( NEWBUILTIN, b_\|NEWBUILTIN ); .)l in the appropriate places. .np The builtins are compiled together into one object file, \fIbuiltin\fR. Update the file \fIMakefile\fR by appending the name of your object code file at the end of the line ``OBJS = ... '' and insert the appropriate commands to compile your C source file, e.g.: .(l OBJS = [ ... \fIother file names\fR ... ] newbuiltin.o ... newbuiltin.o: $(HS) cc $(CFLAGS) newbuiltin.c .)l .np Execute the updated make file to create an updated object file \fIbuiltin\fR. .np Go to the directory \fIsim\fR and execute \fImake\fR to install the new file \fIbuiltin\fR. .sp .lp \fIII. Installing Prolog Code\fR: .pp Assume that the builtin predicate to be added is \fInewbuiltin\fR/4. The procedure for installing the Prolog code for this is as follows: .np Go to the SB-Prolog system directory \fIlib/src\fR, where the Prolog source for the library routines is kept. .np Each builtin definition is of the form .(l pred( ... ) :\- '_\|$builtin'(\fIN\fR\^). .)l where \fIN\fR is an integer, the builtin number of \fIpred\fR. .np Create a Prolog source file \fInewbuiltin.P\fR (notice correspondence with the name of the predicate being defined) containing the definition .(l newbuiltin(A,B,C,D) :\- '_\|$builtin'(\fIN1\fR\^). .)l where \fIN1\fR is the builtin number of the predicate \fInewbuiltin\fR, obtained when installing the C code for the builtin (see above). .np Compile this Prolog predicate, using the simulator and the \fIcompile\fR predicate, into a file \fInewbuiltin\fR (notice correspondence with the name of the predicate being defined) in the SB-Prolog directory \fIlib\fR. .sp .fo '''' .bp .ce \fBTABLE OF CONTENTS\fR .sp .xp c .\" ----------------------- end of section secz.t -----------------------