5 src/grammar/expr/operators.pir - [expr] operator definitions.
7 =head2 Prefix Operators
15 .sub 'prefix:+' :multi(String)
19 toNumber = get_root_global ['_tcl'], 'toNumber'
28 if a == '' goto empty_string
29 die "can't use non-numeric string as operand of \"+\""
32 die "can't use empty string as operand of \"+\""
35 .sub 'prefix:+' :multi(pmc)
41 .sub 'prefix:-' :multi(String)
45 toNumber = get_root_global ['_tcl'], 'toNumber'
51 if $S0 == "TclInt" goto is_int
63 if a == '' goto empty_string
64 die "can't use non-numeric string as operand of \"-\""
67 die "can't use empty string as operand of \"-\""
70 .sub 'prefix:-' :multi(pmc)
79 .sub 'prefix:~' :multi(String)
83 toNumber = get_root_global ['_tcl'], 'toNumber'
90 if $S0 == 'TclFloat' goto cant_use_float
97 die "can't use floating-point value as operand of \"~\""
100 if a == '' goto empty_string
101 die "can't use non-numeric string as operand of \"~\""
104 die "can't use empty string as operand of \"~\""
107 .sub 'prefix:~' :multi(Float)
108 die "can't use floating-point value as operand of \"~\""
111 .sub 'prefix:~' :multi(pmc)
118 .sub 'prefix:!' :multi(String)
122 toBoolean = get_root_global ['_tcl'], 'toBoolean'
133 if a == '' goto empty_string
134 die "can't use non-numeric string as operand of \"!\""
137 die "can't use empty string as operand of \"!\""
140 .sub 'prefix:!' :multi(pmc)
146 =head2 Infix Operators
148 &&, || (and ?:) are handled during the PGE transformation stage.
152 # this is used to make double-quoted strings work
153 # (they're a series of captures that need to be concatenated)
162 $P0 = new 'TclString'
172 toNumber = get_root_global ['_tcl'], 'toNumber'
186 if a == '' goto empty_string
187 if b == '' goto empty_string
188 die "can't use non-numeric string as operand of \"**\""
191 die "can't use empty string as operand of \"**\""
194 if b < 0 goto zero_with_neg
195 if b == 0 goto zero_with_zero
201 die 'exponentiation of zero by negative power'
209 toNumber = get_root_global ['_tcl'], 'toNumber'
220 if a == '' goto empty_string
221 if b == '' goto empty_string
222 die "can't use non-numeric string as operand of \"*\""
225 die "can't use empty string as operand of \"*\""
233 toNumber = get_root_global ['_tcl'], 'toNumber'
240 if b == 0 goto divide_by_zero
250 $S0 = 'divide by zero'
255 if a == '' goto empty_string
256 if b == '' goto empty_string
257 die "can't use non-numeric string as operand of \"/\""
260 die "can't use empty string as operand of \"/\""
268 toNumber = get_root_global ['_tcl'], 'toNumber'
275 $I0 = isa a, 'TclFloat'
277 $I0 = isa b, 'TclFloat'
285 if a == '' goto empty_string
286 if b == '' goto empty_string
287 die "can't use non-numeric string as operand of \"%\""
290 die "can't use empty string as operand of \"%\""
293 die "can't use floating-point value as operand of \"%\""
301 toNumber = get_root_global ['_tcl'], 'toNumber'
312 if a == '' goto empty_string
313 if b == '' goto empty_string
314 die "can't use non-numeric string as operand of \"+\""
317 die "can't use empty string as operand of \"+\""
325 toNumber = get_root_global ['_tcl'], 'toNumber'
336 if a == '' goto empty_string
337 if b == '' goto empty_string
338 die "can't use non-numeric string as operand of \"-\""
341 die "can't use empty string as operand of \"-\""
345 .sub 'infix:<<' :multi(Float, pmc)
346 die "can't use floating-point value as operand of \"<<\""
349 .sub 'infix:<<' :multi(pmc, Float)
350 die "can't use floating-point value as operand of \"<<\""
353 .sub 'infix:<<' :multi(Integer, Integer)
361 .sub 'infix:<<' :multi(pmc, pmc)
366 toNumber = get_root_global ['_tcl'], 'toNumber'
384 if a == '' goto empty_string
385 if b == '' goto empty_string
386 die "can't use non-numeric string as operand of \"<<\""
389 die "can't use empty string as operand of \"<<\""
392 die "can't use floating-point value as operand of \"<<\""
396 .sub 'infix:>>' :multi(Float, pmc)
397 die "can't use floating-point value as operand of \">>\""
400 .sub 'infix:>>' :multi(pmc, Float)
401 die "can't use floating-point value as operand of \">>\""
404 .sub 'infix:>>' :multi(Integer, Integer)
411 .sub 'infix:>>' :multi(pmc, pmc)
416 toNumber = get_root_global ['_tcl'], 'toNumber'
434 if a == '' goto empty_string
435 if b == '' goto empty_string
436 die "can't use non-numeric string as operand of \">>\""
439 die "can't use empty string as operand of \">>\""
442 die "can't use floating-point value as operand of \">>\""
446 .sub 'infix:<' # boolean less than
451 toNumber = get_root_global ['_tcl'], 'toNumber'
465 .sub 'infix:>' # boolean greater than
470 toNumber = get_root_global ['_tcl'], 'toNumber'
484 .sub 'infix:<=' # boolean less than or equal
489 toNumber = get_root_global ['_tcl'], 'toNumber'
504 .sub 'infix:>=' # boolean greater than or equal
509 $P0 = get_root_namespace
510 toNumber = $P0['_tcl'; 'toNumber']
525 .sub 'infix:==' # boolean equal
530 $P0 = get_root_namespace
531 toNumber = $P0['_tcl'; 'toNumber']
548 .sub 'infix:!=' # boolean not equal
553 $P0 = get_root_namespace
554 toNumber = $P0['_tcl'; 'toNumber']
570 .sub 'infix:eq' # string equality
577 .sub 'infix:ne' # string inequality
589 .sub 'infix:&' :multi(String, String)
594 toInteger = get_root_global ['_tcl'], 'toInteger'
607 if a == '' goto empty_string
608 if b == '' goto empty_string
609 die "can't use non-numeric string as operand of \"&\""
612 die "can't use empty string as operand of \"&\""
615 .sub 'infix:&' :multi(String, Integer)
620 toInteger = get_root_global ['_tcl'], 'toInteger'
631 if a == '' goto empty_string
632 die "can't use non-numeric string as operand of \"&\""
635 die "can't use empty string as operand of \"&\""
638 .sub 'infix:&' :multi(Integer, String)
643 toInteger = get_root_global ['_tcl'], 'toInteger'
654 if b == '' goto empty_string
655 die "can't use non-numeric string as operand of \"&\""
658 die "can't use empty string as operand of \"&\""
661 .sub 'infix:&' :multi(Float, String)
666 toInteger = get_root_global ['_tcl'], 'toInteger'
671 die "can't use floating-point value as operand of \"&\""
674 if b == '' goto empty_string
675 die "can't use non-numeric string as operand of \"&\""
678 die "can't use empty string as operand of \"&\""
681 .sub 'infix:&' :multi(String, Float)
686 toInteger = get_root_global ['_tcl'], 'toInteger'
691 die "can't use floating-point value as operand of \"&\""
694 if a == '' goto empty_string
695 die "can't use non-numeric string as operand of \"&\""
698 die "can't use empty string as operand of \"&\""
701 .sub 'infix:&' :multi(Float, pmc)
702 die "can't use floating-point value as operand of \"&\""
705 .sub 'infix:&' :multi(pmc, Float)
706 die "can't use floating-point value as operand of \"&\""
709 .sub 'infix:&' :multi(Integer, Integer)
717 # bitwise exclusive OR
718 .sub 'infix:^' :multi(String, String)
723 toInteger = get_root_global ['_tcl'], 'toInteger'
736 if a == '' goto empty_string
737 if b == '' goto empty_string
738 die "can't use non-numeric string as operand of \"^\""
741 die "can't use empty string as operand of \"^\""
744 .sub 'infix:^' :multi(String, Integer)
749 toInteger = get_root_global ['_tcl'], 'toInteger'
760 if a == '' goto empty_string
761 die "can't use non-numeric string as operand of \"^\""
764 die "can't use empty string as operand of \"^\""
767 .sub 'infix:^' :multi(Integer, String)
772 toInteger = get_root_global ['_tcl'], 'toInteger'
783 if b == '' goto empty_string
784 die "can't use non-numeric string as operand of \"^\""
787 die "can't use empty string as operand of \"^\""
790 .sub 'infix:^' :multi(Float, String)
795 toInteger = get_root_global ['_tcl'], 'toInteger'
800 die "can't use floating-point value as operand of \"^\""
803 if b == '' goto empty_string
804 die "can't use non-numeric string as operand of \"^\""
807 die "can't use empty string as operand of \"^\""
810 .sub 'infix:^' :multi(String, Float)
815 toInteger = get_root_global ['_tcl'], 'toInteger'
820 die "can't use floating-point value as operand of \"^\""
823 if a == '' goto empty_string
824 die "can't use non-numeric string as operand of \"^\""
827 die "can't use empty string as operand of \"^\""
830 .sub 'infix:^' :multi(Float, pmc)
831 die "can't use floating-point value as operand of \"^\""
834 .sub 'infix:^' :multi(pmc, Float)
835 die "can't use floating-point value as operand of \"^\""
838 .sub 'infix:^' :multi(Integer, Integer)
847 .sub 'infix:|' :multi(String, String)
852 toInteger = get_root_global ['_tcl'], 'toInteger'
865 if a == '' goto empty_string
866 if b == '' goto empty_string
867 die "can't use non-numeric string as operand of \"|\""
870 die "can't use empty string as operand of \"|\""
873 .sub 'infix:|' :multi(String, Integer)
878 toInteger = get_root_global ['_tcl'], 'toInteger'
889 if a == '' goto empty_string
890 die "can't use non-numeric string as operand of \"|\""
893 die "can't use empty string as operand of \"|\""
896 .sub 'infix:|' :multi(Integer, String)
901 toInteger = get_root_global ['_tcl'], 'toInteger'
912 if b == '' goto empty_string
913 die "can't use non-numeric string as operand of \"|\""
916 die "can't use empty string as operand of \"|\""
919 .sub 'infix:|' :multi(Float, String)
924 toInteger = get_root_global ['_tcl'], 'toInteger'
929 die "can't use floating-point value as operand of \"|\""
932 if b == '' goto empty_string
933 die "can't use non-numeric string as operand of \"|\""
936 die "can't use empty string as operand of \"|\""
939 .sub 'infix:|' :multi(String, Float)
944 toInteger = get_root_global ['_tcl'], 'toInteger'
949 die "can't use floating-point value as operand of \"|\""
952 if a == '' goto empty_string
953 die "can't use non-numeric string as operand of \"|\""
956 die "can't use empty string as operand of \"|\""
959 .sub 'infix:|' :multi(Float, pmc)
960 die "can't use floating-point value as operand of \"|\""
963 .sub 'infix:|' :multi(pmc, Float)
964 die "can't use floating-point value as operand of \"|\""
967 .sub 'infix:|' :multi(Integer, Integer)
980 $P0 = get_root_namespace
981 toList = $P0['_tcl'; 'toList']
985 iter = new 'Iterator', list
987 unless iter goto false
989 $I0 = 'infix:=='(elem, $P0)
1003 $P0 = get_root_namespace
1004 toList = $P0['_tcl'; 'toList']
1008 iter = new 'Iterator', list
1010 unless iter goto true
1012 $I0 = 'infix:=='(elem, $P0)
1025 # vim: expandtab shiftwidth=4 ft=pir: