1\function{SLallocate_load_type}
2\synopsis{Allocate a SLang_Load_Type object}
3\usage{SLang_Load_Type *SLallocate_load_type (char *name)}
4\description
5  The \var{SLallocate_load_type} function allocates and initializes
6  space for a \var{SLang_Load_Type} object and returns it.  Upon
7  failure, the function returns \var{NULL}.  The parameter \var{name}
8  must uniquely identify the object.  For example, if the object
9  represents a file, then \var{name} could be the absolute path name
10  of the file.
11\seealso{SLdeallocate_load_type, SLang_load_object}
12\done
13
14\function{SLdeallocate_load_type}
15\synopsis{Free a SLang_Load_Type object}
16\usage{void SLdeallocate_load_type (SLang_Load_Type *slt)}
17\description
18  This function frees the memory associated with a
19  \var{SLang_Load_Type} object that was acquired from a call to the
20  \var{SLallocate_load_type} function.
21\seealso{SLallocate_load_type, SLang_load_object}
22\done
23
24\function{SLang_load_object}
25\synopsis{Load an object into the interpreter}
26\usage{int SLang_load_object (SLang_Load_Type *obj)}
27\description
28  The function \var{SLang_load_object} is a generic function that may
29  be used to loaded an object of type \var{SLang_Load_Type} into the
30  interpreter.  For example, the functions \var{SLang_load_file} and
31  \var{SLang_load_string} are wrappers around this function to load a
32  file and a string, respectively.
33\seealso{SLang_load_file, SLang_load_string, SLallocate_load_type}
34\done
35
36\function{SLclass_allocate_class}
37\synopsis{Allocate a class for a new data type}
38\usage{SLang_Class_Type *SLclass_allocate_class (char *name)}
39\description
40  The purpose of this function is to allocate and initialize space
41  that defines a new data type or class called \var{name}.  If
42  successful, a pointer to the class is returned, or upon failure the
43  function returns \var{NULL}.
44
45  This function does not automatically create the new data type.
46  Callback functions must first be associated with the data type via
47  functions such as \var{SLclass_set_push_function}, and the data
48  type must be registered with the interpreter via
49  \var{SLclass_register_class}.  See the \slang library programmer's
50  guide for more information.
51\seealso{SLclass_register_class, SLclass_set_push_function}
52\done
53
54\function{SLclass_register_class}
55\synopsis{Register a new data type with the interpreter}
56\usage{int SLclass_register_class (cl, type, sizeof_type, class_type)}
57#v+
58    SLang_Class_Type *cl
59    SLtype type
60    unsigned int sizeof_type
61    SLclass_Type class_type
62#v-
63\description
64  The \var{SLclass_register_class} function is used to register a new
65  class or data type with the interpreter.  If successful, the
66  function returns \exmp{0}, or upon failure, it returns \var{-1}.
67
68  The first parameter, \var{cl}, must have been previously obtained
69  via the \var{SLclass_allocate_class} function.
70
71  The second parameter, \var{type} specifies the data type of the new
72  class.  If set to \var{SLANG_VOID_TYPE} then the library will
73  automatically allocate an unused value for the class (the allocated
74  value can then be found using the \var{SLclass_get_class_id}
75  function), otherwise a value greater than \exmp{255} should be
76  used.  The values in the range \exmp{0-255} are reserved for
77  internal use by the library.
78
79  The size that the data type represents in bytes is specified by the
80  third parameter, \var{sizeof_type}.   This value should not be
81  confused with the sizeof the structure that represents the data
82  type, unless the data type is of class \var{SLANG_CLASS_TYPE_VECTOR}
83  or \var{SLANG_CLASS_TYPE_SCALAR}.  For pointer objects, the value
84  of this parameter is just \var{sizeof(void *)}.
85
86  The final parameter specifies the class type of the data type.  It must
87  be one of the values:
88#v+
89     SLANG_CLASS_TYPE_SCALAR
90     SLANG_CLASS_TYPE_VECTOR
91     SLANG_CLASS_TYPE_PTR
92     SLANG_CLASS_TYPE_MMT
93#v-
94  The \var{SLANG_CLASS_TYPE_SCALAR} indicates that the new data type
95  is a scalar.  Examples of scalars in \var{SLANG_INT_TYPE} and
96  \var{SLANG_DOUBLE_TYPE}.
97
98  Setting \var{class_type} to SLANG_CLASS_TYPE_VECTOR implies that the
99  new data type is a vector, or a 1-d array of scalar types.  An
100  example of a data type of this class is the
101  \var{SLANG_COMPLEX_TYPE}, which represents complex numbers.
102
103  \var{SLANG_CLASS_TYPE_PTR} specifies the data type is of a pointer
104  type.  Examples of data types of this class include
105  \var{SLANG_STRING_TYPE} and \var{SLANG_ARRAY_TYPE}.  Such types must
106  provide for their own memory management.
107
108  Data types of class \var{SLANG_CLASS_TYPE_MMT} are pointer types
109  except that the memory management, i.e., creation and destruction of
110  the type, is handled by the interpreter.  Such a type is called a
111  \em{memory managed type}.  An example of this data type is the
112  \var{SLANG_FILEPTR_TYPE}.
113\notes
114   See the \slang-library-programmers-guide for more information.
115\seealso{SLclass_allocate_class, SLclass_get_class_id}
116\done
117
118\function{SLclass_set_string_function}
119\synopsis{Set a data type's string representation callback}
120\usage{int SLclass_set_string_function (cl, sfun)}
121#v+
122   SLang_Class_Type *cl
123   char *(*sfun) (SLtype, VOID_STAR);
124#v-
125\description
126  The \var{SLclass_set_string_function} routine is used to define a
127  callback function, \var{sfun}, that will be used when a string
128  representation of an object of the data type represented by \var{cl}
129  is needed.  \var{cl} must have already been obtained via a call to
130  \var{SLclass_allocate_class}.  When called, \var{sfun} will be
131  passed two arguments: an SLtype which represents the data
132  type, and the address of the object for which a string represetation
133  is required.  The callback function must return a \em{malloced}
134  string.
135
136  Upon success, \var{SLclass_set_string_function} returns zero, or
137  upon error it returns \-1.
138\example
139  A callback function that handles both \var{SLANG_STRING_TYPE} and
140  \var{SLANG_INT_TYPE} variables looks like:
141#v+
142     char *string_and_int_callback (SLtype type, VOID_STAR addr)
143     {
144        char buf[64];
145
146        switch (type)
147          {
148           case SLANG_STRING_TYPE:
149             return SLmake_string (*(char **)addr);
150
151           case SLANG_INTEGER_TYPE:
152             sprintf (buf, "%d", *(int *)addr);
153             return SLmake_string (buf);
154          }
155        return NULL;
156     }
157#v-
158\notes
159  The default string callback simply returns the name of the data type.
160\seealso{SLclass_allocate_class, SLclass_register_class}
161\done
162
163\function{SLclass_set_destroy_function}
164\synopsis{Set the destroy method callback for a data type}
165\usage{int SLclass_set_destroy_function (cl, destroy_fun)}
166#v+
167    SLang_Class_Type *cl
168    void (*destroy_fun) (SLtype, VOID_STAR);
169#v-
170\description
171  \var{SLclass_set_destroy_function} is used to set the destroy
172  callback for a data type.  The data type's class \var{cl} must have
173  been previously obtained via a call to \var{SLclass_allocate_class}.
174  When called, \var{destroy_fun} will be passed two arguments: an
175  SLtype which represents the data type, and the address of the
176  object to be destroyed.
177
178  \var{SLclass_set_destroy_function} returns zero upon success, and
179  \-1 upon failure.
180\example
181  The destroy method for \var{SLANG_STRING_TYPE} looks like:
182#v+
183    static void string_destroy (SLtype type, VOID_STAR ptr)
184    {
185       char *s = *(char **) ptr;
186       if (s != NULL) SLang_free_slstring (*(char **) s);
187    }
188#v-
189\notes
190  Data types of class SLANG_CLASS_TYPE_SCALAR do not require a destroy
191  callback.  However, other classes do.
192\seealso{SLclass_allocate_class, SLclass_register_class}
193\done
194
195\function{SLclass_set_push_function}
196\synopsis{Set the push callback for a new data type}
197\usage{int SLclass_set_push_function (cl, push_fun)}
198#v+
199    SLang_Class_Type *cl
200    int (*push_fun) (SLtype, VOID_STAR);
201#v-
202\description
203   \var{SLclass_set_push_function} is used to set the push callback
204   for a new data type specified by \var{cl}, which must have been
205   previously obtained via \var{SLclass_allocate_class}.
206
207   The parameter \var{push_fun} is a pointer to the push callback.  It
208   is required to take two arguments: an SLtype
209   representing the data type, and the address of the object to be
210   pushed.  It must return zero upon success, or \-1 upon failure.
211
212   \var{SLclass_set_push_function} returns zero upon success, or \-1
213   upon failure.
214\example
215   The push callback for \var{SLANG_COMPLEX_TYPE} looks like:
216#v+
217      static int complex_push (SLtype type, VOID_STAR ptr)
218      {
219         double *z = *(double **) ptr;
220         return SLang_push_complex (z[0], z[1]);
221      }
222#v-
223\seealso{SLclass_allocate_class, SLclass_register_class}
224\done
225
226\function{SLclass_set_pop_function}
227\synopsis{Set the pop callback for a new data type}
228\usage{int SLclass_set_pop_function (cl, pop_fun)}
229#v+
230    SLang_Class_Type *cl
231    int (*pop_fun) (SLtype, VOID_STAR);
232#v-
233\description
234   \var{SLclass_set_pop_function} is used to set the callback for
235   popping an object from the stack for a new data type specified by
236   \var{cl}, which must have been previously obtained via
237   \var{SLclass_allocate_class}.
238
239   The parameter \var{pop_fun} is a pointer to the pop callback
240   function, which is required to take two arguments: an unsigned
241   character representing the data type, and the address of the object
242   to be popped.  It must return zero upon success, or \-1 upon
243   failure.
244
245   \var{SLclass_set_pop_function} returns zero upon success, or \-1
246   upon failure.
247\example
248   The pop callback for \var{SLANG_COMPLEX_TYPE} looks like:
249#v+
250      static int complex_push (SLtype type, VOID_STAR ptr)
251      {
252         double *z = *(double **) ptr;
253         return SLang_pop_complex (&z[0], &z[1]);
254      }
255#v-
256\seealso{SLclass_allocate_class, SLclass_register_class}
257\done
258
259\function{SLclass_get_datatype_name}
260\synopsis{Get the name of a data type}
261\usage{char *SLclass_get_datatype_name (SLtype type)}
262\description
263  The \var{SLclass_get_datatype_name} function returns the name of the
264  data type specified by \var{type}.  For example, if \var{type} is
265  \var{SLANG_INT_TYPE}, the string \exmp{"Integer_Type"} will be
266  returned.
267
268  This function returns a pointer that should not be modified or freed.
269\seealso{SLclass_allocate_class, SLclass_register_class}
270\done
271
272\function{SLang_free_mmt}
273\synopsis{Free a memory managed type}
274\usage{void SLang_free_mmt (SLang_MMT_Type *mmt)}
275\description
276  The \var{SLang_MMT_Type} function is used to free a memory managed
277  data type.
278\seealso{SLang_object_from_mmt, SLang_create_mmt}
279\done
280
281\function{SLang_object_from_mmt}
282\synopsis{Get a pointer to the value of a memory managed type}
283\usage{VOID_STAR SLang_object_from_mmt (SLang_MMT_Type *mmt)}
284\description
285  The \var{SLang_object_from_mmt} function returns a pointer to the
286  actual object whose memory is being managed by the interpreter.
287\seealso{SLang_free_mmt, SLang_create_mmt}
288\done
289
290\function{SLang_create_mmt}
291\synopsis{Create a memory managed data type}
292\usage{SLang_MMT_Type *SLang_create_mmt (SLtype t, VOID_STAR ptr)}
293\description
294  The \var{SLang_create_mmt} function returns a pointer to a new
295  memory managed object.  This object contains information necessary
296  to manage the memory associated with the pointer \var{ptr} which
297  represents the application defined data type of type \var{t}.
298\seealso{SLang_object_from_mmt, SLang_push_mmt, SLang_free_mmt}
299\done
300
301\function{SLang_push_mmt}
302\synopsis{Push a memory managed type}
303\usage{int SLang_push_mmt (SLang_MMT_Type *mmt)}
304\description
305   This function is used to push a memory managed type onto the
306   interpreter stack.  It returns zero upon success, or \exmp{-1} upon
307   failure.
308\seealso{SLang_create_mmt, SLang_pop_mmt}
309\done
310
311\function{SLang_pop_mmt}
312\synopsis{Pop a memory managed data type}
313\usage{SLang_MMT_Type *SLang_pop_mmt (SLtype t)}
314\description
315  The \var{SLang_pop_mmt} function may be used to pop a memory managed
316  type of type \var{t} from the stack.  It returns a pointer to the
317  memory managed object upon success, or \var{NULL} upon failure.  The
318  function \var{SLang_object_from_mmt} should be used to access the
319  actual pointer to the data type.
320\seealso{SLang_object_from_mmt, SLang_push_mmt}
321\done
322
323\function{SLang_inc_mmt}
324\synopsis{Increment a memory managed type reference count}
325\usage{void SLang_inc_mmt (SLang_MMT_Type *mmt);}
326\description
327  The \var{SLang_inc_mmt} function may be used to increment the
328  reference count associated with the memory managed data type given
329  by \var{mmt}.
330\seealso{SLang_free_mmt, SLang_create_mmt, SLang_pop_mmt, SLang_pop_mmt}
331\done
332
333\function{SLadd_intrin_fun_table}
334\synopsis{Add a table of intrinsic functions to the interpreter}
335\usage{int SLadd_intrin_fun_table(SLang_Intrin_Fun_Type *tbl, char *pp_name);}
336\description
337  The \var{SLadd_intrin_fun_table} function adds an array, or table, of
338  \var{SLang_Intrin_Fun_Type} objects to the interpreter.  The first
339  parameter, \var{tbl} specifies the table to be added.  The second
340  parameter \var{pp_name}, if non-NULL will be added to the list of
341  preprocessor symbols.
342
343  This function returns \-1 upon failure or zero upon success.
344\notes
345  A table should only be loaded one time and it is considered to be an
346  error on the part of the application if it loads a table more than
347  once.
348\seealso{SLadd_intrin_var_table, SLadd_intrinsic_function, SLdefine_for_ifdef}
349\done
350
351\function{SLadd_intrin_var_table}
352\synopsis{Add a table of intrinsic variables to the interpreter}
353\usage{int SLadd_intrin_var_table (SLang_Intrin_Var_Type *tbl, char *pp_name);}
354\description
355  The \var{SLadd_intrin_var_table} function adds an array, or table, of
356  \var{SLang_Intrin_Var_Type} objects to the interpreter.  The first
357  parameter, \var{tbl} specifies the table to be added.  The second
358  parameter \var{pp_name}, if non-NULL will be added to the list of
359  preprocessor symbols.
360
361  This function returns \-1 upon failure or zero upon success.
362\notes
363  A table should only be loaded one time and it is considered to be an
364  error on the part of the application if it loads a table more than
365  once.
366\seealso{SLadd_intrin_var_table, SLadd_intrinsic_function, SLdefine_for_ifdef}
367\done
368
369\function{SLang_load_file}
370\synopsis{Load a file into the interpreter}
371\usage{int SLang_load_file (char *fn)}
372\description
373  The \var{SLang_load_file} function opens the file whose name is
374  specified by \var{fn} and feeds it to the interpreter, line by line,
375  for execution.  If \var{fn} is \var{NULL}, the function will take
376  input from \var{stdin}.
377
378  If no error occurs, it returns \exmp{0}; otherwise,
379  it returns \exmp{-1}, and sets \var{SLang_Error} accordingly.  For
380  example, if it fails to open the file, it will return \exmp{-1} with
381  \var{SLang_Error} set to \var{SL_OBJ_NOPEN}.
382\notes
383   If the hook \var{SLang_Load_File_Hook} declared as
384#v+
385      int (*SLang_Load_File_Hook)(char *);
386#v-
387   is non-NULL, the function point to by it will be used to load the
388   file.  For example, the \jed editor uses this hook to load files
389   via its own routines.
390\seealso{SLang_load_object, SLang_load_string}
391\done
392
393\function{SLang_restart}
394\synopsis{Reset the interpreter after an error}
395\usage{void SLang_restart (int full)}
396\description
397   The \var{SLang_restart} function should be called by the
398   application at top level if an error occurs.  If the parameter
399   \var{full} is non-zero, any objects on the \slang run time stack
400   will be removed from the stack; otherwise, the stack will be left
401   intact.  Any time the stack is believed to be trashed, this routine
402   should be called with a non-zero argument (e.g., if
403   \var{setjmp}/\var{longjmp} is called).
404
405   Calling \var{SLang_restart} does not reset the global variable
406   \var{SLang_Error} to zero.  It is up to the application to reset
407   that variable to zero after calling \var{SLang_restart}.
408\example
409#v+
410      while (1)
411        {
412           if (SLang_Error)
413             {
414                SLang_restart (1);
415                SLang_Error = 0;
416             }
417           (void) SLang_load_file (NULL);
418        }
419#v-
420\seealso{SLang_init_slang, SLang_load_file}
421\done
422
423\function{SLang_byte_compile_file}
424\synopsis{Byte-compile a file for faster loading}
425\usage{int SLang_byte_compile_file(char *fn, int reserved)}
426\description
427  The \var{SLang_byte_compile_file} function ``byte-compiles'' the
428  file \var{fn} for faster loading by the interpreter.  This produces
429  a new file whose filename is equivalent to the one specified by
430  \var{fn}, except that a \var{'c'} is appended to the name.  For
431  example, if \var{fn} is set to \exmp{init.sl}, then the new file
432  will have the name \exmp{init.slc}.  The meaning of the second
433  parameter, \var{reserved}, is reserved for future use.  For now, set
434  it to \var{0}.
435
436  The function returns zero upon success, or \exmp{-1} upon error and
437  sets SLang_Error accordingly.
438\seealso{SLang_load_file, SLang_init_slang}
439\done
440
441\function{SLang_autoload}
442\synopsis{Autoload a function from a file}
443\usage{int SLang_autoload(char *funct, char *filename)}
444\description
445  The \var{SLang_autoload} function may be used to associate a
446  \var{slang} function name \var{funct} with the file \var{filename}
447  such that if \var{funct} has not already been defined when needed,
448  it will be loaded from \var{filename}.
449
450  \var{SLang_autoload} has no effect if \var{funct} has already been
451  defined.  Otherwise it declares \var{funct} as a user-defined \slang
452  function.  It returns \exmp{0} upon success, or \exmp{-1} upon error.
453\seealso{SLang_load_file, SLang_is_defined}
454\done
455
456\function{SLang_load_string}
457\synopsis{Interpret a string}
458\usage{int SLang_load_string(char *str)}
459\description
460  The \var{SLang_load_string} function feeds the string specified by
461  \var{str} to the interpreter for execution.  It returns zero upon
462  success, or \exmp{-1} upon failure.
463\seealso{SLang_load_file, SLang_load_object}
464\done
465
466\function{SLdo_pop}
467\synopsis{Delete an object from the stack}
468\usage{int SLdo_pop(void)}
469\description
470   This function removes an object from the top of the interpeter's
471   run-time stack and frees any memory associated with it.  It returns
472   zero upon success, or \var{-1} upon error (most likely due to a
473   stack-underflow).
474\seealso{SLdo_pop_n, SLang_pop_integer, SLang_pop_string}
475\done
476
477\function{SLdo_pop_n}
478\synopsis{Delete n objects from the stack}
479\usage{int SLdo_pop_n (unsigned int n)}
480\description
481   The \var{SLdo_pop_n} function removes the top \var{n} objects from
482   the interpreter's run-time stack and frees all memory associated
483   with the objects.  It returns zero upon success, or \var{-1} upon
484   error (most likely due to a stack-underflow).
485\seealso{SLdo_pop, SLang_pop_integer, SLang_pop_string}
486\done
487
488\function{SLang_pop_integer}
489\synopsis{Pop an integer off the stack}
490\usage{int SLang_pop_integer (int *i)}
491\description
492   The \var{SLang_pop_integer} function removes an integer from the
493   top of the interpreter's run-time stack and returns its value via
494   the pointer \var{i}.  If successful, it returns zero.  However, if
495   the top stack item is not of type \var{SLANG_INT_TYPE}, or the
496   stack is empty, the function will return \exmp{-1} and set
497   \var{SLang_Error} accordingly.
498\seealso{SLang_push_integer, SLang_pop_double}
499\done
500
501\function{SLpop_string}
502\synopsis{Pop a string from the stack}
503\usage{int SLpop_string (char **strptr);}
504\description
505   The \var{SLpop_string} function pops a string from the stack and
506   returns it as a malloced pointer.  It is up to the calling routine
507   to free this string via a call to \var{free} or \var{SLfree}.  If
508   successful, \var{SLpop_string} returns zero.  However, if the top
509   stack item is not of type \var{SLANG_STRING_TYPE}, or the stack is
510   empty, the function will return \exmp{-1} and set
511   \var{SLang_Error} accordingly.
512\example
513#v+
514      define print_string (void)
515      {
516         char *s;
517         if (-1 == SLpop_string (&s))
518           return;
519         fputs (s, stdout);
520         SLfree (s);
521      }
522#v-
523\notes
524   This function should not be confused with \var{SLang_pop_slstring},
525   which pops a \em{hashed} string from the stack.
526\seealso{SLang_pop_slstring. SLfree}
527\done
528
529\function{SLang_pop_string}
530\synopsis{Pop a string from the stack}
531\usage{int SLang_pop_string(char **strptr, int *do_free)}
532\description
533   The \var{SLpop_string} function pops a string from the stack and
534   returns it as a malloced pointer via \var{strptr}.  After the
535   function returns, the integer pointed to by the second parameter
536   will be set to a non-zero value if \var{*strptr} should be freed via
537   \var{free} or \var{SLfree}.  If successful, \var{SLpop_string}
538   returns zero.  However, if the top stack item is not of type
539   \var{SLANG_STRING_TYPE}, or the stack is empty, the function will
540   return \exmp{-1} and set \var{SLang_Error} accordingly.
541\notes
542   This function is considered obsolete and should not be used by
543   applications.  If one requires a malloced string for modification,
544   \var{SLpop_string} should be used.  If one requires a constant
545   string that will not be modifed by the application,
546   \var{SLang_pop_slstring} should be used.
547\seealso{SLang_pop_slstring, SLpop_string}
548\done
549
550\function{SLang_pop_slstring}
551\synopsis{Pop a hashed string from the stack}
552\usage{int SLang_pop_slstring (char **s_ptr)}
553\description
554   The \var{SLang_pop_slstring} function pops a hashed string from the
555   \slang run-time stack and returns it via \var{s_ptr}.  It returns
556   zero if successful, or \-1 upon failure.  The resulting string
557   should be freed via a call to \var{SLang_free_slstring} after use.
558\example
559#v+
560   void print_string (void)
561   {
562      char *s;
563      if (-1 == SLang_pop_slstring (&s))
564        return;
565      fprintf (stdout, "%s\n", s);
566      SLang_free_slstring (s);
567   }
568#v-
569\notes
570   \var{SLang_free_slstring} is the preferred function for popping
571   strings.  This is a result of the fact that the interpreter uses
572   hashed strings as the native representation for string data.
573
574   One must \em{never} free a hashed string using \var{free} or
575   \var{SLfree}.  In addition, one must never make any attempt to
576   modify a hashed string and doing so will result in memory
577   corruption.
578\seealso{SLang_free_slstring, SLpop_string}
579\done
580
581\function{SLang_pop_double}
582\synopsis{Pop a double from the stack}
583\usage{int SLang_pop_double (double *dptr)}
584\description
585   The \var{SLang_pop_double} function pops a double precision number
586   from the stack and returns it via \var{dptr}.  This
587   function returns \0 upon success, otherwise it returns \-1 and sets
588   \var{SLang_Error} accordingly.
589\seealso{SLang_pop_integer, SLang_push_double}
590\done
591
592\function{SLang_pop_complex}
593\synopsis{Pop a complex number from the stack}
594\usage{int SLang_pop_complex (double *re, double *im)}
595\description
596   \var{SLang_pop_complex} pops a complex number from the stack and
597   returns it via the parameters \var{re} and \var{im} as the real and
598   imaginary parts of the complex number, respectively.  This function
599   automatically converts objects of type \var{SLANG_DOUBLE_TYPE} and
600   \var{SLANG_INT_TYPE} to \var{SLANG_COMPLEX_TYPE}, if necessary.
601   It returns zero upon success, or \-1 upon error setting
602   \var{SLang_Error} accordingly.
603\seealso{SLang_pop_integer, SLang_pop_double, SLang_push_complex}
604\done
605
606\function{SLang_push_complex}
607\synopsis{Push a complex number onto the stack}
608\usage{int SLang_push_complex (double re, double im)}
609\description
610   \var{SLang_push_complex} may be used to push the complex number
611   whose real and imaginary parts are given by \var{re} and \var{im},
612   respectively.  It returns zero upon success, or \-1 upon error
613   setting \var{SLang_Error} accordingly.
614\seealso{SLang_pop_complex, SLang_push_double}
615\done
616
617\function{SLang_push_double}
618\synopsis{Push a double onto the stack}
619\usage{int SLang_push_double(double d)}
620\description
621   \var{SLang_push_double} may be used to push the double precision
622   floating point number \var{d} onto the interpreter's run-time
623   stack.  It returns zero upon success, or \-1 upon error setting
624   \var{SLang_Error} accordingly.
625\seealso{SLang_pop_double, SLang_push_integer}
626\done
627
628\function{SLang_push_string}
629\synopsis{Push a string onto the stack}
630\usage{int SLang_push_string (char *s)}
631\description
632   \var{SLang_push_string} pushes a copy of the string specified by
633   \var{s} onto the interpreter's run-time stack.  It returns zero
634   upon success, or \-1 upon error setting \var{SLang_Error}
635   accordingly.
636\notes
637   If \var{s} is \var{NULL}, this function pushes \var{NULL}
638   (\var{SLANG_NULL_TYPE}) onto the stack.
639\seealso{SLang_push_malloced_string}
640\done
641
642\function{SLang_push_integer}
643\synopsis{Push an integer onto the stack}
644\usage{int SLang_push_integer (int i)}
645\description
646   \var{SLang_push_integer} the integer \var{i} onto the interpreter's
647   run-time stack.  It returns zero upon success, or \-1 upon error
648   setting \var{SLang_Error} accordingly.
649\seealso{SLang_pop_integer, SLang_push_double, SLang_push_string}
650\done
651
652\function{SLang_push_malloced_string}
653\synopsis{Push a malloced string onto the stack}
654\usage{int SLang_push_malloced_string (char *s);}
655\description
656   \var{SLang_push_malloced_string} may be used to push a malloced
657   string onto the interpreter's run-time stack.  It returns zero upon
658   success, or \-1 upon error setting \var{SLang_Error} accordingly.
659\example
660   The following example illustrates that it is up to the calling
661   routine to free the string if \var{SLang_push_malloced_string} fails:
662#v+
663      int push_hello (void)
664      {
665         char *s = malloc (6);
666         if (s == NULL) return -1;
667         strcpy (s, "hello");
668         if (-1 == SLang_push_malloced_string (s))
669           {
670              free (s);
671              return -1;
672           }
673         return 0;
674      }
675#v-
676\example
677   The function \var{SLang_create_slstring} returns a hashed string.
678   Such a string may not be malloced and should not be passed to
679   \var{SLang_push_malloced_string}.
680\notes
681   If \var{s} is \var{NULL}, this function pushes \var{NULL}
682   (\var{SLANG_NULL_TYPE}) onto the stack.
683\seealso{SLang_push_string, SLmake_string}
684\done
685
686\function{SLang_is_defined}
687\synopsis{Check to see if the interpreter defines an object}
688\usage{int SLang_is_defined (char *nm)}
689\description
690   The \var{SLang_is_defined} function may be used to determine
691   whether or not a variable or function whose name is given by
692   \var{em} has been defined.  It returns zero if no such object has
693   been defined.  Otherwise it returns a non-zero value according to
694   the following table:
695#v+
696      1    intrinsic function
697      2    user-defined slang function
698     -1    intrinsic variable
699     -2    user-defined global variable
700#v-
701   Note that variables correspond to negative numbers and functions
702   are represented by positive numbers.
703\seealso{SLadd_intrinsic_function, SLang_run_hooks, SLang_execute_function}
704\done
705
706\function{SLang_run_hooks}
707\synopsis{Run a user-defined hook with arguments}
708\usage{int SLang_run_hooks (char *fname, unsigned int n, ...)}
709\description
710   The \var{SLang_run_hooks} function may be used to execute a
711   user-defined function named \var{fname}.  Before execution of the
712   function, the \var{n} string arguments specified by the variable
713   parameter list are pushed onto the stack.  If the function
714   \var{fname} does not exist, \var{SLang_run_hooks} returns zero;
715   otherwise, it returns \exmp{1} upon successful execution of the
716   function, or \-1 if an error occurred.
717\example
718   The \jed editor uses \var{SLang_run_hooks} to setup the mode of a
719   buffer based on the filename extension of the file associated with
720   the buffer:
721#v+
722      char *ext = get_filename_extension (filename);
723      if (ext == NULL) return -1;
724      if (-1 == SLang_run_hooks ("mode_hook", 1, ext))
725        return -1;
726      return 0;
727#v-
728\seealso{SLang_is_defined, SLang_execute_function}
729\done
730
731\function{SLang_execute_function}
732\synopsis{Execute a user or intrinsic function}
733\usage{int SLang_execute_function (char *fname)}
734\description
735   This function may be used to execute either a user-defined function
736   or an intrinisic function.  The name of the function is specified
737   by \var{fname}.  It returns zero if \var{fname} is not defined, or
738   \exmp{1} if the function was successfully executed, or \-1 upon
739   error.
740\notes
741   The function \var{SLexecute_function} may be a better alternative
742   for some uses.
743\seealso{SLang_run_hooks, SLexecute_function, SLang_is_defined}
744\done
745
746\function{SLang_get_function}
747\synopsis{Get a pointer to a \slang function}
748\usage{SLang_Name_Type *SLang_get_function (char *fname)}
749\description
750  This function returns a pointer to the internal \slang table entry
751  of a function whose name is given by \var{fname}.  It returns
752  \var{NULL} upon failure.  The value returned by this function can be
753  used \var{SLexecute_function} to call the function directly
754  from C.
755\seealso{SLexecute_function}
756\done
757
758\function{SLexecute_function}
759\synopsis{Execute a \slang or intrinsic function}
760\usage{int SLexecute_function (SLang_Name_Type *nt)}
761\description
762  The \var{SLexecute_function} allows an application to call the
763  \slang function specified by the \var{SLang_Name_Type} pointer
764  \var{nt}.  This parameter must be non \var{NULL} and must have been
765   previously obtained by a call to \var{SLang_get_function}.
766\example
767   Consider the \slang function:
768#v+
769     define my_fun (x)
770     {
771        return x^2 - 2;
772     }
773#v-
774   Suppose that it is desired to call this function many times with
775   different values of x.  There are at least two ways to do this.
776   The easiest way is to use \var{SLang_execute_function} by passing
777   the string \exmp{"my_fun"}.  A better way that is much faster is to
778   use \var{SLexecute_function}:
779#v+
780      int sum_a_function (char *fname, double *result)
781      {
782         double sum, x, y;
783         SLang_Name_Type *nt;
784
785         if (NULL == (nt = SLang_get_function (fname)))
786           return -1;
787
788         sum = 0;
789         for (x = 0; x < 10.0; x += 0.1)
790           {
791              SLang_start_arg_list ();
792              if (-1 == SLang_push_double (x))
793                return -1;
794              SLang_end_arg_list ();
795              if (-1 == SLexecute_function (nt))
796                return -1;
797              if (-1 == SLang_pop_double (&y))
798                return -1;
799
800              sum += y;
801           }
802         return sum;
803      }
804#v-
805   Although not necessary in this case, \var{SLang_start_arg_list} and
806   \var{SLang_end_arg_list} were used to provide the function with
807   information about the number of parameters passed to it.
808\seealso{SLang_get_function, SLang_start_arg_list, SLang_end_arg_list}
809\done
810
811\function{SLang_peek_at_stack}
812\synopsis{Find the type of object on the top of the stack}
813\usage{int SLang_peek_at_stack (void)}
814\description
815  The \var{SLang_peek_at_stack} function is useful for determining the
816  data type of the object at the top of the stack.  It returns the
817  data type, or -1 upon a stack-underflow error.  It does not remove
818  anything from the stack.
819\seealso{SLang_pop_string, SLang_pop_integer}
820\done
821
822\function{SLang_pop_fileptr}
823\synopsis{Pop a file pointer}
824\usage{int SLang_pop_fileptr (SLang_MMT_Type **mmt, FILE **fp)}
825\description
826  \var{SLang_pop_fileptr} pops a file pointer from the \slang
827  run-time stack.  It returns zero upon success, or \-1 upon failure.
828
829  A \slang file pointer (SLANG_FILEPTR_TYPE) is actually a memory
830  managed object.  For this reason, \var{SLang_pop_fileptr} also
831  returns the memory managed object via the argument list.  It is up
832  to the calling routine to call \var{SLang_free_mmt} to free the
833  object.
834\example
835  The following example illustrates an application defined intrinsic
836  function that writes a user defined double precision number to a
837  file.  Note the use of \var{SLang_free_mmt}:
838#v+
839     int write_double (void)
840     {
841        double t;
842        SLang_MMT_Type *mmt;
843        FILE *fp;
844        int status;
845
846        if (-1 == SLang_pop_double (&d, NULL, NULL))
847          return -1;
848        if (-1 == SLang_pop_fileptr (&mmt, &fp))
849          return -1;
850
851        status = fwrite (&d, sizeof (double), 1, fp);
852        SLang_free_mmt (mmt);
853        return status;
854     }
855#v-
856  This function can be used by a \slang function as follows:
857#v+
858     define write_some_values ()
859     {
860        variable fp, d;
861
862        fp = fopen ("myfile.dat", "wb");
863        if (fp == NULL)
864          error ("file failed to open");
865        for (d = 0; d < 10.0; d += 0.1)
866          {
867             if (-1 == write_double (fp, d))
868               error ("write failed");
869          }
870        if (-1 == fclose (fp))
871          error ("fclose failed");
872     }
873#v-
874\seealso{SLang_free_mmt, SLang_pop_double}
875\done
876
877\function{SLadd_intrinsic_function}
878\synopsis{Add a new intrinsic function to the interpreter}
879\usage{int SLadd_intrinsic_function (name, f, type, nargs, ...)}
880#v+
881    char *name
882    FVOID_STAR f
883    SLtype type
884    unsigned int nargs
885#v-
886\description
887  The \var{SLadd_intrinsic_function} function may be used to add a new
888  intrinsic function.  The \slang name of the function is specified by
889  \var{name} and the actual function pointer is given by \var{f}, cast
890  to \var{FVOID_STAR}.  The third parameter, \var{type} specifies the
891  return type of the function and must be one of the following values:
892#v+
893    SLANG_VOID_TYPE   (returns nothing)
894    SLANG_INT_TYPE    (returns int)
895    SLANG_DOUBLE_TYPE (returns double)
896    SLANG_STRING_TYPE (returns char *)
897#v-
898  The \var{nargs} parameter specifies the number of parameters to pass
899  to the function.  The variable argument list following \var{nargs}
900  must consists of \var{nargs} integers which specify the data type of
901  each argument.
902
903  The function returns zero upon success or \-1 upon failure.
904\example
905  The \jed editor uses this function to change the \var{system}
906  intrinsic function to the following:
907#v+
908     static int jed_system (char *cmd)
909     {
910        if (Jed_Secure_Mode)
911          {
912             msg_error ("Access denied.");
913             return -1;
914          }
915        return SLsystem (cmd);
916     }
917#v-
918  After initializing the interpreter with \var{SLang_init_slang},
919  \jed calls \var{SLadd_intrinsic_function} to substitute the above
920  definition for the default \slang definition:
921#v+
922     if (-1 == SLadd_intrinsic_function ("system", (FVOID_STAR)jed_system,
923                                         SLANG_INT_TYPE, 1,
924                                         SLANG_STRING_TYPE))
925       return -1;
926#v-
927\seealso{SLadd_intrinsic_variable, SLadd_intrinsic_array}
928\done
929
930\function{SLadd_intrinsic_variable}
931\synopsis{Add an intrinsic variable to the interpreter}
932\usage{int SLadd_intrinsic_variable (name, addr, type, rdonly)}
933#v+
934    char *name
935    VOID_STAR addr
936    SLtype type
937    int rdonly
938#v-
939\description
940  The \var{SLadd_intrinsic_variable} function adds an intrinsic
941  variable called \var{name} to the interpeter.  The second parameter
942  \var{addr} specifies the address of the variable (cast to
943  \var{VOID_STAR}).  The third parameter, \var{type}, specifies the
944  data type of the variable.  If the fourth parameter, \var{rdonly},
945  is non-zero, the variable will interpreted by the interpreter as
946  read-only.
947
948  If successful, \var{SLadd_intrinsic_variable} returns zero,
949  otherwise it returns \-1.
950\example
951  Suppose that \var{My_Global_Int} is a global variable (at least not
952  a local one):
953#v+
954    int My_Global_Int;
955#v-
956  It can be added to the interpreter via the function call
957#v+
958    if (-1 == SLadd_intrinsic_variable ("MyGlobalInt",
959                                        (VOID_STAR)&My_Global_Int,
960                                        SLANG_INT_TYPE, 0))
961      exit (1);
962#v-
963\notes
964  The current implementation requires all pointer type intrinsic
965  variables to be read-only.  For example,
966#v+
967    char *My_Global_String;
968#v-
969  is of type \var{SLANG_STRING_TYPE}, and must be declared as
970  read-only.  Finally, not that
971#v+
972   char My_Global_Char_Buf[256];
973#v-
974  is \em{not} a \var{SLANG_STRING_TYPE} object.  This difference is
975  very important because internally the interpreter dereferences the
976  address passed to it to get to the value of the variable.
977\seealso{SLadd_intrinsic_function, SLadd_intrinsic_array}
978\done
979
980\function{SLclass_add_unary_op}
981\synopsis{??}
982\usage{int SLclass_add_unary_op (SLtype,int (*) (int, SLtype, VOID_STAR, unsigned int, VOID_STAR), int (*) (int, SLtype, SLtype *));}
983\description
984??
985\seealso{??}
986\done
987
988\function{SLclass_add_app_unary_op}
989\synopsis{??}
990\usage{int SLclass_add_app_unary_op (SLtype, int (*) (int,SLtype, VOID_STAR, unsigned int,VOID_STAR),int (*) (int, SLtype, SLtype *));}
991\description
992??
993\seealso{??}
994\done
995
996\function{SLclass_add_binary_op}
997\synopsis{??}
998\usage{int SLclass_add_binary_op (SLtype, SLtype,int (*)(int, SLtype, VOID_STAR, unsigned int,SLtype, VOID_STAR, unsigned int,VOID_STAR),int (*) (int, SLtype, SLtype, SLtype *));}
999\description
1000??
1001\seealso{??}
1002\done
1003
1004\function{SLclass_add_math_op}
1005\synopsis{??}
1006\usage{int SLclass_add_math_op (SLtype,int (*)(int,SLtype, VOID_STAR, unsigned int,VOID_STAR),int (*)(int, SLtype, SLtype *));}
1007\description
1008??
1009\seealso{??}
1010\done
1011
1012\function{SLclass_add_typecast}
1013\synopsis{??}
1014\usage{int SLclass_add_typecast (SLtype, SLtype int (*)_PROTO((SLtype, VOID_STAR, unsigned int,SLtype, VOID_STAR)),int);}
1015\description
1016??
1017\seealso{??}
1018\done
1019