Skip to content

Commit

Permalink
Reformat the standard library and test programs
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Oct 19, 2024
1 parent 5092e12 commit 451d174
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
28 changes: 15 additions & 13 deletions noir_stdlib/src/meta/expr.nr
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,11 @@ comptime fn new_comptime(exprs: [Expr]) -> Expr {
}

comptime fn new_constructor(typ: UnresolvedType, fields: [(Quoted, Expr)]) -> Expr {
let fields = fields.map(|field: (Quoted, Expr)| {
let (name, value) = field;
quote { $name: $value }
})
let fields = fields
.map(|field: (Quoted, Expr)| {
let (name, value) = field;
quote { $name: $value }
})
.join(quote { , });
quote { $typ { $fields }}.as_expr().unwrap()
}
Expand Down Expand Up @@ -588,15 +589,16 @@ comptime fn new_lambda(
return_type: Option<UnresolvedType>,
body: Expr,
) -> Expr {
let params = params.map(|param: (Expr, Option<UnresolvedType>)| {
let (name, typ) = param;
if typ.is_some() {
let typ = typ.unwrap();
quote { $name: $typ }
} else {
quote { $name }
}
})
let params = params
.map(|param: (Expr, Option<UnresolvedType>)| {
let (name, typ) = param;
if typ.is_some() {
let typ = typ.unwrap();
quote { $name: $typ }
} else {
quote { $name }
}
})
.join(quote { , });

if return_type.is_some() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ fn main() {
MGaffine::new(
7972459279704486422145701269802978968072470631857513331988813812334797879121,
8142420778878030219043334189293412482212146646099536952861607542822144507872,
).into_tecurve(),
)
.into_tecurve(),
),
);
// SWU map-to-curve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ comptime fn inject_context(f: FunctionDefinition) {
comptime fn mapping_function(expr: Expr, f: FunctionDefinition) -> Option<Expr> {
expr.as_function_call().and_then(|func_call: (Expr, [Expr])| {
let (name, arguments) = func_call;
name.resolve(Option::some(f)).as_function_definition()
.and_then(|function_definition: FunctionDefinition| {
name.resolve(Option::some(f)).as_function_definition().and_then(
|function_definition: FunctionDefinition| {
if function_definition.has_named_attribute("inject_context") {
let arguments = arguments.push_front(quote { _context }.as_expr().unwrap());
let arguments = arguments.map(|arg: Expr| arg.quoted()).join(quote { , });
Option::some(quote { $name($arguments) }.as_expr().unwrap())
} else {
Option::none()
}
})
},
)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ comptime fn mangle_fn(f: FunctionDefinition) {
{
WeirdStruct { a: 1, b: [0;3] }
}
}.as_expr()
}
.as_expr()
.unwrap();

f.set_return_type(new_return_type);
Expand Down
12 changes: 7 additions & 5 deletions test_programs/compile_success_empty/unquote_struct/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ fn foo(x: Field, y: u32) -> u32 {

// Given a function, wrap its parameters in a struct definition
comptime fn output_struct(f: FunctionDefinition) -> Quoted {
let fields = f.parameters().map(|param: (Quoted, Type)| {
let name = param.0;
let typ = param.1;
quote { $name: $typ, }
})
let fields = f
.parameters()
.map(|param: (Quoted, Type)| {
let name = param.0;
let typ = param.1;
quote { $name: $typ, }
})
.join(quote {});

quote {
Expand Down
10 changes: 6 additions & 4 deletions test_programs/execution_success/brillig_oracle/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ fn main(_x: Field) {
}

// TODO: this method of returning a slice feels hacky.
let _ = OracleMock::mock("get_number_sequence").with_params(size)
.returns((20, mock_oracle_response));
let _ = OracleMock::mock("get_reverse_number_sequence").with_params(size)
.returns((20, reversed_mock_oracle_response));
let _ = OracleMock::mock("get_number_sequence").with_params(size).returns(
(20, mock_oracle_response),
);
let _ = OracleMock::mock("get_reverse_number_sequence").with_params(size).returns(
(20, reversed_mock_oracle_response),
);

get_number_sequence_wrapper(size as Field);
}
Expand Down

0 comments on commit 451d174

Please sign in to comment.