
--- Stargaming <stargaming@gmail.com> wrote:
? Specifically, how would python know what to dereference and what not to? What if there were two things, named the same, one in the row and one in the namespace? (i.e. a variable named 'salary')
That's a harder one, indeed. Perhaps, nothing should be dereferenced (at ``compile'' time, don't know if that's a valid term in CPython's interpreter chain tho), as it is in a lambda-expression.
Admitting to not fully understanding the Python innards, here's some food for thought on how this would be done: 1) Not to diminish the parsing-into-AST stage, I won't cover that here, as other problems are trickier. Despite pretty different semantics, I think rowexpr would look a lot like lambda at the syntactic level. 2) You'd add a case to compiler_visit_expr for Rowexpr_kind in compile.c. 3) There's a pretty small method in compile.c called compiler_lambda that would be the model for compiler_rowexpr. The compiler_rowexp would generate an opcode that caused the single (implied, C++-"this"-like) arg to be popped, and possibly that opcode would have to be different than a normal opcode to pop one argument off the stack, so that ceval.c can do the right thing, but I'm not so sure. 4) You might need to add something to compiler_unit that is analogous to u_varnames, u_cellvars, u_freevars, etc., so that when you recursively call down to evaluate the expression in the rowexpr, the lower methods know to look in a different place to scope the words "salary," "convert_to_euros," and "dept" in the example expression 'where convert_to_euros(salary) > 50000 an dept = "software development"'. 5) The behavior of compiler_expr would NOT change for most operators, such as Num_kind, Str_kind, Attribute_kind, Subscript_kind, etc., as rowexpr doesn't change how any of those are intrerpreted compared to an expression in other scopes. 6) Compiler_expr eventually gets to building opcodes that give you salary, convert_to_euros, and dept, and those pieces of code need to look into compiler_unit to determine if they're part of the rowexpr, and do the right thing. 7) I'm sure there's more. I'm here to learn. ____________________________________________________________________________________Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php