source: webkit/trunk/JavaScriptCore/kjs/internal.h@ 27695

Last change on this file since 27695 was 27695, checked in by eseidel, 18 years ago

2007-11-10 Eric Seidel <[email protected]>

Reviewed by darin.

Add simple type inferencing to the parser, and create custom
AddNode and LessNode subclasses based on inferred types.
http://bugs.webkit.org/show_bug.cgi?id=15884

SunSpider claims this is at least a 0.5% speedup.

  • JavaScriptCore.exp:
  • kjs/grammar.y:
  • kjs/internal.cpp: (KJS::NumberImp::getPrimitiveNumber): (KJS::GetterSetterImp::getPrimitiveNumber):
  • kjs/internal.h:
  • kjs/lexer.cpp: (KJS::Lexer::lex):
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::StringNode::evaluate): (KJS::StringNode::evaluateToNumber): (KJS::StringNode::evaluateToBoolean): (KJS::RegExpNode::evaluate): (KJS::UnaryPlusNode::optimizeVariableAccess): (KJS::AddNode::evaluate): (KJS::AddNode::evaluateToNumber): (KJS::AddNumbersNode::inlineEvaluateToNumber): (KJS::AddNumbersNode::evaluate): (KJS::AddNumbersNode::evaluateToNumber): (KJS::AddStringsNode::evaluate): (KJS::AddStringLeftNode::evaluate): (KJS::AddStringRightNode::evaluate): (KJS::lessThan): (KJS::lessThanEq): (KJS::LessNumbersNode::evaluate): (KJS::LessStringsNode::evaluate):
  • kjs/nodes.h: (KJS::ExpressionNode::): (KJS::RegExpNode::): (KJS::RegExpNode::precedence): (KJS::TypeOfResolveNode::): (KJS::LocalVarTypeOfNode::): (KJS::UnaryPlusNode::): (KJS::UnaryPlusNode::precedence): (KJS::AddNode::): (KJS::AddNode::precedence): (KJS::AddNumbersNode::): (KJS::AddStringLeftNode::): (KJS::AddStringRightNode::): (KJS::AddStringsNode::): (KJS::LessNode::): (KJS::LessNode::precedence): (KJS::LessNumbersNode::): (KJS::LessStringsNode::):
  • kjs/nodes2string.cpp: (KJS::StringNode::streamTo):
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/value.h: (KJS::JSValue::getPrimitiveNumber):
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2001 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef INTERNAL_H
25#define INTERNAL_H
26
27#include "JSType.h"
28#include "interpreter.h"
29#include "object.h"
30#include "protect.h"
31#include "scope_chain.h"
32#include "types.h"
33#include "ustring.h"
34
35#include <wtf/Noncopyable.h>
36
37#define I18N_NOOP(s) s
38
39namespace KJS {
40
41 class FunctionPrototype;
42
43 // ---------------------------------------------------------------------------
44 // Primitive impls
45 // ---------------------------------------------------------------------------
46
47 class StringImp : public JSCell {
48 public:
49 StringImp(const UString& v) : val(v) { Collector::reportExtraMemoryCost(v.cost()); }
50 enum HasOtherOwnerType { HasOtherOwner };
51 StringImp(const UString& value, HasOtherOwnerType) : val(value) { }
52 const UString& value() const { return val; }
53
54 private:
55 virtual JSType type() const { return StringType; }
56
57 virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
58 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
59 virtual bool toBoolean(ExecState *exec) const;
60 virtual double toNumber(ExecState *exec) const;
61 virtual JSObject *toObject(ExecState *exec) const;
62 virtual UString toString(ExecState*) const;
63
64 UString val;
65 };
66
67 class NumberImp : public JSCell {
68 friend class ConstantValues;
69 friend JSValue *jsNumberCell(double);
70 public:
71 double value() const { return val; }
72
73 virtual JSType type() const { return NumberType; }
74
75 virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
76 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
77 virtual bool toBoolean(ExecState *exec) const;
78 virtual double toNumber(ExecState *exec) const;
79 virtual UString toString(ExecState *exec) const;
80 virtual JSObject *toObject(ExecState *exec) const;
81
82 void* operator new(size_t size)
83 {
84 return Collector::allocateNumber(size);
85 }
86 private:
87 NumberImp(double v) : val(v) { }
88
89 virtual bool getUInt32(uint32_t&) const;
90 virtual bool getTruncatedInt32(int32_t&) const;
91 virtual bool getTruncatedUInt32(uint32_t&) const;
92
93 double val;
94 };
95
96
97 // ---------------------------------------------------------------------------
98 // Evaluation
99 // ---------------------------------------------------------------------------
100
101 struct AttachedInterpreter;
102 class DebuggerImp {
103 public:
104
105 DebuggerImp() {
106 interps = 0;
107 isAborted = false;
108 }
109
110 void abort() { isAborted = true; }
111 bool aborted() const { return isAborted; }
112
113 AttachedInterpreter *interps;
114 bool isAborted;
115 };
116
117#ifndef NDEBUG
118 void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);
119#endif
120
121} // namespace
122
123#endif // INTERNAL_H
Note: See TracBrowser for help on using the repository browser.