mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Optimize default arguments (@ operator) into script rules.
The plan is to deprecate rule form completely, so instead of replace_rule(match:..) write replace_text@(match: ...) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@987 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -9,9 +9,12 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <script/value.hpp>
|
||||
#include <script/to_value.hpp>
|
||||
#include <script/context.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <boost/pool/singleton_pool.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(pair<Variable COMMA ScriptValueP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ScriptValue
|
||||
// Base cases
|
||||
|
||||
@@ -29,6 +32,8 @@ CompareWhat ScriptValue::compareAs(String& compare_str, void const*& compare_pt
|
||||
return COMPARE_AS_STRING;
|
||||
}
|
||||
|
||||
ScriptValueP ScriptValue::simplifyClosure(ScriptClosure&) const { return ScriptValueP(); }
|
||||
|
||||
ScriptValueP ScriptValue::dependencyMember(const String& name, const Dependency&) const { return dependency_dummy; }
|
||||
ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; }
|
||||
|
||||
@@ -357,3 +362,50 @@ ScriptValueP ScriptConcatCollection::getMember(const String& name) const {
|
||||
ScriptValueP ScriptConcatCollection::makeIterator(const ScriptValueP& thisP) const {
|
||||
return new_intrusive2<ScriptConcatCollectionIterator>(a->makeIterator(a), b->makeIterator(b));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Default arguments / closure
|
||||
|
||||
ScriptType ScriptClosure::type() const {
|
||||
return SCRIPT_FUNCTION;
|
||||
}
|
||||
String ScriptClosure::typeName() const {
|
||||
return fun->typeName() + _(" closure");
|
||||
}
|
||||
|
||||
void ScriptClosure::addBinding(Variable v, const ScriptValueP& value) {
|
||||
bindings.push_back(make_pair(v,value));
|
||||
}
|
||||
ScriptValueP ScriptClosure::getBinding(Variable v) const {
|
||||
FOR_EACH_CONST(b, bindings) {
|
||||
if (b.first == v) return b.second;
|
||||
}
|
||||
return ScriptValueP();
|
||||
}
|
||||
|
||||
ScriptValueP ScriptClosure::simplify() {
|
||||
return fun->simplifyClosure(*this);
|
||||
}
|
||||
|
||||
ScriptValueP ScriptClosure::eval(Context& ctx) const {
|
||||
applyBindings(ctx);
|
||||
return fun->eval(ctx);
|
||||
}
|
||||
ScriptValueP ScriptClosure::dependencies(Context& ctx, const Dependency& dep) const {
|
||||
applyBindings(ctx);
|
||||
return fun->dependencies(ctx, dep);
|
||||
}
|
||||
void ScriptClosure::applyBindings(Context& ctx) const {
|
||||
FOR_EACH_CONST(b, bindings) {
|
||||
if (ctx.getVariableScope(b.first) != 0) {
|
||||
ctx.setVariable(b.first, b.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Destructing
|
||||
|
||||
void from_script(const ScriptValueP& value, wxRegEx& regex) {
|
||||
if (!regex.Compile(*value, wxRE_ADVANCED)) {
|
||||
throw ScriptError(_ERROR_2_("can't convert", value->typeName(), _TYPE_("regex")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user