04-expr-ops.M1pp (859B)
1 # Every operator in apply_expr_op. 2 3 # variadic: +, *, &, |, ^, with argc >= 1 (>2 to exercise the fold) 4 $((+ 1 2 3 4 5)) 5 $((* 2 3 4)) 6 $((& 0xFF 0x0F 0x07)) 7 $((| 0x10 0x20 0x40)) 8 $((^ 0xFF 0x0F 0xF0)) 9 10 # subtract: unary negate AND left-assoc with > 2 args 11 $((- 7)) 12 $((- 100 10 20 30)) 13 14 # binary div / mod 15 $((/ 1000 7)) 16 $((% 1000 7)) 17 18 # shifts: << logical, >> arithmetic (so high bit propagates on negatives) 19 $((<< 1 16)) 20 $((>> 0x80000000 4)) 21 22 # unary ~ 23 $((~ 0)) 24 25 # comparisons (each returns 0 or 1) 26 $((= 5 5)) 27 $((!= 5 5)) 28 $((< 3 5)) 29 $((<= 5 5)) 30 $((> 5 3)) 31 $((>= 5 5)) 32 $((>= 5 6)) 33 34 # nested expressions 35 $((+ (* 2 3) (- 7 4) (/ 12 3))) 36 37 # strlen: raw byte count between the quotes (matches what M1's "..." emits 38 # before appending NUL). Composes with arithmetic like any other op. 39 %((strlen "hello")) 40 %((+ (strlen "hello") 1)) 41 !((strlen "x")) 42 %((strlen "")) 43 END