Main Page | Class List | Directories | File List | Class Members | File Members

slang.h

Go to the documentation of this file.
00001 #ifndef DAVIS_SLANG_H_
00002 #define DAVIS_SLANG_H_
00003 /* -*- mode: C; mode: fold; -*- */
00004 /*
00005 Copyright (C) 2004, 2005, 2006 John E. Davis
00006 
00007 This file is part of the S-Lang Library.
00008 
00009 The S-Lang Library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License as
00011 published by the Free Software Foundation; either version 2 of the
00012 License, or (at your option) any later version.
00013 
00014 The S-Lang Library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00022 USA.  
00023 */
00024 
00025 #define SLANG_VERSION 20006
00026 #define SLANG_VERSION_STRING "2.0.6"
00027 /* #ifdef __DATE__ */
00028 /* # define SLANG_VERSION_STRING SLANG_VERSION_STRING0 " " __DATE__ */
00029 /* #else */
00030 /* # define SLANG_VERSION_STRING SLANG_VERSION_STRING0 */
00031 /* #endif */
00032 /*{{{ System Dependent Macros and Typedefs */
00033 
00034 #if defined(__WATCOMC__) && defined(DOS)
00035 # ifndef __MSDOS__
00036 #  define __MSDOS__
00037 # endif
00038 # ifndef  DOS386
00039 #  define  DOS386
00040 # endif
00041 # ifndef IBMPC_SYSTEM
00042 #  define IBMPC_SYSTEM
00043 # endif
00044 #endif /* __watcomc__ */
00045 
00046 #if defined(unix) || defined(__unix)
00047 # ifndef __unix__
00048 #  define __unix__ 1
00049 # endif
00050 #endif
00051 
00052 #if !defined(__GO32__)
00053 # ifdef __unix__
00054 #  define REAL_UNIX_SYSTEM
00055 # endif
00056 #endif
00057 
00058 /* Set of the various defines for pc systems.  This includes OS/2 */
00059 #ifdef __GO32__
00060 # ifndef __DJGPP__
00061 #  define __DJGPP__ 1
00062 # endif
00063 # ifndef IBMPC_SYSTEM
00064 #   define IBMPC_SYSTEM
00065 # endif
00066 #endif
00067 
00068 #ifdef __BORLANDC__
00069 # ifndef IBMPC_SYSTEM
00070 #  define IBMPC_SYSTEM
00071 # endif
00072 #endif
00073 
00074 #ifdef __MSDOS__
00075 # ifndef IBMPC_SYSTEM
00076 #   define IBMPC_SYSTEM
00077 # endif
00078 #endif
00079 
00080 #if defined(OS2) || defined(__os2__)
00081 # ifndef IBMPC_SYSTEM
00082 #   define IBMPC_SYSTEM
00083 # endif
00084 # ifndef __os2__
00085 #  define __os2__
00086 # endif
00087 #endif
00088 
00089 #if defined(__NT__) || defined(__MINGW32__) /* || defined(__CYGWIN32__) */
00090 # ifndef IBMPC_SYSTEM
00091 #  define IBMPC_SYSTEM
00092 # endif
00093 #endif
00094 
00095 #if defined(WIN32) || defined(__WIN32__)
00096 # ifndef IBMPC_SYSTEM
00097 #  define IBMPC_SYSTEM
00098 # endif
00099 # ifndef __WIN32__
00100 #  define __WIN32__
00101 # endif
00102 #endif
00103 
00104 #if defined(IBMPC_SYSTEM) || defined(VMS)
00105 # ifdef REAL_UNIX_SYSTEM
00106 #  undef REAL_UNIX_SYSTEM
00107 # endif
00108 #endif
00109 
00110 #ifdef __cplusplus
00111 extern "C" {
00112 #endif
00113 #if 0
00114 }
00115 #endif
00116 
00117 #include <stdio.h>
00118 #include <stdarg.h>
00119 #if defined(__STDC__) || defined(__BORLANDC__) || defined(__cplusplus)
00120 # include <stddef.h>                   /* for offsetof */
00121 #endif
00122 
00123 #ifdef SIZEOF_SHORT
00124 # define SLANG_SIZEOF_SHORT SIZEOF_SHORT
00125 #endif
00126 #ifdef SIZEOF_INT
00127 # define SLANG_SIZEOF_INT SIZEOF_INT
00128 #endif
00129 #ifdef SIZEOF_FLOAT
00130 # define SLANG_SIZEOF_FLOAT SIZEOF_FLOAT
00131 #endif
00132 #ifdef SIZEOF_DOUBLE
00133 # define SLANG_SIZEOF_DOUBLE SIZEOF_DOUBLE
00134 #endif
00135 
00136 #if !defined(SIZEOF_SHORT) || !defined(SIZEOF_INT) || !defined(SIZEOF_LONG) || !defined(SIZEOF_FLOAT) || !defined(SIZEOF_DOUBLE)
00137 # include <limits.h>
00138 # if !defined(SIZEOF_SHORT) && defined(SHRT_MAX)
00139 #  if SHRT_MAX == 32767
00140 #   define SLANG_SIZEOF_SHORT 2
00141 #  else
00142 #   if SHRT_MAX == 2147483647L
00143 #    define SLANG_SIZEOF_SHORT 4
00144 #   endif
00145 #  endif
00146 # endif
00147 # if !defined(SIZEOF_INT) && defined(INT_MAX)
00148 #  if INT_MAX == 32767
00149 #   define SLANG_SIZEOF_INT 2
00150 #  else
00151 #   if INT_MAX == 2147483647L
00152 #    define SLANG_SIZEOF_INT 4
00153 #   endif
00154 #  endif
00155 # endif
00156 # if !defined(SIZEOF_LONG) && defined(LONG_MAX)
00157 #  if LONG_MAX == 32767
00158 #   define SLANG_SIZEOF_LONG 2
00159 #  else
00160 #   if LONG_MAX == 2147483647L
00161 #    define SLANG_SIZEOF_LONG 4
00162 #   else
00163 #    define SLANG_SIZEOF_LONG 8
00164 #   endif
00165 #  endif
00166 # endif
00167 #endif
00168 
00169 #ifndef SLANG_SIZEOF_SHORT
00170 # define SLANG_SIZEOF_SHORT 2
00171 #endif
00172 #ifndef SLANG_SIZEOF_INT
00173 # define SLANG_SIZEOF_INT 4
00174 #endif
00175 #ifndef SLANG_SIZEOF_LONG
00176 # define SLANG_SIZEOF_LONG 4
00177 #endif
00178 #ifndef SLANG_SIZEOF_FLOAT
00179 # define SLANG_SIZEOF_FLOAT 4
00180 #endif
00181 #ifndef SLANG_SIZEOF_DOUBLE
00182 # define SLANG_SIZEOF_DOUBLE 8
00183 #endif
00184 
00185 /* ---------------------------- Generic Macros ----------------------------- */
00186 
00187 /*  __SC__ is defined for Symantec C++
00188    DOS386 is defined for -mx memory model, 32 bit DOS extender. */
00189 
00190 #if defined(__SC__) && !defined(DOS386)
00191 # include <dos.h>
00192 #endif
00193 
00194 #if defined(__BORLANDC__)
00195 # include <alloc.h>
00196 #endif
00197 
00198 #ifdef __GNUC__
00199 # define SLATTRIBUTE_(x) __attribute__ (x)
00200 #else
00201 # define SLATTRIBUTE_(x)
00202 #endif
00203 #define SLATTRIBUTE_PRINTF(a,b) SLATTRIBUTE_((format(printf,a,b)))
00204   
00205 #if defined (__cplusplus) || defined(__STDC__) || defined(IBMPC_SYSTEM)
00206 typedef void *VOID_STAR;
00207 #define SLCONST const
00208 #else
00209 typedef unsigned char *VOID_STAR;
00210 #define SLCONST
00211 #endif
00212 
00213 typedef int (*FVOID_STAR)(void);
00214 
00215 #if defined(__MSDOS__) && defined(__BORLANDC__)
00216 # define SLFREE(buf)  farfree((void far *)(buf))
00217 # define SLMALLOC(x) farmalloc((unsigned long) (x))
00218 # define SLREALLOC(buf, n) farrealloc((void far *) (buf), (unsigned long) (n))
00219 # define SLCALLOC(n, m) farcalloc((unsigned long) (n), (unsigned long) (m))
00220 #else
00221 # if defined(VMS) && !defined(__DECC)
00222 #  define SLFREE VAXC$FREE_OPT
00223 #  define SLMALLOC VAXC$MALLOC_OPT
00224 #  define SLREALLOC VAXC$REALLOC_OPT
00225 #  define SLCALLOC VAXC$CALLOC_OPT
00226 # else
00227 #  define SLFREE(x) free((char *)(x))
00228 #  define SLMALLOC malloc
00229 #  define SLREALLOC realloc
00230 #  define SLCALLOC calloc
00231 # endif
00232 #endif
00233 
00234 #if defined(__WIN32__) && SLANG_DLL
00235 # define SL_EXPORT __declspec(dllexport)
00236 # define SL_IMPORT __declspec(dllimport)
00237 #else
00238 # define SL_EXPORT
00239 # define SL_IMPORT
00240 #endif
00241 #ifdef SLANG_SOURCE_
00242 # define SL_EXTERN extern SL_EXPORT
00243 #else
00244 # define SL_EXTERN extern SL_IMPORT
00245 #endif
00246 
00247 SL_EXTERN char *SLdebug_malloc (unsigned long);
00248 SL_EXTERN char *SLdebug_calloc (unsigned long, unsigned long);
00249 SL_EXTERN char *SLdebug_realloc (char *, unsigned long);
00250 SL_EXTERN void SLdebug_free (char *);
00251 SL_EXTERN void SLmalloc_dump_statistics (void);
00252 SL_EXTERN char *SLstrcpy(register char *, register char *);
00253 SL_EXTERN int SLstrcmp(register char *, register char *);
00254 SL_EXTERN char *SLstrncpy(char *, register char *, register  int);
00255 
00256 SL_EXTERN void SLmemset (char *, char, int);
00257 SL_EXTERN char *SLmemchr (register char *, register char, register int);
00258 SL_EXTERN char *SLmemcpy (char *, char *, int);
00259 SL_EXTERN int SLmemcmp (char *, char *, int);
00260 
00261 /*}}}*/
00262 
00263 /* SLstrings */
00264 typedef char SLstr_Type;
00265 /* An SLstr_Type object must be treated as a constant and may only be freed
00266  * by the SLang_free_slstring function and nothing else.
00267  */
00268 SL_EXTERN SLstr_Type *SLang_create_nslstring (char *, unsigned int);
00269 SL_EXTERN SLstr_Type *SLang_create_slstring (char *);
00270 SL_EXTERN void SLang_free_slstring (SLstr_Type *);    /* handles NULL */
00271 SL_EXTERN int SLang_pop_slstring (SLstr_Type **);   /* free with SLang_free_slstring */
00272 SL_EXTERN SLstr_Type *SLang_concat_slstrings (SLstr_Type *a, SLstr_Type *b);
00273 
00274 SL_EXTERN void SLstring_dump_stats (void);
00275 
00276 
00277 /*{{{ UTF-8 and Wide Char support */
00278 
00279 #if SLANG_SIZEOF_INT == 4
00280 typedef unsigned int SLwchar_Type;
00281 # define SLANG_WCHAR_TYPE SLANG_UINT_TYPE
00282 #else
00283 typedef unsigned long SLwchar_Type;
00284 # define SLANG_WCHAR_TYPE SLANG_ULONG_TYPE
00285 #endif
00286 typedef unsigned char SLuchar_Type;
00287 
00288 /* Maximum multi-byte len for a unicode wchar */
00289 #define SLUTF8_MAX_MBLEN        6
00290 
00291 /* If argument is 1, force UTF-8 mode on.  If argument is 0, force mode off.
00292  * If -1, determine mode from the locale.
00293  * Returns 1 if enabled, 0 if not.
00294  */
00295 SL_EXTERN int SLutf8_enable (int);
00296 SL_EXTERN int SLutf8_is_utf8_mode (void);
00297 SL_EXTERN int SLtt_utf8_enable (int);
00298 SL_EXTERN int SLtt_is_utf8_mode (void);
00299 SL_EXTERN int SLsmg_utf8_enable (int);
00300 SL_EXTERN int SLsmg_is_utf8_mode (void);
00301 SL_EXTERN int SLinterp_utf8_enable (int);
00302 SL_EXTERN int SLinterp_is_utf8_mode (void);
00303   
00304 SL_EXTERN SLwchar_Type SLwchar_toupper (SLwchar_Type);
00305 SL_EXTERN SLwchar_Type SLwchar_tolower (SLwchar_Type);
00306 
00307 SL_EXTERN int SLwchar_wcwidth (SLwchar_Type);
00308 SL_EXTERN int SLwchar_isalnum (SLwchar_Type);
00309 SL_EXTERN int SLwchar_isalpha (SLwchar_Type);
00310 SL_EXTERN int SLwchar_isblank (SLwchar_Type);
00311 SL_EXTERN int SLwchar_iscntrl (SLwchar_Type);
00312 SL_EXTERN int SLwchar_isdigit (SLwchar_Type);
00313 SL_EXTERN int SLwchar_isgraph (SLwchar_Type);
00314 SL_EXTERN int SLwchar_islower (SLwchar_Type);
00315 SL_EXTERN int SLwchar_isprint (SLwchar_Type);
00316 SL_EXTERN int SLwchar_ispunct (SLwchar_Type);
00317 SL_EXTERN int SLwchar_isspace (SLwchar_Type);
00318 SL_EXTERN int SLwchar_isupper (SLwchar_Type);
00319 SL_EXTERN int SLwchar_isxdigit (SLwchar_Type);
00320 
00321 SL_EXTERN SLuchar_Type *SLutf8_skip_char (SLuchar_Type *u, SLuchar_Type *umax);
00322 SL_EXTERN SLuchar_Type *SLutf8_bskip_char (SLuchar_Type *umin, SLuchar_Type *u);
00323 
00324 /* The SLutf8_strup/lo functions return slstrings -- free with SLang_free_slstring */
00325 SL_EXTERN SLuchar_Type *SLutf8_strup (SLuchar_Type *u, SLuchar_Type *umax);
00326 SL_EXTERN SLuchar_Type *SLutf8_strlo (SLuchar_Type *u, SLuchar_Type *umax);
00327 
00328 SL_EXTERN SLuchar_Type *SLutf8_skip_chars (SLuchar_Type *u, SLuchar_Type *umax,
00329                                         unsigned int num, unsigned int *dnum,
00330                                         int ignore_combining );
00331 SL_EXTERN SLuchar_Type *SLutf8_bskip_chars (SLuchar_Type *umin, SLuchar_Type *u,
00332                                           unsigned int num, unsigned int *dnum,
00333                                          int ignore_combining);
00334 
00335 SL_EXTERN SLstr_Type *SLutf8_subst_wchar (SLuchar_Type *u, SLuchar_Type *umax,
00336                                        SLwchar_Type wch, unsigned int pos,
00337                                        int ignore_combining);
00338 
00339 
00340 SL_EXTERN unsigned int SLutf8_strlen (SLuchar_Type *s, int ignore_combining);
00341 SL_EXTERN SLuchar_Type *SLutf8_decode (SLuchar_Type *u, SLuchar_Type *umax,
00342                                      SLwchar_Type *w, unsigned int *nconsumedp);
00343 SL_EXTERN SLuchar_Type *SLutf8_encode (SLwchar_Type w, SLuchar_Type *u, unsigned int ulen);
00344 
00345 SL_EXTERN int SLutf8_compare (SLuchar_Type *a, SLuchar_Type *amax, 
00346                            SLuchar_Type *b, SLuchar_Type *bmax,
00347                            unsigned int nchars, int case_sensitive);
00348 
00349 /* In these functions, buf is assumed to contain at least SLUTF8_MAX_MBLEN+1 
00350  * bytes 
00351  */
00352 SL_EXTERN SLuchar_Type *SLutf8_extract_utf8_char (SLuchar_Type *u, SLuchar_Type *umax, SLuchar_Type *buf);
00353 SL_EXTERN SLuchar_Type *SLutf8_encode_null_terminate (SLwchar_Type w, SLuchar_Type *buf);
00354 
00355 
00356 typedef struct SLwchar_Lut_Type SLwchar_Lut_Type;
00357 SL_EXTERN SLwchar_Lut_Type *SLwchar_create_lut (unsigned int num_entries);
00358 SL_EXTERN int SLwchar_add_range_to_lut (SLwchar_Lut_Type *r, SLwchar_Type a, SLwchar_Type b);
00359 SL_EXTERN SLuchar_Type *SLwchar_skip_range (SLwchar_Lut_Type *r, SLuchar_Type *p,
00360                                          SLuchar_Type *pmax, int ignore_combining,
00361                                          int invert);
00362 SL_EXTERN SLwchar_Lut_Type *SLwchar_strtolut (SLuchar_Type *u, 
00363                                            int allow_range, int allow_charclass);
00364 SL_EXTERN void SLwchar_free_lut (SLwchar_Lut_Type *r);
00365 SL_EXTERN SLuchar_Type *SLwchar_bskip_range (SLwchar_Lut_Type *r, SLuchar_Type *pmin,
00366                                           SLuchar_Type *p,
00367                                           int ignore_combining,
00368                                           int invert);
00369 SL_EXTERN int SLwchar_in_lut (SLwchar_Lut_Type *r, SLwchar_Type wch);
00370 
00371 
00372 typedef struct SLwchar_Map_Type SLwchar_Map_Type;
00373 SL_EXTERN void SLwchar_free_char_map (SLwchar_Map_Type *map);
00374 SL_EXTERN SLwchar_Map_Type *SLwchar_allocate_char_map (SLuchar_Type *from, SLuchar_Type *to);
00375 SL_EXTERN int SLwchar_apply_char_map (SLwchar_Map_Type *map, SLwchar_Type *input, SLwchar_Type *output, unsigned int num);
00376 
00377 /* This function returns a malloced string */
00378 SLuchar_Type *SLuchar_apply_char_map (SLwchar_Map_Type *map, SLuchar_Type *str);
00379 
00380 
00381 /*}}}*/
00382 
00383 /*{{{ Interpreter Typedefs */
00384 
00385 typedef unsigned int SLtype;
00386 /* typedef unsigned short SLtype; */
00387 
00388 typedef struct _pSLang_Name_Type
00389 {
00390    char *name;
00391    struct _pSLang_Name_Type *next;
00392    unsigned char name_type;
00393    /* These values here map directly to byte codes.  See _slang.h.
00394     */
00395 #define SLANG_LVARIABLE         0x01
00396 #define SLANG_GVARIABLE         0x02
00397 #define SLANG_IVARIABLE         0x03           /* intrinsic variables */
00398    /* Note!!! For Macro MAKE_VARIABLE below to work, SLANG_IVARIABLE Must
00399     be 1 less than SLANG_RVARIABLE!!! */
00400 #define SLANG_RVARIABLE         0x04           /* read only variable */
00401 #define SLANG_INTRINSIC         0x05
00402 #define SLANG_FUNCTION          0x06
00403 #define SLANG_MATH_UNARY        0x07
00404 #define SLANG_APP_UNARY         0x08
00405 #define SLANG_ARITH_UNARY       0x09   /* private */
00406 #define SLANG_ARITH_BINARY      0x0A
00407 #define SLANG_ICONSTANT         0x0B
00408 #define SLANG_DCONSTANT         0x0C
00409 #define SLANG_FCONSTANT         0x0D
00410 #define SLANG_LLCONSTANT        0x0E
00411 #define SLANG_PVARIABLE         0x0F   /* private */
00412 #define SLANG_PFUNCTION         0x10   /* private */
00413 #define SLANG_HCONSTANT         0x11
00414 #define SLANG_LCONSTANT         0x12
00415    /* Rest of fields depend on name type */
00416 }
00417 SLang_Name_Type;
00418 
00419 typedef struct
00420 {
00421    char *name;
00422    struct _pSLang_Name_Type *next;      /* this is for the hash table */
00423    char name_type;
00424 
00425    FVOID_STAR i_fun;                   /* address of object */
00426 
00427    /* Do not change this without modifying slang.c:execute_intrinsic_fun */
00428 #define SLANG_MAX_INTRIN_ARGS   7
00429    SLtype arg_types [SLANG_MAX_INTRIN_ARGS];
00430    unsigned char num_args;
00431    SLtype return_type;
00432 }
00433 SLang_Intrin_Fun_Type;
00434 
00435 typedef struct
00436 {
00437    char *name;
00438    SLang_Name_Type *next;
00439    char name_type;
00440 
00441    VOID_STAR addr;
00442    SLtype type;
00443 }
00444 SLang_Intrin_Var_Type;
00445 
00446 typedef struct
00447 {
00448    char *name;
00449    SLang_Name_Type *next;
00450    char name_type;
00451 
00452    int unary_op;
00453 }
00454 SLang_App_Unary_Type;
00455 
00456 typedef struct
00457 {
00458    char *name;
00459    SLang_Name_Type *next;
00460    char name_type;
00461 
00462    int unary_op;
00463 }
00464 SLang_Math_Unary_Type;
00465 
00466 typedef struct
00467 {
00468    char *name;
00469    SLang_Name_Type *next;
00470    char name_type;
00471 
00472    SLtype data_type;
00473    short value;
00474 }
00475 SLang_HConstant_Type;
00476 
00477 typedef struct
00478 {
00479    char *name;
00480    SLang_Name_Type *next;
00481    char name_type;
00482 
00483    SLtype data_type;
00484    int value;
00485 }
00486 SLang_IConstant_Type;
00487 
00488 typedef struct
00489 {
00490    char *name;
00491    SLang_Name_Type *next;
00492    char name_type;
00493 
00494    SLtype data_type;
00495    long value;
00496 }
00497 SLang_LConstant_Type;
00498 
00499 #ifdef HAVE_LONG_LONG
00500 typedef struct
00501 {
00502    char *name;
00503    SLang_Name_Type *next;
00504    char name_type;
00505 
00506    long long ll;
00507 }
00508 SLang_LLConstant_Type;
00509 #endif
00510 
00511 typedef struct
00512 {
00513    char *name;
00514    SLang_Name_Type *next;
00515    char name_type;
00516    double d;
00517 }
00518 SLang_DConstant_Type;
00519 
00520 typedef struct
00521 {
00522    char *name;
00523    SLang_Name_Type *next;
00524    char name_type;
00525    float f;
00526 }
00527 SLang_FConstant_Type;
00528 
00529 typedef struct
00530 {
00531    char *field_name;                   /* gets replaced by slstring at run-time */
00532    unsigned int offset;
00533    SLtype type;
00534    unsigned char read_only;
00535 }
00536 SLang_IStruct_Field_Type;
00537 
00538 typedef SLCONST struct _pSLang_CStruct_Field_Type   /* a g++ bug?? yuk*/
00539 {
00540    char *field_name;
00541    unsigned int offset;
00542    SLtype type;
00543    unsigned char read_only;
00544 }
00545 SLang_CStruct_Field_Type;
00546 
00547 SL_EXTERN int SLadd_intrin_fun_table (SLang_Intrin_Fun_Type *, char *);
00548 SL_EXTERN int SLadd_intrin_var_table (SLang_Intrin_Var_Type *, char *);
00549 SL_EXTERN int SLadd_app_unary_table (SLang_App_Unary_Type *, char *);
00550 SL_EXTERN int SLadd_math_unary_table (SLang_Math_Unary_Type *, char *);
00551 SL_EXTERN int SLadd_iconstant_table (SLang_IConstant_Type *, char *);
00552 SL_EXTERN int SLadd_dconstant_table (SLang_DConstant_Type *, char *);
00553 SL_EXTERN int SLadd_fconstant_table (SLang_FConstant_Type *, char *);
00554 #if HAVE_LONG_LONG
00555 SL_EXTERN int SLadd_llconstant_table (SLang_LLConstant_Type *, char *);
00556 #endif
00557 SL_EXTERN int SLadd_istruct_table (SLang_IStruct_Field_Type *, VOID_STAR, char *);
00558 
00559 
00560 typedef struct _pSLang_NameSpace_Type SLang_NameSpace_Type;
00561 
00562 SL_EXTERN int SLns_add_intrin_fun_table (SLang_NameSpace_Type *, SLang_Intrin_Fun_Type *, char *);
00563 SL_EXTERN int SLns_add_intrin_var_table (SLang_NameSpace_Type *, SLang_Intrin_Var_Type *, char *);
00564 SL_EXTERN int SLns_add_app_unary_table (SLang_NameSpace_Type *, SLang_App_Unary_Type *, char *);
00565 SL_EXTERN int SLns_add_math_unary_table (SLang_NameSpace_Type *, SLang_Math_Unary_Type *, char *);
00566 SL_EXTERN int SLns_add_hconstant_table (SLang_NameSpace_Type *, SLang_HConstant_Type *, char *);
00567 SL_EXTERN int SLns_add_iconstant_table (SLang_NameSpace_Type *, SLang_IConstant_Type *, char *);
00568 SL_EXTERN int SLns_add_lconstant_table (SLang_NameSpace_Type *, SLang_LConstant_Type *, char *);
00569 SL_EXTERN int SLns_add_fconstant_table (SLang_NameSpace_Type *, SLang_FConstant_Type *, char *);
00570 SL_EXTERN int SLns_add_dconstant_table (SLang_NameSpace_Type *, SLang_DConstant_Type *, char *);
00571 #ifdef HAVE_LONG_LONG
00572 SL_EXTERN int SLns_add_llconstant_table (SLang_NameSpace_Type *, SLang_LLConstant_Type *, char *);
00573 #endif
00574 SL_EXTERN int SLns_add_istruct_table (SLang_NameSpace_Type *, SLang_IStruct_Field_Type *, VOID_STAR, char *);
00575 
00576 SL_EXTERN int SLns_add_hconstant (SLang_NameSpace_Type *, char *, SLtype, short);
00577 SL_EXTERN int SLns_add_iconstant (SLang_NameSpace_Type *, char *, SLtype, int);
00578 SL_EXTERN int SLns_add_lconstant (SLang_NameSpace_Type *, char *, SLtype, long);
00579 SL_EXTERN int SLns_add_fconstant (SLang_NameSpace_Type *, char *, float);
00580 SL_EXTERN int SLns_add_dconstant (SLang_NameSpace_Type *, char *, double);
00581 #ifdef HAVE_LONG_LONG
00582 SL_EXTERN int SLns_add_llconstant (SLang_NameSpace_Type *, char *, long long);
00583 #endif
00584 SL_EXTERN SLang_NameSpace_Type *SLns_create_namespace (char *);
00585 SL_EXTERN void SLns_delete_namespace (SLang_NameSpace_Type *);
00586 
00587 SL_EXTERN int SLns_load_file (char *, char *);
00588 SL_EXTERN int SLns_load_string (char *, char *);
00589 SL_EXTERN int (*SLns_Load_File_Hook) (char *, char *);
00590 SL_EXTERN int SLang_load_file_verbose (int);    
00591 /* if non-zero, display file loading messages */
00592 
00593 typedef struct SLang_Load_Type
00594 {
00595    int type;
00596 
00597    VOID_STAR client_data;
00598    /* Pointer to data that client needs for loading */
00599 
00600    int auto_declare_globals;
00601    /* if non-zero, undefined global variables are declared as static */
00602 
00603    char *(*read)(struct SLang_Load_Type *);
00604    /* function to call to read next line from obj. */
00605 
00606    unsigned int line_num;
00607    /* Number of lines read, used for error reporting */
00608 
00609    int parse_level;
00610    /* 0 if at top level of parsing */
00611 
00612    char *name;
00613    /* Name of this object, e.g., filename.  This name should be unique because
00614     * it alone determines the name space for static objects associated with
00615     * the compilable unit.
00616     */
00617 
00618    char *namespace_name;
00619    unsigned long reserved[3];
00620    /* For future expansion */
00621 } SLang_Load_Type;
00622 
00623 SL_EXTERN SLang_Load_Type *SLallocate_load_type (char *);
00624 SL_EXTERN void SLdeallocate_load_type (SLang_Load_Type *);
00625 SL_EXTERN SLang_Load_Type *SLns_allocate_load_type (char *, char *);
00626   
00627 /* Returns SLang_Error upon failure */
00628 SL_EXTERN int SLang_load_object (SLang_Load_Type *);
00629 SL_EXTERN int (*SLang_Load_File_Hook)(char *);
00630 SL_EXTERN int (*SLang_Auto_Declare_Var_Hook) (char *);
00631 
00632 SL_EXTERN int SLang_generate_debug_info (int);
00633 
00634 
00635 #if defined(ultrix) && !defined(__GNUC__)
00636 # ifndef NO_PROTOTYPES
00637 #  define NO_PROTOTYPES
00638 # endif
00639 #endif
00640 
00641 #ifndef NO_PROTOTYPES
00642 # define _PROTO(x) x
00643 #else
00644 # define _PROTO(x) ()
00645 #endif
00646 
00647 typedef struct _pSLang_Struct_Type SLang_Struct_Type;
00648 SL_EXTERN void SLang_free_struct (SLang_Struct_Type *);
00649 SL_EXTERN int SLang_push_struct (SLang_Struct_Type *);
00650 SL_EXTERN int SLang_pop_struct (SLang_Struct_Type **);
00651 
00652 typedef struct _pSLang_Foreach_Context_Type SLang_Foreach_Context_Type;
00653 
00654 typedef struct _pSLang_Class_Type SLang_Class_Type;
00655 
00656 /* These are the low-level functions for building push/pop methods.  They
00657  * know nothing about memory management.  For SLANG_CLASS_TYPE_MMT, use the
00658  * MMT push/pop functions instead.
00659  */
00660 SL_EXTERN int SLclass_push_double_obj (SLtype, double);
00661 SL_EXTERN int SLclass_push_float_obj (SLtype, float);
00662 SL_EXTERN int SLclass_push_long_obj (SLtype, long);
00663 SL_EXTERN int SLclass_push_int_obj (SLtype, int);
00664 SL_EXTERN int SLclass_push_short_obj (SLtype, short);
00665 SL_EXTERN int SLclass_push_char_obj (SLtype, char);
00666 SL_EXTERN int SLclass_push_ptr_obj (SLtype, VOID_STAR);
00667 SL_EXTERN int SLclass_pop_double_obj (SLtype, double *);
00668 SL_EXTERN int SLclass_pop_float_obj (SLtype, float *);
00669 SL_EXTERN int SLclass_pop_long_obj (SLtype, long *);
00670 SL_EXTERN int SLclass_pop_int_obj (SLtype, int *);
00671 SL_EXTERN int SLclass_pop_short_obj (SLtype, short *);
00672 SL_EXTERN int SLclass_pop_char_obj (SLtype, char *);
00673 SL_EXTERN int SLclass_pop_ptr_obj (SLtype, VOID_STAR *);
00674 
00675 #ifdef HAVE_LONG_LONG
00676 SL_EXTERN int SLang_pop_long_long (long long *);
00677 SL_EXTERN int SLang_push_long_long (long long);
00678 SL_EXTERN int SLang_pop_ulong_long (unsigned long long *);
00679 SL_EXTERN int SLang_push_ulong_long (unsigned long long);
00680 SL_EXTERN int SLclass_pop_llong_obj (SLtype, long long *);
00681 SL_EXTERN int SLclass_push_llong_obj (SLtype, long long);
00682 #endif
00683 
00684 SL_EXTERN SLang_Class_Type *SLclass_allocate_class (char *);
00685 SL_EXTERN int SLclass_get_class_id (SLang_Class_Type *cl);
00686 SL_EXTERN int SLclass_create_synonym (char *, SLtype);
00687 SL_EXTERN int SLclass_is_class_defined (SLtype);
00688 SL_EXTERN int SLclass_dup_object (SLtype type, VOID_STAR from, VOID_STAR to);
00689 
00690 typedef int SLclass_Type;
00691 #define SLANG_CLASS_TYPE_MMT            0
00692 #define SLANG_CLASS_TYPE_SCALAR         1
00693 #define SLANG_CLASS_TYPE_VECTOR         2
00694 #define SLANG_CLASS_TYPE_PTR            3
00695 SL_EXTERN int SLclass_register_class (SLang_Class_Type *, SLtype, unsigned int, SLclass_Type);
00696 
00697 SL_EXTERN int SLclass_set_string_function (SLang_Class_Type *, char *(*)(SLtype, VOID_STAR));
00698 SL_EXTERN int SLclass_set_destroy_function (SLang_Class_Type *, void (*)(SLtype, VOID_STAR));
00699 SL_EXTERN int SLclass_set_push_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
00700 SL_EXTERN int SLclass_set_apush_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
00701 SL_EXTERN int SLclass_set_pop_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
00702 
00703 SL_EXTERN int SLclass_set_aget_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
00704 SL_EXTERN int SLclass_set_aput_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
00705 SL_EXTERN int SLclass_set_anew_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
00706 
00707 SL_EXTERN int SLclass_set_sget_function (SLang_Class_Type *, int (*)(SLtype, char *));
00708 SL_EXTERN int SLclass_set_sput_function (SLang_Class_Type *, int (*)(SLtype, char *));
00709 
00710 SL_EXTERN int SLclass_set_acopy_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR, VOID_STAR));
00711 SL_EXTERN int SLclass_set_deref_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
00712 SL_EXTERN int SLclass_set_eqs_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR, SLtype, VOID_STAR));
00713 
00714 SL_EXTERN int SLclass_set_length_function (SLang_Class_Type *, int(*)(SLtype, VOID_STAR, unsigned int *));
00715 
00716 SL_EXTERN int SLclass_set_is_container (SLang_Class_Type *, int);
00717 SL_EXTERN int SLclass_set_foreach_functions (
00718   SLang_Class_Type *,
00719   SLang_Foreach_Context_Type *(*)(SLtype, unsigned int),   /* open method */
00720   int (*)(SLtype, SLang_Foreach_Context_Type *),   /* foreach method */
00721   void (*)(SLtype, SLang_Foreach_Context_Type *));/* close method */
00722 
00723    
00724 /* Typecast object on the stack to type p1.  p2 and p3 should be set to 1 */
00725 SL_EXTERN int SLclass_typecast (SLtype, int, int);
00726 
00727 #define SLMATH_SIN      1
00728 #define SLMATH_COS      2
00729 #define SLMATH_TAN      3
00730 #define SLMATH_ATAN     4
00731 #define SLMATH_ASIN     5
00732 #define SLMATH_ACOS     6
00733 #define SLMATH_EXP      7
00734 #define SLMATH_LOG      8
00735 #define SLMATH_SQRT     9
00736 #define SLMATH_LOG10    10
00737 #define SLMATH_REAL     11
00738 #define SLMATH_IMAG     12
00739 #define SLMATH_SINH     13
00740 #define SLMATH_COSH     14
00741 #define SLMATH_TANH     15
00742 #define SLMATH_ATANH    16
00743 #define SLMATH_ASINH    17
00744 #define SLMATH_ACOSH    18
00745 #define SLMATH_TODOUBLE 19
00746 #define SLMATH_CONJ     20
00747 #define SLMATH_ISINF    21
00748 #define SLMATH_ISNAN    22
00749 #define SLMATH_FLOOR    23
00750 #define SLMATH_CEIL     24
00751 #define SLMATH_ROUND    25
00752 
00753 SL_EXTERN int SLclass_add_unary_op (SLtype,
00754                                  int (*) (int,
00755                                           SLtype, VOID_STAR, unsigned int,
00756                                           VOID_STAR),
00757                                  int (*) (int, SLtype, SLtype *));
00758 
00759 SL_EXTERN int
00760 SLclass_add_app_unary_op (SLtype,
00761                           int (*) (int,
00762                                    SLtype, VOID_STAR, unsigned int,
00763                                    VOID_STAR),
00764                           int (*) (int, SLtype, SLtype *));
00765 
00766 SL_EXTERN int
00767 SLclass_add_binary_op (SLtype, SLtype,
00768                        int (*) (int,
00769                                 SLtype, VOID_STAR, unsigned int,
00770                                 SLtype, VOID_STAR, unsigned int,
00771                                 VOID_STAR),
00772                        int (*) (int, SLtype, SLtype, SLtype *));
00773 
00774 SL_EXTERN int
00775 SLclass_add_math_op (SLtype,
00776                      int (*)(int,
00777                              SLtype, VOID_STAR, unsigned int,
00778                              VOID_STAR),
00779                      int (*)(int, SLtype, SLtype *));
00780 
00781 SL_EXTERN int
00782 SLclass_add_typecast (SLtype /* from */, SLtype /* to */,
00783                       int (*)_PROTO((SLtype, VOID_STAR, unsigned int,
00784                                      SLtype, VOID_STAR)),
00785                       int              /* allow implicit typecasts */
00786                       );
00787 
00788 SL_EXTERN char *SLclass_get_datatype_name (SLtype);
00789 
00790 SL_EXTERN double SLcomplex_abs (double *);
00791 SL_EXTERN double *SLcomplex_times (double *, double *, double *);
00792 SL_EXTERN double *SLcomplex_divide (double *, double *, double *);
00793 SL_EXTERN double *SLcomplex_sin (double *, double *);
00794 SL_EXTERN double *SLcomplex_cos (double *, double *);
00795 SL_EXTERN double *SLcomplex_tan (double *, double *);
00796 SL_EXTERN double *SLcomplex_asin (double *, double *);
00797 SL_EXTERN double *SLcomplex_acos (double *, double *);
00798 SL_EXTERN double *SLcomplex_atan (double *, double *);
00799 SL_EXTERN double *SLcomplex_exp (double *, double *);
00800 SL_EXTERN double *SLcomplex_log (double *, double *);
00801 SL_EXTERN double *SLcomplex_log10 (double *, double *);
00802 SL_EXTERN double *SLcomplex_sqrt (double *, double *);
00803 SL_EXTERN double *SLcomplex_sinh (double *, double *);
00804 SL_EXTERN double *SLcomplex_cosh (double *, double *);
00805 SL_EXTERN double *SLcomplex_tanh (double *, double *);
00806 SL_EXTERN double *SLcomplex_pow (double *, double *, double *);
00807 SL_EXTERN double SLmath_hypot (double x, double y);
00808 
00809 /* Not implemented yet */
00810 SL_EXTERN double *SLcomplex_asinh (double *, double *);
00811 SL_EXTERN double *SLcomplex_acosh (double *, double *);
00812 SL_EXTERN double *SLcomplex_atanh (double *, double *);
00813 
00814 #ifdef SLANG_SOURCE_
00815 typedef struct _pSLang_MMT_Type SLang_MMT_Type;
00816 #else
00817 typedef int SLang_MMT_Type;
00818 #endif
00819 
00820 SL_EXTERN void SLang_free_mmt (SLang_MMT_Type *);
00821 SL_EXTERN VOID_STAR SLang_object_from_mmt (SLang_MMT_Type *);
00822 SL_EXTERN SLang_MMT_Type *SLang_create_mmt (SLtype, VOID_STAR);
00823 SL_EXTERN int SLang_push_mmt (SLang_MMT_Type *);
00824 SL_EXTERN SLang_MMT_Type *SLang_pop_mmt (SLtype);
00825 SL_EXTERN void SLang_inc_mmt (SLang_MMT_Type *);
00826 
00827 /* Maximum number of dimensions of an array. */
00828 #define SLARRAY_MAX_DIMS                7
00829 typedef int SLindex_Type;
00830 typedef unsigned int SLuindex_Type;
00831 #define SLANG_ARRAY_INDEX_TYPE SLANG_INT_TYPE
00832 typedef struct _pSLang_Array_Type
00833 {
00834    SLtype data_type;
00835    unsigned int sizeof_type;
00836    VOID_STAR data;
00837    SLuindex_Type num_elements;
00838    unsigned int num_dims;
00839