Commit ffbdc730 authored by Boxiang Sun's avatar Boxiang Sun

do not compile code, return None directly

parent a21f7511
...@@ -56,40 +56,42 @@ class RestrictionCapableEval: ...@@ -56,40 +56,42 @@ class RestrictionCapableEval:
if PROFILE: if PROFILE:
from time import clock from time import clock
start = clock() start = clock()
co, err, warn, used = compile_restricted_eval( # Pyston change: do nothing
self.expr, '<string>') # co, err, warn, used = compile_restricted_eval(
if PROFILE: # self.expr, '<string>')
end = clock() # if PROFILE:
print 'prepRestrictedCode: %d ms for %s' % ( # end = clock()
(end - start) * 1000, `self.expr`) # print 'prepRestrictedCode: %d ms for %s' % (
if err: # (end - start) * 1000, `self.expr`)
raise SyntaxError, err[0] # if err:
self.used = tuple(used.keys()) # raise SyntaxError, err[0]
self.rcode = co # self.used = tuple(used.keys())
# self.rcode = co
def prepUnrestrictedCode(self): def prepUnrestrictedCode(self):
if self.ucode is None: if self.ucode is None:
# Use the standard compiler. # Use the standard compiler.
co = compile(self.expr, '<string>', 'eval') co = compile(self.expr, '<string>', 'eval')
if self.used is None: # Pyston change: return code directly
# Examine the code object, discovering which names # if self.used is None:
# the expression needs. # # Examine the code object, discovering which names
names=list(co.co_names) # # the expression needs.
used={} # names=list(co.co_names)
i=0 # used={}
code=co.co_code # i=0
l=len(code) # code=co.co_code
LOAD_NAME=101 # l=len(code)
HAVE_ARGUMENT=90 # LOAD_NAME=101
while(i < l): # HAVE_ARGUMENT=90
c=ord(code[i]) # while(i < l):
if c==LOAD_NAME: # c=ord(code[i])
name=names[ord(code[i+1])+256*ord(code[i+2])] # if c==LOAD_NAME:
used[name]=1 # name=names[ord(code[i+1])+256*ord(code[i+2])]
i=i+3 # used[name]=1
elif c >= HAVE_ARGUMENT: i=i+3 # i=i+3
else: i=i+1 # elif c >= HAVE_ARGUMENT: i=i+3
self.used=tuple(used.keys()) # else: i=i+1
# self.used=tuple(used.keys())
self.ucode=co self.ucode=co
def eval(self, mapping): def eval(self, mapping):
......
...@@ -101,7 +101,8 @@ def compile_restricted_eval(s, filename='<string>'): ...@@ -101,7 +101,8 @@ def compile_restricted_eval(s, filename='<string>'):
"""Compiles a restricted expression.""" """Compiles a restricted expression."""
# gen = RExpression(s, filename) # gen = RExpression(s, filename)
# return compileAndTuplize(gen) # return compileAndTuplize(gen)
return compile(s, filename, 'eval'), (), [], {} # return compile(s, filename, 'eval'), (), [], {}
return None
def compile_restricted(source, filename, mode): def compile_restricted(source, filename, mode):
"""Replacement for the builtin compile() function.""" """Replacement for the builtin compile() function."""
......
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