mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
Remove duplicate GetSquareRoot implementation
This commit is contained in:
parent
d3f5be0950
commit
6d7cb38834
10 changed files with 19 additions and 65 deletions
|
@ -864,6 +864,9 @@ namespace MWScript
|
|||
float param = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
if (param < 0)
|
||||
throw std::runtime_error("square root of negative number (we aren't that imaginary)");
|
||||
|
||||
runtime.push(std::sqrt (param));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -421,42 +421,26 @@ namespace Compiler
|
|||
|
||||
if (mNextOperand)
|
||||
{
|
||||
if (keyword==Scanner::K_getsquareroot)
|
||||
// check for custom extensions
|
||||
if (const Extensions *extensions = getContext().getExtensions())
|
||||
{
|
||||
start();
|
||||
|
||||
mTokenLoc = loc;
|
||||
parseArguments ("f", scanner);
|
||||
char returnType;
|
||||
std::string argumentType;
|
||||
|
||||
Generator::squareRoot (mCode);
|
||||
mOperands.push_back ('f');
|
||||
bool hasExplicit = false;
|
||||
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for custom extensions
|
||||
if (const Extensions *extensions = getContext().getExtensions())
|
||||
if (extensions->isFunction (keyword, returnType, argumentType, hasExplicit))
|
||||
{
|
||||
start();
|
||||
mTokenLoc = loc;
|
||||
int optionals = parseArguments (argumentType, scanner);
|
||||
|
||||
char returnType;
|
||||
std::string argumentType;
|
||||
extensions->generateFunctionCode (keyword, mCode, mLiterals, "", optionals);
|
||||
mOperands.push_back (returnType);
|
||||
|
||||
bool hasExplicit = false;
|
||||
|
||||
if (extensions->isFunction (keyword, returnType, argumentType, hasExplicit))
|
||||
{
|
||||
mTokenLoc = loc;
|
||||
int optionals = parseArguments (argumentType, scanner);
|
||||
|
||||
extensions->generateFunctionCode (keyword, mCode, mLiterals, "", optionals);
|
||||
mOperands.push_back (returnType);
|
||||
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
}
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,11 +104,6 @@ namespace
|
|||
code.push_back (Compiler::Generator::segment5 (17));
|
||||
}
|
||||
|
||||
void opSquareRoot (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (19));
|
||||
}
|
||||
|
||||
void opReturn (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (20));
|
||||
|
@ -452,11 +447,6 @@ namespace Compiler::Generator
|
|||
}
|
||||
}
|
||||
|
||||
void squareRoot (CodeContainer& code)
|
||||
{
|
||||
opSquareRoot (code);
|
||||
}
|
||||
|
||||
void exit (CodeContainer& code)
|
||||
{
|
||||
opReturn (code);
|
||||
|
|
|
@ -74,8 +74,6 @@ namespace Compiler
|
|||
|
||||
void convert (CodeContainer& code, char fromType, char toType);
|
||||
|
||||
void squareRoot (CodeContainer& code);
|
||||
|
||||
void exit (CodeContainer& code);
|
||||
|
||||
void message (CodeContainer& code, Literals& literals, const std::string& message,
|
||||
|
|
|
@ -265,7 +265,6 @@ namespace Compiler
|
|||
"return",
|
||||
"messagebox",
|
||||
"set", "to",
|
||||
"getsquareroot",
|
||||
nullptr
|
||||
};
|
||||
|
||||
|
|
|
@ -205,8 +205,7 @@ namespace Compiler
|
|||
K_while, K_endwhile,
|
||||
K_return,
|
||||
K_messagebox,
|
||||
K_set, K_to,
|
||||
K_getsquareroot
|
||||
K_set, K_to
|
||||
};
|
||||
|
||||
enum special
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace Compiler
|
|||
keyword==Scanner::K_elseif || keyword==Scanner::K_while ||
|
||||
keyword==Scanner::K_endwhile || keyword==Scanner::K_return ||
|
||||
keyword==Scanner::K_messagebox || keyword==Scanner::K_set ||
|
||||
keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot)
|
||||
keyword==Scanner::K_to)
|
||||
{
|
||||
// pretend this is not a keyword
|
||||
std::string name = loc.mLiteral;
|
||||
|
|
|
@ -77,7 +77,7 @@ op 15: div (integer) stack[1] by stack[0], pop twice, push result
|
|||
op 16: div (float) stack[1] by stack[0], pop twice, push result
|
||||
op 17: convert stack[1] from integer to float
|
||||
op 18: convert stack[1] from float to integer
|
||||
op 19: take square root of stack[0] (float)
|
||||
opcode 19 unused
|
||||
op 20: return
|
||||
op 21: replace stack[0] with local short stack[0]
|
||||
op 22: replace stack[0] with local long stack[0]
|
||||
|
|
|
@ -59,7 +59,6 @@ namespace Interpreter
|
|||
interpreter.installSegment5 (14, new OpMulInt<Type_Float>);
|
||||
interpreter.installSegment5 (15, new OpDivInt<Type_Integer>);
|
||||
interpreter.installSegment5 (16, new OpDivInt<Type_Float>);
|
||||
interpreter.installSegment5 (19, new OpSquareRoot);
|
||||
interpreter.installSegment5 (26,
|
||||
new OpCompare<Type_Integer, std::equal_to<Type_Integer> >);
|
||||
interpreter.installSegment5 (27,
|
||||
|
|
|
@ -74,24 +74,6 @@ namespace Interpreter
|
|||
}
|
||||
};
|
||||
|
||||
class OpSquareRoot : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
void execute (Runtime& runtime) override
|
||||
{
|
||||
Type_Float value = runtime[0].mFloat;
|
||||
|
||||
if (value<0)
|
||||
throw std::runtime_error (
|
||||
"square root of negative number (we aren't that imaginary)");
|
||||
|
||||
value = std::sqrt (value);
|
||||
|
||||
runtime[0].mFloat = value;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename C>
|
||||
class OpCompare : public Opcode0
|
||||
{
|
||||
|
@ -105,7 +87,7 @@ namespace Interpreter
|
|||
|
||||
runtime[0].mInteger = result;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue