-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathresolveAllocation.spec.ts
85 lines (74 loc) · 1.86 KB
/
resolveAllocation.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import fs from "fs";
import { resolveDescriptors } from "../types/resolveDescriptors";
import { getAllocations, resolveAllocations } from "./resolveAllocation";
import { openContext, parseModules } from "../context/store";
import { resolveStatements } from "../types/resolveStatements";
import { CompilerContext } from "../context/context";
import { resolveSignatures } from "../types/resolveSignatures";
import path from "path";
import { getParser } from "../grammar";
import { getAstFactory } from "../ast/ast-helpers";
import { stdlibPath } from "../stdlib/path";
import type { Source } from "../imports/source";
const primitivesPath = path.join(stdlibPath, "/std/internal/primitives.tact");
const stdlib = fs.readFileSync(primitivesPath, "utf-8");
const src = `
trait BaseTrait {
}
struct Point3 {
a: Point;
b: Point2;
}
struct Point {
x: Int;
y: Int;
}
struct Point2 {
z: Point;
}
struct Deep {
a: Int;
b: Int;
c: Int;
d: Int;
e: Int;
f: Int;
g: Int;
h: Int;
i: Int;
j: Int;
k: Int;
}
struct Deep2 {
a: Deep;
b: Deep;
c: Deep;
}
contract Sample {
v: Int = 0;
init() {
}
fun main(a: Int, b: Int) {
}
}
`;
describe("resolveAllocation", () => {
it("should write program", () => {
const ast = getAstFactory();
const sources: Source[] = [
{ code: stdlib, path: primitivesPath, origin: "stdlib" },
{ code: src, path: "<unknown>", origin: "user" },
];
let ctx = openContext(
new CompilerContext(),
sources,
[],
parseModules(sources, getParser(ast)),
);
ctx = resolveDescriptors(ctx, ast);
ctx = resolveSignatures(ctx, ast);
ctx = resolveStatements(ctx);
ctx = resolveAllocations(ctx);
expect(getAllocations(ctx)).toMatchSnapshot();
});
});