Skip to content

Commit 120e029

Browse files
authored
Merge pull request #167 from peterdell/way2js4
Way2js3 - Part 1 - 3nd Attempt
2 parents 48b94d0 + b71c9c7 commit 120e029

File tree

8 files changed

+212
-218
lines changed

8 files changed

+212
-218
lines changed

src/Common.pas

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ TType = record
409409
TToken = record
410410
UnitIndex, Column: Smallint;
411411
Line: Integer;
412-
case Kind: Byte of
413-
IDENTTOK:
414-
(Name: ^TString);
415-
INTNUMBERTOK:
416-
(Value: Int64);
417-
FRACNUMBERTOK:
418-
(FracValue: Single);
419-
STRINGLITERALTOK:
420-
(StrAddress: Word;
421-
StrLength: Word);
412+
Kind: Byte;
413+
// For IDENTTOK:
414+
Name: TString;
415+
// For INTNUMBERTOK:
416+
Value: Int64;
417+
// For FRACNUMBERTOK:
418+
FracValue: Single;
419+
// For STRINGLITERALTOK:
420+
StrAddress: Word;
421+
StrLength: Word;
422422
end;
423423

424424
TIdentifier = record
@@ -448,9 +448,9 @@ TIdentifier = record
448448
isInitialized,
449449
Section: Boolean;
450450

451-
case Kind: Byte of
452-
PROCEDURETOK, FUNCTIONTOK:
453-
(NumParams: Word;
451+
Kind: Byte;
452+
// For PROCEDURETOK, FUNCTIONTOK:
453+
NumParams: Word;
454454
Param: TParamList;
455455
ProcAsBlock: Integer;
456456
ObjectIndex: Integer;
@@ -469,11 +469,11 @@ TIdentifier = record
469469
isKeep,
470470
isVolatile,
471471
isStriped,
472-
IsNotDead: Boolean;);
472+
IsNotDead: Boolean;
473473

474-
VARIABLE, USERTYPE:
475-
(NumAllocElements, NumAllocElements_: Cardinal;
476-
AllocElementType: Byte);
474+
// For VARIABLE, USERTYPE:
475+
NumAllocElements, NumAllocElements_: Cardinal;
476+
AllocElementType: Byte;
477477
end;
478478

479479

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

906906

907907
procedure FreeTokens;
908-
var i: Integer;
909908
begin
910909

911-
for i := 1 to NumTok do
912-
if (Tok[i].Kind = IDENTTOK) and (Tok[i].Name <> nil) then Dispose(Tok[i].Name);
913-
914910
SetLength(Tok, 0);
915911
SetLength(IFTmpPosStack, 0);
916912
SetLength(UnitPath, 0);
@@ -963,7 +959,7 @@ function ErrTokenFound(ErrTokenIndex: Integer): string;
963959
procedure CheckOperator(ErrTokenIndex: Integer; op: Byte; DataType: Byte; RightType: Byte = 0);
964960
begin
965961

966-
//writeln(tok[ErrTokenIndex].Name^,',', op,',',DataType);
962+
//writeln(tok[ErrTokenIndex].Name,',', op,',',DataType);
967963

968964
if {(not (DataType in (OrdinalTypes + [REALTOK, POINTERTOK]))) or}
969965
((DataType in RealTypes) and

src/Diagnostic.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ procedure Diagnostics;
3939
else if Tok[i].Kind = FRACNUMBERTOK then
4040
WriteLn(DiagFile, ' = ', Tok[i].FracValue: 8: 4)
4141
else if Tok[i].Kind = IDENTTOK then
42-
WriteLn(DiagFile, ' = ', Tok[i].Name^)
42+
WriteLn(DiagFile, ' = ', Tok[i].Name)
4343
else if Tok[i].Kind = CHARLITERALTOK then
4444
WriteLn(DiagFile, ' = ', Chr(Tok[i].Value))
4545
else if Tok[i].Kind = STRINGLITERALTOK then

src/Messages.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function ErrorMessage(ErrTokenIndex: Integer; err: ErrorCode; IdentIndex: Intege
7979
UnknownIdentifier: if IdentIndex > 0 then
8080
Result := 'Identifier not found ''' + Ident[IdentIndex].Alias + ''''
8181
else
82-
Result := 'Identifier not found ''' + Tok[ErrTokenIndex].Name^ + '''';
82+
Result := 'Identifier not found ''' + Tok[ErrTokenIndex].Name + '''';
8383

8484
IncompatibleTypeOf: Result := 'Incompatible type of ' + Ident[IdentIndex].Name;
8585
IncompatibleEnum: if DstType < 0 then

src/Parser.pas

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ function GetSizeof(i: integer; ValType: byte): Int64;
483483
var IdentIndex: integer;
484484
begin
485485

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

488488
case ValType of
489489

@@ -618,7 +618,7 @@ function CompileConstFactor(i: Integer; out ConstVal: Int64; out ConstValType: B
618618
end;
619619

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

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

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

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

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

956956
IDENTTOK:
957957
begin
958-
IdentIndex := GetIdent(Tok[i].Name^);
958+
IdentIndex := GetIdent(Tok[i].Name);
959959

960960
if IdentIndex > 0 then
961961

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

973973

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

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

982982
CheckTok(j + 1, CPARTOK);
983983

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

10631063
if IdentIndex > 0 then begin
10641064

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

12701270

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

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

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

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

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

18491849
Inc(NumVarOfSameType);
1850-
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name^;
1850+
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name;
18511851
end;
18521852

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

19581958
if Tok[i].Kind in [PROCEDURETOK, CONSTRUCTORTOK, DESTRUCTORTOK] then
19591959
begin
1960-
DefineIdent(i + 1, Tok[i + 1].Name^, Tok[i].Kind, 0, 0, 0, 0);
1960+
DefineIdent(i + 1, Tok[i + 1].Name, Tok[i].Kind, 0, 0, 0, 0);
19611961
IsNestedFunction := FALSE;
19621962
end
19631963
else
19641964
begin
1965-
DefineIdent(i + 1, Tok[i + 1].Name^, FUNCTIONTOK, 0, 0, 0, 0);
1965+
DefineIdent(i + 1, Tok[i + 1].Name, FUNCTIONTOK, 0, 0, 0, 0);
19661966
IsNestedFunction := TRUE;
19671967
end;
19681968

@@ -1998,11 +1998,11 @@ function DefineFunction(i, ForwardIdentIndex: integer; out isForward, isInt, isI
19981998
begin
19991999

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

20042004
Inc(NumVarOfSameType);
2005-
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name^;
2005+
VarOfSameType[NumVarOfSameType].Name := Tok[i + 1].Name;
20062006
end;
20072007

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

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

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

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

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

23692369
if IdentIndex = 0 then begin
23702370

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

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

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

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

24542454
Inc(NumFieldsInList);
2455-
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
2455+
FieldInListName[NumFieldsInList].Name := Tok[i].Name;
24562456

24572457
inc(i);
24582458

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

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

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

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

26122612
CheckTok(i, SEMICOLONTOK);
26132613

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

26322632
Inc(NumFieldsInList);
2633-
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
2633+
FieldInListName[NumFieldsInList].Name := Tok[i].Name;
26342634

26352635
inc(i);
26362636

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

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

27022702
CheckTok(i, SEMICOLONTOK);
27032703

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

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

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

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

27532753
Inc(NumFieldsInList);
2754-
FieldInListName[NumFieldsInList].Name := Tok[i].Name^;
2754+
FieldInListName[NumFieldsInList].Name := Tok[i].Name;
27552755

27562756
inc(i);
27572757

@@ -3042,15 +3042,15 @@ function CompileType(i: Integer; out DataType: Byte; out NumAllocElements: cardi
30423042
// USERTYPE
30433043
// -----------------------------------------------------------------------------
30443044

3045-
if (Tok[i].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i].Name^)].Kind = USERTYPE) then
3045+
if (Tok[i].Kind = IDENTTOK) and (Ident[GetIdent(Tok[i].Name)].Kind = USERTYPE) then
30463046
begin
3047-
IdentIndex := GetIdent(Tok[i].Name^);
3047+
IdentIndex := GetIdent(Tok[i].Name);
30483048

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

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

30553055
DataType := Ident[IdentIndex].DataType;
30563056
NumAllocElements := Ident[IdentIndex].NumAllocElements or (Ident[IdentIndex].NumAllocElements_ shl 16);

src/Scanner.pas

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,12 @@ procedure TokenizeProgram(UsesOn: Boolean = true);
441441

442442
CheckTok(i, IDENTTOK);
443443

444-
nam := FindFile(Tok[i].Name^ + '.pas', 'unit');
444+
nam := FindFile(Tok[i].Name + '.pas', 'unit');
445445

446446
end;
447447

448448

449-
s:=AnsiUpperCase(Tok[i].Name^);
449+
s:=AnsiUpperCase(Tok[i].Name);
450450

451451

452452
for j := 2 to NumUnits do // kasujemy wczesniejsze odwolania
@@ -1498,8 +1498,7 @@ procedure TokenizeProgram(UsesOn: Boolean = true);
14981498
end
14991499
else begin // Identifier found
15001500
Tok[NumTok].Kind := IDENTTOK;
1501-
New(Tok[NumTok].Name);
1502-
Tok[NumTok].Name^ := Text;
1501+
Tok[NumTok].Name := Text;
15031502
end;
15041503

15051504
end;
@@ -2199,8 +2198,7 @@ procedure TokenizeMacro(a: string; Line, Spaces: integer);
21992198
end
22002199
else begin // Identifier found
22012200
Tok[NumTok].Kind := IDENTTOK;
2202-
New(Tok[NumTok].Name);
2203-
Tok[NumTok].Name^ := Text;
2201+
Tok[NumTok].Name := Text;
22042202
end;
22052203

22062204
end;

src/include/compile_string.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190

191191
if Tok[i+3].Kind = DEREFERENCETOK then begin
192192

193-
asm65(#9'mwy ' + GetLocalName(GetIdent(Tok[i + 2].Name^)) + ' :bp2');
193+
asm65(#9'mwy ' + GetLocalName(GetIdent(Tok[i + 2].Name)) + ' :bp2');
194194
asm65(#9'ldy #$00');
195195
asm65(#9'lda (:bp2),y');
196196
asm65(#9'sta @move.src');

src/include/for_in_ident.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if Tok[j].Kind <> IDENTTOK then
77
iError(j, IdentifierExpected);
88

9-
IdentTemp := GetIdent(Tok[j].Name^);
9+
IdentTemp := GetIdent(Tok[j].Name);
1010

1111
ActualParamType := Ident[IdentTemp].DataType;
1212
VarType := Ident[IdentTemp].AllocElementType;

0 commit comments

Comments
 (0)