gofront 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/codegen/index.js +6 -4
- package/src/typechecker/index.js +25 -29
package/package.json
CHANGED
package/src/codegen/index.js
CHANGED
|
@@ -127,14 +127,16 @@ export class CodeGen {
|
|
|
127
127
|
|
|
128
128
|
_emitVarConstDecls(program) {
|
|
129
129
|
for (const d of program.decls) {
|
|
130
|
-
if (d.kind === "
|
|
130
|
+
if (d.kind === "ConstDecl") {
|
|
131
131
|
this._currentSrcFileIdx = d._srcFileIdx ?? 0;
|
|
132
|
-
this.
|
|
132
|
+
this.genConstDecl(d);
|
|
133
133
|
this.blank();
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
}
|
|
136
|
+
for (const d of program.decls) {
|
|
137
|
+
if (d.kind === "VarDecl") {
|
|
136
138
|
this._currentSrcFileIdx = d._srcFileIdx ?? 0;
|
|
137
|
-
this.
|
|
139
|
+
this.genVarDecl(d);
|
|
138
140
|
this.blank();
|
|
139
141
|
}
|
|
140
142
|
}
|
package/src/typechecker/index.js
CHANGED
|
@@ -140,26 +140,7 @@ export class TypeChecker {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
check(program) {
|
|
143
|
-
this.
|
|
144
|
-
// Pass 1: collect type declarations
|
|
145
|
-
for (const decl of program.decls) {
|
|
146
|
-
if (decl.kind === "TypeDecl") this.collectType(decl);
|
|
147
|
-
}
|
|
148
|
-
// Pass 2: collect function / method signatures
|
|
149
|
-
for (const decl of program.decls) {
|
|
150
|
-
if (decl.kind === "FuncDecl" || decl.kind === "MethodDecl") {
|
|
151
|
-
this.collectFunc(decl);
|
|
152
|
-
} else if (decl.kind === "TemplDecl") {
|
|
153
|
-
this._collectTemplDecl(decl);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// Pass 2.1: Promote embedded methods
|
|
157
|
-
this._promoteEmbeddedMethods();
|
|
158
|
-
// Pass 3: check bodies
|
|
159
|
-
for (const decl of program.decls) {
|
|
160
|
-
this.checkTopDecl(decl, this.globals);
|
|
161
|
-
}
|
|
162
|
-
return this.errors;
|
|
143
|
+
return this.checkAll([program]);
|
|
163
144
|
}
|
|
164
145
|
|
|
165
146
|
// Pre-declare a package-level var so other files can reference its name
|
|
@@ -195,6 +176,15 @@ export class TypeChecker {
|
|
|
195
176
|
}
|
|
196
177
|
|
|
197
178
|
_collectTypesPass(programs) {
|
|
179
|
+
for (const p of programs) {
|
|
180
|
+
for (const d of p.decls) {
|
|
181
|
+
if (d.kind === "TypeDecl" && !d.isAlias && !this.types.has(d.name)) {
|
|
182
|
+
const placeholder = { kind: "named", name: d.name, underlying: null };
|
|
183
|
+
this.types.set(d.name, placeholder);
|
|
184
|
+
this.globals.define(d.name, placeholder);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
198
188
|
for (const p of programs) {
|
|
199
189
|
this._setCurrentFile(p);
|
|
200
190
|
for (const d of p.decls) if (d.kind === "TypeDecl") this.collectType(d);
|
|
@@ -274,14 +264,15 @@ export class TypeChecker {
|
|
|
274
264
|
return t;
|
|
275
265
|
});
|
|
276
266
|
const underlying = this.resolveTypeNode(decl.type, typeScope);
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
267
|
+
const existing = this.types.get(decl.name);
|
|
268
|
+
const named =
|
|
269
|
+
existing?.kind === "named"
|
|
270
|
+
? existing
|
|
271
|
+
: { kind: "named", name: decl.name };
|
|
272
|
+
named.underlying = underlying;
|
|
273
|
+
named._generic = {
|
|
274
|
+
typeParams: typeParamTypes,
|
|
275
|
+
declNode: decl,
|
|
285
276
|
};
|
|
286
277
|
if (underlying.kind === "struct") {
|
|
287
278
|
underlying.name = decl.name;
|
|
@@ -298,7 +289,12 @@ export class TypeChecker {
|
|
|
298
289
|
this.globals.define(decl.name, underlying);
|
|
299
290
|
return;
|
|
300
291
|
}
|
|
301
|
-
const
|
|
292
|
+
const existing = this.types.get(decl.name);
|
|
293
|
+
const named =
|
|
294
|
+
existing?.kind === "named"
|
|
295
|
+
? existing
|
|
296
|
+
: { kind: "named", name: decl.name };
|
|
297
|
+
named.underlying = underlying;
|
|
302
298
|
if (underlying.kind === "struct") {
|
|
303
299
|
underlying.name = decl.name;
|
|
304
300
|
underlying.methods = new Map();
|