Forum > General

How to force the not operator to return a byte

<< < (14/14)

y.ivanov:
Here are the snippets from the compiler source:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// from pexpr.pas...            _INTCONST :               begin                 {Try first wether the value fits in an int64.}                 val(pattern,ic,code);                 if code=0 then                   begin                      consume(_INTCONST);                      int_to_type(ic,hdef);                      p1:=cordconstnode.create(ic,hdef,true);                   end                 else                   begin                     { try qword next }                      ...                 if code<>0 then                   begin                     { finally float }                      ... // from defutil.pas  ...    procedure int_to_type(const v:TConstExprInt;var def:tdef);      begin        range_to_type(v,v,def);      end;...    procedure range_to_type(const l,h:TConstExprInt;var def:tdef);      begin        { prefer signed over unsigned }        if (l>=int64(-128)) and (h<=127) then         def:=s8inttype        else if (l>=0) and (h<=255) then         def:=u8inttype        else if (l>=int64(-32768)) and (h<=32767) then         def:=s16inttype        else if (l>=0) and (h<=65535) then         def:=u16inttype        else if (l>=int64(low(longint))) and (h<=high(longint)) then         def:=s32inttype        else if (l>=low(cardinal)) and (h<=high(cardinal)) then         def:=u32inttype        else if (l>=low(int64)) and (h<=high(int64)) then         def:=s64inttype        else         def:=u64inttype;      end;...
I believe the code of procedure range_to_type says it all. No more contradictions.  :D

Roland57:
Thank you all for the very informative discussion.  :)

winni:


To be, Or Not (to be )

Hamlet, Shakespeare


engkin:
Here is the source code for NOT:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//nmatfunction tnotnode.simplify(forinline : boolean):tnode;...{ constant folding }if (left.nodetype=ordconstn) and  (left.resultdef.typ=orddef) then  begin    v:=tordconstnode(left).value;    def:=left.resultdef;....    uchar,    uwidechar,    u8bit,    s8bit,    u16bit,    s16bit,    s32bit,    u32bit,    s64bit,    u64bit:      begin        { unsigned, equal or bigger than the native int size? }        if (torddef(left.resultdef).ordtype in [u64bit,u32bit,u16bit,u8bit,uchar,uwidechar]) and           (is_nativeord(left.resultdef) or is_oversizedord(left.resultdef)) then          begin            { Delphi-compatible: not dword = dword (not word = longint) }            { Extension: not qword = qword                              }            v:=qword(not qword(v));            { will be truncated by the ordconstnode for u32bit }          end        else          begin            v:=int64(not int64(v));            def:=get_common_intdef(torddef(left.resultdef),torddef(sinttype),false);          end;      end;
So NOT is computed as:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---            v:=int64(not int64(v));
"will be truncated by the ordconstnode for us32bit"

Navigation

[0] Message Index

[*] Previous page

Go to full version