Skip to content

Commit 1dee33b

Browse files
committed
Merge branch 'master' into v0.9.3
2 parents f2e27ba + ca6e319 commit 1dee33b

File tree

5 files changed

+451
-25
lines changed

5 files changed

+451
-25
lines changed

src/compiler.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,10 @@ export class Compiler extends DiagnosticEmitter {
656656
break;
657657
}
658658
case ElementKind.PROPERTY_PROTOTYPE: {
659-
let getter = (<PropertyPrototype>element).getterPrototype;
659+
let prototype = <PropertyPrototype>element;
660+
let getter = prototype.getterPrototype;
660661
if (getter) this.ensureModuleExport(GETTER_PREFIX + name, getter, prefix);
661-
let setter = (<PropertyPrototype>element).setterPrototype;
662+
let setter = prototype.setterPrototype;
662663
if (setter) this.ensureModuleExport(SETTER_PREFIX + name, setter, prefix);
663664
break;
664665
}
@@ -700,28 +701,31 @@ export class Compiler extends DiagnosticEmitter {
700701
break;
701702
}
702703
case ElementKind.PROPERTY: {
703-
let getter = (<Property>element).getterInstance;
704+
let instance = <Property>element;
705+
let getter = instance.getterInstance;
704706
if (getter) this.ensureModuleExport(GETTER_PREFIX + name, getter, prefix);
705-
let setter = (<Property>element).setterInstance;
707+
let setter = instance.setterInstance;
706708
if (setter) this.ensureModuleExport(SETTER_PREFIX + name, setter, prefix);
707709
break;
708710
}
709711
case ElementKind.FIELD: {
712+
let instance = <Field>element;
710713
if (element.is(CommonFlags.COMPILED)) {
711714
let module = this.module;
712-
module.addFunctionExport((<Field>element).internalGetterName, prefix + GETTER_PREFIX + name);
715+
module.addFunctionExport(instance.internalGetterName, prefix + GETTER_PREFIX + name);
713716
if (!element.is(CommonFlags.READONLY)) {
714-
module.addFunctionExport((<Field>element).internalSetterName, prefix + SETTER_PREFIX + name);
717+
module.addFunctionExport(instance.internalSetterName, prefix + SETTER_PREFIX + name);
715718
}
716719
}
717720
break;
718721
}
719722
case ElementKind.CLASS: {
723+
let instance = <Class>element;
720724
// make the class name itself represent its runtime id
721-
if (!(<Class>element).type.isUnmanaged) {
725+
if (!instance.type.isUnmanaged) {
722726
let module = this.module;
723-
let internalName = (<Class>element).internalName;
724-
module.addGlobal(internalName, NativeType.I32, false, module.i32((<Class>element).id));
727+
let internalName = instance.internalName;
728+
module.addGlobal(internalName, NativeType.I32, false, module.i32(instance.id));
725729
module.addGlobalExport(internalName, prefix + name);
726730
}
727731
break;
@@ -1502,8 +1506,7 @@ export class Compiler extends DiagnosticEmitter {
15021506
}
15031507
}
15041508
}
1505-
var ctorInstance = instance.constructorInstance;
1506-
if (ctorInstance) this.compileFunction(ctorInstance);
1509+
this.ensureConstructor(instance, instance.identifierNode);
15071510
var instanceMembers = instance.members;
15081511
if (instanceMembers) {
15091512
// TODO: for (let element of instanceMembers.values()) {
@@ -8705,14 +8708,17 @@ export class Compiler extends DiagnosticEmitter {
87058708
CommonNames.constructor,
87068709
new FunctionPrototype(
87078710
CommonNames.constructor,
8708-
classInstance,
8711+
classInstance, // bound
87098712
this.program.makeNativeFunctionDeclaration(CommonNames.constructor,
87108713
CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR
87118714
)
87128715
),
87138716
new Signature(this.program, null, classInstance.type, classInstance.type),
87148717
contextualTypeArguments
87158718
);
8719+
let members = classInstance.members;
8720+
if (!members) classInstance.members = members = new Map();
8721+
members.set("constructor", instance.prototype);
87168722
}
87178723

87188724
instance.internalName = classInstance.internalName + INSTANCE_DELIMITER + "constructor";

tests/compiler/extends-recursive.optimized.wat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
(module
2+
(type $none_=>_none (func))
23
(type $i32_i32_=>_none (func (param i32 i32)))
34
(type $i32_=>_i32 (func (param i32) (result i32)))
45
(memory $0 0)
6+
(global $~lib/rt/stub/startOffset (mut i32) (i32.const 0))
7+
(global $~lib/rt/stub/offset (mut i32) (i32.const 0))
58
(global $extends-recursive/Child i32 (i32.const 3))
69
(export "memory" (memory $0))
710
(export "Child" (global $extends-recursive/Child))
811
(export "Child#get:child" (func $extends-recursive/Parent#get:child))
912
(export "Child#set:child" (func $extends-recursive/Parent#set:child))
13+
(start $~start)
1014
(func $extends-recursive/Parent#get:child (; 0 ;) (param $0 i32) (result i32)
1115
local.get $0
1216
i32.load
@@ -19,4 +23,10 @@
1923
local.get $1
2024
i32.store
2125
)
26+
(func $~start (; 2 ;)
27+
i32.const 16
28+
global.set $~lib/rt/stub/startOffset
29+
i32.const 16
30+
global.set $~lib/rt/stub/offset
31+
)
2232
)

tests/compiler/extends-recursive.untouched.wat

Lines changed: 160 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,170 @@
11
(module
22
(type $i32_=>_i32 (func (param i32) (result i32)))
33
(type $i32_=>_none (func (param i32)))
4+
(type $none_=>_none (func))
45
(type $i32_i32_=>_none (func (param i32 i32)))
6+
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
57
(memory $0 0)
68
(table $0 1 funcref)
9+
(global $~lib/rt/stub/startOffset (mut i32) (i32.const 0))
10+
(global $~lib/rt/stub/offset (mut i32) (i32.const 0))
11+
(global $~lib/heap/__heap_base i32 (i32.const 8))
712
(global $extends-recursive/Child i32 (i32.const 3))
813
(export "memory" (memory $0))
914
(export "Child" (global $extends-recursive/Child))
1015
(export "Child#get:child" (func $extends-recursive/Parent#get:child))
1116
(export "Child#set:child" (func $extends-recursive/Parent#set:child))
12-
(func $~lib/rt/stub/__retain (; 0 ;) (param $0 i32) (result i32)
17+
(start $~start)
18+
(func $~lib/rt/stub/maybeGrowMemory (; 0 ;) (param $0 i32)
19+
(local $1 i32)
20+
(local $2 i32)
21+
(local $3 i32)
22+
(local $4 i32)
23+
(local $5 i32)
24+
memory.size
25+
local.set $1
26+
local.get $1
27+
i32.const 16
28+
i32.shl
29+
local.set $2
30+
local.get $0
31+
local.get $2
32+
i32.gt_u
33+
if
34+
local.get $0
35+
local.get $2
36+
i32.sub
37+
i32.const 65535
38+
i32.add
39+
i32.const 65535
40+
i32.const -1
41+
i32.xor
42+
i32.and
43+
i32.const 16
44+
i32.shr_u
45+
local.set $3
46+
local.get $1
47+
local.tee $4
48+
local.get $3
49+
local.tee $5
50+
local.get $4
51+
local.get $5
52+
i32.gt_s
53+
select
54+
local.set $4
55+
local.get $4
56+
memory.grow
57+
i32.const 0
58+
i32.lt_s
59+
if
60+
local.get $3
61+
memory.grow
62+
i32.const 0
63+
i32.lt_s
64+
if
65+
unreachable
66+
end
67+
end
68+
end
69+
local.get $0
70+
global.set $~lib/rt/stub/offset
71+
)
72+
(func $~lib/rt/stub/__alloc (; 1 ;) (param $0 i32) (param $1 i32) (result i32)
73+
(local $2 i32)
74+
(local $3 i32)
75+
(local $4 i32)
76+
(local $5 i32)
77+
(local $6 i32)
78+
local.get $0
79+
i32.const 1073741808
80+
i32.gt_u
81+
if
82+
unreachable
83+
end
84+
global.get $~lib/rt/stub/offset
85+
i32.const 16
86+
i32.add
87+
local.set $2
88+
local.get $0
89+
i32.const 15
90+
i32.add
91+
i32.const 15
92+
i32.const -1
93+
i32.xor
94+
i32.and
95+
local.tee $3
96+
i32.const 16
97+
local.tee $4
98+
local.get $3
99+
local.get $4
100+
i32.gt_u
101+
select
102+
local.set $5
103+
local.get $2
104+
local.get $5
105+
i32.add
106+
call $~lib/rt/stub/maybeGrowMemory
107+
local.get $2
108+
i32.const 16
109+
i32.sub
110+
local.set $6
111+
local.get $6
112+
local.get $5
113+
i32.store
114+
local.get $6
115+
i32.const 1
116+
i32.store offset=4
117+
local.get $6
118+
local.get $1
119+
i32.store offset=8
120+
local.get $6
121+
local.get $0
122+
i32.store offset=12
123+
local.get $2
124+
)
125+
(func $~lib/rt/stub/__retain (; 2 ;) (param $0 i32) (result i32)
13126
local.get $0
14127
)
15-
(func $extends-recursive/Parent#get:child (; 1 ;) (param $0 i32) (result i32)
128+
(func $extends-recursive/Parent#constructor (; 3 ;) (param $0 i32) (result i32)
129+
local.get $0
130+
i32.eqz
131+
if
132+
i32.const 4
133+
i32.const 4
134+
call $~lib/rt/stub/__alloc
135+
call $~lib/rt/stub/__retain
136+
local.set $0
137+
end
138+
local.get $0
139+
i32.const 0
140+
call $~lib/rt/stub/__retain
141+
i32.store
142+
local.get $0
143+
)
144+
(func $extends-recursive/Child#constructor (; 4 ;) (param $0 i32) (result i32)
145+
local.get $0
146+
i32.eqz
147+
if
148+
i32.const 4
149+
i32.const 3
150+
call $~lib/rt/stub/__alloc
151+
call $~lib/rt/stub/__retain
152+
local.set $0
153+
end
154+
local.get $0
155+
call $extends-recursive/Parent#constructor
156+
local.set $0
157+
local.get $0
158+
)
159+
(func $extends-recursive/Parent#get:child (; 5 ;) (param $0 i32) (result i32)
16160
local.get $0
17161
i32.load
18162
call $~lib/rt/stub/__retain
19163
)
20-
(func $~lib/rt/stub/__release (; 2 ;) (param $0 i32)
164+
(func $~lib/rt/stub/__release (; 6 ;) (param $0 i32)
21165
nop
22166
)
23-
(func $extends-recursive/Parent#set:child (; 3 ;) (param $0 i32) (param $1 i32)
167+
(func $extends-recursive/Parent#set:child (; 7 ;) (param $0 i32) (param $1 i32)
24168
(local $2 i32)
25169
local.get $0
26170
local.get $1
@@ -38,4 +182,16 @@
38182
local.get $1
39183
i32.store
40184
)
185+
(func $~start (; 8 ;)
186+
global.get $~lib/heap/__heap_base
187+
i32.const 15
188+
i32.add
189+
i32.const 15
190+
i32.const -1
191+
i32.xor
192+
i32.and
193+
global.set $~lib/rt/stub/startOffset
194+
global.get $~lib/rt/stub/startOffset
195+
global.set $~lib/rt/stub/offset
196+
)
41197
)

0 commit comments

Comments
 (0)