Skip to content

Commit ada1134

Browse files
authored
Merge pull request #1781 from GaijinEntertainment/stack-opts
optimized stack by default, also args
2 parents 3fc2dc4 + 0ef792f commit ada1134

File tree

7 files changed

+137
-52
lines changed

7 files changed

+137
-52
lines changed

include/daScript/ast/ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ namespace das
14861486
bool log_compile_time = false; // if true, then compile time will be printed at the end of the compilation
14871487
bool log_total_compile_time = false; // if true, then detailed compile time will be printed at the end of the compilation
14881488
bool no_fast_call = false; // disable fastcall
1489-
bool scoped_stack_allocator = false; // reuse stack memory after variables out of scope
1489+
bool scoped_stack_allocator = true; // reuse stack memory after variables out of scope
14901490
// debugger
14911491
// when enabled
14921492
// 1. disables [fastcall]

src/ast/ast_allocate_stack.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace das {
99
public:
1010
VarCMRes( const ProgramPtr & prog, bool everything ) {
1111
program = prog;
12-
isEverything = everything
13-
;
12+
isEverything = everything;
1413
}
1514
protected:
1615
vector<ExprBlock *> blocks;
@@ -128,6 +127,7 @@ namespace das {
128127
log_var_scope = prog->options.getBoolOption("log_var_scope");
129128
optimize = prog->getOptimize();
130129
noFastCall = prog->options.getBoolOption("no_fast_call", prog->policies.no_fast_call);
130+
scopedStackAllocator = prog->options.getBoolOption("scoped_stack_allocator", prog->policies.scoped_stack_allocator);
131131
if( log ) {
132132
logs << "\nSTACK INFORMATION in " << prog->thisModule->name << ":\n";
133133
}
@@ -155,6 +155,7 @@ namespace das {
155155
bool noFastCall = false;
156156
bool isPermanent = false;
157157
bool isEverything = false;
158+
bool scopedStackAllocator = false;
158159
protected:
159160
virtual bool canVisitStructureFieldInit ( Structure * ) override { return false; }
160161
virtual bool canVisitArgumentInit ( Function * , const VariablePtr &, Expression * ) override { return false; }
@@ -180,13 +181,13 @@ namespace das {
180181
}
181182

182183
void pushSp() {
183-
if (program->policies.scoped_stack_allocator) {
184+
if (scopedStackAllocator) {
184185
stackTopStack.emplace_back(StackInfo{stackTop, stackTop});
185186
}
186187
}
187188

188189
StackInfo popSp() {
189-
if (!program->policies.scoped_stack_allocator) {
190+
if (!scopedStackAllocator) {
190191
return {stackTop, stackTop};
191192
}
192193
stackTopStack.back().maxStack = max(stackTopStack.back().maxStack, stackTop);

src/ast/ast_lint.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ namespace das {
874874
"fusion", Type::tBool,
875875
"remove_unused_symbols", Type::tBool,
876876
"no_fast_call", Type::tBool,
877+
"scoped_stack_allocator", Type::tBool,
877878
// language
878879
"always_export_initializer", Type::tBool,
879880
"infer_time_folding", Type::tBool,

src/builtin/builtin.das.inc

Lines changed: 109 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,15 +2242,14 @@ static unsigned char builtin_das[] = {
22422242
0x63,0x74,0x69,0x6f,0x6e,0x5f,0x65,0x78,
22432243
0x69,0x73,0x74,0x73,0x28,0x40,0x40,0x20,
22442244
0x3c,0x20,0x28,0x76,0x61,0x72,0x20,0x61,
2245-
0x20,0x3a,0x20,0x43,0x54,0x20,0x2d,0x20,
2246-
0x23,0x20,0x2d,0x20,0x63,0x6f,0x6e,0x73,
2247-
0x74,0x3b,0x20,0x76,0x61,0x72,0x20,0x62,
2248-
0x20,0x3a,0x20,0x54,0x54,0x20,0x2d,0x20,
2249-
0x23,0x20,0x2d,0x20,0x63,0x6f,0x6e,0x73,
2250-
0x74,0x29,0x20,0x3a,0x20,0x76,0x6f,0x69,
2251-
0x64,0x20,0x3e,0x20,0x5f,0x3a,0x3a,0x65,
2252-
0x6d,0x70,0x6c,0x61,0x63,0x65,0x29,0x29,
2253-
0x20,0x7b,0x0a,
2245+
0x20,0x3a,0x20,0x43,0x54,0x20,0x2d,0x23,
2246+
0x20,0x2d,0x63,0x6f,0x6e,0x73,0x74,0x3b,
2247+
0x20,0x76,0x61,0x72,0x20,0x62,0x20,0x3a,
2248+
0x20,0x54,0x54,0x20,0x2d,0x23,0x20,0x2d,
2249+
0x63,0x6f,0x6e,0x73,0x74,0x29,0x20,0x3a,
2250+
0x20,0x76,0x6f,0x69,0x64,0x20,0x3e,0x20,
2251+
0x5f,0x3a,0x3a,0x65,0x6d,0x70,0x6c,0x61,
2252+
0x63,0x65,0x29,0x29,0x20,0x7b,0x0a,
22542253
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
22552254
0x63,0x6f,0x6e,0x63,0x65,0x70,0x74,0x5f,
22562255
0x61,0x73,0x73,0x65,0x72,0x74,0x28,0x66,
@@ -4907,9 +4906,8 @@ static unsigned char builtin_das[] = {
49074906
0x54,0x54,0x5b,0x74,0x79,0x70,0x65,0x69,
49084907
0x6e,0x66,0x6f,0x20,0x64,0x69,0x6d,0x28,
49094908
0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x73,0x72,
4910-
0x63,0x29,0x5d,0x20,0x2d,0x20,0x63,0x6f,
4911-
0x6e,0x73,0x74,0x20,0x2d,0x20,0x23,0x20,
4912-
0x7b,0x0a,
4909+
0x63,0x29,0x5d,0x20,0x2d,0x63,0x6f,0x6e,
4910+
0x73,0x74,0x20,0x2d,0x23,0x20,0x7b,0x0a,
49134911
0x20,0x20,0x20,0x20,0x75,0x6e,0x73,0x61,
49144912
0x66,0x65,0x20,0x7b,0x0a,
49154913
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
@@ -4918,8 +4916,7 @@ static unsigned char builtin_das[] = {
49184916
0x20,0x54,0x54,0x5b,0x74,0x79,0x70,0x65,
49194917
0x69,0x6e,0x66,0x6f,0x20,0x64,0x69,0x6d,
49204918
0x28,0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x73,
4921-
0x72,0x63,0x29,0x5d,0x20,0x2d,0x20,0x23,
4922-
0x0a,
4919+
0x72,0x63,0x29,0x5d,0x20,0x2d,0x23,0x0a,
49234920
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
49244921
0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x64,0x65,
49254922
0x73,0x74,0x20,0x3a,0x3d,0x20,0x63,0x6c,
@@ -4944,8 +4941,8 @@ static unsigned char builtin_das[] = {
49444941
0x79,0x70,0x65,0x69,0x6e,0x66,0x6f,0x20,
49454942
0x64,0x69,0x6d,0x28,0x63,0x6c,0x6f,0x6e,
49464943
0x65,0x5f,0x73,0x72,0x63,0x29,0x5d,0x20,
4947-
0x2d,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,
4948-
0x2d,0x20,0x23,0x20,0x7b,0x0a,
4944+
0x2d,0x63,0x6f,0x6e,0x73,0x74,0x20,0x2d,
4945+
0x23,0x20,0x7b,0x0a,
49494946
0x20,0x20,0x20,0x20,0x75,0x6e,0x73,0x61,
49504947
0x66,0x65,0x20,0x7b,0x0a,
49514948
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
@@ -4954,8 +4951,7 @@ static unsigned char builtin_das[] = {
49544951
0x20,0x54,0x54,0x5b,0x74,0x79,0x70,0x65,
49554952
0x69,0x6e,0x66,0x6f,0x20,0x64,0x69,0x6d,
49564953
0x28,0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x73,
4957-
0x72,0x63,0x29,0x5d,0x20,0x2d,0x20,0x23,
4958-
0x0a,
4954+
0x72,0x63,0x29,0x5d,0x20,0x2d,0x23,0x0a,
49594955
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
49604956
0x63,0x6c,0x6f,0x6e,0x65,0x5f,0x64,0x65,
49614957
0x73,0x74,0x20,0x3a,0x3d,0x20,0x63,0x6c,
@@ -5468,6 +5464,101 @@ static unsigned char builtin_das[] = {
54685464
0x6f,0x72,0x28,0x61,0x72,0x67,0x73,0x29,
54695465
0x2c,0x20,0x73,0x6b,0x69,0x70,0x5f,0x6c,
54705466
0x6f,0x63,0x6b,0x5f,0x63,0x68,0x65,0x63,
5467+
0x6b,0x5d,0x0a,
5468+
0x64,0x65,0x66,0x20,0x63,0x6c,0x6f,0x6e,
5469+
0x65,0x28,0x76,0x61,0x72,0x20,0x61,0x72,
5470+
0x67,0x73,0x3b,0x20,0x76,0x61,0x72,0x20,
5471+
0x6e,0x61,0x72,0x67,0x73,0x20,0x3a,0x20,
5472+
0x61,0x72,0x72,0x61,0x79,0x3c,0x69,0x6e,
5473+
0x74,0x3e,0x29,0x20,0x7b,0x0a,
5474+
0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,
5475+
0x74,0x6f,0x74,0x20,0x3d,0x20,0x5f,0x3a,
5476+
0x3a,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,
5477+
0x6e,0x61,0x72,0x67,0x73,0x29,0x0a,
5478+
0x20,0x20,0x20,0x20,0x5f,0x3a,0x3a,0x72,
5479+
0x65,0x73,0x69,0x7a,0x65,0x28,0x61,0x72,
5480+
0x67,0x73,0x2c,0x20,0x74,0x6f,0x74,0x29,
5481+
0x0a,
5482+
0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,
5483+
0x28,0x69,0x20,0x69,0x6e,0x20,0x72,0x61,
5484+
0x6e,0x67,0x65,0x28,0x74,0x6f,0x74,0x29,
5485+
0x29,0x20,0x7b,0x0a,
5486+
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
5487+
0x61,0x72,0x67,0x73,0x5b,0x69,0x5d,0x20,
5488+
0x3a,0x3d,0x20,0x6e,0x61,0x72,0x67,0x73,
5489+
0x5b,0x69,0x5d,0x0a,
5490+
0x20,0x20,0x20,0x20,0x7d,0x0a,
5491+
0x7d,0x0a,
5492+
0x0a,
5493+
0x5b,0x65,0x78,0x70,0x65,0x63,0x74,0x5f,
5494+
0x61,0x6e,0x79,0x5f,0x76,0x65,0x63,0x74,
5495+
0x6f,0x72,0x28,0x61,0x72,0x67,0x73,0x29,
5496+
0x2c,0x20,0x73,0x6b,0x69,0x70,0x5f,0x6c,
5497+
0x6f,0x63,0x6b,0x5f,0x63,0x68,0x65,0x63,
5498+
0x6b,0x5d,0x0a,
5499+
0x64,0x65,0x66,0x20,0x63,0x6c,0x6f,0x6e,
5500+
0x65,0x28,0x76,0x61,0x72,0x20,0x61,0x72,
5501+
0x67,0x73,0x3b,0x20,0x76,0x61,0x72,0x20,
5502+
0x6e,0x61,0x72,0x67,0x73,0x20,0x3a,0x20,
5503+
0x61,0x72,0x72,0x61,0x79,0x3c,0x75,0x69,
5504+
0x6e,0x74,0x38,0x3e,0x29,0x20,0x7b,0x0a,
5505+
0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,
5506+
0x74,0x6f,0x74,0x20,0x3d,0x20,0x5f,0x3a,
5507+
0x3a,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,
5508+
0x6e,0x61,0x72,0x67,0x73,0x29,0x0a,
5509+
0x20,0x20,0x20,0x20,0x5f,0x3a,0x3a,0x72,
5510+
0x65,0x73,0x69,0x7a,0x65,0x28,0x61,0x72,
5511+
0x67,0x73,0x2c,0x20,0x74,0x6f,0x74,0x29,
5512+
0x0a,
5513+
0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,
5514+
0x28,0x69,0x20,0x69,0x6e,0x20,0x72,0x61,
5515+
0x6e,0x67,0x65,0x28,0x74,0x6f,0x74,0x29,
5516+
0x29,0x20,0x7b,0x0a,
5517+
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
5518+
0x61,0x72,0x67,0x73,0x5b,0x69,0x5d,0x20,
5519+
0x3a,0x3d,0x20,0x6e,0x61,0x72,0x67,0x73,
5520+
0x5b,0x69,0x5d,0x0a,
5521+
0x20,0x20,0x20,0x20,0x7d,0x0a,
5522+
0x7d,0x0a,
5523+
0x0a,
5524+
0x5b,0x65,0x78,0x70,0x65,0x63,0x74,0x5f,
5525+
0x61,0x6e,0x79,0x5f,0x76,0x65,0x63,0x74,
5526+
0x6f,0x72,0x28,0x61,0x72,0x67,0x73,0x29,
5527+
0x2c,0x20,0x73,0x6b,0x69,0x70,0x5f,0x6c,
5528+
0x6f,0x63,0x6b,0x5f,0x63,0x68,0x65,0x63,
5529+
0x6b,0x5d,0x0a,
5530+
0x64,0x65,0x66,0x20,0x63,0x6c,0x6f,0x6e,
5531+
0x65,0x28,0x76,0x61,0x72,0x20,0x61,0x72,
5532+
0x67,0x73,0x3b,0x20,0x76,0x61,0x72,0x20,
5533+
0x6e,0x61,0x72,0x67,0x73,0x20,0x3a,0x20,
5534+
0x61,0x72,0x72,0x61,0x79,0x3c,0x74,0x75,
5535+
0x70,0x6c,0x65,0x3c,0x75,0x69,0x6e,0x74,
5536+
0x3b,0x20,0x75,0x69,0x6e,0x74,0x3e,0x3e,
5537+
0x29,0x20,0x7b,0x0a,
5538+
0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,
5539+
0x74,0x6f,0x74,0x20,0x3d,0x20,0x5f,0x3a,
5540+
0x3a,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,
5541+
0x6e,0x61,0x72,0x67,0x73,0x29,0x0a,
5542+
0x20,0x20,0x20,0x20,0x5f,0x3a,0x3a,0x72,
5543+
0x65,0x73,0x69,0x7a,0x65,0x28,0x61,0x72,
5544+
0x67,0x73,0x2c,0x20,0x74,0x6f,0x74,0x29,
5545+
0x0a,
5546+
0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,
5547+
0x28,0x69,0x20,0x69,0x6e,0x20,0x72,0x61,
5548+
0x6e,0x67,0x65,0x28,0x74,0x6f,0x74,0x29,
5549+
0x29,0x20,0x7b,0x0a,
5550+
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
5551+
0x61,0x72,0x67,0x73,0x5b,0x69,0x5d,0x20,
5552+
0x3a,0x3d,0x20,0x6e,0x61,0x72,0x67,0x73,
5553+
0x5b,0x69,0x5d,0x0a,
5554+
0x20,0x20,0x20,0x20,0x7d,0x0a,
5555+
0x7d,0x0a,
5556+
0x0a,
5557+
0x5b,0x65,0x78,0x70,0x65,0x63,0x74,0x5f,
5558+
0x61,0x6e,0x79,0x5f,0x76,0x65,0x63,0x74,
5559+
0x6f,0x72,0x28,0x61,0x72,0x67,0x73,0x29,
5560+
0x2c,0x20,0x73,0x6b,0x69,0x70,0x5f,0x6c,
5561+
0x6f,0x63,0x6b,0x5f,0x63,0x68,0x65,0x63,
54715562
0x6b,0x2c,0x20,0x75,0x6e,0x73,0x61,0x66,
54725563
0x65,0x5f,0x77,0x68,0x65,0x6e,0x5f,0x6e,
54735564
0x6f,0x74,0x5f,0x63,0x6c,0x6f,0x6e,0x65,

src/builtin/debugger.das.inc

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,15 @@ static unsigned char debugger_das[] = {
293293
0x67,0x65,0x6e,0x74,0x49,0x6e,0x66,0x6f,
294294
0x29,0x0a,
295295
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
296-
0x75,0x6e,0x73,0x61,0x66,0x65,0x20,0x7b,
297-
0x0a,
298-
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
299-
0x20,0x20,0x20,0x20,0x61,0x67,0x65,0x6e,
300-
0x74,0x50,0x74,0x72,0x2e,0x74,0x68,0x69,
301-
0x73,0x41,0x67,0x65,0x6e,0x74,0x20,0x3d,
302-
0x20,0x72,0x65,0x69,0x6e,0x74,0x65,0x72,
303-
0x70,0x72,0x65,0x74,0x3c,0x44,0x65,0x62,
304-
0x75,0x67,0x41,0x67,0x65,0x6e,0x74,0x3f,
305-
0x3e,0x28,0x61,0x67,0x65,0x6e,0x74,0x41,
306-
0x64,0x61,0x70,0x74,0x65,0x72,0x29,0x0a,
307-
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
308-
0x7d,0x0a,
296+
0x61,0x67,0x65,0x6e,0x74,0x50,0x74,0x72,
297+
0x2e,0x74,0x68,0x69,0x73,0x41,0x67,0x65,
298+
0x6e,0x74,0x20,0x3d,0x20,0x75,0x6e,0x73,
299+
0x61,0x66,0x65,0x28,0x72,0x65,0x69,0x6e,
300+
0x74,0x65,0x72,0x70,0x72,0x65,0x74,0x3c,
301+
0x44,0x65,0x62,0x75,0x67,0x41,0x67,0x65,
302+
0x6e,0x74,0x3f,0x3e,0x28,0x61,0x67,0x65,
303+
0x6e,0x74,0x41,0x64,0x61,0x70,0x74,0x65,
304+
0x72,0x29,0x29,0x0a,
309305
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
310306
0x69,0x6e,0x73,0x74,0x61,0x6c,0x6c,0x5f,
311307
0x64,0x65,0x62,0x75,0x67,0x5f,0x61,0x67,
@@ -365,19 +361,15 @@ static unsigned char debugger_das[] = {
365361
0x67,0x65,0x6e,0x74,0x49,0x6e,0x66,0x6f,
366362
0x29,0x0a,
367363
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
368-
0x75,0x6e,0x73,0x61,0x66,0x65,0x20,0x7b,
369-
0x0a,
370-
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
371-
0x20,0x20,0x20,0x20,0x61,0x67,0x65,0x6e,
372-
0x74,0x50,0x74,0x72,0x2e,0x74,0x68,0x69,
373-
0x73,0x41,0x67,0x65,0x6e,0x74,0x20,0x3d,
374-
0x20,0x72,0x65,0x69,0x6e,0x74,0x65,0x72,
375-
0x70,0x72,0x65,0x74,0x3c,0x44,0x65,0x62,
376-
0x75,0x67,0x41,0x67,0x65,0x6e,0x74,0x3f,
377-
0x3e,0x28,0x61,0x67,0x65,0x6e,0x74,0x41,
378-
0x64,0x61,0x70,0x74,0x65,0x72,0x29,0x0a,
379-
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
380-
0x7d,0x0a,
364+
0x61,0x67,0x65,0x6e,0x74,0x50,0x74,0x72,
365+
0x2e,0x74,0x68,0x69,0x73,0x41,0x67,0x65,
366+
0x6e,0x74,0x20,0x3d,0x20,0x75,0x6e,0x73,
367+
0x61,0x66,0x65,0x28,0x72,0x65,0x69,0x6e,
368+
0x74,0x65,0x72,0x70,0x72,0x65,0x74,0x3c,
369+
0x44,0x65,0x62,0x75,0x67,0x41,0x67,0x65,
370+
0x6e,0x74,0x3f,0x3e,0x28,0x61,0x67,0x65,
371+
0x6e,0x74,0x41,0x64,0x61,0x70,0x74,0x65,
372+
0x72,0x29,0x29,0x0a,
381373
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
382374
0x69,0x6e,0x73,0x74,0x61,0x6c,0x6c,0x5f,
383375
0x64,0x65,0x62,0x75,0x67,0x5f,0x61,0x67,

utils/daScript/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static string projectFile;
2222
static bool aotMacros = false;
2323
static bool profilerRequired = false;
2424
static bool debuggerRequired = false;
25-
static bool scopedStackAllocator = false;
25+
static bool scopedStackAllocator = true;
2626
static bool pauseAfterErrors = false;
2727
static bool quiet = false;
2828
static bool paranoid_validation = false;

utils/dasFormatter/fmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ Result transform_syntax(const string &filename, const string content, format::Fo
225225
format::destroy();
226226
das_yylex_destroy(scanner);
227227
if (err != 0) {
228-
for (const auto err: program->errors) {
229-
tp << err.at.describe() << '\n' << err.what << '\n';
228+
for (const auto erR: program->errors) {
229+
tp << erR.at.describe() << '\n' << erR.what << '\n';
230230
}
231231
if (iter == 0) {
232232
return {};

0 commit comments

Comments
 (0)