Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

partially implemented enhancer

  • Loading branch information...
commit 12e4c7305cafbf2829ec88aa047898aba0a2f9f2 1 parent 965521c
Nature Fresh Milk authored
View
152 src/main/js/21_jsjvm.interpreter.MethodInterpreter.js
@@ -2,55 +2,11 @@
(function(){
var logger = new jsjvm.Logger("interpreter.MethodInterpreter");
-
-
- /**
- * Unwinds a method call
- */
- function unwind(stack, context, count){
- logger.trace("unwinding: " + count);
-
- for (var j=0; j<count; j++)
- {
- var store= stack.pop();
- logger.trace("context["+(j+1)+"] = '"+store+"'");
- context.setLocal(j+1, store);
- }
-
- //Remove context from stack
- stack.pop();
- }
-
- /**
- * Unwinds a method call as array for native method invocation
- */
- function unwindAsArray(stack, count){
- logger.trace("ArrayUnwinding: " + count);
-
- var ret = new Array(count);
-
- for (var j=count-1; j>=0; j--)
- {
- var store= stack.pop();
- logger.trace("ret["+j+"] = '"+store+"'");
-
- if (store instanceof jsjvm.Context)
- //Retrieve native/primary instance
- store = store.getPrimaryInstance();
-
- ret[j] = store;
- }
-
- return ret;
- }
-
/**
* creates a new Method interpreter
*/
jsjvm.interpreter.MethodInterpreter = function(vm, stack, classDefinition, methodName, methodDesc){
-
-
var methodSignature = methodName + methodDesc;
@@ -63,37 +19,107 @@
logger.trace(" isConstructor: " + isConstructor);
logger.trace(" isNative: " + isNative);
-
+
/**
- * Enhances an instance object
+ * Enhances a context for native use
*/
- function enhance(obj){
+ function enhance(context){
+
+ if (context.indiginous != undefined)
+ return;
+
+ logger.trace("Enhancing context: " + context);
+
+ var obj = context.getPrimaryInstance();
+
//Assign vm
obj.$vm = vm;
- var methods = classDefinition.methods;
- for (var method in methods)
- {
- if (methods.hasOwnProperty(method))
+ /**
+ * Enhances the object with the methods
+ */
+ /*
+ function enhanceMethods(methods){
+ for (var method in methods)
{
- var name = methods[method]["name"];
-
- if (obj[name] != undefined)
- continue;
-
- logger.trace("Enhancing object with: " + name);
-
- //Create callback function
- obj[name] = function(){
+ if (methods.hasOwnProperty(method))
+ {
+ var name = methods[method]["name"];
+
+ if (obj[name] != undefined)
+ continue;
+
+ logger.trace("Enhancing object with: " + name);
- };
+ //Create callback function
+ obj[name] = function(){
+
+ };
+ }
}
}
+ var classDef = vm.classes.get( context.getPrimaryType() );
+ var methods = classDef.methods;
+ enhanceMethods(methods);
+
+ var interfaces = classDef.interfaces;
+ for (var i=0; i<interfaces.length; i++)
+ {
+ logger.trace("Enhancing with interface: " + interfaces[i]);
+ enhanceMethods(vm.classes.get(interfaces[i]).methods);
+ }
+ */
+ //Store for later use
+ context.indiginous = obj;
+
+ //Return indiginous object
return obj;
}
+ /**
+ * Unwinds a method call
+ */
+ function unwind(stack, context, count){
+
+ logger.trace("unwinding: " + count);
+
+ for (var j=0; j<count; j++)
+ {
+ var store= stack.pop();
+ logger.trace("context["+(j+1)+"] = '"+store+"'");
+ context.setLocal(j+1, store);
+ }
+
+ //Remove context from stack
+ stack.pop();
+ }
+
+ /**
+ * Unwinds a method call as array for native method invocation
+ */
+ function unwindAsArray(stack, count){
+ logger.trace("ArrayUnwinding: " + count);
+
+ var ret = new Array(count);
+
+ for (var j=count-1; j>=0; j--)
+ {
+ var store = stack.pop();
+ logger.trace("ret["+j+"] = '"+store+"'");
+
+ if (store instanceof jsjvm.Context)
+ {
+ //enhance for native usage
+ store = enhance(store);
+ }
+
+ ret[j] = store;
+ }
+
+ return ret;
+ }
/**
@@ -210,7 +236,7 @@
if (isConstructor)
{
//Create new instance context for the class
- context.initInstance(classDefinition.name, enhance({}));
+ context.initInstance(classDefinition.name, {});
}
if (isNative)
@@ -241,7 +267,7 @@
result = new F();
//Save constructed instance
- context.setInstance(classDefinition.name, enhance(result) );
+ context.setInstance(classDefinition.name, result);
//Pop this
stack.pop();
View
3  src/main/js/50_jsjvm.java_lang_Thread.js
@@ -7,10 +7,11 @@ jsjvm.java_lang_Thread = function(runnable){
var logger = new jsjvm.Logger("Thread");
+ logger.debug("runnable.run: " + runnable.run);
+ logger.debug("runnable.$vm: " + runnable.$vm);
this.start = function(){
- logger.debug("Starting thread: " + runnable.run);
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.