1 /******************************** -*- C -*- ****************************
2 *
3 * Public entry points
4 *
5 * This module provides public routines with a "gst_" prefix.
6 * These are exported by the dynamic library.
7 *
8 *
9 ***********************************************************************/
10
11
12 /***********************************************************************
13 *
14 * Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
15 * Written by Steve Byrne.
16 *
17 * This file is part of GNU Smalltalk.
18 *
19 * GNU Smalltalk is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the Free
21 * Software Foundation; either version 2, or (at your option) any later
22 * version.
23 *
24 * Linking GNU Smalltalk statically or dynamically with other modules is
25 * making a combined work based on GNU Smalltalk. Thus, the terms and
26 * conditions of the GNU General Public License cover the whole
27 * combination.
28 *
29 * In addition, as a special exception, the Free Software Foundation
30 * give you permission to combine GNU Smalltalk with free software
31 * programs or libraries that are released under the GNU LGPL and with
32 * independent programs running under the GNU Smalltalk virtual machine.
33 *
34 * You may copy and distribute such a system following the terms of the
35 * GNU GPL for GNU Smalltalk and the licenses of the other code
36 * concerned, provided that you include the source code of that other
37 * code when and as the GNU GPL requires distribution of source code.
38 *
39 * Note that people who make modified versions of GNU Smalltalk are not
40 * obligated to grant this special exception for their modified
41 * versions; it is their choice whether to do so. The GNU General
42 * Public License gives permission to release a modified version without
43 * this exception; this exception also makes it possible to release a
44 * modified version which carries forward this exception.
45 *
46 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
47 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
49 * more details.
50 *
51 * You should have received a copy of the GNU General Public License along with
52 * GNU Smalltalk; see the file COPYING. If not, write to the Free Software
53 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
54 *
55 return ***********************************************************************/
56
57 #include "gstpriv.h"
58
59 /* By not including this file anywhere else, we make sure that _gst functions
60 are always called, and don't create unnecessary PLA entries. */
61 #include "gstpub.h"
62
63 VMProxy gst_interpreter_proxy = {
64 NULL, NULL, NULL,
65
66 _gst_msg_send, _gst_vmsg_send, _gst_nvmsg_send, _gst_str_msg_send,
67 _gst_msg_sendf,
68 _gst_eval_expr, _gst_eval_code,
69
70 _gst_object_alloc, _gst_basic_size,
71
72 _gst_define_cfunc, _gst_register_oop, _gst_unregister_oop,
73
74 /* Convert C datatypes to Smalltalk types */
75
76 _gst_id_to_oop, _gst_int_to_oop, _gst_float_to_oop, _gst_bool_to_oop,
77 _gst_char_to_oop, _gst_class_name_to_oop,
78 _gst_string_to_oop, _gst_byte_array_to_oop, _gst_symbol_to_oop,
79 _gst_c_object_to_oop, _gst_type_name_to_oop, _gst_set_c_object,
80
81 /* Convert Smalltalk datatypes to C data types */
82
83 _gst_oop_to_c, _gst_oop_to_id, _gst_oop_to_int, _gst_oop_to_float,
84 _gst_oop_to_bool, _gst_oop_to_char,
85 _gst_oop_to_string, _gst_oop_to_byte_array, _gst_oop_to_c_object,
86
87 /* Smalltalk process support */
88 _gst_async_signal, _gst_sync_wait, _gst_async_signal_and_unregister,
89
90 _gst_register_oop_array, _gst_unregister_oop_array,
91
92 /* Convert Smalltalk datatypes to C data types (2) */
93 _gst_oop_to_long_double, _gst_long_double_to_oop,
94
95 _gst_get_object_class, _gst_get_superclass,
96 _gst_class_is_kind_of, _gst_object_is_kind_of,
97 _gst_perform, _gst_perform_with, _gst_class_implements_selector,
98 _gst_class_can_understand, _gst_responds_to,
99 _gst_oop_size, _gst_oop_at, _gst_oop_at_put,
100
101 /* System objects. */
102 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
103 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
104
105 /* New in 2.3. */
106 _gst_wchar_to_oop, _gst_wstring_to_oop,
107 _gst_oop_to_wchar, _gst_oop_to_wstring,
108
109 /* New in 3.0. */
110 _gst_process_stdin,
111 _gst_process_file,
112 _gst_get_var, _gst_set_var,
113 _gst_invoke_hook,
114
115 /* New in 3.1. */
116 _gst_relocate_path,
117 _gst_oop_indexed_base,
118 _gst_oop_indexed_kind,
119 _gst_async_call,
120 _gst_sync_signal,
121 _gst_show_backtrace,
122
123 /* New in 3.2. */
124 _gst_dlopen,
125 _gst_dladdsearchdir,
126 _gst_dlpushsearchpath,
127 _gst_dlpopsearchpath,
128 _gst_wakeup,
129
130 /* New in 3.2.5. */
131 _gst_uint_to_oop
132 };
133
134 /* Functions in comp.h. */
135 void
gst_invoke_hook(enum gst_vm_hook hook)136 gst_invoke_hook (enum gst_vm_hook hook)
137 {
138 _gst_invoke_hook (hook);
139 }
140
141 void
gst_smalltalk_args(int argc,const char ** argv)142 gst_smalltalk_args (int argc,
143 const char **argv)
144 {
145 _gst_smalltalk_args (argc, argv);
146 }
147
148 int
gst_initialize(const char * kernel_dir,const char * image_file,int flags)149 gst_initialize (const char *kernel_dir,
150 const char *image_file,
151 int flags)
152 {
153 return _gst_initialize (kernel_dir, image_file, flags);
154 }
155
gst_process_stdin(const char * prompt)156 void gst_process_stdin (const char *prompt)
157 {
158 _gst_process_stdin (prompt);
159 }
160
161 mst_Boolean
gst_process_file(const char * fileName,enum gst_file_dir dir)162 gst_process_file (const char *fileName, enum gst_file_dir dir)
163 {
164 return _gst_process_file (fileName, dir);
165 }
166
167 int
gst_get_var(enum gst_var_index index)168 gst_get_var (enum gst_var_index index)
169 {
170 return _gst_get_var (index);
171 }
172
173 int
gst_set_var(enum gst_var_index index,int value)174 gst_set_var (enum gst_var_index index, int value)
175 {
176 return _gst_set_var (index, value);
177 }
178
179 OOP
gst_msg_send(OOP receiver,OOP selector,...)180 gst_msg_send (OOP receiver, OOP selector, ...)
181 {
182 va_list ap;
183 va_start (ap, selector);
184 return _gst_va_msg_send (receiver, selector, ap);
185 }
186
187 OOP
gst_vmsg_send(OOP receiver,OOP selector,OOP * args)188 gst_vmsg_send (OOP receiver, OOP selector, OOP * args)
189 {
190 return _gst_vmsg_send (receiver, selector, args);
191 }
192
193 OOP
gst_nvmsg_send(OOP receiver,OOP selector,OOP * args,int nargs)194 gst_nvmsg_send (OOP receiver, OOP selector, OOP * args, int nargs)
195 {
196 return _gst_nvmsg_send (receiver, selector, args, nargs);
197 }
198
199 OOP
gst_str_msg_send(OOP receiver,const char * sel,...)200 gst_str_msg_send (OOP receiver, const char *sel, ...)
201 {
202 va_list ap;
203 OOP selector = _gst_symbol_to_oop (sel);
204 va_start (ap, sel);
205 return _gst_va_msg_send (receiver, selector, ap);
206 }
207
208 void
gst_msg_sendf(PTR result_ptr,const char * fmt,...)209 gst_msg_sendf (PTR result_ptr, const char *fmt, ...)
210 {
211 va_list ap;
212 va_start (ap, fmt);
213 _gst_va_msg_sendf (result_ptr, fmt, ap);
214 }
215
216 OOP
gst_eval_expr(const char * str)217 gst_eval_expr (const char *str)
218 {
219 return _gst_eval_expr (str);
220 }
221
222 void
gst_eval_code(const char * str)223 gst_eval_code (const char *str)
224 {
225 _gst_eval_code (str);
226 }
227
228 OOP
gst_object_alloc(OOP class_oop,int size)229 gst_object_alloc (OOP class_oop, int size)
230 {
231 return _gst_object_alloc (class_oop, size);
232 }
233
234 int
gst_basic_size(OOP oop)235 gst_basic_size (OOP oop)
236 {
237 return _gst_basic_size (oop);
238 }
239
240 void
gst_define_cfunc(const char * func_name,PTR func_addr)241 gst_define_cfunc (const char *func_name, PTR func_addr)
242 {
243 _gst_define_cfunc (func_name, func_addr);
244 }
245
246 OOP
gst_register_oop(OOP oop)247 gst_register_oop (OOP oop)
248 {
249 return _gst_register_oop (oop);
250 }
251
252 void
gst_unregister_oop(OOP oop)253 gst_unregister_oop (OOP oop)
254 {
255 _gst_unregister_oop (oop);
256 }
257
258 OOP
gst_id_to_oop(long i)259 gst_id_to_oop (long i)
260 {
261 return _gst_id_to_oop (i);
262 }
263
264 OOP
gst_int_to_oop(long i)265 gst_int_to_oop (long i)
266 {
267 return _gst_int_to_oop (i);
268 }
269
270 OOP
gst_uint_to_oop(unsigned long i)271 gst_uint_to_oop (unsigned long i)
272 {
273 return _gst_uint_to_oop (i);
274 }
275
276 OOP
gst_float_to_oop(double f)277 gst_float_to_oop (double f)
278 {
279 return _gst_float_to_oop (f);
280 }
281
282 OOP
gst_bool_to_oop(int b)283 gst_bool_to_oop (int b)
284 {
285 return _gst_bool_to_oop (b);
286 }
287
288 OOP
gst_char_to_oop(char c)289 gst_char_to_oop (char c)
290 {
291 return _gst_char_to_oop (c);
292 }
293
294 OOP
gst_class_name_to_oop(const char * name)295 gst_class_name_to_oop (const char *name)
296 {
297 return _gst_class_name_to_oop (name);
298 }
299
300 OOP
gst_string_to_oop(const char * str)301 gst_string_to_oop (const char *str)
302 {
303 return _gst_string_to_oop (str);
304 }
305
306 OOP
gst_byte_array_to_oop(const char * str,int n)307 gst_byte_array_to_oop (const char *str, int n)
308 {
309 return _gst_byte_array_to_oop (str, n);
310 }
311
312 OOP
gst_symbol_to_oop(const char * str)313 gst_symbol_to_oop (const char *str)
314 {
315 return _gst_symbol_to_oop (str);
316 }
317
318 OOP
gst_c_object_to_oop(PTR co)319 gst_c_object_to_oop (PTR co)
320 {
321 return _gst_c_object_to_oop (co);
322 }
323
324 OOP
gst_type_name_to_oop(const char * name)325 gst_type_name_to_oop (const char *name)
326 {
327 return _gst_type_name_to_oop (name);
328 }
329
330 void
gst_set_c_object(OOP oop,PTR co)331 gst_set_c_object (OOP oop, PTR co)
332 {
333 _gst_set_c_object (oop, co);
334 }
335
336 long
gst_oop_to_c(OOP oop)337 gst_oop_to_c (OOP oop)
338 {
339 return _gst_oop_to_c (oop);
340 } /*sometimes answers a PTR */
341
342 long
gst_oop_to_id(OOP oop)343 gst_oop_to_id (OOP oop)
344 {
345 return _gst_oop_to_id (oop);
346 }
347
348 long
gst_oop_to_int(OOP oop)349 gst_oop_to_int (OOP oop)
350 {
351 return _gst_oop_to_int (oop);
352 }
353
354 double
gst_oop_to_float(OOP oop)355 gst_oop_to_float (OOP oop)
356 {
357 return _gst_oop_to_float (oop);
358 }
359
360 int
gst_oop_to_bool(OOP oop)361 gst_oop_to_bool (OOP oop)
362 {
363 return _gst_oop_to_bool (oop);
364 }
365
366 char
gst_oop_to_char(OOP oop)367 gst_oop_to_char (OOP oop)
368 {
369 return _gst_oop_to_char (oop);
370 }
371
372 char *
gst_oop_to_string(OOP oop)373 gst_oop_to_string (OOP oop)
374 {
375 return _gst_oop_to_string (oop);
376 }
377
378 char *
gst_oop_to_byte_array(OOP oop)379 gst_oop_to_byte_array (OOP oop)
380 {
381 return _gst_oop_to_byte_array (oop);
382 }
383
384 PTR
gst_oop_to_c_object(OOP oop)385 gst_oop_to_c_object (OOP oop)
386 {
387 return _gst_oop_to_c_object (oop);
388 }
389
390 void
gst_async_signal(OOP semaphore_oop)391 gst_async_signal (OOP semaphore_oop)
392 {
393 _gst_async_signal (semaphore_oop);
394 }
395
396 void
gst_sync_wait(OOP semaphore_oop)397 gst_sync_wait (OOP semaphore_oop)
398 {
399 _gst_sync_wait (semaphore_oop);
400 }
401
402 void
gst_async_signal_and_unregister(OOP semaphore_oop)403 gst_async_signal_and_unregister (OOP semaphore_oop)
404 {
405 _gst_async_signal_and_unregister (semaphore_oop);
406 }
407
408 mst_Boolean
gst_sync_signal(OOP semaphore_oop,mst_Boolean incr_if_empty)409 gst_sync_signal (OOP semaphore_oop, mst_Boolean incr_if_empty)
410 {
411 return _gst_sync_signal (semaphore_oop, incr_if_empty);
412 }
413
414 void
gst_async_call(void (* func)(OOP),OOP semaphore_oop)415 gst_async_call (void (*func) (OOP), OOP semaphore_oop)
416 {
417 _gst_async_call (func, semaphore_oop);
418 }
419
420 void
gst_show_backtrace(FILE * fp)421 gst_show_backtrace (FILE *fp)
422 {
423 _gst_show_backtrace (fp);
424 }
425
426 mst_Boolean
gst_dlopen(const char * filename,mst_Boolean module)427 gst_dlopen (const char *filename, mst_Boolean module)
428 {
429 return _gst_dlopen (filename, module);
430 }
431
432 void
gst_dladdsearchdir(const char * dir)433 gst_dladdsearchdir (const char *dir)
434 {
435 _gst_dladdsearchdir (dir);
436 }
437
438 void
gst_dlpushsearchpath(void)439 gst_dlpushsearchpath (void)
440 {
441 _gst_dlpushsearchpath ();
442 }
443
444 void
gst_dlpopsearchpath(void)445 gst_dlpopsearchpath (void)
446 {
447 _gst_dlpopsearchpath ();
448 }
449
450 void
gst_wakeup()451 gst_wakeup ()
452 {
453 _gst_wakeup ();
454 }
455
456 void
gst_register_oop_array(OOP ** first,OOP ** last)457 gst_register_oop_array (OOP **first, OOP **last)
458 {
459 _gst_register_oop_array (first, last);
460 }
461
462 void
gst_unregister_oop_array(OOP ** first)463 gst_unregister_oop_array (OOP **first)
464 {
465 _gst_unregister_oop_array (first);
466 }
467
468 long double
gst_oop_to_long_double(OOP oop)469 gst_oop_to_long_double (OOP oop)
470 {
471 return _gst_oop_to_long_double (oop);
472 }
473
474 OOP
gst_long_double_to_oop(long double f)475 gst_long_double_to_oop (long double f)
476 {
477 return _gst_long_double_to_oop (f);
478 }
479
480 OOP
gst_wchar_to_oop(wchar_t c)481 gst_wchar_to_oop (wchar_t c)
482 {
483 return _gst_wchar_to_oop (c);
484 }
485
486 OOP
gst_wstring_to_oop(const wchar_t * str)487 gst_wstring_to_oop (const wchar_t *str)
488 {
489 return _gst_wstring_to_oop (str);
490 }
491
492 wchar_t
gst_oop_to_wchar(OOP oop)493 gst_oop_to_wchar (OOP oop)
494 {
495 return _gst_oop_to_wchar (oop);
496 }
497
498 wchar_t *
gst_oop_to_wstring(OOP oop)499 gst_oop_to_wstring (OOP oop)
500 {
501 return _gst_oop_to_wstring (oop);
502 }
503
504 OOP
gst_get_object_class(OOP oop)505 gst_get_object_class (OOP oop)
506 {
507 return _gst_get_object_class (oop);
508 }
509
510 OOP
gst_get_superclass(OOP oop)511 gst_get_superclass (OOP oop)
512 {
513 return _gst_get_superclass (oop);
514 }
515
516 mst_Boolean
gst_class_is_kind_of(OOP oop,OOP candidate)517 gst_class_is_kind_of (OOP oop, OOP candidate)
518 {
519 return _gst_class_is_kind_of (oop, candidate);
520 }
521
522 mst_Boolean
gst_object_is_kind_of(OOP oop,OOP candidate)523 gst_object_is_kind_of (OOP oop, OOP candidate)
524 {
525 return _gst_object_is_kind_of (oop, candidate);
526 }
527
528 OOP
gst_perform(OOP oop,OOP selector)529 gst_perform (OOP oop, OOP selector)
530 {
531 return _gst_perform (oop, selector);
532 }
533
534 OOP
gst_perform_with(OOP oop,OOP selector,OOP arg)535 gst_perform_with (OOP oop, OOP selector, OOP arg)
536 {
537 return _gst_perform_with (oop, selector, arg);
538 }
539
540 mst_Boolean
gst_class_implements_selector(OOP class_oop,OOP selector)541 gst_class_implements_selector (OOP class_oop, OOP selector)
542 {
543 return _gst_class_implements_selector (class_oop, selector);
544 }
545
gst_class_can_understand(OOP class_oop,OOP selector)546 mst_Boolean gst_class_can_understand (OOP class_oop, OOP selector)
547 {
548 return _gst_class_can_understand (class_oop, selector);
549 }
550
551 mst_Boolean
gst_responds_to(OOP oop,OOP selector)552 gst_responds_to (OOP oop, OOP selector)
553 {
554 return _gst_responds_to (oop, selector);
555 }
556
557 size_t
gst_oop_size(OOP oop)558 gst_oop_size (OOP oop)
559 {
560 return _gst_oop_size (oop);
561 }
562
563 OOP
gst_oop_at(OOP oop,size_t index)564 gst_oop_at (OOP oop, size_t index)
565 {
566 return _gst_oop_at (oop, index);
567 }
568
569 OOP
gst_oop_at_put(OOP oop,size_t index,OOP new_oop)570 gst_oop_at_put (OOP oop, size_t index, OOP new_oop)
571 {
572 return _gst_oop_at_put (oop, index, new_oop);
573 }
574
575 enum gst_indexed_kind
gst_oop_indexed_kind(OOP oop)576 gst_oop_indexed_kind (OOP oop)
577 {
578 return _gst_oop_indexed_kind (oop);
579 }
580
581 void *
gst_oop_indexed_base(OOP oop)582 gst_oop_indexed_base (OOP oop)
583 {
584 return _gst_oop_indexed_base (oop);
585 }
586
587
588 /* Functions in sysdep.h. */
589 void
gst_set_executable_path(const char * argv0)590 gst_set_executable_path (const char *argv0)
591 {
592 _gst_set_executable_path (argv0);
593 }
594
595 char *
gst_relocate_path(const char * path)596 gst_relocate_path (const char *path)
597 {
598 return _gst_relocate_path (path);
599 }
600
601