root/src/VM/cil/cilVMOperatorBitwiseAnd.cpp

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