Skip to content

Commit

Permalink
Merge branch 'edge-obj'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexikos committed May 25, 2018
2 parents 9dd3066 + 01b91e8 commit bb8e921
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 16 deletions.
17 changes: 16 additions & 1 deletion source/script.cpp
Expand Up @@ -8445,6 +8445,7 @@ Func *Script::FindFunc(LPCTSTR aFuncName, size_t aFuncNameLength, int *apInsertP
BIF_OBJ_CASE(Remove, 0, 2) // [min_key, max_key]
BIF_OBJ_CASE(RemoveAt, 1, 2) // position [, count]
BIF_OBJ_CASE(Pop, 0, 0)
BIF_OBJ_CASE(Count, 0, 0)
BIF_OBJ_CASE(Length, 0, 0)
BIF_OBJ_CASE(MinIndex, 0, 0)
BIF_OBJ_CASE(MaxIndex, 0, 0)
Expand All @@ -8460,10 +8461,24 @@ Func *Script::FindFunc(LPCTSTR aFuncName, size_t aFuncNameLength, int *apInsertP
bif = BIF_ObjAddRefRelease;
else if (!_tcsicmp(suffix, _T("RawSet")))
{
bif = BIF_ObjRawSet;
bif = BIF_ObjRaw;
min_params = 3;
max_params = 3;
}
else if (!_tcsicmp(suffix, _T("RawGet")))
{
bif = BIF_ObjRaw;
min_params = 2;
max_params = 2;
}
else if (!_tcsicmp(suffix, _T("GetBase")))
bif = BIF_ObjBase;
else if (!_tcsicmp(suffix, _T("SetBase")))
{
bif = BIF_ObjBase;
min_params = 2;
max_params = 2;
}
else return NULL;
}
else if (!_tcsicmp(func_name, _T("Array")))
Expand Down
4 changes: 3 additions & 1 deletion source/script.h
Expand Up @@ -3304,7 +3304,8 @@ BIF_DECL(BIF_ObjNew); // Pseudo-operator.
BIF_DECL(BIF_ObjIncDec); // Pseudo-operator.
BIF_DECL(BIF_ObjAddRefRelease);
BIF_DECL(BIF_ObjBindMethod);
BIF_DECL(BIF_ObjRawSet);
BIF_DECL(BIF_ObjRaw);
BIF_DECL(BIF_ObjBase);
// Built-ins also available as methods -- these are available as functions for use primarily by overridden methods (i.e. where using the built-in methods isn't possible as they're no longer accessible).
BIF_DECL(BIF_ObjInsert);
BIF_DECL(BIF_ObjInsertAt);
Expand All @@ -3316,6 +3317,7 @@ BIF_DECL(BIF_ObjRemoveAt);
BIF_DECL(BIF_ObjGetCapacity);
BIF_DECL(BIF_ObjSetCapacity);
BIF_DECL(BIF_ObjGetAddress);
BIF_DECL(BIF_ObjCount);
BIF_DECL(BIF_ObjLength);
BIF_DECL(BIF_ObjMaxIndex);
BIF_DECL(BIF_ObjMinIndex);
Expand Down
10 changes: 10 additions & 0 deletions source/script_object.cpp
Expand Up @@ -750,6 +750,9 @@ int Object::GetBuiltinID(LPCTSTR aName)
case 'D':
if (!_tcsicmp(aName, _T("Delete")))
return FID_ObjDelete;
case 'C':
if (!_tcsicmp(aName, _T("Count")))
return FID_ObjCount;
break;
}
// Older methods which support the _ prefix:
Expand Down Expand Up @@ -816,6 +819,7 @@ ResultType Object::CallBuiltin(int aID, ExprTokenType &aResultToken, ExprTokenTy
case_method(InsertAt);
case_method(RemoveAt);
case_method(Delete);
case_method(Count);
case_method(MinIndex);
case_method(GetAddress);
case_method(SetCapacity);
Expand Down Expand Up @@ -1291,6 +1295,12 @@ ResultType Object::_MinIndex(ExprTokenType &aResultToken, ExprTokenType *aParam[
return OK;
}

ResultType Object::_Count(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
aResultToken.SetValue((__int64)mFieldCount);
return OK;
}

ResultType Object::_Length(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
IntKeyType max_index = mKeyOffsetObject ? mFields[mKeyOffsetObject - 1].key.i : 0;
Expand Down
26 changes: 17 additions & 9 deletions source/script_object.h
Expand Up @@ -13,6 +13,7 @@ enum ObjectMethodID { // Partially ported from v2 BuiltInFunctionID. Used for c
FID_ObjInsertAt, FID_ObjDelete, FID_ObjRemoveAt, FID_ObjPush, FID_ObjPop, FID_ObjLength
, FID_ObjHasKey, FID_ObjGetCapacity, FID_ObjSetCapacity, FID_ObjGetAddress, FID_ObjClone
, FID_ObjNewEnum, FID_ObjMaxIndex, FID_ObjMinIndex, FID_ObjRemove, FID_ObjInsert
, FID_ObjCount
};


Expand Down Expand Up @@ -233,23 +234,29 @@ class Object : public ObjectBase
{
return (int)mKeyOffsetObject;
}
bool GetItem(ExprTokenType &aToken, LPTSTR aKey)

bool GetItem(ExprTokenType &aToken, ExprTokenType &aKey)
{
KeyType key;
SymbolType key_type = IsPureNumeric(aKey, FALSE, FALSE, FALSE); // SYM_STRING or SYM_INTEGER.
if (key_type == SYM_INTEGER)
key.i = Exp32or64(ATOI,ATOI64)(aKey);
else
key.s = aKey;
IndexType insert_pos;
FieldType *field = FindField(key_type, key, insert_pos);
TCHAR buf[MAX_NUMBER_SIZE];
SymbolType key_type;
KeyType key;
FieldType *field = FindField(aKey, buf, key_type, key, insert_pos);
if (!field)
return false;
field->ToToken(aToken);
return true;
}

bool GetItem(ExprTokenType &aToken, LPTSTR aKey)
{
ExprTokenType key;
key.symbol = SYM_OPERAND;
key.marker = aKey;
key.buf = NULL;
return GetItem(aToken, key);
}

bool SetItem(ExprTokenType &aKey, ExprTokenType &aValue)
{
IndexType insert_pos;
Expand Down Expand Up @@ -337,6 +344,7 @@ class Object : public ObjectBase
ResultType _GetCapacity(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _SetCapacity(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _GetAddress(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _Count(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _Length(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _MaxIndex(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
ResultType _MinIndex(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount);
Expand Down
75 changes: 70 additions & 5 deletions source/script_object_bif.cpp
Expand Up @@ -379,6 +379,7 @@ BIF_METHOD(RemoveAt)
BIF_METHOD(GetCapacity)
BIF_METHOD(SetCapacity)
BIF_METHOD(GetAddress)
BIF_METHOD(Count)
BIF_METHOD(Length)
BIF_METHOD(MaxIndex)
BIF_METHOD(MinIndex)
Expand Down Expand Up @@ -434,17 +435,81 @@ BIF_DECL(BIF_ObjBindMethod)
// ObjRawSet - set a value without invoking any meta-functions.
//

BIF_DECL(BIF_ObjRawSet)
BIF_DECL(BIF_ObjRaw)
{
Object *obj = dynamic_cast<Object*>(TokenToObject(*aParam[0]));
if (!obj)
{
aResult = g_script.ScriptError(ERR_PARAM1_INVALID);
return;
}
if (!obj->SetItem(*aParam[1], *aParam[2]))
aResult = g_script.ScriptError(ERR_OUTOFMEM);

if (ctoupper(aResultToken.marker[6]) == 'S')
{
if (!obj->SetItem(*aParam[1], *aParam[2]))
{
aResult = g_script.ScriptError(ERR_OUTOFMEM);
return;
}
}
else
{
ExprTokenType value;
if (obj->GetItem(value, *aParam[1]))
{
switch (value.symbol)
{
case SYM_OPERAND:
aResultToken.symbol = SYM_STRING;
aResult = TokenSetResult(aResultToken, value.marker);
break;
case SYM_OBJECT:
aResultToken.symbol = SYM_OBJECT;
aResultToken.object = value.object;
aResultToken.object->AddRef();
break;
default:
aResultToken.symbol = value.symbol;
aResultToken.value_int64 = value.value_int64;
break;
}
return;
}
}
aResultToken.symbol = SYM_STRING;
aResultToken.marker = _T("");
}
}


//
// ObjSetBase/ObjGetBase - Change or return Object's base without invoking any meta-functions.
//

BIF_DECL(BIF_ObjBase)
{
Object *obj = dynamic_cast<Object*>(TokenToObject(*aParam[0]));
if (!obj)
{
aResult = g_script.ScriptError(ERR_PARAM1_INVALID);
return;
}
if (ctoupper(aResultToken.marker[3]) == 'S') // ObjSetBase
{
IObject *new_base = TokenToObject(*aParam[1]);
if (!new_base && !TokenIsEmptyString(*aParam[1]))
{
aResult = g_script.ScriptError(ERR_PARAM2_INVALID);
return;
}
obj->SetBase(new_base);
}
else // ObjGetBase
{
if (IObject *obj_base = obj->Base())
{
obj_base->AddRef();
aResultToken.SetValue(obj_base);
return;
}
}
aResultToken.SetValue(_T(""));
}

0 comments on commit bb8e921

Please sign in to comment.