-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add the `**` operator to Hermes. - Add the tokens to the lexer - Update the parser to allow for right-associative binary operators - Break the stack popping loop early to build from the right with ** - Error when using a UnaryOperator before ** (must use parens) - Update the IR to parse the corresponding strings - Add the HermesInternal call to perform the operation Reviewed By: tmikov Differential Revision: D16628557 fbshipit-source-id: 1d94cd2c7f13ccf694415f7cd28b3061bf5eb38c
- Loading branch information
1 parent
c0d849e
commit ae0bc93
Showing
24 changed files
with
372 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE | ||
* file in the root directory of this source tree. | ||
*/ | ||
#ifndef HERMES_SUPPORT_MATH_H | ||
#define HERMES_SUPPORT_MATH_H | ||
|
||
#include <cmath> | ||
|
||
namespace hermes { | ||
|
||
/// ES9.0 12.6.4 | ||
/// Perform the exponentiation operation on doubles required by the JS spec. | ||
inline double expOp(double x, double y) { | ||
constexpr double nan = std::numeric_limits<double>::quiet_NaN(); | ||
|
||
// Handle special cases that std::pow handles differently. | ||
if (std::isnan(y)) { | ||
return nan; | ||
} else if (y == 0) { | ||
return 1; | ||
} else if (std::abs(x) == 1 && std::isinf(y)) { | ||
return nan; | ||
} | ||
|
||
// std::pow handles the other edge cases as the ES9.0 spec requires. | ||
return std::pow(x, y); | ||
} | ||
|
||
} // namespace hermes | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// | ||
// This source code is licensed under the MIT license found in the LICENSE | ||
// file in the root directory of this source tree. | ||
// | ||
// RUN: (! %hermesc -dump-ast -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s | ||
|
||
+3 ** 2; | ||
// CHECK: {{.*}}:8:1: error: Unary operator before ** must use parens to disambiguate | ||
// CHECK: +3 ** 2; | ||
// CHECK: ^~~~~ | ||
|
||
delete 3 ** 2; | ||
// CHECK: {{.*}}:13:1: error: Unary operator before ** must use parens to disambiguate | ||
// CHECK: delete 3 ** 2; | ||
// CHECK: ^~~~~~~~~~~ |
Oops, something went wrong.