View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package net.sf.zel.instr;
7   
8   import net.sf.zel.vm.EndParamMarker;
9   import net.sf.zel.vm.ExecutionContext;
10  import net.sf.zel.vm.ZExecutionException;
11  import net.sf.zel.vm.Program;
12  import net.sf.zel.vm.SimpleStack;
13  
14  /**
15   *
16   * @author zoly
17   */
18  public final class CACHE extends Instruction
19  {
20      private static final long serialVersionUID = 759722625722456554L;
21  
22      private CACHE(){};
23  
24      @Override
25      public void execute(ExecutionContext context) throws ZExecutionException
26      {        
27          Program p = (Program) context.stack.pop();
28          if (p.getType() != Program.Type.DETERMINISTIC)
29              throw new ZExecutionException("Attempt to assign a value to a non-deterministic function");
30          Object value = context.stack.pop();
31          Object param;
32          SimpleStack params = new SimpleStack();
33          params.push(p);
34          while (((param = context.stack.pop()) != EndParamMarker.instance))
35             params.push(param);
36          context.resultCache.putPermanentResult(params,value);
37          context.ip++;
38      }
39      /**
40       * instance
41       */
42      public static final Instruction instance = new CACHE();
43  }