_slang.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* header file for S-Lang internal structures that users do not (should not)
  2. need. Use slang.h for that purpose. */
  3. /* Copyright (c) 1992, 1995 John E. Davis
  4. * All rights reserved.
  5. *
  6. * You may distribute under the terms of either the GNU General Public
  7. * License or the Perl Artistic License.
  8. */
  9. #include "config.h"
  10. #include <string.h>
  11. #include <glib.h>
  12. #include "slang-mc.h"
  13. #include "jdmacros.h"
  14. #ifdef VMS
  15. # define SLANG_SYSTEM_NAME "_VMS"
  16. #else
  17. # if defined (__GO32__) || defined (__EMX__) || \
  18. defined (msdos) || defined (__os2__)
  19. # define SLANG_SYSTEM_NAME "_IBMPC"
  20. # else
  21. # define SLANG_SYSTEM_NAME "_UNIX"
  22. # endif
  23. #endif /* VMS */
  24. #ifdef msdos
  25. #define SLANG_MAX_SYMBOLS 500
  26. #else
  27. #define SLANG_MAX_SYMBOLS 2500
  28. #endif
  29. /* maximum number of global symbols--- slang builtin, functions, global vars */
  30. /* These quantities are main_types for byte-compiled code. They are used
  31. * by the inner_interp routine. The ones commented out with a // are
  32. * actually defined in slang.h because they are also used as the main_type in
  33. * the name table.
  34. */
  35. /* // #define SLANG_LVARIABLE 0x01 */
  36. #define SLANG_LOGICAL 0x02
  37. #define SLANG_BINARY 0x03
  38. /* // #define SLANG_INTRINSIC 0x06 */
  39. /* // #define SLANG_FUNCTION 0x07 */
  40. #define SLANG_LITERAL 0x08 /* constant objects */
  41. #define SLANG_BLOCK 0x09
  42. #define SLANG_EQS 0x0A
  43. #define SLANG_UNARY 0x0B
  44. #define SLANG_LUNARY 0x0C
  45. /* // #define SLANG_GVARIABLE 0x0D */
  46. /* // #define SLANG_IVARIABLE 0x0E */ /* intrinsic variables */
  47. /* // #define SLANG_RVARIABLE 0x0F */ /* read only variable */
  48. /* These 3 MUST be in this order too ! */
  49. #define SLANG_RETURN 0x10
  50. #define SLANG_BREAK 0x11
  51. #define SLANG_CONTINUE 0x12
  52. #define SLANG_EXCH 0x13
  53. #define SLANG_LABEL 0x14
  54. #define SLANG_LOBJPTR 0x15
  55. #define SLANG_GOBJPTR 0x16
  56. #define SLANG_X_ERROR 0x17
  57. /* These must be in this order */
  58. #define SLANG_X_USER0 0x18
  59. #define SLANG_X_USER1 0x19
  60. #define SLANG_X_USER2 0x1A
  61. #define SLANG_X_USER3 0x1B
  62. #define SLANG_X_USER4 0x1C
  63. #ifdef SLANG_NOOP
  64. # define SLANG_NOOP_DIRECTIVE 0x2F
  65. #endif
  66. /* If SLANG_DATA occurs as the main_type for an object in the interpreter's
  67. * byte-code, it currently refers to a STRING.
  68. */
  69. /* // #define SLANG_DATA 0x30 */ /* real objects which may be destroyed */
  70. /* Subtypes */
  71. #define ERROR_BLOCK 0x01
  72. /* gets executed if block encounters error other than stack related */
  73. #define EXIT_BLOCK 0x02
  74. #define USER_BLOCK0 0x03
  75. #define USER_BLOCK1 0x04
  76. #define USER_BLOCK2 0x05
  77. #define USER_BLOCK3 0x06
  78. #define USER_BLOCK4 0x07
  79. /* The user blocks MUST be in the above order */
  80. /* directive subtypes */
  81. #define SLANG_LOOP_MASK 0x80
  82. #define SLANG_LOOP 0x81
  83. #define SLANG_WHILE 0x82
  84. #define SLANG_FOR 0x83
  85. #define SLANG_FOREVER 0x84
  86. #define SLANG_CFOR 0x85
  87. #define SLANG_DOWHILE 0x86
  88. #define SLANG_IF_MASK 0x40
  89. #define SLANG_IF 0x41
  90. #define SLANG_IFNOT 0x42
  91. #define SLANG_ELSE 0x43
  92. /* local, global variable assignments
  93. * The order here is important. See interp_variable_eqs to see how this
  94. * is exploited. */
  95. #define SLANG_EQS_MASK 0x20
  96. /* local variables */
  97. /* Keep these in this order!! */
  98. #define SLANG_LEQS 0x21
  99. #define SLANG_LPEQS 0x22
  100. #define SLANG_LMEQS 0x23
  101. #define SLANG_LPP 0x24
  102. #define SLANG_LMM 0x25
  103. /* globals */
  104. /* Keep this on this order!! */
  105. #define SLANG_GEQS 0x26
  106. #define SLANG_GPEQS 0x27
  107. #define SLANG_GMEQS 0x28
  108. #define SLANG_GPP 0x29
  109. #define SLANG_GMM 0x2A
  110. /* intrinsic variables */
  111. #define SLANG_IEQS 0x2B
  112. #define SLANG_IPEQS 0x2C
  113. #define SLANG_IMEQS 0x2D
  114. #define SLANG_IPP 0x2E
  115. #define SLANG_IMM 0x2F
  116. #define SLANG_ELSE_MASK 0x10
  117. #define SLANG_ANDELSE 0x11
  118. #define SLANG_ORELSE 0x12
  119. #define SLANG_SWITCH 0x13
  120. /* LOGICAL SUBTYPES (operate on integers) */
  121. #define SLANG_MOD 16
  122. #define SLANG_OR 17
  123. #define SLANG_AND 18
  124. #define SLANG_BAND 19
  125. #define SLANG_BOR 20
  126. #define SLANG_BXOR 21
  127. #define SLANG_SHL 22
  128. #define SLANG_SHR 23
  129. /* LUnary Subtypes */
  130. #define SLANG_NOT 24
  131. #define SLANG_BNOT 25
  132. typedef struct SLBlock_Type
  133. {
  134. unsigned char main_type;
  135. unsigned char sub_type;
  136. union
  137. {
  138. struct SLBlock_Type *blk;
  139. int i_blk;
  140. SLang_Name_Type *n_blk;
  141. char *s_blk;
  142. #ifdef FLOAT_TYPE
  143. float64 *f_blk; /*literal float is a pointer */
  144. #endif
  145. long l_blk;
  146. }
  147. b;
  148. }
  149. SLBlock_Type;
  150. typedef struct
  151. {
  152. unsigned char main_type; /* block, intrinsic... */
  153. unsigned char sub_type; /* SLANG_WHILE, SLANG_DATA, ... */
  154. union
  155. {
  156. long l_val;
  157. char *s_val;
  158. int i_val;
  159. SLuser_Object_Type *uobj;
  160. SLang_Name_Type *n_val;
  161. #ifdef FLOAT_TYPE
  162. float64 f_val;
  163. #endif
  164. } v;
  165. } SLang_Object_Type;
  166. extern void SLang_free_object (SLang_Object_Type *);
  167. extern int SLang_pop_non_object (SLang_Object_Type *);
  168. extern void _SLdo_error (char *, ...);
  169. extern void SLcompile(char *);
  170. extern void (*SLcompile_ptr)(char *);
  171. typedef struct
  172. {
  173. char *name; int type;
  174. } SLang_Name2_Type;
  175. extern void SLstupid_hash(void);
  176. typedef struct SLName_Table
  177. {
  178. struct SLName_Table *next; /* next table */
  179. SLang_Name_Type *table; /* pointer to table */
  180. int n; /* entries in this table */
  181. char name[32]; /* name of table */
  182. int ofs[256]; /* offsets into table */
  183. } SLName_Table;
  184. extern SLName_Table *SLName_Table_Root;
  185. #ifdef MSWINDOWS
  186. extern SLang_Name_Type *SLang_Name_Table;
  187. #else
  188. extern SLang_Name_Type SLang_Name_Table[SLANG_MAX_SYMBOLS];
  189. #endif
  190. extern SLang_Name2_Type SL_Binary_Ops [];
  191. extern SLang_Object_Type *SLStack_Pointer;
  192. extern char *SLbyte_compile_name(char *);
  193. extern int SLang_pop(SLang_Object_Type *);
  194. extern char *SLexpand_escaped_char(char *, char *);
  195. extern void SLexpand_escaped_string (char *, char *, char *);
  196. extern SLang_Object_Type *_SLreverse_stack (int);
  197. extern SLang_Name_Type *SLang_locate_name(char *);
  198. /* returns a pointer to a MALLOCED string */
  199. extern char *SLstringize_object (SLang_Object_Type *);
  200. /* array types */
  201. typedef struct SLArray_Type
  202. {
  203. unsigned char type; /* int, float, etc... */
  204. int dim; /* # of dims (max 3) */
  205. int x, y, z; /* actual dims */
  206. union
  207. {
  208. unsigned char *c_ptr;
  209. unsigned char **s_ptr;
  210. int *i_ptr;
  211. #ifdef FLOAT_TYPE
  212. float64 *f_ptr;
  213. #endif
  214. SLuser_Object_Type **u_ptr;
  215. }
  216. buf;
  217. unsigned char flags; /* readonly, etc... If this is non-zero,
  218. * the buf pointer will NOT be freed.
  219. * See SLarray_free_array.
  220. */
  221. } SLArray_Type;
  222. /* Callback to delete array */
  223. extern void SLarray_free_array (long *);
  224. /* maximum size of run time stack */
  225. #ifdef msdos
  226. #define SLANG_MAX_STACK_LEN 500
  227. #else
  228. #define SLANG_MAX_STACK_LEN 2500
  229. #endif
  230. #ifdef MSWINDOWS
  231. extern SLang_Object_Type *SLRun_Stack;
  232. #else
  233. extern SLang_Object_Type SLRun_Stack[SLANG_MAX_STACK_LEN];
  234. #endif
  235. extern SLang_Object_Type *SLStack_Pointer;
  236. extern int SLang_Trace;
  237. extern int SLstack_depth(void);
  238. extern void SLang_trace_fun(char *);
  239. extern void SLexecute_function(SLang_Name_Type *);
  240. extern char *SLmake_string (char *);
  241. extern int _SLeqs_name(char *, SLang_Name2_Type *);
  242. extern void SLang_push(SLang_Object_Type *);
  243. extern void SLang_push_float(float64);
  244. extern void SLadd_variable(char *);
  245. extern void SLang_clear_error(void);
  246. extern void SLarray_info (void);
  247. extern int SLPreprocess_Only; /* preprocess instead of
  248. * bytecompiling
  249. */
  250. extern void SLdo_pop (void);
  251. extern unsigned int SLsys_getkey (void);
  252. extern int SLsys_input_pending (int);
  253. #ifdef REAL_UNIX_SYSTEM
  254. extern int SLtt_tigetflag (char *, char **);
  255. extern int SLtt_tigetnum (char *, char **);
  256. extern char *SLtt_tigetstr (char *, char **);
  257. extern char *SLtt_tigetent (char *);
  258. #endif
  259. #ifdef msdos
  260. #define MAX_INPUT_BUFFER_LEN 40
  261. #else
  262. #define MAX_INPUT_BUFFER_LEN 1024
  263. #endif
  264. extern unsigned char SLang_Input_Buffer [MAX_INPUT_BUFFER_LEN];
  265. extern unsigned int SLang_Input_Buffer_Len;
  266. extern int SLregister_types (void);
  267. #ifndef pc_system
  268. extern char *SLtt_Graphics_Char_Pairs;
  269. #endif /* NOT pc_system */
  270. extern void _SLerrno_set_return_status (void);
  271. extern char *_SLerrno_strerror (void);
  272. extern int _SLerrno_Return_Status;