2013-07-29 09:42:45 +00:00
|
|
|
#ifdef NALL_STRING_INTERNAL_HPP
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
namespace Eval {
|
|
|
|
|
|
|
|
inline string evaluateExpression(Node* node) {
|
|
|
|
#define p(n) evaluateExpression(node->link[n])
|
|
|
|
switch(node->type) {
|
|
|
|
case Node::Type::Null: return "Null";
|
|
|
|
case Node::Type::Literal: return {"Literal:", node->literal};
|
|
|
|
case Node::Type::Function: return {"Function(0:", p(0), ", 1:", p(1), ")"};
|
|
|
|
case Node::Type::Subscript: return {"Subscript(0:", p(0), ", 1:", p(1), ")"};
|
|
|
|
case Node::Type::Member: return {"Member(0:", p(0), ", 1:", p(1), ")"};
|
|
|
|
case Node::Type::SuffixIncrement: return {"SuffixIncrement(0:", p(0), ")"};
|
|
|
|
case Node::Type::SuffixDecrement: return {"SuffixDecrement(0:", p(0), ")"};
|
|
|
|
case Node::Type::Reference: return {"Reference(0:", p(0), ")"};
|
|
|
|
case Node::Type::Dereference: return {"Dereference(0:", p(0), ")"};
|
|
|
|
case Node::Type::BitwiseNot: return {"Complement(0:", p(0), ")"};
|
|
|
|
case Node::Type::PrefixIncrement: return {"PrefixIncrement(0:", p(0), ")"};
|
|
|
|
case Node::Type::PrefixDecrement: return {"PrefixDecrement(0:", p(0), ")"};
|
|
|
|
case Node::Type::Add: return {"Add(0:", p(0), ", 1:", p(1), ")"};
|
|
|
|
case Node::Type::Multiply: return {"Multiply(0:", p(0), ", 1:", p(1), ")"};
|
|
|
|
case Node::Type::Concatenate: return {"Concatenate(0:", p(0), ", ", p(1), ")"};
|
|
|
|
case Node::Type::Coalesce: return {"Coalesce(0:", p(0), ", ", p(1), ")"};
|
|
|
|
case Node::Type::Condition: return {"Condition(0:", p(0), ", ", p(1), ", ", p(2), ")"};
|
|
|
|
case Node::Type::Assign: return {"Assign(0:", p(0), ", ", p(1), ")"};
|
|
|
|
case Node::Type::Separator: {
|
|
|
|
string result = "Separator(";
|
|
|
|
for(auto& link : node->link) {
|
|
|
|
result.append(evaluateExpression(link), ", ");
|
|
|
|
}
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
return result.rtrim(", ").append(")");
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef p
|
|
|
|
|
|
|
|
throw "invalid operator";
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int64_t evaluateInteger(Node* node) {
|
Update to v093r01 release.
byuu says:
Changelog:
- added SA-1 MDR; fixes bug in SD Gundam G-Next where the main
battleship was unable to fire
- added out-of-the-box support for any BSD running Clang 3.3+ (FreeBSD
10+, notably)
- added new video shader, "Display Emulation", which changes the shader
based on the emulated system
- fixed the home button to go to your default library path
- phoenix: Windows port won't send onActivate unless an item is selected
(prevents crashing on pressing enter in file dialog)
- ruby: removed vec4 position from out Vertex {} (helps AMD cards)
- shaders: updated all shaders to use texture() instead of texture2D()
(helps AMD cards)
The "Display Emulation" option works like this: when selected, it tries
to load "<path>/Video Shaders/Emulation/<systemName>.shader/"; otherwise
it falls back to the blur shader. <path> is the usual (next to binary,
then in <config>/higan, then in /usr/share/higan, etc); and <systemName>
is "Famicom", "Super Famicom", "Game Boy", "Game Boy Color", "Game Boy
Advance"
To support BSD, I had to modify the $(platform) variable to
differentiate between Linux and BSD.
As such, the new $(platform) values are:
win -> windows
osx -> macosx
x -> linux or bsd
I am also checking uname -s instead of uname -a now. No reason to
potentially match the hostname to the wrong OS type.
2013-10-21 11:45:39 +00:00
|
|
|
if(node->type == Node::Type::Literal) {
|
2013-12-03 10:01:59 +00:00
|
|
|
if(node->literal.beginsWith("0b")) return nall::binary(node->literal);
|
|
|
|
if(node->literal.beginsWith("0o")) return nall::octal(node->literal);
|
|
|
|
if(node->literal.beginsWith("0x")) return nall::hex(node->literal);
|
|
|
|
if(node->literal.beginsWith("%")) return nall::binary(node->literal);
|
|
|
|
if(node->literal.beginsWith("$")) return nall::hex(node->literal);
|
Update to v093r01 release.
byuu says:
Changelog:
- added SA-1 MDR; fixes bug in SD Gundam G-Next where the main
battleship was unable to fire
- added out-of-the-box support for any BSD running Clang 3.3+ (FreeBSD
10+, notably)
- added new video shader, "Display Emulation", which changes the shader
based on the emulated system
- fixed the home button to go to your default library path
- phoenix: Windows port won't send onActivate unless an item is selected
(prevents crashing on pressing enter in file dialog)
- ruby: removed vec4 position from out Vertex {} (helps AMD cards)
- shaders: updated all shaders to use texture() instead of texture2D()
(helps AMD cards)
The "Display Emulation" option works like this: when selected, it tries
to load "<path>/Video Shaders/Emulation/<systemName>.shader/"; otherwise
it falls back to the blur shader. <path> is the usual (next to binary,
then in <config>/higan, then in /usr/share/higan, etc); and <systemName>
is "Famicom", "Super Famicom", "Game Boy", "Game Boy Color", "Game Boy
Advance"
To support BSD, I had to modify the $(platform) variable to
differentiate between Linux and BSD.
As such, the new $(platform) values are:
win -> windows
osx -> macosx
x -> linux or bsd
I am also checking uname -s instead of uname -a now. No reason to
potentially match the hostname to the wrong OS type.
2013-10-21 11:45:39 +00:00
|
|
|
return nall::integer(node->literal);
|
|
|
|
}
|
2013-07-29 09:42:45 +00:00
|
|
|
|
|
|
|
#define p(n) evaluateInteger(node->link[n])
|
|
|
|
switch(node->type) {
|
|
|
|
case Node::Type::SuffixIncrement: return p(0);
|
|
|
|
case Node::Type::SuffixDecrement: return p(0);
|
|
|
|
case Node::Type::LogicalNot: return !p(0);
|
|
|
|
case Node::Type::BitwiseNot: return ~p(0);
|
|
|
|
case Node::Type::Positive: return +p(0);
|
|
|
|
case Node::Type::Negative: return -p(0);
|
|
|
|
case Node::Type::PrefixIncrement: return p(0) + 1;
|
|
|
|
case Node::Type::PrefixDecrement: return p(0) - 1;
|
|
|
|
case Node::Type::Multiply: return p(0) * p(1);
|
|
|
|
case Node::Type::Divide: return p(0) / p(1);
|
|
|
|
case Node::Type::Modulo: return p(0) % p(1);
|
|
|
|
case Node::Type::Add: return p(0) + p(1);
|
|
|
|
case Node::Type::Subtract: return p(0) - p(1);
|
|
|
|
case Node::Type::ShiftLeft: return p(0) << p(1);
|
|
|
|
case Node::Type::ShiftRight: return p(0) >> p(1);
|
|
|
|
case Node::Type::BitwiseAnd: return p(0) & p(1);
|
|
|
|
case Node::Type::BitwiseOr: return p(0) | p(1);
|
|
|
|
case Node::Type::BitwiseXor: return p(0) ^ p(1);
|
|
|
|
case Node::Type::Equal: return p(0) == p(1);
|
|
|
|
case Node::Type::NotEqual: return p(0) != p(1);
|
|
|
|
case Node::Type::LessThanEqual: return p(0) <= p(1);
|
|
|
|
case Node::Type::GreaterThanEqual: return p(0) >= p(1);
|
|
|
|
case Node::Type::LessThan: return p(0) < p(1);
|
|
|
|
case Node::Type::GreaterThan: return p(0) > p(1);
|
|
|
|
case Node::Type::LogicalAnd: return p(0) && p(1);
|
|
|
|
case Node::Type::LogicalOr: return p(0) || p(1);
|
|
|
|
case Node::Type::Condition: return p(0) ? p(1) : p(2);
|
|
|
|
case Node::Type::Assign: return p(1);
|
|
|
|
case Node::Type::AssignMultiply: return p(0) * p(1);
|
|
|
|
case Node::Type::AssignDivide: return p(0) / p(1);
|
|
|
|
case Node::Type::AssignModulo: return p(0) % p(1);
|
|
|
|
case Node::Type::AssignAdd: return p(0) + p(1);
|
|
|
|
case Node::Type::AssignSubtract: return p(0) - p(1);
|
|
|
|
case Node::Type::AssignShiftLeft: return p(0) << p(1);
|
|
|
|
case Node::Type::AssignShiftRight: return p(0) >> p(1);
|
|
|
|
case Node::Type::AssignBitwiseAnd: return p(0) & p(1);
|
|
|
|
case Node::Type::AssignBitwiseOr: return p(0) | p(1);
|
|
|
|
case Node::Type::AssignBitwiseXor: return p(0) ^ p(1);
|
|
|
|
}
|
|
|
|
#undef p
|
|
|
|
|
|
|
|
throw "invalid operator";
|
|
|
|
}
|
|
|
|
|
2014-02-09 05:59:46 +00:00
|
|
|
inline maybe<int64_t> integer(const string& expression) {
|
2013-07-29 09:42:45 +00:00
|
|
|
try {
|
|
|
|
auto tree = new Node;
|
|
|
|
const char* p = expression;
|
|
|
|
parse(tree, p, 0);
|
|
|
|
auto result = evaluateInteger(tree);
|
|
|
|
delete tree;
|
2014-02-09 05:59:46 +00:00
|
|
|
return result;
|
2013-07-29 09:42:45 +00:00
|
|
|
} catch(const char*) {
|
2014-02-09 05:59:46 +00:00
|
|
|
return nothing;
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline long double evaluateReal(Node* node) {
|
|
|
|
if(node->type == Node::Type::Literal) return nall::real(node->literal);
|
|
|
|
|
|
|
|
#define p(n) evaluateReal(node->link[n])
|
|
|
|
switch(node->type) {
|
|
|
|
case Node::Type::LogicalNot: return !p(0);
|
|
|
|
case Node::Type::Positive: return +p(0);
|
|
|
|
case Node::Type::Negative: return -p(0);
|
|
|
|
case Node::Type::Multiply: return p(0) * p(1);
|
|
|
|
case Node::Type::Divide: return p(0) / p(1);
|
|
|
|
case Node::Type::Add: return p(0) + p(1);
|
|
|
|
case Node::Type::Subtract: return p(0) - p(1);
|
|
|
|
case Node::Type::Equal: return p(0) == p(1);
|
|
|
|
case Node::Type::NotEqual: return p(0) != p(1);
|
|
|
|
case Node::Type::LessThanEqual: return p(0) <= p(1);
|
|
|
|
case Node::Type::GreaterThanEqual: return p(0) >= p(1);
|
|
|
|
case Node::Type::LessThan: return p(0) < p(1);
|
|
|
|
case Node::Type::GreaterThan: return p(0) > p(1);
|
|
|
|
case Node::Type::LogicalAnd: return p(0) && p(1);
|
|
|
|
case Node::Type::LogicalOr: return p(0) || p(1);
|
|
|
|
case Node::Type::Condition: return p(0) ? p(1) : p(2);
|
|
|
|
case Node::Type::Assign: return p(1);
|
|
|
|
case Node::Type::AssignMultiply: return p(0) * p(1);
|
|
|
|
case Node::Type::AssignDivide: return p(0) / p(1);
|
|
|
|
case Node::Type::AssignAdd: return p(0) + p(1);
|
|
|
|
case Node::Type::AssignSubtract: return p(0) - p(1);
|
|
|
|
}
|
|
|
|
#undef p
|
|
|
|
|
|
|
|
throw "invalid operator";
|
|
|
|
}
|
|
|
|
|
2014-02-09 05:59:46 +00:00
|
|
|
inline maybe<long double> real(const string& expression) {
|
2013-07-29 09:42:45 +00:00
|
|
|
try {
|
|
|
|
auto tree = new Node;
|
|
|
|
const char* p = expression;
|
|
|
|
parse(tree, p, 0);
|
|
|
|
auto result = evaluateReal(tree);
|
|
|
|
delete tree;
|
2014-02-09 05:59:46 +00:00
|
|
|
return result;
|
2013-07-29 09:42:45 +00:00
|
|
|
} catch(const char*) {
|
2014-02-09 05:59:46 +00:00
|
|
|
return nothing;
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|