Commit 974822d7 by Aaron Leung

Environments now store a link to the global env. Makes it easy to handle 2-level…

Environments now store a link to the global env. Makes it easy to handle 2-level scope for mixins and arbitrarily nested scopes for variables.
parent d5440047
...@@ -6,17 +6,17 @@ namespace Sass { ...@@ -6,17 +6,17 @@ namespace Sass {
struct Environment { struct Environment {
map<Token, Node> current_frame; map<Token, Node> current_frame;
Environment* parent; Environment* parent;
Environment* global;
Environment() Environment()
: current_frame(map<Token, Node>()), parent(0) : current_frame(map<Token, Node>()), parent(0), global(0)
{ }
Environment(Environment* env)
: current_frame(map<Token, Node>()),
parent(env)
{ } { }
void link(Environment& env) void link(Environment& env)
{ parent = &env; } {
parent = &env;
global = parent->global ? parent->global : parent;
}
bool query(const Token& key) const bool query(const Token& key) const
{ {
......
...@@ -277,7 +277,7 @@ namespace Sass { ...@@ -277,7 +277,7 @@ namespace Sass {
} }
} }
// cerr << "BOUND DEFAULT ARGS FOR " << string(mixin[0].token) << endl; // cerr << "BOUND DEFAULT ARGS FOR " << string(mixin[0].token) << endl;
m_env.link(env.parent ? *env.parent : env); m_env.link(env.global ? *env.global : env);
// cerr << "LINKED ENVIRONMENT FOR " << string(mixin[0].token) << endl << endl; // cerr << "LINKED ENVIRONMENT FOR " << string(mixin[0].token) << endl << endl;
for (int i = 0; i < body.size(); ++i) { for (int i = 0; i < body.size(); ++i) {
body[i] = eval(body[i], m_env); body[i] = eval(body[i], m_env);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment