LinderScript virtual machine: feedback wanted

Started by
22 comments, last by BAH_Strike 17 years, 4 months ago
For some time i've been working on a virtual machine integrated into my engine (http://www.linderdaum.com) capable of such features as: 0) UnrealScript-looking object model 1) inherit script classes from native C++ classes 2) allow mixed classes (part of the classe's methods are written in C++, part in script) 3) allow transparent usage of scripted classes in C++ code 4) allow fast methods invokation 5*) latent functions - this one is still been discussed and under construction The scripting system is called LinderScript and it is part of the Linderdaum Engine. It has far more advanced features than usual standalone scripting systems could provide. The LinderScript Run-Time is the heart of the Linderdaum Engine and provides a metaclasses management facilities. Well, it is inseparable from the engine, but as a plus we have a bunch of features which any standalone scripting system is unable to provide: purely object-oriented solution where one can derive scripted classes from native C++ ones, there is no difference for the engine if some class contains scripted methods or not, in derived classes you can override some methods with LinderScript or leave them as inherited C++ methods at your own will. All this stuff is handled at the lowest level inside the engine so any engine’s class could be extended or rewritten using LinderScript. At the same time the performance of the LinderScript is comparable to Python. Could you have a look at it and maybe recommend some future extensions, point to the pitfalls and so on ;) Source code FAQ Doxygen-generated documentation [Edited by - _Sergey_ on September 26, 2006 2:19:36 AM]
--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com
Advertisement
Do you have any sort of info on the VM except the source? A design doc or something?
No special documentation, except the one autogenerated by Doxygen (http://www.linderdaum.com/Docs/HTML/index.html)
--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com
Nobody interested in such kind of things? Or everybody silently downloaded the source... ;)
--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com
I suspect many people do not have time to read and conceptualize the source... you will probably get more responses if you ask specific questions about smaller aspects of your design (after describing how you implemented them), rather than asking for general comments about a huge chunk of your code.
Now for me one of the most important things is - how typesafe is this code and what is possible to improve:

#include <memory>#include <vector>class iParameter;typedef std::vector<iParameter*>    clParametersList;class iParameter{public:   iParameter() {};   virtual ~iParameter() {};   //   // iParameter   //   virtual LString  GetParamType() const = 0;   virtual int      GetParamSize() const = 0;   virtual void     ReadValue(const void* UntypedNativeBlock) = 0;   virtual void*    GetNativeBlock() = 0;   virtual void     PushToStack(iStack* Stack) const = 0;   virtual void     PopFromStack(iStack* Stack) = 0;};class clStringParameter: public iParameter{public:   //   // iParameter interface   //   virtual LString  GetParamType() const { return "STRING"; } ;   virtual int      GetParamSize() const { return sizeof(LStringBuffer); };   virtual void     ReadValue(const void* UntypedNativeBlock)   {      FString = *reinterpret_cast<const LString*>(UntypedNativeBlock);   }   virtual void*    GetNativeBlock()   {      return &FString;   }   virtual void     PushToStack(iStack* Stack) const   {      LStringBuffer Buffer = FString.GetStringBuffer();      Stack->Push( Buffer );   }   virtual void     PopFromStack(iStack* Stack)   {      LStringBuffer Buffer = Stack->Pop<LStringBuffer>();      FString = LString( Buffer );   }private:   LString    FString;};class clScriptedPODParameter: public iParameter{public:   clScriptedPODParameter(int Size):FSize(Size), FParameter( malloc(Size) ) {};   virtual ~clScriptedPODParameter() { free(FParameter); };   //   // iParameter interface   //   virtual LString  GetParamType() const { return "SCRIPTED_POD"; } ;   virtual int      GetParamSize() const { return FSize; };   virtual void     ReadValue(const void* UntypedNativeBlock)   {      memcpy( FParameter, UntypedNativeBlock, FSize );   }   virtual void*    GetNativeBlock()   {      return FParameter;   }   virtual void     PushToStack(iStack* Stack) const   {      Stack->PushBytes( FSize, FParameter );   }   virtual void     PopFromStack(iStack* Stack)   {      Stack->PopBytes( FSize, FParameter );         }private:   int      FSize;   void*    FParameter;};template <class T> class clPODParameter: public clScriptedPODParameter{public:   clPODParameter():clScriptedPODParameter( sizeof(T) ) {};};template <typename T> class clPointerParameter: public iParameter{public:   clPointerParameter():FPointer(NULL) {};   //   // iParameter interface   //   virtual LString  GetParamType() const { return "PTR"; } ;   virtual int      GetParamSize() const { return sizeof(T*); };   virtual void     ReadValue(const void* UntypedNativeBlock)   {       FPointer = *reinterpret_cast<T**>( const_cast<void*>( UntypedNativeBlock ) );   }   virtual void*    GetNativeBlock()   {      return &FPointer;   }   virtual void     PushToStack(iStack* Stack) const   {      Stack->Push<T*>( FPointer );   }   virtual void     PopFromStack(iStack* Stack)   {      FPointer = Stack->Pop<T*>();   }private:   T*   FPointer;};#define PARAMETER( selector, type ) typename SelectType<                                        TypeTraits<T>::selector, type,#define PTR_TRAITS typename ::LEngine::Utils::TypeTraits<T>::PointeeType#define REF_TRAITS typename ::LEngine::Utils::TypeTraits<T>::ReferredTypeusing namespace ::LEngine::Utils;template <class T>struct ParameterType{   typedef    PARAMETER( IsString,         clStringParameter              )   PARAMETER( IsReference,      clPODParameter<REF_TRAITS>     )   PARAMETER( IsPointer,        clPointerParameter<PTR_TRAITS> )   PARAMETER( IsFundamental,    clPODParameter<T>              )   // defaule   clPODParameter<T>   >::Result   >::Result   >::Result    >::Result    Type;};template <class T> inline iParameter* CreateNativeParameter(){   return new (typename ParameterType<T>::Type);}template <class T> inline iParameter* CreateInvokeParameter(T P){   iParameter* Param = CreateNativeParameter<T>();   Param->ReadValue( &P );   return Param;}



The purpose of this is to allow typesafe parameters transfer from native methods into scripted and back.
--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com
Quote:Original post by 0xCHAOS
I suspect many people do not have time to read and conceptualize the source... you will probably get more responses if you ask specific questions about smaller aspects of your design (after describing how you implemented them), rather than asking for general comments about a huge chunk of your code.


agreed, VERY few people are likely to spend any significant amount of time trying to understand your source code in order to come up with suggestions for improvements, be specific and we'll be specific in your questions, be coarse and we'll be, too.

Original post by Anonymous Poster
Quote:Original post by 0xCHAOS
VERY few people are likely to spend any significant amount of time

Does this mean, that most people will more likely use any ready out-of-the-box solution instead of trying to learn and create there own one? Seems so from my experience...

--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com
nope, this was merely referring to the requested FEEDBACK not to actually using your code-however, using it as well as providing feedback would be more straightforward to do, if there was some basic background information-I mean more than just the source, which has to be looked at, read, understood.
And what kind of information do you think would be the most interesting and useful?
--Sergey K. Linderdaum Project Coordinator http://www.linderdaum.comsupport@linderdaum.com

This topic is closed to new replies.

Advertisement