Skip to content

Commit 9a03920

Browse files
committed
Removed class generation
1 parent 8364526 commit 9a03920

File tree

6 files changed

+56
-728
lines changed

6 files changed

+56
-728
lines changed

src/compiler.ts

+6-25
Original file line numberDiff line numberDiff line change
@@ -6431,7 +6431,6 @@ export class Compiler extends DiagnosticEmitter {
64316431
let _values = Map_values(locals);
64326432
var exprs = new Array<ExpressionRef>(_values.length);
64336433
assert(type.is(TypeFlags.REFERENCE));
6434-
var closureClass = assert(type.classReference);
64356434
for (let i = 0, k = _values.length; i < k; ++i) {
64366435
let local = unchecked(_values[i]);
64376436
let nativeType = local.type.toNativeType();
@@ -6440,7 +6439,7 @@ export class Compiler extends DiagnosticEmitter {
64406439
module.local_get(closureContextLocal.index, this.options.nativeSizeType),
64416440
module.local_get(local.index, nativeType),
64426441
nativeType,
6443-
closureClass.offsetof(local.name)
6442+
assert(local.closureContextOffset)
64446443
);
64456444
}
64466445
return module.block(null, exprs);
@@ -8208,28 +8207,9 @@ export class Compiler extends DiagnosticEmitter {
82088207
var wasm64 = nativeUsize == NativeType.I64;
82098208

82108209
if(instance.closedLocals.size > 0) {
8211-
// Create field declarations for the function and each closed local
8212-
var members = Array<DeclarationStatement>(instance.closedLocals.size + 1);
8213-
members[0] = this.program.makeNativeMember("__functionPtr", usize.toString())
8214-
for (let _values = Map_values(instance.closedLocals), i = 0, k = _values.length; i < k; ++i) {
8215-
let local = unchecked(_values[i]);
8216-
members[i + 1] = this.program.makeNativeMember(local.name, local.type.intType.toString());
8217-
}
8218-
8219-
// Create a native class prototype with a dummy syntax tree, similar to native functions
8220-
var closureClassPrototype = assert(this.program.makeNativeClassPrototype(
8221-
"closure|" + this.program.nextClassId.toString(),
8222-
members
8223-
));
8224-
8225-
// Resolve this prototype to get the class
8226-
var closureClass = assert(this.resolver.resolveClass(closureClassPrototype, null));
8227-
8228-
// Compile this class to get the type
8229-
this.compileClass(closureClass);
8230-
82318210
// Append the appropriate signature and flags for this closure type, then set it to currentType
8232-
this.currentType = closureClass.type.asClosure(instance.signature)
8211+
this.currentType = Type.closure32;
8212+
this.currentType.signatureReference = instance.signature;
82338213

82348214
// create a local which will hold our closure class instance
82358215
var tempLocal = flow.getAutoreleaseLocal(this.currentType);
@@ -8238,14 +8218,15 @@ export class Compiler extends DiagnosticEmitter {
82388218
// copied closed locals into type
82398219
this.currentType.locals = instance.closedLocals;
82408220

8221+
const closureSize = instance.nextGlobalClosureOffset
82418222

82428223
var closureExpr = this.module.flatten([
82438224
this.module.local_set( // Allocate memory for the closure
82448225
tempLocalIndex,
82458226
this.makeRetain(
82468227
this.module.call(this.program.allocInstance.internalName, [
8247-
wasm64 ? this.module.i64(closureClass.type.byteSize) : this.module.i32(closureClass.type.byteSize),
8248-
wasm64 ? this.module.i64(closureClass.id) : this.module.i32(closureClass.id)
8228+
wasm64 ? this.module.i64(closureSize) : this.module.i32(closureSize),
8229+
wasm64 ? this.module.i64(0) : this.module.i32(0)
82498230
], nativeUsize)
82508231
)
82518232
),

src/program.ts

-42
Original file line numberDiff line numberDiff line change
@@ -671,48 +671,6 @@ export class Program extends DiagnosticEmitter {
671671
);
672672
}
673673

674-
// TODO: make these more generic, purpose built for closures atm
675-
makeNativeMember(
676-
name: string,
677-
type: string
678-
): DeclarationStatement {
679-
return Node.createFieldDeclaration(
680-
Node.createIdentifierExpression(name, this.nativeSource.range),
681-
Node.createNamedType(
682-
Node.createSimpleTypeName(type, this.nativeSource.range),
683-
null,
684-
false,
685-
this.nativeSource.range,
686-
),
687-
null,
688-
null,
689-
CommonFlags.INSTANCE,
690-
this.nativeSource.range
691-
);
692-
}
693-
694-
makeNativeClassDeclaration(name: string, members: DeclarationStatement[]): ClassDeclaration {
695-
return Node.createClassDeclaration(
696-
Node.createIdentifierExpression(name, this.nativeSource.range),
697-
null,
698-
null,
699-
null,
700-
members,
701-
null,
702-
0,
703-
this.nativeSource.range
704-
);
705-
}
706-
707-
makeNativeClassPrototype(name: string, members: DeclarationStatement[]): ClassPrototype | null {
708-
return this.initializeClass(
709-
this.makeNativeClassDeclaration(name, members),
710-
this.nativeFile,
711-
[],
712-
[]
713-
);
714-
}
715-
716674
/** Gets the (possibly merged) program element linked to the specified declaration. */
717675
getElementByDeclaration(declaration: DeclarationStatement): DeclaredElement | null {
718676
var elementsByDeclaration = this.elementsByDeclaration;

src/types.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class Type {
185185
}
186186

187187
get isFunction(): bool {
188-
return this.signatureReference !== null && this.classReference === null;
188+
return this.signatureReference !== null && !this.is(TypeFlags.CLOSURE);
189189
}
190190

191191
/** Computes the sign-extending shift in the target type. */
@@ -535,6 +535,13 @@ export class Type {
535535

536536
/** Alias of i32 indicating type inference of locals and globals with just an initializer. */
537537
static readonly auto: Type = new Type(Type.i32.kind, Type.i32.flags, Type.i32.size);
538+
539+
/** Type of an in-context local */
540+
static readonly closure32: Type = new Type(Type.i32.kind,
541+
TypeFlags.CLOSURE |
542+
TypeFlags.REFERENCE,
543+
Type.i32.size
544+
);
538545
}
539546

540547
/** Converts an array of types to an array of native types. */

0 commit comments

Comments
 (0)