This make no sense! Blogger has been having issues, and for some reason, I can't set the title on postings of this particular blog! ARG!
Anyway I was thinking about the vm. Why not make it simply manipulate objects, and nothing else. By this I mean the vm will know nothing about object/data types and therefore, it won't support math and such. Instead, such operations will be stored in native-code modules that can be loaded into the vm. For example, consider what happens traditionally when adding two numbers. The numbers get pushed into the stack, and then the add operator is executed, which then pops the two numbers, adds them, and pushes the result into the stack:
5 4 add
But this means the vm contains the add operator and knows about numbers and how to add them. What if the vm is unaware of data types and only contains basic stack-manipulation operators. Since xX is object-oriented at the lowest level, it knows how to create objects. So, lets add the same two numbers:
math load 5 Number new 4 Number new add
In the code above, the math module is loaded, 5 is pushed into the stack, followed by Number, which is a class name, and followed by the new operator. The new operator creates an object using the provided class name as a template. When new is executed, it pops the stack to retrieve the class name. The class name is then looked up in the definition dictionary (think PostScript) to determine the coded needed to create the object. In this case, the code is native, so it's a pointer to a function. This function, which acts as an object constructor, is executed. In the case of the Number function, the stack is popped to retrieve the initial value for the number. The object is then created and pushed into the stack. The same process is used to create an object for the second number. When add is executed, it pops the stack to get the number object (4), and calls it's add method with the argument 5.
Anyway, that's my crazy idea. Somewhat cloudy still.
Anyway I was thinking about the vm. Why not make it simply manipulate objects, and nothing else. By this I mean the vm will know nothing about object/data types and therefore, it won't support math and such. Instead, such operations will be stored in native-code modules that can be loaded into the vm. For example, consider what happens traditionally when adding two numbers. The numbers get pushed into the stack, and then the add operator is executed, which then pops the two numbers, adds them, and pushes the result into the stack:
5 4 add
But this means the vm contains the add operator and knows about numbers and how to add them. What if the vm is unaware of data types and only contains basic stack-manipulation operators. Since xX is object-oriented at the lowest level, it knows how to create objects. So, lets add the same two numbers:
math load 5 Number new 4 Number new add
In the code above, the math module is loaded, 5 is pushed into the stack, followed by Number, which is a class name, and followed by the new operator. The new operator creates an object using the provided class name as a template. When new is executed, it pops the stack to retrieve the class name. The class name is then looked up in the definition dictionary (think PostScript) to determine the coded needed to create the object. In this case, the code is native, so it's a pointer to a function. This function, which acts as an object constructor, is executed. In the case of the Number function, the stack is popped to retrieve the initial value for the number. The object is then created and pushed into the stack. The same process is used to create an object for the second number. When add is executed, it pops the stack to get the number object (4), and calls it's add method with the argument 5.
Anyway, that's my crazy idea. Somewhat cloudy still.


0 Comments:
Post a Comment
<< Home