r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Red] Red language group

Kaj
21-Feb-2012
[5238x4]
I'm compiling with -g but show-fpu-state is not available
I've added your FPU code to the C binding because all floating point 
code now generates an exception, but now the Mandelbrot doesn't work 
anymore:
*** Runtime Error 1: access violation
*** at: 08049FACh
At least the browser works again on my WebKit version
Pekr
22-Feb-2012
[5242]
I got that error too. I thought it is related to my weak attempts 
to wrap my led library (which still can be the case), as I saw the 
error for the first time yesterday ...
PeterWood
22-Feb-2012
[5243]
I've found the easiest way to raise that runtime error is to accidently 
treat an integer as a pointer.
Dockimbel
22-Feb-2012
[5244x3]
Kaj: `show-fpu-state` was renamed to `show-fpu-info` yesterday. I 
forgot to mention it here.
FP exceptions: will look into it.


Peter: can you send me an example code of your use case raising a 
FP exception?
Mandelbrot: it produces an error here too, but not the same one (testing 
on Win7): *** Runtime Error 11: float stack check
Kaj
22-Feb-2012
[5247x3]
Mine is on Linux
Peter, yes, but this is the same Mandelbrot that worked with the 
0.2.4 release
You probably mainly meant that as a response to Petr
PeterWood
22-Feb-2012
[5250x3]
Yes my reponse was mainly to Petr as it may be of help to him.
The runtime errors that I got were correct - in the sense that the 
compiler and run-time acted correctly.
This code will cause an access violation as clock in libc returns 
an integer not a pointer to an integer.

pi: declare pointer! [integer!] 
#import [
	LIBC-FILE cdecl [
	  read-cpu-clock: "clock" [
	    return:    [pointer! [integer!]]
	  ]
    ]
]
pi: read-cpu-clock
pi/value
Pekr
22-Feb-2012
[5253]
One question towards library wrapping and type casting. One DLL function 
is defined as:

typedef bool (WINAPI *LSN_OPENCARD)(void);//open led card 


When I defined the return type of wrapper funciton as LOGIC!, it 
was always true. When I defined it as an integer, it was either 1, 
or some really high integer number. So i took Cyphre's advice towards 
R2's interface, and in R2 I used CHAR, and in Red/System, I used 
BYTE! type.


Pity construct of a type return: "as integer! [byte!]" is not allowed, 
but at least I now get correct result - 0, or 1, in my print statement, 
where I do: print [as integer! led-open-card lf]


So my question is - why using Red/System's LOGIC! did not work? Is 
C level BOOL a clearly defined type, or can it be defined in various 
ways, so I can't say, that I can automatically use LOGIC! = BOOL 
logic, when wrapping stuff?
PeterWood
22-Feb-2012
[5254]
From the spec Red/System does not support the use of  the logic! 
datatype in #import  - http://static.red-lang.org/red-system-specs.html#section-14.1


The spec is also silent about how a the logic! field is actually 
stored. I'd guess a byte! but I'd probably be wrong.


By the way no need to cast byte! to integer!, just test for #"^(00)" 
or #"^(01)".
Kaj
22-Feb-2012
[5255x2]
I do use logic! in #import:
gtk-set-window-resizable: "gtk_window_set_resizable" [  ; Set window 
resizability.
		window				[gtk-window!]
		resizable?			[logic!]
	]
Dockimbel
22-Feb-2012
[5257]
Logic! is stored as an integer (so 32-bit). The specification document 
is not supposed to describe the implementation (that's why I try 
to put implementation-specific details in special notes). Logic! 
uses 1/0 internally to represent true/false values, so if the imported 
function is not conforming to that convention, type casting to logic! 
won't work and a manual test would then be required.
Kaj
22-Feb-2012
[5258]
But you have to be sure that the library defines it as 0 or 1. There 
is no standard for it in C, but that's what Red uses
Dockimbel
22-Feb-2012
[5259]
Right, we extended the import interface to allow logic!, the spec 
doc seems to lag behind on that feature, it needs to be updated (with 
a note about 1/0 requirement in such case).
Kaj
22-Feb-2012
[5260]
The "other standard" for true is -1, but there are no signed integers 
in red/System, so that's where you get the high value from
Pekr
22-Feb-2012
[5261]
OK, that's clear at least now ...
Kaj
22-Feb-2012
[5262]
It's very nice that Red/System has a first class logic! but external 
code doesn't know that
Pekr
22-Feb-2012
[5263]
would it be possible to cast import values directly in import clauses, 
to prevent the need to write another wrapping functions? call me 
lazy :-)
Dockimbel
22-Feb-2012
[5264]
Integer! _is_ signed in Red/System, byte! is not.
Pekr
22-Feb-2012
[5265x2]
I mean, so I could write:

return: as integer! [byte!]
or: return: as logic! as integer! [byte!], so that I would get true/false 
directly :-)
Dockimbel
22-Feb-2012
[5267]
No! But you can use a macro to avoid making a function wrapper.
Pekr
22-Feb-2012
[5268]
macro?
Dockimbel
22-Feb-2012
[5269]
#define
Kaj
22-Feb-2012
[5270]
Oh, right, the other way around. But how do you get a high integer 
from a library, then?
Pekr
22-Feb-2012
[5271x2]
aha ... I would probably use something like _func-name ... and func-name: 
[as logic! as byte! _func-name]
I will look into #define ...
Dockimbel
22-Feb-2012
[5273x2]
Pekr: yes, that's an option.
Kaj: the same way as you get a low integer. :) The signed representation 
is just a convention, the actual data remains the same, signed or 
unsigned.
Kaj
22-Feb-2012
[5275]
It seems that Petr's library puts garbage in the high bytes if it 
returns 1 or a high integer
Dockimbel
22-Feb-2012
[5276]
Pekr: it should be  [as logic! _func-name], while setting [return: 
[byte!]] in _func-name definition.
Pekr
22-Feb-2012
[5277x2]
yes, I confused it - ti came from R2, where I put char as a return 
value, and then to-integer ... I develop in in R2, Red/System, World, 
to see if eventual crashes are environment specific, or library specific
the library is clearly a junk imo ... e.g. two consecutive calls 
to the same function do crash the app, etc.
Kaj
22-Feb-2012
[5279x3]
I split the C library binding in two branches so that users of the 
Red release can keep using the main (trunk) branch:
http://red.esperconsultancy.nl/Red-C-library/timeline
The new "developing" branch is not compatible with Red/System 0.2.4 
but is needed to use WebKit
Dockimbel
22-Feb-2012
[5282]
Kaj: I've just pushed a fix for the floats exceptions and regressions. 
Mandelbrot is running fine again now. Let me know if the issues are 
fixed for you too.
Kaj
22-Feb-2012
[5283x3]
Fixed, thanks
; CLOCKS_PER_SEC value for Syllable, Linux (XSI-conformant systems)
; TODO: check for other systems
#define clocks-per-second		1000'000
Judging by your screenshot, it's different for Windows
Dockimbel
22-Feb-2012
[5286]
IIRC, it should be 60 for Windows, but I'm not certain this is valid 
for all Windows versions.
Kaj
22-Feb-2012
[5287]
Sounds like that could be 50 in the US