Skip to content

Commit

Permalink
fix: broken constants gen (#9387)
Browse files Browse the repository at this point in the history
Fixes broken constants gen due to new formatting in noir.
  • Loading branch information
sklppy88 authored Oct 24, 2024
1 parent fd1a0d1 commit eb7bc6b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions yarn-project/circuits.js/src/scripts/constants.in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function parseNoirFile(fileContent: string): ParsedContent {
}

{
const [, name, _type, value, end] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*([^;]+)(;)?/) || [];
const [, name, _type, value, end] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*([^;]*)(;)?/) || [];
if (name && value) {
const [, indexName] = name.match(/GENERATOR_INDEX__(\w+)/) || [];
if (indexName) {
Expand All @@ -336,6 +336,10 @@ function parseNoirFile(fileContent: string): ParsedContent {
expression = { name, content: [value] };
}
return;
} else if (name) {
// This case happens if we have only a name, with the value being on the next line
expression = { name, content: [] };
return;
}
}

Expand Down Expand Up @@ -389,8 +393,11 @@ function evaluateExpressions(expressions: [string, string][]): { [key: string]:
// We make some space around the parentheses, so that constant numbers are still split.
.replace(/\(/g, '( ')
.replace(/\)/g, ' )')
// We also make some space around common operators
.replace(/\+/g, ' + ')
.replace(/(?<!\/)\*(?!\/)/, ' * ')
// We split the expression into terms...
.split(' ')
.split(/\s+/)
// ...and then we convert each term to a BigInt if it is a number.
.map(term => (isNaN(+term) ? term : `BigInt('${term}')`))
// .. also, we convert the known bigints to BigInts.
Expand Down

0 comments on commit eb7bc6b

Please sign in to comment.