Skip to content
Closed
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
12 changes: 7 additions & 5 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ jobs:
sudo apt-get update &&
sudo apt-get install -y fpc
- name: build
run: make
run:
mkdir build
make
- name: list build binaries
run: ls -l bin/
run: ls -l build/
- uses: actions/upload-artifact@v4
with:
name: mp-bin-ubuntu
Expand Down Expand Up @@ -52,17 +54,17 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: mp-bin-ubuntu
path: bin
path: build
- uses: actions/download-artifact@v4
with:
name: mads-bin-ubuntu
path: mads
- name: install mads
run: sudo cp -v mads/mads /usr/local/bin/mads
- name: set permissions
run: sudo chmod a+x bin/mp /usr/local/bin/mads
run: sudo chmod a+x build/mp /usr/local/bin/mads
- name: list binaries from the artifacts
run: ls -l bin/ mads/ /usr/local/bin/mads
run: ls -l build/ mads/ /usr/local/bin/mads
- name: setup test environment
run: make test-setup
- name: run tests
Expand Down
40 changes: 18 additions & 22 deletions src/Common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,16 @@ TType = record
TToken = record
UnitIndex, Column: Smallint;
Line: Integer;
case Kind: Byte of
IDENTTOK:
(Name: ^TString);
INTNUMBERTOK:
(Value: Int64);
FRACNUMBERTOK:
(FracValue: Single);
STRINGLITERALTOK:
(StrAddress: Word;
StrLength: Word);
Kind: Byte;
// For IDENTTOK:
Name: TString;
// For INTNUMBERTOK:
Value: Int64;
// For FRACNUMBERTOK:
FracValue: Single;
// For STRINGLITERALTOK:
StrAddress: Word;
StrLength: Word;
end;

TIdentifier = record
Expand Down Expand Up @@ -448,9 +448,9 @@ TIdentifier = record
isInitialized,
Section: Boolean;

case Kind: Byte of
PROCEDURETOK, FUNCTIONTOK:
(NumParams: Word;
Kind: Byte;
// For PROCEDURETOK, FUNCTIONTOK:
NumParams: Word;
Param: TParamList;
ProcAsBlock: Integer;
ObjectIndex: Integer;
Expand All @@ -469,11 +469,11 @@ TIdentifier = record
isKeep,
isVolatile,
isStriped,
IsNotDead: Boolean;);
IsNotDead: Boolean;

VARIABLE, USERTYPE:
(NumAllocElements, NumAllocElements_: Cardinal;
AllocElementType: Byte);
// For VARIABLE, USERTYPE:
NumAllocElements, NumAllocElements_: Cardinal;
AllocElementType: Byte;
end;


Expand Down Expand Up @@ -905,12 +905,8 @@ function Min(a,b: integer): integer;


procedure FreeTokens;
var i: Integer;
begin

for i := 1 to NumTok do
if (Tok[i].Kind = IDENTTOK) and (Tok[i].Name <> nil) then Dispose(Tok[i].Name);

SetLength(Tok, 0);
SetLength(IFTmpPosStack, 0);
SetLength(UnitPath, 0);
Expand Down Expand Up @@ -963,7 +959,7 @@ function ErrTokenFound(ErrTokenIndex: Integer): string;
procedure CheckOperator(ErrTokenIndex: Integer; op: Byte; DataType: Byte; RightType: Byte = 0);
begin

//writeln(tok[ErrTokenIndex].Name^,',', op,',',DataType);
//writeln(tok[ErrTokenIndex].Name,',', op,',',DataType);

if {(not (DataType in (OrdinalTypes + [REALTOK, POINTERTOK]))) or}
((DataType in RealTypes) and
Expand Down
2 changes: 1 addition & 1 deletion src/Diagnostic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ procedure Diagnostics;
else if Tok[i].Kind = FRACNUMBERTOK then
WriteLn(DiagFile, ' = ', Tok[i].FracValue: 8: 4)
else if Tok[i].Kind = IDENTTOK then
WriteLn(DiagFile, ' = ', Tok[i].Name^)
WriteLn(DiagFile, ' = ', Tok[i].Name)
else if Tok[i].Kind = CHARLITERALTOK then
WriteLn(DiagFile, ' = ', Chr(Tok[i].Value))
else if Tok[i].Kind = STRINGLITERALTOK then
Expand Down
2 changes: 1 addition & 1 deletion src/Messages.pas
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function ErrorMessage(ErrTokenIndex: Integer; err: ErrorCode; IdentIndex: Intege
UnknownIdentifier: if IdentIndex > 0 then
Result := 'Identifier not found ''' + Ident[IdentIndex].Alias + ''''
else
Result := 'Identifier not found ''' + Tok[ErrTokenIndex].Name^ + '''';
Result := 'Identifier not found ''' + Tok[ErrTokenIndex].Name + '''';

IncompatibleTypeOf: Result := 'Incompatible type of ' + Ident[IdentIndex].Name;
IncompatibleEnum: if DstType < 0 then
Expand Down
64 changes: 32 additions & 32 deletions src/Parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ function GetSizeof(i: integer; ValType: byte): Int64;
var IdentIndex: integer;
begin

IdentIndex := GetIdent(Tok[i + 2].Name^);
IdentIndex := GetIdent(Tok[i + 2].Name);

case ValType of

Expand Down Expand Up @@ -618,7 +618,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B
end;

if ConstValType in Pointers then begin
IdentIndex := GetIdent(Tok[i].Name^);
IdentIndex := GetIdent(Tok[i].Name);

if Ident[IdentIndex].AllocElementType in [RECORDTOK, OBJECTTOK] then
ConstVal := Ident[IdentIndex].NumAllocElements_ - 1
Expand Down Expand Up @@ -647,7 +647,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B

if Tok[i + 2].Kind = IDENTTOK then begin

IdentIndex := GetIdent(Tok[i + 2].Name^);
IdentIndex := GetIdent(Tok[i + 2].Name);

if IdentIndex = 0 then
iError(i + 2, UnknownIdentifier);
Expand Down Expand Up @@ -955,7 +955,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B

IDENTTOK:
begin
IdentIndex := GetIdent(Tok[i].Name^);
IdentIndex := GetIdent(Tok[i].Name);

if IdentIndex > 0 then

Expand All @@ -971,13 +971,13 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B
iError(i, TypeMismatch);


if (Ident[GetIdent(Tok[i].Name^)].DataType in RealTypes) and (ConstValType in RealTypes) then begin
if (Ident[GetIdent(Tok[i].Name)].DataType in RealTypes) and (ConstValType in RealTypes) then begin
// ok
end else
if Ident[GetIdent(Tok[i].Name^)].DataType in Pointers then
Error(j, 'Illegal type conversion: "'+InfoAboutToken(ConstValType)+'" to "'+Tok[i].Name^+'"');
if Ident[GetIdent(Tok[i].Name)].DataType in Pointers then
Error(j, 'Illegal type conversion: "'+InfoAboutToken(ConstValType)+'" to "'+Tok[i].Name+'"');

ConstValType := Ident[GetIdent(Tok[i].Name^)].DataType;
ConstValType := Ident[GetIdent(Tok[i].Name)].DataType;

CheckTok(j + 1, CPARTOK);

Expand Down Expand Up @@ -1058,7 +1058,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B
if Tok[i + 1].Kind <> IDENTTOK then
iError(i + 1, IdentifierExpected)
else begin
IdentIndex := GetIdent(Tok[i + 1].Name^);
IdentIndex := GetIdent(Tok[i + 1].Name);

if IdentIndex > 0 then begin

Expand Down Expand Up @@ -1268,7 +1268,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B
CheckTok(i + 1, OPARTOK);


if (Tok[i + 2].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i + 2].Name^)].Kind = FUNCTIONTOK) then
if (Tok[i + 2].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i + 2].Name)].Kind = FUNCTIONTOK) then
isError := TRUE
else
j := CompileConstExpression(i + 2, ConstVal, ConstValType);
Expand All @@ -1279,7 +1279,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B

if (ConstValType in Pointers) and (Tok[i + 2].Kind = IDENTTOK) and (Tok[i + 3].Kind <> OBRACKETTOK) then begin

IdentIndex := GetIdent(Tok[i + 2].Name^);
IdentIndex := GetIdent(Tok[i + 2].Name);

if (Ident[IdentIndex].DataType in Pointers) and ( (Ident[IdentIndex].NumAllocElements > 0) and (Ident[IdentIndex].AllocElementType <> RECORDTOK) ) then
if ((Ident[IdentIndex].AllocElementType <> UNTYPETOK) and (Ident[IdentIndex].NumAllocElements in [0,1])) or (Ident[IdentIndex].DataType = STRINGPOINTERTOK) then begin
Expand Down Expand Up @@ -1843,11 +1843,11 @@ function DeclareFunction(i: integer; out ProcVarIndex: cardinal): integer;
begin

for x := 1 to NumVarOfSameType do
if VarOfSameType[x].Name = Tok[i + 1].Name^ then
Error(i + 1, 'Identifier ' + Tok[i + 1].Name^ + ' is already defined');
if VarOfSameType[x].Name = Tok[i + 1].Name then
Error(i + 1, 'Identifier ' + Tok[i + 1].Name + ' is already defined');

Inc(NumVarOfSameType);
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name^;
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name;
end;

i := i + 2;
Expand Down Expand Up @@ -1957,12 +1957,12 @@ function DefineFunction(i, ForwardIdentIndex: integer; out isForward, isInt, isI

if Tok[i].Kind in [PROCEDURETOK, CONSTRUCTORTOK, DESTRUCTORTOK] then
begin
DefineIdent(i + 1, Tok[i + 1].Name^, Tok[i].Kind, 0, 0, 0, 0);
DefineIdent(i + 1, Tok[i + 1].Name, Tok[i].Kind, 0, 0, 0, 0);
IsNestedFunction := FALSE;
end
else
begin
DefineIdent(i + 1, Tok[i + 1].Name^, FUNCTIONTOK, 0, 0, 0, 0);
DefineIdent(i + 1, Tok[i + 1].Name, FUNCTIONTOK, 0, 0, 0, 0);
IsNestedFunction := TRUE;
end;

Expand Down Expand Up @@ -1998,11 +1998,11 @@ function DefineFunction(i, ForwardIdentIndex: integer; out isForward, isInt, isI
begin

for x := 1 to NumVarOfSameType do
if VarOfSameType[x].Name = Tok[i + 1].Name^ then
Error(i + 1, 'Identifier ' + Tok[i + 1].Name^ + ' is already defined');
if VarOfSameType[x].Name = Tok[i + 1].Name then
Error(i + 1, 'Identifier ' + Tok[i + 1].Name + ' is already defined');

Inc(NumVarOfSameType);
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name^;
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name;
end;

i := i + 2;
Expand Down Expand Up @@ -2180,7 +2180,7 @@ function DefineFunction(i, ForwardIdentIndex: integer; out isForward, isInt, isI

if Tok[i + 1].Kind = IDENTTOK then begin

Ident[NumIdent].Alias := Tok[i + 1].Name^;
Ident[NumIdent].Alias := Tok[i + 1].Name;

if Tok[i + 2].Kind = STRINGLITERALTOK then begin
Ident[NumIdent].Libraries := i + 2;
Expand Down Expand Up @@ -2364,7 +2364,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
end else
if Tok[i + 1].Kind = IDENTTOK then begin

IdentIndex := GetIdent(Tok[i + 1].Name^);
IdentIndex := GetIdent(Tok[i + 1].Name);

if IdentIndex = 0 then begin

Expand Down Expand Up @@ -2430,7 +2430,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi

if Tok[i].Kind = OPARTOK then begin // enumerated

Name := Tok[i-2].Name^;
Name := Tok[i-2].Name;

inc(NumTypes);
RecType := NumTypes;
Expand All @@ -2452,7 +2452,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
CheckTok(i, IDENTTOK);

Inc(NumFieldsInList);
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
FieldInListName[NumFieldsInList].Name := Tok[i].Name;

inc(i);

Expand Down Expand Up @@ -2578,7 +2578,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
if Tok[i].Kind = OBJECTTOK then // Object
begin

Name := Tok[i-2].Name^;
Name := Tok[i-2].Name;

inc(NumTypes);
RecType := NumTypes;
Expand Down Expand Up @@ -2607,7 +2607,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
Ident[NumIdent].IsUnresolvedForward := TRUE;

Ident[NumIdent].ObjectIndex := RecType;
Ident[NumIdent].Name := Name + '.' + Tok[k + 1].Name^;
Ident[NumIdent].Name := Name + '.' + Tok[k + 1].Name;

CheckTok(i, SEMICOLONTOK);

Expand All @@ -2630,7 +2630,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
CheckTok(i, IDENTTOK);

Inc(NumFieldsInList);
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
FieldInListName[NumFieldsInList].Name := Tok[i].Name;

inc(i);

Expand Down Expand Up @@ -2697,7 +2697,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
Ident[NumIdent].IsUnresolvedForward := TRUE;

Ident[NumIdent].ObjectIndex := RecType;
Ident[NumIdent].Name := Name + '.' + Tok[k + 1].Name^;
Ident[NumIdent].Name := Name + '.' + Tok[k + 1].Name;

CheckTok(i, SEMICOLONTOK);

Expand Down Expand Up @@ -2729,7 +2729,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
if (Tok[i].Kind = RECORDTOK) or ((Tok[i].Kind = PACKEDTOK) and (Tok[i+1].Kind = RECORDTOK)) then // Record
begin

Name := Tok[i-2].Name^;
Name := Tok[i-2].Name;

if Tok[i].Kind = PACKEDTOK then inc(i);

Expand All @@ -2751,7 +2751,7 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
CheckTok(i, IDENTTOK);

Inc(NumFieldsInList);
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
FieldInListName[NumFieldsInList].Name := Tok[i].Name;

inc(i);

Expand Down Expand Up @@ -3042,15 +3042,15 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
// USERTYPE
// -----------------------------------------------------------------------------

if (Tok[i].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i].Name^)].Kind = USERTYPE) then
if (Tok[i].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i].Name)].Kind = USERTYPE) then
begin
IdentIndex := GetIdent(Tok[i].Name^);
IdentIndex := GetIdent(Tok[i].Name);

if IdentIndex = 0 then
iError(i, UnknownIdentifier);

if Ident[IdentIndex].Kind <> USERTYPE then
Error(i, 'Type expected but ' + Tok[i].Name^ + ' found');
Error(i, 'Type expected but ' + Tok[i].Name + ' found');

DataType := Ident[IdentIndex].DataType;
NumAllocElements := Ident[IdentIndex].NumAllocElements or (Ident[IdentIndex].NumAllocElements_ shl 16);
Expand Down
Loading
Loading