Rewrite gen_ext_hhvm and gen_infotabs in C++
[hiphop-php.git] / hphp / runtime / ext / ext_variable.ext_hhvm.cpp
blob2fbe9dc2e2fe81558f730346a59c0270b39adf9d
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #include "runtime/ext_hhvm/ext_hhvm.h"
19 #include "runtime/base/builtin_functions.h"
20 #include "runtime/base/array/array_init.h"
21 #include "runtime/ext/ext.h"
22 #include "runtime/vm/class.h"
23 #include "runtime/vm/runtime.h"
24 #include <exception>
26 namespace HPHP {
28 Value* fh_gettype(Value* _rv, TypedValue* v) asm("_ZN4HPHP9f_gettypeERKNS_7VariantE");
30 TypedValue* fg_gettype(ActRec* ar) {
31 TypedValue rvSpace;
32 TypedValue* rv = &rvSpace;
33 int32_t count = ar->numArgs();
34 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
35 if (count == 1) {
36 rv->m_type = KindOfString;
37 fh_gettype(&(rv->m_data), (args-0));
38 if (rv->m_data.num == 0LL) rv->m_type = KindOfNull;
39 } else {
40 throw_wrong_arguments_nr("gettype", count, 1, 1, 1);
41 rv->m_data.num = 0LL;
42 rv->m_type = KindOfNull;
44 frame_free_locals_no_this_inl(ar, 1);
45 memcpy(&ar->m_r, rv, sizeof(TypedValue));
46 return &ar->m_r;
49 Value* fh_get_resource_type(Value* _rv, Value* handle) asm("_ZN4HPHP19f_get_resource_typeERKNS_6ObjectE");
51 void fg1_get_resource_type(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
52 void fg1_get_resource_type(TypedValue* rv, ActRec* ar, int32_t count) {
53 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
54 tvCastToObjectInPlace(args-0);
55 rv->m_type = KindOfString;
56 fh_get_resource_type(&(rv->m_data), &args[-0].m_data);
57 if (rv->m_data.num == 0LL) rv->m_type = KindOfNull;
60 TypedValue* fg_get_resource_type(ActRec* ar) {
61 TypedValue rvSpace;
62 TypedValue* rv = &rvSpace;
63 int32_t count = ar->numArgs();
64 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
65 if (count == 1) {
66 if ((args - 0)->m_type == KindOfObject) {
67 rv->m_type = KindOfString;
68 fh_get_resource_type(&(rv->m_data), &args[-0].m_data);
69 if (rv->m_data.num == 0LL) rv->m_type = KindOfNull;
70 } else {
71 fg1_get_resource_type(rv, ar, count);
73 } else {
74 throw_wrong_arguments_nr("get_resource_type", count, 1, 1, 1);
75 rv->m_data.num = 0LL;
76 rv->m_type = KindOfNull;
78 frame_free_locals_no_this_inl(ar, 1);
79 memcpy(&ar->m_r, rv, sizeof(TypedValue));
80 return &ar->m_r;
83 long fh_intval(TypedValue* v, long base) asm("_ZN4HPHP8f_intvalERKNS_7VariantEl");
85 void fg1_intval(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
86 void fg1_intval(TypedValue* rv, ActRec* ar, int32_t count) {
87 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
88 tvCastToInt64InPlace(args-1);
89 rv->m_type = KindOfInt64;
90 rv->m_data.num = (int64_t)fh_intval((args-0), (count > 1) ? (long)(args[-1].m_data.num) : (long)(10));
93 TypedValue* fg_intval(ActRec* ar) {
94 TypedValue rvSpace;
95 TypedValue* rv = &rvSpace;
96 int32_t count = ar->numArgs();
97 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
98 if (count >= 1 && count <= 2) {
99 if ((count <= 1 || (args - 1)->m_type == KindOfInt64)) {
100 rv->m_type = KindOfInt64;
101 rv->m_data.num = (int64_t)fh_intval((args-0), (count > 1) ? (long)(args[-1].m_data.num) : (long)(10));
102 } else {
103 fg1_intval(rv, ar, count);
105 } else {
106 throw_wrong_arguments_nr("intval", count, 1, 2, 1);
107 rv->m_data.num = 0LL;
108 rv->m_type = KindOfNull;
110 frame_free_locals_no_this_inl(ar, 2);
111 memcpy(&ar->m_r, rv, sizeof(TypedValue));
112 return &ar->m_r;
115 double fh_doubleval(TypedValue* v) asm("_ZN4HPHP11f_doublevalERKNS_7VariantE");
117 TypedValue* fg_doubleval(ActRec* ar) {
118 TypedValue rvSpace;
119 TypedValue* rv = &rvSpace;
120 int32_t count = ar->numArgs();
121 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
122 if (count == 1) {
123 rv->m_type = KindOfDouble;
124 rv->m_data.dbl = fh_doubleval((args-0));
125 } else {
126 throw_wrong_arguments_nr("doubleval", count, 1, 1, 1);
127 rv->m_data.num = 0LL;
128 rv->m_type = KindOfNull;
130 frame_free_locals_no_this_inl(ar, 1);
131 memcpy(&ar->m_r, rv, sizeof(TypedValue));
132 return &ar->m_r;
135 double fh_floatval(TypedValue* v) asm("_ZN4HPHP10f_floatvalERKNS_7VariantE");
137 TypedValue* fg_floatval(ActRec* ar) {
138 TypedValue rvSpace;
139 TypedValue* rv = &rvSpace;
140 int32_t count = ar->numArgs();
141 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
142 if (count == 1) {
143 rv->m_type = KindOfDouble;
144 rv->m_data.dbl = fh_floatval((args-0));
145 } else {
146 throw_wrong_arguments_nr("floatval", count, 1, 1, 1);
147 rv->m_data.num = 0LL;
148 rv->m_type = KindOfNull;
150 frame_free_locals_no_this_inl(ar, 1);
151 memcpy(&ar->m_r, rv, sizeof(TypedValue));
152 return &ar->m_r;
155 Value* fh_strval(Value* _rv, TypedValue* v) asm("_ZN4HPHP8f_strvalERKNS_7VariantE");
157 TypedValue* fg_strval(ActRec* ar) {
158 TypedValue rvSpace;
159 TypedValue* rv = &rvSpace;
160 int32_t count = ar->numArgs();
161 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
162 if (count == 1) {
163 rv->m_type = KindOfString;
164 fh_strval(&(rv->m_data), (args-0));
165 if (rv->m_data.num == 0LL) rv->m_type = KindOfNull;
166 } else {
167 throw_wrong_arguments_nr("strval", count, 1, 1, 1);
168 rv->m_data.num = 0LL;
169 rv->m_type = KindOfNull;
171 frame_free_locals_no_this_inl(ar, 1);
172 memcpy(&ar->m_r, rv, sizeof(TypedValue));
173 return &ar->m_r;
176 bool fh_settype(TypedValue* var, Value* type) asm("_ZN4HPHP9f_settypeERKNS_14VRefParamValueERKNS_6StringE");
178 void fg1_settype(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
179 void fg1_settype(TypedValue* rv, ActRec* ar, int32_t count) {
180 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
181 tvCastToStringInPlace(args-1);
182 rv->m_type = KindOfBoolean;
183 rv->m_data.num = (fh_settype((args-0), &args[-1].m_data)) ? 1LL : 0LL;
186 TypedValue* fg_settype(ActRec* ar) {
187 TypedValue rvSpace;
188 TypedValue* rv = &rvSpace;
189 int32_t count = ar->numArgs();
190 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
191 if (count == 2) {
192 if (IS_STRING_TYPE((args - 1)->m_type)) {
193 rv->m_type = KindOfBoolean;
194 rv->m_data.num = (fh_settype((args-0), &args[-1].m_data)) ? 1LL : 0LL;
195 } else {
196 fg1_settype(rv, ar, count);
198 } else {
199 throw_wrong_arguments_nr("settype", count, 2, 2, 1);
200 rv->m_data.num = 0LL;
201 rv->m_type = KindOfNull;
203 frame_free_locals_no_this_inl(ar, 2);
204 memcpy(&ar->m_r, rv, sizeof(TypedValue));
205 return &ar->m_r;
208 bool fh_is_bool(TypedValue* var) asm("_ZN4HPHP9f_is_boolERKNS_7VariantE");
210 TypedValue* fg_is_bool(ActRec* ar) {
211 TypedValue rvSpace;
212 TypedValue* rv = &rvSpace;
213 int32_t count = ar->numArgs();
214 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
215 if (count == 1) {
216 rv->m_type = KindOfBoolean;
217 rv->m_data.num = (fh_is_bool((args-0))) ? 1LL : 0LL;
218 } else {
219 throw_wrong_arguments_nr("is_bool", count, 1, 1, 1);
220 rv->m_data.num = 0LL;
221 rv->m_type = KindOfNull;
223 frame_free_locals_no_this_inl(ar, 1);
224 memcpy(&ar->m_r, rv, sizeof(TypedValue));
225 return &ar->m_r;
228 bool fh_is_int(TypedValue* var) asm("_ZN4HPHP8f_is_intERKNS_7VariantE");
230 TypedValue* fg_is_int(ActRec* ar) {
231 TypedValue rvSpace;
232 TypedValue* rv = &rvSpace;
233 int32_t count = ar->numArgs();
234 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
235 if (count == 1) {
236 rv->m_type = KindOfBoolean;
237 rv->m_data.num = (fh_is_int((args-0))) ? 1LL : 0LL;
238 } else {
239 throw_wrong_arguments_nr("is_int", count, 1, 1, 1);
240 rv->m_data.num = 0LL;
241 rv->m_type = KindOfNull;
243 frame_free_locals_no_this_inl(ar, 1);
244 memcpy(&ar->m_r, rv, sizeof(TypedValue));
245 return &ar->m_r;
248 bool fh_is_integer(TypedValue* var) asm("_ZN4HPHP12f_is_integerERKNS_7VariantE");
250 TypedValue* fg_is_integer(ActRec* ar) {
251 TypedValue rvSpace;
252 TypedValue* rv = &rvSpace;
253 int32_t count = ar->numArgs();
254 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
255 if (count == 1) {
256 rv->m_type = KindOfBoolean;
257 rv->m_data.num = (fh_is_integer((args-0))) ? 1LL : 0LL;
258 } else {
259 throw_wrong_arguments_nr("is_integer", count, 1, 1, 1);
260 rv->m_data.num = 0LL;
261 rv->m_type = KindOfNull;
263 frame_free_locals_no_this_inl(ar, 1);
264 memcpy(&ar->m_r, rv, sizeof(TypedValue));
265 return &ar->m_r;
268 bool fh_is_long(TypedValue* var) asm("_ZN4HPHP9f_is_longERKNS_7VariantE");
270 TypedValue* fg_is_long(ActRec* ar) {
271 TypedValue rvSpace;
272 TypedValue* rv = &rvSpace;
273 int32_t count = ar->numArgs();
274 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
275 if (count == 1) {
276 rv->m_type = KindOfBoolean;
277 rv->m_data.num = (fh_is_long((args-0))) ? 1LL : 0LL;
278 } else {
279 throw_wrong_arguments_nr("is_long", count, 1, 1, 1);
280 rv->m_data.num = 0LL;
281 rv->m_type = KindOfNull;
283 frame_free_locals_no_this_inl(ar, 1);
284 memcpy(&ar->m_r, rv, sizeof(TypedValue));
285 return &ar->m_r;
288 bool fh_is_double(TypedValue* var) asm("_ZN4HPHP11f_is_doubleERKNS_7VariantE");
290 TypedValue* fg_is_double(ActRec* ar) {
291 TypedValue rvSpace;
292 TypedValue* rv = &rvSpace;
293 int32_t count = ar->numArgs();
294 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
295 if (count == 1) {
296 rv->m_type = KindOfBoolean;
297 rv->m_data.num = (fh_is_double((args-0))) ? 1LL : 0LL;
298 } else {
299 throw_wrong_arguments_nr("is_double", count, 1, 1, 1);
300 rv->m_data.num = 0LL;
301 rv->m_type = KindOfNull;
303 frame_free_locals_no_this_inl(ar, 1);
304 memcpy(&ar->m_r, rv, sizeof(TypedValue));
305 return &ar->m_r;
308 bool fh_is_float(TypedValue* var) asm("_ZN4HPHP10f_is_floatERKNS_7VariantE");
310 TypedValue* fg_is_float(ActRec* ar) {
311 TypedValue rvSpace;
312 TypedValue* rv = &rvSpace;
313 int32_t count = ar->numArgs();
314 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
315 if (count == 1) {
316 rv->m_type = KindOfBoolean;
317 rv->m_data.num = (fh_is_float((args-0))) ? 1LL : 0LL;
318 } else {
319 throw_wrong_arguments_nr("is_float", count, 1, 1, 1);
320 rv->m_data.num = 0LL;
321 rv->m_type = KindOfNull;
323 frame_free_locals_no_this_inl(ar, 1);
324 memcpy(&ar->m_r, rv, sizeof(TypedValue));
325 return &ar->m_r;
328 bool fh_is_numeric(TypedValue* var) asm("_ZN4HPHP12f_is_numericERKNS_7VariantE");
330 TypedValue* fg_is_numeric(ActRec* ar) {
331 TypedValue rvSpace;
332 TypedValue* rv = &rvSpace;
333 int32_t count = ar->numArgs();
334 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
335 if (count == 1) {
336 rv->m_type = KindOfBoolean;
337 rv->m_data.num = (fh_is_numeric((args-0))) ? 1LL : 0LL;
338 } else {
339 throw_wrong_arguments_nr("is_numeric", count, 1, 1, 1);
340 rv->m_data.num = 0LL;
341 rv->m_type = KindOfNull;
343 frame_free_locals_no_this_inl(ar, 1);
344 memcpy(&ar->m_r, rv, sizeof(TypedValue));
345 return &ar->m_r;
348 bool fh_is_real(TypedValue* var) asm("_ZN4HPHP9f_is_realERKNS_7VariantE");
350 TypedValue* fg_is_real(ActRec* ar) {
351 TypedValue rvSpace;
352 TypedValue* rv = &rvSpace;
353 int32_t count = ar->numArgs();
354 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
355 if (count == 1) {
356 rv->m_type = KindOfBoolean;
357 rv->m_data.num = (fh_is_real((args-0))) ? 1LL : 0LL;
358 } else {
359 throw_wrong_arguments_nr("is_real", count, 1, 1, 1);
360 rv->m_data.num = 0LL;
361 rv->m_type = KindOfNull;
363 frame_free_locals_no_this_inl(ar, 1);
364 memcpy(&ar->m_r, rv, sizeof(TypedValue));
365 return &ar->m_r;
368 bool fh_is_string(TypedValue* var) asm("_ZN4HPHP11f_is_stringERKNS_7VariantE");
370 TypedValue* fg_is_string(ActRec* ar) {
371 TypedValue rvSpace;
372 TypedValue* rv = &rvSpace;
373 int32_t count = ar->numArgs();
374 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
375 if (count == 1) {
376 rv->m_type = KindOfBoolean;
377 rv->m_data.num = (fh_is_string((args-0))) ? 1LL : 0LL;
378 } else {
379 throw_wrong_arguments_nr("is_string", count, 1, 1, 1);
380 rv->m_data.num = 0LL;
381 rv->m_type = KindOfNull;
383 frame_free_locals_no_this_inl(ar, 1);
384 memcpy(&ar->m_r, rv, sizeof(TypedValue));
385 return &ar->m_r;
388 bool fh_is_scalar(TypedValue* var) asm("_ZN4HPHP11f_is_scalarERKNS_7VariantE");
390 TypedValue* fg_is_scalar(ActRec* ar) {
391 TypedValue rvSpace;
392 TypedValue* rv = &rvSpace;
393 int32_t count = ar->numArgs();
394 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
395 if (count == 1) {
396 rv->m_type = KindOfBoolean;
397 rv->m_data.num = (fh_is_scalar((args-0))) ? 1LL : 0LL;
398 } else {
399 throw_wrong_arguments_nr("is_scalar", count, 1, 1, 1);
400 rv->m_data.num = 0LL;
401 rv->m_type = KindOfNull;
403 frame_free_locals_no_this_inl(ar, 1);
404 memcpy(&ar->m_r, rv, sizeof(TypedValue));
405 return &ar->m_r;
408 bool fh_is_array(TypedValue* var) asm("_ZN4HPHP10f_is_arrayERKNS_7VariantE");
410 TypedValue* fg_is_array(ActRec* ar) {
411 TypedValue rvSpace;
412 TypedValue* rv = &rvSpace;
413 int32_t count = ar->numArgs();
414 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
415 if (count == 1) {
416 rv->m_type = KindOfBoolean;
417 rv->m_data.num = (fh_is_array((args-0))) ? 1LL : 0LL;
418 } else {
419 throw_wrong_arguments_nr("is_array", count, 1, 1, 1);
420 rv->m_data.num = 0LL;
421 rv->m_type = KindOfNull;
423 frame_free_locals_no_this_inl(ar, 1);
424 memcpy(&ar->m_r, rv, sizeof(TypedValue));
425 return &ar->m_r;
428 bool fh_is_object(TypedValue* var) asm("_ZN4HPHP11f_is_objectERKNS_7VariantE");
430 TypedValue* fg_is_object(ActRec* ar) {
431 TypedValue rvSpace;
432 TypedValue* rv = &rvSpace;
433 int32_t count = ar->numArgs();
434 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
435 if (count == 1) {
436 rv->m_type = KindOfBoolean;
437 rv->m_data.num = (fh_is_object((args-0))) ? 1LL : 0LL;
438 } else {
439 throw_wrong_arguments_nr("is_object", count, 1, 1, 1);
440 rv->m_data.num = 0LL;
441 rv->m_type = KindOfNull;
443 frame_free_locals_no_this_inl(ar, 1);
444 memcpy(&ar->m_r, rv, sizeof(TypedValue));
445 return &ar->m_r;
448 bool fh_is_resource(TypedValue* var) asm("_ZN4HPHP13f_is_resourceERKNS_7VariantE");
450 TypedValue* fg_is_resource(ActRec* ar) {
451 TypedValue rvSpace;
452 TypedValue* rv = &rvSpace;
453 int32_t count = ar->numArgs();
454 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
455 if (count == 1) {
456 rv->m_type = KindOfBoolean;
457 rv->m_data.num = (fh_is_resource((args-0))) ? 1LL : 0LL;
458 } else {
459 throw_wrong_arguments_nr("is_resource", count, 1, 1, 1);
460 rv->m_data.num = 0LL;
461 rv->m_type = KindOfNull;
463 frame_free_locals_no_this_inl(ar, 1);
464 memcpy(&ar->m_r, rv, sizeof(TypedValue));
465 return &ar->m_r;
468 bool fh_is_null(TypedValue* var) asm("_ZN4HPHP9f_is_nullERKNS_7VariantE");
470 TypedValue* fg_is_null(ActRec* ar) {
471 TypedValue rvSpace;
472 TypedValue* rv = &rvSpace;
473 int32_t count = ar->numArgs();
474 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
475 if (count == 1) {
476 rv->m_type = KindOfBoolean;
477 rv->m_data.num = (fh_is_null((args-0))) ? 1LL : 0LL;
478 } else {
479 throw_wrong_arguments_nr("is_null", count, 1, 1, 1);
480 rv->m_data.num = 0LL;
481 rv->m_type = KindOfNull;
483 frame_free_locals_no_this_inl(ar, 1);
484 memcpy(&ar->m_r, rv, sizeof(TypedValue));
485 return &ar->m_r;
488 TypedValue* fh_print_r(TypedValue* _rv, TypedValue* expression, bool ret) asm("_ZN4HPHP9f_print_rERKNS_7VariantEb");
490 void fg1_print_r(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
491 void fg1_print_r(TypedValue* rv, ActRec* ar, int32_t count) {
492 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
493 tvCastToBooleanInPlace(args-1);
494 fh_print_r(rv, (args-0), (count > 1) ? (bool)(args[-1].m_data.num) : (bool)(false));
495 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
498 TypedValue* fg_print_r(ActRec* ar) {
499 TypedValue rvSpace;
500 TypedValue* rv = &rvSpace;
501 int32_t count = ar->numArgs();
502 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
503 if (count >= 1 && count <= 2) {
504 if ((count <= 1 || (args - 1)->m_type == KindOfBoolean)) {
505 fh_print_r(rv, (args-0), (count > 1) ? (bool)(args[-1].m_data.num) : (bool)(false));
506 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
507 } else {
508 fg1_print_r(rv, ar, count);
510 } else {
511 throw_wrong_arguments_nr("print_r", count, 1, 2, 1);
512 rv->m_data.num = 0LL;
513 rv->m_type = KindOfNull;
515 frame_free_locals_no_this_inl(ar, 2);
516 memcpy(&ar->m_r, rv, sizeof(TypedValue));
517 return &ar->m_r;
520 TypedValue* fh_var_export(TypedValue* _rv, TypedValue* expression, bool ret) asm("_ZN4HPHP12f_var_exportERKNS_7VariantEb");
522 void fg1_var_export(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
523 void fg1_var_export(TypedValue* rv, ActRec* ar, int32_t count) {
524 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
525 tvCastToBooleanInPlace(args-1);
526 fh_var_export(rv, (args-0), (count > 1) ? (bool)(args[-1].m_data.num) : (bool)(false));
527 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
530 TypedValue* fg_var_export(ActRec* ar) {
531 TypedValue rvSpace;
532 TypedValue* rv = &rvSpace;
533 int32_t count = ar->numArgs();
534 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
535 if (count >= 1 && count <= 2) {
536 if ((count <= 1 || (args - 1)->m_type == KindOfBoolean)) {
537 fh_var_export(rv, (args-0), (count > 1) ? (bool)(args[-1].m_data.num) : (bool)(false));
538 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
539 } else {
540 fg1_var_export(rv, ar, count);
542 } else {
543 throw_wrong_arguments_nr("var_export", count, 1, 2, 1);
544 rv->m_data.num = 0LL;
545 rv->m_type = KindOfNull;
547 frame_free_locals_no_this_inl(ar, 2);
548 memcpy(&ar->m_r, rv, sizeof(TypedValue));
549 return &ar->m_r;
552 void fh_var_dump(int64_t _argc, TypedValue* expression, Value* _argv) asm("_ZN4HPHP10f_var_dumpEiRKNS_7VariantERKNS_5ArrayE");
554 TypedValue* fg_var_dump(ActRec* ar) {
555 TypedValue rvSpace;
556 TypedValue* rv = &rvSpace;
557 int32_t count = ar->numArgs();
558 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
559 if (count >= 1) {
560 rv->m_type = KindOfNull;
562 Array extraArgs;
564 ArrayInit ai(count-1);
565 for (int32_t i = 1; i < count; ++i) {
566 TypedValue* extraArg = ar->getExtraArg(i-1);
567 if (tvIsStronglyBound(extraArg)) {
568 ai.setRef(i-1, tvAsVariant(extraArg));
569 } else {
570 ai.set(i-1, tvAsVariant(extraArg));
573 extraArgs = ai.create();
575 fh_var_dump(count, (args-0), (Value*)(&extraArgs));
576 } else {
577 throw_missing_arguments_nr("var_dump", 1, count, 1);
578 rv->m_data.num = 0LL;
579 rv->m_type = KindOfNull;
581 frame_free_locals_no_this_inl(ar, 1);
582 memcpy(&ar->m_r, rv, sizeof(TypedValue));
583 return &ar->m_r;
586 void fh_debug_zval_dump(TypedValue* variable) asm("_ZN4HPHP17f_debug_zval_dumpERKNS_7VariantE");
588 TypedValue* fg_debug_zval_dump(ActRec* ar) {
589 TypedValue rvSpace;
590 TypedValue* rv = &rvSpace;
591 int32_t count = ar->numArgs();
592 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
593 if (count == 1) {
594 rv->m_type = KindOfNull;
595 fh_debug_zval_dump((args-0));
596 } else {
597 throw_wrong_arguments_nr("debug_zval_dump", count, 1, 1, 1);
598 rv->m_data.num = 0LL;
599 rv->m_type = KindOfNull;
601 frame_free_locals_no_this_inl(ar, 1);
602 memcpy(&ar->m_r, rv, sizeof(TypedValue));
603 return &ar->m_r;
606 TypedValue* fh_unserialize(TypedValue* _rv, Value* str, Value* class_whitelist) asm("_ZN4HPHP13f_unserializeERKNS_6StringERKNS_5ArrayE");
608 void fg1_unserialize(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
609 void fg1_unserialize(TypedValue* rv, ActRec* ar, int32_t count) {
610 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
611 switch (count) {
612 default: // count >= 2
613 if ((args-1)->m_type != KindOfArray) {
614 tvCastToArrayInPlace(args-1);
616 case 1:
617 break;
619 if (!IS_STRING_TYPE((args-0)->m_type)) {
620 tvCastToStringInPlace(args-0);
622 Array defVal1 = empty_array;
623 fh_unserialize(rv, &args[-0].m_data, (count > 1) ? &args[-1].m_data : (Value*)(&defVal1));
624 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
627 TypedValue* fg_unserialize(ActRec* ar) {
628 TypedValue rvSpace;
629 TypedValue* rv = &rvSpace;
630 int32_t count = ar->numArgs();
631 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
632 if (count >= 1 && count <= 2) {
633 if ((count <= 1 || (args - 1)->m_type == KindOfArray) &&
634 IS_STRING_TYPE((args - 0)->m_type)) {
635 Array defVal1 = empty_array;
636 fh_unserialize(rv, &args[-0].m_data, (count > 1) ? &args[-1].m_data : (Value*)(&defVal1));
637 if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
638 } else {
639 fg1_unserialize(rv, ar, count);
641 } else {
642 throw_wrong_arguments_nr("unserialize", count, 1, 2, 1);
643 rv->m_data.num = 0LL;
644 rv->m_type = KindOfNull;
646 frame_free_locals_no_this_inl(ar, 2);
647 memcpy(&ar->m_r, rv, sizeof(TypedValue));
648 return &ar->m_r;
651 Value* fh_get_defined_vars(Value* _rv) asm("_ZN4HPHP18f_get_defined_varsEv");
653 TypedValue* fg_get_defined_vars(ActRec* ar) {
654 TypedValue rvSpace;
655 TypedValue* rv = &rvSpace;
656 int32_t count = ar->numArgs();
657 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
658 if (count == 0) {
659 rv->m_type = KindOfArray;
660 fh_get_defined_vars(&(rv->m_data));
661 if (rv->m_data.num == 0LL) rv->m_type = KindOfNull;
662 } else {
663 throw_toomany_arguments_nr("get_defined_vars", 0, 1);
664 rv->m_data.num = 0LL;
665 rv->m_type = KindOfNull;
667 frame_free_locals_no_this_inl(ar, 0);
668 memcpy(&ar->m_r, rv, sizeof(TypedValue));
669 return &ar->m_r;
672 bool fh_import_request_variables(Value* types, Value* prefix) asm("_ZN4HPHP26f_import_request_variablesERKNS_6StringES2_");
674 void fg1_import_request_variables(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
675 void fg1_import_request_variables(TypedValue* rv, ActRec* ar, int32_t count) {
676 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
677 switch (count) {
678 default: // count >= 2
679 if (!IS_STRING_TYPE((args-1)->m_type)) {
680 tvCastToStringInPlace(args-1);
682 case 1:
683 break;
685 if (!IS_STRING_TYPE((args-0)->m_type)) {
686 tvCastToStringInPlace(args-0);
688 rv->m_type = KindOfBoolean;
689 String defVal1 = "";
690 rv->m_data.num = (fh_import_request_variables(&args[-0].m_data, (count > 1) ? &args[-1].m_data : (Value*)(&defVal1))) ? 1LL : 0LL;
693 TypedValue* fg_import_request_variables(ActRec* ar) {
694 TypedValue rvSpace;
695 TypedValue* rv = &rvSpace;
696 int32_t count = ar->numArgs();
697 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
698 if (count >= 1 && count <= 2) {
699 if ((count <= 1 || IS_STRING_TYPE((args - 1)->m_type)) &&
700 IS_STRING_TYPE((args - 0)->m_type)) {
701 rv->m_type = KindOfBoolean;
702 String defVal1 = "";
703 rv->m_data.num = (fh_import_request_variables(&args[-0].m_data, (count > 1) ? &args[-1].m_data : (Value*)(&defVal1))) ? 1LL : 0LL;
704 } else {
705 fg1_import_request_variables(rv, ar, count);
707 } else {
708 throw_wrong_arguments_nr("import_request_variables", count, 1, 2, 1);
709 rv->m_data.num = 0LL;
710 rv->m_type = KindOfNull;
712 frame_free_locals_no_this_inl(ar, 2);
713 memcpy(&ar->m_r, rv, sizeof(TypedValue));
714 return &ar->m_r;
717 long fh_extract(Value* var_array, int extract_type, Value* prefix) asm("_ZN4HPHP9f_extractERKNS_5ArrayEiRKNS_6StringE");
719 void fg1_extract(TypedValue* rv, ActRec* ar, int32_t count) __attribute__((noinline,cold));
720 void fg1_extract(TypedValue* rv, ActRec* ar, int32_t count) {
721 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
722 switch (count) {
723 default: // count >= 3
724 if (!IS_STRING_TYPE((args-2)->m_type)) {
725 tvCastToStringInPlace(args-2);
727 case 2:
728 if ((args-1)->m_type != KindOfInt64) {
729 tvCastToInt64InPlace(args-1);
731 case 1:
732 break;
734 if ((args-0)->m_type != KindOfArray) {
735 tvCastToArrayInPlace(args-0);
737 rv->m_type = KindOfInt64;
738 String defVal2 = "";
739 rv->m_data.num = (int64_t)fh_extract(&args[-0].m_data, (count > 1) ? (int)(args[-1].m_data.num) : (int)(k_EXTR_OVERWRITE), (count > 2) ? &args[-2].m_data : (Value*)(&defVal2));
742 TypedValue* fg_extract(ActRec* ar) {
743 TypedValue rvSpace;
744 TypedValue* rv = &rvSpace;
745 int32_t count = ar->numArgs();
746 TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
747 if (count >= 1 && count <= 3) {
748 if ((count <= 2 || IS_STRING_TYPE((args - 2)->m_type)) &&
749 (count <= 1 || (args - 1)->m_type == KindOfInt64) &&
750 (args - 0)->m_type == KindOfArray) {
751 rv->m_type = KindOfInt64;
752 String defVal2 = "";
753 rv->m_data.num = (int64_t)fh_extract(&args[-0].m_data, (count > 1) ? (int)(args[-1].m_data.num) : (int)(k_EXTR_OVERWRITE), (count > 2) ? &args[-2].m_data : (Value*)(&defVal2));
754 } else {
755 fg1_extract(rv, ar, count);
757 } else {
758 throw_wrong_arguments_nr("extract", count, 1, 3, 1);
759 rv->m_data.num = 0LL;
760 rv->m_type = KindOfNull;
762 frame_free_locals_no_this_inl(ar, 3);
763 memcpy(&ar->m_r, rv, sizeof(TypedValue));
764 return &ar->m_r;
767 } // namespace HPHP