source: trunk/processor/main.m4 @ 837

Last change on this file since 837 was 837, checked in by moo, 2 years ago

PHP_5_4: improves traits support

  • Property svn:eol-style set to native
File size: 8.9 KB
RevLine 
[1]1divert(-1)
2dnl ================ start ======================
[12]3dnl define(`XCACHE_ENABLE_TEST')
[300]4dnl define(`DEBUG_SIZE')
[1]5define(`USEMEMCPY')
6
7dnl ================ main
8
9dnl {{{ basic
[342]10define(`REDEF', `ifdef(`$1', `undefine(`$1')') define(`$1', `$2')')
[290]11define(`MAKE_MACRONAME', `translit(`$1', ` ():
12', `_____')')
[291]13define(`ONCE', `ifdef(MAKE_MACRONAME(`ONCE $1'), `', `define(MAKE_MACRONAME(`ONCE $1'))$1')')
[1]14define(`m4_errprint', `ONCE(`errprint(`$1
15')')')
[292]16ifdef(`len', `
17define(`m4_len', defn(`len'))
18undefine(`len')
19')
[233]20define(`ZEND_STRS', `($1), (sizeof($1))')
21define(`ZEND_STRL', `($1), (sizeof($1) - 1)')
[1]22dnl ============
23define(`INDENT', `xc_dprint_indent(indent);')
24dnl }}}
25dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2)
26define(`ALLOC', `
27    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
28    pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
29    pushdef(`FORCETYPE', `ifelse(`$5', , `$2', `$5')')
30    /* allocate */
31    IFCALC(`
32        IFASSERT(`
[193]33            xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
34            xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
[1]35        ')
36        processor->size = (size_t) ALIGN(processor->size);
37        processor->size += SIZE;
38    ')
39    IFSTORE(`
40        IFASSERT(`{
[307]41            if (!xc_stack_count(&processor->allocsizes)) {
[1]42                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
43            }
44            else {
[193]45                unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
46                unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
47                unsigned long real = SIZE;
[1]48                if (expect != real) {
[295]49                    fprintf(stderr, "mismatch `$@' at line %d(was %lu): real %lu - expect %lu = %lu\n", __LINE__, atline, real, expect, real - expect);
[1]50                }
51            }
52        }')
[302]53        ifdef(`DEBUG_SIZE', ` {
54            void *oldp = processor->p;
55        ')
[1]56        $1 = (FORCETYPE *) (processor->p = (char *) ALIGN(processor->p));
57        ifelse(`$4', `', `
[836]58                IFASSERT(`memsetptr($1, (void *) __LINE__, SIZE);')
[1]59            ', `
60                memset($1, 0, SIZE);
61        ')
62        processor->p += SIZE;
[300]63
64        ifdef(`DEBUG_SIZE', `
65            xc_totalsize += (char *) processor->p - (char *) oldp;
66            fprintf(stderr, "%d\t%d\t`'SIZE()\n", (char *) processor->p - (char *) oldp, xc_totalsize);
[302]67        }
[300]68        ')
[1]69    ')
70    IFRESTORE(`ifelse(`$4', `', `
71            ifelse(
72                FORCETYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
73                FORCETYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
74                `', `', `$1 = (FORCETYPE *) emalloc(SIZE);')
[836]75            IFASSERT(`memsetptr($1, (void *) __LINE__, SIZE);')
[1]76        ', `
77            $1 = (FORCETYPE *) ecalloc(COUNT, sizeof($2));
78        ')
79    ')
80    popdef(`COUNT')
81    popdef(`SIZE')
82')
83dnl CALLOC(1:dst, 2:type [, 3:count=1 ])
84define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1')')
85dnl }}}
86dnl {{{ PROC_INT(1:elm, 2:format=%d, 3:type=, 4:spec=)
87define(`PROC_INT', `
88    IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')
89    IFDPRINT(`
90        INDENT()
91        ifelse(
92            `$3 $1', `zval_data_type type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_data_type(src->$1));'
93        , `$3 $1', `int op_type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_op_type(src->$1));'
94        , `$3 $1', `zend_uchar opcode', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_opcode(src->$1));'
95        , `', `', `fprintf(stderr, "$3:$1:\t%ifelse(`$2',`',`d',`$2')\n", src->$1);')
96    ')
97    IFDASM(`
98        ifelse(
99            `$3', `zend_bool', `add_assoc_bool_ex(dst, ZEND_STRS("$1"), src->$1 ? 1 : 0);'
100        , `', `', `add_assoc_long_ex(dst, ZEND_STRS("$1"), src->$1);'
101        )
102    ')
103    DONE(`$1')
104')
105dnl }}}
[4]106dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
107define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1', `$1')`'DONE(`$1')')
108dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
[1]109define(`PROC_CLASS_ENTRY_P_EX', `
110    if ($2) {
111        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
[90]112        IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);')
[569]113#ifdef IS_UNICODE
[504]114        IFDASM(`add_assoc_unicodel_ex(dst, ZEND_STRS("$3"), ZSTR_U($2->name), $2->name_length, 1);')
[569]115#else
116        IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("$3"), $2->name, $2->name_length, 1);')
117#endif
[1]118    }
119    else {
[4]120        COPYNULL_EX(`$1', `$3')
[1]121    }
122')
123dnl }}}
[690]124dnl {{{ IFASSERTEX
125define(`IFASSERTEX', `ifdef(`XCACHE_ENABLE_TEST', `$1', `$2')')
126dnl }}}
[1]127dnl {{{ IFASSERT
[690]128define(`IFASSERT', `IFASSERTEX(`
[1]129#ifndef NDEBUG
130        $1
131#endif
132')')
133dnl }}}
134dnl {{{ DBG
135define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
136    /* `$1' */
137')')
138dnl }}}
139dnl {{{ EXPORT
140define(`EXPORT', `define(`EXPORT_$1')')
141dnl }}}
142dnl {{{ FIXPOINTER
143define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')')
144define(`FIXPOINTER_EX', `IFSTORE(`
[311]145    $2 = ($1 *) processor->cache->shm->handlers->to_readonly(processor->cache->shm, (char *)$2);
[1]146')')
147define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
148define(`UNFIXPOINTER_EX', `IFSTORE(`
[311]149    $2 = ($1 *) processor->cache->shm->handlers->to_readwrite(processor->cache->shm, (char *)$2);
[1]150')')
151dnl }}}
152dnl {{{ COPY
153define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')DONE(`$1')')
154dnl }}}
[662]155dnl {{{ COPY_N_EX
156define(`COPY_N_EX', `
157    ALLOC(`dst->$3', `$2', `src->$1')
158    IFCOPY(`
159        memcpy(dst->$3, src->$3, sizeof(dst->$3[0]) * src->$1);
160        ')
161')
162dnl }}}
163dnl {{{ COPY_N
164define(`COPY_N', `COPY_N_EX(`$1',`$2')DONE(`$1')')
165dnl }}}
[311]166dnl {{{ COPYPOINTER
167define(`COPYPOINTER', `COPY(`$1')')
168dnl }}}
[662]169dnl {{{ COPYARRAY_EX
170define(`COPYARRAY_EX', `IFNOTMEMCPY(`IFCOPY(`memcpy(dst->$1, src->$1, sizeof(dst->$1));')')')
171dnl }}}
[311]172dnl {{{ COPYARRAY
[662]173define(`COPYARRAY', `COPYARRAY_EX(`$1',`$2')DONE(`$1')')
[311]174dnl }}}
[1]175dnl {{{ SETNULL_EX
176define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
177define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')')
178dnl }}}
[4]179dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
[1]180define(`COPYNULL_EX', `
[4]181    IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
[1]182    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
[837]183    assert(patsubst($1, dst, src) == NULL);
[1]184')
[4]185dnl }}}
186dnl {{{ COPYNULL(1:elm)
[1]187define(`COPYNULL', `
[794]188    COPYNULL_EX(`dst->$1', `$1')DONE(`$1')
[1]189')
190dnl }}}
[4]191dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
192define(`foreach',
193       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
194define(`_arg1', `$1')
195define(`_foreach',                             
196       `ifelse(`$2', `()', ,                       
197       `define(`$1', _arg1$2)$3`'_foreach(`$1',
198                                                       (shift$2),
199                                                       `$3')')')
200define(`LIST_DIFF', `dnl
201foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
202foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
203foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
[356]204foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
[4]205foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
206')
207dnl }}}
[1]208dnl {{{ DONE_*
[719]209define(`DONE_SIZE', `IFASSERT(`dnl
[1]210    done_size += $1`';
211    done_count ++;
212')')
213define(`DONE', `
[719]214    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
215    IFASSERT(`dnl
216        if (zend_hash_exists(&done_names, "$1", sizeof("$1"))) {
217            fprintf(stderr
218                , "duplicate field at %s `#'%d FUNC_NAME`' : %s\n"
219                , __FILE__, __LINE__
220                , "$1"
221                );
222        }
223        else {
224            zend_uchar b = 1;
225            zend_hash_add(&done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
226        }
227    ')
[1]228    DONE_SIZE(`sizeof(src->$1)')
229')
230define(`DISABLECHECK', `
231    pushdef(`DONE_SIZE')
232    pushdef(`DONE')
233$1
234    popdef(`DONE_SIZE')
235    popdef(`DONE')
236')
237dnl }}}
238dnl {{{ IF**
239define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')')
240define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')')
[198]241define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
[1]242define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')')
[198]243define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
244define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
[1]245define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')')
246define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')')
247define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')')
248dnl }}}
249EXPORT(`zend_op')
250EXPORT(`zend_op_array')
251EXPORT(`zend_function')
252EXPORT(`HashTable_zend_function')
253EXPORT(`zend_class_entry')
254EXPORT(`xc_classinfo_t')
255EXPORT(`xc_funcinfo_t')
256EXPORT(`xc_entry_t')
[311]257EXPORT(`xc_entry_data_php_t')
[1]258EXPORT(`zval')
259
[4]260include(srcdir`/processor/hashtable.m4')
261include(srcdir`/processor/string.m4')
262include(srcdir`/processor/struct.m4')
263include(srcdir`/processor/dispatch.m4')
264include(srcdir`/processor/head.m4')
[1]265
266define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
[4]267REDEF(`KIND', `calc') include(srcdir`/processor/processor.m4')
[662]268pushdef(`xc_get_class_num', ``xc_get_class_num'($@)')
[4]269REDEF(`KIND', `store') include(srcdir`/processor/processor.m4')
[662]270popdef(`xc_get_class_num')
271pushdef(`xc_get_class', ``xc_get_class'($@)')
[4]272REDEF(`KIND', `restore') include(srcdir`/processor/processor.m4')
[662]273popdef(`xc_get_class')
[1]274
275REDEF(`IFNOTMEMCPY', `$1')
276#ifdef HAVE_XCACHE_DPRINT
[4]277REDEF(`KIND', `dprint') include(srcdir`/processor/processor.m4')
[1]278#endif /* HAVE_XCACHE_DPRINT */
279#ifdef HAVE_XCACHE_DISASSEMBLER
[4]280REDEF(`KIND', `dasm') include(srcdir`/processor/processor.m4')
[1]281#endif /* HAVE_XCACHE_DISASSEMBLER */
282#ifdef HAVE_XCACHE_ASSEMBLER
[4]283REDEF(`KIND', `asm') include(srcdir`/processor/processor.m4')
[1]284#endif /* HAVE_XCACHE_ASSEMBLER */
285
286ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.