<html><head><base href="x-msg://5629/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I guess I am uncertain what it is you are trying to achieve. The Modula-3 frontend never generates unsigned integers. Everything is signed. If you want to represent (unsigned) then, yes, I guess you want TWord.TBytes.</div><br>
<br><div><div>On 23 Feb 2010, at 13:15, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">So we need TWord.ToBytes?<br> <br> - Jay<br> <br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Tue, 23 Feb 2010 12:39:49 -0500<br>To:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>Subject: Re: [M3commit] CVS Update: cm3<br><br>Actually, on second thought, of course it cannot be fixed. The signed value 128 *does* require 2 bytes to represent. (char)128 == -128. (short)128 == 128.<div>These TInt functions should be interpreted as having C arithmetic semantics.</div><div><br><div><div>On 23 Feb 2010, at 08:35, Tony Hosking wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div style="word-wrap: break-word; "><div><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><div style="word-wrap: break-word; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><div><span class="ecxApple-style-span" style="font-size: medium; "><font class="ecxApple-style-span" color="#0000ff" face="'Gill Sans'">That can be fixed...</font></span></div><div><font class="ecxApple-style-span" color="#0000ff" face="'Gill Sans'"><span class="ecxApple-style-span" style="font-size: medium; "><br></span></font></div></span></span></span></span></span></span></span></span></div></span></span></div><div><div>On 22 Feb 2010, at 21:30, Jay K wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div><br>ToBytes claims the value 128 requires 2 bytes. Which is reasonable. But not always expected. There should be an unsigned version that claims 1 byte?<br>I can look into Chop and ToBytes more, but I am at least currently reusing add/subtract/multiple/div/mod/shift/rotate/toint/fromint/tochars, not bad.<br><br><br>- Jay<br><br><br>----------------------------------------<br><blockquote>From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br></blockquote><blockquote>Date: Mon, 22 Feb 2010 21:10:10 -0500<br></blockquote><blockquote>To:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br></blockquote><blockquote>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br></blockquote><blockquote>Subject: Re: [M3commit] CVS Update: cm3<br></blockquote><blockquote><br></blockquote><blockquote>On 22 Feb 2010, at 20:30, Jay K wrote:<br></blockquote><blockquote><br></blockquote><blockquote><blockquote>I'm still a bit leary of Chop and ToBytes.<br></blockquote></blockquote><blockquote><br></blockquote><blockquote>Chop is just the same as a C cast.<br></blockquote><blockquote>i.e., (char)0xFFFFFFFF and (char)0x000000FF return the same value (char)-1.<br></blockquote><blockquote><br></blockquote><blockquote>ToBytes simply returns the significant bytes.<br></blockquote><blockquote><br></blockquote><blockquote><blockquote>I *suspect* we need a bit more in TWord to make this all hold together.<br></blockquote></blockquote><blockquote><br></blockquote><blockquote>I don't see the need. I think this speaks to confusion on your part...<br></blockquote><blockquote><br></blockquote><blockquote><blockquote>Look at my current M3BackInt.m3. It is almost entirely now delegating to TInt/TWord, except it has its own conversions back and forth. It applies Widen before every operation, chop after every one. They are different for unsigned vs. signed. (Hm, unsigned narrow should probably check that the value fits, and the caller can ignore that or not.)<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>I don't entirely ignore ToInt's boolean.<br></blockquote></blockquote><blockquote><blockquote>I then check if the value fits in Word32. If it does, I ignore the overflow, knowing the value converted "reasonably". If it doesn't, I error.<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>I think TWord.ToWord, which doesn't exist, would do what I want -- allow for 0-2^n and fail otherwise.<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>Further, I should chose TWord.ToWord vs. TInt.ToInt based on the types I have. And then the frontend shouldn't claim 255 is an Int8. And such.<br></blockquote></blockquote><blockquote><blockquote>(I'm not sure how I'm getting away with this currently, maybe something odd in my ToBytes.)<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>What is there now is in pretty good shape, and M3BackInt/Word reinvent exceedingly little code now. I'd be plenty ok moving to other stuff now, such as atomic8/16/64 (and more testing of atomic32, which I think are done and working). I wasn't too keen spending the time adapting to the TInt/TWord changes, but I also didn't want the two nearly identical copies, esp. since I haven't read through DivMod to understand it.<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>And then rewriting hand.c in Modula-3.<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>And then other stuff.<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>..Jay<br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote><br></blockquote></blockquote><blockquote><blockquote>________________________________<br></blockquote></blockquote><blockquote><blockquote><blockquote>From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Date: Mon, 22 Feb 2010 20:03:03 -0500<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>To:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Subject: Re: [M3commit] CVS Update: cm3<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>P.S. The assumption is that results from operations that overflow should be discarded.<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Antony Hosking | Associate Professor | Computer Science | Purdue University<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>305 N. University Street | West Lafayette | IN 47907 | USA<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Office +1 765 494 6001 | Mobile +1 765 427 5484<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>On 22 Feb 2010, at 20:01, Tony Hosking wrote:<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Jay, If you want that behavior, just do:<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>TInt.Chop(x, BYTESIZE(INTEGER), x);<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>TInt.ToInt(x, i)<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>On 22 Feb 2010, at 23:57, Jay Krell wrote:<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>CVSROOT: /usr/cvs<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Changes by: jkrell@birch. 10/02/22 23:57:21<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Modified files:<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>cm3/m3-sys/m3back/src/: M3BackInt.m3<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>Log message:<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>remove local versions of ToInt and FromInt now that TInt.ToInt packs the bytes even if there is overflow (the right solution I suspect it TWord.ToWord)<br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><br></blockquote></blockquote></blockquote><blockquote><span class="ecxApple-tab-span" style="white-space: pre; "></span><span class="ecxApple-tab-span" style="white-space: pre; "></span><span class="ecxApple-tab-span" style="white-space: pre; "></span> <span class="ecxApple-tab-span" style="white-space: pre; "> </span><span class="ecxApple-tab-span" style="white-space: pre; "></span> <br></blockquote></div></blockquote></div><br></div></blockquote></div><br></div></div></span><br class="Apple-interchange-newline"></blockquote></div><br></body></html>