Skip to content

Commit

Permalink
Add some object checks. Fix return type
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Aug 7, 2014
1 parent 709671d commit 73cbb6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/hx/Cppia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,7 @@ struct ScriptCallable : public CppiaDynamicExpr
stackSize = 0;
data = 0;
returnTypeId = stream.getInt();
returnType = etVoid;
argCount = stream.getInt();
args.resize(argCount);
hasDefault.resize(argCount);
Expand Down Expand Up @@ -2898,7 +2899,7 @@ class CppiaClosure : public hx::Object
ctx->pushFloat(inValue->__ToDouble());
break;
case etString:
ctx->pushString(inValue->toString());
ctx->pushString(inValue.mPtr ? inValue->toString() : String());
break;
default:
ctx->pushObject(inValue.mPtr);
Expand Down Expand Up @@ -3332,6 +3333,7 @@ struct CallFunExpr : public CppiaExpr
args.swap(ioArgs);
function = inFunction;
thisExpr = inThisExpr;
returnType = etVoid;
}

CppiaExpr *link(CppiaData &inData)
Expand All @@ -3341,7 +3343,7 @@ struct CallFunExpr : public CppiaExpr
//function = (ScriptCallable *)function->link(inData);
if (thisExpr)
thisExpr = thisExpr->link(inData);
returnType = inData.types[ function->returnType ]->expressionType;
returnType = inData.types[ function->returnTypeId ]->expressionType;
return this;
}

Expand Down Expand Up @@ -4767,6 +4769,9 @@ struct MemReference : public CppiaExpr
T *pointer;
CppiaExpr *object;

#define CHECKVAL \
if (REFMODE==locObj) CPPIA_CHECK(object);

#define MEMGETVAL \
*(T *)( \
( REFMODE==locObj ?(char *)object->runObject(ctx) : \
Expand Down Expand Up @@ -4810,18 +4815,25 @@ struct MemReference : public CppiaExpr


void runVoid(CppiaCtx *ctx) { }
int runInt(CppiaCtx *ctx) { return ValToInt( MEMGETVAL ); }
int runInt(CppiaCtx *ctx)
{
CHECKVAL;
return ValToInt( MEMGETVAL );
}
Float runFloat(CppiaCtx *ctx)
{
CHECKVAL;
return ValToFloat( MEMGETVAL );
}
::String runString(CppiaCtx *ctx) {
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToString(t);
}
hx::Object *runObject(CppiaCtx *ctx)
{
CHECKVAL;
return Dynamic( MEMGETVAL ).mPtr;
}

Expand Down Expand Up @@ -4883,30 +4895,35 @@ struct MemReferenceSetter : public CppiaExpr

void runVoid(CppiaCtx *ctx)
{
CHECKVAL;
T &t = MEMGETVAL;
BCR_VCHECK;
Assign::run( t, ctx, value);
}
int runInt(CppiaCtx *ctx)
{
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToInt( Assign::run(t,ctx, value ) );
}
Float runFloat(CppiaCtx *ctx)
{
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToFloat( Assign::run(t,ctx, value) );
}
::String runString(CppiaCtx *ctx)
{
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToString( Assign::run(t,ctx, value) );
}
hx::Object *runObject(CppiaCtx *ctx)
{
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return Dynamic( Assign::run(t,ctx,value) ).mPtr;
Expand Down Expand Up @@ -4982,25 +4999,30 @@ struct MemReferenceCrement : public CppiaExpr
}

void runVoid(CppiaCtx *ctx) {
CHECKVAL;
CREMENT::run( MEMGETVAL );
}
int runInt(CppiaCtx *ctx) {
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToInt( CREMENT::run(t) );
}
Float runFloat(CppiaCtx *ctx) {
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToFloat( CREMENT::run(t));
}
::String runString(CppiaCtx *ctx) {
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return ValToString( CREMENT::run(t) );
}

hx::Object *runObject(CppiaCtx *ctx) {
CHECKVAL;
T &t = MEMGETVAL;
BCR_CHECK;
return Dynamic( CREMENT::run(t) ).mPtr;
Expand Down
7 changes: 6 additions & 1 deletion src/hx/Cppia.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ struct CppiaExpr
#define CPPIA_CHECK(obj)
#endif

#define CPPIA_CHECK_FUNC(obj) if (!obj) Dynamic::ThrowBadFunctionError()
#ifdef HXCPP_CHECK_POINTER
#define CPPIA_CHECK_FUNC(obj) if (!obj) Dynamic::ThrowBadFunctionError(); GCCheckPointer(obj);
#else
#define CPPIA_CHECK_FUNC(obj) if (!obj) Dynamic::ThrowBadFunctionError();
#endif



struct BCRReturn
Expand Down

0 comments on commit 73cbb6a

Please sign in to comment.