Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 14, 2023
1 parent 63743a5 commit 2bda8bb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
11 changes: 5 additions & 6 deletions generated_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Builder } from 'ton'
import { Slice } from 'ton'
import { beginCell } from 'ton'
import { BitString } from 'ton'
import { Cell } from 'ton'
export interface Unit {
readonly kind: 'Unit';
}
Expand Down Expand Up @@ -1141,7 +1142,7 @@ export interface Block {
readonly global_id: number;
readonly info: BlockInfo;
readonly value_flow: ValueFlow;
readonly state_update: MERKLE_UPDATE<ShardState>;
readonly state_update: Cell;
readonly extra: BlockExtra;
}

Expand Down Expand Up @@ -6884,8 +6885,8 @@ export function loadBlock(slice: Slice): Block {
let info: BlockInfo = loadBlockInfo(slice1);
let slice2 = slice.loadRef().beginParse();
let value_flow: ValueFlow = loadValueFlow(slice2);
let slice3 = slice.loadRef().beginParse();
let state_update: MERKLE_UPDATE<ShardState> = loadMERKLE_UPDATE<ShardState>(slice3, loadShardState);
let cell3 = slice.loadRef();
let state_update = cell3;
let slice4 = slice.loadRef().beginParse();
let extra: BlockExtra = loadBlockExtra(slice4);
return {
Expand All @@ -6911,9 +6912,7 @@ export function storeBlock(block: Block): (builder: Builder) => void {
let cell2 = beginCell();
storeValueFlow(block.value_flow)(cell2);
builder.storeRef(cell2);
let cell3 = beginCell();
storeMERKLE_UPDATE<ShardState>(block.state_update, storeShardState)(cell3);
builder.storeRef(cell3);
builder.storeRef(block.state_update);
let cell4 = beginCell();
storeBlockExtra(block.extra)(cell4);
builder.storeRef(cell4);
Expand Down
1 change: 1 addition & 0 deletions generated_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Builder } from 'ton'
import { Slice } from 'ton'
import { beginCell } from 'ton'
import { BitString } from 'ton'
import { Cell } from 'ton'
export interface Simple {
readonly kind: 'Simple';
readonly a: number;
Expand Down
4 changes: 0 additions & 4 deletions src/codegen/combinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export function handleCombinator(expr: ParserExpression, fieldName: string, isFi
insideStoreParameters = [tMemberExpression(tIdentifier(variableCombinatorName), tIdentifier(goodVariableName(fieldName)))];
let insideStoreParameters2: Expression[] = [tIdentifier('arg')]

if (constructor.declaration.combinator.name == 'VarUInteger') {
console.log(expr)
}

if (expr instanceof BuiltinZeroArgs) {
if (expr.name == '#') {
exprForParam = {argLoadExpr: tNumericLiteral(32), argStoreExpr: tNumericLiteral(32), paramType: 'number', fieldLoadStoreSuffix: 'Uint'}
Expand Down
31 changes: 24 additions & 7 deletions src/codegen/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,31 @@ export function handleField(field: FieldDefinition, slicePrefix: Array<number>,
}

if (field.expr instanceof CellRefExpr) {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0)

constructorLoadStatements.push(sliceLoad(slicePrefix, currentSlice))
subStructStoreStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'cell')), tFunctionCall(tIdentifier('beginCell'), []))))
handleField(new FieldNamedDef(fieldName, field.expr.expr), slicePrefix, tlbCode, constructor, constructorLoadStatements, subStructStoreStatements, subStructProperties, subStructLoadProperties, variableCombinatorName, variableSubStructName, jsCodeFunctionsDeclarations, fieldIndex)
subStructStoreStatements.push(tExpressionStatement(tFunctionCall(tMemberExpression(tIdentifier(currentCell), tIdentifier('storeRef')), [tIdentifier(getCurrentSlice(slicePrefix, 'cell'))])))
slicePrefix.pop();
if (field.expr.expr instanceof CombinatorExpr && (field.expr.expr.name == 'MERKLE_UPDATE' || field.expr.expr.name == 'MERKLE_ROOT')) {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0);
constructorLoadStatements.push(
tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'cell')),

tFunctionCall(tMemberExpression(
tIdentifier(currentSlice), tIdentifier('loadRef')
), []),)))
addLoadProperty(goodVariableName(fieldName), tIdentifier(getCurrentSlice(slicePrefix, 'cell')), undefined, constructorLoadStatements, subStructLoadProperties)
subStructProperties.push(tTypedIdentifier(tIdentifier(goodVariableName(fieldName)), tIdentifier('Cell')));
subStructStoreStatements.push(tExpressionStatement(tFunctionCall(tMemberExpression(tIdentifier(currentCell), tIdentifier('storeRef')), [tMemberExpression(tIdentifier(variableCombinatorName), tIdentifier(goodVariableName(fieldName)))])))

// subStructStoreStatements
slicePrefix.pop();
} else {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0)
constructorLoadStatements.push(sliceLoad(slicePrefix, currentSlice))
subStructStoreStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'cell')), tFunctionCall(tIdentifier('beginCell'), []))))
handleField(new FieldNamedDef(fieldName, field.expr.expr), slicePrefix, tlbCode, constructor, constructorLoadStatements, subStructStoreStatements, subStructProperties, subStructLoadProperties, variableCombinatorName, variableSubStructName, jsCodeFunctionsDeclarations, fieldIndex)
subStructStoreStatements.push(tExpressionStatement(tFunctionCall(tMemberExpression(tIdentifier(currentCell), tIdentifier('storeRef')), [tIdentifier(getCurrentSlice(slicePrefix, 'cell'))])))
slicePrefix.pop();
}
}

if (field.expr instanceof CombinatorExpr || field.expr instanceof NameExpr || field.expr instanceof BuiltinZeroArgs || field.expr instanceof BuiltinOneArgExpr || field.expr instanceof MathExpr || field.expr instanceof CondExpr) {
Expand Down
1 change: 1 addition & 0 deletions src/codegen/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function generate(tree: Program, input: string) {
jsCodeDeclarations.push(tImportDeclaration(tIdentifier('Slice'), tStringLiteral('ton'))) // importDeclaration([importSpecifier(identifier('Slice'), identifier('Slice'))], stringLiteral('../boc/Slice')))
jsCodeDeclarations.push(tImportDeclaration(tIdentifier('beginCell'), tStringLiteral('ton')))
jsCodeDeclarations.push(tImportDeclaration(tIdentifier('BitString'), tStringLiteral('ton')))
jsCodeDeclarations.push(tImportDeclaration(tIdentifier('Cell'), tStringLiteral('ton')))

let jsCodeConstructorDeclarations: GenDeclaration[] = []
let jsCodeFunctionsDeclarations: FunctionDeclaration[] = []
Expand Down
2 changes: 1 addition & 1 deletion tests/my.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const fixturesDir = path.resolve(__dirname, 'fixtures')
describe('parsing into intermediate representation using grammar', () => {
test('test.tlb can be parsed', () => {
let builder = beginCell();
// builder.storeUint(5, 0);
builder.storeUint(BigInt(0), 0);


let x = beginCell().endCell().beginParse()
Expand Down
Loading

0 comments on commit 2bda8bb

Please sign in to comment.