Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/c-libs/c-libraries.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/c-libs/c-libraries.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 569 - (view) (download) (as text)

1 : monnier 249 /* c-libraries.c
2 :     *
3 :     * COPYRIGHT (c) 1994 AT&T Bell Laboratories.
4 :     *
5 :     * This is the home of the CLibrary table, C library initialization code,
6 :     * and C function lookup code. It is part of the run-time proper (not part
7 :     * of libcfuns.a).
8 :     */
9 :    
10 : blume 569 #include <stdio.h>
11 :    
12 : monnier 249 #ifdef OPSYS_UNIX
13 :     # include "ml-unixdep.h" /* for the HAS_POSIX_LIBRARIES option flag */
14 :     #endif
15 :     #include "ml-base.h"
16 :     #include "ml-values.h"
17 :     #include "c-library.h"
18 : blume 569 #include "c-globals-tbl.h"
19 : monnier 249
20 :     #define C_LIBRARY(lib) extern c_library_t lib;
21 :     #include "clib-list.h"
22 :     #undef C_LIBRARY
23 :    
24 :     PVT c_library_t *CLibs[] = {
25 :     #define C_LIBRARY(lib) &lib,
26 :     # include "clib-list.h"
27 :     #undef C_LIBRARY
28 :     NIL(c_library_t *)
29 :     };
30 :    
31 :     /* InitCFunList:
32 :     * Initialize the list of C functions callable from ML.
33 :     */
34 :     void InitCFunList ()
35 :     {
36 :     int i, j, libNameLen;
37 :     char *nameBuf;
38 :    
39 :     for (i = 0; CLibs[i] != NIL(c_library_t *); i++) {
40 :     c_library_t *clib = CLibs[i];
41 :     cfunc_binding_t *cfuns = CLibs[i]->cfuns;
42 :    
43 :     if (clib->initFn != NIL(clib_init_fn_t)) {
44 :     /* call the libraries initialization function */
45 :     (*(clib->initFn)) (0, 0/** argc, argv **/);
46 :     }
47 :    
48 :     /* register the C functions in the C symbol table */
49 :     libNameLen = strlen(clib->libName) + 2; /* incl "." and "\0" */
50 :     for (j = 0; cfuns[j].name != NIL(char *); j++) {
51 :     nameBuf = NEW_VEC(char, strlen(cfuns[j].name) + libNameLen);
52 :     sprintf (nameBuf, "%s.%s", clib->libName, cfuns[j].name);
53 :     #ifdef INDIRECT_CFUNC
54 :     RecordCSymbol (nameBuf, PTR_CtoML(&(cfuns[j])));
55 :     #else
56 :     RecordCSymbol (nameBuf, PTR_CtoML(cfuns[j].cfunc));
57 :     #endif
58 :     }
59 :     }
60 :    
61 :     } /* end of InitCFunList */
62 :    
63 :     /* BindCFun:
64 :     *
65 :     * Search the C function table for the given function; return ML_unit, if
66 :     * not found.
67 :     * NOTE: eventually, we will raise an exception when the function isn't found.
68 :     */
69 :     ml_val_t BindCFun (char *moduleName, char *funName)
70 :     {
71 :     int i, j;
72 :    
73 :     /* SayDebug("BIND: %s.%s\n", moduleName, funName); */
74 :     for (i = 0; CLibs[i] != NIL(c_library_t *); i++) {
75 :     if (strcmp(CLibs[i]->libName, moduleName) == 0) {
76 :     cfunc_binding_t *cfuns = CLibs[i]->cfuns;
77 :     for (j = 0; cfuns[j].name != NIL(char *); j++) {
78 :     if (strcmp(cfuns[j].name, funName) == 0)
79 :     #ifdef INDIRECT_CFUNC
80 :     return PTR_CtoML(&(cfuns[j]));
81 :     #else
82 :     return PTR_CtoML(cfuns[j].cfunc);
83 :     #endif
84 :     }
85 :     /* here, we didn't find the library so we return ML_unit */
86 :     return ML_unit;
87 :     }
88 :     }
89 :    
90 :     /* here, we didn't find the library so we return ML_unit */
91 :     return ML_unit;
92 :    
93 :     } /* end of BindCFun */
94 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0