-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
+ Func syntax tree + Essential functionality Func formatter + A new `codegen` package that includes the updated backend + Hacks in the compilation pipeline that allow to use both backends which is needed for differential testing.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AstExpression, SrcInfo } from "../grammar/ast"; | ||
import { CompilerContext } from "../context"; | ||
import { TypeRef } from "../types/types"; | ||
import { FuncAstExpr } from "../func/syntax"; | ||
|
||
/** | ||
* A static map of functions defining Func expressions for Tact ABI functions and methods. | ||
*/ | ||
export type AbiFunction = { | ||
name: string; | ||
resolve: (ctx: CompilerContext, args: TypeRef[], loc: SrcInfo) => TypeRef; | ||
generate: ( | ||
args: TypeRef[], | ||
resolved: AstExpression[], | ||
loc: SrcInfo, | ||
) => FuncAstExpr; | ||
}; | ||
|
||
// TODO | ||
export const MapFunctions: Map<string, AbiFunction> = new Map([]); | ||
|
||
// TODO | ||
export const StructFunctions: Map<string, AbiFunction> = new Map([]); | ||
|
||
// TODO | ||
export const GlobalFunctions: Map<string, AbiFunction> = new Map([]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { CompilerContext } from "../context"; | ||
import { getAllTypes } from "../types/resolveDescriptors"; | ||
import { TypeDescription } from "../types/types"; | ||
import { getSortedTypes } from "../storage/resolveAllocation"; | ||
import { FuncAstModule, FuncAstComment } from "../func/syntax"; | ||
import { FunctionGen } from "./function"; | ||
|
||
/** | ||
* Encapsulates generation of Func contracts from the Tact contract. | ||
*/ | ||
export class ContractGen { | ||
private constructor( | ||
private ctx: CompilerContext, | ||
private contractName: string, | ||
private abiName: string, | ||
) {} | ||
|
||
static fromTact( | ||
ctx: CompilerContext, | ||
contractName: string, | ||
abiName: string, | ||
): ContractGen { | ||
return new ContractGen(ctx, contractName, abiName); | ||
} | ||
|
||
/** | ||
* Adds stdlib definitions to the generated module. | ||
*/ | ||
private addStdlib(m: FuncAstModule): void { | ||
Check failure on line 29 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 29 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
private addSerializers(m: FuncAstModule): void { | ||
Check failure on line 33 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 33 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
const sortedTypes = getSortedTypes(this.ctx); | ||
for (const t of sortedTypes) { | ||
Check failure on line 35 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 35 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 35 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
Check failure on line 35 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
Check failure on line 35 in src/codegen/contract.ts GitHub Actions / test (20, macos-latest)
|
||
} | ||
} | ||
|
||
private addAccessors(m: FuncAstModule): void { | ||
Check failure on line 39 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 39 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
private addInitSerializer(m: FuncAstModule): void { | ||
Check failure on line 43 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 43 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
private addStorageFunctions(m: FuncAstModule): void { | ||
Check failure on line 47 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 47 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
private addStaticFunctions(m: FuncAstModule): void { | ||
Check failure on line 51 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 51 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
private addExtensions(m: FuncAstModule): void { | ||
Check failure on line 55 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 55 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
// TODO | ||
} | ||
|
||
/** | ||
* Adds functions defined within the Tact contract to the generated Func module. | ||
* TODO: Why do we need function from *all* the contracts? | ||
*/ | ||
private addContractFunctions(m: FuncAstModule, c: TypeDescription): void { | ||
// TODO: Generate init | ||
for (const tactFun of c.functions.values()) { | ||
const funcFun = FunctionGen.fromTact(this.ctx, tactFun).generate(); | ||
Check failure on line 66 in src/codegen/contract.ts GitHub Actions / test (20, ubuntu-latest)
Check failure on line 66 in src/codegen/contract.ts GitHub Actions / test (20, windows-latest)
|
||
} | ||
} | ||
|
||
private addMain(m: FuncAstModule): void { | ||
// TODO | ||
} | ||
|
||
/** | ||
* Adds a comment entry to the module. | ||
*/ | ||
private addComment(m: FuncAstModule, c: FuncAstComment): void { | ||
m.entries.push(c); | ||
} | ||
|
||
public generate(): FuncAstModule { | ||
const m: FuncAstModule = { kind: "module", entries: [] }; | ||
|
||
const allTypes = Object.values(getAllTypes(this.ctx)); | ||
const contracts = allTypes.filter((v) => v.kind === "contract"); | ||
const contract = contracts.find((v) => v.name === this.contractName); | ||
if (contract === undefined) { | ||
throw Error(`Contract "${this.contractName}" not found`); | ||
} | ||
|
||
this.addStdlib(m); | ||
this.addSerializers(m); | ||
this.addAccessors(m); | ||
this.addInitSerializer(m); | ||
this.addStorageFunctions(m); | ||
this.addStaticFunctions(m); | ||
this.addExtensions(m); | ||
contracts.forEach((c) => this.addContractFunctions(m, c)); | ||
this.addMain(m); | ||
|
||
return m; | ||
} | ||
} |