1 /******************************** -*- C -*- **************************** 2 * 3 * Public definitions for extensions to Smalltalk. 4 * 5 * 6 ***********************************************************************/ 7 8 9 /*********************************************************************** 10 * 11 * Copyright 1988,89,90,91,92,94,95,99,2000,2001,2002,2006,2008,2009 12 * Free Software Foundation, Inc. 13 * Written by Steve Byrne and Paolo Bonzini. 14 * 15 * This file is part of GNU Smalltalk. 16 * 17 * GNU Smalltalk is free software; you can redistribute it and/or modify it 18 * under the terms of the GNU General Public License as published by the Free 19 * Software Foundation; either version 2, or (at your option) any later 20 * version. 21 * 22 * Linking GNU Smalltalk statically or dynamically with other modules is 23 * making a combined work based on GNU Smalltalk. Thus, the terms and 24 * conditions of the GNU General Public License cover the whole 25 * combination. 26 * 27 * In addition, as a special exception, the Free Software Foundation 28 * give you permission to combine GNU Smalltalk with free software 29 * programs or libraries that are released under the GNU LGPL and with 30 * independent programs running under the GNU Smalltalk virtual machine. 31 * 32 * You may copy and distribute such a system following the terms of the 33 * GNU GPL for GNU Smalltalk and the licenses of the other code 34 * concerned, provided that you include the source code of that other 35 * code when and as the GNU GPL requires distribution of source code. 36 * 37 * Note that people who make modified versions of GNU Smalltalk are not 38 * obligated to grant this special exception for their modified 39 * versions; it is their choice whether to do so. The GNU General 40 * Public License gives permission to release a modified version without 41 * this exception; this exception also makes it possible to release a 42 * modified version which carries forward this exception. 43 * 44 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT 45 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 47 * more details. 48 * 49 * You should have received a copy of the GNU General Public License along with 50 * GNU Smalltalk; see the file COPYING. If not, write to the Free Software 51 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 52 * 53 ***********************************************************************/ 54 55 56 #ifndef GST_GSTPUB_H 57 #define GST_GSTPUB_H 58 59 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ 60 #if defined(c_plusplus) && !defined(__cplusplus) 61 #define __cplusplus c_plusplus 62 #endif 63 64 #ifdef __cplusplus 65 #include <cstddef> 66 #include <cstdio> 67 extern "C" 68 { 69 #else 70 71 #include <stddef.h> 72 #include <stdio.h> 73 #endif 74 75 #include "gst.h" 76 77 78 typedef struct VMProxy 79 { 80 OOP nilOOP, trueOOP, falseOOP; 81 82 OOP (*msgSend) (OOP receiver, 83 OOP selector, 84 ...); 85 OOP (*vmsgSend) (OOP receiver, 86 OOP selector, 87 OOP * args); 88 OOP (*nvmsgSend) (OOP receiver, 89 OOP selector, 90 OOP * args, 91 int nargs); 92 93 OOP (*strMsgSend) (OOP receiver, 94 const char * selector, 95 ...); 96 void (*msgSendf) (PTR resultPtr, 97 const char *fmt, 98 ...); 99 OOP (*evalExpr) (const char *str); 100 void (*evalCode) (const char *str); 101 102 OOP (*objectAlloc) (OOP classOOP, 103 int size); 104 int (*basicSize) (OOP oop); 105 106 /* Actually funcAddr is a function pointer, but we don't know the 107 returned type so we must declare it as PTR */ 108 void (*defineCFunc) (const char *funcName, 109 PTR funcAddr); 110 OOP (*registerOOP) (OOP oop); 111 void (*unregisterOOP) (OOP oop); 112 113 /* Convert C datatypes to Smalltalk types */ 114 115 OOP (*idToOOP) (long i); 116 OOP (*intToOOP) (long i); 117 OOP (*floatToOOP) (double f); 118 OOP (*boolToOOP) (int b); 119 OOP (*charToOOP) (char c); 120 OOP (*classNameToOOP) (const char *name); 121 OOP (*stringToOOP) (const char *str); 122 OOP (*byteArrayToOOP) (const char *str, 123 int n); 124 OOP (*symbolToOOP) (const char *str); 125 OOP (*cObjectToOOP) (PTR co); 126 OOP (*typeNameToOOP) (const char *name); 127 void (*setCObject) (OOP oop, PTR co); 128 129 /* Convert Smalltalk datatypes to C data types */ 130 131 long (*OOPToC) (OOP oop); /* sometimes answers a PTR */ 132 long (*OOPToId) (OOP oop); 133 long (*OOPToInt) (OOP oop); 134 double (*OOPToFloat) (OOP oop); 135 int (*OOPToBool) (OOP oop); 136 char (*OOPToChar) (OOP oop); 137 char *(*OOPToString) (OOP oop); 138 char *(*OOPToByteArray) (OOP oop); 139 PTR (*OOPToCObject) (OOP oop); 140 141 /* Smalltalk process support */ 142 void (*asyncSignal) (OOP semaphoreOOP); 143 void (*syncWait) (OOP semaphoreOOP); 144 void (*asyncSignalAndUnregister) (OOP semaphoreOOP); 145 146 /* Array-of-OOP registry support. Move these above 147 when we break binary compatibility. */ 148 void (*registerOOPArray) (OOP **first, OOP **last); 149 void (*unregisterOOPArray) (OOP **first); 150 151 /* More conversions. */ 152 long double (*OOPToLongDouble) (OOP oop); 153 OOP (*longDoubleToOOP) (long double f); 154 155 /* More functions, added in 2.2. */ 156 OOP (*getObjectClass) (OOP oop); 157 OOP (*getSuperclass) (OOP oop); 158 mst_Boolean (*classIsKindOf) (OOP oop, 159 OOP candidate); 160 mst_Boolean (*objectIsKindOf) (OOP oop, 161 OOP candidate); 162 OOP (*perform) (OOP oop, 163 OOP selector); 164 OOP (*performWith) (OOP oop, 165 OOP selector, 166 OOP arg); 167 mst_Boolean (*classImplementsSelector) (OOP classOOP, 168 OOP selector); 169 mst_Boolean (*classCanUnderstand) (OOP classOOP, 170 OOP selector); 171 mst_Boolean (*respondsTo) (OOP oop, 172 OOP selector); 173 size_t (*OOPSize) (OOP oop); 174 OOP (*OOPAt) (OOP oop, 175 size_t index); 176 OOP (*OOPAtPut) (OOP oop, 177 size_t index, 178 OOP newOOP); 179 180 /* Some system classes. */ 181 OOP objectClass, arrayClass, stringClass, characterClass, smallIntegerClass, 182 floatDClass, floatEClass, byteArrayClass, objectMemoryClass, classClass, 183 behaviorClass, blockClosureClass, contextPartClass, blockContextClass, 184 methodContextClass, compiledMethodClass, compiledBlockClass, 185 fileDescriptorClass, fileStreamClass, processClass, semaphoreClass, 186 cObjectClass; 187 188 /* More system objects. */ 189 OOP processorOOP; 190 191 /* More functions, added in 2.3. */ 192 OOP (*wcharToOOP) (wchar_t wc); 193 OOP (*wstringToOOP) (const wchar_t *str); 194 wchar_t (*OOPToWChar) (OOP oop); 195 wchar_t *(*OOPToWString) (OOP oop); 196 197 /* 3.0+ functions. */ 198 void (*processStdin) (const char *); 199 mst_Boolean (*processFile) (const char *fileName, enum gst_file_dir dir); 200 int (*getVar) (enum gst_var_index index); 201 int (*setVar) (enum gst_var_index index, int value); 202 void (*invokeHook) (enum gst_vm_hook); 203 204 /* 3.1+ functions. */ 205 char *(*relocatePath) (const char *); 206 void *(*OOPIndexedBase) (OOP oop); 207 enum gst_indexed_kind (*OOPIndexedKind) (OOP oop); 208 void (*asyncCall) (void (*func) (OOP), OOP argOOP); 209 mst_Boolean (*syncSignal) (OOP semaphoreOOP, mst_Boolean incrIfEmpty); 210 void (*showBacktrace) (FILE *fp); 211 212 /* 3.2+ functions. */ 213 mst_Boolean (*dlOpen) (const char *filename, mst_Boolean module); 214 void (*dlAddSearchDir) (const char *dir); 215 void (*dlPushSearchPath) (void); 216 void (*dlPopSearchPath) (void); 217 void (*wakeUp) (void); 218 219 /* 3.2.5+ functions. */ 220 OOP (*uintToOOP) (unsigned long i); 221 } VMProxy; 222 223 /* Compatibility section */ 224 #define indexedWord(obj, n) INDEXED_WORD(obj, n) 225 #define indexedByte(obj, n) INDEXED_BYTE(obj, n) 226 #define indexedOOP(obj, n) INDEXED_OOP(obj, n) 227 #define arrayOOPAt(obj, n) ARRAY_OOP_AT(obj, n) 228 #define stringOOPAt(obj, n) STRING_OOP_AT(obj, n) 229 #define oopToObj(oop) OOP_TO_OBJ(oop) 230 #define oopClass(oop) OOP_CLASS(oop) 231 #define isInt(oop) IS_INT(oop) 232 #define isOOP(oop) IS_OOP(oop) 233 234 /* These are extern in case one wants to link to libgst.a; these 235 are not meant to be called by a module, which is brought up by 236 GNU Smalltalk when the VM is already up and running. */ 237 238 /* These are the library counterparts of the functions in files.h. */ 239 extern void gst_smalltalk_args (int argc, const char **argv); 240 extern int gst_initialize (const char *kernel_dir, 241 const char *image_file, 242 int flags); 243 244 /* Functions in input.h. */ 245 extern void gst_process_stdin (const char *prompt); 246 extern mst_Boolean gst_process_file (const char *fileName, enum gst_file_dir dir); 247 248 /* Functions in interp.h. */ 249 extern int gst_get_var (enum gst_var_index index); 250 extern int gst_set_var (enum gst_var_index index, int value); 251 252 /* Functions in comp.h. */ 253 extern void gst_invoke_hook (enum gst_vm_hook); 254 255 /* Functions in sysdep.h. */ 256 extern void gst_set_executable_path (const char *); 257 extern char *gst_relocate_path (const char *); 258 259 /* Functions in cint.h. */ 260 extern mst_Boolean gst_dlopen (const char *filename, mst_Boolean module); 261 262 /* Add DIR at the beginning of the libltdl search path. */ 263 extern void gst_dladdsearchdir (const char *dir); 264 265 /* Push the current libltdl search path. */ 266 extern void gst_dlpushsearchpath (void); 267 268 /* Pop the saved search path into the current libltdl search path. */ 269 extern void gst_dlpopsearchpath (void); 270 271 /* These are the library counterparts of the functions in 272 gst_vm_proxy. */ 273 extern OOP gst_msg_send (OOP receiver, OOP selector, ...); 274 extern OOP gst_vmsg_send (OOP receiver, OOP selector, OOP * args); 275 extern OOP gst_nvmsg_send (OOP receiver, OOP selector, OOP * args, int nargs); 276 extern OOP gst_str_msg_send (OOP receiver, const char * selector, ...); 277 extern void gst_msg_sendf (PTR result_ptr, const char *fmt, ...); 278 extern OOP gst_eval_expr (const char *str); 279 extern void gst_eval_code (const char *str); 280 extern OOP gst_object_alloc (OOP class_oop, int size); 281 extern int gst_basic_size (OOP oop); 282 extern void gst_define_cfunc (const char *func_name, PTR func_addr); 283 extern OOP gst_register_oop (OOP oop); 284 extern void gst_unregister_oop (OOP oop); 285 extern OOP gst_id_to_oop (long i); 286 extern OOP gst_int_to_oop (long i); 287 extern OOP gst_uint_to_oop (unsigned long i); 288 extern OOP gst_float_to_oop (double f); 289 extern OOP gst_bool_to_oop (int b); 290 extern OOP gst_char_to_oop (char c); 291 extern OOP gst_class_name_to_oop (const char *name); 292 extern OOP gst_string_to_oop (const char *str); 293 extern OOP gst_byte_array_to_oop (const char *str, int n); 294 extern OOP gst_symbol_to_oop (const char *str); 295 extern OOP gst_c_object_to_oop (PTR co); 296 extern OOP gst_type_name_to_oop (const char *name); 297 extern void gst_set_c_o_bject (OOP oop, PTR co); 298 extern long gst_oop_to_c (OOP oop); /* sometimes answers a PTR */ 299 extern long gst_oop_to_id (OOP oop); 300 extern long gst_oop_to_int (OOP oop); 301 extern double gst_oop_to_float (OOP oop); 302 extern int gst_oop_to_bool (OOP oop); 303 extern char gst_oop_to_char (OOP oop); 304 extern char *gst_oop_to_string (OOP oop); 305 extern char *gst_oop_to_byte_array (OOP oop); 306 extern PTR gst_oop_to_c_object (OOP oop); 307 extern void gst_async_signal (OOP semaphore_oop); 308 extern void gst_async_call (void (*func) (OOP), OOP arg_oop); 309 extern mst_Boolean gst_sync_signal (OOP semaphore_oop, mst_Boolean incr_if_empty); 310 extern void gst_sync_wait (OOP semaphore_oop); 311 extern void gst_wakeup (void); 312 extern void gst_show_backtrace (FILE *fp); 313 extern void gst_async_signal_and_unregister (OOP semaphore_oop); 314 extern void gst_register_oop_array (OOP **first, OOP **last); 315 extern void gst_unregister_oop_array (OOP **first); 316 extern long double gst_oop_to_long_double (OOP oop); 317 extern OOP gst_long_double_to_oop (long double f); 318 extern OOP gst_get_object_class (OOP oop); 319 extern OOP gst_get_superclass (OOP oop); 320 extern mst_Boolean gst_class_is_kind_of (OOP oop, OOP candidate); 321 extern mst_Boolean gst_object_is_kind_of (OOP oop, OOP candidate); 322 extern void gst_set_c_object (OOP oop, PTR co); 323 extern OOP gst_perform (OOP oop, OOP selector); 324 extern OOP gst_perform_with (OOP oop, OOP selector, OOP arg); 325 extern mst_Boolean gst_class_implements_selector (OOP class_oop, OOP selector); 326 extern mst_Boolean gst_class_can_understand (OOP class_oop, OOP selector); 327 extern mst_Boolean gst_responds_to (OOP oop, OOP selector); 328 extern size_t gst_oop_size (OOP oop); 329 extern OOP gst_oop_at (OOP oop, size_t index); 330 extern OOP gst_oop_at_put (OOP oop, size_t index, OOP new_oop); 331 extern void *gst_oop_indexed_base (OOP oop); 332 extern enum gst_indexed_kind gst_oop_indexed_kind (OOP oop); 333 extern OOP gst_wchar_to_oop (wchar_t c); 334 extern OOP gst_wstring_to_oop (const wchar_t *str); 335 extern wchar_t gst_oop_to_wchar (OOP oop); 336 extern wchar_t *gst_oop_to_wstring (OOP oop); 337 338 /* This is exclusively for programs who link with libgst.a; plugins 339 should not use this VMProxy but rather the one they receive in 340 gst_initModule. */ 341 extern VMProxy gst_interpreter_proxy; 342 343 #ifdef __cplusplus 344 } 345 #endif 346 347 #endif /* GST_GSTPUB_H */ 348