[m-users.] uint32 FFI problem

emacstheviking objitsu at gmail.com
Sun Jul 7 06:05:26 AEST 2019


Getting to grips with the FFI and starting to create/port my GNU Prolog
SDL2 wrapper from long ago. The "extras/graphics" folder is amazing amount
of work but I liked SDL so I figured if I ever complete it to standard then
it might complete the set!

I can't figure out why I can't use "uint32" in the predicate declaration,
currently I use int but cast the value:

:- pred sdl_delay(int::in, io::di, io::uo) is det.
:- pragma foreign_proc("C",
  sdl_delay(MSecs::in, _IO0::di, _IO::uo),
  [promise_pure,will_not_call_mercury,does_not_affect_liveness],
"
SDL_Delay((Uint32)MSecs);
").

What I *want* to do is this:

:- pred sdl_delay(uint32::in, io::di, io::uo) is det.
:- pragma foreign_proc("C",
  sdl_delay(MSecs::in, _IO0::di, _IO::uo),
  [promise_pure,will_not_call_mercury,does_not_affect_liveness],
"
SDL_Delay(MSecs);
").

But when I do thois the compiler is angry with me:   :(

sdl2.m:067: In clause for predicate `main'/2:
sdl2.m:067:   in argument 1 of call to predicate `sdl2.sdl_delay'/3:
sdl2.m:067:   type error: argument has type `int',
sdl2.m:067:   expected type was `uint32'.
sdl2.m:067:   The partial type assignment was:
sdl2.m:067:     IsUp_4: bool.bool
sdl2.m:067:     V_5: string
sdl2.m:067:     STATE_VARIABLE_IO_0_7: io.state
sdl2.m:067:     STATE_VARIABLE_IO_8: io.state
sdl2.m:067:     V_9: string
sdl2.m:067:     V_10: list.list(string.poly_type)
sdl2.m:067:     STATE_VARIABLE_IO_11_11: io.state
sdl2.m:067:     STATE_VARIABLE_IO_12_12: io.state
sdl2.m:067:     STATE_VARIABLE_IO_19_19: io.state
sdl2.m:067:     V_20: string

i can see it's a type error but I thought that uint32 was a built in
mercury type that would translate into the C code without issue.  ?!?!

Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190706/9cb2f325/attachment.html>


More information about the users mailing list