Skip to content

Commit

Permalink
support constraints for both store and load
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 9, 2023
1 parent 2bde57d commit a0def47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions generated_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ export function storeHmLabel(hmLabel: HmLabel): (builder: Builder) => void {
hmLabel.s.forEach((arg: BitString) => {
builder.storeBits(arg);
});
if ((!(hmLabel.n <= hmLabel.m))) {
throw new Error('');
};
};
};
if ((hmLabel.kind == 'HmLabel_hml_long')) {
Expand Down Expand Up @@ -1467,5 +1470,8 @@ export function loadImplicitCondition(slice: Slice): ImplicitCondition {
export function storeImplicitCondition(implicitCondition: ImplicitCondition): (builder: Builder) => void {
return (builder: Builder) => {
builder.storeUint(implicitCondition.flags, 10);
if ((!(implicitCondition.flags <= 100))) {
throw new Error('');
};
};
}
1 change: 1 addition & 0 deletions src/codegen/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function generate(tree: Program) {

constructor.constraints.forEach(constraint => {
constructorLoadStatements.push(tIfStatement(tUnaryOpExpression('!', convertToAST(constraint, constructor, true)), [tExpressionStatement(tIdentifier("throw new Error('')"))]));
subStructStoreStatements.push(tIfStatement(tUnaryOpExpression('!', convertToAST(constraint, constructor, true, tIdentifier(variableCombinatorName))), [tExpressionStatement(tIdentifier("throw new Error('')"))]))
});

constructorLoadStatements.push(tReturnStatement(tObjectExpression(subStructLoadProperties)));
Expand Down
15 changes: 13 additions & 2 deletions tests/tlbgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,19 @@ describe('Generating tlb code', () => {
})

test('Exceptions', () => {
let implicitCondition: ImplicitCondition = {kind: 'ImplicitCondition', flags: 200}
checkThrowOnStoreLoad(implicitCondition, loadImplicitCondition, storeImplicitCondition);
let implicitConditionIncorrect: ImplicitCondition = {kind: 'ImplicitCondition', flags: 200}
checkThrowOnStoreLoad(implicitConditionIncorrect, loadImplicitCondition, storeImplicitCondition);

let implicitCondition: ImplicitCondition = {kind: 'ImplicitCondition', flags: 100}
checkSameOnStoreLoad(implicitCondition, loadImplicitCondition, storeImplicitCondition);

let implicitConditionIncorrectCell = beginCell().storeUint(200, 10).endCell().beginParse();
expect(() => {
loadImplicitCondition(implicitConditionIncorrectCell)
}).toThrow(Error);

let implicitConditionCell = beginCell().storeUint(100, 10).endCell().beginParse();
expect(loadImplicitCondition(implicitConditionCell).flags == 100).toBeTruthy()
})

test('Hashmap', () => {
Expand Down

0 comments on commit a0def47

Please sign in to comment.