_slang.h 7.8 KB

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