aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/UPGRADE.txt
blob: 9ab4e3e63714b30aafdeb7af093e6126ae8c709d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
This document consists of two parts.  The first part describes some
changes to the interpreter that may affect existing slang macros.  The
second part describes changes that may affect applications that use
the library.

Part 1: Interpreter Changes.
============================

Changes to the slang syntax.
---------------------------
 The syntax has not changed too much since version 0.99-XX.  However
 there are a few changes that you need to be aware of so that you can
 modify your slang functions accordingly.  See slang/doc/* for more
 information about slang version 1.0.
 
 To help track areas where you code needs changed, add the following
 line to the top of each file that you load into the interpreter:
 
     _debug_info = 1;

 This will cause extra debugging information to get generated.

 The important differences that you must be aware of are listed below:

 * The parser is more sensitive to missing semi-colons.  For that
   reason, you may experience some parse errors.  Make sure each
   statement is terminated by a semi-colon.

 * The switch statement has changed--- it is cleaner.  In particular,
   the `pop' in the default case should be removed.  For example, in
   0.99-XX, the object was pushed onto the stack before each switch
   case block was executed.  In 1.0, the switch statement nolonger
   works this way.  So, if you currently have code that looks like:
       
          switch (x)
	  { case 1:                  do_something () }
	  { case 2 or case (x, 3):   do_something_else () }
	  { () > 7:                  do_big_thing ();
	  { pop ();                  do_default () }
	  
   
   You must change it to:

          switch (x)
	  { case 1:                  do_something (); }
	  { case 2 or case 3:        do_something_else (); }
	  { x > 7:                   do_big_thing (); }
	  {                          do_default (); }

   Note that this example also illustrates that you may need to insert
   some semi-colons to terminate statements.  In any event, it is a
   good idea to study your switch statements very carefully.

 * The `create_array' function has been eliminated in favor of a new,
   cleaner mechanism.  For example, instead of using
   
         a = create_array ('s', 10, 20, 2);
	 
   to create a 10x20 array of strings, you must now use
   
         a = String_Type [10, 20];
 
   Similarly, use `Integer_Type [10, 20]' to create a 10x20 array of
   integers.  [Note for JED users: See jed/lib/compat.sl for an
   implementation of create_array]
   
 * The semantics of the ``alias'' operator `&' has changed in a much
   more useful way.  Briefly, if you have code that looks like:
   
         define exec_function (f)
	 {
	    variable x = 1.0;
	    return f(x);
	 }
	 
	 variable y = exec_function (&sin);

   Then you must change it to:
   
         define exec_function (f)
	 {
	    variable x = 1.0;
	    return @f(x);
	 }
	 
	 variable y = exec_function (&sin);

   where `@' is a ``dereference'' operator.
   
 * Several intrinsic functions have changed and a few have been
   removed, or renamed.  See the documentation in slang/doc/ for more
   detailed information about each function.

   Functions ones that have been removed or renamed include:

     create_array
        Use simpler syntax, e.g.,  x = Integer_Type [10];

     _obj_info
        Use the new `typeof' function.  See documentation for more
	information.
	
     print_stack has been renamed to _print_stack
     
     `slapropos' has been renamed to `_apropos'.  It also takes an
     additional argument.
	
     `float' has been renamed to `double'.  See also `atof'.
     
     `slang_trace_function' renamed to `_trace_function'
     
     `pop_n' has been renamed to `_pop_n'
     
   The semantics of the following functions have changed:
   
      `fopen': 
         It now returns NULL upon failure.  Change code such as
      
            fp = fopen (file, "r");
	    if (fp == -1) error (...);

         to:

            fp = fopen (file, "r");
	    if (fp == NULL) error (...);
      
      `getenv', `extract_element':
         These return NULL upon failure instead of "".  This means code 
	 that looks like:
	   
	    n = 0;
	    while (elem = extract_element (list, n, ','), strlen(elem))
	      {
	         n++;
		 .
		 .
	      }

	 should be changed to:
	 
	    n = 0;
	    while (elem = extract_element (list, n, ','), elem != NULL)
	      {
	         n++;
		 .
		 .
	      }

      `fclose': It now returns -1 upon failure and sets errno, or 0 if
          successful. Previously, it returned 0 upon failure and 1
	  upon success. 
      
      `fgets': It now returns just 1 value but takes a reference as an
          argument.  That is, replace code such as:
	  
	    while (fgets (fp) > 0)
	      {
	         buf = ();
		 .
		 .
	      }
	     
	  with:
	  
	    while (-1 != fgets (&buf, fp))
	      {
	         .
		 .
	      }
	    

Part 2:  C interface changes
============================

[Please review slang/doc/text/cslang.txt for information regarding
 embedding the interpreter]

There have been many, many changes since 0.99-XX.  Most of the changes
concern the interpreter and the interpreter interface.  Other aspects
of the library, e.g., SLsmg, etc have not changed too much.  I made
every attempt to maintain as much backward compatibility as possible,
weighing the pros and cons of every change.  I think that I arrived at
a reasonable compromise, and, hopefully, you will agree.

When recompiling your application, make sure that you compile it with
warnings turned on so that prototype changes may be detected.

-----------------------------------------------------------------------
The way objects are accessed internally by the interpreter has changed
dramatically.  This has important ramifications for an any application
embedding the interpreter.  In particular, the way intrinsic objects
are made available to the interpreter has changed.

In 0.99-XX, the standard procedure was to use the MAKE_INTRINSIC macro
inside an array of SLang_Name_Type, e.g.,

    void c_fname (void) { ... }
    char *String_Variable;
    int Int_Variable;
    char String_Buf[256];

    static SLang_Name_Type My_Intrinsics [] = 
    {
       MAKE_INTRINSIC(".fname", c_fname, VOID_TYPE, 0),
       MAKE_VARIABLE(".string_vname", String_Variable, STRING_TYPE, 1),
       MAKE_VARIABLE(".string_buf_vname", String_Buf, STRING_TYPE, 1),
       MAKE_VARIABLE(".int_vname", &Int_Variable, INT_TYPE, 0),
       SLANG_END_TABLE
    };

In the new version, variables and intrinsics cannot be grouped in the
same table.  Instead two tables must be used:

    static SLang_Intrin_Fun_Type My_Intrinsic_Funs [] =
    {
       MAKE_INTRINSIC("fname", c_fname, VOID_TYPE, 0),
       SLANG_END_TABLE
    };
    
    char *String_Buf_Ptr = String_Buf;
    static SLang_Intrin_Var_Type My_Intrinsic_Funs [] =
    {
       MAKE_VARIABLE("string_vname", &String_Variable, STRING_TYPE, 1),
       MAKE_VARIABLE("int_vname", &Int_Variable, INT_TYPE, 0),
       MAKE_VARIABLE(".string_buf_vname", &String_Buf_Ptr, STRING_TYPE, 1),
       SLANG_END_TABLE
    };
    
Note that the `.' is no longer required to be the first character in
the name.  Also, the `&' address operator must be used for all
variables in the MAKE_VARIABLE macro.  Finally, intrinsic STRING_TYPE
variables must be pointers and not arrays.  This is the reason
String_Buf_Ptr was introduced.

You are encouraged to read the documentation about embedding the
interpreter because it is now possible to ensure that variables passed
to an intrinsic are type checked.  See slang/slstd.c for examples.

------------------------------------------------------------------------
0.99-XX had a very inconsistent interface.  For example, while some
functions returned 0 upon success, others returned 0 to indicate
failure.  One of the major changes to the library was to provide a
consistent return value to indicate error.  In this version, -1
indicates an error and 0 indicates success.  In particular, the
following functions were affected:

   SLdefine_for_ifdef
   SLang_execute_function
   SLexecute_function
   SLang_run_hooks
   SLang_load_object
   SLang_pop_*
   SLang_push_*
   SLsmg_resume_smg
   SLsmg_suspend_smg
   SLtt_init_video
   SLtt_reset_video

Another change involved the name space.  All external symbols now
start with `SL'.  To this end, the following functions have been
renamed:

    init_SLmath -->     SLang_init_slmath
    init_SLunix -->     SLang_init_slunix
    init_SLang -->      SLang_init_slang
    init_SLfiles -->    SLang_init_slfile
    slang_add_array --> SLang_add_intrinsic_array

Some other functions were renamed when the interface changed:

    SLang_extract_list_element --> SLextract_list_element
    SLang_Error_Routine --> SLang_Error_Hook

Some functions were not renamed but do have different prototypes:

    int SLang_run_hooks(char *, unsigned int, ...);

Some functions are nolonger available or have been replaced by newer,
more flexible versions:

    SLadd_name --> SLadd_intrinsic_variable, SLadd_intrinsic_function
    SLang_pop/push_float --> SLang_pop/push_double


Typedef Modifications
---------------------
SLang_Load_Type: The interface has been completely rewritten.  See
  the documentation.
  
Preprocessor defines:
--------------------
  __SLMATH__ if math functions available (SLang_init_slmath)
  __SLUNIX__ if unix functions available (SLang_init_slunix)
  __SLFILE__ if file I/O functions available (SLang_init_slfile)