home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plbin.zip / pl / include / SWI-Prolog.h < prev   
C/C++ Source or Header  |  1993-03-04  |  8KB  |  270 lines

  1. /*  pl-itf.h,v 1.18 1993/02/23 13:16:36 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     See ../LICENCE to find out about your rights.
  5.     jan@swi.psy.uva.nl
  6.  
  7.     Purpose: SWI-Prolog foreign language interface include file
  8. */
  9.  
  10. #ifndef PL_INCLUDED
  11. #define PL_INCLUDED
  12.  
  13. #ifndef PLVERSION
  14. #define PLVERSION "1.6.12, February 1993"
  15. #endif
  16.  
  17. #ifndef P
  18. #if __STDC__ || PROTO
  19. #define P(x) x
  20. #else
  21. #define P(x) ()
  22. #endif
  23. #endif
  24.  
  25. #if __GNUC__
  26. #define constf const            /* const function */
  27. #else
  28. #define constf
  29. #endif
  30.  
  31. #ifndef PL_KERNEL
  32. typedef    unsigned long    atomic;        /* atomic Prolog datum */
  33. typedef unsigned long    functor;    /* name/arity pair as Prolog */
  34. typedef unsigned long    module;        /* Prolog module */
  35. typedef unsigned long *    term;        /* general term */
  36. typedef unsigned long    foreign_t;    /* return type of foreign functions */
  37. #define O_STRING 1
  38. #else
  39. typedef word        atomic;
  40. typedef FunctorDef    functor;
  41. typedef Module        module;
  42. typedef Word        term;
  43. typedef word        foreign_t;
  44. #endif
  45.  
  46. typedef foreign_t    (*function)();    /* foreign language functions */
  47.  
  48. #ifndef TRUE
  49. #define TRUE    (1)
  50. #define FALSE    (0)
  51. #endif
  52.  
  53. typedef struct
  54. { unsigned long context[2];
  55. } bktrk_buf;                /* data-backtrack buffer */
  56.  
  57.  
  58.         /********************************
  59.         *            SYMBOLS            *
  60.         *********************************/
  61.  
  62. /*  The TOS linker on the ATARI_ST only allows for 8 character external
  63.     symbols.  The macros below redefine some of the interface function
  64.     names to avoid name clashes.
  65. */
  66.  
  67. #if __TOS__
  68. #define    PL_new_functor        PL_nfunc
  69. #define PL_new_float        PL_nflt
  70. #define PL_functor        PL_funct
  71. #define PL_functor_name        PL_fname
  72. #define PL_functor_arity    PL_farity
  73. #define    PL_unify        PL_uf
  74. #define PL_unify_atomic        PL_ufa
  75. #define PL_unify_functor    PL_uff
  76. #endif
  77.  
  78.         /********************************
  79.         *           ANALYSES            *
  80.         *********************************/
  81.  
  82. #define    PL_VARIABLE    (1)
  83. #define PL_ATOM        (2)
  84. #define PL_INTEGER    (3)
  85. #define PL_FLOAT    (4)
  86. #define PL_STRING    (5)
  87. #define PL_TERM        (6)
  88.  
  89. #define PL_atomic(t)    (*(t))        /* convert term to atomic */
  90.  
  91. int constf PL_is_var P((const term));
  92. int constf PL_is_int P((const term));
  93. int constf PL_is_atom P((const term));
  94. int constf PL_is_float P((const term));
  95. int constf PL_is_string P((const term));
  96. int constf PL_is_term P((const term));
  97.  
  98. int    constf PL_type P((const term));
  99. long    constf PL_integer_value P((const atomic));
  100. double           PL_float_value P((const atomic));
  101. char *           PL_string_value P((const atomic));
  102. char *         PL_list_string_value P((const term));
  103. char *    constf PL_atom_value P((const atomic));
  104. functor constf PL_functor P((const term));
  105. atomic    constf PL_functor_name P((const functor));
  106. int    constf PL_functor_arity P((const functor));
  107. term    constf PL_arg P((const term, int));
  108. term    constf PL_strip_module P((const term, module*));
  109.  
  110.         /********************************
  111.         *         CONSTRUCTION          *
  112.         *********************************/
  113.  
  114. term    PL_new_term P((void));        /* create a new term (variable) */
  115. atomic    PL_new_atom P((char *));    /* create an atom from a char * */
  116. atomic  PL_new_integer P((int));    /* create a new integer */
  117. atomic    PL_new_float P((double));    /* create a new float */
  118. #if O_STRING
  119. atomic    PL_new_string P((char *));    /* create a new string */
  120. #endif /* O_STRING */
  121. functor    PL_new_functor P((atomic, int)); /* create a new functor */
  122. int    PL_unify P((term, term));    /* unify two terms */
  123. int    PL_unify_atomic P((term, atomic));  /* unify term with atomic value */
  124. int    PL_unify_functor P((term, functor));/* unify term with functor */
  125.  
  126.         /********************************
  127.         *    DETERMINISTIC CALL/RETURN  *
  128.         *********************************/
  129.  
  130. #define    PL_succeed    return 1    /* succeed deterministically */
  131. #define PL_fail        return 0    /* fail */
  132.  
  133.         /********************************
  134.         * NON-DETERMINISTIC CALL/RETURN *
  135.         *********************************/
  136.  
  137. /*  Note 1: Non-deterministic foreign functions may also use the deterministic
  138.     return methods PL_succeed and PL_fail.
  139.  
  140.     Note 2: The argument to PL_retry is a 30 bits signed integer (long).
  141. */
  142.  
  143. #define PL_FIRST_CALL        (0)
  144. #define PL_CUTTED        (1)
  145. #define PL_REDO            (2)
  146.  
  147. #define PL_retry(n)        return _PL_retry(n)
  148. #define PL_retry_address(a)    return _PL_retry((long) a)
  149.  
  150. extern int             PL_foreign_control P((long));
  151. extern foreign_t        _PL_retry P((long));
  152. extern foreign_t        _PL_retry_address P((void *));
  153. extern long             PL_foreign_context P((long));
  154. #ifdef __STDC__
  155. extern void *             PL_foreign_context_address P((long));
  156. #else
  157. extern char *             PL_foreign_context_address P((long));
  158. #endif
  159.  
  160.         /********************************
  161.         *      REGISTERING FOREIGNS     *
  162.         *********************************/
  163.  
  164. #define PL_FA_NOTRACE        (1)    /* foreign cannot be traced */
  165. #define PL_FA_TRANSPARENT    (2)    /* foreign is module transparent */
  166. #define PL_FA_NONDETERMINISTIC    (4)    /* foreign is non-deterministic */
  167.  
  168. int    PL_register_foreign P((char *, int, function, ...));
  169.  
  170.         /********************************
  171.         *        CALLING PROLOG         *
  172.         *********************************/
  173.  
  174. void    PL_mark P((bktrk_buf *));    /* mark global and trail stack */
  175. void    PL_bktrk P((bktrk_buf *));    /* backtrack global stack to mark */
  176.  
  177. int    PL_call P((term, module));    /* invoke term as Prolog goal */
  178.  
  179.         /********************************
  180.         *            MODULES            *
  181.         *********************************/
  182.  
  183. module    PL_context P((void));        /* context module of predicate */        
  184. atomic    PL_module_name P((module));    /* return name of a module */
  185. module    PL_new_module P((atomic));    /* return module from an atom */
  186.  
  187.  
  188.         /********************************
  189.         *         EVENT HANDLING    *
  190.         ********************************/
  191.  
  192. #define PL_DISPATCH_INPUT   0        /* There is input available */
  193. #define PL_DISPATCH_TIMEOUT 1        /* Dispatch timeout */
  194.  
  195. extern int (*PL_dispatch_events) P((void));    /* Dispatch user events */
  196.  
  197.  
  198.         /********************************
  199.         *      INITIALISATION HOOK    *
  200.         ********************************/
  201.  
  202. extern void (*PL_foreign_reinit_function) P((int argc, char **argv));
  203.  
  204.  
  205.         /********************************
  206.         *            SIGNALS            *
  207.         *********************************/
  208.  
  209. void (*PL_signal P((int sig, void (*func)())))(); /* signal() replacement */
  210.  
  211.  
  212.         /********************************
  213.         *             ABORTS        *
  214.         ********************************/
  215.  
  216. void PL_abort_handle P((void (*func)())); /* func called by pl_abort() */
  217.  
  218.  
  219.         /********************************
  220.         *           WARNINGS            *
  221.         *********************************/
  222.  
  223. int    PL_warning P((char *, ...));    /* Print standard Prolog warning */
  224. void    PL_fatal_error P((char *, ...));    /* Print warning and die */
  225.  
  226.         /********************************
  227.         *        PROLOG ACTIONS         *
  228.         *********************************/
  229.  
  230. #define    PL_ACTION_TRACE        1    /* switch to trace mode */
  231. #define PL_ACTION_DEBUG        2    /* switch to debug mode */
  232. #define PL_ACTION_BACKTRACE    3    /* show a backtrace (stack dump) */
  233. #define PL_ACTION_BREAK        4    /* create a break environment */
  234. #define PL_ACTION_HALT        5    /* halt Prolog execution */
  235. #define PL_ACTION_ABORT        6    /* generate a Prolog abort */
  236. #define PL_ACTION_SYMBOLFILE    7    /* make arg. the symbol file */
  237. #define PL_ACTION_WRITE        8    /* write via Prolog i/o buffer */
  238. #define PL_ACTION_FLUSH        9    /* Flush Prolog i/o buffer */
  239.  
  240. int    PL_action P((int, void *));    /* perform some action */
  241. void    PL_on_halt P((void (*)(int, void *), void *));
  242.  
  243.         /********************************
  244.         *         QUERY PROLOG          *
  245.         *********************************/
  246.  
  247. #define PL_QUERY_ARGC        1    /* return main() argc */
  248. #define PL_QUERY_ARGV        2    /* return main() argv */
  249. #define PL_QUERY_SYMBOLFILE    3    /* return current symbol file */
  250. #define PL_QUERY_ORGSYMBOLFILE    4    /* symbol file before first load */
  251. #define PL_QUERY_GETC        5    /* Read character from terminal */
  252.  
  253. long    PL_query P((int));        /* get information from Prolog */
  254.  
  255.         /********************************
  256.         *        STATIC LINKING        *
  257.         ********************************/
  258.  
  259. typedef struct _PL_extension
  260. { char         *predicate_name;    /* Name of the predicate */
  261.   short        arity;            /* Arity of the predicate */
  262.   function    function;        /* Implementing functions */
  263.   short        flags;            /* Or of PL_FA_... */
  264. } PL_extension;
  265.  
  266. extern PL_extension PL_extensions[];    /* see pl-extend.c */
  267.  
  268. #endif /* PL_INCLUDED */
  269. /* DO NOT WRITE BELOW THIS ENDIF */
  270.