Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 22, 2023
1 parent 80edf5d commit 3455028
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/codegen/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type TLBVariable = {
name: string
deriveExpr?: TLBMathExpr
initialExpr?: TLBMathExpr
isField: boolean

calculated: boolean
}
Expand Down
15 changes: 10 additions & 5 deletions src/codegen/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ export class TypescriptGenerator implements CodeGenerator {
})

let fieldIndex = 0;
declaration?.fields.forEach(fieldDefinition => {
if (fieldDefinition instanceof FieldBuiltinDef && fieldDefinition.type != 'Type') {
subStructProperties.push(tTypedIdentifier(tIdentifier(goodVariableName(fieldDefinition.name)), tIdentifier('number')));
let parameter = constructor.parametersMap.get(fieldDefinition.name)
constructor.variables.forEach(variable => {
if (variable.type == '#' && !variable.isField) {
subStructProperties.push(tTypedIdentifier(tIdentifier(goodVariableName(variable.name)), tIdentifier('number')));
let parameter = constructor.parametersMap.get(variable.name)
if (parameter && !parameter.variable.const && !parameter.variable.negated) {
subStructLoadProperties.push(tObjectProperty(tIdentifier(goodVariableName(fieldDefinition.name)), getParamVarExpr(parameter, constructor)))
subStructLoadProperties.push(tObjectProperty(tIdentifier(goodVariableName(variable.name)), getParamVarExpr(parameter, constructor)))
}
}
})
declaration?.fields.forEach(fieldDefinition => {
if (fieldDefinition instanceof FieldBuiltinDef && fieldDefinition.type == '#') {

}
});

Expand Down
8 changes: 4 additions & 4 deletions src/codegen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ export function fillConstructors(declarations: Declaration[], tlbCode: TLBCode,
tlbType.constructors.forEach(constructor => {
constructor.declaration?.fields.forEach(field => {
if (field instanceof FieldBuiltinDef) {
constructor.variables.push({ name: field.name, const: false, negated: false, type: field.type, calculated: false })
constructor.variables.push({ name: field.name, const: false, negated: false, type: field.type, calculated: false, isField: false })
}
if (field instanceof FieldNamedDef) {
constructor.variables.push({ name: field.name, const: false, negated: false, type: '#', calculated: false })
constructor.variables.push({ name: field.name, const: false, negated: false, type: '#', calculated: false, isField: true })
}
})
constructor.variables.forEach(variable => {
Expand Down Expand Up @@ -471,12 +471,12 @@ export function fillConstructors(declarations: Declaration[], tlbCode: TLBCode,
variable.initialExpr = derivedExpr.derived
parameter = { variable: variable, paramExpr: derivedExpr.derived}
} else if (derivedExpr.name == '' && toBeConst) {
parameter = { variable: { negated: true, const: toBeConst, type: '#', name: derivedExpr.name, deriveExpr: derivedExpr.derived, initialExpr: derivedExpr.derived, calculated: false }, paramExpr: derivedExpr.derived };
parameter = { variable: { negated: true, const: toBeConst, type: '#', name: derivedExpr.name, deriveExpr: derivedExpr.derived, initialExpr: derivedExpr.derived, calculated: false, isField: false }, paramExpr: derivedExpr.derived };
} else {
throw new Error('Cannot identify combinator arg')
}
} else if (element instanceof NumberExpr) {
parameter = { variable: { negated: false, const: true, type: '#', name: '', deriveExpr: new TLBNumberExpr(element.num), initialExpr: new TLBNumberExpr(element.num), calculated: false }, paramExpr: new TLBNumberExpr(element.num) }
parameter = { variable: { negated: false, const: true, type: '#', name: '', deriveExpr: new TLBNumberExpr(element.num), initialExpr: new TLBNumberExpr(element.num), calculated: false, isField: false }, paramExpr: new TLBNumberExpr(element.num) }
} else {
throw new Error('Cannot identify combinator arg: ' + element)
}
Expand Down

0 comments on commit 3455028

Please sign in to comment.