mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:27:35 +00:00
LibJS: Implement <= and >= binary operators
This commit is contained in:
parent
fdf7f81ba9
commit
0fe87c5fec
6 changed files with 38 additions and 0 deletions
|
@ -125,8 +125,12 @@ Value BinaryExpression::execute(Interpreter& interpreter) const
|
||||||
return Value(!typed_eq(lhs_result, rhs_result).to_boolean());
|
return Value(!typed_eq(lhs_result, rhs_result).to_boolean());
|
||||||
case BinaryOp::GreaterThan:
|
case BinaryOp::GreaterThan:
|
||||||
return greater_than(lhs_result, rhs_result);
|
return greater_than(lhs_result, rhs_result);
|
||||||
|
case BinaryOp::GreaterThanEquals:
|
||||||
|
return greater_than_equals(lhs_result, rhs_result);
|
||||||
case BinaryOp::LessThan:
|
case BinaryOp::LessThan:
|
||||||
return less_than(lhs_result, rhs_result);
|
return less_than(lhs_result, rhs_result);
|
||||||
|
case BinaryOp::LessThanEquals:
|
||||||
|
return less_than_equals(lhs_result, rhs_result);
|
||||||
case BinaryOp::BitwiseAnd:
|
case BinaryOp::BitwiseAnd:
|
||||||
return bitwise_and(lhs_result, rhs_result);
|
return bitwise_and(lhs_result, rhs_result);
|
||||||
case BinaryOp::BitwiseOr:
|
case BinaryOp::BitwiseOr:
|
||||||
|
@ -213,9 +217,15 @@ void BinaryExpression::dump(int indent) const
|
||||||
case BinaryOp::GreaterThan:
|
case BinaryOp::GreaterThan:
|
||||||
op_string = ">";
|
op_string = ">";
|
||||||
break;
|
break;
|
||||||
|
case BinaryOp::GreaterThanEquals:
|
||||||
|
op_string = ">=";
|
||||||
|
break;
|
||||||
case BinaryOp::LessThan:
|
case BinaryOp::LessThan:
|
||||||
op_string = "<";
|
op_string = "<";
|
||||||
break;
|
break;
|
||||||
|
case BinaryOp::LessThanEquals:
|
||||||
|
op_string = "<=";
|
||||||
|
break;
|
||||||
case BinaryOp::BitwiseAnd:
|
case BinaryOp::BitwiseAnd:
|
||||||
op_string = "&";
|
op_string = "&";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -219,7 +219,9 @@ enum class BinaryOp {
|
||||||
TypedEquals,
|
TypedEquals,
|
||||||
TypedInequals,
|
TypedInequals,
|
||||||
GreaterThan,
|
GreaterThan,
|
||||||
|
GreaterThanEquals,
|
||||||
LessThan,
|
LessThan,
|
||||||
|
LessThanEquals,
|
||||||
BitwiseAnd,
|
BitwiseAnd,
|
||||||
BitwiseOr,
|
BitwiseOr,
|
||||||
BitwiseXor,
|
BitwiseXor,
|
||||||
|
|
|
@ -133,6 +133,12 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
|
||||||
case TokenType::Slash:
|
case TokenType::Slash:
|
||||||
consume();
|
consume();
|
||||||
return make<BinaryExpression>(BinaryOp::Slash, move(lhs), parse_expression());
|
return make<BinaryExpression>(BinaryOp::Slash, move(lhs), parse_expression());
|
||||||
|
case TokenType::GreaterThanEquals:
|
||||||
|
consume();
|
||||||
|
return make<BinaryExpression>(BinaryOp::GreaterThanEquals, move(lhs), parse_expression());
|
||||||
|
case TokenType::LessThanEquals:
|
||||||
|
consume();
|
||||||
|
return make<BinaryExpression>(BinaryOp::LessThanEquals, move(lhs), parse_expression());
|
||||||
case TokenType::ParenOpen:
|
case TokenType::ParenOpen:
|
||||||
return parse_call_expression(move(lhs));
|
return parse_call_expression(move(lhs));
|
||||||
case TokenType::Equals:
|
case TokenType::Equals:
|
||||||
|
@ -248,6 +254,8 @@ bool Parser::match_secondary_expression() const
|
||||||
|| type == TokenType::Asterisk
|
|| type == TokenType::Asterisk
|
||||||
|| type == TokenType::Slash
|
|| type == TokenType::Slash
|
||||||
|| type == TokenType::Equals
|
|| type == TokenType::Equals
|
||||||
|
|| type == TokenType::GreaterThanEquals
|
||||||
|
|| type == TokenType::LessThanEquals
|
||||||
|| type == TokenType::ParenOpen
|
|| type == TokenType::ParenOpen
|
||||||
|| type == TokenType::Period;
|
|| type == TokenType::Period;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,13 @@ enum class TokenType {
|
||||||
Finally,
|
Finally,
|
||||||
Function,
|
Function,
|
||||||
GreaterThan,
|
GreaterThan,
|
||||||
|
GreaterThanEquals,
|
||||||
Identifier,
|
Identifier,
|
||||||
If,
|
If,
|
||||||
Interface,
|
Interface,
|
||||||
Invalid,
|
Invalid,
|
||||||
LessThan,
|
LessThan,
|
||||||
|
LessThanEquals,
|
||||||
Let,
|
Let,
|
||||||
Minus,
|
Minus,
|
||||||
MinusEquals,
|
MinusEquals,
|
||||||
|
|
|
@ -96,6 +96,13 @@ Value greater_than(Value lhs, Value rhs)
|
||||||
return Value(lhs.as_double() > rhs.as_double());
|
return Value(lhs.as_double() > rhs.as_double());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value greater_than_equals(Value lhs, Value rhs)
|
||||||
|
{
|
||||||
|
ASSERT(lhs.is_number());
|
||||||
|
ASSERT(rhs.is_number());
|
||||||
|
return Value(lhs.as_double() >= rhs.as_double());
|
||||||
|
}
|
||||||
|
|
||||||
Value less_than(Value lhs, Value rhs)
|
Value less_than(Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
ASSERT(lhs.is_number());
|
ASSERT(lhs.is_number());
|
||||||
|
@ -103,6 +110,13 @@ Value less_than(Value lhs, Value rhs)
|
||||||
return Value(lhs.as_double() < rhs.as_double());
|
return Value(lhs.as_double() < rhs.as_double());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value less_than_equals(Value lhs, Value rhs)
|
||||||
|
{
|
||||||
|
ASSERT(lhs.is_number());
|
||||||
|
ASSERT(rhs.is_number());
|
||||||
|
return Value(lhs.as_double() <= rhs.as_double());
|
||||||
|
}
|
||||||
|
|
||||||
Value bitwise_and(Value lhs, Value rhs)
|
Value bitwise_and(Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
ASSERT(lhs.is_number());
|
ASSERT(lhs.is_number());
|
||||||
|
|
|
@ -159,7 +159,9 @@ inline Value js_null()
|
||||||
}
|
}
|
||||||
|
|
||||||
Value greater_than(Value lhs, Value rhs);
|
Value greater_than(Value lhs, Value rhs);
|
||||||
|
Value greater_than_equals(Value lhs, Value rhs);
|
||||||
Value less_than(Value lhs, Value rhs);
|
Value less_than(Value lhs, Value rhs);
|
||||||
|
Value less_than_equals(Value lhs, Value rhs);
|
||||||
Value bitwise_and(Value lhs, Value rhs);
|
Value bitwise_and(Value lhs, Value rhs);
|
||||||
Value bitwise_or(Value lhs, Value rhs);
|
Value bitwise_or(Value lhs, Value rhs);
|
||||||
Value bitwise_xor(Value lhs, Value rhs);
|
Value bitwise_xor(Value lhs, Value rhs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue