Implement basic OP_CLOSURE (no support for upvalues yet)

Wed, 07 Apr 2010 03:05:52 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 07 Apr 2010 03:05:52 +0100
changeset 15
5240eaff785f
parent 14
21a2fce50931
child 16
9c8710ea2a5a

Implement basic OP_CLOSURE (no support for upvalues yet)

lvm.js file | annotate | diff | comparison | revisions
--- a/lvm.js	Wed Apr 07 03:05:24 2010 +0100
+++ b/lvm.js	Wed Apr 07 03:05:52 2010 +0100
@@ -6,6 +6,7 @@
 var OP_SETGLOBAL = 7;
 var OP_CALL = 28;
 var OP_RETURN = 30;
+var OP_CLOSURE = 36;
 
 var debugMode = false;
 
@@ -294,6 +295,14 @@
 					// Lua function
 				}
 				break;
+			case OP_CLOSURE:
+				var prototype_id = INS_Bx(instruction);
+				var chunk = this.frame.f.chunk.prototypes[prototype_id];
+				if(chunk.numUpvalues>0)
+					throw "Upvalues not yet implemented, sorry :)";
+				var f = new LFunction(chunk, this.frame.f.environment);
+				this.frame.reg[INS_A(instruction)] = new LValue("function", f);
+				break;
 			case OP_RETURN:
 				this.callstack.pop();
 				break;

mercurial