Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Jan 14, 2024
1 parent 5106ea0 commit f067ed7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export type TLBVarIntegerType = {

export type TLBHashmapType = {
kind: "TLBHashmapType";
key: TLBMathExprType,
value: TLBFieldType
key: TLBMathExprType;
value: TLBFieldType;
extra?: TLBFieldType;
}

export type TLBCellType = {
Expand Down
13 changes: 12 additions & 1 deletion src/astbuilder/handle_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,25 @@ export function getType(
};
} else if (expr.name == "HashmapE") {
if (expr.args.length != 2) {
throw new Error('')
throw new Error('Not enough arguments for HashmapE')
}
let key = getType(expr.args[0], constructor, fieldTypeName)
let value = getType(expr.args[1], constructor, fieldTypeName)
if (key.kind != 'TLBExprMathType') {
throw new Error('Hashmap key should be number')
}
return { kind: "TLBHashmapType", key: key, value: value };
} else if (expr.name == "HashmapAugE") {
if (expr.args.length != 3) {
throw new Error('Not enough arguments for HashmapAugE')
}
let key = getType(expr.args[0], constructor, fieldTypeName)
let value = getType(expr.args[1], constructor, fieldTypeName)
let extra = getType(expr.args[2], constructor, fieldTypeName)
if (key.kind != 'TLBExprMathType') {
throw new Error('Hashmap key should be number')
}
return { kind: "TLBHashmapType", key: key, value: value, extra: extra };
} else if (
expr.name == "VarUInteger" &&
(expr.args[0] instanceof MathExpr ||
Expand Down
28 changes: 24 additions & 4 deletions test/generated_files/generated_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Address } from 'ton'
import { ExternalAddress } from 'ton'
import { Dictionary } from 'ton'
import { DictionaryValue } from 'ton'
import util from 'util'
export function bitLen(n: number) {
return n.toString(2).length;;
}
Expand Down Expand Up @@ -1105,7 +1106,7 @@ export interface AccountBlock {

export interface ShardAccountBlocks {
readonly kind: 'ShardAccountBlocks';
readonly anon0: HashmapAugE<AccountBlock, CurrencyCollection>;
readonly anon0: Dictionary<bigint, {accountBlock: AccountBlock, currencyCollection: CurrencyCollection}>;
}

/*
Expand Down Expand Up @@ -6963,18 +6964,37 @@ export function storeAccountBlock(accountBlock: AccountBlock): (builder: Builder

// _ (HashmapAugE 256 AccountBlock CurrencyCollection) = ShardAccountBlocks;

const dictValueShardAccountBlocks: DictionaryValue<{accountBlock: AccountBlock, currencyCollection: CurrencyCollection}> = {
serialize: (arg, builder) => {
console.log('serializing now')
builder.store(storeCurrencyCollection(arg.currencyCollection));
builder.store(storeAccountBlock(arg.accountBlock));
},
parse: (slice: Slice) => {
console.log('parsing now')
let currencyCollection = loadCurrencyCollection(slice);
let accountBlock = loadAccountBlock(slice);
return {
accountBlock,
currencyCollection
}
}
}

export function loadShardAccountBlocks(slice: Slice): ShardAccountBlocks {
let anon0: HashmapAugE<AccountBlock, CurrencyCollection> = loadHashmapAugE<AccountBlock, CurrencyCollection>(slice, 256, loadAccountBlock, loadCurrencyCollection);
let anon0: Dictionary<bigint, {accountBlock: AccountBlock, currencyCollection: CurrencyCollection}> = Dictionary.load(Dictionary.Keys.BigUint(256), dictValueShardAccountBlocks, slice)
// console.log(util.inspect(anon0, false, null, true))
// let anon0: HashmapAugE<AccountBlock, CurrencyCollection> = loadHashmapAugE<AccountBlock, CurrencyCollection>(slice, 256, loadAccountBlock, loadCurrencyCollection);
return {
kind: 'ShardAccountBlocks',
anon0: anon0,
}

}

export function storeShardAccountBlocks(shardAccountBlocks: ShardAccountBlocks): (builder: Builder) => void {
return ((builder: Builder) => {
storeHashmapAugE<AccountBlock, CurrencyCollection>(shardAccountBlocks.anon0, storeAccountBlock, storeCurrencyCollection)(builder);
builder.storeDict(shardAccountBlocks.anon0, Dictionary.Keys.BigUint(256), dictValueShardAccountBlocks)
// storeHashmapAugE<AccountBlock, CurrencyCollection>(shardAccountBlocks.anon0, storeAccountBlock, storeCurrencyCollection)(builder);
})

}
Expand Down

0 comments on commit f067ed7

Please sign in to comment.