Skip to content

Commit

Permalink
Working on an elusive evaluation bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Leung committed Sep 26, 2012
1 parent 4c08606 commit 0917520
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
11 changes: 11 additions & 0 deletions environment.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ namespace Sass {
else if (parent) return (*parent)[key]; else if (parent) return (*parent)[key];
else return current_frame[key]; else return current_frame[key];
} }

void print()
{
for (map<Token, Node>::iterator i = current_frame.begin(); i != current_frame.end(); ++i) {
cerr << i->first.to_string() << ": " << i->second.to_string() << endl;
}
if (parent) {
cerr << "---" << endl;
parent->print();
}
}
}; };
} }
22 changes: 22 additions & 0 deletions eval_apply.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ namespace Sass {


case Node::variable: { case Node::variable: {
if (!env.query(expr.token())) throw_eval_error("reference to unbound variable " + expr.token().to_string(), expr.path(), expr.line()); if (!env.query(expr.token())) throw_eval_error("reference to unbound variable " + expr.token().to_string(), expr.path(), expr.line());

cerr << "ACCESSING VARIABLE " << expr.token().to_string() << endl;

cerr << endl << "*** ENV DUMP ***" << endl;
env.print();
cerr << "*** END ENV ***" << endl << endl;


return env[expr.token()]; return env[expr.token()];
} break; } break;


Expand Down Expand Up @@ -454,6 +462,7 @@ namespace Sass {


case Node::warning: { case Node::warning: {
expr[0] = eval(expr[0], prefix, env, f_env, new_Node, ctx); expr[0] = eval(expr[0], prefix, env, f_env, new_Node, ctx);
cerr << "WARNING:" << expr.path() << ":" << expr.line() << " -- " << expr[0].to_string() << endl;
return expr; return expr;
} break; } break;


Expand Down Expand Up @@ -759,10 +768,14 @@ namespace Sass {
val = eval(val, Node(), bindings, ctx.function_env, new_Node, ctx); val = eval(val, Node(), bindings, ctx.function_env, new_Node, ctx);
} }
Node var(stm[0]); Node var(stm[0]);
// cerr << "ASSIGNMENT IN FUNCTION: " << var.to_string() << ": " << val.to_string() << endl;
if (stm.is_guarded() && bindings.query(var.token())) continue; if (stm.is_guarded() && bindings.query(var.token())) continue;
// If a binding exists (possibly upframe), then update it. // If a binding exists (possibly upframe), then update it.
// Otherwise, make a new one in the current frame. // Otherwise, make a new one in the current frame.
if (bindings.query(var.token())) { if (bindings.query(var.token())) {
cerr << "MODIFYING EXISTING BINDING FOR " << var.token().to_string() << endl;
cerr << "CURRENT VALUE: " << bindings[var.token()].to_string() << endl;
cerr << "NEW VALUE: " << val.to_string() << endl;
bindings[var.token()] = val; bindings[var.token()] = val;
} }
else { else {
Expand Down Expand Up @@ -818,7 +831,11 @@ namespace Sass {
each_env.link(bindings); each_env.link(bindings);
for (size_t j = 0, T = list.size(); j < T; ++j) { for (size_t j = 0, T = list.size(); j < T; ++j) {
each_env.current_frame[iter_var.token()] = eval(list[j], Node(), bindings, ctx.function_env, new_Node, ctx); each_env.current_frame[iter_var.token()] = eval(list[j], Node(), bindings, ctx.function_env, new_Node, ctx);
cerr << "EACH with " << iter_var.token().to_string() << ": " << each_env[iter_var.token()].to_string() << endl;
Node v(function_eval(name, each_body, each_env, new_Node, ctx)); Node v(function_eval(name, each_body, each_env, new_Node, ctx));
// cerr << endl << "*** ENV DUMP ***" << endl;
// each_env.print();
// cerr << "*** END ENV ***" << endl << endl;
if (v.is_null_ptr()) continue; if (v.is_null_ptr()) continue;
else return v; else return v;
} }
Expand All @@ -840,6 +857,11 @@ namespace Sass {
} }
} break; } break;


case Node::warning: {
stm[0] = eval(stm[0], Node(), bindings, ctx.function_env, new_Node, ctx);
cerr << "WARNING:" << stm.path() << ":" << stm.line() << " -- " << stm[0].to_string() << endl;
} break;

case Node::return_directive: { case Node::return_directive: {
Node retval(eval(stm[0], Node(), bindings, ctx.function_env, new_Node, ctx)); Node retval(eval(stm[0], Node(), bindings, ctx.function_env, new_Node, ctx));
if (retval.type() == Node::comma_list || retval.type() == Node::space_list) { if (retval.type() == Node::comma_list || retval.type() == Node::space_list) {
Expand Down
22 changes: 11 additions & 11 deletions node_emitters.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -368,17 +368,17 @@ namespace Sass {
} break; } break;


case warning: { case warning: {
string prefix("WARNING: "); // string prefix("WARNING: ");
string indent(" "); // string indent(" ");
Node contents(at(0)); // Node contents(at(0));
string result(contents.to_string()); // string result(contents.to_string());
if (contents.type() == string_constant || contents.type() == string_schema) { // if (contents.type() == string_constant || contents.type() == string_schema) {
result = result.substr(1, result.size()-2); // unquote if it's a single string // result = result.substr(1, result.size()-2); // unquote if it's a single string
} // }
// These cerrs aren't log lines! They're supposed to be here! // // These cerrs aren't log lines! They're supposed to be here!
cerr << prefix << result << endl; // cerr << prefix << result << endl;
cerr << indent << "on line " << at(0).line() << " of " << at(0).path(); // cerr << indent << "on line " << at(0).line() << " of " << at(0).path();
cerr << endl << endl; // cerr << endl << endl;
return ""; return "";
} break; } break;


Expand Down

0 comments on commit 0917520

Please sign in to comment.