Skip to content

Commit

Permalink
feat(parser): add semicolon for return expr
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Aug 9, 2024
1 parent ce498f0 commit f515073
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 123 deletions.
40 changes: 20 additions & 20 deletions air-script/tests/functions/functions_complex.air
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
def FunctionsAir

fn get_multiplicity_flags(s0: felt, s1: felt) -> felt[4] {
return [!s0 & !s1, s0 & !s1, !s0 & s1, s0 & s1]
return [!s0 & !s1, s0 & !s1, !s0 & s1, s0 & s1];
}

fn fold_vec(a: felt[12]) -> felt {
return sum([x for x in a])
return sum([x for x in a]);
}

fn fold_scalar_and_vec(a: felt, b: felt[12]) -> felt {
let m = fold_vec(b)
let n = m + 1
let o = n * 2
return o
let m = fold_vec(b);
let n = m + 1;
let o = n * 2;
return o;
}

trace_columns {
main: [t, s0, s1, v, b[12]]
aux: [b_range]
main: [t, s0, s1, v, b[12]],
aux: [b_range],
}

public_inputs {
stack_inputs: [16]
stack_inputs: [16],
}

random_values {
alpha: [16]
alpha: [16],
}

boundary_constraints {
enf v.first = 0
enf v.first = 0;
}

integrity_constraints {
# let val = $alpha[0] + v
let f = get_multiplicity_flags(s0, s1)
let z = v^7 * f[3] + v^2 * f[2] + v * f[1] + f[0]
# let folded_value = fold_scalar_and_vec(v, b)
enf b_range' = b_range * (z * t - t + 1)
# enf b_range' = b_range * 2
let y = fold_scalar_and_vec(v, b)
# let c = fold_scalar_and_vec(t, b)
enf v' = y
# let val = $alpha[0] + v;
let f = get_multiplicity_flags(s0, s1);
let z = v^7 * f[3] + v^2 * f[2] + v * f[1] + f[0];
# let folded_value = fold_scalar_and_vec(v, b);
enf b_range' = b_range * (z * t - t + 1);
# enf b_range' = b_range * 2;
let y = fold_scalar_and_vec(v, b);
# let c = fold_scalar_and_vec(t, b);
enf v' = y;
}
66 changes: 33 additions & 33 deletions air-script/tests/functions/functions_simple.air
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
def FunctionsAir

fn fold_sum(a: felt[4]) -> felt {
return a[0] + a[1] + a[2] + a[3]
return a[0] + a[1] + a[2] + a[3];
}

fn fold_vec(a: felt[4]) -> felt {
let m = a[0] * a[1]
let n = m * a[2]
let o = n * a[3]
return o
let m = a[0] * a[1];
let n = m * a[2];
let o = n * a[3];
return o;
}

fn cube(base: felt) -> felt {
return base^3
return base^3;
}

fn cube_vec(base: felt[4]) -> felt[4] {
let cubed_vec = [x^3 for x in base]
return cubed_vec
let cubed_vec = [x^3 for x in base];
return cubed_vec;
}

fn func_return(a: felt[4]) -> felt {
return fold_sum(a)
return fold_sum(a);
}

fn func_func_return(a: felt[4]) -> felt {
return fold_sum(a) * fold_vec(a)
return fold_sum(a) * fold_vec(a);
}

fn bin_return(a: felt[4]) -> felt {
return fold_sum(a) * 4
return fold_sum(a) * 4;
}

trace_columns {
main: [t, s0, s1, v, b[4]]
aux: [b_range]
main: [t, s0, s1, v, b[4]],
aux: [b_range],
}

public_inputs {
stack_inputs: [16]
stack_inputs: [16],
}

random_values {
alpha: [16]
alpha: [16],
}

boundary_constraints {
enf v.first = 0
enf v.first = 0;
}

integrity_constraints {
# -------- function call is assigned to a variable and used in a binary expression ------------

# binary expression invloving scalar expressions
let simple_expression = t * v
enf simple_expression = 1
let simple_expression = t * v;
enf simple_expression = 1;

# binary expression involving one function call
let folded_vec = fold_vec(b) * v
enf folded_vec = 1
let folded_vec = fold_vec(b) * v;
enf folded_vec = 1;

# binary expression involving two function calls
let complex_fold = fold_sum(b) * fold_vec(b)
enf complex_fold = 1
let complex_fold = fold_sum(b) * fold_vec(b);
enf complex_fold = 1;


# -------- function calls used in constraint ------------
enf fold_vec(b) = 1
enf t * fold_vec(b) = 1
enf s0 + fold_sum(b) * fold_vec(b) = 1
enf fold_vec(b) = 1;
enf t * fold_vec(b) = 1;
enf s0 + fold_sum(b) * fold_vec(b) = 1;

# -------- functions with function calls as return statements ------------
enf func_return(b) = 1
enf func_func_return(b) = 1
enf bin_return(b) = 1
enf func_return(b) = 1;
enf func_func_return(b) = 1;
enf bin_return(b) = 1;

# -------- different types of arguments in a function call ------------

# function call with a function call as an argument
# enf fold_vec(cube_vec(b)) = 1
# enf fold_vec(cube_vec(b)) = 1;

# function call as value in list comprehension
# let folded_vec = sum([cube(x) for x in b])
# enf t * folded_vec = 1
# let folded_vec = sum([cube(x) for x in b]);
# enf t * folded_vec = 1;

# function call as iterable in list comprehension
# let folded_vec = sum([x + 1 for x in cube_vec(b)])
# enf t * folded_vec = 1
# let folded_vec = sum([x + 1 for x in cube_vec(b)]);
# enf t * folded_vec = 1;
}
40 changes: 20 additions & 20 deletions air-script/tests/functions/inlined_functions_simple.air
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@
def FunctionsAir

trace_columns {
main: [t, s0, s1, v, b[4]]
aux: [b_range]
main: [t, s0, s1, v, b[4]],
aux: [b_range],
}

public_inputs {
stack_inputs: [16]
stack_inputs: [16],
}

random_values {
alpha: [16]
alpha: [16],
}

boundary_constraints {
enf v.first = 0
enf v.first = 0;
}

integrity_constraints {
# -------- function call is assigned to a variable and used in a binary expression ------------

# binary expression invloving scalar expressions
let simple_expression = t * v
enf simple_expression = 1
let simple_expression = t * v;
enf simple_expression = 1;

# binary expression involving one function call

# fold_vec function body where o is the return value of the function
let m = b[0] * b[1]
let n = m * b[2]
let o = n * b[3]
let m = b[0] * b[1];
let n = m * b[2];
let o = n * b[3];

let folded_vec = o * v
enf folded_vec = 1
let folded_vec = o * v;
enf folded_vec = 1;

# binary expression involving two function calls
let complex_fold = (b[0] + b[1] + b[2] + b[3]) * o
enf complex_fold = 1
let complex_fold = (b[0] + b[1] + b[2] + b[3]) * o;
enf complex_fold = 1;

# function calls used in constraints
enf o = 1
enf t * o = 1
enf s0 + (b[0] + b[1] + b[2] + b[3]) * o = 1
enf o = 1;
enf t * o = 1;
enf s0 + (b[0] + b[1] + b[2] + b[3]) * o = 1;

# -------- functions with function calls as return statements ------------
enf b[0] + b[1] + b[2] + b[3] = 1
enf (b[0] + b[1] + b[2] + b[3]) * o = 1
enf (b[0] + b[1] + b[2] + b[3]) * 4 = 1
enf b[0] + b[1] + b[2] + b[3] = 1;
enf (b[0] + b[1] + b[2] + b[3]) * o = 1;
enf (b[0] + b[1] + b[2] + b[3]) * 4 = 1;
}
2 changes: 1 addition & 1 deletion parser/src/parser/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ ConstraintStatement: Vec<Statement> = {
}

ReturnStatement: Expr = {
<l:@L> "return" <expr: Expr> <r:@R> => expr,
<l:@L> "return" <expr: Expr> ";" <r:@R> => expr,
}

MatchArm: Statement = {
Expand Down
Loading

0 comments on commit f515073

Please sign in to comment.