From bdd0785aa5a209f18c5550165f7cdfeb9443b8e2 Mon Sep 17 00:00:00 2001 From: Antoine Fondeur Date: Tue, 10 Dec 2024 13:00:01 -0500 Subject: [PATCH] fixed bug making it impossible to load programs with no builtins (#65) --- src/ui/ui.ts | 12 ++++++++---- src/vm/vm.ts | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 160fa00..f6fde93 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -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) diff --git a/src/vm/vm.ts b/src/vm/vm.ts index 76c2ec9..05743c5 100644 --- a/src/vm/vm.ts +++ b/src/vm/vm.ts @@ -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 @@ -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}`)