Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2682c6a

Browse files
committed
[[ Foundation ]] Added UnboundType and Unimplemented errors with appropriate Throw methods.
1 parent 966f36b commit 2682c6a

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

libfoundation/include/foundation.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,8 @@ MC_DLLEXPORT bool MCHandlerGetFunctionPtr(MCHandlerRef handler, void*& r_func_pt
26712671

26722672
MC_DLLEXPORT extern MCTypeInfoRef kMCOutOfMemoryErrorTypeInfo;
26732673
MC_DLLEXPORT extern MCTypeInfoRef kMCGenericErrorTypeInfo;
2674+
MC_DLLEXPORT extern MCTypeInfoRef kMCUnboundTypeErrorTypeInfo;
2675+
MC_DLLEXPORT extern MCTypeInfoRef kMCUnimplementedErrorTypeInfo;
26742676

26752677
MC_DLLEXPORT bool MCErrorCreate(MCTypeInfoRef typeinfo, MCArrayRef info, MCErrorRef& r_error);
26762678

@@ -2708,6 +2710,12 @@ MC_DLLEXPORT MCErrorRef MCErrorPeek(void);
27082710

27092711
// Throw an out of memory error.
27102712
MC_DLLEXPORT bool MCErrorThrowOutOfMemory(void);
2713+
2714+
// Throw an unbound type error.
2715+
MC_DLLEXPORT bool MCErrorThrowUnboundType(MCTypeInfoRef type);
2716+
2717+
// Throw an unimplemented error.
2718+
MC_DLLEXPORT bool MCErrorThrowUnimplemented(MCStringRef thing);
27112719

27122720
// Throw a generic runtime error (one that hasn't had a class made for it yet).
27132721
// The message argument is optional (nil if no message).

libfoundation/src/foundation-error.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2525

2626
MC_DLLEXPORT_DEF MCTypeInfoRef kMCOutOfMemoryErrorTypeInfo;
2727
MC_DLLEXPORT_DEF MCTypeInfoRef kMCGenericErrorTypeInfo;
28+
MC_DLLEXPORT_DEF MCTypeInfoRef kMCUnboundTypeErrorTypeInfo;
29+
MC_DLLEXPORT_DEF MCTypeInfoRef kMCUnimplementedErrorTypeInfo;
2830

2931
static MCErrorRef s_last_error = nil;
3032

@@ -388,6 +390,18 @@ bool MCErrorThrowOutOfMemory(void)
388390
return false;
389391
}
390392

393+
MC_DLLEXPORT_DEF
394+
bool MCErrorThrowUnboundType(MCTypeInfoRef p_type)
395+
{
396+
return MCErrorCreateAndThrow(kMCUnboundTypeErrorTypeInfo, "type", MCNamedTypeInfoGetName(p_type), nil);
397+
}
398+
399+
MC_DLLEXPORT_DEF
400+
bool MCErrorThrowUnimplemented(MCStringRef p_reason)
401+
{
402+
return MCErrorCreateAndThrow(kMCUnimplementedErrorTypeInfo, "reason", p_reason, nil);
403+
}
404+
391405
MC_DLLEXPORT_DEF
392406
bool MCErrorThrowGeneric(MCStringRef p_reason)
393407
{
@@ -448,6 +462,12 @@ bool __MCErrorInitialize(void)
448462

449463
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.GenericError"), MCNAME("runtime"), MCSTR("%{reason}"), kMCGenericErrorTypeInfo))
450464
return false;
465+
466+
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.UnboundTypeError"), MCNAME("runtime"), MCSTR("attempt to use unbound named type %{type}"), kMCUnboundTypeErrorTypeInfo))
467+
return false;
468+
469+
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.UnimplementedError"), MCNAME("runtime"), MCSTR("%{reason}"), kMCUnboundTypeErrorTypeInfo))
470+
return false;
451471

452472
if (!MCErrorCreate(kMCOutOfMemoryErrorTypeInfo, nil, s_out_of_memory_error))
453473
return false;

libscript/src/script-instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ bool MCScriptThrowUnableToResolveForeignHandlerError(MCScriptModuleRef p_module,
249249

250250
bool MCScriptThrowUnableToResolveTypeError(MCTypeInfoRef p_type)
251251
{
252-
return MCErrorCreateAndThrow(kMCScriptTypeBindingErrorTypeInfo, "type", MCNamedTypeInfoGetName(p_type), nil);
252+
return MCErrorThrowUnboundTypeError(p_type);
253253
}
254254

255255
bool MCScriptThrowUnableToResolveMultiInvoke(MCScriptModuleRef p_module, MCScriptDefinition *p_definition, MCProperListRef p_arguments)

libscript/src/script-object.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ bool MCScriptInitialize(void)
262262
return false;
263263
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.PolymorphicHandlerBindingError"), MCNAME("runtime"), MCSTR("Unable to bind appropriate handler"), kMCScriptMultiInvokeBindingErrorTypeInfo))
264264
return false;
265-
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.TypeBindingError"), MCNAME("runtime"), MCSTR("Attempt to use unbound named type %{type}"), kMCScriptTypeBindingErrorTypeInfo))
266-
return false;
267265
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.NoMatchingHandlerError"), MCNAME("runtime"), MCSTR("No matching handler for arguments with types (%{types}) - possible handlers (%{handlers})"), kMCScriptNoMatchingHandlerErrorTypeInfo))
268266
return false;
269267
if (!MCNamedErrorTypeInfoCreate(MCNAME("livecode.lang.CannotSetReadOnlyPropertyError"), MCNAME("runtime"), MCSTR("Cannot set read-only property %{module}.%{property}"), kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo))

libscript/src/script-private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ extern MCTypeInfoRef kMCScriptNotABooleanValueErrorTypeInfo;
3636
extern MCTypeInfoRef kMCScriptWrongNumberOfArgumentsErrorTypeInfo;
3737
extern MCTypeInfoRef kMCScriptForeignHandlerBindingErrorTypeInfo;
3838
extern MCTypeInfoRef kMCScriptMultiInvokeBindingErrorTypeInfo;
39-
extern MCTypeInfoRef kMCScriptTypeBindingErrorTypeInfo;
4039
extern MCTypeInfoRef kMCScriptNoMatchingHandlerErrorTypeInfo;
4140
extern MCTypeInfoRef kMCScriptCannotSetReadOnlyPropertyErrorTypeInfo;
4241
extern MCTypeInfoRef kMCScriptInvalidPropertyValueErrorTypeInfo;

0 commit comments

Comments
 (0)