Add op_arrayexpr
This commit is contained in:
parent
d1705df76c
commit
2f732ef209
|
@ -13,7 +13,7 @@
|
||||||
namespace fallout {
|
namespace fallout {
|
||||||
|
|
||||||
static ArrayId nextArrayID = 1;
|
static ArrayId nextArrayID = 1;
|
||||||
static ArrayId stackArrayId = 1;
|
static ArrayId stackArrayId = 0;
|
||||||
|
|
||||||
#define ARRAY_MAX_STRING (255) // maximum length of string to be stored as array key or value
|
#define ARRAY_MAX_STRING (255) // maximum length of string to be stored as array key or value
|
||||||
#define ARRAY_MAX_SIZE (100000) // maximum number of array elements,
|
#define ARRAY_MAX_SIZE (100000) // maximum number of array elements,
|
||||||
|
@ -358,7 +358,7 @@ void sfallArraysReset()
|
||||||
temporaryArrays.clear();
|
temporaryArrays.clear();
|
||||||
arrays.clear();
|
arrays.clear();
|
||||||
nextArrayID = 1;
|
nextArrayID = 1;
|
||||||
stackArrayId = 1;
|
stackArrayId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResizeArray(ArrayId array_id, int newLen)
|
void ResizeArray(ArrayId array_id, int newLen)
|
||||||
|
@ -369,4 +369,24 @@ void ResizeArray(ArrayId array_id, int newLen)
|
||||||
};
|
};
|
||||||
arr->ResizeArray(newLen);
|
arr->ResizeArray(newLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int StackArray(const ProgramValue& key, const ProgramValue& val)
|
||||||
|
{
|
||||||
|
if (stackArrayId == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto arr = get_array_by_id(stackArrayId);
|
||||||
|
if (!arr) {
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto size = arr->size();
|
||||||
|
if (size >= ARRAY_MAX_SIZE) return 0;
|
||||||
|
if (key.asInt() >= size) arr->ResizeArray(size + 1);
|
||||||
|
|
||||||
|
SetArray(stackArrayId, key, val, false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@ void FixArray(ArrayId id);
|
||||||
void ResizeArray(ArrayId array_id, int newLen);
|
void ResizeArray(ArrayId array_id, int newLen);
|
||||||
void DeleteAllTempArrays();
|
void DeleteAllTempArrays();
|
||||||
void sfallArraysReset();
|
void sfallArraysReset();
|
||||||
|
int StackArray(const ProgramValue& key, const ProgramValue& val);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* SFALL_ARRAYS */
|
#endif /* SFALL_ARRAYS */
|
|
@ -533,6 +533,19 @@ static void opSetArray(Program* program)
|
||||||
SetArray(arrayId, key, value, true);
|
SetArray(arrayId, key, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// arrayexpr
|
||||||
|
static void opStackArray(Program* program)
|
||||||
|
{
|
||||||
|
auto value = programStackPopValue(program);
|
||||||
|
auto key = programStackPopValue(program);
|
||||||
|
auto returnValue = StackArray(key, value);
|
||||||
|
programStackPushInteger(program, returnValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get_array
|
// get_array
|
||||||
static void opGetArray(Program* program)
|
static void opGetArray(Program* program)
|
||||||
{
|
{
|
||||||
|
@ -744,6 +757,7 @@ void sfallOpcodesInit()
|
||||||
interpreterRegisterOpcode(0x824F, opGetStringLength);
|
interpreterRegisterOpcode(0x824F, opGetStringLength);
|
||||||
interpreterRegisterOpcode(0x8253, opTypeOf);
|
interpreterRegisterOpcode(0x8253, opTypeOf);
|
||||||
interpreterRegisterOpcode(0x8256, opGetArrayKey);
|
interpreterRegisterOpcode(0x8256, opGetArrayKey);
|
||||||
|
interpreterRegisterOpcode(0x8257, opStackArray);
|
||||||
interpreterRegisterOpcode(0x8263, op_power);
|
interpreterRegisterOpcode(0x8263, op_power);
|
||||||
interpreterRegisterOpcode(0x8267, opRound);
|
interpreterRegisterOpcode(0x8267, opRound);
|
||||||
interpreterRegisterOpcode(0x826B, opGetMessage);
|
interpreterRegisterOpcode(0x826B, opGetMessage);
|
||||||
|
|
Loading…
Reference in New Issue