Skip to content

Commit 9e74aa5

Browse files
committed
incrementDynamicScratchSlot
1 parent ab0b7ea commit 9e74aa5

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

src/lib/compiler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,12 @@ export default class Compiler {
35873587
typeComparison(this.lastType, type);
35883588
if (slot !== undefined) {
35893589
this.pushVoid(node, `store ${slot}`);
3590+
} else {
3591+
const call = node.getDescendantsOfKind(ts.SyntaxKind.CallExpression)[0];
3592+
3593+
this.processNode(call.getArguments()[0]);
3594+
this.pushVoid(node, 'swap');
3595+
this.pushVoid(node, `stores`);
35903596
}
35913597

35923598
return;

tests/contracts/artifacts/GeneralTest.approval.teal

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,42 @@ incrementScratchSlot:
22692269
assert
22702270
retsub
22712271

2272+
// incrementDynamicScratchSlot()void
2273+
*abi_route_incrementDynamicScratchSlot:
2274+
// execute incrementDynamicScratchSlot()void
2275+
callsub incrementDynamicScratchSlot
2276+
int 1
2277+
return
2278+
2279+
// incrementDynamicScratchSlot(): void
2280+
incrementDynamicScratchSlot:
2281+
proto 0 0
2282+
2283+
// tests/contracts/general.algo.ts:454
2284+
// this.dynamicScratch(2).value = 1337
2285+
int 2
2286+
int 1337
2287+
stores
2288+
2289+
// tests/contracts/general.algo.ts:455
2290+
// this.dynamicScratch(2).value += 1
2291+
int 2
2292+
loads
2293+
int 1
2294+
+
2295+
int 2
2296+
swap
2297+
stores
2298+
2299+
// tests/contracts/general.algo.ts:456
2300+
// assert(this.dynamicScratch(2).value === 1338)
2301+
int 2
2302+
loads
2303+
int 1338
2304+
==
2305+
assert
2306+
retsub
2307+
22722308
*abi_route_createApplication:
22732309
int 1
22742310
return
@@ -2341,8 +2377,9 @@ incrementScratchSlot:
23412377
method "staticTypeLen()void"
23422378
method "dynamicScratchSlot()void"
23432379
method "incrementScratchSlot()void"
2380+
method "incrementDynamicScratchSlot()void"
23442381
txna ApplicationArgs 0
2345-
match *abi_route_txnTypeEnum *abi_route_txnGroupLength *abi_route_asserts *abi_route_verifyTxnFromArg *abi_route_verifyTxnFromTxnGroup *abi_route_verifyTxnCondition *abi_route_verifyTxnIncludedIn *abi_route_verifyTxnNotIncludedIn *abi_route_submitPendingGroup *abi_route_methodWithTxnArgs *abi_route_shift *abi_route_fromBytes *abi_route_fromUint64 *abi_route_bzeroFunction *abi_route_events *abi_route_letOptimization *abi_route_staticContractProperties *abi_route_numberToString *abi_route_methodOnParens *abi_route_stringSubstring *abi_route_idProperty *abi_route_scratchSlot *abi_route_ecdsa *abi_route_verifyTxnTypes *abi_route_stringPlusEquals *abi_route_importedProgram *abi_route_callPrivateDefinedLater *abi_route_interalPublicMethod *abi_route_callInternalPublicMethod *abi_route_appLoadScratch *abi_route_uintNWithUnderscore *abi_route_opUp *abi_route_returnValueOnAssignment *abi_route_returnArrayValueOnAssignment *abi_route_returnStorageValueOnAssignment *abi_route_returnOperatorAssignmentValue *abi_route_returnArrayValueOnOperatorAssignment *abi_route_returnArrayInStorageValueOnOperatorAssignment *abi_route_consts *abi_route_assertWithMessage *abi_route_opcodeAliases *abi_route_vrfVerifyOp *abi_route_ecMath *abi_route_gitxn *abi_route_getSetBytes *abi_route_getSetUint64 *abi_route_blockOp *abi_route_b64 *abi_route_json *abi_route_bitlenOp *abi_route_computedConst *abi_route_multiComputedConst *abi_route_computedConstAsStaticArrayLength *abi_route_readSchema *abi_route_comparisonOr *abi_route_txnArgsMethod *abi_route_callTxnArgsMethod *abi_route_staticValueLen *abi_route_staticTypeLen *abi_route_dynamicScratchSlot *abi_route_incrementScratchSlot
2382+
match *abi_route_txnTypeEnum *abi_route_txnGroupLength *abi_route_asserts *abi_route_verifyTxnFromArg *abi_route_verifyTxnFromTxnGroup *abi_route_verifyTxnCondition *abi_route_verifyTxnIncludedIn *abi_route_verifyTxnNotIncludedIn *abi_route_submitPendingGroup *abi_route_methodWithTxnArgs *abi_route_shift *abi_route_fromBytes *abi_route_fromUint64 *abi_route_bzeroFunction *abi_route_events *abi_route_letOptimization *abi_route_staticContractProperties *abi_route_numberToString *abi_route_methodOnParens *abi_route_stringSubstring *abi_route_idProperty *abi_route_scratchSlot *abi_route_ecdsa *abi_route_verifyTxnTypes *abi_route_stringPlusEquals *abi_route_importedProgram *abi_route_callPrivateDefinedLater *abi_route_interalPublicMethod *abi_route_callInternalPublicMethod *abi_route_appLoadScratch *abi_route_uintNWithUnderscore *abi_route_opUp *abi_route_returnValueOnAssignment *abi_route_returnArrayValueOnAssignment *abi_route_returnStorageValueOnAssignment *abi_route_returnOperatorAssignmentValue *abi_route_returnArrayValueOnOperatorAssignment *abi_route_returnArrayInStorageValueOnOperatorAssignment *abi_route_consts *abi_route_assertWithMessage *abi_route_opcodeAliases *abi_route_vrfVerifyOp *abi_route_ecMath *abi_route_gitxn *abi_route_getSetBytes *abi_route_getSetUint64 *abi_route_blockOp *abi_route_b64 *abi_route_json *abi_route_bitlenOp *abi_route_computedConst *abi_route_multiComputedConst *abi_route_computedConstAsStaticArrayLength *abi_route_readSchema *abi_route_comparisonOr *abi_route_txnArgsMethod *abi_route_callTxnArgsMethod *abi_route_staticValueLen *abi_route_staticTypeLen *abi_route_dynamicScratchSlot *abi_route_incrementScratchSlot *abi_route_incrementDynamicScratchSlot
23462383
err
23472384

23482385
*intToAscii:

tests/contracts/artifacts/GeneralTest.arc32.json

Lines changed: 13 additions & 1 deletion
Large diffs are not rendered by default.

tests/contracts/artifacts/GeneralTest.arc4.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@
485485
"type": "void"
486486
}
487487
},
488+
{
489+
"name": "incrementDynamicScratchSlot",
490+
"args": [],
491+
"returns": {
492+
"type": "void"
493+
}
494+
},
488495
{
489496
"name": "createApplication",
490497
"args": [],

tests/contracts/general.algo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,10 @@ class GeneralTest extends Contract {
449449
this.scratch.value += 1;
450450
assert(this.scratch.value === 1338);
451451
}
452+
453+
incrementDynamicScratchSlot(): void {
454+
this.dynamicScratch(2).value = 1337;
455+
this.dynamicScratch(2).value += 1;
456+
assert(this.dynamicScratch(2).value === 1338);
457+
}
452458
}

tests/general.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('General', function () {
3737
'opUp',
3838
'dynamicScratchSlot',
3939
'incrementScratchSlot',
40+
'incrementDynamicScratchSlot',
4041
].forEach((method) => {
4142
test(method, async function () {
4243
const { appClient } = await compileAndCreate(await sender, PATH, ARTIFACTS_DIR, NAME);

0 commit comments

Comments
 (0)