1 | | |
2 | | |
3 | | |
4 | | |
5 | | |
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
16 | | |
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
47 | | |
48 | | |
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
58 | | |
59 | | |
60 | | |
61 | | |
62 | | |
63 | | |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | |
71 | | |
72 | | |
73 | | |
74 | | |
75 | | |
76 | | |
77 | | |
78 | | |
79 | | |
80 | | |
81 | | |
82 | | |
83 | | |
84 | | |
85 | | |
86 | | |
87 | | |
88 | | |
89 | | |
90 | | |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 | | |
98 | | |
99 | | |
100 | | |
101 | | |
102 | | |
103 | | |
104 | | |
105 | | |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | |
112 | | |
113 | | |
114 | | |
115 | | |
116 | | |
117 | | |
118 | | |
119 | | |
120 | | |
121 | | |
122 | | |
123 | | |
124 | | |
125 | | |
126 | | |
127 | | |
128 | | |
129 | | |
130 | | |
131 | | |
132 | | |
133 | | |
134 | | |
135 | | |
136 | | |
137 | | |
138 | | |
139 | | |
140 | | |
141 | | |
142 | | |
143 | | |
144 | | |
145 | | |
146 | | |
147 | | |
148 | | |
149 | | |
150 | | |
151 | | |
152 | | |
153 | | |
154 | | |
155 | | |
156 | | |
157 | | |
158 | | |
159 | | |
160 | | |
161 | | |
162 | | |
163 | | |
164 | | |
165 | | |
166 | | |
167 | | |
168 | | |
169 | | |
170 | | |
171 | | |
172 | | |
173 | | |
174 | | |
| | | | | | | #include "global.h" | #include "constants.h" | #include "pike_macros.h" | #include "program.h" | #include "pike_types.h" | #include "stralloc.h" | #include "pike_memory.h" | #include "interpret.h" | #include "mapping.h" | #include "error.h" | #include "block_alloc.h" | | RCSID("$Id: constants.c,v 1.22 2000/07/28 17:16:54 hubbe Exp $"); | | struct mapping *builtin_constants = 0; | | PMOD_EXPORT struct mapping *get_builtin_constants(void) | { | if(!builtin_constants) | builtin_constants=allocate_mapping(20); | | return builtin_constants; | } | | void low_add_efun(struct pike_string *name, struct svalue *fun) | { | struct svalue s; | | if(!builtin_constants) | builtin_constants=allocate_mapping(20); | | s.type=T_STRING; | s.subtype=0; | s.u.string=name; | | if(fun) | { | mapping_insert(builtin_constants, &s, fun); | }else{ | map_delete(builtin_constants, &s); | } | } | | void low_add_constant(char *name, struct svalue *fun) | { | struct pike_string *p; | p=make_shared_string(name); | low_add_efun(p, fun); | free_string(p); | } | | PMOD_EXPORT void add_global_program(char *name, struct program *p) | { | struct svalue s; | s.type=T_PROGRAM; | s.subtype=0; | s.u.program=p; | low_add_constant(name, &s); | } | | #undef EXIT_BLOCK | #define EXIT_BLOCK(X) do { \ | free_string(X->type); \ | free_string(X->name); \ | }while(0) | BLOCK_ALLOC(callable,128) | | | PMOD_EXPORT struct callable *low_make_callable(c_fun fun, | struct pike_string *name, | struct pike_string *type, | INT16 flags, | optimize_fun optimize, | docode_fun docode) | { | struct callable *f=alloc_callable(); | f->refs=1; | f->function=fun; | f->name=name; | f->type=type; | f->flags=flags; | f->docode=docode; | f->optimize=optimize; | #ifdef PIKE_DEBUG | { | struct pike_string *z=check_call(function_type_string,type,0); | f->may_return_void= z == void_type_string; | if(!z) fatal("Gnapp!\n"); | free_string(z); | } | #endif | return f; | } | | PMOD_EXPORT struct callable *make_callable(c_fun fun, | char *name, | char *type, | INT16 flags, | optimize_fun optimize, | docode_fun docode) | { | return low_make_callable(fun,make_shared_string(name),parse_type(type),flags,optimize,docode); | } | | PMOD_EXPORT struct callable *add_efun2(char *name, | c_fun fun, | char *type, | INT16 flags, | optimize_fun optimize, | docode_fun docode) | { | struct svalue s; | struct pike_string *n; | struct callable *ret; | | n=make_shared_string(name); | s.type=T_FUNCTION; | s.subtype=FUNCTION_BUILTIN; | ret=s.u.efun=make_callable(fun, name, type, flags, optimize, docode); | low_add_efun(n, &s); | free_svalue(&s); | free_string(n); | return ret; | } | | PMOD_EXPORT struct callable *add_efun(char *name, c_fun fun, char *type, INT16 flags) | { | return add_efun2(name,fun,type,flags,0,0); | } | | PMOD_EXPORT struct callable *quick_add_efun(char *name, int name_length, | c_fun fun, | char *type, int type_length, | INT16 flags, | optimize_fun optimize, | docode_fun docode) | { | struct svalue s; | struct pike_string *n,*t; | struct callable *ret; | | n=make_shared_binary_string(name,name_length); | t=make_shared_binary_string(type,type_length); | #ifdef DEBUG | check_type_string(t); | #endif | s.type=T_FUNCTION; | s.subtype=FUNCTION_BUILTIN; | add_ref(n); | ret=s.u.efun=low_make_callable(fun, n, t, flags, optimize, docode); | low_add_efun(n, &s); | free_svalue(&s); | free_string(n); | return ret; | } | | void cleanup_added_efuns(void) | { | #ifdef DO_PIKE_CLEANUP | if(builtin_constants) | { | free_mapping(builtin_constants); | builtin_constants=0; | } | #endif | } | | |
|