Shop OBEX P1 Docs P2 Docs Learn Events
What I am doing wrong with a class? ( a strange compiler error) — Parallax Forums

What I am doing wrong with a class? ( a strange compiler error)

pik33pik33 Posts: 2,387
edited 2022-05-21 16:23 in BASIC (for Propeller)

I am getting a strange compilation error while trying to compile the code containing a class using another class. As the original code is too long, I extracted simple examples.

(1). This compiles:

dim psram as class using "psram4.spin2"
psram.fill(0,123,1,0,1)

(2) This doesn't compile:

dim psram as class using "psram4.spin2"

class f

dim a as integer

sub b
psram.fill(0,123,1,0,1)
end sub

end class

psram.fill(0,123,1,0,1)

error: Unable to determine class type at psram.fill in sub b

So it doesn't recognize "psram" if used in another class. So I tried to declare it inside the class

dim psram as class using "psram4.spin2"

class f
dim psram as class using "psram4.spin2"
dim a as integer

sub b
psram.fill(0,123,1,0,1)
end sub

end class

psram.fill(0,123,1,0,1)

This time the error I got is totally stupid:

Unable to open file `psram4.spin2': No such file or directory
test003.bas
|-psram4.spin2
|-|-psram4drv.spin2
child process exited abnormally

What's wrong? There already IS the psram4.spin2 in the directory.

This is not a duplicate file use problem as this example:

class f
dim psram as class using "psram4.spin2"
dim a as integer

sub b
psram.fill(0,123,1,0,1)
end sub

end class

gives the same error:

Unable to open file `psram4.spin2': No such file or directory

Tested in 5.9.10 and 5.9 11 (fresh complied)

Comments

  • pik33pik33 Posts: 2,387
    edited 2022-05-21 17:33

    Worked around:

    dim psram as class using "/home/pik33/Programowanie/P2-retromachine/Propeller/Videodriver develop/psram4.spin2"

    A full path did the trick. Why?


    If I set a starting directory to the project directory it also compiles


    Summary as it is now:

    Adding class using "filename" in a program works, opens and compiles the file in the current project directory. But if the declaration is inside a class, then it searches the file not in the project directory, but in the directory from where Flexprop was started. The re are 2 workarounds (1) use absolute path to the file (2) start Flexprop from inside the project directory.

  • If all the classes are declared as "class using" then it may work -- that is, if you put your basic class into a file "f.bas" and include it with class using "f.bas" then I'm guessing it'll work as expected, since it'll be going through the same path as Spin objects. BASIC classes declared "inline" are supposed to work, but they're kind of an exception and not tested as well as classes that are stored in files.

  • pik33pik33 Posts: 2,387
    edited 2022-05-23 11:53

    The next strange thing:

    class TWindow
    
      dim x,y as integer
      dim l,h as ulong                     
      dim vcl,vch as ulong                   
      dim vcx,vcy as ulong
      dim canvas as ulong
      dim deco as ulong
      dim i,j as integer
      dim font_ptr,font_family as ulong
      dim blitbuf(1023) as ubyte
      dim cursor_x,cursor_y as ubyte
      dim write_color,write_background as ubyte
      dim ccc(1) as ulong
      dim mailbox as ulong
      dim needclose,selected,visible,num as ubyte
    
      dim psram as class using "/home/pik33/Programowanie/P2-retromachine/Propeller/Videodriver_develop/psram4.spin2"
    
    
    
    ''---------- putpixel - put a pixel on the screen - a mother of all graphic functions ---------------------------
    
      sub putpixel(xx, yy as ulong, c as ubyte)
    
      if ((xx>=0) andalso (xx<l) andalso (yy>=0) andalso (yy<h)) then psram.fill(canvas+(l*yy+xx),c,1,0,1)      ' <<- this is line 30
      end sub
    

    /home/pik33/Programowanie/P2-retromachine/Propeller/Videodriver_develop/windows.bas:30: warning: signed/unsigned comparison may not work properly

    Where is the signed/unsigned comparison when l,h,xx,yy are ulongs ?

  • evanhevanh Posts: 16,029

    Unsigned compare of (xx>=0) will always be true. Optimiser should eliminate the compare, but 0 will be signed by default me thinks.

  • In the declaration:

    sub putpixel(xx, yy as ulong, c as ubyte)
    

    xx has no explicit type and defaults to integer. That is, the parsing of types in parameter lists does not extend across commas.

  • pik33pik33 Posts: 2,387

    Too much Pascal programming before where procedure putpixel (xx,yy:cardinal, c:byte) makes both xx and yy unsigned :)

  • achaji3achaji3 Posts: 1
    edited 2022-09-06 20:33

    i got same error. how can i solve this? myfiosgateway.com

    mobdro

  • @achaji3 said:
    i got same error. how can i solve this?

    There are several errors discussed in this thread... which one are you getting? And which version of FlexProp are you using?

Sign In or Register to comment.