Archived

This topic is now archived and is closed to further replies.

Virtual Machine (Java and Unreal) question

This topic is 5306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am currently developing a virtual machine, i have played with several concepts of internal object and class representation. I have researched Java 2, Unreal, and even a few more obscure virtual machine implementations and all do it a little differently. If anyone has any ideas or could shed some light on this subject I would be most appreciative. Scenerio: 1) Class information is loaded from a file in raw data format 2) An Object of Class "Class" is created to store this raw data and create the appropriate data structures for things such as methods, variables, and states in the case of unreal. 3) HERE IS MY PROBLEM : when instantiating a class type into an object instance of that class, how do i represent that. In my code i have a base object that provides basic functionality and a subclass called class that stores information. I know this is confusing but if anyone understands what i am saying and has any advice i would be gratefull.

Share this post


Link to post
Share on other sites
Well here is how Java does it. The base type java.lang.Object contains a member java.lang.Class. The java.lang.Class contains all the type information, methods, and members of a class. For each class type that is loaded by the Virtual Machine a new java.lang.Class is created, keep in mind that the constructors for this class are not public as only the Vitrual Machine can create instance of it. When new instance of the class is created, i.e. a java.lang.Object, either a handle or copy of the underlying java.lang.Class is set in the Object.

This differs from your solution in that you have your class inheriting from Object instead of having the Object contain a handle to a Class instance. By doing it the way you have your object model is stating that classes extend objects which isn’t not accurate.

Share this post


Link to post
Share on other sites
Torque Script''s virtual machine is great. Every single object that can be accessed in script can be serialized to a text-based script file, later to be unserialized back into the script environment, all seamlessly. This allows you to just concentrate on the development of your script language and how it integrates into your system. Once you get that down, get the scripts compiled, and you''re all set.

Share this post


Link to post
Share on other sites
What language are you coding in?

I would suggest adding code the classes to allow self-instanciation(sp?, is that even a real word?)

Look for information on serialization and rtti.

I have some serialization code if your interested.

Kory

Share this post


Link to post
Share on other sites
Thanks to all who replied,

to PaleRaider:
I realize that I am inheriting object in class but this is all in native code so that I only have one type of object on my heap meaning that base object object contains serialization functionality, stack frame, and garbage collection info so that any object on the heap is of the same base type. This is definitely the way Unreal does it. Each object class has a pointer to the class it is, its name, its index in the object hash table, and other object only stuff. Its really just an abstract placeholder.

to daerid:
I have never been able to quite figure out the torque scripting system. I do own a license of it and have read the code extensively but its to embeded in with everything else. I am just writing a straitforwared VM and then building from there.

to kspansel:
I am coding the native VM in C++

To Add to my first question and perhaps elaborate:

Scenerio:
All the class data is loaded into method area data structures like Java. Then a class class object is created and is linked to that information and resolves references by looking at other loaded classes method area structures basically like the java linking model.
Then when i want to create my Actor, Pawn, Engine Ect. I create What? A new Class? this creates a problem because i somehow have to have a real object of the created class somewhere like the native Actor class must be created as well ( loaded from a .dll or something ) then any native functionaliy can be access through it ( Unreal generates C++ header files by scanning script files and creates native function stubs ). But I also have the script only functions and variables to think about. so what object do i create ( or does that link to a class in the base object give me access to the classes methods, if so then what about variables i need unique values for each reference ).

I think if i can wrap my head around this It will be a breeze from here out.

BTW there is another source i have drawn from called the Nebula Device i believe written by the guys at Radon Labs its also a very interesting piece of code but doesnt provide pure virtual machine implementation.


Share this post


Link to post
Share on other sites