Changeset 619
- Timestamp:
- 08/01/08 10:24:51 (4 months ago)
- Files:
-
- trunk/rphp/runtime/include/pExtBase.h (modified) (2 diffs)
- trunk/rphp/runtime/include/pExtManager.h (modified) (1 diff)
- trunk/rphp/runtime/include/pFunctionManager.h (modified) (1 diff)
- trunk/rphp/runtime/include/pFunctionSig.h (modified) (2 diffs)
- trunk/rphp/runtime/include/pTypes.h (modified) (3 diffs)
- trunk/rphp/runtime/include/pVar.h (modified) (1 diff)
- trunk/rphp/runtime/pExtBase.cpp (modified) (1 diff)
- trunk/rphp/runtime/pExtManager.cpp (modified) (2 diffs)
- trunk/rphp/runtime/pFunctionManager.cpp (modified) (1 diff)
- trunk/rphp/runtime/pRuntime.cpp (modified) (1 diff)
- trunk/rphp/runtime/pTypes.cpp (modified) (1 diff)
- trunk/rphp/runtime/test/CMakeLists.txt (modified) (1 diff)
- trunk/rphp/runtime/test/functionTestCase.cpp (added)
- trunk/rphp/runtime/test/functionTestCase.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/include/pExtBase.h
r618 r619 21 21 22 22 #include <string> 23 #include "pTypes.h" 23 24 #include "pFunctionManager.h" 24 25 … … 33 34 pRuntimeEngine* runtime; 34 35 35 void registerBuiltin( std::string name, pFunPointer1 f);36 void registerBuiltin(pUString name, pFunPointer1 f); 36 37 37 38 public: trunk/rphp/runtime/include/pExtManager.h
r617 r619 30 30 class pExtManager { 31 31 32 typedef std::deque<pExtBase*> registryType;32 typedef std::deque<pExtBase*> extRegistryType; 33 33 34 34 private: 35 35 pRuntimeEngine* runtime; 36 registryType extRegistry;36 extRegistryType extRegistry; 37 37 38 38 public: 39 pExtManager(pRuntimeEngine *r) ;39 pExtManager(pRuntimeEngine *r): runtime(r) { } 40 40 ~pExtManager(); 41 42 void startUp(); 41 43 42 44 }; trunk/rphp/runtime/include/pFunctionManager.h
r618 r619 21 21 22 22 #include <string> 23 #include <boost/multi_index_container.hpp> 24 #include <boost/multi_index/hashed_index.hpp> 25 #include <boost/multi_index/member.hpp> 26 #include <ext/hash_map> 23 27 #include "pFunctionSig.h" 28 29 using boost::multi_index_container; 30 using namespace boost::multi_index; 24 31 25 32 namespace rphp { 26 33 34 struct functionEntry { 35 pUString canonicalName; 36 pFunctionSig* signature; 37 functionEntry(pUString name, pFunctionSig* sig) : canonicalName(name.toLower()), signature(sig) { } 38 }; 39 40 typedef multi_index_container< 41 functionEntry, 42 indexed_by< 43 hashed_unique < 44 BOOST_MULTI_INDEX_MEMBER(functionEntry, const pUString, canonicalName) 45 > 46 > 47 > functionRegistryType; 48 49 class pRuntimeEngine; 50 27 51 class pFunctionManager { 28 52 29 30 53 private: 54 pRuntimeEngine* runtime; 55 functionRegistryType functionRegistry; 31 56 32 57 public: 33 58 34 //pFunctionManager(pRuntimeEngine *r) : runtime(r) { } 59 pFunctionManager(pRuntimeEngine *r) : runtime(r) { } 60 ~pFunctionManager() { 61 // TODO delete function signatures 62 } 35 63 36 void registerBuiltin(std::string name, pFunPointer1 f); 64 void registerBuiltin(const pExtBase*, const pUString&, const pFunPointer1&); 65 66 pVar invoke(pUString funName, pVar arg1) { 67 functionRegistryType::iterator function = functionRegistry.find(funName.toLower()); 68 if (function != functionRegistry.end()) { 69 return (*function).signature->invoke(arg1); 70 } 71 else { 72 return pNull; 73 } 74 } 37 75 38 76 }; trunk/rphp/runtime/include/pFunctionSig.h
r618 r619 21 21 22 22 #include <vector> 23 #include <string>24 23 #include <boost/function.hpp> 25 #include "p Var.h"24 #include "pTypes.h" 26 25 27 26 namespace rphp { … … 45 44 class pFunctionSig { 46 45 private: 47 // declaration location 48 pUInt startLineNum;49 pUInt endLineNum; 50 pUString fileName;51 pExtBase* parentExtension;46 // declaration location (user function) 47 const pSourceStartEndLocation sourceLocation; 48 49 // or parent extension (only builtins) 50 const pExtBase* parentExtension; 52 51 53 52 // docComment? 54 53 55 54 // signature 56 pUString functionName; 57 pUString canonicalName; 58 pFunType funType; 59 pUInt arity; 60 pUInt minRequiredArity; 61 bool isVarArity; 55 const pUString functionName; 56 const pFunType funType; 57 const pUInt requiredArity; 58 const pUInt maxArity; 59 const bool isVarArity; 62 60 63 61 std::vector<pFunctionParam> paramList; 64 62 63 const pFunPointer1 funPointer1; 64 65 65 public: 66 67 // standard builtin function: one argument 68 pFunctionSig(const pExtBase* e, const pUString& f, const pFunPointer1& fun) : 69 parentExtension(e), 70 functionName(f), 71 funType(pBuiltinFunType), 72 requiredArity(1), 73 maxArity(1), 74 isVarArity(false), 75 funPointer1(fun) 76 { 77 78 } 79 80 // invocation 81 pVar invoke(pVar arg1) { 82 return funPointer1(arg1); 83 } 66 84 67 85 }; trunk/rphp/runtime/include/pTypes.h
r618 r619 21 21 22 22 #include <boost/lexical_cast.hpp> 23 #include <boost/tuple/tuple.hpp> 23 24 24 25 #include "pVar.h" … … 26 27 #include "pObject.h" 27 28 29 U_NAMESPACE_BEGIN 30 // boost hash function for pUString 31 std::size_t hash_value(rphp::pUString const& k); 32 U_NAMESPACE_END 33 28 34 namespace rphp { 35 36 // types used in the runtime which aren't related to pVar (i.e. that aren't builtin php types) 37 38 // note, pUInt is not a base PHP type (all PHP numbers are signed) 39 typedef unsigned long pUInt; 40 41 // source locations: filename/linenum 42 typedef boost::tuple<const pUString, const pUInt> pSourceLocation; 43 44 // source locations: filename/startlinenum/endlinenum 45 typedef boost::tuple<const pUString, const pUInt, const pUInt> pSourceStartEndLocation; 29 46 30 47 // a visitor for determining type of pVar … … 186 203 } 187 204 188 inline longpVar_getVal_pInt(const pVar &p) {205 inline pInt pVar_getVal_pInt(const pVar &p) { 189 206 return boost::get<pInt>(p); 190 207 } trunk/rphp/runtime/include/pVar.h
r618 r619 47 47 typedef double pFloat; 48 48 49 // note, pUInt is not a base PHP type (all PHP numbers are signed)50 typedef unsigned long pUInt;51 52 49 // string types: binary and unicode flavor 53 50 // "binary" strings trunk/rphp/runtime/pExtBase.cpp
r618 r619 22 22 namespace rphp { 23 23 24 void pExtBase::registerBuiltin( std::string name, pFunPointer1 f) {24 void pExtBase::registerBuiltin(pUString name, pFunPointer1 f) { 25 25 26 runtime->functionManager->registerBuiltin( name, f);26 runtime->functionManager->registerBuiltin(this, name, f); 27 27 28 28 } trunk/rphp/runtime/pExtManager.cpp
r617 r619 24 24 namespace rphp { 25 25 26 /* 26 27 pExtManager::pExtManager(pRuntimeEngine *r) : runtime(r) { 27 28 29 30 } 31 */ 32 33 void pExtManager::startUp() { 34 28 35 // initialize standard library 29 pStandardExt* sext = new pStandardExt(r );36 pStandardExt* sext = new pStandardExt(runtime); 30 37 sext->extensionStartup(); 31 38 extRegistry.push_back(sext); … … 36 43 37 44 // shutdown extensions 38 for ( registryType::iterator i=extRegistry.begin(); i!=extRegistry.end(); ++i) {45 for (extRegistryType::iterator i=extRegistry.begin(); i!=extRegistry.end(); ++i) { 39 46 (*i)->extensionShutdown(); 40 47 delete *i; trunk/rphp/runtime/pFunctionManager.cpp
r618 r619 22 22 namespace rphp { 23 23 24 void pFunctionManager::registerBuiltin( std::string name, pFunPointer1f) {24 void pFunctionManager::registerBuiltin(const pExtBase* sourceExt, const pUString& funName, const pFunPointer1& f) { 25 25 26 std::cout << "registering " << name << std::endl; 26 std::cout << "registering " << funName << std::endl; 27 functionRegistry.insert(functionEntry(funName, new pFunctionSig(sourceExt, funName, f))); 27 28 28 29 } trunk/rphp/runtime/pRuntime.cpp
r618 r619 25 25 26 26 pRuntimeEngine::pRuntimeEngine() : extManager(new pExtManager(this)), 27 functionManager(new pFunctionManager( ))27 functionManager(new pFunctionManager(this)) 28 28 { 29 29 // runtime initialization 30 31 // load standard extension 30 extManager->startUp(); 32 31 33 32 } trunk/rphp/runtime/pTypes.cpp
r618 r619 18 18 19 19 #include "pTypes.h" 20 21 U_NAMESPACE_BEGIN 22 std::size_t hash_value(rphp::pUString const& k) { 23 return (std::size_t)k.hashCode(); 24 } 25 U_NAMESPACE_END 20 26 21 27 namespace rphp { trunk/rphp/runtime/test/CMakeLists.txt
r611 r619 7 7 8 8 # XXX fixme 9 link_directories (${CMAKE_SOURCE_DIR}/../ build/)9 link_directories (${CMAKE_SOURCE_DIR}/../../build/runtime/) 10 10 include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/../include/) 11 11 12 12 # test apps 13 add_executable( rphp-runtime-suite main.cpp phashTestCase.cpp pvarTestCase.cpp )13 add_executable( rphp-runtime-suite main.cpp phashTestCase.cpp pvarTestCase.cpp functionTestCase.cpp ) 14 14 target_link_libraries( rphp-runtime-suite cppunit rphp-runtime ${ICU_LIBRARIES} ${ICU_IO_LIBRARIES})
