[pypy-svn] r55540 - in pypy/branch/js-refactoring/pypy/lang/js: . test test/ecma
santagada at codespeak.net
santagada at codespeak.net
Wed Jun 4 00:57:25 CEST 2008
Author: santagada
Date: Wed Jun 4 00:57:23 2008
New Revision: 55540
Modified:
pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
pypy/branch/js-refactoring/pypy/lang/js/jscode.py
pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
pypy/branch/js-refactoring/pypy/lang/js/operations.py
pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
pypy/branch/js-refactoring/pypy/lang/js/test/ecma/shell.js
pypy/branch/js-refactoring/pypy/lang/js/test/test_astbuilder.py
Log:
added Boolean to passing tests, and some translation fixes
Modified: pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py Wed Jun 4 00:57:23 2008
@@ -1,4 +1,4 @@
-from pypy.rlib.rarithmetic import intmask, ovfcheck
+from pypy.rlib.rarithmetic import intmask, ovfcheck, ovfcheck_float_to_int
from pypy.rlib.parsing.tree import RPythonVisitor, Symbol, Nonterminal
from pypy.lang.js import operations
from pypy.rlib.parsing.parsing import ParseError
@@ -87,10 +87,15 @@
def visit_DECIMALLITERAL(self, node):
pos = self.get_pos(node)
try:
- ovfcheck(int(node.additional_info))
+
+ f = float(node.additional_info)
+ i = ovfcheck_float_to_int(f)
+ if i != f:
+ return operations.FloatNumber(pos, f)
+ else:
+ return operations.IntNumber(pos, i)
except (ValueError, OverflowError):
return operations.FloatNumber(pos, float(node.additional_info))
- return operations.IntNumber(pos, intmask(node.additional_info))
def visit_HEXINTEGERLITERAL(self, node):
pos = self.get_pos(node)
@@ -347,7 +352,8 @@
visit_assignmentexpressionnoin = visit_assignmentexpression
def visit_emptystatement(self, node):
- pass
+ pos = self.get_pos(node)
+ return operations.Empty(pos)
def visit_newexpression(self, node):
if len(node.children) == 1:
Modified: pypy/branch/js-refactoring/pypy/lang/js/jscode.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jscode.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jscode.py Wed Jun 4 00:57:23 2008
@@ -10,6 +10,7 @@
compare_e, increment, commonnew, mult, division, uminus, mod
from pypy.rlib.jit import hint
from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.objectmodel import we_are_translated
class AlreadyRun(Exception):
pass
@@ -25,13 +26,21 @@
to_pop = 0
try:
while i < len(opcodes):
- for name, op in opcode_unrolling:
- opcode = opcodes[i]
- opcode = hint(opcode, deepfreeze=True)
- if isinstance(opcode, op):
- result = opcode.eval(ctx, stack)
- assert result is None
- break
+ opcode = opcodes[i]
+ if we_are_translated():
+ #this is an optimization strategy for translated code
+ #on top of cpython it destroys the performance
+ #besides, this code might be completely wrong
+ for name, op in opcode_unrolling:
+ opcode = hint(opcode, deepfreeze=True)
+ if isinstance(opcode, op):
+ result = opcode.eval(ctx, stack)
+ assert result is None
+ break
+ else:
+ result = opcode.eval(ctx, stack)
+ assert result is None
+
if isinstance(opcode, BaseJump):
i = opcode.do_jump(stack, i)
else:
@@ -73,7 +82,10 @@
self.opcodes = []
self.label_count = 0
self.has_labels = True
- self.stack = T()
+ if we_are_translated():
+ self.stack = []
+ else:
+ self.stack = T()
self.startlooplabel = []
self.endlooplabel = []
@@ -105,7 +117,7 @@
def emit_break(self):
if not self.endlooplabel:
- raise ThrowError(W_String("Break outside loop"))
+ raise ThrowException(W_String("Break outside loop"))
self.emit('JUMP', self.endlooplabel[-1])
def emit_continue(self):
@@ -487,7 +499,7 @@
return
if isinstance(stack[-1], W_FloatNumber):
return
- stack.append(stack.pop().ToNumber(ctx))
+ stack.append(W_FloatNumber(stack.pop().ToNumber(ctx)))
class UMINUS(BaseUnaryOperation):
def eval(self, ctx, stack):
Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py Wed Jun 4 00:57:23 2008
@@ -30,7 +30,7 @@
# return self
def ToBoolean(self, ctx):
- raise NotImplementedError()
+ raise NotImplementedError(self.__class__)
def ToPrimitive(self, ctx, hint=""):
return self
@@ -52,25 +52,25 @@
return r_uint(0)
def Get(self, ctx, P):
- raise NotImplementedError()
+ raise NotImplementedError(self.__class__)
def Put(self, ctx, P, V, flags = 0):
- raise NotImplementedError()
+ raise NotImplementedError(self.__class__)
def PutValue(self, w, ctx):
pass
def Call(self, ctx, args=[], this=None):
- raise NotImplementedError()
+ raise NotImplementedError(self.__class__)
def __str__(self):
return self.ToString(ctx=None)
def type(self):
- raise NotImplementedError
+ raise NotImplementedError(self.__class__)
def GetPropertyName(self):
- raise NotImplementedError
+ raise NotImplementedError(self.__class__)
class W_Undefined(W_Root):
def __str__(self):
Modified: pypy/branch/js-refactoring/pypy/lang/js/operations.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/operations.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/operations.py Wed Jun 4 00:57:23 2008
@@ -124,6 +124,8 @@
addoper = OPERANDS[self.operand]
if addoper:
addoper = '_' + self.prefix.upper() + addoper
+ else:
+ addoper = ''
return addoper
OPERANDS = {
@@ -454,6 +456,8 @@
what = self.what
if isinstance(what, Identifier):
bytecode.emit('DELETE', what.name)
+ elif isinstance(what, VariableIdentifier):
+ bytecode.emit('DELETE', what.identifier)
elif isinstance(what, MemberDot):
what.left.emit(bytecode)
# XXX optimize
@@ -668,8 +672,6 @@
if self.expr is not None:
self.expr.emit(bytecode)
bytecode.emit('STORE', self.identifier)
- else:
- return True
class VariableIdentifier(Expression):
def __init__(self, pos, depth, identifier):
@@ -690,7 +692,8 @@
def emit(self, bytecode):
for node in self.nodes:
- if node.emit(bytecode) is None:
+ node.emit(bytecode)
+ if isinstance(node, VariableDeclaration) and node.expr is not None:
bytecode.emit('POP')
class Variable(Statement):
@@ -701,6 +704,13 @@
def emit(self, bytecode):
self.body.emit(bytecode)
+class Empty(Expression):
+ def __init__(self, pos):
+ self.pos = pos
+
+ def emit(self, bytecode):
+ pass
+
class Void(Expression):
def __init__(self, pos, expr):
self.pos = pos
Modified: pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py Wed Jun 4 00:57:23 2008
@@ -18,7 +18,7 @@
except JsBaseExcept:
return W_String("error")
-passing_tests = ['Number']
+passing_tests = ['Number', 'Boolean']
class JSDirectory(py.test.collect.Directory):
Modified: pypy/branch/js-refactoring/pypy/lang/js/test/ecma/shell.js
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/ecma/shell.js (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/ecma/shell.js Wed Jun 4 00:57:23 2008
@@ -223,6 +223,11 @@
}
/* end of print functions */
+var TIME_1970 = 0;
+var TIME_2000 = 946684800000;
+var TIME_1900 = -2208988800000;
+var TIME_YEAR_0 = -62167219200000;
+
/*
* When running in the shell, run the garbage collector after the
Modified: pypy/branch/js-refactoring/pypy/lang/js/test/test_astbuilder.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/test_astbuilder.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/test_astbuilder.py Wed Jun 4 00:57:23 2008
@@ -37,3 +37,6 @@
def test_sourcename():
p = to_ast('x()()').body
assert p.sourcename == 'test'
+
+def test_empty():
+ p = to_ast(';')
More information about the Pypy-commit
mailing list