Back to index

texmacs  1.0.7.15
scheme.h
Go to the documentation of this file.
00001 /* SCHEME.H */
00002 
00003 #ifndef _SCHEME_H
00004 #define _SCHEME_H
00005 
00006 #include <stdio.h>
00007 
00008 #ifdef __cplusplus
00009 extern "C" {
00010 #endif
00011 
00012 /*
00013  * Default values for #define'd symbols
00014  */
00015 #ifndef STANDALONE       /* If used as standalone interpreter */
00016 # define STANDALONE 1
00017 #endif
00018 
00019 #ifndef _MSC_VER
00020 # define USE_STRCASECMP 1
00021 # ifndef USE_STRLWR
00022 #   define USE_STRLWR 1
00023 # endif
00024 # define SCHEME_EXPORT
00025 #else
00026 # define USE_STRCASECMP 0
00027 # define USE_STRLWR 0
00028 # ifdef _SCHEME_SOURCE
00029 #  define SCHEME_EXPORT __declspec(dllexport)
00030 # else
00031 #  define SCHEME_EXPORT __declspec(dllimport)
00032 # endif
00033 #endif
00034 
00035 #if USE_NO_FEATURES
00036 # define USE_MATH 0
00037 # define USE_CHAR_CLASSIFIERS 0
00038 # define USE_ASCII_NAMES 0
00039 # define USE_STRING_PORTS 0
00040 # define USE_ERROR_HOOK 0
00041 # define USE_TRACING 0
00042 # define USE_COLON_HOOK 0
00043 # define USE_DL 0
00044 # define USE_PLIST 0
00045 #endif
00046 
00047 /*
00048  * Leave it defined if you want continuations, and also for the Sharp Zaurus.
00049  * Undefine it if you only care about faster speed and not strict Scheme compatibility.
00050  */
00051 #define USE_SCHEME_STACK
00052 
00053 #if USE_DL
00054 # define USE_INTERFACE 1
00055 #endif
00056 
00057 
00058 #ifndef USE_MATH         /* If math support is needed */
00059 # define USE_MATH 1
00060 #endif
00061 
00062 #ifndef USE_CHAR_CLASSIFIERS  /* If char classifiers are needed */
00063 # define USE_CHAR_CLASSIFIERS 1
00064 #endif
00065 
00066 #ifndef USE_ASCII_NAMES  /* If extended escaped characters are needed */
00067 # define USE_ASCII_NAMES 1
00068 #endif
00069 
00070 #ifndef USE_STRING_PORTS      /* Enable string ports */
00071 # define USE_STRING_PORTS 1
00072 #endif
00073 
00074 #ifndef USE_TRACING
00075 # define USE_TRACING 1
00076 #endif
00077 
00078 #ifndef USE_PLIST
00079 # define USE_PLIST 0
00080 #endif
00081 
00082 /* To force system errors through user-defined error handling (see *error-hook*) */
00083 #ifndef USE_ERROR_HOOK
00084 # define USE_ERROR_HOOK 1
00085 #endif
00086 
00087 #ifndef USE_COLON_HOOK   /* Enable qualified qualifier */
00088 # define USE_COLON_HOOK 1
00089 #endif
00090 
00091 #ifndef USE_STRCASECMP   /* stricmp for Unix */
00092 # define USE_STRCASECMP 0
00093 #endif
00094 
00095 #ifndef USE_STRLWR
00096 # define USE_STRLWR 1
00097 #endif
00098 
00099 #ifndef STDIO_ADDS_CR    /* Define if DOS/Windows */
00100 # define STDIO_ADDS_CR 0
00101 #endif
00102 
00103 #ifndef INLINE
00104 # define INLINE
00105 #endif
00106 
00107 #ifndef USE_INTERFACE
00108 # define USE_INTERFACE 0
00109 #endif
00110 
00111 #ifndef SHOW_ERROR_LINE   /* Show error line in file */
00112 # define SHOW_ERROR_LINE 1
00113 #endif
00114 
00115 typedef struct scheme scheme;
00116 typedef struct cell *cell_ptr;
00117 
00118 typedef void * (*func_alloc)(size_t);
00119 typedef void (*func_dealloc)(void *);
00120 
00121 /* num, for generic arithmetic */
00122 typedef struct num {
00123      char is_fixnum;
00124      union {
00125           long ivalue;
00126           double rvalue;
00127      } value;
00128 } num;
00129 
00130 SCHEME_EXPORT scheme *scheme_init_new();
00131 SCHEME_EXPORT scheme *scheme_init_new_custom_alloc(func_alloc malloc, func_dealloc free);
00132 SCHEME_EXPORT int scheme_init(scheme *sc);
00133 SCHEME_EXPORT int scheme_init_custom_alloc(scheme *sc, func_alloc, func_dealloc);
00134 SCHEME_EXPORT void scheme_deinit(scheme *sc);
00135 void scheme_set_input_port_file(scheme *sc, FILE *fin);
00136 void scheme_set_input_port_string(scheme *sc, char *start, char *past_the_end);
00137 SCHEME_EXPORT void scheme_set_output_port_file(scheme *sc, FILE *fin);
00138 void scheme_set_output_port_string(scheme *sc, char *start, char *past_the_end);
00139 SCHEME_EXPORT void scheme_load_file(scheme *sc, FILE *fin);
00140 SCHEME_EXPORT void scheme_load_named_file(scheme *sc, FILE *fin, const char *filename);
00141 SCHEME_EXPORT void scheme_load_string(scheme *sc, const char *cmd);
00142 SCHEME_EXPORT cell_ptr scheme_apply0(scheme *sc, const char *procname);
00143 SCHEME_EXPORT cell_ptr scheme_call(scheme *sc, cell_ptr func, cell_ptr args);
00144 SCHEME_EXPORT cell_ptr scheme_eval(scheme *sc, cell_ptr obj);
00145 void scheme_set_external_data(scheme *sc, void *p);
00146 SCHEME_EXPORT void scheme_define(scheme *sc, cell_ptr env, cell_ptr symbol, cell_ptr value);
00147 
00148 typedef cell_ptr (*foreign_func)(scheme *, cell_ptr);
00149 
00150 cell_ptr _cons(scheme *sc, cell_ptr a, cell_ptr b, int immutable);
00151 cell_ptr mk_integer(scheme *sc, long num);
00152 cell_ptr mk_real(scheme *sc, double num);
00153 cell_ptr mk_symbol(scheme *sc, const char *name);
00154 cell_ptr gensym(scheme *sc);
00155 cell_ptr mk_string(scheme *sc, const char *str);
00156 cell_ptr mk_counted_string(scheme *sc, const char *str, int len);
00157 cell_ptr mk_empty_string(scheme *sc, int len, char fill);
00158 cell_ptr mk_character(scheme *sc, int c);
00159 cell_ptr mk_foreign_func(scheme *sc, foreign_func f);
00160 cell_ptr mk_blackbox(scheme *sc, void* b);
00161 void putstr(scheme *sc, const char *s);
00162 int list_length(scheme *sc, cell_ptr a);
00163 int eqv(cell_ptr a, cell_ptr b);
00164 
00165 void finalize_blackbox(void *p);
00166        
00167 #if USE_INTERFACE
00168 struct scheme_interface {
00169   void (*scheme_define)(scheme *sc, cell_ptr env, cell_ptr symbol, cell_ptr value);
00170   cell_ptr (*cons)(scheme *sc, cell_ptr a, cell_ptr b);
00171   cell_ptr (*immutable_cons)(scheme *sc, cell_ptr a, cell_ptr b);
00172   cell_ptr (*reserve_cells)(scheme *sc, int n);
00173   cell_ptr (*mk_integer)(scheme *sc, long num);
00174   cell_ptr (*mk_real)(scheme *sc, double num);
00175   cell_ptr (*mk_symbol)(scheme *sc, const char *name);
00176   cell_ptr (*gensym)(scheme *sc);
00177   cell_ptr (*mk_string)(scheme *sc, const char *str);
00178   cell_ptr (*mk_counted_string)(scheme *sc, const char *str, int len);
00179   cell_ptr (*mk_character)(scheme *sc, int c);
00180   cell_ptr (*mk_vector)(scheme *sc, int len);
00181   cell_ptr (*mk_foreign_func)(scheme *sc, foreign_func f);
00182   void (*putstr)(scheme *sc, const char *s);
00183   void (*putcharacter)(scheme *sc, int c);
00184 
00185   int (*is_string)(cell_ptr p);
00186   char *(*string_value)(cell_ptr p);
00187   int (*is_number)(cell_ptr p);
00188   num (*nvalue)(cell_ptr p);
00189   long (*ivalue)(cell_ptr p);
00190   double (*rvalue)(cell_ptr p);
00191   int (*is_integer)(cell_ptr p);
00192   int (*is_real)(cell_ptr p);
00193   int (*is_character)(cell_ptr p);
00194   long (*charvalue)(cell_ptr p);
00195   int (*is_list)(scheme *sc, cell_ptr p);
00196   int (*is_vector)(cell_ptr p);
00197   int (*list_length)(scheme *sc, cell_ptr vec);
00198   long (*vector_length)(cell_ptr vec);
00199   void (*fill_vector)(cell_ptr vec, cell_ptr elem);
00200   cell_ptr (*vector_elem)(cell_ptr vec, int ielem);
00201   cell_ptr (*set_vector_elem)(cell_ptr vec, int ielem, cell_ptr newel);
00202   int (*is_port)(cell_ptr p);
00203 
00204   int (*is_pair)(cell_ptr p);
00205   cell_ptr (*pair_car)(cell_ptr p);
00206   cell_ptr (*pair_cdr)(cell_ptr p);
00207   cell_ptr (*set_car)(cell_ptr p, cell_ptr q);
00208   cell_ptr (*set_cdr)(cell_ptr p, cell_ptr q);
00209 
00210   int (*is_symbol)(cell_ptr p);
00211   char *(*symname)(cell_ptr p);
00212 
00213   int (*is_syntax)(cell_ptr p);
00214   int (*is_proc)(cell_ptr p);
00215   int (*is_foreign)(cell_ptr p);
00216   char *(*syntaxname)(cell_ptr p);
00217   int (*is_closure)(cell_ptr p);
00218   int (*is_macro)(cell_ptr p);
00219   cell_ptr (*closure_code)(cell_ptr p);
00220   cell_ptr (*closure_env)(cell_ptr p);
00221 
00222   int (*is_continuation)(cell_ptr p);
00223   int (*is_promise)(cell_ptr p);
00224   int (*is_environment)(cell_ptr p);
00225   int (*is_immutable)(cell_ptr p);
00226   void (*setimmutable)(cell_ptr p);
00227   void (*load_file)(scheme *sc, FILE *fin);
00228   void (*load_string)(scheme *sc, const char *input);
00229 };
00230 #endif
00231 
00232 #if !STANDALONE
00233 typedef struct scheme_registerable
00234 {
00235   foreign_func  f;
00236   char *        name;
00237 }
00238 scheme_registerable;
00239 
00240 void scheme_register_foreign_func_list(scheme * sc,
00241                                        scheme_registerable * list,
00242                                        int n);
00243 
00244 #endif /* !STANDALONE */
00245 
00246 #ifdef __cplusplus
00247 }
00248 #endif
00249 
00250 #endif
00251 
00252 
00253 /*
00254 Local variables:
00255 c-file-style: "k&r"
00256 End:
00257 */