I need a code review. I have changed a fundamental part of the compiler to resolve an issue.
This has take two long days to resolve. :-(
If I get this incorrect the compiler with fall over with bad asm.
If you can do code review - ping me.
Evan
The issue reported: The ASM code generated was different when a comment is the last line of code before an END SUB, and the code is the same when comments are removed from the program.
The only difference is the comment at the end of _FN1 before the End Sub.
Code example 1 generated a call _fn1 & return and Code example 1 generated a goto _fn1 with no return (which is the intent).
With assmebly.bi line 235
Was
'Check for subs that have a call as the last instruction 'Turncallintoagoto'If call is last instruction and always runs, no need for a return at the end either 'GetlastlineofsubCompSub->HasFinalGoto=0CompSub->FinalGotoDest=""CurrLine=CompSub->CodeStartDoWhileCurrLine->Next<>0CurrLine=CurrLine->NextLoopLastLine=CurrLine'Get line before last CheckLine = LastLine->Prev If CheckLine <> 0 Then Do While (Left(CheckLine->Value, 1) = ";" Or Left(CheckLine->Value, 8) = "PRESERVE") AND CheckLine->Prev <> 0 CheckLine = CheckLine->Prev Loop End If
now
'Check for subs that have a call as the last instruction 'Turncallintoagoto'If call is last instruction and always runs, no need for a return at the end either 'GetlastlineofsubCompSub->HasFinalGoto=0CompSub->FinalGotoDest=""'Restart the code list CurrLine = CompSub->CodeStart 'DowhilehasdataincodelistDoWhileCurrLine->Next<>0'While has code in code list, set to next code line CurrLine = CurrLine->Next Loop 'Handlelastline...itcouldbeacommentthereforePRESERVEd'Do while the current code line is PRESERVEd Do while Left(CurrLine->Value, 8) = "PRESERVE" 'ifPREViouscodeisNOTaPRESERVEdlinethengetthePREViouslineasthecurrentlineIfLeft(CurrLine->Prev->Value,8)<>"PRESERVE"thenCurrLine=CurrLine->PrevEnd ifLoopLastLine=CurrLine'Get line before last CheckLine = LastLine->Prev If CheckLine <> 0 Then Do While (Left(CheckLine->Value, 1) = ";" Or Left(CheckLine->Value, 8) = "PRESERVE") AND CheckLine->Prev <> 0 CheckLine = CheckLine->Prev Loop End If
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My initial attempt did break the compiler. It caused an indefinite loop, so, the compiler never completed.
New attempt with update code. With an additional test to check that the list is not pass the top extent of list.
'Handle last line... it could be a comment therefore PRESERVEd 'DowhilethecurrentcodelineisPRESERVEdDowhileLeft(CurrLine->Value,8)="PRESERVE"'if PREVious code is NOT a PRESERVEd line then get the PREVious line as the current line, and, check that we are not at the top of the list If Left(CurrLine->Prev->Value, 8) <> "PRESERVE" and CurrLine->Prev <> 0 then CurrLine = CurrLine->Prev Else Exit Do End if print CurrLine->Value Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I need a code review. I have changed a fundamental part of the compiler to resolve an issue.
This has take two long days to resolve. :-(
If I get this incorrect the compiler with fall over with bad asm.
If you can do code review - ping me.
Evan
The issue reported: The ASM code generated was different when a comment is the last line of code before an END SUB, and the code is the same when comments are removed from the program.
Code Example 1
Code Example 2
The only difference is the comment at the end of
_FN1
before theEnd Sub
.Code example 1 generated a
call _fn1
&return
and Code example 1 generated agoto _fn1
with no return (which is the intent).With assmebly.bi line 235
Was
now
My initial attempt did break the compiler. It caused an indefinite loop, so, the compiler never completed.
New attempt with update code. With an additional test to check that the list is not pass the top extent of list.