syntax for 'prototype' declaration

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

syntax for 'prototype' declaration

Post by Jerry Messina » Mon Feb 09, 2009 10:25 am

I just tried to use the 'prototype' keyword (as outlined in http://www.sfcompiler.co.uk/forum/posti ... ote&p=5000),
but I keep getting an "END expected" error at the line containing

Code: Select all

sub myNeededFunc() prototype
What am I doing wrong?

Jerry

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Mon Feb 09, 2009 1:26 pm

Hello
As I said in previous posts, since David didnt documented that clearly it maybe changed. Use it at your own risk. I only saw this keyword in the New Feature document (Compiler History from version dated on 14th August 2007 - 2.0.1.0 at http://www.sfcompiler.co.uk/wiki/pmwiki ... ionHistory ).

The "prototype" keyword is like the "compound" keyword, it introduce a special kind of declaration for a proc (proto means that the sub/func body/implementation will come later).

Code: Select all

prototype sub myNeededFunc() 
Regards
octal

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Feb 13, 2009 12:02 pm

Thanks, octal. That syntax worked out much better.

However, your warning about "USE AT YOUR OWN RISK" is right.
If you declare a function with the 'prototype' keyword, the code generator screws up,
causing any 'inline' routines accessed by that function to be expanded incorrectly.

Taking a look at the output ASM for the following, you can see that the
'GetTicks()' function isn't always correct...

Code: Select all

'prototype declaration causes incorrect code generation with inline
prototype function funct_with_prototype() as word

'uncommenting the following causes this function to screw up too
'prototype function funct_without_prototype() as word

dim w as word
dim ticks as word

sub IncrTicks()
    inc(ticks)
end sub

' disable intr while accessing ticks
inline function GetTicks() as word
    INTCON.bits(7) = 0
    result = ticks
    INTCON.bits(7) = 1
end function

function funct_with_prototype() as word
    result = GetTicks()
end function

function funct_without_prototype() as word
    result = GetTicks()
end function

main:
    ticks = 0
    ' this generates correct code
    w = GetTicks()
    
    IncrTicks()
    ' so does this
    w = funct_without_prototype()

    IncrTicks()
    ' this does NOT
    w = funct_with_prototype()
    
end    
btw, being a new user, is this the best place to report bugs like this?

Thanks,
Jerry

Post Reply