Skip to content

Commit

Permalink
as_any_integer -> as_integer
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Aug 16, 2024
1 parent 01687e9 commit ebfe7a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
32 changes: 16 additions & 16 deletions compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ impl<'local, 'context> Interpreter<'local, 'context> {
"array_as_str_unchecked" => array_as_str_unchecked(interner, arguments, location),
"array_len" => array_len(interner, arguments, location),
"as_slice" => as_slice(interner, arguments, location),
"expr_as_any_integer" => expr_as_any_integer(arguments, return_type, location),
"expr_as_binary_op" => expr_as_binary_op(arguments, return_type, location),
"expr_as_bool" => expr_as_bool(arguments, return_type, location),
"expr_as_function_call" => expr_as_function_call(arguments, return_type, location),
"expr_as_if" => expr_as_if(arguments, return_type, location),
"expr_as_index" => expr_as_index(arguments, return_type, location),
"expr_as_integer" => expr_as_integer(arguments, return_type, location),
"expr_as_member_access" => expr_as_member_access(arguments, return_type, location),
"expr_as_unary_op" => expr_as_unary_op(arguments, return_type, location),
"expr_as_tuple" => expr_as_tuple(arguments, return_type, location),
Expand Down Expand Up @@ -758,21 +758,6 @@ fn zeroed(return_type: Type) -> IResult<Value> {
}
}

// fn as_any_integer(self) -> Option<(Field, bool)>
fn expr_as_any_integer(
arguments: Vec<(Value, Location)>,
return_type: Type,
location: Location,
) -> IResult<Value> {
expr_as(arguments, return_type.clone(), location, |expr| {
if let ExpressionKind::Literal(Literal::Integer(field, sign)) = expr {
Some(Value::Tuple(vec![Value::Field(field), Value::Bool(sign)]))
} else {
None
}
})
}

// fn as_bool(self) -> Option<bool>
fn expr_as_bool(
arguments: Vec<(Value, Location)>,
Expand Down Expand Up @@ -856,6 +841,21 @@ fn expr_as_index(
})
}

// fn as_integer(self) -> Option<(Field, bool)>
fn expr_as_integer(
arguments: Vec<(Value, Location)>,
return_type: Type,
location: Location,
) -> IResult<Value> {
expr_as(arguments, return_type.clone(), location, |expr| {
if let ExpressionKind::Literal(Literal::Integer(field, sign)) = expr {
Some(Value::Tuple(vec![Value::Field(field), Value::Bool(sign)]))
} else {
None
}
})
}

// fn as_member_access(self) -> Option<(Expr, Quoted)>
fn expr_as_member_access(
arguments: Vec<(Value, Location)>,
Expand Down
4 changes: 2 additions & 2 deletions noir_stdlib/src/meta/expr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::meta::op::UnaryOp;
use crate::meta::op::BinaryOp;

impl Expr {
#[builtin(expr_as_any_integer)]
fn as_any_integer(self) -> Option<(Field, bool)> {}
#[builtin(expr_as_integer)]
fn as_integer(self) -> Option<(Field, bool)> {}

#[builtin(expr_as_binary_op)]
fn as_binary_op(self) -> Option<(Expr, BinaryOp, Expr)> {}
Expand Down
6 changes: 3 additions & 3 deletions test_programs/compile_success_empty/comptime_exp/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ fn main() {
assert(get_binary_op(quote { x << y }).is_shift_left());
assert(get_binary_op(quote { x % y }).is_modulo());

// Check Expr::as_any_integer
// Check Expr::as_integer
let expr = quote { 1 }.as_expr().unwrap();
assert_eq((1, false), expr.as_any_integer().unwrap());
assert_eq((1, false), expr.as_integer().unwrap());

let expr = quote { -2 }.as_expr().unwrap();
assert_eq((2, true), expr.as_any_integer().unwrap());
assert_eq((2, true), expr.as_integer().unwrap());

// Check Expr::as_member_access
let expr = quote { foo.bar }.as_expr().unwrap();
Expand Down

0 comments on commit ebfe7a4

Please sign in to comment.