Related articles |
---|
[2 earlier articles] |
Re: My scripting language - any suggestions? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-08-27) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-29) |
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-30) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31) |
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-08-31) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-31) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-01) |
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-09-02) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-02) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-09-04) |
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-09-06) |
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-09-07) |
[4 later articles] |
From: | lican <licaner@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Sun, 31 Aug 2008 10:05:00 -0700 (PDT) |
Organization: | Compilers Central |
References: | 08-08-069 08-08-081 08-08-100 08-08-106 08-08-107 08-08-109 |
Keywords: | OOP, types |
Posted-Date: | 31 Aug 2008 13:11:05 EDT |
Yeah, I thought about it. You're right. ToFloat is not scalable. Maybe
something like: To(Float), To(Type)? It's something between
my .ToType() and the 'to' operator proposed Johannes. Every solution
is better than the ugly (SomeClass)var).SomeMethod() ;) The preference
is to use as few (key)word operators as possible. I'm also thinking
about changing new Class to Class.New() or Class.Create(); It would
create a rather consistent interface with methods like object.Clone()
and maybe object.Destroy(). Also the general idea is that all objects
inherit some general methods from the base object called
'Object' (like Java and C#). The methods can be overridden depending
on the type:
- bool Is( Type )
- bool Instance( Type ) or Of( Type ) or InstanceOf( Type )
- Object To( Type )
- String Serialize();
- bool Unserialize();
- Object Clone();
- void Destroy();
As for the int and float representation... the Value class takes care
of that stuff. It's written in C++ and goes something like this:
[code]
class Value
{
public:
Value();
Value( Value& value );
Value& operator =( Value& value );
void SetNull();
void SetBool( bool b );
void SetInt( int i );
void SetFloat( float f );
void SetString( String* s );
...................................
public:
int type; // NULL, BOOL, INT, FLOAT, STRING, ARRAY, REF, OBJECT,
FUNC, ect
union
{
bool b;
int i;
float f;
} ;
Object* o; // everything else
};
[/code]
It's rather simple, but it works. Most scripting VM work that way.
As for the Serialize and To(String) methods, I find them distinct.
I.e. someone wants to display a float to the user, they do
var.To(Float) and get '1234.0987'. But if someone wants to write the
data to a file Serialize would return 'f:1234.0987' or 'float:
1234.0987'. The thing is I think the type:value can be parsed more
easily than just value.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.