@@ -306,8 +306,7 @@ void Compiler::CompileFor(const node::Loop *loop) {
306
306
307
307
CHECK_AST_NODE (node::type_ast_loop_, loop);
308
308
309
- if (!this ->unit_ ->symt ->NewNestedTable ())
310
- throw DatatypeException ();
309
+ this ->unit_ ->EnterSub ();
311
310
312
311
if (loop->init != nullptr )
313
312
this ->Compile (loop->init );
@@ -356,7 +355,7 @@ void Compiler::CompileFor(const node::Loop *loop) {
356
355
357
356
this ->unit_ ->JBPop ();
358
357
359
- SymbolExitNested ( this ->unit_ ->symt );
358
+ this ->unit_ ->ExitSub ( false );
360
359
361
360
this ->unit_ ->BlockAppend (end);
362
361
}
@@ -367,8 +366,7 @@ void Compiler::CompileForEach(const node::Loop *loop) {
367
366
368
367
CHECK_AST_NODE (node::type_ast_loop_, loop);
369
368
370
- if (!this ->unit_ ->symt ->NewNestedTable ())
371
- throw DatatypeException ();
369
+ this ->unit_ ->EnterSub ();
372
370
373
371
if ((end = BasicBlockNew ()) == nullptr )
374
372
throw DatatypeException ();
@@ -407,7 +405,7 @@ void Compiler::CompileForEach(const node::Loop *loop) {
407
405
408
406
this ->unit_ ->JBPop ();
409
407
410
- SymbolExitNested ( this ->unit_ ->symt );
408
+ this ->unit_ ->ExitSub ( false );
411
409
412
410
this ->unit_ ->BlockAppend (end);
413
411
@@ -542,8 +540,7 @@ void Compiler::CompileIF(const node::Branch *branch) {
542
540
543
541
this ->unit_ ->BlockNew ();
544
542
545
- if (!this ->unit_ ->symt ->NewNestedTable ())
546
- throw DatatypeException ();
543
+ this ->unit_ ->EnterSub ();
547
544
548
545
if (merge)
549
546
this ->unit_ ->symt ->stack ->nested --;
@@ -560,22 +557,21 @@ void Compiler::CompileIF(const node::Branch *branch) {
560
557
orelse = nullptr ; // Avoid releasing it in case of an exception.
561
558
562
559
if (AR_TYPEOF (branch->orelse , node::type_ast_unary_)) {
563
- if (!this ->unit_ ->symt ->NewNestedTable ())
564
- throw DatatypeException ();
560
+ this ->unit_ ->EnterSub ();
565
561
566
562
if (merge)
567
563
this ->unit_ ->symt ->stack ->nested --;
568
564
569
565
this ->CompileBlock (branch->orelse , false );
570
566
571
- SymbolExitNested ( this ->unit_ ->symt , merge);
567
+ this ->unit_ ->ExitSub ( merge);
572
568
} else if (AR_TYPEOF (branch->orelse , node::type_ast_branch_))
573
569
this ->CompileIF ((const node::Branch *) branch->orelse );
574
570
else
575
571
throw CompilerException (kCompilerErrors [1 ], (int ) branch->orelse ->node_type , __FUNCTION__);
576
572
}
577
573
578
- SymbolExitNested ( this ->unit_ ->symt , merge);
574
+ this ->unit_ ->ExitSub ( merge);
579
575
} catch (...) {
580
576
if (orelse != end) {
581
577
BasicBlockDel (orelse);
@@ -819,8 +815,7 @@ void Compiler::CompileSwitchCase(const node::Binary *swcase, BasicBlock **ltest,
819
815
820
816
CHECK_AST_NODE (node::type_ast_switchcase_, swcase);
821
817
822
- if (!this ->unit_ ->symt ->NewNestedTable ())
823
- throw DatatypeException ();
818
+ this ->unit_ ->EnterSub ();
824
819
825
820
if ((*lbody)->size > 0 ) {
826
821
// Switch to bodies thread
@@ -879,7 +874,7 @@ void Compiler::CompileSwitchCase(const node::Binary *swcase, BasicBlock **ltest,
879
874
if (!fallthrough)
880
875
this ->unit_ ->Emit (vm::OpCode::JMP, 0 , end, nullptr );
881
876
882
- SymbolExitNested ( this ->unit_ ->symt );
877
+ this ->unit_ ->ExitSub ( false );
883
878
884
879
*lbody = this ->unit_ ->bbb .current ;
885
880
}
@@ -1161,7 +1156,6 @@ void Compiler::IdentifierNew(String *name, const scanner::Loc *loc, SymbolType t
1161
1156
if (!sym)
1162
1157
throw DatatypeException ();
1163
1158
1164
- auto *dest = this ->unit_ ->names ;
1165
1159
auto *p_sym = (SymbolT *) sym.Get ();
1166
1160
1167
1161
p_sym->declared = true ;
@@ -1174,36 +1168,33 @@ void Compiler::IdentifierNew(String *name, const scanner::Loc *loc, SymbolType t
1174
1168
}
1175
1169
1176
1170
if (p_sym->nested == 0 ) {
1177
- auto id = (unsigned short ) (p_sym->id >= 0 ? p_sym->id : dest ->length );
1171
+ auto id = (unsigned short ) (p_sym->id >= 0 ? p_sym->id : this -> unit_ -> names ->length );
1178
1172
1179
1173
if (emit)
1180
1174
this ->unit_ ->Emit (vm::OpCode::NGV, (unsigned char ) aflags, id, loc);
1181
1175
1182
1176
if (p_sym->id >= 0 )
1183
1177
return ;
1184
- } else {
1185
- dest = this ->unit_ ->locals ;
1186
1178
1187
- if (emit)
1188
- this ->unit_ ->Emit (vm::OpCode::STLC, (int ) dest->length , nullptr , loc);
1189
- }
1179
+ p_sym->id = (short ) this ->unit_ ->names ->length ;
1190
1180
1191
- ArObject *arname;
1181
+ if (!ListAppend (this ->unit_ ->names , (ArObject *) name))
1182
+ throw DatatypeException ();
1192
1183
1193
- if (p_sym->id >= 0 )
1194
- arname = ListGet (!p_sym->free ? this ->unit_ ->names : this ->unit_ ->enclosed , p_sym->id );
1195
- else
1196
- arname = (ArObject *) IncRef (name);
1184
+ return ;
1185
+ }
1197
1186
1198
- p_sym->id = (short ) dest->length ;
1187
+ if (emit)
1188
+ this ->unit_ ->Emit (vm::OpCode::STLC, (int ) this ->unit_ ->local .current , nullptr , loc);
1199
1189
1200
- if (!ListAppend (dest, arname)) {
1201
- Release (arname);
1190
+ p_sym->id = (short ) this ->unit_ ->local .current ;
1202
1191
1203
- throw DatatypeException ();
1204
- }
1192
+ this ->unit_ ->local .current ++;
1193
+ if (this ->unit_ ->local .required < this ->unit_ ->local .current )
1194
+ this ->unit_ ->local .required ++;
1205
1195
1206
- Release (arname);
1196
+ if (!emit && !ListAppend (this ->unit_ ->lnames , (ArObject *) name))
1197
+ throw DatatypeException ();
1207
1198
}
1208
1199
1209
1200
void Compiler::IdentifierNew (const node::Unary *id, SymbolType type, AttributeFlag aflags, bool emit) {
@@ -1259,14 +1250,14 @@ void Compiler::CompileBlock(const node::Node *node, bool sub) {
1259
1250
if (!iter)
1260
1251
throw DatatypeException ();
1261
1252
1262
- if (sub && ! this -> unit_ -> symt -> NewNestedTable () )
1263
- throw DatatypeException ();
1253
+ if (sub)
1254
+ this -> unit_ -> EnterSub ();
1264
1255
1265
1256
while ((stmt = IteratorNext (iter.Get ())))
1266
1257
this ->Compile ((const node::Node *) stmt.Get ());
1267
1258
1268
1259
if (sub)
1269
- SymbolExitNested ( this ->unit_ ->symt );
1260
+ this ->unit_ ->ExitSub ( false );
1270
1261
}
1271
1262
1272
1263
void Compiler::CompileCall (const node::Call *call) {
0 commit comments