blob: 80d8667bf16b98c1d63e15ceea586dfeb6b840b9 (
plain) (
blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package com.modulus.qbar.lang;
import java.util.HashMap;
import java.util.Map;
import com.modulus.common.collections.ArrayStack;
import com.modulus.common.collections.Stack;
import com.modulus.qbar.core.QBFunction;
import com.modulus.qbar.core.QBNamespace;
import com.modulus.qbar.core.QBObject;
import com.modulus.qbar.core.interpreter.QBInterpreter;
import com.modulus.qbar.core.parser.ByteOperation;
public class QBFunctionListFunction extends QBFunction{
private static final long serialVersionUID = 1123773383702904111L;
private ByteOperation[] command;
private String var;
private static Map<String, QBObject> namespaceTemplate = new HashMap<String,QBObject>();
private Stack<QBNamespace> namespaceCalls = new ArrayStack<QBNamespace>();
public QBFunctionListFunction( ){
super(2);
namespaceCalls.push(new QBNamespace(namespaceTemplate));
}
public ByteOperation[] getCommand() {
return command;
}
public void setCommand(ByteOperation[] command) {
this.command = command;
}
public String getVar() {
return var;
}
public void setVar(String var) {
this.var = var;
}
@Override
public QBObject execute(QBObject[] args){
QBNamespace tmp = new QBNamespace(new HashMap<String, QBObject>());
tmp.setSuper(this.getSuper());
namespaceCalls.push(tmp);
this.set(var, args[0]);
this.set("this", args[1]);
Stack<QBObject> stack = QBInterpreter.instance().getStack();
exec(command, stack);
namespaceCalls.pop();
return returnedValue;
}
@Override
public QBObject get(String name){
return namespaceCalls.peek().get(name);
}
@Override
public void set(String name, QBObject obj){
namespaceCalls.peek().set(name, obj);
}
}
|