Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Nov 8, 2024
1 parent eb1f751 commit a3bda54
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 54 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [
"**/?(*.)+(spec|test).[j]s?(x)"
"**/?(*.)+(spec|test).[j|t]s?(x)"
]
};
1 change: 1 addition & 0 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type TLBHashmapType = {
key: TLBMathExprType;
value: TLBFieldType;
extra?: TLBFieldType;
directStore: boolean;
}

export type TLBCellType = {
Expand Down
11 changes: 9 additions & 2 deletions src/astbuilder/handle_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function getType(
if (key.kind != 'TLBExprMathType') {
throw new Error('Hashmap key should be number')
}
return { kind: "TLBHashmapType", key: key, value: value };
return { kind: "TLBHashmapType", key: key, value: value, directStore: false };
} else if (expr.name == "HashmapAugE") {
if (expr.args.length != 3) {
throw new Error('Not enough arguments for HashmapAugE')
Expand All @@ -181,7 +181,14 @@ export function getType(
if (key.kind != 'TLBExprMathType') {
throw new Error('Hashmap key should be number')
}
return { kind: "TLBHashmapType", key: key, value: value, extra: extra };
return { kind: "TLBHashmapType", key: key, value: value, extra: extra, directStore: false };
} else if (expr.name == "Hashmap") {
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, directStore: true };
} else if (
expr.name == "VarUInteger" &&
(expr.args[0] instanceof MathExpr ||
Expand Down
8 changes: 4 additions & 4 deletions src/generators/typescript/complex_expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ export function negationDerivationFuncDecl(
)
);
}
export function dictStoreStmt(currentCell: string, storeParametersInside: Expression[], keyForStore: Expression, valueStore: ObjectExpression): Statement | undefined {
return tExpressionStatement(tFunctionCall(tMemberExpression(id(currentCell), id('storeDict')), storeParametersInside.concat([keyForStore, valueStore])));
export function dictStoreStmt(currentCell: string, storeParametersInside: Expression[], keyForStore: Expression, valueStore: ObjectExpression, direct: boolean): Statement | undefined {
return tExpressionStatement(tFunctionCall(tMemberExpression(id(currentCell), id('storeDict' + (direct ? 'Direct' : ''))), storeParametersInside.concat([keyForStore, valueStore])));
}
export function dictTypeParamExpr(fieldType: TLBHashmapType, typeParamExpr: TypeExpression): TypeExpression | undefined {
return tTypeWithParameters(id('Dictionary'), tTypeParametersExpression([(isBigIntExpr(fieldType.key) ? id('bigint') : id('number')), typeParamExpr]));
Expand All @@ -352,8 +352,8 @@ export function dictValueStore(typeParamExpr: TypeExpression, storeFunctionExpr:
)
]);
}
export function dictLoadExpr(keyForLoad: Expression, loadFunctionExpr: Expression, currentSlice: string): Expression | undefined {
return tFunctionCall(tMemberExpression(id('Dictionary'), id('load')), [keyForLoad, dictValueLoad(loadFunctionExpr), id(currentSlice)]);
export function dictLoadExpr(keyForLoad: Expression, loadFunctionExpr: Expression, currentSlice: string, direct: boolean): Expression | undefined {
return tFunctionCall(tMemberExpression(id('Dictionary'), id('load' + (direct ? 'Direct' : ''))), [keyForLoad, dictValueLoad(loadFunctionExpr), id(currentSlice)]);
}
function dictValueLoad(loadFunctionExpr: Expression) {
return tObjectExpression([
Expand Down
9 changes: 4 additions & 5 deletions src/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,6 @@ export function storeBool(bool: Bool): (builder: Builder) => void {
let keyForStore: Expression = dictKeyExpr(fieldType.key, ctx, ctx.typeName);
let subExprInfo = this.handleType(field, fieldType.value, fieldType.extra != undefined, ctx, slicePrefix, argIndex);


if (subExprInfo.typeParamExpr && subExprInfo.loadFunctionExpr && subExprInfo.storeFunctionExpr) {
let valueStore: Expression;
if (fieldType.extra && subExprInfo.loadExpr) {
Expand All @@ -980,15 +979,15 @@ export function storeBool(bool: Bool): (builder: Builder) => void {
valueStore = dictValueStore(subExprInfo.typeParamExpr, subExprInfo.storeFunctionExpr, extraInfo.storeFunctionExpr)

if (extraInfo.loadExpr) {
result.loadExpr = dictLoadExpr(keyForLoad, dictAugParse(extraInfo.loadExpr, subExprInfo.loadExpr), currentSlice)
result.loadExpr = dictLoadExpr(keyForLoad, dictAugParse(extraInfo.loadExpr, subExprInfo.loadExpr), currentSlice, fieldType.directStore)
}
} else {
valueStore = dictValueStore(subExprInfo.typeParamExpr, subExprInfo.storeFunctionExpr)
result.loadExpr = dictLoadExpr(keyForLoad, subExprInfo.loadFunctionExpr, currentSlice)
result.loadExpr = dictLoadExpr(keyForLoad, subExprInfo.loadFunctionExpr, currentSlice, fieldType.directStore)
}
result.typeParamExpr = dictTypeParamExpr(fieldType, subExprInfo.typeParamExpr)
result.storeStmtInside = dictStoreStmt(currentCell, storeParametersInside, keyForStore, valueStore)
result.storeStmtOutside = dictStoreStmt(currentCell, storeParametersOutside, keyForStore, valueStore)
result.storeStmtInside = dictStoreStmt(currentCell, storeParametersInside, keyForStore, valueStore, fieldType.directStore)
result.storeStmtOutside = dictStoreStmt(currentCell, storeParametersOutside, keyForStore, valueStore, fieldType.directStore)
}
} else if (fieldType.kind == "TLBNamedType" && fieldType.arguments.length) {
let typeName = fieldType.name;
Expand Down
Loading

0 comments on commit a3bda54

Please sign in to comment.