Skip to content

Commit 62edd61

Browse files
committed
cleanup
1 parent 451706b commit 62edd61

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/compiler.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,7 @@ export class Compiler extends DiagnosticEmitter {
11091109
if (instance.is(CommonFlags.CONSTRUCTOR)) {
11101110
let nativeSizeType = this.options.nativeSizeType;
11111111
assert(instance.is(CommonFlags.INSTANCE));
1112-
let parent = assert(instance.parent);
1113-
assert(parent.kind == ElementKind.CLASS);
1112+
let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS);
11141113

11151114
// implicitly return `this` if the constructor doesn't always return on its own
11161115
if (!flow.is(FlowFlags.RETURNS)) {
@@ -1128,19 +1127,19 @@ export class Compiler extends DiagnosticEmitter {
11281127
module.createGetLocal(0, nativeSizeType)
11291128
),
11301129
module.createSetLocal(0,
1131-
this.makeAllocation(<Class>parent)
1130+
this.makeAllocation(<Class>classInstance)
11321131
)
11331132
)
11341133
);
1135-
this.makeFieldInitialization(<Class>parent, stmts);
1134+
this.makeFieldInitialization(<Class>classInstance, stmts);
11361135
}
11371136
stmts.push(
11381137
module.createGetLocal(0, nativeSizeType)
11391138
);
11401139
}
11411140

11421141
// check that super has been called if this is a derived class
1143-
if ((<Class>parent).base && !flow.is(FlowFlags.CALLS_SUPER)) {
1142+
if ((<Class>classInstance).base && !flow.is(FlowFlags.CALLS_SUPER)) {
11441143
this.error(
11451144
DiagnosticCode.Constructors_for_derived_classes_must_contain_a_super_call,
11461145
instance.prototype.declaration.range
@@ -4699,8 +4698,7 @@ export class Compiler extends DiagnosticEmitter {
46994698
var argumentExpressions: Expression[];
47004699
var thisArg: ExpressionRef = 0;
47014700
if (operatorInstance.is(CommonFlags.INSTANCE)) {
4702-
let parent = assert(operatorInstance.parent);
4703-
assert(parent.kind == ElementKind.CLASS);
4701+
let classInstance = assert(operatorInstance.parent); assert(classInstance.kind == ElementKind.CLASS);
47044702
thisArg = leftExpr; // can reuse the previously evaluated leftExpr as the this value here
47054703
argumentExpressions = [ right ];
47064704
} else {
@@ -5521,8 +5519,7 @@ export class Compiler extends DiagnosticEmitter {
55215519
// here, with their respective locals being blocked. There is no 'makeCallInline'.
55225520
var body = [];
55235521
if (thisArg) {
5524-
let parent = assert(instance.parent);
5525-
assert(parent.kind == ElementKind.CLASS);
5522+
let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS);
55265523
let thisType = assert(instance.signature.thisType);
55275524
let classType = thisType.classReference;
55285525
let superType = classType
@@ -6093,8 +6090,7 @@ export class Compiler extends DiagnosticEmitter {
60936090
}
60946091
if (currentFunction.is(CommonFlags.INSTANCE)) {
60956092
let thisLocal = assert(flow.getScopedLocal("this"));
6096-
let parent = assert(currentFunction.parent);
6097-
assert(parent.kind == ElementKind.CLASS);
6093+
let classInstance = assert(currentFunction.parent); assert(classInstance.kind == ElementKind.CLASS);
60986094
let nativeSizeType = this.options.nativeSizeType;
60996095
if (currentFunction.is(CommonFlags.CONSTRUCTOR)) {
61006096
if (!flow.is(FlowFlags.ALLOCATES)) {
@@ -6111,11 +6107,11 @@ export class Compiler extends DiagnosticEmitter {
61116107
module.createGetLocal(thisLocal.index, nativeSizeType)
61126108
),
61136109
module.createSetLocal(thisLocal.index,
6114-
this.makeAllocation(<Class>parent)
6110+
this.makeAllocation(<Class>classInstance)
61156111
)
61166112
)
61176113
];
6118-
this.makeFieldInitialization(<Class>parent, stmts);
6114+
this.makeFieldInitialization(<Class>classInstance, stmts);
61196115
stmts.push(
61206116
module.createGetLocal(thisLocal.index, nativeSizeType)
61216117
);
@@ -6158,11 +6154,10 @@ export class Compiler extends DiagnosticEmitter {
61586154
}
61596155
}
61606156
if (currentFunction.is(CommonFlags.INSTANCE)) {
6161-
let parent = assert(currentFunction.parent);
6162-
assert(parent.kind == ElementKind.CLASS);
6163-
let base = (<Class>parent).base;
6164-
if (base) {
6165-
let superType = base.type;
6157+
let classInstance = assert(currentFunction.parent); assert(classInstance.kind == ElementKind.CLASS);
6158+
let baseClassInstance = (<Class>classInstance).base;
6159+
if (baseClassInstance) {
6160+
let superType = baseClassInstance.type;
61666161
this.currentType = superType;
61676162
return module.createGetLocal(0, superType.toNativeType());
61686163
}
@@ -6774,10 +6769,18 @@ export class Compiler extends DiagnosticEmitter {
67746769
ctorInstance.set(CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR | CommonFlags.COMPILED);
67756770
classInstance.constructorInstance = ctorInstance;
67766771

6777-
// start with a conditional allocation (i.e. if called with zero as the first argument)
6772+
// generate body
67786773
var module = this.module;
67796774
var nativeSizeType = this.options.nativeSizeType;
67806775
var stmts = new Array<ExpressionRef>();
6776+
6777+
// {
6778+
// if (!this) this = <ALLOC>
6779+
// IF_DERIVED: this = super(this, ...args)
6780+
// this.a = X
6781+
// this.b = Y
6782+
// return this
6783+
// }
67816784
stmts.push(
67826785
module.createIf(
67836786
module.createUnary(nativeSizeType == NativeType.I64 ? UnaryOp.EqzI64 : UnaryOp.EqzI32,
@@ -6788,8 +6791,6 @@ export class Compiler extends DiagnosticEmitter {
67886791
)
67896792
)
67906793
);
6791-
6792-
// call the super constructor if this is a derived class
67936794
if (baseClass) {
67946795
let parameterTypes = signature.parameterTypes;
67956796
let numParameters = parameterTypes.length;
@@ -6804,8 +6805,6 @@ export class Compiler extends DiagnosticEmitter {
68046805
)
68056806
);
68066807
}
6807-
6808-
// initialize own fields and return `this`
68096808
this.makeFieldInitialization(classInstance, stmts);
68106809
stmts.push(
68116810
module.createGetLocal(0, nativeSizeType)
@@ -6876,9 +6875,8 @@ export class Compiler extends DiagnosticEmitter {
68766875
return module.createGetGlobal((<Global>target).internalName, globalType.toNativeType());
68776876
}
68786877
case ElementKind.ENUMVALUE: { // enum value
6879-
let parent = (<EnumValue>target).parent;
6880-
assert(parent !== null && parent.kind == ElementKind.ENUM);
6881-
if (!this.compileEnum(<Enum>parent)) {
6878+
let theEnum = assert((<EnumValue>target).parent); assert(theEnum.kind == ElementKind.ENUM);
6879+
if (!this.compileEnum(<Enum>theEnum)) {
68826880
this.currentType = Type.i32;
68836881
return this.module.createUnreachable();
68846882
}
@@ -6939,8 +6937,7 @@ export class Compiler extends DiagnosticEmitter {
69396937
}
69406938
let inline = (instance.decoratorFlags & DecoratorFlags.INLINE) != 0;
69416939
if (instance.is(CommonFlags.INSTANCE)) {
6942-
let parent = assert(instance.parent);
6943-
assert(parent.kind == ElementKind.CLASS);
6940+
let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS);
69446941
let thisExpression = assert(this.resolver.currentThisExpression); //!!!
69456942
let thisExpr = this.compileExpressionRetainType(
69466943
thisExpression,

std/assembly/builtins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,4 @@ export namespace f64 {
192192

193193
@builtin export declare function start(): void;
194194

195-
@builtin export function NATIVE_CODE(): void {}
195+
@builtin export function NATIVE_CODE(): void { unreachable(); }

0 commit comments

Comments
 (0)