root/src/VM/cil/cilVMOperatorBitwiseOr.cpp

Revision 138, 6.3 kB (checked in by hak, 6 months ago)

- Added CCilVm::reset()
- Fixed VM status management (ticket #5)
- Fixed API names not to have upper case as 1st letter.
- Fixed sample build break
- Added new sample, "vm_contol" to demonstrate VM status control API

Line 
1 /****************************************************************************
2  *
3  | CRI Middleware SDK
4  *
5  | Copyright (c) 2005-2008 CRI Middleware Co., Ltd.
6  *
7  | Library  : CRIScript
8  | Module   : cil Virtual Machine Arithmetical ops
9  | File     : CCilVmOperatorbitwiseOr.cpp
10  | Date     :
11  | Version  :
12  *
13  ****************************************************************************/
14
15 /***************************************************************************
16  |      Include file
17  ***************************************************************************/
18 #include "stdafx.h"
19 #include "criScript.h"
20 #include "cilVm.h"
21 namespace cri {
22 /***************************************************************************
23  |      Variables
24  ***************************************************************************/
25
26 /***************************************************************************
27  |      Methods
28  ***************************************************************************/
29
30 /***************************************************************************
31  |      Add operator
32  |      (1) take value from stack
33  |      (2) take value from stack
34  |      (3) result(1) | result (2)
35  |      (4) push result (3)
36  ***************************************************************************/
37 void CCilVm::bitwiseOrOperator()
38 {
39         assert( getEvalStackSize() >= 2 );
40         CVariable& rhs = getEvalStackFirstEntry();
41         CVariable& lhs = getEvalStackSecondEntry();
42
43         if( lhs.iOperandType == OPERAND_OBJECTREF
44                 || rhs.iOperandType == OPERAND_OBJECTREF)
45         {
46                 OPERAND_TYPE lhsType = lhs.getPrimitiveType( PRIMITIVETYPE_NUMBER );
47                 OPERAND_TYPE rhsType = rhs.getPrimitiveType( PRIMITIVETYPE_NUMBER );
48                 if( lhsType == OPERAND_STRING )
49                 {
50                         rhsType = rhs.getPrimitiveType( PRIMITIVETYPE_STRING );
51                 }
52                 else if( rhsType == OPERAND_STRING )
53                 {
54                         lhsType = lhs.getPrimitiveType( PRIMITIVETYPE_STRING );
55                 }
56                
57                 if( lhsType == OPERAND_OBJECTREF || rhsType == OPERAND_OBJECTREF )
58                 {
59                         //Throw TypeError
60                         popThrowTypeError();
61                         return;
62                 }
63                
64                 if( lhsType == OPERAND_UNDEFINED || rhsType == OPERAND_UNDEFINED )
65                 {
66                         popPushEvalStackUndefined();
67                         return;
68                 }
69                 else if( lhsType == OPERAND_NAN || rhsType == OPERAND_NAN )
70                 {
71                         popPushEvalStackNaN();
72                         return;
73                 }
74
75
76                 if( lhsType == OPERAND_STRING || rhsType == OPERAND_STRING )
77                 {
78                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
79                 }
80                 else if( lhsType == OPERAND_DOUBLE || rhsType == OPERAND_DOUBLE )
81                 {
82                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
83                 }
84                 else if( lhsType == OPERAND_FLOAT || rhsType == OPERAND_FLOAT )
85                 {
86                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
87                 }
88                 else if( lhsType == OPERAND_INT64 || rhsType == OPERAND_INT64 )
89                 {
90                         int64_t i64 = rhs.toInt64();
91                         popPushEvalStack( lhs.toInt64() |  i64 );
92                 }
93                 else if( lhsType == OPERAND_INT || rhsType == OPERAND_INT )
94                 {
95                         int32_t i = rhs.toInt();
96                         popPushEvalStack( lhs.toInt() |  i );
97                 }
98                 else if( lhsType == OPERAND_BOOLEAN || rhsType == OPERAND_BOOLEAN )
99                 {
100                         int32_t i = rhs.toInt();
101                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
102                 }
103                 else
104                 {
105                         Debug_Fatal( "Not implemented yet" );
106                 }
107                 return;
108         } else if( lhs.iOperandType == OPERAND_STRING
109                 || rhs.iOperandType == OPERAND_STRING )
110         {
111                 popPushEvalStack( lhs.toInt() | rhs.toInt() );
112                 return;
113         } else if( lhs.iOperandType == OPERAND_NAN
114                 || rhs.iOperandType == OPERAND_NAN )
115         {
116                 popPushEvalStackUndefined();
117                 return;
118         } else if( lhs.iOperandType == OPERAND_UNDEFINED
119                 || rhs.iOperandType == OPERAND_UNDEFINED )
120         {
121                 popPushEvalStackNaN();
122                 return;
123         }
124        
125         int32_t i;
126         int64_t i64;
127
128         switch( lhs.iOperandType )
129         {
130         case OPERAND_INT:
131                 switch( rhs.iOperandType )
132                 {
133                 case OPERAND_INT:
134                         i = rhs.toInt();
135                         popPushEvalStack( int32_t( lhs.iValue | i ) );
136                         break;
137                 case OPERAND_INT64:
138                         i64 = rhs.toInt64();
139                         popPushEvalStack( int64_t( int64_t(lhs.iValue) | i64 ) );
140                         break;
141                 case OPERAND_FLOAT:
142                 case OPERAND_DOUBLE:
143                         popPushEvalStack( lhs.iValue | rhs.toInt() );
144                         break;
145                 case OPERAND_UNDEFINED:
146                 case OPERAND_NAN:
147                 case OPERAND_STRING:
148                 case OPERAND_OBJECTREF:
149                         Debug_Fatal( "Illegal operand" );
150                         break;
151                 default:
152                         i = rhs.toInt();
153                         popPushEvalStack( int32_t( lhs.iValue |  i ) );
154                         break;
155                 }
156                 break;
157         case OPERAND_INT64:
158                 switch( rhs.iOperandType )
159                 {
160                 case OPERAND_INT:
161                 case OPERAND_INT64:
162                         i64 = rhs.toInt64();
163                         popPushEvalStack( lhs.i64Value | i64 );
164                         break;
165                 case OPERAND_FLOAT:
166                 case OPERAND_DOUBLE:
167                         popPushEvalStack( lhs.i64Value | rhs.toInt64() );
168                         break;
169                 case OPERAND_UNDEFINED:
170                 case OPERAND_NAN:
171                 case OPERAND_STRING:
172                 case OPERAND_OBJECTREF:
173                         Debug_Fatal( "Illegal operand" );
174                         break;
175                 default:
176                         popPushEvalStack( lhs.i64Value | rhs.toInt64() );
177                         break;
178                 }
179                 break;
180         case OPERAND_FLOAT:
181                 switch( rhs.iOperandType )
182                 {
183                 case OPERAND_UNDEFINED:
184                 case OPERAND_NAN:
185                 case OPERAND_STRING:
186                 case OPERAND_OBJECTREF:
187                         Debug_Fatal( "Illegal operand" );
188                         break;
189                 case OPERAND_FLOAT:
190                 case OPERAND_DOUBLE:
191                 default:
192                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
193                         break;
194                 }
195                 break;
196         case OPERAND_DOUBLE:
197                 switch( rhs.iOperandType )
198                 {
199                 case OPERAND_UNDEFINED:
200                 case OPERAND_NAN:
201                 case OPERAND_STRING:
202                 case OPERAND_OBJECTREF:
203                         Debug_Fatal( "Illegal operand" );
204                         break;
205                 case OPERAND_FLOAT:
206                 case OPERAND_DOUBLE:
207                 default:
208                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
209                         break;
210                 }
211                 break;
212                 break;
213         case OPERAND_UNDEFINED:
214         case OPERAND_NAN:
215         case OPERAND_OBJECTREF:
216         case OPERAND_STRING:
217                 Debug_Fatal( "Illegal operand" );
218                 break;
219         case OPERAND_BOOLEAN:
220                 switch( rhs.iOperandType )
221                 {
222                 case OPERAND_UNDEFINED:
223                 case OPERAND_NAN:
224                 case OPERAND_STRING:
225                 case OPERAND_OBJECTREF:
226                         Debug_Fatal( "Illegal operand" );
227                         break;
228                 default:
229                         popPushEvalStack( lhs.toInt() | rhs.toInt() );
230                         break;
231                 }
232                 break;
233                 break;
234         case OPERAND_NULL:
235                 popPushEvalStack( lhs.toInt() | rhs.toInt() );
236                 break;
237         default:
238                 Debug_Fatal( "Illegal operand" );
239                 break;
240         }
241 }
242
243 /***************************************************************************
244  |      bitwiseOr operator Helper
245  ***************************************************************************/
246
247 } //namespace CRI
Note: See TracBrowser for help on using the browser.