[pypy-svn] r66423 - pypy/branch/parser-compiler/pypy/interpreter/astcompiler
benjamin at codespeak.net
benjamin at codespeak.net
Mon Jul 20 01:26:53 CEST 2009
Author: benjamin
Date: Mon Jul 20 01:26:53 2009
New Revision: 66423
Modified:
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
Log:
revert unintended changes
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py Mon Jul 20 01:26:53 2009
@@ -14,38 +14,38 @@
return TopLevelCodeGenerator(space, module, symbols, info).assemble()
-name_ops_default = misc.dict_to_switch({
+name_ops_default = {
ast.Load : ops.LOAD_NAME,
ast.Store : ops.STORE_NAME,
ast.Del : ops.DELETE_NAME
-})
+}
-name_ops_fast = misc.dict_to_switch({
+name_ops_fast = {
ast.Load : ops.LOAD_FAST,
ast.Store : ops.STORE_FAST,
ast.Del : ops.DELETE_FAST
-})
+}
-name_ops_deref = misc.dict_to_switch({
+name_ops_deref = {
ast.Load : ops.LOAD_DEREF,
ast.Store : ops.STORE_DEREF,
-})
+}
-name_ops_global = misc.dict_to_switch({
+name_ops_global = {
ast.Load : ops.LOAD_GLOBAL,
ast.Store : ops.STORE_GLOBAL,
ast.Del : ops.DELETE_GLOBAL
-})
+}
-unary_operations = misc.dict_to_switch({
+unary_operations = {
ast.Invert : ops.UNARY_INVERT,
ast.Not : ops.UNARY_NOT,
ast.UAdd : ops.UNARY_POSITIVE,
ast.USub : ops.UNARY_NEGATIVE
-})
+}
-binary_operations = misc.dict_to_switch({
+binary_operations = {
ast.Add : ops.BINARY_ADD,
ast.Sub : ops.BINARY_SUBTRACT,
ast.Mult : ops.BINARY_MULTIPLY,
@@ -57,9 +57,9 @@
ast.BitAnd : ops.BINARY_AND,
ast.BitXor : ops.BINARY_XOR,
ast.FloorDiv : ops.BINARY_FLOOR_DIVIDE
-})
+}
-inplace_operations = misc.dict_to_switch({
+inplace_operations = {
ast.Add : ops.INPLACE_ADD,
ast.Sub : ops.INPLACE_SUBTRACT,
ast.Mult : ops.INPLACE_MULTIPLY,
@@ -71,9 +71,9 @@
ast.BitAnd : ops.INPLACE_AND,
ast.BitXor : ops.INPLACE_XOR,
ast.FloorDiv : ops.INPLACE_FLOOR_DIVIDE
-})
+}
-compare_operations = misc.dict_to_switch({
+compare_operations = {
ast.Eq : 2,
ast.NotEq : 3,
ast.Lt : 0,
@@ -84,23 +84,23 @@
ast.NotIn : 7,
ast.Is : 8,
ast.IsNot : 9
-})
+}
-subscr_operations = misc.dict_to_switch({
+subscr_operations = {
ast.AugLoad : ops.BINARY_SUBSCR,
ast.Load : ops.BINARY_SUBSCR,
ast.AugStore : ops.STORE_SUBSCR,
ast.Store : ops.STORE_SUBSCR,
ast.Del : ops.DELETE_SUBSCR
-})
+}
-slice_operations = misc.dict_to_switch({
+slice_operations = {
ast.AugLoad : ops.SLICE,
ast.Load : ops.SLICE,
ast.AugStore : ops.STORE_SLICE,
ast.Store : ops.STORE_SLICE,
ast.Del : ops.DELETE_SLICE
-})
+}
F_BLOCK_LOOP = 0
@@ -168,7 +168,7 @@
elif scope == symtable.SCOPE_GLOBAL_EXPLICIT:
kind = name_ops_global
try:
- op = kind(ctx)
+ op = kind[ctx]
except KeyError:
if kind is name_ops_deref and ctx == ast.Del:
raise SyntaxError("Can't delete variable used in "
@@ -275,7 +275,7 @@
return ops.INPLACE_TRUE_DIVIDE
else:
return ops.INPLACE_DIVIDE
- return inplace_operations(op)
+ return inplace_operations[op]
def visit_AugAssign(self, assign):
self.update_position(assign.lineno)
@@ -325,7 +325,7 @@
return ops.BINARY_TRUE_DIVIDE
else:
return ops.BINARY_DIVIDE
- return binary_operations(op)
+ return binary_operations[op]
def visit_BinOp(self, binop):
self.update_position(binop.lineno)
@@ -716,7 +716,7 @@
def visit_UnaryOp(self, op):
self.update_position(op.lineno)
op.operand.walkabout(self)
- self.emit_op(unary_operations(op.op))
+ self.emit_op(unary_operations[op.op])
def visit_BoolOp(self, op):
self.update_position(op.lineno)
@@ -743,14 +743,14 @@
for i in range(1, ops_count):
self.emit_op(ops.DUP_TOP)
self.emit_op(ops.ROT_THREE)
- op_kind = compare_operations(comp.ops[i - 1])
+ op_kind = compare_operations[comp.ops[i - 1]]
self.emit_op_arg(ops.COMPARE_OP, op_kind)
self.emit_jump(ops.JUMP_IF_FALSE, cleanup)
self.emit_op(ops.POP_TOP)
if i < (ops_count - 1):
comp.comparators[i].walkabout(self)
comp.comparators[-1].walkabout(self)
- last_kind = compare_operations(comp.ops[-1])
+ last_kind = compare_operations[comp.ops[-1]]
self.emit_op_arg(ops.COMPARE_OP, last_kind)
if ops_count > 1:
end = self.new_block()
@@ -1047,7 +1047,7 @@
self.emit_op(ops.ROT_THREE)
elif stack_count == 2:
self.emit_op(ops.ROT_FOUR)
- self.emit_op(slice_operations(ctx) + slice_offset)
+ self.emit_op(slice_operations[ctx] + slice_offset)
def _complex_slice(self, slc, ctx):
if slc.lower:
@@ -1102,7 +1102,7 @@
self.emit_op_arg(ops.DUP_TOPX, 2)
elif ctx == ast.AugStore:
self.emit_op(ops.ROT_THREE)
- self.emit_op(subscr_operations(ctx))
+ self.emit_op(subscr_operations[ctx])
def visit_Subscript(self, sub):
self.update_position(sub.lineno)
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py Mon Jul 20 01:26:53 2009
@@ -1,7 +1,5 @@
from pypy.interpreter import gateway
from pypy.interpreter.astcompiler import ast2 as ast
-from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib.unroll import unrolling_iterable
app = gateway.applevel("""
@@ -40,21 +38,6 @@
return False
-def dict_to_switch(d):
- def lookup(query):
- if we_are_translated():
- for key, value in unrolling_iteritems:
- if key == query:
- return value
- else:
- raise KeyError
- else:
- return d[query]
- lookup._always_inline_ = True
- unrolling_iteritems = unrolling_iterable(d.iteritems())
- return lookup
-
-
def flatten(tup):
elts = []
for elt in tup:
More information about the Pypy-commit
mailing list