Changeset 618

Show
Ignore:
Timestamp:
07/30/08 13:38:03 (4 months ago)
Author:
weyrick
Message:

more work on functions and extensions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/frontend/cli/main.cpp

    r616 r618  
    55#include <boost/program_options.hpp> 
    66#include "pDriver.h" 
     7#include "pRuntime.h" 
    78 
    89namespace po = boost::program_options; 
     
    1112{ 
    1213 
     14    rphp::pRuntimeEngine runtime; 
    1315    rphp::pDriver driver; 
    1416 
     
    3335        return 1; 
    3436    } 
    35      
     37 
    3638    //std::cout << "Roadsend PHP" << std::endl; 
    3739 
     
    4244 
    4345    //std::cout << "Optimization level is " << opt << "\n"; 
    44   
     46 
    4547} 
  • trunk/rphp/runtime/CMakeLists.txt

    r617 r618  
    1313  pOutputManager.cpp 
    1414  pFunctionManager.cpp 
     15  pFunctionSig.cpp 
    1516  pExtBase.cpp 
    1617  pExtManager.cpp 
  • trunk/rphp/runtime/include/pExtBase.h

    r617 r618  
    2020#define PEXTENSIONBASE_H_ 
    2121 
     22#include <string> 
     23#include "pFunctionManager.h" 
     24 
    2225namespace rphp { 
    2326 
     
    2730 
    2831    protected: 
     32        std::string extName; 
    2933        pRuntimeEngine* runtime; 
    3034 
     35        void registerBuiltin(std::string name, pFunPointer1 f); 
     36 
    3137    public: 
    32         pExtBase(pRuntimeEngine *r) : runtime(r) { } 
     38        pExtBase(pRuntimeEngine *r, std::string eName) : runtime(r), extName(eName) { } 
    3339 
    3440        virtual void extensionStartup() = 0; 
  • trunk/rphp/runtime/include/pFunctionManager.h

    r617 r618  
    2020#define RPHP_PFUNCTIONMANAGER 
    2121 
     22#include <string> 
     23#include "pFunctionSig.h" 
     24 
    2225namespace rphp { 
    23  
    24     class pRuntimeEngine; 
    2526 
    2627    class pFunctionManager { 
    2728 
     29 
    2830        private: 
    29             pRuntimeEngine* runtime; 
    3031 
    3132        public: 
    32             pFunctionManager(pRuntimeEngine *r) : runtime(r) { } 
     33 
     34            //pFunctionManager(pRuntimeEngine *r) : runtime(r) { } 
     35 
     36            void registerBuiltin(std::string name, pFunPointer1 f); 
    3337 
    3438    }; 
  • trunk/rphp/runtime/include/pTypes.h

    r600 r618  
    106106            var = (pInt)h->getSize(); 
    107107        } 
    108          
     108 
    109109        void operator()(pObjectP &h) const { 
    110110            var = (pInt)h->getNumProperties(); 
     
    118118    }; 
    119119 
     120    // a visitor for converting to a string 
     121    class convertToBString : public boost::static_visitor<void> { 
     122    protected: 
     123        pVar &var; 
     124 
     125    public: 
     126        convertToBString(pVar &v) : var(v) { } 
     127 
     128        void operator()(pTriState &h) const { 
     129                (h) ? var = pBString("1") : var = pBString("0"); 
     130        } 
     131 
     132        void operator()(pInt &a) const { 
     133            // TODO: real conversion 
     134            var = pBString("some pInt"); 
     135        } 
     136 
     137        void operator()(pFloat &i) const { 
     138            // TODO: real conversion 
     139            var = pBString("some pFloat"); 
     140        } 
     141 
     142        void operator()(pBString &a) const { 
     143            // nothing 
     144        } 
     145 
     146        void operator()(pUStringP &a) const { 
     147            // TODO 
     148        } 
     149 
     150        void operator()(pHashP &h) const { 
     151            var = pBString("array"); 
     152        } 
     153 
     154        void operator()(pObjectP &h) const { 
     155            // TODO: toString 
     156            var = pBString("object"); 
     157        } 
     158 
     159        void operator()(pVarRef &r) const { 
     160            // TODO 
     161            // unbox 
     162            //boost::apply_visitor(convertToNumber(*r), *r); 
     163        } 
     164 
     165    }; 
    120166 
    121167    /* 
     
    143189            return boost::get<pInt>(p); 
    144190    } 
    145      
     191 
    146192    inline pBString pVar_getVal_pBString(const pVar &p) { 
    147193            return boost::get<pBString>(p); 
    148194    } 
    149      
     195 
    150196    inline pUStringP pVar_getVal_pUString(const pVar &p) { 
    151197            return boost::get<pUStringP>(p); 
     
    161207     */ 
    162208    pVar pVar_castToNumber(const pVar p); 
     209    pVar pVar_castToBString(const pVar p); 
     210 
    163211    pVar pVar_add(const pVar lhs, const pVar rhs); 
    164212 
  • trunk/rphp/runtime/include/pVar.h

    r593 r618  
    4747    typedef double pFloat; 
    4848 
     49    // note, pUInt is not a base PHP type (all PHP numbers are signed) 
     50    typedef unsigned long pUInt; 
     51 
    4952    // string types: binary and unicode flavor 
    5053    // "binary" strings 
  • trunk/rphp/runtime/pExtBase.cpp

    r617 r618  
    1818 
    1919#include "pExtBase.h" 
     20#include "pRuntime.h" 
    2021 
    2122namespace rphp { 
    2223 
     24void pExtBase::registerBuiltin(std::string name, pFunPointer1 f) { 
    2325 
     26    runtime->functionManager->registerBuiltin(name, f); 
    2427 
    2528} 
     29 
     30} 
  • trunk/rphp/runtime/pFunctionManager.cpp

    r617 r618  
    2222namespace rphp { 
    2323 
     24void pFunctionManager::registerBuiltin(std::string name, pFunPointer1 f) { 
     25 
     26    std::cout << "registering " << name << std::endl; 
    2427 
    2528} 
    2629 
    2730 
     31} 
     32 
     33 
  • trunk/rphp/runtime/pRuntime.cpp

    r617 r618  
    2525 
    2626pRuntimeEngine::pRuntimeEngine() : extManager(new pExtManager(this)), 
    27                                    functionManager(new pFunctionManager(this)) 
     27                                   functionManager(new pFunctionManager()) 
    2828{ 
    2929    // runtime initialization 
    3030 
    3131    // load standard extension 
    32      
     32 
    3333} 
    3434 
    3535 
    3636pRuntimeEngine::~pRuntimeEngine() { 
    37     // runtime shutdown  
     37    // runtime shutdown 
    3838    delete functionManager; 
    3939    delete extManager; 
  • trunk/rphp/runtime/pTypes.cpp

    r600 r618  
    2323    // non destructive cast (explicit copy) 
    2424    pVar pVar_castToNumber(const pVar p) { 
    25  
    2625        pVar r = p; 
    2726        boost::apply_visitor(convertToNumber(r), r); 
    2827        return r; 
     28    } 
    2929 
     30    // non destructive cast (explicit copy) 
     31    pVar pVar_castToBString(const pVar p) { 
     32        pVar r = p; 
     33        boost::apply_visitor(convertToBString(r), r); 
     34        return r; 
    3035    } 
    3136 
  • trunk/rphp/runtime/standard/pStandardExt.cpp

    r617 r618  
    2626    std::cout << "initializing standard extension" << std::endl; 
    2727 
     28    registerBuiltin("strlen", boost::bind(&pStandardExt::strlen, this, _1)); 
     29 
    2830} 
    2931 
     
    3436} 
    3537 
     38/* Library Implementation */ 
     39 
     40pVar pStandardExt::strlen(pVar str) { 
     41    pVar_castToBString(str); 
     42    return (pInt)pVar_getVal_pBString(str).length(); 
     43} 
    3644 
    3745} 
  • trunk/rphp/runtime/standard/pStandardExt.h

    r617 r618  
    2020#define PSTANDARDEXT_H_ 
    2121 
     22#include "pTypes.h" 
    2223#include "pExtBase.h" 
     24 
     25#define STD_EXT_NAME "standard" 
    2326 
    2427namespace rphp { 
     
    2831    public: 
    2932 
    30         pStandardExt(pRuntimeEngine *r) : pExtBase(r) { } 
     33        pStandardExt(pRuntimeEngine *r) : pExtBase(r, STD_EXT_NAME) { } 
    3134 
    3235        void extensionStartup(); 
    3336        void extensionShutdown(); 
     37 
     38        pVar strlen(pVar str); 
    3439 
    3540    };