Dropped to assembler output on invalid extern

BlitzMax Forums/BlitzMax Bug Reports/Dropped to assembler output on invalid extern

When attempting to build the excellent MicroC library (thread, download) on Mac OS 10.5, I am dumped at a MaxIDE editor window with the file microc.bmx.debug.macosx.x86.s opened to the first line with this error message:

Compile Error
Rest of line ignored. 1st junk character valued 64 (@).


The first few lines look like this:

	.reference	_QueryPerformanceCounter@4
	.reference	_QueryPerformanceFrequency@4
	.reference	___bb_basic_basic
	.reference	___bb_blitz_blitz
	.reference	___bb_retro_retro
	.reference	___bb_system_system


It would appear that the first two are using a syntax not supported by the Mac OS assembler.

The only place (in this file) where QueryPerformanceCounter@4 or _QueryPerformanceFrequency@4 are referenced is:

_binphx_microc_HPMillisecs:
	push	%ebp
	mov	%esp,%ebp
	sub	$24,%esp
	movl	%ebp,4(%esp)
	movl	$_17395,(%esp)
	calll	*_bbOnDebugEnterScope
	movl	$_17385,(%esp)
	calll	*_bbOnDebugEnterStm
	movl	$_17387,(%esp)
	calll	*_bbOnDebugEnterStm
	movl	$_17389,(%esp)
	calll	*_bbOnDebugEnterStm
	movl	$0,12(%esp)
	movl	$0,8(%esp)
	movl	_17386+4,%eax
	movl	%eax,4(%esp)
	movl	_17386,%eax
	movl	%eax,(%esp)
	call	_bbLongSeq
	cmp	$0,%eax
	je	_17390
	movl	%ebp,4(%esp)
	movl	$_17393,(%esp)
	calll	*_bbOnDebugEnterScope
	movl	$_17391,(%esp)
	calll	*_bbOnDebugEnterStm
	lea	_17386,%eax
	movl	%eax,(%esp)
	call	_QueryPerformanceFrequency@4
	movl	$_17392,(%esp)
	calll	*_bbOnDebugEnterStm
	lea	_17388,%eax
	movl	%eax,(%esp)
	call	_QueryPerformanceCounter@4
	calll	*_bbOnDebugLeaveScope


This function is declared in the file Shared.bmx.

Rem
	        _                  ___ 
	  /\/\ (_) ___ _ __ ___   / __\
	 /    \| |/ __| '__/ _ \ / /   
	/ /\/\ \ | (__| | | (_) / /___ 
	\/    \/_|\___|_|  \___/\____/ 

	MicroC
	Copyright (C) 2008 Binary Phoenix - All Rights Reserved

	This software is designed to provide a simple, efficient and easy
	to integrate scripting language in a limited syntantic form similar
	to the C language.
	
	If you have any suggestions for new features To be added To this 
	module please contact me at BinaryPhoenix.com, Or helios4ever@gmail.com.
	
	Notes:
	
		- This source file just contains a number of general purpose functions
		  that are used by all source files.
		
	Change Log:
	
		Version 1.0
	
			- File Created.

End Rem

Rem
	
	Couple of external functions used in this source file.

End Rem
Extern "win32"
	Function QueryPerformanceCounter(count:Long Var)
	Function QueryPerformanceFrequency(freq:Long Var)
End Extern

Rem

	Returns the index of the object within the given list.

End Rem
Function ListIndexOf:Int(list:TList, obj:Object)
	Local index:Int = 0
	For Local check:Object = EachIn list
		If (check = obj) Then Return index
		index :+ 1
	Next
	Return -1
End Function

Rem

	Returns the index of the object within the given array.

End Rem
Function ArrayIndexOf:Int(list:Object[], obj:Object)
	Local index:Int = 0
	For Local check:Object = EachIn list
		If (check = obj) Then Return index
		index :+ 1
	Next
	Return -1
End Function

Rem

	No, it has nothing to do with HP sauce ;). It mearly wraps the high preformance
	timer of the OS so we can get more accurate timing.

	Returns the current milliseconds since the computer started up, within the accuracy
	of the given OS's internal clock.

End Rem
Function HPMillisecs:Float()
	
	Global frequency:Long = 0
	Global start:Long = 0
	If (frequency = 0)
		QueryPerformanceFrequency(frequency)
		QueryPerformanceCounter(start) 
	EndIf
	
	?win32

		Local time:Long
		QueryPerformanceCounter(time) 
		Return (Double(time - start) / Double(frequency)) * 1000.0
	
	?

	Return MilliSecs()

End Function


This appears to use a windows-only extern. I can patch this, however the error behavior in this case is very, very confusing. The compiler should stop in the BMX file and indicate that an unsupported Extern is being used.

Use ?win around the Extern

Yeh Azathoth is correct. Put a ?win32 block around the extern block and add a ?win32 block around the first if statement in HPMillisecs. Very stupid mistake I made >_>

Yes, well I did put that patch in, as I said it was easy to fix. However this is not good behavior, the compiler should report an intelligent error instead of dumping to assembler output on obscure line of assembler syntax.

But how would the compiler know what is the problem is to generate an intelligent report ?

But how would the compiler know what is the problem is to generate an intelligent report ?

In this case I think it's pretty easy - MacOS doesn't support "Win32", so it would know it should be in ?Win32 ... ? and could easily throw an error on Mac OS and Linux. The code throwing the error was below the fold so I'll repeat it:

Extern "win32"
	Function QueryPerformanceCounter(count:Long Var)
	Function QueryPerformanceFrequency(freq:Long Var)
End Extern


If the compiler can't tell that won't work on Mac OS and Linux, well. Uh. Hmm. It should be able to. ;)

You wouldn't want to to report an error - you would just want it to be ignored. If you ask Mark nicely, he might add it in before the main release :)


You wouldn't want to to report an error - you would just want it to be ignored. If you ask Mark nicely,


Well, no I really would like to get a notice that I have Windows only code that's about to be dropped, instead of later having a strange "undeclared function" error. It's quite conceivable that I forgot, or never knew, that the given function was Windows-only (for instance if it were declared in a third-party library file that I only skimmed). I'm not sure how to ask Mark for things other than posting here, so uh, Mark plz add this? It would be helpful for us cross-platform people.


he might add it in before the main release :)


Oh, is there a new release coming soon? That'd be awesome! I probably haven't been paying proper attention to the work logs, etc....

It was suppposed to be out last week-ish.