mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-26 04:24:45 +02:00
Update to v093 release.
byuu says: Changelog: - added Cocoa target: higan can now be compiled for OS X Lion [Cydrak, byuu] - SNES/accuracy profile hires color blending improvements - fixes Marvelous text [AWJ] - fixed a slight bug in SNES/SA-1 VBR support caused by a typo - added support for multi-pass shaders that can load external textures (requires OpenGL 3.2+) - added game library path (used by ananke->Import Game) to Settings->Advanced - system profiles, shaders and cheats database can be stored in "all users" shared folders now (eg /usr/share on Linux) - all configuration files are in BML format now, instead of XML (much easier to read and edit this way) - main window supports drag-and-drop of game folders (but not game files / ZIP archives) - audio buffer clears when entering a modal loop on Windows (prevents audio repetition with DirectSound driver) - a substantial amount of code clean-up (probably the biggest refactoring to date) One highly desired target for this release was to default to the optimal drivers instead of the safest drivers, but because AMD drivers don't seem to like my OpenGL 3.2 driver, I've decided to postpone that. AMD has too big a market share. Hopefully with v093 officially released, we can get some public input on what AMD doesn't like.
This commit is contained in:
150
nall/string/eval/evaluator.hpp
Normal file
150
nall/string/eval/evaluator.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#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), ", ");
|
||||
}
|
||||
return result.rtrim<1>(", ").append(")");
|
||||
}
|
||||
}
|
||||
#undef p
|
||||
|
||||
throw "invalid operator";
|
||||
}
|
||||
|
||||
inline int64_t evaluateInteger(Node* node) {
|
||||
if(node->type == Node::Type::Literal) return nall::integer(node->literal);
|
||||
|
||||
#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";
|
||||
}
|
||||
|
||||
inline optional<int64_t> integer(const string& expression) {
|
||||
try {
|
||||
auto tree = new Node;
|
||||
const char* p = expression;
|
||||
parse(tree, p, 0);
|
||||
auto result = evaluateInteger(tree);
|
||||
delete tree;
|
||||
return {true, result};
|
||||
} catch(const char*) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
inline optional<long double> real(const string& expression) {
|
||||
try {
|
||||
auto tree = new Node;
|
||||
const char* p = expression;
|
||||
parse(tree, p, 0);
|
||||
auto result = evaluateReal(tree);
|
||||
delete tree;
|
||||
return {true, result};
|
||||
} catch(const char*) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user