Skip to content

Commit fb067ad

Browse files
MCVariable functions updated to use an MCExecContext
MCB_setmsg updated subsequently
1 parent a4ff1e8 commit fb067ad

File tree

6 files changed

+87
-227
lines changed

6 files changed

+87
-227
lines changed

engine/src/cmds.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,9 +2438,8 @@ void MCSort::additem(MCExecContext &ctxt, MCSortnode *items, uint4 &nitems, Sort
24382438
MCAutoValueRef t_value;
24392439
if (by != NULL)
24402440
{
2441-
MCerrorlock++;
2442-
ctxt.GetEP().setvalueref(p_value);
2443-
MCeach->set(ctxt.GetEP());
2441+
MCerrorlock++;
2442+
MCeach -> setvalueref(p_value);
24442443
if (by->eval(ctxt.GetEP()) == ES_NORMAL)
24452444
t_value = ctxt.GetEP().getvalueref();
24462445
else

engine/src/debug.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static int2 depth;
7676

7777
#include "srvdebug.h"
7878

79-
void MCB_setmsg(MCStringRef p_msg)
79+
void MCB_setmsg(MCExecContext& ctxt, MCStringRef p_msg)
8080
{
8181

8282
}
@@ -122,11 +122,10 @@ void MCB_setvar(MCExecContext &ctxt, MCValueRef p_value, MCNameRef name)
122122

123123
#else
124124

125-
void MCB_setmsg(MCStringRef p_msg)
125+
void MCB_setmsg(MCExecContext& ctxt, MCStringRef p_msg)
126126
{
127-
MCExecPoint ep(nil, nil, nil);
128-
ep . setvalueref(p_msg);
129-
MCB_setmsg(ep);
127+
ctxt . GetEP() . setvalueref(p_msg);
128+
MCB_setmsg(ctxt . GetEP());
130129
}
131130

132131
void MCB_setmsg(MCExecPoint &ep)

engine/src/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern uint2 MCnexecutioncontexts;
6262
extern uint2 MCdebugcontext;
6363
extern Boolean MCmessagemessages;
6464

65-
extern void MCB_setmsg(MCStringRef p_string);
65+
extern void MCB_setmsg(MCExecContext& ctxt, MCStringRef p_msg);
6666
extern void MCB_setmsg(MCExecPoint &ep);
6767
extern void MCB_message(MCExecPoint &ep, MCNameRef message, MCParameter *p);
6868
extern void MCB_prepmessage(MCExecPoint &ep, MCNameRef message, uint2 line, uint2 pos, uint2 id, MCStringRef p_info = kMCEmptyString);

engine/src/lnxdc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ uint4 MCScreenDC::getdisplays(MCDisplay const *& p_displays, bool p_effective)
434434
bool MCScreenDC::listprinters(MCStringRef& r_printers)
435435
{
436436
MCdefaultstackptr->domess(MCSTR(LIST_PRINTER_SCRIPT));
437-
MCresult->eval(false, (MCValueRef&)r_printers);
437+
MCresult->copyasvalueref((MCValueRef&)r_printers);
438438
return true;
439439
}
440440

engine/src/variable.cpp

Lines changed: 62 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -235,60 +235,54 @@ MCValueRef MCVariable::getvalueref(MCNameRef *p_path, uindex_t p_length, bool p_
235235
return kMCEmptyString;
236236
}
237237

238-
bool MCVariable::copyasvalueref(MCValueRef &r_value)
238+
bool MCVariable::copyasvalueref(MCValueRef& r_value)
239239
{
240-
return MCValueCopy(getvalueref(nil, 0, false), r_value);
240+
return copyasvalueref(nil, 0, false, r_value);
241241
}
242242

243-
bool MCVariable::copyasvalueref(MCNameRef *p_path, uindex_t p_length, bool p_case_sensitive, MCValueRef &r_value)
243+
bool MCVariable::copyasvalueref(MCNameRef *p_path, uindex_t p_length, bool p_case_sensitive, MCValueRef& r_value)
244244
{
245-
return MCValueCopy(getvalueref(p_path, p_length, p_case_sensitive));
245+
return MCValueCopy(getvalueref(p_path, p_length, p_case_sensitive), r_value);
246246
}
247247

248248
Exec_stat MCVariable::eval(MCExecPoint& ep)
249249
{
250-
return eval(ep, nil, 0);
250+
return eval(ep, nil, 0);
251251
}
252252

253-
void MCVariable::eval(bool p_case_sensitive, MCValueRef &r_value)
253+
Exec_stat MCVariable::eval(MCExecPoint& ep, MCNameRef *p_path, uindex_t p_length)
254254
{
255-
eval(nil, 0, p_case_sensitive, r_value);
256-
}
255+
MCExecContext ctxt(ep);
257256

258-
void MCVariable::eval(MCNameRef *p_path, uindex_t p_length, bool p_case_sensitive, MCValueRef &r_value)
259-
{
260-
r_value = getvalueref(p_path, p_length, p_case_sensitive);
257+
MCAutoValueRef t_value;
258+
if (eval(ctxt, p_path, p_length, &t_value) &&
259+
ep . setvalueref(*t_value))
260+
return ES_NORMAL;
261+
262+
return ES_ERROR;
261263
}
262264

263-
Exec_stat MCVariable::eval(MCExecPoint& ep, MCNameRef *p_path, uindex_t p_length)
265+
bool MCVariable::eval(MCExecContext& ctxt, MCNameRef *p_path, uindex_t p_length, MCValueRef& r_value)
264266
{
265-
MCValueRef t_value;
266-
t_value = getvalueref(p_path, p_length, ep . getcasesensitive() == True);
267-
268-
if (ep . setvalueref(t_value))
269-
return ES_NORMAL;
270-
271-
return ES_ERROR;
267+
return copyasvalueref(p_path, p_length, ctxt . GetCaseSensitive(), r_value);
272268
}
273269

274270
Exec_stat MCVariable::set(MCExecPoint& ep)
275271
{
276-
return set(ep, nil, 0);
272+
return set(ep, nil, 0);
277273
}
278274

279275
Exec_stat MCVariable::set(MCExecPoint& ep, MCNameRef *p_path, uindex_t p_length)
280276
{
281-
MCAutoValueRef t_value;
282-
if (!ep . copyasvalueref(&t_value))
283-
return ES_ERROR;
277+
MCAutoValueRef t_value;
278+
if (!ep . copyasvalueref(&t_value))
279+
return ES_ERROR;
284280

285-
if (setvalueref(p_path, p_length, ep . getcasesensitive() == True, *t_value))
286-
{
287-
synchronize(ep, True);
288-
return ES_NORMAL;
289-
}
281+
MCExecContext ctxt(ep);
282+
if (set(ctxt, *t_value, p_path, p_length))
283+
return ES_NORMAL;
290284

291-
return ES_ERROR;
285+
return ES_ERROR;
292286
}
293287

294288
bool MCVariable::set(MCExecContext& ctxt, MCValueRef p_value)
@@ -303,7 +297,7 @@ bool MCVariable::set(MCExecContext& ctxt, MCValueRef p_value, MCNameRef *p_path,
303297

304298
if (setvalueref(p_path, p_length, ctxt . GetCaseSensitive(), *t_value))
305299
{
306-
synchronize(ctxt, p_value, true);
300+
synchronize(ctxt, true);
307301
return true;
308302
}
309303

@@ -312,45 +306,20 @@ bool MCVariable::set(MCExecContext& ctxt, MCValueRef p_value, MCNameRef *p_path,
312306

313307
Exec_stat MCVariable::append(MCExecPoint& ep)
314308
{
315-
return append(ep, nil, 0);
309+
return append(ep, nil, 0);
316310
}
317311

318312
Exec_stat MCVariable::append(MCExecPoint& ep, MCNameRef *p_path, uindex_t p_length)
319313
{
320-
MCAutoStringRef t_value;
321-
if (!ep . copyasstringref(&t_value))
322-
return ES_ERROR;
323-
324-
if (p_length == 0)
325-
{
326-
if (!converttomutablestring(ep))
327-
return ES_ERROR;
328-
329-
if (!MCStringAppend((MCStringRef)value, *t_value))
330-
return ES_ERROR;
331-
332-
synchronize(ep, True);
314+
MCAutoValueRef t_value;
315+
if (!ep . copyasvalueref(&t_value))
316+
return ES_ERROR;
333317

334-
return ES_NORMAL;
335-
}
318+
MCExecContext ctxt(ep);
319+
if (append(ctxt, *t_value, p_path, p_length))
320+
return ES_NORMAL;
336321

337-
MCValueRef t_current_value;
338-
t_current_value = getvalueref(p_path, p_length, ep . getcasesensitive() == True);
339-
340-
MCStringRef t_current_value_as_string;
341-
t_current_value_as_string = nil;
342-
if (ep . convertvaluereftostring(t_current_value, t_current_value_as_string) &&
343-
MCStringMutableCopyAndRelease(t_current_value_as_string, t_current_value_as_string) &&
344-
MCStringAppend(t_current_value_as_string, *t_value) &&
345-
setvalueref(p_path, p_length, ep . getcasesensitive() == True, t_current_value_as_string))
346-
{
347-
MCValueRelease(t_current_value_as_string);
348-
synchronize(ep, True);
349-
return ES_NORMAL;
350-
}
351-
352-
MCValueRelease(t_current_value_as_string);
353-
return ES_ERROR;
322+
return ES_ERROR;
354323
}
355324

356325
bool MCVariable::append(MCExecContext& ctxt, MCValueRef p_value)
@@ -372,11 +341,11 @@ bool MCVariable::append(MCExecContext& ctxt, MCValueRef p_value, MCNameRef *p_pa
372341
if (!MCStringAppend((MCStringRef)value, *t_value))
373342
return false;
374343

375-
synchronize(ctxt, p_value, true);
344+
synchronize(ctxt, true);
376345

377346
return true;
378347
}
379-
348+
380349
MCValueRef t_current_value;
381350
t_current_value = getvalueref(p_path, p_length, ctxt . GetCaseSensitive());
382351

@@ -388,7 +357,7 @@ bool MCVariable::append(MCExecContext& ctxt, MCValueRef p_value, MCNameRef *p_pa
388357
setvalueref(p_path, p_length, ctxt . GetCaseSensitive(), t_current_value_as_string))
389358
{
390359
MCValueRelease(t_current_value_as_string);
391-
synchronize(ctxt, p_value, true);
360+
synchronize(ctxt, true);
392361
return true;
393362
}
394363

@@ -398,36 +367,16 @@ bool MCVariable::append(MCExecContext& ctxt, MCValueRef p_value, MCNameRef *p_pa
398367

399368
Exec_stat MCVariable::remove(MCExecPoint& ep)
400369
{
401-
return remove(ep, nil, 0);
370+
return remove(ep, nil, 0);
402371
}
403372

404373
Exec_stat MCVariable::remove(MCExecPoint& ep, MCNameRef *p_path, uindex_t p_length)
405374
{
406-
if (p_length == 0)
407-
{
408-
clear();
409-
410-
if (is_env)
411-
{
412-
if (!isdigit(MCNameGetCharAtIndex(name, 1)) && MCNameGetCharAtIndex(name, 1) != '#')
413-
{
414-
MCAutoStringRef t_env;
415-
/* UNCHECKED */ MCStringCopySubstring(MCNameGetString(name), MCRangeMake(1, MCStringGetLength(MCNameGetString(name))), &t_env);
416-
MCS_unsetenv(*t_env);
417-
}
418-
}
419-
}
420-
421-
if (MCValueGetTypeCode(value) != kMCValueTypeCodeArray)
422-
return ES_NORMAL;
423-
424-
if (!converttomutablearray())
425-
return ES_ERROR;
426-
427-
MCArrayRemoveValueOnPath((MCArrayRef)value, ep . getcasesensitive() == True, p_path, p_length);
428-
429-
return ES_NORMAL;
375+
MCExecContext ctxt(ep);
376+
if (remove(ctxt, p_path, p_length))
377+
return ES_NORMAL;
430378

379+
return ES_ERROR;
431380
}
432381

433382
bool MCVariable::remove(MCExecContext& ctxt)
@@ -627,6 +576,7 @@ bool MCVariable::ensureglobal(MCNameRef p_name, MCVariable*& r_var)
627576

628577
////////////////////////////////////////////////////////////////////////////////
629578

579+
#if 0
630580
void MCVariable::synchronize(MCExecPoint& ep, Boolean notify)
631581
{
632582
if (is_env)
@@ -682,15 +632,16 @@ void MCVariable::synchronize(MCExecPoint& ep, Boolean notify)
682632
}
683633
}
684634
}
635+
#endif
685636

686-
void MCVariable::synchronize(MCExecContext& ctxt, MCValueRef p_value, bool p_notify)
637+
void MCVariable::synchronize(MCExecContext& ctxt, bool p_notify)
687638
{
688639
if (is_env)
689640
{
690641
if (!isdigit(MCNameGetCharAtIndex(name, 1)) && MCNameGetCharAtIndex(name, 1) != '#')
691642
{
692643
MCAutoStringRef t_string;
693-
if (ctxt . ConvertToString(p_value, &t_string))
644+
if (ctxt . ConvertToString(value, &t_string))
694645
{
695646
MCAutoStringRef t_env;
696647
/* UNCHECKED */ MCStringCopySubstring(MCNameGetString(name), MCRangeMake(1, MCStringGetLength(MCNameGetString(name))), &t_env);
@@ -699,13 +650,10 @@ void MCVariable::synchronize(MCExecContext& ctxt, MCValueRef p_value, bool p_not
699650
}
700651
}
701652
else if (is_msg)
702-
{
703-
MCAutoValueRef t_value;
704-
eval(ctxt . GetCaseSensitive(), &t_value);
705-
653+
{
706654
MCAutoStringRef t_msg;
707-
if (ctxt . ConvertToString(*t_value, &t_msg))
708-
MCB_setmsg(*t_msg);
655+
if (ctxt . ConvertToString(value, &t_msg))
656+
MCB_setmsg(ctxt, *t_msg);
709657
}
710658

711659
if (p_notify && MCnwatchedvars)
@@ -723,24 +671,22 @@ void MCVariable::synchronize(MCExecContext& ctxt, MCValueRef p_value, bool p_not
723671
MCwatchedvars[i] . handlername == NULL &&
724672
!is_global)
725673
continue;
726-
727-
// Otherwise, trigger the setvar message.
728-
MCAutoValueRef t_value;
729-
eval(ctxt . GetCaseSensitive(), &t_value);
730-
674+
731675
if (*MCwatchedvars[i].expression)
732676
{
733677
MCAutoStringRef t_expression;
734678
MCStringCreateWithCString(MCwatchedvars[i].expression, &t_expression);
735-
MCAutoValueRef t_bool_value;
679+
MCAutoValueRef t_value;
680+
MCAutoBooleanRef t_bool_value;
736681

737-
ctxt . GetHandler() -> eval(ctxt, *t_expression, &t_bool_value);
738-
739-
if (!ctxt . HasError() && (MCBooleanRef)*t_bool_value == kMCTrue)
740-
MCB_setvar(ctxt, *t_value, name);
682+
ctxt . GetHandler() -> eval(ctxt, *t_expression, &t_value);
683+
if (!ctxt . HasError() &&
684+
ctxt . ConvertToBoolean(*t_value, &t_bool_value))
685+
if (!ctxt . HasError() && *t_bool_value == kMCTrue)
686+
MCB_setvar(ctxt, value, name);
741687
}
742688
else
743-
MCB_setvar(ctxt, *t_value, name);
689+
MCB_setvar(ctxt, value, name);
744690

745691
break;
746692
}
@@ -803,9 +749,9 @@ Exec_stat MCContainer::remove(MCExecPoint& ep)
803749
return m_variable -> remove(ep, m_path, m_length);
804750
}
805751

806-
void MCContainer::eval(bool p_case_sensitive, MCValueRef& r_value)
752+
bool MCContainer::eval(MCExecContext& ctxt, MCValueRef& r_value)
807753
{
808-
m_variable -> eval(m_path, m_length, p_case_sensitive, r_value);
754+
return m_variable -> eval(ctxt, m_path, m_length, r_value);
809755
}
810756

811757
bool MCContainer::set(MCExecContext& ctxt, MCValueRef p_value)
@@ -958,16 +904,15 @@ bool MCVarref::eval(MCExecContext& ctxt, MCValueRef& r_value)
958904

959905
t_resolved_ref = fetchvar(ctxt);
960906

961-
t_resolved_ref -> eval(ctxt . GetCaseSensitive(), r_value);
962-
963-
return true;
907+
return t_resolved_ref -> copyasvalueref(r_value);
964908
}
965909

966910
MCAutoPointer<MCContainer> t_container;
967911
if (!resolve(ctxt, &t_container))
968912
return false;
969913

970-
t_container -> eval(ctxt . GetCaseSensitive(), r_value);
914+
if (!t_container -> eval(ctxt, r_value))
915+
return false;
971916

972917
return true;
973918
}
@@ -1168,7 +1113,7 @@ Exec_stat MCVarref::dofree(MCExecPoint &ep)
11681113

11691114
t_var = fetchvar(ep);
11701115

1171-
return t_var -> remove(ep, nil, 0);
1116+
return t_var -> remove(ep);
11721117
}
11731118

11741119
MCAutoPointer<MCContainer> t_container;

0 commit comments

Comments
 (0)