1. Phix : variable types
- Posted by ChrisB (moderator) Dec 08, 2016
- 1420 views
Hi Pete
How does one deal with this in Phix, or do I just write a shim to test for atom / sequences
global function w32remainder(object a,object b) if sequence(a) then for i=1 to length(a) do a[i]=remainder(a[i],b) end for return a elsif sequence(b) then for i=1 to length(a) do b[i]=remainder(a,b[i]) end for return b end if if compare(a,0.0)=compare(b,0.0) then return remainder(a,b) else return b+remainder(a,b) end if end function
D:\Phix\demo\win32lib7\w32utils.e:351 for i=1 to length(a) do ^ incompatible type for routine signature ...included by D:\Phix\demo\win32lib7\w32support.e, line 4 ...included by D:\Phix\demo\win32lib7\win32lib.ew, line 575 ...included by D:\Phix\demo\Win32Demo\win32lib.ew, line 9 ...included by D:\Phix\demo\Win32Demo\MonthCalendar.exw, line 4
Cheers
Chris
2. Re: Phix : variable types
- Posted by petelomax Dec 08, 2016
- 1414 views
Like this:
global function w32remainder(object a,object b) if sequence(a) then for i=1 to length(a) do a[i]=remainder(a[i],b) end for return a elsif sequence(b) then -- for i=1 to length(a) do for i=1 to length(b) do b[i]=remainder(a,b[i]) end for return b end if if compare(a,0.0)=compare(b,0.0) then return remainder(a,b) else return b+remainder(a,b) end if end function
Phix has, quite correctly, found a bug which has lain undetected in w32remainder for donkey's years - I first found that particular case in July 2009.
Were you to invoke w32remainder(1,{2,3}) on OpenEuphoria it would either:
a) crash on any older version where length(atom) crashed, or
b) only ever process b[1], and that way go quietly wrong.
Also, invoking w32remainder(1,{}) would crash every time, if that actually counts as a bug.
In Phix, length(atom) is [still] an error, for reasons just like this.
Pete
PS: If you are using a version of win32lib other than the one (0.60) shipped with Phix, it will be worth checking any errors against demo\win32lib6 to see if it has already been found and fixed, although that does not apply to the one above.
PPS: I have also long suspected that both the a[i]/b[i]= statements should really be recursive calls to w32remainder... maybe.
3. Re: Phix : variable types
- Posted by petelomax Dec 08, 2016
- 1367 views
Here is a long list of win32lib tweaks you might need (some others may be missing).
You should of course convince yourself these are individually correct before/when applying.
All of these are intended to make things compatible with both Phix and OpenEuphoria.
w32support or w32memory:
function l_SafePeek(object addr) --PL 29/4/09: -- if object(addr) then return {} -- else -- return 0 -- end if
ditto for l_SafePeek4s and l_SafePeek4u
w32support or w32utils:
global function w32rand32(atom N) --/**/ d = sq_mul(vOldSeed,d) --/* Phix d = vOldSeed * d -- RDS */
series.e:
global function next_number(object pName) -- sequence lRC -- PL 29/4/09
global function current_number(object pName) -- atom lNextNum -- PL 29/4/09
compat02.ew:
global function fetch_SYSTEMTIME( atom st ) -- PL 29/4/09: --return w32from_memory(ID_SYSTEMTIME, st ) return w32from_memory(st,ID_SYSTEMTIME) end function global function fetch_CHARFORMAT( atom CHARFORMAT ) --PL 29/4/09: --return w32from_memory(ID_CHARFORMAT, CHARFORMAT) return w32from_memory(CHARFORMAT,ID_CHARFORMAT) end function --PL 29/4/09??? --/**/ TVDISPINFO_TVITEMcchTextMax = {TVDISPINFO_item,sq_add(TVITEM_pszText,4)}, --/* Phix TVDISPINFO_TVITEMcchTextMax = {TVDISPINFO_item,TVITEM_pszText+4}, -- RDS */ integer xxxx global procedure w32release_all_mem() -- No longer needed. xxxx=1 -- suppress warnings -- PL 29/4/09 end procedure
rttext.e:
-- PL 29/4/09 --global function setContainer(sequence pNew) global function setContainer(object pNew)
w32file.e:
--constant WM_USER = #400 -- PL 29/4/09 global function getFullPathName(sequence pFile, integer pOption) -- sequence lShortFile -- PL 29/4/09 -- PL 29/4/09 --global function setSearchPaths(sequence pPaths) global function setSearchPaths(object pPaths)
w32memory:
-- PL 29/4/09 --xIsBadCodePtr = define_c_func(kernel32, "IsBadReadPtr", {C_LONG, C_LONG}, C_LONG), procedure l_MyFreeMem(atom pAddress) -- integer lMemSize -- PL 29/4/09 global function w32allot( object pDataType ) -- atom a -- PL 29/4/09 -- PL 29/4/09 (we just set this to 1!!) -- fieldv=sequence(lCnt) -- fieldv=0 (and fieldv is guaranteed to be 0 here anyway) function fetchSize(atom struct,atom at,sequence s,integer flag) -- PL 29/4/09 -- integer strlen,wsize,strtype integer strlen,wsize -- object x -- PL 29/4/09 function w32ElemAddr(atom struct,sequence s) -- atom at -- PL 29/4/09 -- object x -- PL 29/4/09 global procedure w32copy_field(atom struct,sequence s,atom origin) -- PL 29/4/09 -- integer size,sel,var,units integer sel,var,units global procedure w32poke_words(atom at,object words) --/**/ words = sq_floor(sq_rmdr(words,65536)) --/* -- Phix words = floor(remainder(words,65536)) --*/ -- RDS function internal_fetch( atom struct, sequence s ) -- sequence s0, result -- PL 29/4/09 function virtualise_blank(object strtype) --/**/ sm2 = sq_sub(s0,2) --/* -- Phix sm2 = s0-2 --*/ -- RDS function fetchSize(atom struct,atom at,sequence s,integer flag) -- PL 29/4/09 -- integer strlen,wsize,strtype integer strlen,wsize -- object x -- PL 29/4/09 --/**/ s[arrayPos..length(s)]=sq_sub(s[arrayPos..length(s)],1) --/* -- Phix s[arrayPos..length(s)]-=1 --*/ -- RDS
procedure l_SafePoke(atom addr, object thedata) -- PL 29/4/09 -- atom a, l
ditto for l_SafePoke4
w32msgs:
procedure fCleanUp(integer pErrCode, sequence pDispMsg) -- PL 29/4/09 --integer lRC, lNumUserIds, lCurControl integer lRC, lNumUserIds
w32utils
global function w32remainder(object a,object b) elsif sequence(b) then --PL 27/07/09: (DEV: untested) -- for i=1 to length(a) do for i=1 to length(b) do global function w32round(object a,object b,integer flag) elsif sequence(b) then --PL 27/07/09: (DEV: untested) -- for i=1 to length(a) do for i=1 to length(b) do
w32resources:
global function textToBitmap(sequence s) -- all spaces become 1 and all non-spaces become 0. --/**/ s = sq_eq(s,' ') --/* Phix s = ( s = ' ' ) -- RDS */ global function createMousePointer(integer x, integer y, sequence image) -- create the and mask --/**/ maskBits = sq_eq(image,' ') --/* Phix maskBits = ( image = ' ' ) -- RDS */ -- create the xor mask --/**/ maskBits = sq_eq(image,'.') --/* Phix maskBits = (image = '.') -- RDS */
4. Re: Phix : variable types
- Posted by ChrisB (moderator) Dec 09, 2016
- 1385 views
Hi Pete
Great thanks, I shall work my way through those.
Cheers
Chris
5. Re: Phix : variable types
- Posted by katsmeow Dec 09, 2016
- 1329 views
Hi Pete
Great thanks, I shall work my way through those.
Cheers
Chris
I can't figure why those aren't in Phix already, if Phix required them, or is improved by them. And the block comments thing not working as expected too. I just looked at the new site, really clean and proper looking, but i still cannot find the list of keywords of the language.
6. Re: Phix : variable types
- Posted by petelomax Dec 09, 2016
- 1354 views
I can't figure why those aren't in Phix already
That is win32lib. I currently include a Phix-compatible version of 0.60 only; if asked I will create a Phix-compatible version of a (more recent) version of win32lib, but I am not about to ship tweaked versions of every known version of win32lib that exists. And as I do not use win32lib, I have no inkling of which versions are most needed. When someone uses a non-Phix-compatible version of win32lib, the compiler will in fact spit out an appropriate warning, however (it is quite understandable) that is almost always overlooked when faced with an error such as the one above.
And the block comments thing not working as expected too.
They are working pretty much exactly as as I expect them to, but I stopped testing that things run on eui some time ago, partly at your suggestion.
i still cannot find the list of keywords of the language.
How about Core Language/Declarations
Regards, Pete
7. Re: Phix : variable types
- Posted by ChrisB (moderator) Dec 10, 2016
- 1310 views
Hi
I am working my way through 0.70.4 at the moment. Sorry Pete, likely to have several more questions. My goal is to get a working version of the IDE with Phix.
Cheers
8. Re: Phix : variable types
- Posted by katsmeow Dec 10, 2016
- 1341 views
They are working pretty much exactly as as I expect them to, but I stopped testing that things run on eui some time ago, partly at your suggestion.
<blink?> I don't recall that suggestion. Maybe i said something that didn't translate well. Anyhow, all languages are different some way, as long as the customers know about it....
i still cannot find the list of keywords of the language.
How about Core Language/Declarations
Thanks, Pete, saw that. Was looking for "goto" or the other flow control keywords. I didn't see any mention of it in the section about differences between OE and Phix. Ergo, on that one word, i was confused about if it existed in Phix, or not, or if you had improved on it's performance from OE, or maybe i simply could not find it in the docs. Of course, i was going to look up other words after that one, so i mentioned keyword list in general.
Kat
9. Re: Phix : variable types
- Posted by petelomax Dec 11, 2016
- 1287 views
- Last edited Dec 12, 2016
Was looking for "goto" or the other flow control keywords. I didn't see any mention of it in the section about differences between OE and Phix. Ergo, on that one word, i was confused about if it existed in Phix, or not, or if you had improved on it's performance from OE, or maybe i simply could not find it in the docs.
The following (draft) text is copied from pops.e, and yes it should be tidied up and added to the docs somewhere (there should really be an Internals/#ilASM section, or something, but there's only one of me):
-- A brief note from the author about goto. -- ======================================== -- The subject of many a holy war, perhaps the most compelling argument against -- goto is that were it not pure evil we would all still be coding in assembly. -- High level constructs, such as if, for, while, procedure, and so on, along -- with sensible indentation, clearly make code far easier to read/understand. -- -- There is no shame in using a sensibly-named flag to control processing, and -- in many cases that additional sensible name also improves code legibility. -- -- There is no hll goto statement in Phix. However goto/jmp is unavoidable in -- assembly programming, and of course Phix supports inline assembly, hence in -- the very rare cases a goto is genuinely needed in hll code (I have seen just -- /three/ in the last two decades), the following construct(s) may be used: -- -- #ilASM{ jump :meaningful_label } -- ... -- #ilASM{ ::meaningful_label } -- -- In top level code, label scope is restricted to a single ilASM construct, -- but within a routine, the scope is across all the ilASM in that routine. -- -- There is quite deliberately no support for jumping from the middle of one -- routine into another: without a frame, then quite simply parameters and -- local variables have not been allocated and cannot be used/referenced. -- (See also global labels discussed below.) -- -- Making "goto" somewhat more difficult to type in this manner ensures that -- it is far less likely to be abused, and discourages newbie programmers -- from adopting it as a weapon of choice, as usually(/always) happens with -- a hll goto. -- -- Ultimately, and paradoxically, the real problem with goto is that as soon -- as they get daisy-chained together, something will inevitably end up in -- the wrong place, usually with no clue as to how or why they got there. -- Minor savings when writing code should of course always be balanced against -- potential wasted time trying to understand or debug it at some later date. -- Meaningless label names (eg "label4") make code substantially harder to -- understand. Error handling is much better and easier with normal hll code -- such as "return error(..)" or "error(..); return" - not only will any -- diagnostics have a clear "called from", but you can pass any required -- arguments, have just one error handler which serves several different -- routines, and very easily write unit tests for it - which you simply -- cannot do should it be embedded as a label inside something else. -- It is plain wrong to use more than one "goto" a year in hll code, the -- only real justification is when you find an algorithm which works and -- there is no simple way to replace jumps with proper hll constructs, or -- (extremely rarely) when doing so significantly impacts performance. -- Global Labels: (design notes) -- ============================= -- These were added to enable the replacement of (closed source) asm back end -- code with (open source) hll/#ilASM. In particular, tests showed that getc() -- would suffer badly with an opFrame/opCall overhead, besides it might prove -- rather difficult to ever implement opFrame/opCall via themselves! -- -- The "brief note about goto" above explained the use of local labels, which -- are deliberately rather limited due to the opFrame requirement. It is also -- possible to declare global labels, which are superficially similar however -- quite different internally, and have a different set of restrictions: -- -- #ilASM{ call :%unique_label } -- ... -- #ilASM{ jmp :skip -- :%unique_label -- ret -- ::skip } -- -- Global labels cannot be declared inside a routine, since without an opFrame -- there are no parameters or local variables, and as shown (almost always) -- require a skip construct. It is up to the programmer to ensure global labels -- are unique across the entire application, including any and all third party -- sources, and as mentioned above anything already set in pttree.e/iload(). -- Note that global labels are both declared and referenced with ":%". -- -- Whereas local labels are resolved using various offsets and are automatically -- converted into short form when the offset fits in a byte, global labels are -- resolved as absolute addresses. Since they are intended to be used with call, -- which has no short form, no such similar packing is attempted. -- -- To implement global labels I added several new tables to pglobals.e (glblused etc) -- and opLogPos to pops.e. The latter records the x86 offset in pilx86.e, which is -- adjusted at the end of scanforShortJmp() in pemit.e (and used in blurph()). -- -- Since global labels were implemented for the specific purpose of migrating back -- end code, use with caution, particularly so for any shared code. There is no -- attempt to permit the use of namespaces or anything similar. You may want to -- minimise the risk of clashes by using eg "printPL20130508" instead of "print".
HTH, Pete