Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

introduce __pure__ attribute (for native functions, TODO: automatical…

…ly mark functions as pure)
  • Loading branch information...
commit 2c2ed87732c3f1468311a16b5e7526c69903500f 1 parent f073d4c
@kazuho kazuho authored
Showing with 31 additions and 27 deletions.
  1. +26 −26 lib/built-in.jsx
  2. +1 −0  src/classdef.js
  3. +4 −1 src/parser.js
View
52 lib/built-in.jsx
@@ -200,11 +200,11 @@ native final class Number {
function toPrecision(precision : int) : string;
// 15.1.2 (Function Properties of the Global Object)
- static function parseInt(str :string) :number;
- static function parseInt(str :string, radix :int) :number;
- static function parseFloat(str :string) :number;
- static function isNaN(num :number) :boolean;
- static function isFinite(num :number) :boolean;
+ static __pure__ function parseInt(str :string) :number;
+ static __pure__ function parseInt(str :string, radix :int) :number;
+ static __pure__ function parseFloat(str :string) :number;
+ static __pure__ function isNaN(num :number) :boolean;
+ static __pure__ function isFinite(num :number) :boolean;
}
@@ -221,34 +221,34 @@ native final class Math {
static const SQRT2 = 1.4142135623730951;
// 15.8.2
- static function abs(x :number) :number {
+ static __pure__ function abs(x :number) :number {
return x >= 0 ? x : -x;
}
- static function acos(x :number) :number;
- static function asin(x :number) :number;
- static function atan(x :number) :number;
- static function atan2(y :number, x :number) :number;
- static function ceil(x :number) :number;
- static function cos(x :number) :number;
- static function exp(x :number) :number;
- static function floor(x :number) :number;
- static function log(x :number) :number;
- static function max(value1 : number, value2 : number, value3 : number, ...valueN : number) : number;
- static function max(value1 : number) : number;
- static function min(value1 : number, value2 : number, value3 : number, ...valueN : number) : number;
- static function min(value1 : number) : number;
- static function pow(x :number, y :number) :number;
+ static __pure__ function acos(x :number) :number;
+ static __pure__ function asin(x :number) :number;
+ static __pure__ function atan(x :number) :number;
+ static __pure__ function atan2(y :number, x :number) :number;
+ static __pure__ function ceil(x :number) :number;
+ static __pure__ function cos(x :number) :number;
+ static __pure__ function exp(x :number) :number;
+ static __pure__ function floor(x :number) :number;
+ static __pure__ function log(x :number) :number;
+ static __pure__ function max(value1 : number, value2 : number, value3 : number, ...valueN : number) : number;
+ static __pure__ function max(value1 : number) : number;
+ static __pure__ function min(value1 : number, value2 : number, value3 : number, ...valueN : number) : number;
+ static __pure__ function min(value1 : number) : number;
+ static __pure__ function pow(x :number, y :number) :number;
static function random() :number;
- static function round(x :number) :number;
- static function sin(x :number) :number;
- static function sqrt(x :number) :number;
- static function tan(x :number) :number;
+ static __pure__ function round(x :number) :number;
+ static __pure__ function sin(x :number) :number;
+ static __pure__ function sqrt(x :number) :number;
+ static __pure__ function tan(x :number) :number;
// optimized (inlined) version for two-arg min/max
- static function max(value1 :number, value2 :number) :number {
+ static __pure__ function max(value1 :number, value2 :number) :number {
return value1 >= value2 ? value1 : value2;
}
- static function min(value1 :number, value2 :number) :number {
+ static __pure__ function min(value1 :number, value2 :number) :number {
return value1 <= value2 ? value1 : value2;
}
}
View
1  src/classdef.js
@@ -98,6 +98,7 @@ var ClassDefinition = exports.ClassDefinition = Class.extend({
$IS_FAKE: 256, // used for marking a JS non-class object that should be treated like a JSX class instance (e.g. window)
$IS_READONLY: 512,
$IS_INLINE: 1024,
+ $IS_PURE: 2048, // constexpr (intended for for native functions)
constructor: function (token, className, flags, extendType, implementTypes, members, objectTypesUsed) {
this._token = token;
View
5 src/parser.js
@@ -1092,7 +1092,7 @@ var Parser = exports.Parser = Class.extend({
_memberDefinition: function (classFlags) {
var flags = 0;
while (true) {
- var token = this._expect([ "function", "var", "static", "abstract", "override", "final", "const", "native", "__readonly__", "inline" ]);
+ var token = this._expect([ "function", "var", "static", "abstract", "override", "final", "const", "native", "__readonly__", "inline", "__pure__" ]);
if (token == null)
return null;
if (token.getValue() == "const") {
@@ -1140,6 +1140,9 @@ var Parser = exports.Parser = Class.extend({
case "inline":
newFlag = ClassDefinition.IS_INLINE;
break;
+ case "__pure__":
+ newFlag = ClassDefinition.IS_PURE;
+ break;
default:
throw new Error("logic flaw");
}
Please sign in to comment.
Something went wrong with that request. Please try again.