1
2
3
4
5
6 package net.sf.zel.instr.var;
7
8 import java.util.List;
9 import net.sf.zel.vm.ZExecutionException;
10 import net.sf.zel.instr.Instruction;
11 import net.sf.zel.nr.OperableNumber;
12 import net.sf.zel.vm.ExecutionContext;
13 import net.sf.zel.vm.Program;
14
15 public class FOR extends Instruction
16 {
17
18
19
20
21 public static final Instruction instance = new FOR();
22
23 private static final long serialVersionUID = -2188094226970211700L;
24
25 private FOR(){};
26
27
28
29
30
31
32 public final void execute(ExecutionContext context) throws ZExecutionException
33 {
34 Program prog = (Program) context.stack.pop();
35 final MatchIterator iterator = new MatchIterator((String) context.popSyncStackVal());
36 context.stack.pop();
37 DoIt stuff = new DoIt(prog, context);
38 iterator.iterate(stuff, context.memContext);
39 context.stack.push(stuff.getReturn());
40 context.ip++;
41 }
42
43 private static final class DoIt implements MatchIterator.DoStuff
44 {
45
46 DoIt(Program p, ExecutionContext ec)
47 {
48 this.p = p;
49 this.ec = ec;
50 }
51
52 Program p;
53 ExecutionContext ec;
54 Object retObject;
55
56 public Object getReturn()
57 {
58 return retObject;
59 }
60
61 public void execute(Object obj, List context)
62 throws ZExecutionException
63 {
64 if (obj instanceof OperableNumber)
65 {
66 retObject = p.execute(ec.memContext, obj);
67 }
68 }
69 }
70 }