75 ExpressionValue* op = null; |
75 ExpressionValue* op = null; |
76 enum ELocalException { failed }; |
76 enum ELocalException { failed }; |
77 |
77 |
78 try |
78 try |
79 { |
79 { |
80 ScriptVariable* globalvar; |
|
81 mLexer->MustGetNext(); |
80 mLexer->MustGetNext(); |
82 |
81 |
83 if (mLexer->GetTokenType() == tkColon) |
82 if (mLexer->GetTokenType() == tkColon) |
84 return new ExpressionColon; |
83 return new ExpressionColon; |
85 |
84 |
106 |
105 |
107 op->SetBuffer (mParser->ParseCommand (comm)); |
106 op->SetBuffer (mParser->ParseCommand (comm)); |
108 return op; |
107 return op; |
109 } |
108 } |
110 |
109 |
111 // Check constant |
|
112 if (ConstantInfo* constant = mParser->FindConstant (GetTokenString())) |
|
113 { |
|
114 if (mType != constant->type) |
|
115 Error ("constant `%1` is %2, expression requires %3\n", |
|
116 constant->name, GetTypeName (constant->type), |
|
117 GetTypeName (mType)); |
|
118 |
|
119 switch (constant->type) |
|
120 { |
|
121 case EBoolType: |
|
122 case EIntType: |
|
123 op->SetValue (constant->val.ToLong()); |
|
124 break; |
|
125 |
|
126 case EStringType: |
|
127 op->SetValue (GetStringTableIndex (constant->val)); |
|
128 break; |
|
129 |
|
130 case EVoidType: |
|
131 case EUnknownType: |
|
132 break; |
|
133 } |
|
134 |
|
135 return op; |
|
136 } |
|
137 |
|
138 // Check global variable |
110 // Check global variable |
139 if ((globalvar = FindGlobalVariable (GetTokenString()))) |
111 // TODO: handle locals too when they're implemented |
140 { |
112 if (mLexer->GetTokenType() == tkDollarSign) |
141 DataBuffer* buf = new DataBuffer (8); |
113 { |
142 buf->WriteDWord (dhPushGlobalVar); |
114 mLexer->MustGetNext (tkSymbol); |
143 buf->WriteDWord (globalvar->index); |
115 ScriptVariable* globalvar = FindGlobalVariable (GetTokenString()); |
144 op->SetBuffer (buf); |
116 |
|
117 if (globalvar == null) |
|
118 Error ("unknown variable %1", GetTokenString()); |
|
119 |
|
120 if (globalvar->writelevel == ScriptVariable::WRITE_Constexpr) |
|
121 op->SetValue (globalvar->value); |
|
122 else |
|
123 { |
|
124 DataBuffer* buf = new DataBuffer (8); |
|
125 buf->WriteDWord (dhPushGlobalVar); |
|
126 buf->WriteDWord (globalvar->index); |
|
127 op->SetBuffer (buf); |
|
128 } |
|
129 |
145 return op; |
130 return op; |
146 } |
131 } |
147 |
132 |
148 EToken tt; |
133 EToken tt; |
149 |
134 |