Skip to content

Commit

Permalink
fix load statment on new slices
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Nov 17, 2023
1 parent 0a9f0a8 commit 4a2d799
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
42 changes: 21 additions & 21 deletions generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ export type Bool_bool_true = {
b: number;
};
export function loadBool(slice: Slice): Bool {
let a: number;
a = slice.loadUint(32);
let b: number;
b = slice.loadUint(7);
let c: number;
c = slice.loadUint(32);
if (slice.preloadUint(1) == 0b0) {
let a: number;
a = slice.loadUint(32);
let b: number;
b = slice.loadUint(7);
let c: number;
c = slice.loadUint(32);
return {
kind: 'Bool_bool_false',
a: a,
b: b,
c: c
};
};
b = slice.loadUint(32);
if (slice.preloadUint(1) == 0b1) {
b = slice.loadUint(32);
return {
kind: 'Bool_bool_true',
b: b
Expand Down Expand Up @@ -568,9 +568,9 @@ export function loadHashmapNode<X>(slice: Slice, n: number, loadX: (slice: Slice
value: loadX(slice)
};
};
let slice1 = slice.loadRef().beginParse();
let slice2 = slice.loadRef().beginParse();
if (true) {
let slice1 = slice.loadRef().beginParse();
let slice2 = slice.loadRef().beginParse();
return {
kind: 'HashmapNode_hmn_fork',
left: loadHashmap<X>(slice1, n, loadX),
Expand Down Expand Up @@ -627,9 +627,9 @@ export function loadHmLabel(slice: Slice, m: number): HmLabel {
m: m
};
};
let v: BitString;
v = slice.loadBits(1);
if (slice.preloadUint(2) == 0b11) {
let v: BitString;
v = slice.loadBits(1);
return {
kind: 'HmLabel_hml_same',
m: m,
Expand Down Expand Up @@ -709,19 +709,19 @@ export type Same_t<X> = {
z: number;
};
export function loadSame<X>(slice: Slice, loadX: (slice: Slice) => X): Same<X> {
let x: number;
x = slice.loadUint(32);
if (slice.preloadUint(1) == 0b0) {
let x: number;
x = slice.loadUint(32);
return {
kind: 'Same_g',
x: x
};
};
let y: number;
y = slice.loadUint(32);
let z: number;
z = slice.loadUint(32);
if (slice.preloadUint(1) == 0b1) {
let y: number;
y = slice.loadUint(32);
let z: number;
z = slice.loadUint(32);
return {
kind: 'Same_t',
y: y,
Expand Down Expand Up @@ -757,17 +757,17 @@ export type Const_b = {
y: number;
};
export function loadConst(slice: Slice, n: number): Const {
let x: number;
x = slice.loadUint(32);
if (slice.preloadUint(1) == 0b0) {
let x: number;
x = slice.loadUint(32);
return {
kind: 'Const_a',
x: x
};
};
let y: number;
y = slice.loadUint(2);
if (slice.preloadUint(1) == 0b1) {
let y: number;
y = slice.loadUint(2);
return {
kind: 'Const_b',
X: X,
Expand Down
17 changes: 9 additions & 8 deletions tests/my.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ describe('parsing into intermediate representation using grammar', () => {
let variablesDeclared = new Set<string>;

tlbType.constructors.forEach(constructor => {
let constructorLoadStatements: Statement[] = []
let declaration = constructor.declaration;
let subStructName: string;
if (tlbType.constructors.length > 1) {
Expand Down Expand Up @@ -738,7 +739,7 @@ describe('parsing into intermediate representation using grammar', () => {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0)

loadStatements.push(
constructorLoadStatements.push(
tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'slice')),
tFunctionCall(tMemberExpression(
tFunctionCall(tMemberExpression(
Expand Down Expand Up @@ -804,7 +805,7 @@ describe('parsing into intermediate representation using grammar', () => {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0)

loadStatements.push(
constructorLoadStatements.push(
tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'slice')),
tFunctionCall(tMemberExpression(
tFunctionCall(tMemberExpression(
Expand Down Expand Up @@ -970,9 +971,9 @@ describe('parsing into intermediate representation using grammar', () => {
}
if (!variablesDeclared.has(field.name)) {
variablesDeclared.add(field.name);
loadStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(field.name), undefined, tIdentifier(fieldType))))
constructorLoadStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(field.name), undefined, tIdentifier(fieldType))))
}
loadStatements.push(tExpressionStatement(tBinaryExpression(tIdentifier(field.name), '=', loadSt)))
constructorLoadStatements.push(tExpressionStatement(tBinaryExpression(tIdentifier(field.name), '=', loadSt)))
subStructProperties.push(tTypedIdentifier(tIdentifier(field.name), tIdentifier(fieldType)))
subStructLoadProperties.push(tObjectProperty(tIdentifier(field.name), tIdentifier(field.name)))
let storeParams: Expression[] = [tMemberExpression(tIdentifier(variableCombinatorName), tIdentifier(field.name))];
Expand All @@ -990,8 +991,7 @@ describe('parsing into intermediate representation using grammar', () => {

let structX = tStructDeclaration(tIdentifier(subStructName), subStructProperties, structTypeParametersExpr);

let loadStatement: Statement;
loadStatement = tReturnStatement(tObjectExpression(subStructLoadProperties));
constructorLoadStatements.push(tReturnStatement(tObjectExpression(subStructLoadProperties)));
if (tlbType.constructors.length > 1) {
let conditions: Array<BinaryExpression> = []
if (tagBinary[tagBinary.length - 1] != '_') {
Expand All @@ -1003,9 +1003,10 @@ describe('parsing into intermediate representation using grammar', () => {
}
});
}
loadStatement = tIfStatement(getCondition(conditions), [loadStatement])
loadStatements.push(tIfStatement(getCondition(conditions), constructorLoadStatements))
} else {
loadStatements = loadStatements.concat(constructorLoadStatements);
}
loadStatements.push(loadStatement)

if (tlbType.constructors.length > 1 && tagBinary[tagBinary.length - 1] != '_') {
let preStoreStatement: Statement[] = [tExpressionStatement(tFunctionCall(tMemberExpression(tIdentifier('builder'), tIdentifier('storeUint')), [tIdentifier(tagBinary), tNumericLiteral(tagBitLen)]))];
Expand Down

0 comments on commit 4a2d799

Please sign in to comment.