mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-09-27 18:58:34 +00:00
Allocate staticNum prefixes only for scopes that have statics.
This is somewhat faster, and also reduces the theoretical chance of overflowing the available staticNum values for a large source file.
This commit is contained in:
parent
a7551d8c44
commit
53fcb84352
57
Symbol.pas
57
Symbol.pas
@ -77,9 +77,10 @@ type
|
|||||||
{NOTE: the array of buckets must come first in the record!}
|
{NOTE: the array of buckets must come first in the record!}
|
||||||
buckets: array[0..hashSize2] of identPtr; {hash buckets}
|
buckets: array[0..hashSize2] of identPtr; {hash buckets}
|
||||||
next: symbolTablePtr; {next symbol table}
|
next: symbolTablePtr; {next symbol table}
|
||||||
staticNum: packed array[1..6] of char; {staticNum at start of table}
|
|
||||||
isEmpty: boolean; {is the pool empty (nothing in buckets)?}
|
isEmpty: boolean; {is the pool empty (nothing in buckets)?}
|
||||||
noStatics: boolean; {no statics using this staticNum?}
|
case noStatics: boolean of {no statics/staticNum for this table?}
|
||||||
|
false: (staticNum: packed array[1..6] of char); {staticNum for this table}
|
||||||
|
true: ();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -1216,7 +1217,7 @@ while sPtr <> nil do begin
|
|||||||
end; {while}
|
end; {while}
|
||||||
|
|
||||||
{rescan for a static variable}
|
{rescan for a static variable}
|
||||||
if staticAllowed then begin
|
if staticAllowed and not sPtr^.noStatics then begin
|
||||||
if np = nil then begin {form the static name}
|
if np = nil then begin {form the static name}
|
||||||
if length(name^) < 251 then begin
|
if length(name^) < 251 then begin
|
||||||
new(np);
|
new(np);
|
||||||
@ -2315,6 +2316,30 @@ var
|
|||||||
p: identPtr; {work pointer}
|
p: identPtr; {work pointer}
|
||||||
tk: tokenType; {fake token; for FindSymbol}
|
tk: tokenType; {fake token; for FindSymbol}
|
||||||
|
|
||||||
|
|
||||||
|
procedure AllocateStaticNum;
|
||||||
|
|
||||||
|
{ Allocate a staticNum value for the current table. }
|
||||||
|
|
||||||
|
var
|
||||||
|
done: boolean; {loop termination}
|
||||||
|
i: integer; {loop index}
|
||||||
|
|
||||||
|
begin {AllocateStaticNum}
|
||||||
|
i := 5; {increment the static var number}
|
||||||
|
repeat
|
||||||
|
staticNum[i] := succ(staticNum[i]);
|
||||||
|
done := staticNum[i] <> succ('9');
|
||||||
|
if not done then begin
|
||||||
|
staticNum[i] := '0';
|
||||||
|
i := i-1;
|
||||||
|
done := i = 1;
|
||||||
|
end; {if}
|
||||||
|
until done;
|
||||||
|
table^.staticNum := staticNum; {record the static symbol table number}
|
||||||
|
end; {AllocateStaticNum}
|
||||||
|
|
||||||
|
|
||||||
procedure UnInline;
|
procedure UnInline;
|
||||||
|
|
||||||
{ Generate a non-inline definition for a function previously }
|
{ Generate a non-inline definition for a function previously }
|
||||||
@ -2344,6 +2369,7 @@ var
|
|||||||
Gen0(dc_enp);
|
Gen0(dc_enp);
|
||||||
end; {UnInline}
|
end; {UnInline}
|
||||||
|
|
||||||
|
|
||||||
begin {NewSymbol}
|
begin {NewSymbol}
|
||||||
needSymbol := true; {assume we need a symbol}
|
needSymbol := true; {assume we need a symbol}
|
||||||
isGlobal := false; {set up defaults}
|
isGlobal := false; {set up defaults}
|
||||||
@ -2405,11 +2431,16 @@ if space <> fieldListSpace then begin {are we defining a function?}
|
|||||||
end; {if}
|
end; {if}
|
||||||
end; {if}
|
end; {if}
|
||||||
end; {if}
|
end; {if}
|
||||||
if class = staticsy then {statics go in the global symbol table}
|
if needSymbol then begin
|
||||||
|
if class = staticsy then {statics go in the global symbol table}
|
||||||
if not isFunction then
|
if not isFunction then
|
||||||
if globalTable <> table then begin
|
if globalTable <> table then begin
|
||||||
isGlobal := true; {note that we will use the global table}
|
isGlobal := true; {note that we will use the global table}
|
||||||
useGlobalPool := true;
|
useGlobalPool := true;
|
||||||
|
if table^.noStatics then begin
|
||||||
|
table^.noStatics := false;
|
||||||
|
AllocateStaticNum;
|
||||||
|
end; {if}
|
||||||
np := pointer(GMalloc(length(name^)+6)); {form static name}
|
np := pointer(GMalloc(length(name^)+6)); {form static name}
|
||||||
np^[0] := chr(5+length(name^));
|
np^[0] := chr(5+length(name^));
|
||||||
for i := 1 to 5 do
|
for i := 1 to 5 do
|
||||||
@ -2418,7 +2449,6 @@ if class = staticsy then {statics go in the global symbol table}
|
|||||||
np^[i+5] := name^[i];
|
np^[i+5] := name^[i];
|
||||||
name := np;
|
name := np;
|
||||||
end; {if}
|
end; {if}
|
||||||
if needSymbol then begin
|
|
||||||
p := pointer(Calloc(sizeof(identRecord))); {get space for the record}
|
p := pointer(Calloc(sizeof(identRecord))); {get space for the record}
|
||||||
{p^.iPtr := nil;} {no initializers, yet}
|
{p^.iPtr := nil;} {no initializers, yet}
|
||||||
{p^.saved := 0;} {not saved}
|
{p^.saved := 0;} {not saved}
|
||||||
@ -2433,10 +2463,8 @@ if needSymbol then begin
|
|||||||
hashPtr := pointer(ord4(table)+Hash(name));
|
hashPtr := pointer(ord4(table)+Hash(name));
|
||||||
table^.isEmpty := false;
|
table^.isEmpty := false;
|
||||||
end {if}
|
end {if}
|
||||||
else begin
|
else
|
||||||
hashPtr := pointer(ord4(globalTable)+Hash(name));
|
hashPtr := pointer(ord4(globalTable)+Hash(name));
|
||||||
table^.noStatics := false;
|
|
||||||
end; {else}
|
|
||||||
if space = tagSpace then
|
if space = tagSpace then
|
||||||
hashPtr := pointer(ord4(hashPtr) + 4*(hashSize+1));
|
hashPtr := pointer(ord4(hashPtr) + 4*(hashSize+1));
|
||||||
p^.next := hashPtr^;
|
p^.next := hashPtr^;
|
||||||
@ -2513,21 +2541,9 @@ procedure PushTable;
|
|||||||
{ Create a new symbol table, pushing the old one }
|
{ Create a new symbol table, pushing the old one }
|
||||||
|
|
||||||
var
|
var
|
||||||
done: boolean; {loop termination}
|
|
||||||
i: integer; {loop index}
|
|
||||||
tPtr: symbolTablePtr; {work pointer}
|
tPtr: symbolTablePtr; {work pointer}
|
||||||
|
|
||||||
begin {PushTable}
|
begin {PushTable}
|
||||||
i := 5; {increment the static var number}
|
|
||||||
repeat
|
|
||||||
staticNum[i] := succ(staticNum[i]);
|
|
||||||
done := staticNum[i] <> succ('9');
|
|
||||||
if not done then begin
|
|
||||||
staticNum[i] := '0';
|
|
||||||
i := i-1;
|
|
||||||
done := i = 1;
|
|
||||||
end; {if}
|
|
||||||
until done;
|
|
||||||
if tablePool <> nil then begin {use existing empty table if available}
|
if tablePool <> nil then begin {use existing empty table if available}
|
||||||
tPtr := tablePool;
|
tPtr := tablePool;
|
||||||
tablePool := tPtr^.next;
|
tablePool := tPtr^.next;
|
||||||
@ -2540,7 +2556,6 @@ else begin
|
|||||||
end; {else}
|
end; {else}
|
||||||
tPtr^.next := table;
|
tPtr^.next := table;
|
||||||
table := tPtr;
|
table := tPtr;
|
||||||
tPtr^.staticNum := staticNum; {record the static symbol table number}
|
|
||||||
tPtr^.noStatics := true;
|
tPtr^.noStatics := true;
|
||||||
end; {PushTable}
|
end; {PushTable}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user