fix coupling of impl + call_info + decl
[m6w6/ext-psi] / src / context.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PSI_CONTEXT_H
27 #define PSI_CONTEXT_H
28
29 /* zend_function_entry */
30 #include "Zend/zend_API.h"
31
32 struct psi_context;
33 struct psi_token;
34 struct psi_parser;
35 struct psi_call_frame;
36 struct impl_vararg;
37 struct psi_decl;
38 struct psi_impl;
39
40 enum psi_context_query {
41 PSI_CONTEXT_QUERY_SELF, /* ffi/jit */
42 PSI_CONTEXT_QUERY_TYPE, /* impl type token_t to native ffi_type/jit_type */
43 };
44
45 struct psi_context_ops {
46 void (*init)(struct psi_context *C);
47 void (*dtor)(struct psi_context *C);
48 zend_function_entry *(*compile)(struct psi_context *C);
49 void (*call)(struct psi_call_frame *frame);
50 void *(*query)(struct psi_context *C, enum psi_context_query q, void *arg);
51 };
52
53 #include "data.h"
54
55 struct psi_context {
56 PSI_DATA_MEMBERS;
57 void *context;
58 struct psi_context_ops *ops;
59 zend_function_entry *closures;
60 struct psi_data *data;
61 size_t count;
62 };
63
64 struct psi_context_call_data {
65 struct psi_context *context;
66 union {
67 struct psi_impl *fn;
68 struct psi_let_callback *cb;
69 } impl;
70 };
71
72 struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_ops *ops, psi_error_cb error, unsigned flags);
73 void psi_context_build(struct psi_context *C, const char *path);
74 bool psi_context_add_data(struct psi_context *C, struct psi_data *P);
75 zend_function_entry *psi_context_compile(struct psi_context *C);
76 ZEND_RESULT_CODE psi_context_call(struct psi_context *C, zend_execute_data *execute_data, zval *return_value, struct psi_impl *impl);
77 void psi_context_dump(struct psi_context *C, int fd);
78 void psi_context_dtor(struct psi_context *C);
79 void psi_context_free(struct psi_context **C);
80
81 #endif