Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-07 Thread Sergei Gavrikov
On Mon, 7 Apr 2014, Jan Nijtmans wrote:

> 2014-04-07 19:34 GMT+02:00 Sergei Gavrikov wrote:
> 
> > Could you, please, take a look on this puzzle?
>
> 

Thanks!

Regards,
Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-07 Thread Jan Nijtmans
2014-04-07 19:34 GMT+02:00 Sergei Gavrikov :
> Hi Jan
>
> I found one exception, if there is digit 'b' (only) on the second
> position (only) in a hexadecimal number


> Could you, please, take a look on this puzzle?



Regards,
   Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-07 Thread Sergei Gavrikov
On Fri, 4 Apr 2014, Sergei Gavrikov wrote:

> On Fri, 4 Apr 2014, Jan Nijtmans wrote:
>
> > An additional issue is that binary/octal/hex numbers cannot contain
> > dots, so they must be handled separately anyway. Done here:
> >  
>
> [the issues went away]
>
> Thank you very much! Now we have the comfortable way to manage any
> numbers on embedded targets.

Hi Jan

I found one exception, if there is digit 'b' (only) on the second
position (only) in a hexadecimal number

  % fossil test-th-eval 'expr 0+0xb'
  11
  % fossil test-th-eval 'expr 0+0x0b'
  0
  % fossil test-th-eval 'expr 0+0x00b'
  11

  % fossil test-th-eval 'expr 0+0xbc'
  188
  % fossil test-th-eval 'expr 0+0x0bc'
  TH_ERROR: expected number, got: "0x0bc"
  % fossil test-th-eval 'expr 0+0x00bc'
  188

First, I thought that (0b) somehow shadows (0x), but this expressions
also fail

  % fossil test-th-eval 'expr 0+0xab'
  0
  % fossil test-th-eval 'expr 0+0xabc'
  TH_ERROR: expected number, got: "0xabc"

Could you, please, take a look on this puzzle?

Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-05 Thread Jan Nijtmans
2014-04-04 10:57 GMT+02:00 Stephan Beal :
> Maybe if you want to output your UUIDs in binary format... that might be fun
> to do each year on April 1st.

   ;-)

Regards,
  Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread B Harder
I think th1 "happens" to basically be a subset of Tcl, but is not
"designed" to strictly be a subset of Tcl, fwiw.

On 4/4/14, Jan Nijtmans  wrote:
> 2014-04-04 10:54 GMT+02:00 Mark Janssen :
>> Why can't n-ary numbers have dots? 0b1.11 is a perfectly valid
>> representation of 1.75.
>
> $ tclsh8.6
> % expr 0+0b1.1
> missing operator at _@_
> in expression "0+0b1_@_.1"
> %
>
> Since th1 is supposed to be a subset of Tcl, I don't think
> that th1 should invent any syntax which Tcl doesn't support.
> (Feel free to write a Tcl TIP, but I don't think it has a high
> chance to be accepted.)
>
> Regards,
>  Jan Nijtmans
> ___
> fossil-users mailing list
> fossil-users@lists.fossil-scm.org
> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
>


-- 
Brad Harder
Method Logic Digital Consulting
http://www.methodlogic.net/
http://twitter.com/bcharder
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Sergei Gavrikov
On Fri, 4 Apr 2014, Jan Nijtmans wrote:

> An additional issue is that binary/octal/hex numbers cannot contain
> dots, so they must be handled separately anyway. Done here:
>  
 
[the issues went away]

Thank you very much! Now we have the comfortable way to manage any
numbers on embedded targets.

Regards,
Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Jan Nijtmans
2014-04-04 11:06 GMT+02:00 Jan Nijtmans :
> Since th1 is supposed to be a subset of Tcl, I don't think
> that th1 should invent any syntax which Tcl doesn't support.
> (Feel free to write a Tcl TIP, but I don't think it has a high
> chance to be accepted.)

Noted that the floating point format accepted for TH1
is a subset of that accepted by Tcl already:

$ tclsh8.6
% expr 0+1.
1.0
% expr 0+1e-1
0.1

$ fossil test-th-eval "expr 0+1."
TH_ERROR: expected number, got: "1."
$ fossil test-th-eval "expr 0+1e-1"
TH_ERROR: syntax error in expression: "0+1e-1"

I'm not going to enhance fossil to accept the same
floating point syntax as Tcl (since I simply don't need
it), but if someone else needs it I wouldn't object.

Regards,
   Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Jan Nijtmans
2014-04-04 10:54 GMT+02:00 Mark Janssen :
> Why can't n-ary numbers have dots? 0b1.11 is a perfectly valid
> representation of 1.75.

$ tclsh8.6
% expr 0+0b1.1
missing operator at _@_
in expression "0+0b1_@_.1"
%

Since th1 is supposed to be a subset of Tcl, I don't think
that th1 should invent any syntax which Tcl doesn't support.
(Feel free to write a Tcl TIP, but I don't think it has a high
chance to be accepted.)

Regards,
 Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Stephan Beal
On Fri, Apr 4, 2014 at 10:54 AM, Mark Janssen  wrote:

> Why can't n-ary numbers have dots? 0b1.11 is a perfectly valid
> representation of 1.75.
>

i would argue that in the context of fossil, which rarely uses floating
point numbers and never uses binary numbers, such a feature is YAGNI[1].
Maybe if you want to output your UUIDs in binary format... that might be
fun to do each year on April 1st.

[1] http://en.wikipedia.org/wiki/You_aren't_gonna_need_it

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Mark Janssen
On Fri, Apr 4, 2014 at 10:28 AM, Jan Nijtmans wrote:

>
>
> An additional issue is that binary/octal/hex numbers cannot contain
> dots, so they must be handled separately anyway. Done here:
>  
>
>
>
Why can't n-ary numbers have dots? 0b1.11 is a perfectly valid
representation of 1.75.

Mark
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-04 Thread Jan Nijtmans
2014-04-03 23:23 GMT+02:00 Sergei Gavrikov :
> It seems that should not reload isdigit validator for octal and binary
> numbers, otherwise early break on illegal digit returns bad tokens: for
> example, for "0b2" sequence thNextNumber() will return "0b" token, for
> "0o8" sequence it will return "0o". But, tokens should be "0b2" or
> "0o8". Only hexadecimal numbers is a case to change the validator.

An additional issue is that binary/octal/hex numbers cannot contain
dots, so they must be handled separately anyway. Done here:
 

Regards,
   Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Ron Wilson
On Thu, Apr 3, 2014 at 10:34 AM, Jan Nijtmans wrote:

> See: 
>
> > Newer languages have been abandoning the prefix 0, as decimal numbers
> > are often represented with leading zeroes. The prefix q was introduced to
> > avoid the prefix o being mistaken for a zero, while the prefix 0o was
> introduced
> > to avoid starting a numerical literal with an alphabetic character (like
> o or q),
> > since these might cause the literal to be confused with a variable name.
> The
> > prefix 0o also follows the model set by the prefix 0x used for
> hexadecimal
> > literals in the C language; it is supported by Haskell,[10] OCaml,[11]
> Perl 6,
> > [12] Python as of version 3.0,[13] Ruby,[14] Tcl as of version 9,[15]
> and it is
> > intended to be supported by ECMAScript 6[16] (the prefix 0 has been
> > discouraged in ECMAScript 3 and dropped in ECMAScript 5[17]).


Interesting. Never heard of this trend, but 90% of my coding for work is in
C/C++ as I develop SW for controlling electro-mechanical systems.

I use 0x (for hexadecimal) and 0b (for binary), but almost never use any
octal notation, as nearly all the integer values I work with are 8, 16 or
32 bits in length. (Occasionally, 24 bits)
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
On Thu, 3 Apr 2014, Sergei Gavrikov wrote:

> On Thu, 3 Apr 2014, Sergei Gavrikov wrote:
>
> > The fix is attached.
>   ^^^
>
> Please, forget it! Sorry.

It seems that should not reload isdigit validator for octal and binary
numbers, otherwise early break on illegal digit returns bad tokens: for
example, for "0b2" sequence thNextNumber() will return "0b" token, for
"0o8" sequence it will return "0o". But, tokens should be "0b2" or
"0o8". Only hexadecimal numbers is a case to change the validator.

Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
On Thu, 3 Apr 2014, Sergei Gavrikov wrote:

> The fix is attached.
  ^^^

Please, forget it! Sorry.

Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
On Thu, 3 Apr 2014, Sergei Gavrikov wrote:

> TH does trig on such typos
>
>   expr 0+0b2
>   expr 0+0o8

I mean

  % fossil test-th-eval 'expr 0+0b2'
  fossil: ../src/th.c:2140: exprMakeTree: Assertion `!apToken[jj] || 
!apToken[0]' failed.
  Aborted

> So, for the new three things I would enter three new bit sets for
> aCharProp[].

Jan, excuse me that was mistaken guess on the bit sets, the reason was
my miss in src/th.c:thNexNumber(). The fix is attached.

Thank you.

SergeiIndex: src/th.c
==
--- src/th.c
+++ src/th.c
@@ -1879,31 +1879,35 @@
   int nInput,
   int *pnLiteral
 ){
   int i = 0;
   int seenDot = 0;
+  int seenPfx = 0;
   int (*isdigit)(char) = th_isdigit;
   if( nInput>2 ){
 if( zInput[0]=='0' && (zInput[1]=='x' || zInput[1]=='X') ){
   i=2;
+  seenPfx = 1;
   isdigit = th_ishexdig;
 }
 if( zInput[0]=='0' && (zInput[1]=='o' || zInput[1]=='O') ){
   i=2;
+  seenPfx = 1;
   isdigit = th_isoctdig;
 }
 if( zInput[0]=='0' && (zInput[1]=='b' || zInput[1]=='B') ){
   i=2;
+  seenPfx = 1;
   isdigit = th_isbindig;
 }
   }
   for(; i___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
On Thu, 3 Apr 2014, Jan Nijtmans wrote:

> 2014-04-03 15:10 GMT+02:00 Sergei Gavrikov :
> > Good point. Thak you. With new patch TH1 works as Tcl 8.5
>
> While on it, I added binary as well.
>
> 

Thanks! Sure, '0b' also will be helpful for folk who need to move the
bits. However, TH does trig on such typos

  expr 0+0b2
  expr 0+0o8

So, for the new three things I would enter three new bit sets for
aCharProp[].

Sergei
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Jan Nijtmans
2014-04-03 15:10 GMT+02:00 Sergei Gavrikov :
> Good point. Thak you. With new patch TH1 works as Tcl 8.5

While on it, I added binary as well.



Thanks!

Regards,
  Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Jan Nijtmans
2014-04-03 15:14 GMT+02:00 Stephan Beal :
> Weird - i've never seen octals written that way, but i trust Jan's judgement
> implicitly regarding issued of "TCL-ness."

See: 

> Newer languages have been abandoning the prefix 0, as decimal numbers
> are often represented with leading zeroes. The prefix q was introduced to
> avoid the prefix o being mistaken for a zero, while the prefix 0o was 
> introduced
> to avoid starting a numerical literal with an alphabetic character (like o or 
> q),
> since these might cause the literal to be confused with a variable name. The
> prefix 0o also follows the model set by the prefix 0x used for hexadecimal
> literals in the C language; it is supported by Haskell,[10] OCaml,[11] Perl 6,
> [12] Python as of version 3.0,[13] Ruby,[14] Tcl as of version 9,[15] and it 
> is
> intended to be supported by ECMAScript 6[16] (the prefix 0 has been
> discouraged in ECMAScript 3 and dropped in ECMAScript 5[17]).

Actually, Tcl 8.5 was the first Tcl version which understands the "0o"
prefix, but since Tcl 8.4 is still in use somewhere availability is not
guaranteed in all Tcl environments. That's my explanation why
it isn't used very much.

Regards,
Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Stephan Beal
On Thu, Apr 3, 2014 at 3:10 PM, Sergei Gavrikov
wrote:

> On Thu, 3 Apr 2014, Jan Nijtmans wrote:Good point. Thak you. With new
> patch TH1 works as Tcl 8.5
>
>   % expr {0o10+10+0x10}
>   34
>   % expr {0O10+10+0X10}
>   34
>   % expr {0o77+99+0xff}
>   417
>

Weird - i've never seen octals written that way, but i trust Jan's
judgement implicitly regarding issued of "TCL-ness."

i'll get that patch added to the standalone th1 library in the next day or
two. If you'd like access to that one, contact me off-list and i'll set you
up (it's independent of the fossil tree, requires no license waiver, and
this would be at least the second fix from you).

Thanks, Sergei!

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
On Thu, 3 Apr 2014, Jan Nijtmans wrote:

> 2014-04-03 14:05 GMT+02:00 Sergei Gavrikov :
> > Could anyone take a look on the workaround, please? Well, Th_ToInt()
> > become itself a bit more slow, but I think it is still more fast than
> > strtoll(). At the least, I can say that the patch does not break the
> > existing Fossil TH1 tests.
> 
> I'm not fond of allowing a "0"-prefix for octal numbers, better
> restrict it to "0o", which is more consistent with "0x" for hex.
> Yes, Tcl 8.x allows it now, but in future Tcl versions it will
> most likely being abandoned. See: 
 
Good point. Thak you. With new patch TH1 works as Tcl 8.5

  % expr {0o10+10+0x10}
  34
  % expr {0O10+10+0X10}
  34
  % expr {0o77+99+0xff}
  417

> Other than that, it looks good to me.
 
Thanks you for review!

SergeiIndex: src/th.c
==
--- src/th.c
+++ src/th.c
@@ -1867,10 +1867,13 @@
   {"|",  OP_BITWISE_OR,10, ARG_INTEGER},
 
   {0,0,0,0}
 };
 
+int th_ishexdig(char c);  /* 0x* and 0X* */
+int th_isoctdig(char c);  /* 0o* and 0O* */
+
 /*
 ** The first part of the string (zInput,nInput) contains a number.
 ** Set *pnVarname to the number of bytes in the numeric string.
 */
 static int thNextNumber(
@@ -1877,15 +1880,26 @@
   Th_Interp *interp,
   const char *zInput,
   int nInput,
   int *pnLiteral
 ){
-  int i;
+  int i = 0;
   int seenDot = 0;
-  for(i=0; i2 ){
+if( zInput[0]=='0' && (zInput[1]=='x' || zInput[1]=='X') ){
+  i=2;
+  isdigit = th_ishexdig;
+}
+if( zInput[0]=='0' && (zInput[1]=='o' || zInput[1]=='O') ){
+  i=2;
+  isdigit = th_isoctdig;
+}
+  }
+  for(; i0 && (z[0]=='-' || z[0]=='+') ){
 i = 1;
+  }
+  if( n>2 ){
+if( z[i]=='0' && (z[i+1]=='x' || z[i+1]=='X') ){
+  i += 2;
+  base = 16;
+  isdigit = th_ishexdig;
+}
+if( z[i]=='0' && (z[i+1]=='o' || z[i+1]=='O') ){
+  i += 2;
+  base = 8;
+  isdigit = th_isoctdig;
+}
   }
   for(; i='a' ){
+  shift = 87;
+}else if( z[i]>='A' ){
+  shift = 55;
+}else{
+  shift = 48;
+}
+iOut = iOut * base + (z[i] - shift);
   }
 
   if( n>0 && z[0]=='-' ){
 iOut *= -1;
   }

___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Jan Nijtmans
2014-04-03 14:05 GMT+02:00 Sergei Gavrikov :
> Could anyone take a look on the workaround, please? Well, Th_ToInt()
> become itself a bit more slow, but I think it is still more fast than
> strtoll(). At the least, I can say that the patch does not break the
> existing Fossil TH1 tests.

I'm not fond of allowing a "0"-prefix for octal numbers, better
restrict it to "0o", which is more consistent with "0x" for hex.
Yes, Tcl 8.x allows it now, but in future Tcl versions it will
most likely being abandoned. See: 

Other than that, it looks good to me.

Regards,
  Jan Nijtmans
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


[fossil-users] TH1: support for octal and hexadecimal numbers in expressions

2014-04-03 Thread Sergei Gavrikov
Hi

I have a small patch (it is attached just for reference) to make TH1
use the integers also in other formats (hexadecimal and octal forms).

For example, we would use the same expressions then

  %  expr {010+10+0x10}
  34

Could we add such a support in Fossil TH1? I believe the TH1 stands for
"Test Harness 1" and I use TH1 core with the extensions in my embedded
projects and it is pity that I cannot just type 0x... :-)

Could anyone take a look on the workaround, please? Well, Th_ToInt()
become itself a bit more slow, but I think it is still more fast than
strtoll(). At the least, I can say that the patch does not break the
existing Fossil TH1 tests.

Thanks for Fossil!

SergeiIndex: src/th.c
==
--- src/th.c
+++ src/th.c
@@ -1867,10 +1867,12 @@
   {"|",  OP_BITWISE_OR,10, ARG_INTEGER},
 
   {0,0,0,0}
 };
 
+int th_ishexdig(char c);
+
 /*
 ** The first part of the string (zInput,nInput) contains a number.
 ** Set *pnVarname to the number of bytes in the numeric string.
 */
 static int thNextNumber(
@@ -1877,15 +1879,20 @@
   Th_Interp *interp,
   const char *zInput,
   int nInput,
   int *pnLiteral
 ){
-  int i;
+  int i = 0;
   int seenDot = 0;
-  for(i=0; i2 && zInput[0]=='0' && (zInput[1]=='x' || zInput[1]=='X') ){
+i=2;
+isdigit = th_ishexdig;
+  }
+  for(; i0 && (z[0]=='-' || z[0]=='+') ){
 i = 1;
   }
+  if( n>2 && z[i]=='0' && (z[i+1]=='x' || z[i+1]=='X') ){
+i += 2;
+base = 16;
+isdigit = th_ishexdig;
+  }else if( n>1 && z[i]=='0' ){
+i += 1;
+base = 8;
+isdigit = th_isoctdig;
+  }
   for(; i='a' ){
+  shift = 87;
+}else if( z[i]>='A' ){
+  shift = 55;
+}else{
+  shift = 48;
+}
+iOut = iOut * base + (z[i] - shift);
   }
 
   if( n>0 && z[0]=='-' ){
 iOut *= -1;
   }

___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users