cpp
[m6w6/ext-psi] / src / context.c
index b98ecc2e4940cab596d9c5ce1632d804abda114a..199f533317ed7dfce6981ec01778a3fdfd819511 100644 (file)
@@ -97,10 +97,25 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o
                T.types = psi_plist_add(T.types, &def);
        }
        for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) {
-               struct psi_impl_def_val *val = psi_impl_def_val_init(predef_const->val_type_tag, predef_const->val_text);
                struct psi_const_type *type = psi_const_type_init(predef_const->type_tag, predef_const->type_name);
-               struct psi_const *constant = psi_const_init(type, predef_const->var_name, val);
+               struct psi_impl_def_val *val;
+               struct psi_const *constant;
 
+               switch (type->type) {
+               case PSI_T_INT:
+                       val = psi_impl_def_val_init(PSI_T_INT, NULL);
+                       val->ival.zend.lval = predef_const->value.lval;
+                       break;
+               case PSI_T_STRING:
+                       val = psi_impl_def_val_init(PSI_T_STRING, NULL);
+                       val->ival.zend.str = zend_string_init(predef_const->value.ptr, strlen(predef_const->value.ptr), 1);
+                       break;
+               default:
+                       assert(0);
+                       break;
+               }
+
+               constant = psi_const_init(type, predef_const->var_name, val);
                T.consts = psi_plist_add(T.consts, &constant);
        }
        for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) {
@@ -241,14 +256,7 @@ void psi_context_build(struct psi_context *C, const char *paths)
                                        continue;
                                }
 
-                               while (0 < psi_parser_scan(&P)) {
-                                       psi_parser_parse(&P, psi_token_alloc(&P));
-                                       if (P.num == PSI_T_EOF) {
-                                               break;
-                                       }
-                               }
-
-                               psi_parser_parse(&P, NULL);
+                               psi_parser_parse(&P);
                                psi_context_add_data(C, PSI_DATA(&P));
                                psi_parser_dtor(&P);
                        }
@@ -284,34 +292,36 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                struct psi_const *c;
 
                while (psi_plist_get(C->consts, i++, &c)) {
-                       zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1);
 
-                       if (zend_get_constant(zc.name)) {
-                               zend_string_release(zc.name);
+                       if (zend_get_constant_str(c->name, strlen(c->name))) {
                                continue;
                        }
 
-                       ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1));
+                       zc.name = zend_string_init(c->name, strlen(c->name), 1);
 
                        switch (c->type->type) {
                        case PSI_T_BOOL:
-                               convert_to_boolean(&zc.value);
+                               ZVAL_BOOL(&zc.value, c->val->ival.zend.bval);
                                break;
                        case PSI_T_INT:
-                               convert_to_long(&zc.value);
+                               ZVAL_LONG(&zc.value, c->val->ival.zend.lval);
                                break;
                        case PSI_T_FLOAT:
-                               convert_to_double(&zc.value);
+                               ZVAL_DOUBLE(&zc.value, c->val->ival.dval);
                                break;
                        case PSI_T_STRING:
                        case PSI_T_QUOTED_STRING:
+                               ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str));
                                break;
                        default:
                                assert(0);
+                               break;
                        }
+
                        zend_register_constant(&zc);
                }
        }
+
        if (C->enums) {
                size_t i = 0;
                struct psi_decl_enum *e;
@@ -324,7 +334,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                                zend_string *name = strpprintf(0, "psi\\%s\\%s", e->name, item->name);
 
                                zc.name = zend_string_dup(name, 1);
-                               ZVAL_LONG(&zc.value, psi_long_num_exp(item->num, NULL));
+                               ZVAL_LONG(&zc.value, psi_long_num_exp(item->num, NULL, NULL));
                                zend_register_constant(&zc);
                                zend_string_release(name);
                        }
@@ -356,7 +366,22 @@ ZEND_RESULT_CODE psi_context_call(struct psi_context *C, zend_execute_data *exec
                return FAILURE;
        }
 
+       if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_PRE)) {
+               psi_call_frame_do_return(frame, return_value);
+               psi_call_frame_free(frame);
+
+               return FAILURE;
+       }
+
        psi_call_frame_do_call(frame);
+
+       if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_POST)) {
+               psi_call_frame_do_return(frame, return_value);
+               psi_call_frame_free(frame);
+
+               return FAILURE;
+       }
+
        psi_call_frame_do_return(frame, return_value);
        psi_call_frame_do_set(frame);
        psi_call_frame_do_free(frame);