Skip to content

Commit

Permalink
fixed bug making it impossible to load programs with no builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineFONDEUR committed Dec 9, 2024
1 parent 6074a23 commit 3dc4081
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/ui/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,14 @@ function loadProgram(
programSheet.getRange(rowOffset, 2).setValue(isProofMode ? 1 : 0);
rowOffset++;
programSheet.getRange(rowOffset, 1).setValue("used_builtins");
programSheet
.getRange(rowOffset, 2, program.builtins.length)
.setValues(program.builtins.map((builtin) => [builtin]));
rowOffset += program.builtins.length;
if (program.builtins.length > 0) {
programSheet
.getRange(rowOffset, 2, program.builtins.length)
.setValues(program.builtins.map((builtin) => [builtin]));
rowOffset += program.builtins.length;
} else {
rowOffset += 1;
}
programSheet.getRange(rowOffset, 1).setValue("initial_pc");
programSheet
.getRange(rowOffset, 2)
Expand Down
42 changes: 28 additions & 14 deletions src/vm/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,32 @@ function initializeProgram(program: any, isProofMode: boolean, layout: Layout) {

let stack: string[] = [];
if (!isProofMode) {
let fpRow: string = indexToColumn(
columnToIndex(builtins[builtinsList[builtinsList.length - 1]].column) + 1,
);
let pcRow: string = indexToColumn(
columnToIndex(builtins[builtinsList[builtinsList.length - 1]].column) + 2,
);
stack = [...builtinStack, `${fpRow}2`, `${pcRow}2`];
let fpColumn: string =
program.builtins.length != 0
? indexToColumn(
columnToIndex(
builtins[builtinsList[builtinsList.length - 1]].column,
) + 1,
)
: indexToColumn(columnToIndex(executionColumn) + 1);
let pcColumn: string =
program.builtins.length != 0
? indexToColumn(
columnToIndex(
builtins[builtinsList[builtinsList.length - 1]].column,
) + 2,
)
: indexToColumn(columnToIndex(executionColumn) + 2);
stack = [...builtinStack, `${fpColumn}2`, `${pcColumn}2`];
runSheet
.getRange(`${builtins[builtinsList[0]].column}1:${pcRow}1`)
.getRange(
`${indexToColumn(columnToIndex(executionColumn) + 1)}1:${pcColumn}1`,
)
.setValues([[...builtinsList, FINAL_FP, FINAL_PC]]);
programSheet
.getRange(`B${Number(getFinalPcCell().substring(1)) + 1}`)
.setValue(stack.length);
programSheet.getRange(getFinalPcCell()).setValue(`${pcRow}2`);
programSheet.getRange(getFinalPcCell()).setValue(`${pcColumn}2`);
} else {
stack = [`${executionColumn}2`, "0", ...builtinStack];
programSheet
Expand All @@ -183,11 +195,13 @@ function initializeProgram(program: any, isProofMode: boolean, layout: Layout) {
.getRange(getFinalPcCell())
.setValue(program["identifiers"]["__main__.__end__"]["pc"]);

runSheet
.getRange(
`${builtins[builtinsList[0]].column}1:${builtins[builtinsList[builtinsList.length - 1]].column}1`,
)
.setValues([builtinsList]);
if (builtinsList.length > 0) {
runSheet
.getRange(
`${builtins[builtinsList[0]].column}1:${builtins[builtinsList[builtinsList.length - 1]].column}1`,
)
.setValues([builtinsList]);
}
}
runSheet
.getRange(`${executionColumn}2:${executionColumn}${stack.length + 1}`)
Expand Down

0 comments on commit 3dc4081

Please sign in to comment.