-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStackFrame.as
51 lines (43 loc) · 1.56 KB
/
StackFrame.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.sixsided.scripting.SJS {
/* A function call frame, with its own program counter and local variables.
Function calls are the only use of callframes in this VM. (As opposed to org.sixsided.fith, which uses them for
loops.)
*/
/*import org.sixsided.scripting.SJS.Inspector;*/
public class StackFrame {
public var code:Array;
public var pc:Number;
public var exhausted:Boolean;
public var vars:Object;
public var parent:StackFrame;
function StackFrame(code:Array,vars:Object=null, parent:StackFrame=null) {
this.code = code;
this.pc = 0;
this.exhausted = false;
this.vars = vars || {};
this.parent = parent;
}
public function next_word():*{
// this check is here because we want to return control to run and let it finish out the current
// iteration *before* we exhaust the call frame. The last word might be a JUMP back to the start of the frame.
if(pc >= this.code.length) {
/*trace('[StackFrame] next_word exhausted StackFrame @', pc);*/
this.exhausted = true;
return VM.NOP;
}
// console.log('StackFrame.next_word', this.pc, this.code[this.pc]);
return code[pc++];
}
public function prev_word():* {
return code[pc-1];
}
public function toString():String{
return '[StackFrame @' + pc + ']';
/*var str:String = '';
for(var k:String in vars) {
str += k + ' : ' + Inspector.inspect(vars[k]) + "\n";
}
return str;*/
}
}
}