- implemented array-style syntax for Random calls.

- implemented handling of the basic math operators so that heretic/beast.txt can be processed.

This is working, aside from still needing the type casts to properly transform the strings to class pointers.
This commit is contained in:
Christoph Oelckers 2016-10-16 10:59:12 +02:00
commit 59ab8b7ccd
3 changed files with 73 additions and 26 deletions

View file

@ -3796,15 +3796,15 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
if (CheckArgSize(MethodName, ArgList, 1, -1, ScriptPosition))
{
func = new FxRandomPick(RNG, *ArgList, MethodName == NAME_FRandomPick, ScriptPosition, ctx.FromDecorate);
for (auto &i : *ArgList) i = nullptr; // Ownership of items is transferred to FxMinMax but not ownership of the array itself, so Clear cannot be called here.
for (auto &i : *ArgList) i = nullptr;
}
break;
case NAME_Random2:
if (CheckArgSize(NAME_Random2, ArgList, 1, 1, ScriptPosition))
if (CheckArgSize(NAME_Random2, ArgList, 0, 1, ScriptPosition))
{
func = new FxRandom2(RNG, (*ArgList)[0], ScriptPosition, ctx.FromDecorate);
(*ArgList)[0] = nullptr;
func = new FxRandom2(RNG, ArgList->Size() == 0? nullptr : (*ArgList)[0], ScriptPosition, ctx.FromDecorate);
if (ArgList->Size() > 0) (*ArgList)[0] = nullptr;
}
break;
@ -3813,7 +3813,7 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
if (CheckArgSize(MethodName, ArgList, 2, -1, ScriptPosition))
{
func = new FxMinMax(*ArgList, MethodName, ScriptPosition);
for (auto &i : *ArgList) i = nullptr; // Ownership of items is transferred to FxMinMax but not ownership of the array itself, so Clear cannot be called here.
for (auto &i : *ArgList) i = nullptr;
}
break;

View file

@ -48,10 +48,6 @@
FxExpression *ConvertFunctionCall(ZCC_Expression *function, FArgumentList *args, PClass *cls, FScriptPosition &sc)
{
// function names can either be
// - plain identifiers
// - class members
// - array syntax for random() calls.
switch(function->NodeType)
{
@ -63,10 +59,6 @@ FxExpression *ConvertFunctionCall(ZCC_Expression *function, FArgumentList *args,
case AST_ExprBinary:
// Array access syntax is wrapped into a ZCC_ExprBinary object.
if (fcall->Function->Operation == PEX_ArrayAccess)
{
return ConvertArrayFunctionCall(fcall);
}
break;
default: