diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-12-06 07:42:36 -0800 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-12-06 07:42:36 -0800 |
commit | c91dc2292f4fd49a3103691cb70fee8336c6aa6c (patch) | |
tree | 578d41f25a0ce7b37ab3b7c9d2aa1992ca91b0c0 | |
parent | 3750e24683f3a1d0b643e9808d9619db40d31cc4 (diff) |
Global variables are now accessible via Php::globals["varname"]
-rw-r--r-- | include/base.h | 35 | ||||
-rw-r--r-- | include/environment.h | 156 | ||||
-rw-r--r-- | include/extension.h | 56 | ||||
-rw-r--r-- | include/function.h | 3 | ||||
-rw-r--r-- | include/global.h | 4 | ||||
-rw-r--r-- | include/globals.h | 115 | ||||
-rw-r--r-- | include/init.h | 57 | ||||
-rw-r--r-- | include/method.h | 27 | ||||
-rw-r--r-- | include/value.h | 4 | ||||
-rw-r--r-- | phpcpp.h | 2 | ||||
-rw-r--r-- | src/extension.cpp | 29 | ||||
-rw-r--r-- | src/function.cpp | 1 | ||||
-rw-r--r-- | src/globals.cpp (renamed from src/environment.cpp) | 48 | ||||
-rw-r--r-- | src/includes.h | 4 | ||||
-rw-r--r-- | src/methodmember.h | 5 | ||||
-rw-r--r-- | src/nativefunction.h | 19 |
16 files changed, 208 insertions, 357 deletions
diff --git a/include/base.h b/include/base.h index 1dc131e..56189e2 100644 --- a/include/base.h +++ b/include/base.h @@ -28,46 +28,21 @@ public: /** * The pseudo constructor that is called from PHP after the object is constructed - * @param environment * @param parameters */ - virtual void __construct(Environment &environment, const Parameters ¶meters) + virtual void __construct(const Parameters ¶meters) { // call all other possible implementations - __construct(environment); - __construct(parameters); __construct(); } /** * The pseudo constructor that is called from PHP after the object is constructed - * @param environment - */ - virtual void __construct(Environment &environment) {} - - /** - * The pseudo constructor that is called from PHP after the object is constructed - * @param parameters - */ - virtual void __construct(const Parameters ¶meters) {} - - /** - * The pseudo constructor that is called from PHP after the object is constructed */ virtual void __construct() {} /** * The pseudo destructor that is called from PHP right before the object is destructed - * @param environment - */ - virtual void __destruct(Environment &environment) - { - // call the other implementation - __destruct(); - } - - /** - * The pseudo destructor that is called from PHP right before the object is destructed */ virtual void __destruct() {} @@ -100,12 +75,8 @@ private: */ typedef void (Base::*method_callback_0)(); typedef void (Base::*method_callback_1)(Parameters &); -typedef void (Base::*method_callback_2)(Environment &); -typedef void (Base::*method_callback_3)(Environment &, Parameters &); -typedef Value (Base::*method_callback_4)(); -typedef Value (Base::*method_callback_5)(Parameters &); -typedef Value (Base::*method_callback_6)(Environment &); -typedef Value (Base::*method_callback_7)(Environment &, Parameters &); +typedef Value (Base::*method_callback_2)(); +typedef Value (Base::*method_callback_3)(Parameters &); /** * End of namespace diff --git a/include/environment.h b/include/environment.h deleted file mode 100644 index a7512d7..0000000 --- a/include/environment.h +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Environment.h - * - * During the lifetime of the extension, multiple requests can be handled - * by it. For every request that is handled, an environment object is created. - * - * The base class for the environment is defined in this file. If you'd like - * to add state variables to the environment you can override this class and - * add the extra features you'd like. If you override this method, you should - * also override Extension::createEnvironment() to return an instance of a - * different class. - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - */ - -/** - * Set up namespace - */ -namespace Php { - -/** - * Forward definitions - */ -class Extension; -class Global; - -/** - * Class definition - */ -class Environment -{ -public: - /** - * Constructor - * @param extension - */ - Environment(Extension *extension) : _extension(extension) {} - - /** - * Disable copy and move operations - */ - Environment(const Environment &environment) = delete; - Environment(Environment &&environment) = delete; - - /** - * Destructor - */ - virtual ~Environment() {} - - /** - * Initialize the request - * - * This method is called directly after the object was destructed. You can - * override this method to add your own initialization code. - * - * @return bool - */ - virtual bool initialize() - { - return true; - } - - /** - * Finalize the request - * - * This method is called right before the object is destructed. Note that - * the object is going to be destructed anyway, even if this method returns - * false - * - * @return bool - */ - virtual bool finalize() - { - return true; - } - - /** - * Get access to the user supplied data - * @return void* - */ - virtual void *data() - { - return _data; - } - - /** - * Change the user supplied data - * @param data - */ - virtual void setData(void *data) - { - _data = data; - } - - /** - * Get access to a global variable - * @param name - * @return Global - */ - Global operator[](const char *name); - - /** - * Get access to a global variable - * @param name - * @return Global - */ - Global operator[](const std::string &name); - - /** - * Call a function in PHP - * We have ten variants of this function, depending on the number of parameters - * @param name Name of the function - * @return Value - */ - Value call(const Value &name); - Value call(const Value &name, Value p0); - Value call(const Value &name, Value p0, Value p1); - Value call(const Value &name, Value p0, Value p1, Value p2); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9); - -private: - /** - * Call function with a number of parameters - * @param name Function name - * @param argc Number of parameters - * @param argv The parameters - * @return Value - */ - Value exec(const Value &name, int argc, struct _zval_struct ***params); - -protected: - /** - * The extension that this environment belongs to - * @var Extension* - */ - Extension *_extension; - - /** - * Pointer to user supplied data - * @var void* - */ - void *_data = NULL; -}; - -/** - * End of namespace - */ -} - diff --git a/include/extension.h b/include/extension.h index bf945f7..3555fb6 100644 --- a/include/extension.h +++ b/include/extension.h @@ -29,9 +29,15 @@ struct _zend_module_entry; namespace Php { /** + * Forward declaration + */ +class Extension; + +/** * Optional callback types for starting and stopping the request + * @param extension */ -typedef bool (*request_callback)(Environment &); +typedef bool (*request_callback)(Extension *extension); /** * A couple of predefined native callback functions that can be registered. @@ -40,12 +46,8 @@ typedef bool (*request_callback)(Environment &); */ typedef void (*native_callback_0)(); typedef void (*native_callback_1)(Parameters &); -typedef void (*native_callback_2)(Environment &); -typedef void (*native_callback_3)(Environment &, Parameters &); -typedef Value (*native_callback_4)(); -typedef Value (*native_callback_5)(Parameters &); -typedef Value (*native_callback_6)(Environment &); -typedef Value (*native_callback_7)(Environment &, Parameters &); +typedef Value (*native_callback_2)(); +typedef Value (*native_callback_3)(Parameters &); /** * Class definition @@ -105,34 +107,6 @@ public: } /** - * Create a new environment - * - * You can override this method if you've created your own environment class, - * and you'd like to use an instance of that class instead. The returned - * object must have been created on the heap. - * - * @return Environment* - */ - virtual Environment *createEnvironment() - { - // allocate the environment - return new Environment(this); - } - - /** - * Destruct an environment - * - * This is the counterpart of the createEnvironment method. - * - * @param Environment - */ - virtual void deleteEnvironment(Environment *environment) - { - // destruct the environment - delete environment; - } - - /** * Start a request * * This method is called when the zend engine is about to start a new @@ -141,13 +115,13 @@ public: * * @return boolean */ - virtual bool startRequest(Environment &environment) + virtual bool startRequest() { // ok if no callback was set if (!_start) return true; // call the callback function - return _start(environment); + return _start(this); } /** @@ -158,13 +132,13 @@ public: * * @return boolean */ - virtual bool endRequest(Environment &environment) + virtual bool endRequest() { // ok if no callback is set if (!_stop) return true; // call callback - return _stop(environment); + return _stop(this); } /** @@ -194,10 +168,6 @@ public: Function *add(const char *name, native_callback_1 function, const std::initializer_list<Argument> &arguments = {}); Function *add(const char *name, native_callback_2 function, const std::initializer_list<Argument> &arguments = {}); Function *add(const char *name, native_callback_3 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_4 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_5 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_6 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_7 function, const std::initializer_list<Argument> &arguments = {}); /** * Add a native class to the extension diff --git a/include/function.h b/include/function.h index 3704ce8..d2461ef 100644 --- a/include/function.h +++ b/include/function.h @@ -94,11 +94,10 @@ public: /** * Method that gets called every time the function is executed - * @param environment Environment object * @param params The parameters that were passed * @return Variable Return value */ - virtual Value invoke(Environment &environment, Parameters ¶ms) + virtual Value invoke(Parameters ¶ms) { return nullptr; } diff --git a/include/global.h b/include/global.h index ead2e08..4531f77 100644 --- a/include/global.h +++ b/include/global.h @@ -180,9 +180,9 @@ private: bool _exists; /** - * The environment can access the private method from this class + * The globals can access the private method from this class */ - friend class Environment; + friend class Globals; }; /** diff --git a/include/globals.h b/include/globals.h index 052bab8..b3ee6c3 100644 --- a/include/globals.h +++ b/include/globals.h @@ -1,55 +1,104 @@ /** * Globals.h * - * Variables and structured required by the Zend engine to work - * with global variables + * Wrapper object that gives access to all global variables. You + * can use it more or less the same as the $_GLOBALS object in + * PHP. + * + * The global PHP variables are acessible via the Php::globals["varname"] + * variables. * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013 Copernica BV */ - + /** - * Namespace + * Set up namespace */ namespace Php { /** - * The way how PHP C API deals with "global" variables is stupid. - * - * This is supposed to turn into a structure that is going to be - * instantiated for each parallel running request, and for which the - * PHP engine allocates a certain amount of memory, and a magic - * pointer that is passed and should be forwarded to every thinkable - * PHP function. - * - * We don't like this architecture. We have our own environment object - * that makes much more sense, and that we use. However, we need - * to assign this object somewhere, so that's what we do in this - * one and only global variable + * Forward definitions */ -ZEND_BEGIN_MODULE_GLOBALS(phpcpp) - Php::Environment *environment; -ZEND_END_MODULE_GLOBALS(phpcpp) +class Global; /** - * And now we're going to define a macro. This also is a ridiculous - * architecture from PHP to get access to a variable from the - * structure above. + * Class definition */ -#ifdef ZTS -#define PHPCPP_G(v) TSRMG(phpcpp_globals_id, phpcpp_globals *, v) -#else -#define PHPCPP_G(v) (phpcpp_globals.v) -#endif +class Globals +{ +public: + /** + * Disable copy and move operations + */ + Globals(const Globals &globals) = delete; + Globals(Globals &&globals) = delete; + + /** + * Destructor + */ + virtual ~Globals() {} + + /** + * Get access to a global variable + * @param name + * @return Global + */ + Global operator[](const char *name); + + /** + * Get access to a global variable + * @param name + * @return Global + */ + Global operator[](const std::string &name); + + /** + * Call a function in PHP + * We have ten variants of this function, depending on the number of parameters + * @param name Name of the function + * @return Value + */ + Value call(const Value &name); + Value call(const Value &name, Value p0); + Value call(const Value &name, Value p0, Value p1); + Value call(const Value &name, Value p0, Value p1, Value p2); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8); + Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9); + +private: + /** + * Call function with a number of parameters + * @param name Function name + * @param argc Number of parameters + * @param argv The parameters + * @return Value + */ + Value exec(const Value &name, int argc, struct _zval_struct ***params); + + /** + * Constructor + */ + Globals() {} + +public: + /** + * Get the one and only instance + * @return Globals + */ + static Globals &instance(); +}; /** - * We're almost there, we now need to declare an instance of the - * structure defined above (if building for a single thread) or some - * sort of impossible to understand magic pointer-to-a-pointer (for - * multi-threading builds). We make this a static variable because - * this already is bad enough. + * We always have one instance + * @var Globals */ -extern ZEND_DECLARE_MODULE_GLOBALS(phpcpp) +extern Globals &globals; /** * End of namespace diff --git a/include/init.h b/include/init.h new file mode 100644 index 0000000..ca6ff65 --- /dev/null +++ b/include/init.h @@ -0,0 +1,57 @@ +/** + * Init.h + * + * Variables and structured required by the Zend engine to work + * with global variables + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2013 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * The way how PHP C API deals with "global" variables is stupid. + * + * This is supposed to turn into a structure that is going to be + * instantiated for each parallel running request, and for which the + * PHP engine allocates a certain amount of memory, and a magic + * pointer that is passed and should be forwarded to every thinkable + * PHP function. + * + * We don't like this architecture. We have our own environment object + * that makes much more sense, and that we use. However, we need + * to assign this object somewhere, so that's what we do in this + * one and only global variable + */ +ZEND_BEGIN_MODULE_GLOBALS(phpcpp) +ZEND_END_MODULE_GLOBALS(phpcpp) + +/** + * And now we're going to define a macro. This also is a ridiculous + * architecture from PHP to get access to a variable from the + * structure above. + */ +#ifdef ZTS +#define PHPCPP_G(v) TSRMG(phpcpp_globals_id, phpcpp_globals *, v) +#else +#define PHPCPP_G(v) (phpcpp_globals.v) +#endif + +/** + * We're almost there, we now need to declare an instance of the + * structure defined above (if building for a single thread) or some + * sort of impossible to understand magic pointer-to-a-pointer (for + * multi-threading builds). We make this a static variable because + * this already is bad enough. + */ +extern ZEND_DECLARE_MODULE_GLOBALS(phpcpp) + +/** + * End of namespace + */ +} + diff --git a/include/method.h b/include/method.h index 9398fd7..d652d89 100644 --- a/include/method.h +++ b/include/method.h @@ -33,11 +33,10 @@ public: /** * Invoke the method - * @param environment * @param parameters * @return Value */ - Value invoke(Environment &environment, Parameters ¶meters) + Value invoke(Parameters ¶meters) { // the object to call a method on Base *base = parameters.object(); @@ -46,12 +45,8 @@ public: switch (_type) { case 0: (base->*_callback.m0)(); return Value(); case 1: (base->*_callback.m1)(parameters); return Value(); - case 2: (base->*_callback.m2)(environment); return Value(); - case 3: (base->*_callback.m3)(environment, parameters); return Value(); - case 4: return (base->*_callback.m4)(); - case 5: return (base->*_callback.m5)(parameters); - case 6: return (base->*_callback.m6)(environment); - case 7: return (base->*_callback.m7)(environment, parameters); + case 2: return (base->*_callback.m2)(); + case 3: return (base->*_callback.m3)(parameters); default: return Value(); } } @@ -64,10 +59,6 @@ protected: _Method(method_callback_1 callback) : _type(1) { _callback.m1 = callback; } _Method(method_callback_2 callback) : _type(2) { _callback.m2 = callback; } _Method(method_callback_3 callback) : _type(3) { _callback.m3 = callback; } - _Method(method_callback_4 callback) : _type(4) { _callback.m4 = callback; } - _Method(method_callback_5 callback) : _type(5) { _callback.m5 = callback; } - _Method(method_callback_6 callback) : _type(6) { _callback.m6 = callback; } - _Method(method_callback_7 callback) : _type(7) { _callback.m7 = callback; } private: /** @@ -85,10 +76,6 @@ private: method_callback_1 m1; method_callback_2 m2; method_callback_3 m3; - method_callback_4 m4; - method_callback_5 m5; - method_callback_6 m6; - method_callback_7 m7; } _callback; }; @@ -105,12 +92,8 @@ public: */ Method(void(T::*callback)()) : _Method(static_cast<method_callback_0>(callback)) {} Method(void(T::*callback)(Parameters&)) : _Method(static_cast<method_callback_1>(callback)) {} - Method(void(T::*callback)(Environment&)) : _Method(static_cast<method_callback_2>(callback)) {} - Method(void(T::*callback)(Environment&,Parameters&)) : _Method(static_cast<method_callback_3>(callback)) {} - Method(Value(T::*callback)()) : _Method(static_cast<method_callback_4>(callback)) {} - Method(Value(T::*callback)(Parameters&)) : _Method(static_cast<method_callback_5>(callback)) {} - Method(Value(T::*callback)(Environment&)) : _Method(static_cast<method_callback_6>(callback)) {} - Method(Value(T::*callback)(Environment&,Parameters&)) : _Method(static_cast<method_callback_7>(callback)) {} + Method(Value(T::*callback)()) : _Method(static_cast<method_callback_2>(callback)) {} + Method(Value(T::*callback)(Parameters&)) : _Method(static_cast<method_callback_3>(callback)) {} /** * Destructor diff --git a/include/value.h b/include/value.h index 336bb1d..b2ce89b 100644 --- a/include/value.h +++ b/include/value.h @@ -564,9 +564,9 @@ protected: struct _zval_struct *_val; /** - * The environment can access the zval directly + * The Globals and Member classes can access the zval directly */ - friend class Environment; + friend class Globals; friend class Member; }; @@ -25,7 +25,7 @@ #include <phpcpp/type.h> #include <phpcpp/value.h> #include <phpcpp/hiddenpointer.h> -#include <phpcpp/environment.h> +#include <phpcpp/globals.h> #include <phpcpp/argument.h> #include <phpcpp/byval.h> #include <phpcpp/byref.h> diff --git a/src/extension.cpp b/src/extension.cpp index f4cc9ce..3e2ff25 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -77,17 +77,8 @@ static int extension_shutdown(SHUTDOWN_FUNC_ARGS) */ static int request_startup(INIT_FUNC_ARGS) { - // create the environment - Environment *environment = extension->createEnvironment(); - - // store in global structure - PHPCPP_G(environment) = environment; - - // initialize the environment - environment->initialize(); - // start the request - return BOOL2SUCCESS(environment->initialize() && extension->startRequest(*environment)); + return extension->startRequest(); } /** @@ -98,20 +89,8 @@ static int request_startup(INIT_FUNC_ARGS) */ static int request_shutdown(INIT_FUNC_ARGS) { - // retrieve the environment - Environment *environment = PHPCPP_G(environment); - // end the request - bool success = extension->endRequest(*environment) && environment->finalize(); - - // deallocate the environment - extension->deleteEnvironment(environment); - - // reset global variable - PHPCPP_G(environment) = NULL; - - // done - return BOOL2SUCCESS(success); + return BOOL2SUCCESS(extension->endRequest()); } /** @@ -203,10 +182,6 @@ Function *Extension::add(const char *name, native_callback_0 function, const std Function *Extension::add(const char *name, native_callback_1 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } Function *Extension::add(const char *name, native_callback_2 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } Function *Extension::add(const char *name, native_callback_3 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } -Function *Extension::add(const char *name, native_callback_4 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } -Function *Extension::add(const char *name, native_callback_5 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } -Function *Extension::add(const char *name, native_callback_6 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } -Function *Extension::add(const char *name, native_callback_7 function, const std::initializer_list<Argument> &arguments) { return add(new NativeFunction(name, function, arguments)); } /** * Retrieve the module entry diff --git a/src/function.cpp b/src/function.cpp index ef9cf78..a710f36 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -45,6 +45,7 @@ void invoke_function(INTERNAL_FUNCTION_PARAMETERS) } catch (Php::Exception &exception) { + // an exception originally thrown by C++ should be passed on to PHP zend_throw_exception(zend_exception_get_default(), (char*)exception.message().c_str(), 0 TSRMLS_CC); } } diff --git a/src/environment.cpp b/src/globals.cpp index 9b0a18e..e8672aa 100644 --- a/src/environment.cpp +++ b/src/globals.cpp @@ -1,7 +1,7 @@ /** - * Environment.cpp + * Globals.cpp * - * Implementation of the environment class + * Implementation of the globals class * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013 Copernica BV @@ -14,11 +14,27 @@ namespace Php { /** + * Get access to the globals single instance + * @return Globals + */ +Globals &Globals::instance() +{ + static Globals globals; + return globals; +} + +/** + * The one and only instance + * @var Globals + */ +Globals &globals = Globals::instance(); + +/** * Get access to a global variable * @param name * @return Global */ -Global Environment::operator[](const char *name) +Global Globals::operator[](const char *name) { // pointer to a zval zval **varvalue; @@ -43,7 +59,7 @@ Global Environment::operator[](const char *name) * @param name * @return Global */ -Global Environment::operator[](const std::string &name) +Global Globals::operator[](const std::string &name) { // pointer to a zval zval **varvalue; @@ -70,7 +86,7 @@ Global Environment::operator[](const std::string &name) * @param argv The parameters * @return Value */ -Value Environment::exec(const Value &name, int argc, zval ***params) +Value Globals::exec(const Value &name, int argc, zval ***params) { // the return zval zval *retval = nullptr; @@ -90,7 +106,7 @@ Value Environment::exec(const Value &name, int argc, zval ***params) * @param name Name of the function * @return Value */ -Value Environment::call(const Value &name) +Value Globals::call(const Value &name) { // call with zero parameters return exec(name, 0, NULL); @@ -102,7 +118,7 @@ Value Environment::call(const Value &name) * @param p0 The first parameter * @return Value */ -Value Environment::call(const Value &name, Value p0) +Value Globals::call(const Value &name, Value p0) { // array of parameters zval **params[1] = { &p0._val }; @@ -118,7 +134,7 @@ Value Environment::call(const Value &name, Value p0) * @param p1 The second parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1) +Value Globals::call(const Value &name, Value p0, Value p1) { // array of parameters zval **params[2] = { &p0._val, &p1._val }; @@ -135,7 +151,7 @@ Value Environment::call(const Value &name, Value p0, Value p1) * @param p2 The third parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2) { // array of parameters zval **params[3] = { &p0._val, &p1._val, &p2._val }; @@ -153,7 +169,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2) * @param p3 The fourth parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3) { // array of parameters zval **params[4] = { &p0._val, &p1._val, &p2._val, &p3._val }; @@ -172,7 +188,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p4 The fifth parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4) { // array of parameters zval **params[5] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val }; @@ -192,7 +208,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p5 The sixth parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) { // array of parameters zval **params[6] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val }; @@ -213,7 +229,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p6 The seventh parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) { // array of parameters zval **params[7] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val }; @@ -235,7 +251,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p7 The eight parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) { // array of parameters zval **params[8] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val }; @@ -258,7 +274,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p8 The nineth parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) { // array of parameters zval **params[9] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val }; @@ -282,7 +298,7 @@ Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p * @param p9 The tenth parameter * @return Value */ -Value Environment::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) +Value Globals::call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) { // array of parameters zval **params[10] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val, &p9._val }; diff --git a/src/includes.h b/src/includes.h index ac99950..ae8956f 100644 --- a/src/includes.h +++ b/src/includes.h @@ -38,7 +38,7 @@ #include "../include/type.h" #include "../include/value.h" #include "../include/hiddenpointer.h" -#include "../include/environment.h" +#include "../include/globals.h" #include "../include/argument.h" #include "../include/byval.h" #include "../include/byref.h" @@ -57,7 +57,7 @@ #include "../include/classinfo.h" #include "../include/extension.h" #include "../include/exception.h" -#include "../include/globals.h" +#include "../include/init.h" /** * Interface files for internal use only diff --git a/src/methodmember.h b/src/methodmember.h index 20f2749..9d4bcd1 100644 --- a/src/methodmember.h +++ b/src/methodmember.h @@ -51,13 +51,12 @@ public: /** * Method that gets called every time the function is executed - * @param environment Environment object * @param params The parameters that were passed * @return Variable Return value */ - virtual Value invoke(Environment &environment, Parameters ¶ms) + virtual Value invoke(Parameters ¶ms) { - return _method.invoke(environment, params); + return _method.invoke(params); } private: diff --git a/src/nativefunction.h b/src/nativefunction.h index 2a61ccb..8b946a3 100644 --- a/src/nativefunction.h +++ b/src/nativefunction.h @@ -28,10 +28,6 @@ public: NativeFunction(const char *name, native_callback_1 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(1) { _function.f1 = function; } NativeFunction(const char *name, native_callback_2 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(2) { _function.f2 = function; } NativeFunction(const char *name, native_callback_3 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(3) { _function.f3 = function; } - NativeFunction(const char *name, native_callback_4 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(4) { _function.f4 = function; } - NativeFunction(const char *name, native_callback_5 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(5) { _function.f5 = function; } - NativeFunction(const char *name, native_callback_6 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(6) { _function.f6 = function; } - NativeFunction(const char *name, native_callback_7 function, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _type(7) { _function.f7 = function; } /** * Destructor @@ -40,21 +36,16 @@ public: /** * Method that gets called every time the function is executed - * @param environment Environment * @param params The parameters that were passed * @return Variable Return value */ - virtual Value invoke(Environment &environment, Parameters ¶ms) override + virtual Value invoke(Parameters ¶ms) override { switch (_type) { case 0: _function.f0(); return Value(); case 1: _function.f1(params); return Value(); - case 2: _function.f2(environment); return Value(); - case 3: _function.f3(environment, params); return Value(); - case 4: return _function.f4(); - case 5: return _function.f5(params); - case 6: return _function.f6(environment); - case 7: return _function.f7(environment, params); + case 2: return _function.f2(); + case 3: return _function.f3(params); default: return Value(); } } @@ -69,10 +60,6 @@ private: native_callback_1 f1; native_callback_2 f2; native_callback_3 f3; - native_callback_4 f4; - native_callback_5 f5; - native_callback_6 f6; - native_callback_7 f7; } _function; /** |