2007-10-24 Eric Seidel <eric@webkit.org>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 08:06:03 +0000 (08:06 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 08:06:03 +0000 (08:06 +0000)
        Reviewed by darin.

        Add ImmediateNumberNode to hold a JSValue* instead of a double for numbers
        which can be represented by JSImmediate.

        * kjs/grammar.y:
        * kjs/nodes.cpp:
        (KJS::NumberNode::evaluate):
        (KJS::ImmediateNumberNode::evaluate):
        * kjs/nodes.h:
        (KJS::Node::):
        (KJS::ImmediateNumberNode::):
        * kjs/nodes2string.cpp:
        (ImmediateNumberNode::streamTo):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@26957 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h
JavaScriptCore/kjs/nodes2string.cpp

index a81628d7ec705e48db874fb8fa7d470411d3e982..9a85ef44ef590419c370f1a398d4c1d37d0a2e83 100644 (file)
@@ -1,3 +1,20 @@
+2007-10-24  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by darin.
+        
+        Add ImmediateNumberNode to hold a JSValue* instead of a double for numbers
+        which can be represented by JSImmediate.
+
+        * kjs/grammar.y:
+        * kjs/nodes.cpp:
+        (KJS::NumberNode::evaluate):
+        (KJS::ImmediateNumberNode::evaluate):
+        * kjs/nodes.h:
+        (KJS::Node::):
+        (KJS::ImmediateNumberNode::):
+        * kjs/nodes2string.cpp:
+        (ImmediateNumberNode::streamTo):
+
 2007-10-24  Darin Adler  <darin@apple.com>
 
         Reviewed by Maciej.
index fa0011ca0fde3282f1b661eadc1fd4dd5b4e4bc6..5970f925905207c3d012bb8abc6726e7de5142d0 100644 (file)
@@ -65,6 +65,7 @@ static Node *makeFunctionCallNode(Node *func, ArgumentsNode *args);
 static Node *makeTypeOfNode(Node *expr);
 static Node *makeDeleteNode(Node *expr);
 static Node *makeNegateNode(Node *expr);
+static Node* makeNumberNode(double);
 
 #if COMPILER(MSVC)
 
@@ -210,7 +211,7 @@ Literal:
     NULLTOKEN                           { $$ = new NullNode(); }
   | TRUETOKEN                           { $$ = new BooleanNode(true); }
   | FALSETOKEN                          { $$ = new BooleanNode(false); }
-  | NUMBER                              { $$ = new NumberNode($1); }
+  | NUMBER                              { $$ = makeNumberNode($1); }
   | STRING                              { $$ = new StringNode($1); }
   | '/' /* regexp */                    {
                                             Lexer *l = Lexer::curr();
@@ -1014,11 +1015,26 @@ static Node* makeNegateNode(Node *n)
             number->setValue(-number->value());
             return number;
         }
+    } else if (n->isImmediateValue()) {
+        ImmediateNumberNode* number = static_cast<ImmediateNumberNode*>(n);
+        double value = number->value();
+        if (value > 0.0) {
+            number->setValue(-value);
+            return number;
+        }
     }
 
     return new NegateNode(n);
 }
 
+static Node* makeNumberNode(double d)
+{
+    JSValue* value = JSImmediate::fromDouble(d);
+    if (value)
+        return new ImmediateNumberNode(value);
+    return new NumberNode(d);
+}
+
 /* called by yyparse on error */
 int yyerror(const char *)
 {
index 16549488f2c03327edf84413810ee0fc3b0e9161..f12405dd6e34bd1652b65c144cb1d273b9513e05 100644 (file)
@@ -347,7 +347,13 @@ JSValue *BooleanNode::evaluate(ExecState *)
 
 JSValue *NumberNode::evaluate(ExecState *)
 {
-  return jsNumber(val);
+    // Number nodes are only created when the number can't fit in a JSImmediate, so no need to check again.
+    return jsNumberCell(val);
+}
+
+JSValue* ImmediateNumberNode::evaluate(ExecState*)
+{
+    return m_value;
 }
 
 // ------------------------------ StringNode -----------------------------------
index ad3fa45436ad3a508344250d4abdfd1c96eaef55..7fa32e1bc120a226d893c55706d7fcf57e851193 100644 (file)
@@ -117,6 +117,7 @@ namespace KJS {
     virtual Node *nodeInsideAllParens() KJS_FAST_CALL;
 
     virtual bool isNumber() const KJS_FAST_CALL { return false; }
+    virtual bool isImmediateValue() const KJS_FAST_CALL { return false; }
     virtual bool isLocation() const KJS_FAST_CALL { return false; }
     virtual bool isResolveNode() const KJS_FAST_CALL { return false; }
     virtual bool isBracketAccessorNode() const KJS_FAST_CALL { return false; }
@@ -200,6 +201,19 @@ namespace KJS {
   private:
     double val;
   };
+  
+  class ImmediateNumberNode : public Node {
+  public:
+      ImmediateNumberNode(JSValue* v) KJS_FAST_CALL : m_value(v) {}
+      JSValue* evaluate(ExecState*) KJS_FAST_CALL;
+      virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
+      
+      virtual bool isImmediateValue() const KJS_FAST_CALL { return true; }
+      double value() const KJS_FAST_CALL { return JSImmediate::toDouble(m_value); }
+      void setValue(double v) KJS_FAST_CALL { m_value = JSImmediate::fromDouble(v); ASSERT(m_value == v); } 
+  private:
+      JSValue* m_value;
+  };
 
   class StringNode : public Node {
   public:
index 5465e458cecedeeaabe5d7d6d0e6657ce03b415f..d1a728e1470f285c4c56b13babef84c6dab3e4dc 100644 (file)
@@ -142,6 +142,11 @@ void BooleanNode::streamTo(SourceStream &s) const
 
 void NumberNode::streamTo(SourceStream &s) const { s << val; }
 
+void ImmediateNumberNode::streamTo(SourceStream& s) const
+{
+    s << value();
+}
+
 void StringNode::streamTo(SourceStream &s) const
 {
   s << '"' << escapeStringForPrettyPrinting(value) << '"';