Rollback from r3608 to r3606
[public/netxms.git] / src / libnxsl / instruction.cpp
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
3** NetXMS Scripting Language Interpreter
4** Copyright (C) 2005, 2006, 2007, 2008 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: instruction.cpp
21**
22**/
23
24#include "libnxsl.h"
25
26
27//
28// Constructors
29//
30
31NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode)
32{
33 m_nOpCode = nOpCode;
34 m_nSourceLine = nLine;
35 m_nStackItems = 0;
36}
37
38NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode, NXSL_Value *pValue)
39{
40 m_nOpCode = nOpCode;
41 m_nSourceLine = nLine;
42 m_operand.m_pConstant = pValue;
43 m_nStackItems = 0;
44}
45
46NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode, char *pszString)
47{
48 m_nOpCode = nOpCode;
49 m_nSourceLine = nLine;
50 m_operand.m_pszString = pszString;
51 m_nStackItems = 0;
52}
53
54NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode, char *pszString, int nStackItems)
55{
56 m_nOpCode = nOpCode;
57 m_nSourceLine = nLine;
58 m_operand.m_pszString = pszString;
59 m_nStackItems = nStackItems;
60}
61
62NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode, DWORD dwAddr)
63{
64 m_nOpCode = nOpCode;
65 m_nSourceLine = nLine;
66 m_operand.m_dwAddr = dwAddr;
67}
68
69NXSL_Instruction::NXSL_Instruction(int nLine, int nOpCode, int nStackItems)
70{
71 m_nOpCode = nOpCode;
72 m_nSourceLine = nLine;
73 m_nStackItems = nStackItems;
74}
75
76NXSL_Instruction::NXSL_Instruction(NXSL_Instruction *pSrc)
77{
78 m_nOpCode = pSrc->m_nOpCode;
79 m_nSourceLine = pSrc->m_nSourceLine;
80 m_nStackItems = pSrc->m_nStackItems;
81 switch(m_nOpCode)
82 {
83 case OPCODE_PUSH_CONSTANT:
84 m_operand.m_pConstant = new NXSL_Value(pSrc->m_operand.m_pConstant);
85 break;
86 case OPCODE_PUSH_VARIABLE:
87 case OPCODE_SET:
88 case OPCODE_CALL_EXTERNAL:
89 case OPCODE_BIND:
90 case OPCODE_ARRAY:
91 case OPCODE_INC:
92 case OPCODE_DEC:
93 case OPCODE_INCP:
94 case OPCODE_DECP:
95 case OPCODE_REFERENCE:
96 m_operand.m_pszString = strdup(pSrc->m_operand.m_pszString);
97 break;
98 default:
99 m_operand.m_dwAddr = pSrc->m_operand.m_dwAddr;
100 break;
101 }
102}
103
104
105//
106// Destructor
107//
108
109NXSL_Instruction::~NXSL_Instruction()
110{
111 switch(m_nOpCode)
112 {
113 case OPCODE_PUSH_VARIABLE:
114 case OPCODE_CALL_EXTERNAL:
115 case OPCODE_SET:
116 case OPCODE_BIND:
117 case OPCODE_ARRAY:
118 case OPCODE_INC:
119 case OPCODE_DEC:
120 case OPCODE_INCP:
121 case OPCODE_DECP:
122 case OPCODE_REFERENCE:
123 safe_free(m_operand.m_pszString);
124 break;
125 case OPCODE_PUSH_CONSTANT:
126 delete m_operand.m_pConstant;
127 break;
128 default:
129 break;
130 }
131}