Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug fix

git-svn-id: http://hotruby.googlecode.com/svn/trunk@21 4fb8041d-b042-0410-9571-f50be27af959
  • Loading branch information...
commit 8be643309ede416e51e8ee3f91981096182d3321 1 parent ec3c929
yukoba@accelart.jp authored
View
15 src/RubyVM.js
@@ -40,6 +40,10 @@ var HotRuby = function() {
__className : "FalseClass",
__native : false
};
+ this.topObject = {
+ __className : "Object",
+ __native : {}
+ };
this.checkEnv();
};
@@ -114,7 +118,7 @@ HotRuby.prototype = {
*/
run : function(opcode) {
try {
- this.runOpcode(opcode, this.classes["<global>"], null, null, [], null, false, null);
+ this.runOpcode(opcode, this.classes["<global>"], null, this.topObject, [], null, false, null);
} catch(e) {
alert(e);
}
@@ -399,8 +403,9 @@ HotRuby.prototype = {
var args = sf.stack.slice(sf.sp - cmd[2], sf.sp);
sf.sp -= cmd[2];
var recver = sf.stack[--sf.sp];
- //if (recver == null || recver == this.nilObj)
- // recver = sf.self;
+ if(cmd[4] & HotRuby.VM_CALL_FCALL_BIT) {
+ recver = sf.self;
+ }
if(cmd[3] instanceof Array)
cmd[3] = this.createRubyProc(cmd[3], sf);
if(cmd[3] != null)
@@ -455,13 +460,13 @@ HotRuby.prototype = {
this.setConstant(sf, sf.classObj, cmd[1], newClass);
}
// Run the class definition
- this.runOpcode(cmd[2], newClass, null, null, [], sf, false, null);
+ this.runOpcode(cmd[2], newClass, null, sf.self, [], sf, false, null);
} else if(cmd[3] == 1) {
// Object-Specific Classes
if(cbaseObj == null || typeof(cbaseObj) != "object")
throw "Not supported Object-Specific Classes on Primitive Object"
// Run the class definition
- this.runOpcode(cmd[2], cbaseObj.__className, null, null, [], sf, false, cbaseObj);
+ this.runOpcode(cmd[2], cbaseObj.__className, null, sf.self, [], sf, false, cbaseObj);
} else if(cmd[3] == 2) {
// TODO
throw "Not implemented";
View
1  test/const/const.js
@@ -0,0 +1 @@
+var src = ["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<main>","const\\const.rb","top",[],0,[],[1,["putnil"],["putnil"],["defineclass","Foo",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo>","const\\const.rb","class",[],0,[],[2,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],5,["putnil"],["putnil"],["defineclass","Bar",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar>","const\\const.rb","class",[],0,[],[6,["putstring","Bar"],["putnil"],["setconstant","CONST"],7,["putnil"],["putnil"],["getconstant","Foo"],["defineclass","Baz",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Baz>","const\\const.rb","class",[],0,[],[8,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],10,["putnil"],["putnil"],["getconstant","Foo"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]],0],["pop"],14,["putnil"],["putnil"],["defineclass","Foo2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo2>","const\\const.rb","class",[],0,[],[15,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],18,["putstring","Object"],["putnil"],["setconstant","CONST"],20,["putnil"],["putnil"],["getconstant","Foo2"],["defineclass","Bar2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar2>","const\\const.rb","class",[],0,[],[21,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["pop"],25,["putnil"],["putnil"],["defineclass","Object",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Object>","const\\const.rb","class",[],0,[],[26,["putnil"],["putnil"],["getconstant","Foo2"],["defineclass","Bar2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar2>","const\\const.rb","class",[],0,[],[27,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]],0],["pop"],31,["putnil"],["putnil"],["defineclass","Foo3",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo3>","const\\const.rb","class",[],0,[],[32,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],34,["putnil"],["putnil"],["getconstant","Foo3"],["defineclass","Bar3",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar3>","const\\const.rb","class",[],0,[],[35,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],36,["putstring","Bar"],["putnil"],["setconstant","CONST"],37,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],38,["putnil"],["putnil"],["getconstant","Foo3"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]];
View
1  test/const/const.json
@@ -1 +0,0 @@
-["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<main>","const\\const.rb","top",[],0,[],[1,["putnil"],["putnil"],["defineclass","Foo",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo>","const\\const.rb","class",[],0,[],[2,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],5,["putnil"],["putnil"],["defineclass","Bar",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar>","const\\const.rb","class",[],0,[],[6,["putstring","Bar"],["putnil"],["setconstant","CONST"],7,["putnil"],["putnil"],["getconstant","Foo"],["defineclass","Baz",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Baz>","const\\const.rb","class",[],0,[],[8,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],10,["putnil"],["putnil"],["getconstant","Foo"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]],0],["pop"],14,["putnil"],["putnil"],["defineclass","Foo2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo2>","const\\const.rb","class",[],0,[],[15,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],18,["putstring","Object"],["putnil"],["setconstant","CONST"],19,["putnil"],["putnil"],["getconstant","Object"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],21,["putnil"],["putnil"],["getconstant","Foo2"],["defineclass","Bar2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar2>","const\\const.rb","class",[],0,[],[22,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["pop"],27,["putnil"],["putnil"],["defineclass","Object",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Object>","const\\const.rb","class",[],0,[],[28,["putnil"],["putnil"],["getconstant","Foo2"],["defineclass","Bar2",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar2>","const\\const.rb","class",[],0,[],[29,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]],0],["pop"],33,["putnil"],["putnil"],["defineclass","Foo3",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":3},"<class:Foo3>","const\\const.rb","class",[],0,[],[34,["putstring","Foo"],["dup"],["putnil"],["setconstant","CONST"],["leave"]]],0],["pop"],36,["putnil"],["putnil"],["getconstant","Foo3"],["defineclass","Bar3",["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":1,"stack_max":2},"<class:Bar3>","const\\const.rb","class",[],0,[],[37,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],38,["putstring","Bar"],["putnil"],["setconstant","CONST"],39,["putnil"],["putnil"],["getconstant","CONST"],["send","puts",1,null,8,null],["pop"],40,["putnil"],["putnil"],["getconstant","Foo3"],["getconstant","CONST"],["send","puts",1,null,8,null],["leave"]]],0],["leave"]]]
View
633 test/const/const_pretty.json
@@ -0,0 +1,633 @@
+[
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<main>",
+ "const\\const.rb",
+ "top",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 1,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "defineclass",
+ "Foo",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 3
+ },
+ "<class:Foo>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 2,
+ [
+ "putstring",
+ "Foo"
+ ],
+ [
+ "dup"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 5,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "defineclass",
+ "Bar",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Bar>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 6,
+ [
+ "putstring",
+ "Bar"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ 7,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo"
+ ],
+ [
+ "defineclass",
+ "Baz",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Baz>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 8,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "pop"
+ ],
+ 10,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 14,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "defineclass",
+ "Foo2",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 3
+ },
+ "<class:Foo2>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 15,
+ [
+ "putstring",
+ "Foo"
+ ],
+ [
+ "dup"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 18,
+ [
+ "putstring",
+ "Object"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ 20,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo2"
+ ],
+ [
+ "defineclass",
+ "Bar2",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Bar2>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 21,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 25,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "defineclass",
+ "Object",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Object>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 26,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo2"
+ ],
+ [
+ "defineclass",
+ "Bar2",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Bar2>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 27,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 31,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "defineclass",
+ "Foo3",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 3
+ },
+ "<class:Foo3>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 32,
+ [
+ "putstring",
+ "Foo"
+ ],
+ [
+ "dup"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "pop"
+ ],
+ 34,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo3"
+ ],
+ [
+ "defineclass",
+ "Bar3",
+ [
+ "YARVInstructionSequence\/SimpleDataFormat",
+ 1,
+ 1,
+ 1,
+ {
+ "arg_size": 0,
+ "local_size": 1,
+ "stack_max": 2
+ },
+ "<class:Bar3>",
+ "const\\const.rb",
+ "class",
+ [
+
+ ],
+ 0,
+ [
+
+ ],
+ [
+ 35,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "pop"
+ ],
+ 36,
+ [
+ "putstring",
+ "Bar"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "setconstant",
+ "CONST"
+ ],
+ 37,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "pop"
+ ],
+ 38,
+ [
+ "putnil"
+ ],
+ [
+ "putnil"
+ ],
+ [
+ "getconstant",
+ "Foo3"
+ ],
+ [
+ "getconstant",
+ "CONST"
+ ],
+ [
+ "send",
+ "puts",
+ 1,
+ null,
+ 8,
+ null
+ ],
+ [
+ "leave"
+ ]
+ ]
+ ],
+ 0
+ ],
+ [
+ "leave"
+ ]
+ ]
+]
View
1  test/plus/plus.js
@@ -0,0 +1 @@
+var src = ["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":3,"stack_max":3},"<main>","plus\\plus.rb","top",["a","b"],0,[],[1,["putobject",1],["setlocal",3],2,["putobject",2],["setlocal",2],3,["putnil"],["getlocal",3],["getlocal",2],["send","+",1,null,0,null],["send","puts",1,null,8,null],["leave"]]];
View
3  test/plus/plus.rb
@@ -0,0 +1,3 @@
+a = 1
+b = 2
+puts(a+b)
View
26 test/plus/plustest2.json → test/plus/plus_pretty.json
@@ -1,22 +1,24 @@
[
- "YARVInstructionSequence/SimpleDataFormat",
+ "YARVInstructionSequence\/SimpleDataFormat",
1,
1,
1,
{
- "arg_size" : 0,
- "local_size" : 3,
- "stack_max" : 3
+ "arg_size": 0,
+ "local_size": 3,
+ "stack_max": 3
},
"<main>",
- "plustest.rb",
+ "plus\\plus.rb",
"top",
[
"a",
"b"
],
0,
- [],
+ [
+
+ ],
[
1,
[
@@ -52,16 +54,20 @@
"send",
"+",
1,
- 0
+ null,
+ 0,
+ null
],
[
"send",
- "print",
+ "puts",
1,
- 8
+ null,
+ 8,
+ null
],
[
"leave"
]
]
-]
+]
View
1  test/plus/plustest.json
@@ -1 +0,0 @@
-["YARVInstructionSequence\/SimpleDataFormat",1,1,1,{"arg_size":0,"local_size":3,"stack_max":3},"<main>","plustest.rb","top",["a","b"],0,[],[1,["putobject",1],["setlocal",3],2,["putobject",2],["setlocal",2],3,["putnil"],["getlocal",3],["getlocal",2],["send","+",1,null,0,null],["send","puts",1,null,8,null],["leave"]]]
View
3  test/plus/plustest.rb
@@ -1,3 +0,0 @@
-a = 1
-b = 2
-puts a+b
View
15 web/js/HotRuby.js
@@ -40,6 +40,10 @@ var HotRuby = function() {
__className : "FalseClass",
__native : false
};
+ this.topObject = {
+ __className : "Object",
+ __native : {}
+ };
this.checkEnv();
};
@@ -114,7 +118,7 @@ HotRuby.prototype = {
*/
run : function(opcode) {
try {
- this.runOpcode(opcode, this.classes["<global>"], null, null, [], null, false, null);
+ this.runOpcode(opcode, this.classes["<global>"], null, this.topObject, [], null, false, null);
} catch(e) {
alert(e);
}
@@ -399,8 +403,9 @@ HotRuby.prototype = {
var args = sf.stack.slice(sf.sp - cmd[2], sf.sp);
sf.sp -= cmd[2];
var recver = sf.stack[--sf.sp];
- //if (recver == null || recver == this.nilObj)
- // recver = sf.self;
+ if(cmd[4] & HotRuby.VM_CALL_FCALL_BIT) {
+ recver = sf.self;
+ }
if(cmd[3] instanceof Array)
cmd[3] = this.createRubyProc(cmd[3], sf);
if(cmd[3] != null)
@@ -455,13 +460,13 @@ HotRuby.prototype = {
this.setConstant(sf, sf.classObj, cmd[1], newClass);
}
// Run the class definition
- this.runOpcode(cmd[2], newClass, null, null, [], sf, false, null);
+ this.runOpcode(cmd[2], newClass, null, sf.self, [], sf, false, null);
} else if(cmd[3] == 1) {
// Object-Specific Classes
if(cbaseObj == null || typeof(cbaseObj) != "object")
throw "Not supported Object-Specific Classes on Primitive Object"
// Run the class definition
- this.runOpcode(cmd[2], cbaseObj.__className, null, null, [], sf, false, cbaseObj);
+ this.runOpcode(cmd[2], cbaseObj.__className, null, sf.self, [], sf, false, cbaseObj);
} else if(cmd[3] == 2) {
// TODO
throw "Not implemented";
Please sign in to comment.
Something went wrong with that request. Please try again.