Support for return values from LVM.call()

Mon, 24 May 2010 15:22:29 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 24 May 2010 15:22:29 +0100
changeset 47
b8c4273edbbb
parent 46
33ae4e0de8cc
child 48
31787f1bd76c

Support for return values from LVM.call()

lvm.js file | annotate | diff | comparison | revisions
--- a/lvm.js	Mon May 24 14:12:14 2010 +0100
+++ b/lvm.js	Mon May 24 15:22:29 2010 +0100
@@ -286,7 +286,7 @@
 		this.callstack.push(frame);
 		for(var i=0;i<lfFunction.maxStackSize;i++)
 			frame.reg[i] = new LValue("nil", null);
-		this.run(frame);
+		return this.run(frame);
 	},
 	run: function(frame)
 	{
@@ -397,19 +397,21 @@
 			case OP_RETURN:
 				var oldFrame = this.callstack.pop();
 				frame = this.callstack[this.callstack.length-1];
+				var rets;
+				if(INS_B(instruction) == 0)
+					rets = oldFrame.reg.slice(INS_A(instruction));
+				else
+					rets = oldFrame.reg.slice(INS_A(instruction),INS_A(instruction)+(INS_B(instruction)-1));
 				if(frame)
 				{
-					var rets;
-					if(INS_B(instruction) == 0)
-						rets = oldFrame.reg.slice(INS_A(instruction));
-					else
-						rets = oldFrame.reg.slice(INS_A(instruction),INS_A(instruction)+(INS_B(instruction)-1));
 					var i;
 					for(i=0;(oldFrame.retCount == 0||i<oldFrame.retCount)&&i<rets.length;i++)
 						frame.reg[oldFrame.retAt+i] = rets[i];
 					if(oldFrame.retAt+i<frame.reg.length)
 						frame.reg.splice(0,oldFrame.retAt+i);
 				}
+				else
+					return rets;
 				break;
 			case OP_SELF:
 				var table = frame.reg[INS_B(instruction)];

mercurial