1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <JavaScriptCore/JSBase.h>
36 #include "Standard.hpp"
39 struct CYTypedIdentifier;
43 #define JOC_TYPE_INOUT (1 << 0)
44 #define JOC_TYPE_IN (1 << 1)
45 #define JOC_TYPE_BYCOPY (1 << 2)
46 #define JOC_TYPE_OUT (1 << 3)
47 #define JOC_TYPE_BYREF (1 << 4)
48 #define JOC_TYPE_CONST (1 << 5)
49 #define JOC_TYPE_ONEWAY (1 << 6)
59 virtual Type *Copy(CYPool &pool, const char *name = NULL) const = 0;
60 virtual const char *GetName() const;
62 virtual const char *Encode(CYPool &pool) const = 0;
63 virtual CYTypedIdentifier *Decode(CYPool &pool) const = 0;
65 virtual ffi_type *GetFFI(CYPool &pool) const = 0;
66 virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0;
67 virtual JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL) const = 0;
70 template <typename Type_>
74 Primitive *Copy(CYPool &pool, const char *name) const {
75 return new(pool) Primitive();
78 const char *Encode(CYPool &pool) const override;
79 CYTypedIdentifier *Decode(CYPool &pool) const override;
81 ffi_type *GetFFI(CYPool &pool) const override;
82 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
83 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
100 Void *Copy(CYPool &pool, const char *name = NULL) const override;
102 const char *Encode(CYPool &pool) const override;
103 CYTypedIdentifier *Decode(CYPool &pool) const override;
105 ffi_type *GetFFI(CYPool &pool) const override;
106 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
107 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
113 Unknown *Copy(CYPool &pool, const char *name = NULL) const override;
115 const char *Encode(CYPool &pool) const override;
116 CYTypedIdentifier *Decode(CYPool &pool) const override;
118 ffi_type *GetFFI(CYPool &pool) const override;
119 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
120 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
126 String *Copy(CYPool &pool, const char *name = NULL) const override;
128 const char *Encode(CYPool &pool) const override;
129 CYTypedIdentifier *Decode(CYPool &pool) const override;
131 ffi_type *GetFFI(CYPool &pool) const override;
132 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
133 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
139 Meta *Copy(CYPool &pool, const char *name = NULL) const override;
141 const char *Encode(CYPool &pool) const override;
142 CYTypedIdentifier *Decode(CYPool &pool) const override;
144 ffi_type *GetFFI(CYPool &pool) const override;
145 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
146 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
152 Selector *Copy(CYPool &pool, const char *name = NULL) const override;
154 const char *Encode(CYPool &pool) const override;
155 CYTypedIdentifier *Decode(CYPool &pool) const override;
157 ffi_type *GetFFI(CYPool &pool) const override;
158 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
159 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
172 Bits *Copy(CYPool &pool, const char *name = NULL) const override;
174 const char *Encode(CYPool &pool) const override;
175 CYTypedIdentifier *Decode(CYPool &pool) const override;
177 ffi_type *GetFFI(CYPool &pool) const override;
178 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
179 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
187 Pointer(Type &type) :
192 Pointer *Copy(CYPool &pool, const char *name = NULL) const override;
194 const char *Encode(CYPool &pool) const override;
195 CYTypedIdentifier *Decode(CYPool &pool) const override;
197 ffi_type *GetFFI(CYPool &pool) const override;
198 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
199 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
208 Array(Type &type, size_t size = _not(size_t)) :
214 Array *Copy(CYPool &pool, const char *name = NULL) const override;
216 const char *Encode(CYPool &pool) const override;
217 CYTypedIdentifier *Decode(CYPool &pool) const override;
219 ffi_type *GetFFI(CYPool &pool) const override;
220 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
221 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
229 Object(const char *name = NULL) :
234 Object *Copy(CYPool &pool, const char *name = NULL) const override;
235 const char *GetName() const override;
237 const char *Encode(CYPool &pool) const override;
238 CYTypedIdentifier *Decode(CYPool &pool) const override;
240 ffi_type *GetFFI(CYPool &pool) const override;
241 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
242 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
252 Aggregate(bool overlap, const char *name = NULL) :
258 Aggregate *Copy(CYPool &pool, const char *name = NULL) const override;
259 const char *GetName() const override;
261 const char *Encode(CYPool &pool) const override;
262 CYTypedIdentifier *Decode(CYPool &pool) const override;
264 ffi_type *GetFFI(CYPool &pool) const override;
265 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
266 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
278 Function *Copy(CYPool &pool, const char *name = NULL) const override;
280 const char *Encode(CYPool &pool) const override;
281 CYTypedIdentifier *Decode(CYPool &pool) const override;
283 ffi_type *GetFFI(CYPool &pool) const override;
284 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
285 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
291 Block *Copy(CYPool &pool, const char *name = NULL) const override;
293 const char *Encode(CYPool &pool) const override;
294 CYTypedIdentifier *Decode(CYPool &pool) const override;
296 ffi_type *GetFFI(CYPool &pool) const override;
297 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
298 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
301 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
302 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
306 #endif/*SIG_TYPES_H*/