Skip to content

Commit

Permalink
Rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
acuarica committed Oct 7, 2023
1 parent b833007 commit 6bb2bd1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,30 @@ function solInst(inst: Inst): string {
case 'SigCase':
return `case when ${inst.condition} goto ${inst.offset} or fall ${inst.fallBranch.key}`;
case 'SStore': {
let variableName = sol`storage[${inst.location}]`;
let varName = sol`storage[${inst.location}]`;
if (inst.location.isVal() && inst.location.val.toString() in inst.variables) {
const loc = inst.location.val.toString();
const label = inst.variables[loc].label;
if (label) {
variableName = label;
varName = label;
} else {
variableName = `var${Object.keys(inst.variables).indexOf(loc) + 1}`;
varName = `var${Object.keys(inst.variables).indexOf(loc) + 1}`;
}
}
if (
inst.data.tag === 'Add' &&
inst.data.left.tag === 'SLoad' &&
solExpr(inst.data.left.location) === solExpr(inst.location)
) {
return sol`${variableName} += ${inst.data.right};`;
return sol`${varName} += ${inst.data.right};`;
} else if (
inst.data.tag === 'Sub' &&
inst.data.left.tag === 'SLoad' &&
solExpr(inst.data.left.location) === solExpr(inst.location)
) {
return sol`${variableName} -= ${inst.data.right};`;
return sol`${varName} -= ${inst.data.right};`;
} else {
return sol`${variableName} = ${inst.data};`;
return sol`${varName} = ${inst.data};`;
}
}
case 'MappingStore': {
Expand Down

0 comments on commit 6bb2bd1

Please sign in to comment.