Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions origin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.bak
*.exe
*.xex
*.tmp
*.log
*.lps
backup/
lib/
54 changes: 53 additions & 1 deletion origin/Common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ TIdentifier = record
NumDefines: integer = 1; // NumDefines = AddDefines

NumTok, NumIdent, NumTypes, NumPredefIdent, NumStaticStrChars, NumUnits, NumBlocks, NumProc,
BlockStackTop, CodeSize, CodePosStackTop, BreakPosStackTop, VarDataSize, Pass, ShrShlCnt,
BlockStackTop, CodeSize, CodePosStackTop, BreakPosStackTop, _VarDataSize, Pass, ShrShlCnt,
NumStaticStrCharsTmp, AsmBlockIndex, IfCnt, CaseCnt, IfdefLevel, run_func: Integer;

iOut: integer = -1;
Expand Down Expand Up @@ -675,12 +675,64 @@ TIdentifier = record

function StrToInt(const a: string): Int64;

type TTokenIndex = Integer;
procedure IncVarDataSize(const tokenIndex: TTokenIndex; const size: Integer);

function GetVarDataSize: Integer;
procedure SetVarDataSize(const tokenIndex: TTokenIndex; const size: Integer);

var TraceFile: TextFile;
procedure LogTrace(message: String);

// ----------------------------------------------------------------------------

implementation

uses SysUtils, Messages;

procedure LogTrace(message: String);
begin
{$IFDEF USETRACEFILE}
Writeln(traceFile, message);
{$ENDIF}
end;

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

function GetVarDataSize: Integer;
begin
Result := _VarDataSize;
end;


procedure SetVarDataSize(const tokenIndex: TTokenIndex; const size: Integer);
var token: TToken;
// var GetSourceFileLocationString: String;

begin
_VarDataSize := size;
token:= Tok[tokenIndex];

(*
GetSourceFileLocationString := UnitName[ token.UnitIndex].Path;

if (token.line>0) then
begin
GetSourceFileLocationString:=GetSourceFileLocationString+ ' ( line ' + IntToStr(token.Line) + ', column ' + IntToStr(token.Column) + ')';
end;


// LogTrace(Format('SetVarDataSize: TokenIndex=%d: %s %s VarDataSize=%d', [tokenIndex, GetSourceFileLocationString,'TODO', _VarDataSize]));
*)
end;


procedure IncVarDataSize(const tokenIndex: TTokenIndex; const size: Integer);
begin
SetVarDataSize(tokenIndex, _VarDataSize + size);
end;

// ----------------------------------------------------------------------------


Expand Down
19 changes: 11 additions & 8 deletions origin/Parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ procedure SaveToDataSegment(ConstDataSize: integer; ConstVal: Int64; ConstValTyp
var ftmp: TFloat;
begin

// LogTrace(Format('SaveToDataSegment(index=%d, value=%d, valueDataType=%d', [ConstDataSize, ConstVal, ConstValType]));


if (ConstDataSize < 0) or (ConstDataSize > $FFFF) then begin writeln('SaveToDataSegment: ', ConstDataSize); halt end;

ftmp:=Default(TFloat);
Expand Down Expand Up @@ -1747,10 +1750,10 @@ procedure DefineIdent(ErrTokenIndex: Integer; Name: TString; Kind: Byte; DataTyp
if Ident[NumIdent].isAbsolute then
Ident[NumIdent].Value := Data - 1
else
Ident[NumIdent].Value := DATAORIGIN + VarDataSize; // Variable address
Ident[NumIdent].Value := DATAORIGIN + GetVarDataSize; // Variable address

if not OutputDisabled then
VarDataSize := VarDataSize + DataSize[DataType];
IncVarDataSize( ErrTokenIndex,DataSize[DataType]);

Ident[NumIdent].NumAllocElements := NumAllocElements; // Number of array elements (0 for single variable)
Ident[NumIdent].NumAllocElements_ := NumAllocElements_;
Expand All @@ -1760,28 +1763,28 @@ procedure DefineIdent(ErrTokenIndex: Integer; Name: TString; Kind: Byte; DataTyp
if not OutputDisabled then begin

if (DataType = POINTERTOK) and (AllocElementType in [RECORDTOK, OBJECTTOK]) and (NumAllocElements_ = 0) then
inc(VarDataSize, DataSize[POINTERTOK])
IncVarDataSize( ErrTokenIndex, DataSize[POINTERTOK])
else

if DataType in [ENUMTYPE] then
inc(VarDataSize)
IncVarDataSize( ErrTokenIndex,1)
else
if (DataType in [RECORDTOK, OBJECTTOK]) and (NumAllocElements > 0) then
VarDataSize := VarDataSize + 0
IncVarDataSize( ErrTokenIndex, 0)
else
if (DataType in [FILETOK, TEXTFILETOK]) and (NumAllocElements > 0) then
VarDataSize := VarDataSize + 12
IncVarDataSize( ErrTokenIndex, 12)
else begin

if (Ident[NumIdent].idType = ARRAYTOK) and (Ident[NumIdent].isAbsolute = false) and (Elements(NumIdent) = 1) then // [0..0] ; [0..0, 0..0]

else
VarDataSize := VarDataSize + integer(Elements(NumIdent) * DataSize[AllocElementType]);
IncVarDataSize( ErrTokenIndex, integer(Elements(NumIdent) * DataSize[AllocElementType]));

end;


if NumAllocElements > 0 then dec(VarDataSize, DataSize[DataType]);
if NumAllocElements > 0 then IncVarDataSize( ErrTokenIndex,-DataSize[DataType]);

end;

Expand Down
2 changes: 1 addition & 1 deletion origin/Scanner.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ procedure TokenizeProgramInitialization;
SetLength(msgWarning, 1);
SetLength(msgNote, 1);

NumBlocks := 0; BlockStackTop := 0; CodeSize := 0; CodePosStackTop := 0; VarDataSize := 0;
NumBlocks := 0; BlockStackTop := 0; CodeSize := 0; CodePosStackTop := 0; SetVarDataSize(0,0);
CaseCnt := 0; IfCnt := 0; ShrShlCnt := 0; NumTypes := 0; run_func := 0; NumProc := 0;
NumTok := 0; NumIdent := 0;

Expand Down
4 changes: 4 additions & 0 deletions origin/define.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//{$DEFINE WHILEDO}

//{$DEFINE USEOPTFILE}
//{$DEFINE USETRACEFILE}

{$DEFINE OPTIMIZECODE}

// The origin version still relies on accessing the element [0] of arrays starting at 1.
{$RANGECHECKS OFF}

{$I+}
Loading
Loading