OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
controlopcodes.hpp
Go to the documentation of this file.
1 #ifndef INTERPRETER_CONTROLOPCODES_H_INCLUDED
2 #define INTERPRETER_CONTROLOPCODES_H_INCLUDED
3 
4 #include <stdexcept>
5 
6 #include "opcodes.hpp"
7 #include "runtime.hpp"
8 
9 namespace Interpreter
10 {
11  class OpReturn : public Opcode0
12  {
13  public:
14 
15  virtual void execute (Runtime& runtime)
16  {
17  runtime.setPC (-1);
18  }
19  };
20 
21  class OpSkipZero : public Opcode0
22  {
23  public:
24 
25  virtual void execute (Runtime& runtime)
26  {
27  Type_Integer data = runtime[0].mInteger;
28  runtime.pop();
29 
30  if (data==0)
31  runtime.setPC (runtime.getPC()+1);
32  }
33  };
34 
35  class OpSkipNonZero : public Opcode0
36  {
37  public:
38 
39  virtual void execute (Runtime& runtime)
40  {
41  Type_Integer data = runtime[0].mInteger;
42  runtime.pop();
43 
44  if (data!=0)
45  runtime.setPC (runtime.getPC()+1);
46  }
47  };
48 
49  class OpJumpForward : public Opcode1
50  {
51  public:
52 
53  virtual void execute (Runtime& runtime, unsigned int arg0)
54  {
55  if (arg0==0)
56  throw std::logic_error ("infinite loop");
57 
58  runtime.setPC (runtime.getPC()+arg0-1);
59  }
60  };
61 
62  class OpJumpBackward : public Opcode1
63  {
64  public:
65 
66  virtual void execute (Runtime& runtime, unsigned int arg0)
67  {
68  if (arg0==0)
69  throw std::logic_error ("infinite loop");
70 
71  runtime.setPC (runtime.getPC()-arg0-1);
72  }
73  };
74 }
75 
76 #endif
virtual void execute(Runtime &runtime, unsigned int arg0)
Definition: controlopcodes.hpp:66
Definition: controlopcodes.hpp:21
void pop()
pop stack
Definition: runtime.cpp:94
Runtime data and engine interface.
Definition: runtime.hpp:15
virtual void execute(Runtime &runtime)
Definition: controlopcodes.hpp:25
opcode for 0 arguments
Definition: opcodes.hpp:9
virtual void execute(Runtime &runtime)
Definition: controlopcodes.hpp:39
Definition: controlopcodes.hpp:62
Definition: controlopcodes.hpp:35
int getPC() const
return program counter.
Definition: runtime.cpp:11
Definition: controlopcodes.hpp:49
Definition: controlopcodes.hpp:11
void setPC(int PC)
set program counter.
Definition: runtime.cpp:70
virtual void execute(Runtime &runtime, unsigned int arg0)
Definition: controlopcodes.hpp:53
opcode for 1 argument
Definition: opcodes.hpp:19
virtual void execute(Runtime &runtime)
Definition: controlopcodes.hpp:15