-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathstmt.bal
1365 lines (1255 loc) · 61.3 KB
/
stmt.bal
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import wso2/nballerina.bir;
import wso2/nballerina.types as t;
import wso2/nballerina.front.syntax as s;
import wso2/nballerina.comm.err;
import wso2/nballerina.comm.diagnostic as d;
type Position d:Position;
type Range d:Range;
type StmtEffect record {|
bir:BasicBlock? block;
BindingChain? bindings = ();
|};
type LExprEffect record {|
bir:BasicBlock block;
bir:Register result;
|};
type LoopContext record {|
// number of first register created in the loop, including the ones created in the cond
bir:BasicBlock? onBreak;
bir:BasicBlock? onContinue;
LoopContext? enclosing;
// Bindings at break/continue stmts. Will use this to validate assignments in loops and to
// determine assignments to be passed up.
BindingChain?[] breakBindings = [];
BindingChain?[] continueBindings = [];
boolean continueIsBackward;
|};
type BindingLookupResult record {|
Binding binding;
boolean inOuterFunction;
|};
type ClosureContext object {
*err:SemanticContext;
function isClosure() returns boolean;
};
type CapturedRegisterMemo readonly & record {|
bir:CapturableRegister outerRegister;
bir:CapturedRegister innerRegister;
|};
type BlockState readonly & record {|
bir:Label label;
int instructionCount;
|};
type StmtContextState record {|
int registerCount;
int regionCount;
int openRegionCount;
table<BlockState> key(label) blockState;
table<CapturedRegisterMemo> key(outerRegister) capturedRegisters;
int innerCapturedRegisterCount;
|};
class StmtContext {
*ClosureContext;
final Module mod;
final ModuleSymbols syms;
final s:SourceFile file;
final s:Function func;
final bir:FunctionCode code;
final t:SemType returnType;
final s:FunctionDefn moduleLevelDefn;
table<CapturedRegisterMemo> key(outerRegister) outerCapturedRegisters = table[];
LoopContext? loopContext = ();
bir:RegionIndex[] openRegions = [];
bir:RegisterScope[] scopeStack = [];
int[] innerCapturedRegisters = [];
boolean newCaptureInsn = false;
int[] directRefVarRegisters = [];
function init(Module mod, ModuleSymbols syms, s:Function func, s:FunctionDefn moduleLevelDefn, t:SemType returnType) {
self.mod = mod;
self.syms = syms;
self.func = func;
self.file = moduleLevelDefn.part.file;
self.code = {};
self.returnType = returnType;
self.moduleLevelDefn = moduleLevelDefn;
self.scopeStack.push({ scope: (), startPos: func.startPos, endPos: func.endPos });
}
function isClosure() returns boolean {
return self.func is s:AnonFunction;
}
function createVarRegister(bir:SemType t, Position pos, string name) returns bir:VarRegister {
return bir:createVarRegister(self.code, t, pos, name, self.getCurrentScope());
}
function createFinalRegister(bir:SemType t, Position pos, string name) returns bir:FinalRegister {
return bir:createFinalRegister(self.code, t, pos, name, self.getCurrentScope());
}
function createNarrowRegister(bir:SemType t, bir:Register underlying, Position? pos) returns bir:NarrowRegister {
return bir:createNarrowRegister(self.code, t, underlying, pos);
}
function createParamRegister(bir:SemType t, Position pos, string name) returns bir:ParamRegister {
return bir:createParamRegister(self.code, t, pos, name, self.getCurrentScope());
}
function getCaptureRegister(bir:SemType t, bir:CapturableRegister underlying, Position? pos = ()) returns bir:CapturedRegister {
// We need to ensure for a given register in the outer function, there is only one captured register.
CapturedRegisterMemo? memo = self.outerCapturedRegisters[underlying];
if memo != () {
return memo.innerRegister;
}
bir:CapturedRegister register = bir:createCapturedRegister(self.code, t, underlying, underlying.name, self.getCurrentScope(), pos);
self.outerCapturedRegisters.add({ outerRegister: underlying, innerRegister: register });
return register;
}
function currentState() returns StmtContextState {
int registerCount = self.code.registers.length();
int regionCount = self.code.regions.length();
table<BlockState> key(label) blockState = table key(label) from var block in self.code.blocks select { label: block.label, instructionCount: block.insns.length() };
int openRegionCount = self.openRegions.length();
table<CapturedRegisterMemo> key(outerRegister) capturedRegisters = self.outerCapturedRegisters.clone();
int innerCapturedRegisterCount = self.innerCapturedRegisters.length();
return { registerCount, regionCount, blockState, openRegionCount, capturedRegisters, innerCapturedRegisterCount };
}
function restoreState(StmtContextState state) {
var { registerCount, regionCount, blockState, openRegionCount, capturedRegisters, innerCapturedRegisterCount } = state;
self.code.blocks = self.code.blocks.slice(0, blockState.length());
self.code.registers = self.code.registers.slice(0, registerCount);
self.code.regions = self.code.regions.slice(0, regionCount);
foreach bir:BasicBlock bb in self.code.blocks {
bb.insns = bb.insns.slice(0, blockState.get(bb.label).instructionCount);
}
self.openRegions = self.openRegions.slice(0, openRegionCount);
self.outerCapturedRegisters = capturedRegisters;
self.innerCapturedRegisters = self.innerCapturedRegisters.slice(0, innerCapturedRegisterCount);
}
function markAsCaptured(bir:DeclRegister register) {
uniquePush(self.innerCapturedRegisters, register.number);
}
function markAsDirectRef(bir:VarRegister register) {
uniquePush(self.directRefVarRegisters, register.number);
}
function markCaptureInsn() {
self.newCaptureInsn = true;
}
function isCaptured(bir:DeclRegister register) returns boolean {
return self.innerCapturedRegisters.indexOf(register.number) != ();
}
public function getCurrentScope() returns bir:RegisterScope {
return self.scopeStack[self.scopeStack.length() - 1];
}
function popScope() {
_ = self.scopeStack.pop();
}
function pushScope(Position startPos, Position endPos) {
bir:RegisterScope scope = self.getCurrentScope();
self.scopeStack.push({ scope, startPos, endPos });
}
function createTmpRegister(bir:SemType t, Position? pos = ()) returns bir:TmpRegister {
return bir:createTmpRegister(self.code, t, pos);
}
function nextRegisterNumber() returns int {
return self.code.registers.length();
}
function registerVarName(int registerNumber) returns string? {
return bir:getRegister(self.code, registerNumber).name;
}
function registerPosition(int registerNumber) returns Position? {
return bir:getRegister(self.code, registerNumber).pos;
}
function createBasicBlock(string? name = ()) returns bir:BasicBlock {
return bir:createBasicBlock(self.code, name);
}
function openRegion(bir:Label entry, bir:RegionKind kind, bir:Label? exit = ()) {
bir:RegionIndex regionIndex = self.code.regions.length();
int openCount = self.openRegions.length();
bir:RegionIndex? parent = openCount > 0 ? self.openRegions[openCount - 1] : ();
self.code.regions.push({ entry, kind, exit, parent });
self.openRegions.push(regionIndex);
}
function closeRegion(bir:Label? exit = ()) {
int regionIndex = self.openRegions.pop();
self.code.regions[regionIndex].exit = exit;
}
function qNameRange(Position startPos) returns Range {
return self.file.qNameRange(startPos);
}
public function semanticErr(d:Message msg, Position|Range pos, error? cause = ()) returns err:Semantic {
return err:semantic(msg, loc=self.location(pos), cause=cause, defnName=self.moduleLevelDefn.name);
}
function unimplementedErr(d:Message msg, Position|Range pos, error? cause = ()) returns err:Unimplemented {
return err:unimplemented(msg, loc=self.location(pos), cause=cause, defnName=self.moduleLevelDefn.name);
}
private function location(Position|Range pos) returns d:Location {
return d:location(self.file, pos);
}
function pushLoopContext(bir:BasicBlock? onBreak, bir:BasicBlock? onContinue, boolean continueIsBackward) {
LoopContext c = { onBreak, onContinue, enclosing: self.loopContext, continueIsBackward };
self.loopContext = c;
}
function loopContinueBlock() returns bir:BasicBlock? {
return (<LoopContext>self.loopContext).onContinue;
}
function loopBreakBlock() returns bir:BasicBlock? {
return (<LoopContext>self.loopContext).onBreak;
}
function popLoopContext() {
self.loopContext = (<LoopContext>self.loopContext).enclosing;
}
function onBreakLabel(Position pos) returns bir:Label|err:Semantic {
LoopContext? c = self.loopContext;
if c == () {
return self.semanticErr("break not in loop", pos);
}
else {
bir:BasicBlock b = c.onBreak ?: self.createBasicBlock();
c.onBreak = b;
return b.label;
}
}
// Returns basic block to branch on continue, and whether the branch will be backwards
function onContinueLabel(Position pos) returns [bir:Label, boolean]|err:Semantic {
LoopContext? c = self.loopContext;
if c == () {
return self.semanticErr("continue not in loop", pos);
}
else {
bir:BasicBlock b = c.onContinue ?: self.createBasicBlock();
c.onContinue = b;
return [b.label, c.continueIsBackward];
}
}
function addBreakBindings(BindingChain? bindings) {
LoopContext c = <LoopContext>self.loopContext;
c.breakBindings.push(bindings);
}
function addContinueBindings(BindingChain? bindings) {
LoopContext c = <LoopContext>self.loopContext;
c.continueBindings.push(bindings);
}
function continueBindings() returns BindingChain?[] {
return (<LoopContext>self.loopContext).continueBindings;
}
function breakBindings() returns BindingChain?[] {
return (<LoopContext>self.loopContext).breakBindings;
}
function exprContext(BindingChain? bindings) returns ExprContext {
return new ExprContext(self.syms, self.moduleLevelDefn, self.code, bindings, self);
}
function codeGenExpr(bir:BasicBlock block, BindingChain? bindings, t:SemType? expectedType, s:Expr expr) returns CodeGenError|ExprEffect {
return codeGenExpr(self.exprContext(bindings), block, expectedType, expr);
}
function codeGenExprForInt(bir:BasicBlock block, BindingChain? bindings, s:Expr expr) returns CodeGenError|IntExprEffect {
return codeGenExprForInt(self.exprContext(bindings), block, expr);
}
function codeGenExprForString(bir:BasicBlock block, BindingChain? bindings, s:Expr expr) returns CodeGenError|StringExprEffect {
return codeGenExprForString(self.exprContext(bindings), block, expr);
}
function codeGenExprForBoolean(bir:BasicBlock block, BindingChain? bindings, s:Expr expr) returns CodeGenError|BooleanExprEffect {
return codeGenExprForBoolean(self.exprContext(bindings), block, expr);
}
function resolveTypeDesc(s:TypeDesc td) returns t:SemType|ResolveTypeError {
return resolveSubsetTypeDesc(self.syms, self.moduleLevelDefn, td);
}
}
function codeGenFunction(Module mod, s:Function func, s:FunctionDefn moduleLevelDefn, t:FunctionSignature signature, BindingChain? closureBindings = ()) returns bir:FunctionCode|CodeGenError {
StmtContext cx = new(mod, mod.syms, func, moduleLevelDefn, signature.returnType);
bir:BasicBlock startBlock = cx.createBasicBlock();
BindingChain bindings = { head: "func", prev: closureBindings };
foreach int i in 0 ..< func.params.length() {
var { name, namePos } = func.params[i];
if envDefines(cx, name, bindings) {
return cx.semanticErr(`duplicate declaration of ${name}`, namePos);
}
bir:ParamRegister reg = cx.createParamRegister(signature.paramTypes[i], namePos, name);
bindings = { head: { name: <string>name, reg, isFinal: true }, prev: bindings };
}
var { block: endBlock } = check codeGenScope(cx, startBlock, bindings, func.body);
if endBlock != () {
bir:RetInsn ret = { operand: bir:NIL_OPERAND, pos: func.body.closeBracePos };
endBlock.insns.push(ret);
}
codeGenOnPanic(cx, func.body.closeBracePos);
return cx.code;
}
function codeGenOnPanic(StmtContext cx, Position pos) {
bir:BasicBlock[] blocks = cx.code.blocks;
bir:BasicBlock? onPanicBlock = ();
foreach var b in blocks {
if bir:isBasicBlockPotentiallyPanicking(b) {
bir:BasicBlock pb;
if onPanicBlock == () {
pb = cx.createBasicBlock();
onPanicBlock = pb;
}
else {
pb = onPanicBlock;
}
b.onPanic = pb.label;
}
}
if onPanicBlock != () {
bir:TmpRegister reg = cx.createTmpRegister(t:ERROR, pos);
bir:CatchInsn catch = { result: reg, pos };
onPanicBlock.insns.push(catch);
onPanicBlock.insns.push(<bir:AbnormalRetInsn>{ operand: reg, pos });
}
}
type Scope s:StmtBlock|s:IfElseStmt;
type ScopedStmt s:MatchStmt|s:WhileStmt|s:ForeachStmt;
// If the scope doesn't complete normally, will return empty bindings.
function codeGenScope(StmtContext cx, bir:BasicBlock bb, BindingChain? initialBindings, Scope scope) returns CodeGenError|StmtEffect {
BindingChain? bindings = initialBindings;
final int startRegister = cx.nextRegisterNumber();
bir:BasicBlock? curBlock = bb;
if scope is s:IfElseStmt {
StmtEffect effect = check codeGenIfElseStmt(cx, bb, bindings, scope);
curBlock = effect.block;
bindings = effect.bindings ?: bindings;
}
else {
foreach var stmt in scope.stmts {
StmtEffect effect = check codeGenStmt(cx, curBlock, bindings, stmt);
curBlock = effect.block;
bindings = effect.bindings ?: bindings;
}
}
check unusedLocalVariables(cx, bindings, initialBindings);
BindingChain? outerScopeBindings = curBlock != () ? addBindings(initialBindings, bindings, startRegister) : ();
return { block: curBlock, bindings: outerScopeBindings };
}
// Add `Bindings` from `bodyBindings`, up to `bindingLimit`, that assigns to/narrows outside registers, on top `bindingLimit`.
function addBindings(BindingChain? bindingLimit, BindingChain? bodyBindings, int startRegister) returns BindingChain? {
BindingChain? newBindings = bindingLimit;
foreach var b in bindingsUpTo(bindingLimit, bodyBindings).reverse() {
if b is OccurrenceBinding && b.unnarrowed.reg.number < startRegister {
newBindings = { prev: newBindings, head: b };
}
}
return newBindings;
}
// Add `Bindings` from `bindings`, up to `bindingLimit`, that assigns to outside registers, on top `rootBindings`.
function addAssignments(BindingChain? bindingLimit, BindingChain? bindings, BindingChain? rootBindings, int startRegister) returns BindingChain? {
BindingChain? newBindings = rootBindings;
foreach var b in bindingsUpTo(bindingLimit, bindings).reverse() {
if b is AssignmentBinding && b.reg.number < startRegister { // For assignments, reg is same as unnarrowed.reg
newBindings = { prev: newBindings, head: b };
}
}
return newBindings;
}
// List Bindings from `bindings` up to `bindingLimit`.
function bindingsUpTo(BindingChain? bindingLimit, BindingChain? bindings) returns Binding[] {
Binding[] result = [];
BindingChain? b = bindings;
while b !== bindingLimit {
// Since `bindingLimit` is a sub-chain of `bindings`, we never reach nil on `b`.
var { head, prev } = <BindingChain>b;
if head !is FunctionMarker {
result.push(head);
}
b = prev;
}
return result;
}
function codeGenStmt(StmtContext cx, bir:BasicBlock? curBlock, BindingChain? bindings, s:Stmt stmt) returns CodeGenError|StmtEffect {
StmtContextState initialState = cx.currentState();
StmtEffect result;
int directRefVarRegisterCount = cx.directRefVarRegisters.length();
if curBlock == () {
return cx.semanticErr("unreachable code", s:range(stmt));
}
else if stmt is ScopedStmt {
result = check codeGenScopedStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:IfElseStmt {
result = check codeGenIfElseStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:BreakContinueStmt {
result = check codeGenBreakContinueStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:ReturnStmt {
result = check codeGenReturnStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:PanicStmt {
result = check codeGenPanicStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:VarDeclStmt {
result = check codeGenVarDeclStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:AssignStmt {
result = check codeGenAssignStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:CompoundAssignStmt {
result = check codeGenCompoundAssignStmt(cx, curBlock, bindings, stmt);
}
else {
result = check codeGenCallStmt(cx, curBlock, bindings, stmt);
}
bir:VarRegister[] shouldCopyRegisters = registersToBeLocallyStored(cx, initialState, cx.directRefVarRegisters.slice(directRefVarRegisterCount));
cx.directRefVarRegisters = cx.directRefVarRegisters.slice(0, directRefVarRegisterCount);
cx.newCaptureInsn = false;
if shouldCopyRegisters.length() != 0 {
cx.restoreState(initialState);
foreach var register in shouldCopyRegisters {
cx.markAsCaptured(register);
}
return check codeGenStmt(cx, curBlock, bindings, stmt);
}
return result;
}
function codeGenScopedStmt(StmtContext cx, bir:BasicBlock curBlock, BindingChain? bindings, ScopedStmt stmt) returns CodeGenError|StmtEffect {
StmtEffect|CodeGenError effect;
cx.pushScope(stmt.startPos, stmt.endPos);
if stmt is s:MatchStmt {
effect = codeGenMatchStmt(cx, curBlock, bindings, stmt);
}
else if stmt is s:WhileStmt {
effect = codeGenWhileStmt(cx, curBlock, bindings, stmt);
}
else {
effect = codeGenForeachStmt(cx, curBlock, bindings, stmt);
}
cx.popScope();
return effect;
}
function unusedLocalVariables(StmtContext cx, BindingChain? blockBindings, BindingChain? bindingLimit) returns CodeGenError? {
BindingChain? bindings = blockBindings;
while bindings !== bindingLimit {
// Since `bindingLimit` is a sub-chain of `blockBindings`, we never reach nil on `bindings`.
var { head, prev } = <BindingChain>bindings;
if head is DeclBinding && !head.used {
return cx.semanticErr(`unused local variable ${head.name}`, <Position>head.reg.pos);
}
bindings = prev;
}
}
function codeGenForeachStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:ForeachStmt stmt) returns CodeGenError|StmtEffect {
string varName = stmt.name;
if envDefines(cx, varName, initialBindings) {
return cx.semanticErr(`duplicate declaration of ${varName}`, stmt.namePos);
}
s:RangeExpr range = stmt.range;
var { result: lower, block: evalUpper } = check cx.codeGenExprForInt(startBlock, initialBindings, range.lower);
var { result: upper, block: initLoopVar } = check cx.codeGenExprForInt(evalUpper, initialBindings, range.upper);
bir:VarRegister loopVar = cx.createVarRegister(t:INT, stmt.namePos, varName);
bir:AssignInsn init = { pos: stmt.kwPos, result: loopVar, operand: lower };
initLoopVar.insns.push(init);
bir:BasicBlock loopHead = cx.createBasicBlock();
bir:BasicBlock exit = cx.createBasicBlock();
bir:BranchInsn branchToLoopHead = { dest: loopHead.label, pos: stmt.body.startPos };
initLoopVar.insns.push(branchToLoopHead);
bir:TmpRegister condition = cx.createTmpRegister(t:BOOLEAN, stmt.range.opPos);
bir:CompareInsn compare = { op: "<", pos: stmt.range.opPos, operands: [loopVar, upper], result: condition };
loopHead.insns.push(compare);
bir:BasicBlock loopBody = cx.createBasicBlock();
bir:CondBranchInsn branch = { operand: condition, ifFalse: exit.label, ifTrue: loopBody.label, pos: stmt.range.opPos };
loopHead.insns.push(branch);
var startRegister = cx.nextRegisterNumber();
cx.pushLoopContext(exit, (), false);
BindingChain loopBodyBindings = { head: { name: varName, reg: loopVar, isFinal: true }, prev: initialBindings };
var { block: loopEnd, bindings: loopEndBindings } = check codeGenScope(cx, loopBody, loopBodyBindings, stmt.body);
bir:BasicBlock? loopStep = cx.loopContinueBlock();
if loopEnd != () {
loopStep = loopStep ?: cx.createBasicBlock();
bir:BranchInsn branchToLoopStep = { dest: (<bir:BasicBlock>loopStep).label, pos: stmt.kwPos };
loopEnd.insns.push(branchToLoopStep);
check validLoopAssignments(cx, loopBodyBindings, loopEndBindings, startRegister);
}
foreach var continueBindings in cx.continueBindings() {
check validLoopAssignments(cx, loopBodyBindings, continueBindings, startRegister);
}
BindingChain? bindings = ();
foreach var breakBindings in cx.breakBindings() {
bindings = addAssignments(loopBodyBindings, breakBindings, bindings ?: initialBindings, startRegister);
}
if loopStep != () {
bir:TmpRegister nextLoopVal = cx.createTmpRegister(t:INT);
bir:IntNoPanicArithmeticBinaryInsn increment = { op: "+", pos: stmt.kwPos, operands: [loopVar, singletonIntOperand(cx.syms.tc, 1)], result: nextLoopVal };
bir:AssignInsn incrementAssign = { result: loopVar, operand: nextLoopVal, pos: stmt.kwPos };
bir:BranchInsn backwardBranchToLoopHead = { dest: loopHead.label, pos: stmt.body.startPos, backward: true };
loopStep.insns.push(increment, incrementAssign, backwardBranchToLoopHead);
}
cx.popLoopContext();
return { block: exit, bindings };
}
function codeGenWhileStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:WhileStmt stmt) returns CodeGenError|StmtEffect {
ExprContext ec = cx.exprContext(initialBindings);
bir:BasicBlock loopHead = cx.createBasicBlock(); // where we go to on continue
cx.openRegion(loopHead.label, bir:REGION_LOOP);
bir:BranchInsn forwardBranchToLoopHead = { dest: loopHead.label, pos: stmt.body.startPos };
startBlock.insns.push(forwardBranchToLoopHead);
// Its OK to assign to bindings created in the cond, so loop assignable variables should start from here
int startRegister = cx.nextRegisterNumber();
var { trueMerger, falseMerger } = check codeGenExprForCond(ec, loopHead, stmt.condition);
if trueMerger is () && falseMerger is TypeMerger {
if stmt.body.length() == 0 {
return codeGenTypeMergeFromMerger(ec, falseMerger, stmt.body.startPos);
}
else {
return cx.semanticErr("unreachable code", stmt.body.stmts[0].startPos);
}
}
else if trueMerger is TypeMerger && falseMerger is () {
return finishCodeGenWhileStmt(cx, initialBindings, stmt, loopHead, trueMerger, startRegister);
}
else if trueMerger is TypeMerger && falseMerger is TypeMerger {
var { block: exit, binding: _ } = codeGenTypeMergeFromMerger(ec, falseMerger, stmt.body.endPos); // binding is ignored, see: #ballerina-spec/1019
return finishCodeGenWhileStmt(cx, initialBindings, stmt, loopHead, trueMerger, startRegister, exit);
}
panic err:impossible();
}
// JBUG #35748 had to be broken into a separate function
function finishCodeGenWhileStmt(StmtContext cx, BindingChain? initialBindings, s:WhileStmt stmt, bir:BasicBlock loopHead, TypeMerger loopBodyMerger, int startRegister, bir:BasicBlock? exit = ()) returns CodeGenError|StmtEffect {
ExprContext ec = cx.exprContext(initialBindings);
var { block: loopBody, bindings: loopBodyBindings } = codeGenTypeMergeFromMerger(ec, loopBodyMerger, stmt.body.startPos);
cx.pushLoopContext(exit, loopHead, true);
var { block: loopEnd, bindings: loopEndBindings } = check codeGenScope(cx, loopBody, loopBodyBindings, stmt.body);
if loopEnd != () {
bir:BranchInsn backwardBranchToLoopHead = { dest: loopHead.label, pos: stmt.body.startPos, backward: true };
loopEnd.insns.push(backwardBranchToLoopHead);
check validLoopAssignments(cx, loopBodyBindings, loopEndBindings, startRegister);
}
foreach var continueBindings in cx.continueBindings() {
check validLoopAssignments(cx, loopBodyBindings, continueBindings, startRegister);
}
BindingChain? bindings = ();
foreach var breakBindings in cx.breakBindings() {
bindings = addAssignments(loopBodyBindings, breakBindings, bindings ?: initialBindings, startRegister);
}
bir:BasicBlock? breakBlock = cx.loopBreakBlock();
cx.popLoopContext();
cx.closeRegion(breakBlock?.label);
return { block: breakBlock, bindings };
}
function validLoopAssignments(StmtContext cx, BindingChain? bindingLimit, BindingChain? bindings, int startRegister) returns CodeGenError? {
BindingChain? b = bindings;
while b !== bindingLimit {
// Since `bindingLimit` is a sub-chain of `bindings`, we never reach nil on `b`.
var { head, prev } = <BindingChain>b;
if head is AssignmentBinding && head.invalidates.number < startRegister {
return cx.semanticErr(`assignment to narrowed variable ${ head.name } in loop`, head.pos);
}
b = prev;
}
}
function codeGenBreakContinueStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:BreakContinueStmt stmt) returns CodeGenError|StmtEffect {
bir:Label dest;
boolean backward;
if stmt.breakContinue == "break" {
dest = check cx.onBreakLabel(stmt.startPos);
backward = false;
cx.addBreakBindings(initialBindings);
}
else {
[dest, backward] = check cx.onContinueLabel(stmt.startPos);
cx.addContinueBindings(initialBindings);
}
bir:BranchInsn branch = {dest, pos: stmt.startPos, backward};
startBlock.insns.push(branch);
return { block: () };
}
type MatchTest EqualMatchTest|BasicTypeMatchTest;
type EqualMatchTest record {|
int clauseIndex;
Position pos;
bir:SingleValueConstOperand operand;
readonly t:SingleValue value;
|};
type BasicTypeMatchTest record {|
int clauseIndex;
Position pos;
t:BasicTypeBitSet bitSet;
|};
function codeGenMatchStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:MatchStmt stmt) returns CodeGenError|StmtEffect {
ExprContext ec = cx.exprContext(initialBindings);
final int startRegister = cx.nextRegisterNumber();
var { result: matched, block: testBlock, binding } = check codeGenExpr(ec, startBlock, (), stmt.expr);
t:Context tc = cx.syms.tc;
t:SemType matchedType = operandSemType(tc, matched);
// defaultCodeIndex is either () or the index of the last clause;
// the latter case means that the match is exhaustive
int? defaultClauseIndex = ();
boolean hadWildcardPattern = false;
table<EqualMatchTest> key(value) equalMatchTests = table [];
MatchTest[] matchTests = [];
t:SemType[] clauseLooksLike = [];
t:SemType[] clauseUnmatchedLooksLike = [];
t:SemType[] clausePatternUnions = [];
// union of all clause patterns preceding this one
t:SemType precedingPatternsUnion = t:NEVER;
bir:BasicBlock[] clauseBlocks = [];
foreach int i in 0 ..< stmt.clauses.length() {
var clause = stmt.clauses[i];
clauseBlocks[i] = cx.createBasicBlock("clause." + i.toString());
t:SemType clausePatternUnion = t:NEVER;
foreach var pattern in clause.patterns {
t:SemType patternType;
if pattern is s:SimpleConstExpr {
t:SingleValue value = check resolveConstMatchPattern(cx, initialBindings, pattern, matchedType);
if equalMatchTests.hasKey(value) {
return cx.semanticErr("duplicate const match pattern", pos=s:range(pattern));
}
if !t:containsConst(matchedType, value) {
return cx.semanticErr("match pattern cannot match value of expression", pos=s:range(pattern));
}
patternType = t:singleton(tc, value);
bir:SingleValueConstOperand operand = { value, semType: patternType };
EqualMatchTest mt = { value, operand, clauseIndex: i, pos: clause.opPos };
equalMatchTests.add(mt);
matchTests.push(mt);
}
else {
// `1|_ => {}` is pointless, but I'm not making it an error
// because a later pattern that overlaps an earlier one is not in general an error
if hadWildcardPattern {
return cx.semanticErr("duplicate wildcard match pattern", pattern.startPos);
}
hadWildcardPattern = true;
BasicTypeMatchTest mt = { bitSet: t:ANY, clauseIndex: i, pos: clause.opPos };
matchTests.push(mt);
patternType = t:ANY;
if t:isSubtypeSimple(matchedType, t:ERROR) {
return cx.semanticErr("wildcard match pattern cannot match error", pattern.startPos);
}
}
clausePatternUnion = t:union(clausePatternUnion, patternType);
}
clauseLooksLike[i] = t:diff(clausePatternUnion, precedingPatternsUnion);
precedingPatternsUnion = t:union(precedingPatternsUnion, clausePatternUnion);
clauseUnmatchedLooksLike[i] = t:diff(matchedType , precedingPatternsUnion);
clausePatternUnions[i] = clausePatternUnion;
if t:isSubtype(cx.syms.tc, matchedType, precedingPatternsUnion) {
if i != stmt.clauses.length() - 1 {
return cx.semanticErr("match clause unmatchable because of previous wildcard match pattern", pos=s:range(stmt.clauses[i + 1]));
}
defaultClauseIndex = i;
}
}
BindingChain?[] clauseBindings = [];
clauseBindings[stmt.clauses.length() - 1] = ();
if binding != () {
// Match expression is a variable
// We get one type narrowing per clause (which combines all the patterns in the clause)
bir:Register unmatchedReg = <bir:Register>matched;
foreach var i in 0 ..< stmt.clauses.length() {
var pos = stmt.clauses[i].opPos;
if i == defaultClauseIndex {
// Safe to cast when i != 0, previous iteration created a narrowed reg.
clauseBindings[i] = i == 0 ? initialBindings : narrow(initialBindings, binding, <bir:NarrowRegister>unmatchedReg, pos);
break;
}
bir:NarrowRegister ifTrueRegister = cx.createNarrowRegister(clauseLooksLike[i], binding.reg, pos);
bir:NarrowRegister ifFalseRegister = cx.createNarrowRegister(clauseUnmatchedLooksLike[i], binding.reg, pos);
bir:BasicBlock nextBlock;
nextBlock = cx.createBasicBlock("gard." + i.toString());
bir:TypeCondBranchInsn branch = {
ifTrue: clauseBlocks[i].label,
ifFalse: nextBlock.label,
ifTrueRegister,
ifFalseRegister,
operand: unmatchedReg,
semType: clausePatternUnions[i],
pos: pos
};
unmatchedReg = ifFalseRegister;
clauseBindings[i] = narrow(initialBindings, binding, ifTrueRegister, pos);
testBlock.insns.push(branch);
testBlock = nextBlock;
}
}
else {
// Match expression is not a variable: we do not get type narrowing
int patternIndex = 0;
foreach var mt in matchTests {
int clauseIndex = mt.clauseIndex;
if clauseIndex == defaultClauseIndex {
break;
}
bir:TmpRegister testResult = cx.createTmpRegister(t:BOOLEAN, mt.pos);
if mt is EqualMatchTest {
bir:EqualityInsn eq = { op: "==", pos: mt.pos, result: testResult, operands: [matched, mt.operand] };
testBlock.insns.push(eq);
}
else {
// We only get here if there is no defaultClauseIndex
// A wildcard match pattern can only not be the default if the type of the match pattern includes error,
// in which case the matched Operand cannot be const.
// So the cast to `bir:Register` is safe.
bir:TypeTestInsn tt = { pos: mt.pos, result: testResult, operand: <bir:Register>matched, semType: mt.bitSet, negated: false };
testBlock.insns.push(tt);
}
bir:BasicBlock nextBlock = cx.createBasicBlock("pattern." + patternIndex.toString());
patternIndex += 1;
bir:CondBranchInsn condBranch = { operand: testResult, ifTrue: clauseBlocks[clauseIndex].label, ifFalse: nextBlock.label, pos: mt.pos } ;
testBlock.insns.push(condBranch);
testBlock = nextBlock;
}
}
bir:BasicBlock? contBlock = ();
BindingChain? bindings = ();
foreach int clauseIndex in 0 ..< stmt.clauses.length() {
s:MatchClause clause = stmt.clauses[clauseIndex];
bir:BasicBlock stmtBlock = clauseBlocks[clauseIndex];
var { block: stmtBlockEnd, bindings: blockBindings } = check codeGenScope(cx, stmtBlock, clauseBindings[clauseIndex] ?: initialBindings, clause.block);
if stmtBlockEnd == () {
continue;
}
else {
bir:BasicBlock b = maybeCreateBasicBlock(ec, contBlock);
contBlock = b;
bir:BranchInsn branchToCont = { dest: b.label, pos: clause.startPos };
stmtBlockEnd.insns.push(branchToCont);
bindings = addAssignments(initialBindings, blockBindings, bindings ?: initialBindings, startRegister);
}
}
if defaultClauseIndex != () {
bir:BranchInsn branch = { dest: clauseBlocks[defaultClauseIndex].label, pos: stmt.clauses[defaultClauseIndex].startPos };
testBlock.insns.push(branch);
if contBlock == () {
// all the clauses have a return or similar
return { block: () };
}
}
else {
bir:BasicBlock b = maybeCreateBasicBlock(ec, contBlock);
contBlock = b;
Position endPos = stmt.clauses.length() > 0 ? (stmt.clauses[stmt.clauses.length() - 1].block.closeBracePos) : stmt.startPos;
bir:BranchInsn branch = { dest: b.label, pos: endPos };
testBlock.insns.push(branch);
}
return { block: contBlock, bindings };
}
function resolveConstMatchPattern(StmtContext cx, BindingChain? bindings, s:SimpleConstExpr expr, t:SemType? expectedType) returns t:SingleValue|ResolveTypeError {
if expr !is s:VarRefExpr || expr.prefix != () || !envDefines(cx, expr.name, bindings) {
var [_, value] = check resolveConstExprForType(cx.syms, cx.moduleLevelDefn, expr, expectedType, "pattern will not be matched");
return value;
}
return cx.semanticErr(`match pattern is not constant`, s:range(expr));
}
function maybeCreateBasicBlock(ExprContext cx, bir:BasicBlock? block) returns bir:BasicBlock {
if block == () {
return cx.createBasicBlock();
}
else {
return block;
}
}
function codeGenIfElseStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:IfElseStmt stmt) returns CodeGenError|StmtEffect {
ExprContext ec = cx.exprContext(initialBindings);
var { condition, ifTrue, ifFalse } = stmt;
CondExprEffect condEffect = check codeGenExprForCond(ec, startBlock, condition);
var {trueMerger, falseMerger} = condEffect;
if trueMerger == () || falseMerger == () {
// this will happen when type of condition is singleton true or singleton false
var [constCond, merger] = typeMergerPairSingleton(condEffect);
[Scope?, Scope?] [taken, notTaken] = constCond ? [ifTrue, ifFalse] : [ifFalse, ifTrue];
s:Stmt? errStmt = scopeFirstStmt(notTaken);
if errStmt != () {
return cx.semanticErr("unreachable code", s:range(errStmt));
}
if taken != () {
return codeGenScopeWithTypeMerger(cx, merger, initialBindings, taken);
}
else {
// `if false` without `else` block.
return { block: merger.dest };
}
}
else {
cx.openRegion(startBlock.label, bir:REGION_COND);
var { block: ifContBlock, bindings: ifBindings } = check codeGenScopeWithTypeMerger(cx, trueMerger, initialBindings, ifTrue);
if ifFalse == () {
// Just an if branch
TypeMerger contMerger = falseMerger;
if ifBindings != () && ifContBlock != () { // ifContBlock != () is redundant
bir:BranchInsn branch = { dest: falseMerger.dest.label, pos: stmt.condition.startPos };
ifContBlock.insns.push(branch);
contMerger = { dest: falseMerger.dest, origins: { bindings: ifBindings, label: ifContBlock.label, prev: falseMerger.origins } };
}
cx.closeRegion(contMerger.dest.label);
return codeGenTypeMergeFromMerger(ec, contMerger, ifTrue.endPos);
}
else {
// An if and an else
var { block: elseContBlock, bindings: elseBindings } = check codeGenScopeWithTypeMerger(cx, falseMerger, initialBindings, ifFalse);
if ifContBlock != () && elseContBlock != () {
// this is the case where we have a real type merge
bir:BasicBlock contBlock = cx.createBasicBlock();
Position joinPos = (ifFalse is s:StmtBlock ? ifFalse : ifFalse.ifTrue).closeBracePos;
bir:BranchInsn branch = { dest: contBlock.label, pos: joinPos };
ifContBlock.insns.push(branch);
elseContBlock.insns.push(branch);
TypeMergerOrigin? combinedOrigin = { bindings: ifBindings, label: ifContBlock.label, prev: { bindings: elseBindings, label: elseContBlock.label, prev: () } };
BindingChain? bindings = codeGenTypeMerge(ec, contBlock, initialBindings, combinedOrigin, ifTrue.endPos);
cx.closeRegion(contBlock.label);
return { block: contBlock, bindings };
}
else {
// One or both arms are branching outside.
bir:BasicBlock? contBlock = ifContBlock ?: elseContBlock;
BindingChain? bindings = ifBindings ?: elseBindings;
cx.closeRegion(contBlock?.label);
return { block: contBlock, bindings };
}
}
}
}
// code gen a scope that might start with a TypeMergeInsn, ie might have multiple branches coming in.
function codeGenScopeWithTypeMerger(StmtContext cx, TypeMerger merger, BindingChain? initialBindings, Scope scope) returns CodeGenError|StmtEffect {
var { bindings } = codeGenTypeMergeFromMerger(cx.exprContext(initialBindings), merger, scope.startPos);
return codeGenScope(cx, merger.dest, bindings, scope);
}
function scopeFirstStmt(Scope? s) returns s:Stmt? {
if s is s:IfElseStmt {
return scopeFirstStmt(s.ifTrue) ?: scopeFirstStmt(s.ifFalse);
}
else if s is s:StmtBlock {
if s.stmts.length() > 0 {
return s.stmts[0];
}
}
return ();
}
function codeGenReturnStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:ReturnStmt stmt) returns CodeGenError|StmtEffect {
var { returnExpr } = stmt;
bir:BasicBlock nextBlock;
bir:Operand operand;
if returnExpr is s:Expr {
{ result: operand, block: nextBlock } = check cx.codeGenExpr(startBlock, initialBindings, cx.returnType, returnExpr);
}
else {
operand = bir:NIL_OPERAND;
nextBlock = startBlock;
}
bir:RetInsn insn = { operand, pos: stmt.kwPos };
nextBlock.insns.push(insn);
return { block: () };
}
function codeGenPanicStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:PanicStmt stmt) returns CodeGenError|StmtEffect {
var { panicExpr } = stmt;
var { result: operand, block: nextBlock } = check cx.codeGenExpr(startBlock, initialBindings, t:ERROR, panicExpr);
if operand is bir:Register && t:isSubtypeSimple(operand.semType, t:ERROR) {
bir:PanicInsn insn = { operand, pos: stmt.kwPos };
nextBlock.insns.push(insn);
return { block: () };
}
else {
return cx.semanticErr("argument to panic must be a error", stmt.startPos);
}
}
function codeGenVarDeclStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:VarDeclStmt stmt) returns CodeGenError|StmtEffect {
var { name, namePos, initExpr, td, isFinal } = stmt;
if name is s:WILDCARD {
return codeGenWildcardDeclStmt(cx, startBlock, initialBindings, initExpr, td, stmt.opPos);
}
else {
if envDefines(cx, name, initialBindings) {
return cx.semanticErr(`duplicate declaration of ${name}`, namePos);
}
t:SemType semType = check cx.resolveTypeDesc(td);
bir:VarRegister|bir:FinalRegister result = isFinal ? cx.createFinalRegister(semType, namePos, name) : cx.createVarRegister(semType, namePos, name);
bir:BasicBlock nextBlock = check codeGenAssign(cx, initialBindings, startBlock, result, initExpr, semType, stmt.opPos);
return { block: nextBlock, bindings: { head: { name, reg: result, isFinal }, prev: initialBindings } };
}
}
function codeGenWildcardDeclStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:Expr expr, s:TypeDesc td, Position pos) returns CodeGenError|StmtEffect {
t:SemType semType = check cx.resolveTypeDesc(td);
if !t:isSubtype(cx.syms.tc, semType, t:ANY) {
return cx.semanticErr("type descriptor of wildcard should be a subtype of any", pos);
}
bir:BasicBlock nextBlock = check codeGenAssign(cx, initialBindings, startBlock, cx.createVarRegister(semType, pos, "_"), expr, semType, pos);
return { block: nextBlock };
}
function codeGenAssignStmt(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, s:AssignStmt stmt) returns CodeGenError|StmtEffect {
var { lValue, expr } = stmt;
if lValue is s:VarRefExpr {
return codeGenAssignToVar(cx, startBlock, initialBindings, lValue.name, expr, stmt.opPos);
}
else if lValue is s:WILDCARD {
bir:BasicBlock nextBlock = check codeGenAssign(cx, initialBindings, startBlock, cx.createVarRegister(t:ANY, stmt.opPos, "_"), expr, t:ANY, stmt.opPos);
return { block: nextBlock };
}
else {
return codeGenAssignToMember(cx, startBlock, initialBindings, lValue, expr);
}
}
function codeGenAssignToVar(StmtContext cx, bir:BasicBlock startBlock, BindingChain? initialBindings, string varName, s:Expr expr, Position pos) returns CodeGenError|StmtEffect {
var [unnarrowedReg, bindings] = check lookupVarRefForAssign(cx, initialBindings, varName, pos);
bir:BasicBlock nextBlock = check codeGenAssign(cx, initialBindings, startBlock, unnarrowedReg, expr, unnarrowedReg.semType, pos);
return { block: nextBlock, bindings };
}
function lookupVarRefForAssign(StmtContext cx, BindingChain? initialBindings, string varName, Position pos) returns CodeGenError|[bir:VarRegister|bir:CapturedRegister, BindingChain?] {
var { binding, inOuterFunction } = check lookupVarRefBinding(cx, varName, initialBindings, pos);
DeclBinding unnarrowed = unnarrowBinding(binding);
if unnarrowed.isFinal {
return cx.semanticErr(`cannot assign to ${varName}`, pos);
}
bir:VarRegister|bir:CapturedRegister reg;
bir:VarRegister unnarrowedReg = <bir:VarRegister>unnarrowed.reg; // assigning to final or param registers are semantic errors
if inOuterFunction {
reg = cx.getCaptureRegister(unnarrowedReg.semType, unnarrowedReg, pos);
}
else {
reg = unnarrowedReg;
}
BindingChain? bindings;
if binding is NarrowBinding {
// create an assignment binding shadowing the narrowed binding
bindings = { head: { name: varName, reg, unnarrowed, pos, invalidates: binding.reg }, prev: initialBindings };
}
else {
// no narrowed binding in effect
bindings = ();
}
return [reg, bindings];
}
function codeGenAssign(StmtContext cx, BindingChain? initialBindings, bir:BasicBlock block, bir:VarRegister|bir:FinalRegister|bir:CapturedRegister result, s:Expr expr, t:SemType semType, Position pos) returns CodeGenError|bir:BasicBlock {
var { result: operand, block: nextBlock } = check cx.codeGenExpr(block, initialBindings, semType, expr);
bir:AssignInsn insn = { pos, result, operand };
nextBlock.insns.push(insn);
return nextBlock;
}