remove parentheses in parser, rename to ArrayLiteralExpression

This commit is contained in:
schaeff
2023-03-29 10:43:09 +02:00
parent fa66f1ee13
commit 82ce286f20
9 changed files with 34 additions and 30 deletions

View File

@@ -826,7 +826,7 @@ mod test {
pub fn compile_simple_sum() {
let expectation = r#"
namespace Assembly(1024);
pol constant first_step = ([1] + [0]*);
pol constant first_step = [1] + [0]*;
(first_step * pc) = 0;
pol commit pc;
pol commit X;
@@ -859,19 +859,19 @@ CNT' = ((((first_step' * 0) + (reg_write_X_CNT * X)) + (instr_dec_CNT * (CNT - 1
pc' = ((((first_step' * 0) + (instr_jmpz * ((XIsZero * instr_jmpz_param_l) + ((1 - XIsZero) * (pc + 1))))) + (instr_jmp * instr_jmp_param_l)) + ((1 - ((first_step' + instr_jmpz) + instr_jmp)) * (pc + 1)));
pol constant line(i) { i };
pol commit X_free_value(i) query (i, pc, (0, ("input", 1)), (3, ("input", (CNT + 1))), (7, ("input", 0)));
pol constant p_X_const = ([0, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_X_read_free = ([1, 0, 0, 1, 0, 0, 0, -1, 0] + [0]*);
pol constant p_instr_assert_zero = ([0, 0, 0, 0, 0, 0, 0, 0, 1] + [0]*);
pol constant p_instr_dec_CNT = ([0, 0, 0, 0, 1, 0, 0, 0, 0] + [0]*);
pol constant p_instr_jmp = ([0, 0, 0, 0, 0, 1, 0, 0, 0] + [0]*);
pol constant p_instr_jmp_param_l = ([0, 0, 0, 0, 0, 1, 0, 0, 0] + [0]*);
pol constant p_instr_jmpz = ([0, 0, 1, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_instr_jmpz_param_l = ([0, 0, 6, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_read_X_A = ([0, 0, 0, 1, 0, 0, 0, 1, 1] + [0]*);
pol constant p_read_X_CNT = ([0, 0, 1, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_read_X_pc = ([0, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_reg_write_X_A = ([0, 0, 0, 1, 0, 0, 0, 1, 0] + [0]*);
pol constant p_reg_write_X_CNT = ([1, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*);
pol constant p_X_const = [0, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*;
pol constant p_X_read_free = [1, 0, 0, 1, 0, 0, 0, -1, 0] + [0]*;
pol constant p_instr_assert_zero = [0, 0, 0, 0, 0, 0, 0, 0, 1] + [0]*;
pol constant p_instr_dec_CNT = [0, 0, 0, 0, 1, 0, 0, 0, 0] + [0]*;
pol constant p_instr_jmp = [0, 0, 0, 0, 0, 1, 0, 0, 0] + [0]*;
pol constant p_instr_jmp_param_l = [0, 0, 0, 0, 0, 1, 0, 0, 0] + [0]*;
pol constant p_instr_jmpz = [0, 0, 1, 0, 0, 0, 0, 0, 0] + [0]*;
pol constant p_instr_jmpz_param_l = [0, 0, 6, 0, 0, 0, 0, 0, 0] + [0]*;
pol constant p_read_X_A = [0, 0, 0, 1, 0, 0, 0, 1, 1] + [0]*;
pol constant p_read_X_CNT = [0, 0, 1, 0, 0, 0, 0, 0, 0] + [0]*;
pol constant p_read_X_pc = [0, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*;
pol constant p_reg_write_X_A = [0, 0, 0, 1, 0, 0, 0, 1, 0] + [0]*;
pol constant p_reg_write_X_CNT = [1, 0, 0, 0, 0, 0, 0, 0, 0] + [0]*;
{ pc, reg_write_X_A, reg_write_X_CNT, instr_jmpz, instr_jmpz_param_l, instr_jmp, instr_jmp_param_l, instr_dec_CNT, instr_assert_zero, X_const, X_read_free, read_X_A, read_X_CNT, read_X_pc } in { line, p_reg_write_X_A, p_reg_write_X_CNT, p_instr_jmpz, p_instr_jmpz_param_l, p_instr_jmp, p_instr_jmp_param_l, p_instr_dec_CNT, p_instr_assert_zero, p_X_const, p_X_read_free, p_read_X_A, p_read_X_CNT, p_read_X_pc };
"#;

View File

@@ -264,9 +264,9 @@ mod test {
let src = r#"
constant %N = 10;
namespace F(%N);
col fixed alt = ([0, 1, 0, 1, 0, 1] + [0]*);
col fixed empty = ([] + [0]*);
col fixed ref_other = ([%N-1, alt(1), 8] + [0]*);
col fixed alt = [0, 1, 0, 1, 0, 1] + [0]*;
col fixed empty = [] + [0]*;
col fixed ref_other = [%N-1, alt(1), 8] + [0]*;
"#;
let analyzed = analyze_string(src);
let (constants, degree) = generate(&analyzed);

View File

@@ -97,7 +97,7 @@ impl Display for ArrayExpression {
ArrayExpression::RepeatedValue(expressions) => {
write!(f, "[{}]*", format_expressions(expressions))
}
ArrayExpression::Concat(left, right) => write!(f, "({} + {})", left, right),
ArrayExpression::Concat(left, right) => write!(f, "{} + {}", left, right),
}
}
}

View File

@@ -71,13 +71,23 @@ PolynomialConstantDefinition: Statement = {
FunctionDefinition: FunctionDefinition = {
"(" <ParameterList> ")" "{" <Expression> "}" => FunctionDefinition::Mapping(<>),
"=" <ArrayExpression> => FunctionDefinition::Array(<>),
"=" <ArrayLiteralExpression> => FunctionDefinition::Array(<>),
}
ParameterList: Vec<String> = {
<mut list:( <Identifier> "," )*> <end:Identifier> => { list.push(end); list }
}
ArrayLiteralExpression: ArrayExpression = {
<ArrayLiteralExpression> "+" <ArrayLiteralTerm> => ArrayExpression::concat(<>),
ArrayLiteralTerm,
}
ArrayLiteralTerm: ArrayExpression = {
"[" <ExpressionList> "]" => ArrayExpression::value(<>),
"[" <ExpressionList> "]" "*" => ArrayExpression::repeated_value(<>),
}
PolynomialCommitDeclaration: Statement = {
<@L> PolCol CommitWitness <PolynomialNameList> => Statement::PolynomialCommitDeclaration(<>, None),
<start:@L> PolCol CommitWitness <name:PolynomialName> "(" <param:ParameterList> ")" "query" <value:Expression>
@@ -329,12 +339,6 @@ PublicReference: String = {
":" <Identifier>
}
ArrayExpression: ArrayExpression = {
"[" <ExpressionList> "]" => ArrayExpression::value(<>),
"[" <ExpressionList> "]" "*" => ArrayExpression::repeated_value(<>),
"(" <ArrayExpression> "+" <ArrayExpression> ")" => ArrayExpression::concat(<>),
}
// ---------------------------- Terminals -----------------------------

View File

@@ -78,7 +78,7 @@ pil{
// positive numbers (assumed to be much smaller than the field order)
col fixed POSITIVE(i) { i + 1 };
col fixed FIRST = ([1] + [0]*);
col fixed FIRST = [1] + [0]*;
col fixed LAST(i) { FIRST(i + 1) };
col fixed STEP(i) { i };

View File

@@ -28,7 +28,7 @@ pil{
// positive numbers (assumed to be much smaller than the field order)
col fixed POSITIVE(i) { i + 1 };
col fixed FIRST = ([1] + [0]*);
col fixed FIRST = [1] + [0]*;
col fixed LAST(i) { FIRST(i + 1) };
col fixed STEP(i) { i };

View File

@@ -24,7 +24,7 @@ pil{
// positive numbers (assumed to be less than half the field order)
col fixed POSITIVE(i) { i + 1 };
col fixed FIRST = ([1] + [0]*);
col fixed FIRST = [1] + [0]*;
col fixed NOTLAST(i) { 1 - FIRST(i + 1) };
// This enforces that addresses are stored in an ascending order

View File

@@ -16,7 +16,7 @@ namespace Global(%N);
macro ite(C, A, B) { is_nonzero(C) * A + is_zero(C) * B};
macro one_hot(i, index) { ite(is_equal(i, index), 1, 0) };
col fixed L1 = ([1] + [0]*); // will be filled with zeros
col fixed L1 = [1] + [0]*;
col fixed LLAST(i) { one_hot(i, %N - 1) };
col fixed BYTE(i) { i & 0xff };
col fixed BYTE2(i) { i & 0xffff };

View File

@@ -12,7 +12,7 @@ namespace Sum(%N);
pol fixed ISLAST(i) { one_hot(i, %last_row) };
pol fixed ISALMOSTLAST(i) { one_hot(i, %last_row - 1) };
pol fixed ISFIRST = ([ 1, 0 ] + [0]*);
pol fixed ISFIRST = [ 1, 0 ] + [0]*;
col witness input(i) query ("in", i);
col witness sum;