Error compiling CRC code

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Error compiling CRC code

Post by Don_Kirby »

The code shown below returns the error message
Compiler wrote: CRCError.bas:9: Internal Error: no means to generate code for expression

Code: Select all

Sub Main()
	Dim CRC as UnsignedInteger
	Dim DataCount as Integer
	Dim BufferQ(1 to 100) as Byte
	Dim ReceivedCRC as UnsignedInteger
	DataCount = 10
	CRC = CRC16(BufferQ(1), DataCount, &H8005, &Hffff, zxCRCRefIn Or zxCRCRefOut) 
	'ReceivedCRC = MakeWord(BufferQ(DataCount+1), BufferQ(DataCount + 2))
	If CRC <> ReceivedCRC Then
		'Do some work		
	End If
End Sub
Code details aside, the 'Internal Error' is indicative of a compiler issue.

The three functional bits...

Code: Select all

	CRC = CRC16&#40;BufferQ&#40;1&#41;, DataCount, &H8005, &Hffff, zxCRCRefIn Or zxCRCRefOut&#41; 

Code: Select all

	ReceivedCRC = MakeWord&#40;BufferQ&#40;DataCount+1&#41;, BufferQ&#40;DataCount + 2&#41;&#41;

Code: Select all

	If CRC <> ReceivedCRC Then
		'Do some work		
	End If
...all compile correctly if the other two are commented out.

-Don
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Error compiling CRC code

Post by dkinzer »

Don_Kirby wrote:The code shown below returns the error message
Thanks for reporting this. We should still have time to figure out the solution and get it in before the final test run for the upcoming release.

Oddly, the error only occurs when compiling for native mode devices. Moreover, it's not related to the functions that you're using; the following simpler test case produces the same result.

Code: Select all

Dim b1 as Byte
Dim b2 as Byte
Sub Main&#40;&#41;
  b1 = Register.PortA
  b2 = Register.PortC
  If &#40;b1 <> b2&#41; Then
  End If
End Sub
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

The source of the problem has been located and a likely solution identified. You can work around the problem by putting a useful statement inside the If as shown in the test case below or by turning off optimization (use the compiler option optimize=no-optimize). Doing the latter shouldn't have a significant effect, if any, on the code size in native mode since the backend compiler will still be optimizing.

Code: Select all

Sub Main&#40;&#41;
  Dim b1 as Byte
  Dim b2 as Byte
  b1 = Register.PortA
  b2 = Register.PortC
  If &#40;b1 <> b2&#41; Then
    Debug.Print
  End If
End Sub
- Don Kinzer
Post Reply