Shop OBEX P1 Docs P2 Docs Learn Events
@Bean: SXB 2.0 bug when using FUNC with local variables — Parallax Forums

@Bean: SXB 2.0 bug when using FUNC with local variables

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2009-04-11 15:28 in General Discussion
@Bean,

This program

' =========================================================================
'   File...... Memory_demo2.SXB
'   Compiler.. SXB 2.00.16
'   Purpose... Optimizing memory use
'   Author.... Peter Verkaik
'   E-mail.... [url=mailto:verkaik6@zonnet.nl]verkaik6@zonnet.nl[/url]
'   Started... 10 april, 2009
'   Updated...
' =========================================================================
'******************************************************************************
'device settings
'******************************************************************************
device  SX28,OSCHS2
freq  20_000_000
id              "Memory"
stack  16
'******************************************************************************
'CON section
'******************************************************************************
'******************************************************************************
'I/O pins
'******************************************************************************
'******************************************************************************
'VAR section
'******************************************************************************
bytevar  var byte
wordvar  var word
longvar  var byte (4)
'******************************************************************************
INTERRUPTRATE con 230400
INTERRUPT nocode INTERRUPTRATE
  returnint
'******************************************************************************
'SUB/FUNC/TASK declarations
'******************************************************************************
byteFunc FUNC 1,1
wordFunc FUNC 2,1
longFunc FUNC 4,1
'******************************************************************************
'Reset entry
'******************************************************************************
PROGRAM Start
'******************************************************************************
'Program Code
'******************************************************************************
Start:
Main:
  GOTO Main
'******************************************************************************
'Sub/Func/Task code
'******************************************************************************
FUNC byteFunc 'returns byte
  lbyte var byte
  lword var word
  lbyte = __param1
  lword = wordFunc lbyte ,lbyte
  return lword_msb
ENDFUNC
FUNC wordFunc 'returns word
  lbyte var byte
  lword var word
  lbyte = __param1
  lword = wordFunc lbyte,lbyte
  return lword
  return
ENDFUNC
FUNC longFunc 'returns long
  lbyte var byte
  lword var word
  lbyte = __param1
  lword = wordFunc lbyte,lbyte
  lword * lbyte 'result in __param1,__param2,__param3,__param4
  return
ENDFUNC
'end of file Memory_demo2.SXB


generates errors "Symbol <__PARAM0> not defined"
(__param0 is not used by SXB)
But note that the lines
lword = wordFunc lbyte,lbyte
do not generate an error but they should as the function expects only 1 byte argument!
Change the line to
lword = wordFunc lbyte
and you get the error "Invalid number of parameters"

I used compiler version r19.
The program is also attached.

Edit: compiler version r14 compiles without error when using lines
lword = wordFunc lbyte
(but then of course the FUNC 1,5,5,byte,byte,word,word no longer works
as that was fixed in a later release).

All later releases generate the errors.

regards peter

Post Edited (Peter Verkaik) : 4/10/2009 3:51:01 PM GMT

Comments

  • RS_JimRS_Jim Posts: 1,773
    edited 2009-04-10 21:49
    Peter,
    That is the exact same error as I was getting with my earlier post. __param0 was being generated by compiler when I was attempting to use local variables.
    RS_Jim
  • BeanBean Posts: 8,129
    edited 2009-04-11 13:50
    I'll look into this problem. And let you know...

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • BeanBean Posts: 8,129
    edited 2009-04-11 14:46
    Okay, I have posted version 2.00.20. This fixes the __PARAM0 error, and the parameter count is not correctly detected too.

    Peter, there is a couple problem with the posted program.

    1) The wordFunc is defined as having 1 parameter, but you are giving it two (this was not picked up because of the bug).

    2) The wordFunc is unconditionally recursive. (Infinate loop)

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-04-11 15:28
    Hi Bean,

    The fix appears to work.

    To reply at your replies:
    1) I added the 2nd argument to show the __param0 bug AND the bug that
    2 arguments was not detected.

    2) I was busy creatiig FUNC's (using copy and paste) when I encountered
    the error. The program as such does not do anything useful.

    regards peter
Sign In or Register to comment.