Skip to content

Commit c8a1663

Browse files
Merge branch 'refactor-syntax_unicode_shims_operators' into refactor-syntax_unicode_shims
2 parents ca03cdc + 7aa3a61 commit c8a1663

5 files changed

Lines changed: 1011 additions & 1382 deletions

File tree

engine/src/exec.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,54 @@ bool MCExecContext::ConvertToMutableString(MCValueRef p_value, MCStringRef& r_st
110110
return MCStringMutableCopy(*t_string, r_string);
111111
}
112112

113+
bool MCExecContext::ConvertToNumberOrArray(MCExecValue& x_value)
114+
{
115+
switch(x_value . type)
116+
{
117+
case kMCExecValueTypeNone:
118+
return false;
119+
120+
case kMCExecValueTypeValueRef:
121+
case kMCExecValueTypeBooleanRef:
122+
case kMCExecValueTypeStringRef:
123+
case kMCExecValueTypeNameRef:
124+
case kMCExecValueTypeDataRef:
125+
case kMCExecValueTypeNumberRef:
126+
{
127+
double t_real;
128+
if (!ConvertToReal(x_value . valueref_value, t_real))
129+
return false;
130+
131+
MCValueRelease(x_value . valueref_value);
132+
MCExecValueTraits<double>::set(x_value, t_real);
133+
return true;
134+
}
135+
136+
case kMCExecValueTypeUInt:
137+
MCExecValueTraits<double>::set(x_value, (double)x_value . uint_value);
138+
return true;
139+
140+
case kMCExecValueTypeInt:
141+
MCExecValueTraits<double>::set(x_value, (double)x_value . int_value);
142+
return true;
143+
144+
case kMCExecValueTypeFloat:
145+
MCExecValueTraits<double>::set(x_value, (double)x_value . float_value);
146+
return true;
147+
148+
case kMCExecValueTypeArrayRef:
149+
case kMCExecValueTypeDouble:
150+
return true;
151+
152+
case kMCExecValueTypeBool:
153+
case kMCExecValueTypeChar:
154+
case kMCExecValueTypePoint:
155+
case kMCExecValueTypeColor:
156+
case kMCExecValueTypeRectangle:
157+
return false;
158+
}
159+
}
160+
113161
bool MCExecContext::ConvertToData(MCValueRef p_value, MCDataRef& r_data)
114162
{
115163
MCAutoStringRef t_string;
@@ -790,6 +838,59 @@ bool MCExecContext::EvalExprAsBool(MCExpression *p_expr, Exec_errors p_error, bo
790838
return false;
791839
}
792840

841+
bool MCExecContext::EvalExprAsNonStrictBool(MCExpression *p_expr, Exec_errors p_error, bool& r_value)
842+
{
843+
MCAssert(p_expr != nil);
844+
MCExecValue t_value;
845+
846+
p_expr -> eval_ctxt(*this, t_value);
847+
848+
if (HasError())
849+
{
850+
LegacyThrow(p_error);
851+
return false;
852+
}
853+
854+
switch(t_value . type)
855+
{
856+
case kMCExecValueTypeBool:
857+
r_value = t_value . bool_value;
858+
break;
859+
case kMCExecValueTypeBooleanRef:
860+
r_value = t_value . booleanref_value == kMCTrue;
861+
break;
862+
case kMCExecValueTypeStringRef:
863+
r_value = t_value . stringref_value == kMCTrueString;
864+
break;
865+
case kMCExecValueTypeNameRef:
866+
r_value = MCNameGetString(t_value . nameref_value) == kMCTrueString;
867+
break;
868+
case kMCExecValueTypeValueRef:
869+
if (!ConvertToBool(t_value . valueref_value, r_value))
870+
r_value = false;
871+
break;
872+
case kMCExecValueTypeNumberRef:
873+
case kMCExecValueTypeUInt:
874+
case kMCExecValueTypeInt:
875+
case kMCExecValueTypeFloat:
876+
case kMCExecValueTypeDouble:
877+
case kMCExecValueTypeNone:
878+
case kMCExecValueTypeDataRef:
879+
case kMCExecValueTypeArrayRef:
880+
case kMCExecValueTypeChar:
881+
case kMCExecValueTypePoint:
882+
case kMCExecValueTypeColor:
883+
case kMCExecValueTypeRectangle:
884+
case kMCExecValueTypeSet:
885+
case kMCExecValueTypeEnum:
886+
default:
887+
r_value = false;
888+
break;
889+
}
890+
891+
return true;
892+
}
893+
793894
bool MCExecContext::EvalOptionalExprAsBool(MCExpression *p_expr, bool p_default, Exec_errors p_error, bool& r_value)
794895
{
795896
if (p_expr == nil)

engine/src/exec.h

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ class MCExecContext
13381338
bool ConvertToLegacyColor(MCValueRef value, MCColor& r_color);
13391339

13401340
bool ConvertToMutableString(MCValueRef p_value, MCStringRef &r_string);
1341+
bool ConvertToNumberOrArray(MCExecValue &x_value);
13411342

13421343
// These attempt to convert the given value as specified. If conversion
13431344
// was successful then 'r_converted' is set to true, else 'false'. If
@@ -1505,6 +1506,7 @@ class MCExecContext
15051506
bool EvalOptionalExprAsInt(MCExpression *expr, integer_t default_value, Exec_errors error, integer_t& r_int);
15061507

15071508
bool EvalExprAsBool(MCExpression *expr, Exec_errors error, bool& r_bool);
1509+
bool EvalExprAsNonStrictBool(MCExpression *expr, Exec_errors error, bool& r_bool);
15081510
bool EvalOptionalExprAsBool(MCExpression *expr, bool default_value, Exec_errors error, bool& r_bool);
15091511

15101512
bool EvalExprAsDouble(MCExpression *expr, Exec_errors error, double& r_double);
@@ -5007,15 +5009,15 @@ template<> struct MCExecValueTraits<MCValueRef>
50075009
inline static void set(MCExecValue& self, MCValueRef p_value)
50085010
{
50095011
self . type = kMCExecValueTypeValueRef;
5010-
self . valueref_value = p_value;
5012+
self . valueref_value = MCValueRetain(p_value);
50115013
}
50125014

5013-
inline static void free(out_type self)
5015+
inline static void free(MCValueRef& self)
50145016
{
50155017
MCValueRelease(self);
50165018
}
50175019

5018-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5020+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCValueRef& r_value)
50195021
{
50205022
return ctxt . EvalExprAsValueRef(p_expr, p_error, r_value);
50215023
}
@@ -5029,15 +5031,15 @@ template<> struct MCExecValueTraits<MCBooleanRef>
50295031
inline static void set(MCExecValue& self, MCBooleanRef p_value)
50305032
{
50315033
self . type = kMCExecValueTypeBooleanRef;
5032-
self . booleanref_value = p_value;
5034+
self . booleanref_value = MCValueRetain(p_value);
50335035
}
50345036

5035-
inline static void free(out_type self)
5037+
inline static void free(MCBooleanRef& self)
50365038
{
50375039
MCValueRelease(self);
50385040
}
50395041

5040-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5042+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCBooleanRef& r_value)
50415043
{
50425044
return ctxt . EvalExprAsBooleanRef(p_expr, p_error, r_value);
50435045
}
@@ -5051,15 +5053,15 @@ template<> struct MCExecValueTraits<MCNameRef>
50515053
inline static void set(MCExecValue& self, MCNameRef p_value)
50525054
{
50535055
self . type = kMCExecValueTypeNameRef;
5054-
self . nameref_value = p_value;
5056+
self . nameref_value = MCValueRetain(p_value);
50555057
}
50565058

5057-
inline static void free(out_type self)
5059+
inline static void free(MCNameRef& self)
50585060
{
50595061
MCNameDelete(self);
50605062
}
50615063

5062-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5064+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCNameRef& r_value)
50635065
{
50645066
return ctxt . EvalExprAsNameRef(p_expr, p_error, r_value);
50655067
}
@@ -5073,15 +5075,15 @@ template<> struct MCExecValueTraits<MCDataRef>
50735075
inline static void set(MCExecValue& self, MCDataRef p_value)
50745076
{
50755077
self . type = kMCExecValueTypeDataRef;
5076-
self . dataref_value = p_value;
5078+
self . dataref_value = MCValueRetain(p_value);
50775079
}
50785080

5079-
inline static void free(out_type self)
5081+
inline static void free(MCDataRef& self)
50805082
{
50815083
MCValueRelease(self);
50825084
}
50835085

5084-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5086+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCDataRef& r_value)
50855087
{
50865088
return ctxt . EvalExprAsDataRef(p_expr, p_error, r_value);
50875089
}
@@ -5095,15 +5097,15 @@ template<> struct MCExecValueTraits<MCArrayRef>
50955097
inline static void set(MCExecValue& self, MCArrayRef p_value)
50965098
{
50975099
self . type = kMCExecValueTypeArrayRef;
5098-
self . arrayref_value = p_value;
5100+
self . arrayref_value = MCValueRetain(p_value);
50995101
}
51005102

5101-
inline static void free(out_type self)
5103+
inline static void free(MCArrayRef& self)
51025104
{
51035105
MCValueRelease(self);
51045106
}
51055107

5106-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5108+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCArrayRef& r_value)
51075109
{
51085110
return ctxt . EvalExprAsArrayRef(p_expr, p_error, r_value);
51095111
}
@@ -5117,15 +5119,15 @@ template<> struct MCExecValueTraits<MCNumberRef>
51175119
inline static void set(MCExecValue& self, MCNumberRef p_value)
51185120
{
51195121
self . type = kMCExecValueTypeNumberRef;
5120-
self . numberref_value = p_value;
5122+
self . numberref_value = MCValueRetain(p_value);
51215123
}
51225124

5123-
inline static void free(out_type self)
5125+
inline static void free(MCNumberRef& self)
51245126
{
51255127
MCValueRelease(self);
51265128
}
51275129

5128-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5130+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCNumberRef& r_value)
51295131
{
51305132
return ctxt . EvalExprAsNumberRef(p_expr, p_error, r_value);
51315133
}
@@ -5139,15 +5141,15 @@ template<> struct MCExecValueTraits<MCStringRef>
51395141
inline static void set(MCExecValue& self, MCStringRef p_value)
51405142
{
51415143
self . type = kMCExecValueTypeStringRef;
5142-
self . stringref_value = p_value;
5144+
self . stringref_value = MCValueRetain(p_value);
51435145
}
51445146

5145-
inline static void free(out_type self)
5147+
inline static void free(MCStringRef& self)
51465148
{
51475149
MCValueRelease(self);
51485150
}
51495151

5150-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5152+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCStringRef& r_value)
51515153
{
51525154
return ctxt . EvalExprAsStringRef(p_expr, p_error, r_value);
51535155
}
@@ -5164,9 +5166,9 @@ template<> struct MCExecValueTraits<integer_t>
51645166
self . int_value = p_value;
51655167
}
51665168

5167-
inline static void free(out_type){}
5169+
inline static void free(integer_t& self){}
51685170

5169-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5171+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, integer_t& r_value)
51705172
{
51715173
return ctxt . EvalExprAsInt(p_expr, p_error, r_value);
51725174
}
@@ -5183,9 +5185,9 @@ template<> struct MCExecValueTraits<uinteger_t>
51835185
self . uint_value = p_value;
51845186
}
51855187

5186-
inline static void free(out_type){}
5188+
inline static void free(uinteger_t& self){}
51875189

5188-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5190+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, uinteger_t& r_value)
51895191
{
51905192
return ctxt . EvalExprAsUInt(p_expr, p_error, r_value);
51915193
}
@@ -5202,9 +5204,9 @@ template<> struct MCExecValueTraits<bool>
52025204
self . bool_value = p_value;
52035205
}
52045206

5205-
inline static void free(out_type){}
5207+
inline static void free(bool& self){}
52065208

5207-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5209+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, bool& r_value)
52085210
{
52095211
return ctxt . EvalExprAsBool(p_expr, p_error, r_value);
52105212
}
@@ -5221,9 +5223,9 @@ template<> struct MCExecValueTraits<double>
52215223
self . double_value = p_value;
52225224
}
52235225

5224-
inline static void free(out_type){}
5226+
inline static void free(double& self){}
52255227

5226-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5228+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, double& r_value)
52275229
{
52285230
return ctxt . EvalExprAsDouble(p_expr, p_error, r_value);
52295231
}
@@ -5240,9 +5242,9 @@ template<> struct MCExecValueTraits<char_t>
52405242
self . char_value = p_value;
52415243
}
52425244

5243-
inline static void free(out_type){}
5245+
inline static void free(char_t& self){}
52445246

5245-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5247+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, char_t& r_value)
52465248
{
52475249
return ctxt . EvalExprAsChar(p_expr, p_error, r_value);
52485250
}
@@ -5259,9 +5261,9 @@ template<> struct MCExecValueTraits<MCPoint>
52595261
self . point_value = p_value;
52605262
}
52615263

5262-
inline static void free(out_type){}
5264+
inline static void free(MCPoint& self){}
52635265

5264-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5266+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCPoint& r_value)
52655267
{
52665268
return ctxt . EvalExprAsPoint(p_expr, p_error, r_value);
52675269
}
@@ -5278,9 +5280,9 @@ template<> struct MCExecValueTraits<MCColor>
52785280
self . color_value = p_value;
52795281
}
52805282

5281-
inline static void free(out_type){}
5283+
inline static void free(MCColor& self){}
52825284

5283-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5285+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCColor& r_value)
52845286
{
52855287
return ctxt . EvalExprAsColor(p_expr, p_error, r_value);
52865288
}
@@ -5297,9 +5299,9 @@ template<> struct MCExecValueTraits<MCRectangle>
52975299
self . rectangle_value = p_value;
52985300
}
52995301

5300-
inline static void free(out_type){}
5302+
inline static void free(MCRectangle& self){}
53015303

5302-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5304+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, MCRectangle& r_value)
53035305
{
53045306
return ctxt . EvalExprAsRectangle(p_expr, p_error, r_value);
53055307
}
@@ -5316,9 +5318,9 @@ template<> struct MCExecValueTraits<float>
53165318
self . float_value = p_value;
53175319
}
53185320

5319-
inline static void free(out_type){}
5321+
inline static void free(float& self){}
53205322

5321-
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, out_type r_value)
5323+
inline static bool eval(MCExecContext &ctxt, MCExpression* p_expr, Exec_errors p_error, float& r_value)
53225324
{
53235325
double t_double;
53245326
if (!ctxt . EvalExprAsDouble(p_expr, p_error, t_double))

engine/src/express.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ void MCExpression::eval_arrayref(MCExecContext& ctxt, MCArrayRef& r_value)
658658

659659
void MCExpression::eval_bool(MCExecContext& ctxt, bool& r_value)
660660
{
661-
eval_typed(ctxt, kMCExecValueTypeNumberRef, &r_value);
661+
eval_typed(ctxt, kMCExecValueTypeBool, &r_value);
662662
}
663663

664664
void MCExpression::eval_uint(MCExecContext& ctxt, uinteger_t& r_value)

0 commit comments

Comments
 (0)