Skip to content

Commit 3f5771b

Browse files
gh-186: Rename operators.
Closes #186
1 parent e16fc8e commit 3f5771b

190 files changed

Lines changed: 479 additions & 479 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/SPECIFICATION.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@
685685

686686
The subsections below use a type-annotation convention. A type annotation is written as `TYPE name`, where `TYPE` is followed by one or more space characters and then the annotated name. A union notation such as `INT|FLT` restricts an argument to any one of the listed types. `ANY` denotes any runtime type (`BOOL`, `INT`, `FLT`, `STR`, `TNS`, `MAP`, `FUNC`, or `THR`), including extension-defined types when extensions are active, unless the signature narrows the set explicitly. `SYMBOL` is a pseudo-type indicating that the argument MUST be a plain unquoted identifier; such operators receive the symbol name rather than its runtime value.
687687

688-
`MODULE` is a pseudo-type indicating that the argument MUST be a plain unquoted module identifier or a package-qualified module name using the language's `..` separator. A slash-separated signature such as `ADD/SUB/MUL` denotes a family of distinct operators that share the same argument rules and differ only in the named operation.
688+
`MODULE` is a pseudo-type indicating that the argument MUST be a plain unquoted module identifier or a package-qualified module name using the language's `..` separator. A comma-separated signature such as `+, -, *` denotes a family of distinct operators that share the same argument rules and differ only in the named operation.
689689

690690
`EXTENSION` is a pseudo-type indicating that the argument MUST be a plain unquoted extension specifier used by `EXTEND`, excluding the platform filename suffix and optionally using package-style `..` separators.
691691

@@ -737,15 +737,15 @@
737737

738738
#### 9.1.3 Arithmetic operators
739739

740-
- `INT|FLT ADD/SUB/MUL/DIV/CDIV/POW/MOD(INT|FLT a, INT|FLT b)` = MUST implement, respectively, addition, subtraction, multiplication, division, ceiling division, exponentiation, and remainder. Except where an operator explicitly states otherwise, `a` and `b` MUST have the same numeric type. Division by zero MUST raise a runtime error.
740+
- `INT|FLT +, -, *, /, CDIV, POW, MOD(INT|FLT a, INT|FLT b)` = MUST implement, respectively, addition, subtraction, multiplication, division, ceiling division, exponentiation, and remainder. Except where an operator explicitly states otherwise, `a` and `b` MUST have the same numeric type. Division by zero MUST raise a runtime error.
741741

742742
- `INT|FLT NEG/ABS(INT|FLT value)` = MUST return the additive inverse or absolute value of `value`, respectively.
743743

744744
- `INT|FLT GCD/LCM(INT|FLT a, INT|FLT b)` = MUST compute the greatest common divisor or least common multiple of `a` and `b`. Mixed `INT` and `FLT` operands MUST be rejected.
745745

746746
- `INT|FLT ROOT(INT|FLT x, INT|FLT n)` = MUST compute the `n`th root of `x`. For `INT` operands, positive `n` MUST produce the greatest integer `r` such that `r^n <= x` when that notion is defined; `n = 0` MUST raise a runtime error; and negative-`n` integer results are valid only where the reciprocal remains an integer. For `FLT` operands, the result MUST be `x^(1/n)`, with negative `x` permitted only when `n` denotes an odd integer. Invalid roots MUST raise a runtime error.
747747
748-
- `INT IADD/ISUB/IMUL/IDIV/IPOW/IROOT(INT|FLT a, INT|FLT b)` and `FLT FADD/FSUB/FMUL/FDIV/FPOW/FROOT(INT|FLT a, INT|FLT b)` = MUST first coerce both operands to the target numeric type and then perform the corresponding arithmetic operation. Failed coercion MUST raise a runtime error.
748+
- `INT I+, I-, I*, I/, IPOW, IROOT(INT|FLT a, INT|FLT b)` and `FLT F+, F-, F*, F/, FPOW, FROOT(INT|FLT a, INT|FLT b)` = MUST first coerce both operands to the target numeric type and then perform the corresponding arithmetic operation. Failed coercion MUST raise a runtime error.
749749
750750
- `INT|FLT SUM/PROD(INT|FLT a1, ..., INT|FLT aN)`, `INT ISUM/IPROD(INT|FLT a1, ..., INT|FLT aN)`, and `FLT FSUM/FPROD(INT|FLT a1, ..., INT|FLT aN)` = MUST compute the corresponding aggregate sum or product across all arguments. The unprefixed forms MUST reject mixed `INT` and `FLT` operands.
751751
@@ -815,11 +815,11 @@
815815
816816
- `BOOL IN(ANY value, TNS tensor)` = MUST return `TRUE` if any tensor element is equal to `value` and `FALSE` otherwise.
817817
818-
- `TNS MADD/MSUB/MMUL/MDIV(TNS x, TNS y)` = MUST perform elementwise tensor-tensor arithmetic. The input shapes MUST match exactly, the element types MUST be uniformly numeric and mutually compatible, and division by zero MUST raise a runtime error.
818+
- `TNS M+, M-, M*, M/(TNS x, TNS y)` = MUST perform elementwise tensor-tensor arithmetic. The input shapes MUST match exactly, the element types MUST be uniformly numeric and mutually compatible, and division by zero MUST raise a runtime error.
819819
820820
- `TNS MSUM/MPROD(TNS t1, ..., TNS tN)` = MUST perform elementwise sum or product across tensors of identical shape and mutually compatible numeric element type.
821821
822-
- `TNS TADD/TSUB/TMUL/TDIV/TPOW(TNS tensor, INT|FLT scalar)` = MUST perform tensor-scalar arithmetic. All tensor elements and the scalar MUST share the same numeric type, except where a specific operator explicitly permits widening. Division by zero MUST raise a runtime error.
822+
- `TNS T+, T-, T*, T/, TPOW(TNS tensor, INT|FLT scalar)` = MUST perform tensor-scalar arithmetic. All tensor elements and the scalar MUST share the same numeric type, except where a specific operator explicitly permits widening. Division by zero MUST raise a runtime error.
823823
824824
---
825825

lib/std/csprng.pre

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! ChaCha20-based cryptographically secure pseudorandom number generator
22

3-
INT MASK32 = SUB( POW(0b10, 0b100000), 1 ) ! 2^32-1
3+
INT MASK32 = -( POW(0b10, 0b100000), 1 ) ! 2^32-1
44

55
! ChaCha20 constants ("expand 32-byte k")
66
MAP CH_CONST = < ^
@@ -19,7 +19,7 @@ INT ch_buf_pos = TLEN(ch_buf, 0b1) ! set to buffer length to force refill
1919
FUNC INT ROTL32(INT x, INT n){
2020
INT x32 = BAND(x, MASK32)
2121
INT left = BAND(SHL(x32, n), MASK32)
22-
INT right = SHR(x32, SUB(0b100000, n)) ! 32 - n
22+
INT right = SHR(x32, -(0b100000, n)) ! 32 - n
2323
RETURN( BAND(BOR(left, right), MASK32) )
2424
}
2525

@@ -29,13 +29,13 @@ FUNC INT QR(TNS s, INT ia, INT ib, INT ic, INT id){
2929
INT c = s[ic]
3030
INT d = s[id]
3131

32-
a = BAND( ADD(a, b), MASK32 )
32+
a = BAND( +(a, b), MASK32 )
3333
d = ROTL32( BXOR(d, a), 0b10000 ) ! 16
34-
c = BAND( ADD(c, d), MASK32 )
34+
c = BAND( +(c, d), MASK32 )
3535
b = ROTL32( BXOR(b, c), 0b1100 ) ! 12
36-
a = BAND( ADD(a, b), MASK32 )
36+
a = BAND( +(a, b), MASK32 )
3737
d = ROTL32( BXOR(d, a), 0b1000 ) ! 8
38-
c = BAND( ADD(c, d), MASK32 )
38+
c = BAND( +(c, d), MASK32 )
3939
b = ROTL32( BXOR(b, c), 0b111 ) ! 7
4040

4141
s[ia] = a
@@ -78,45 +78,45 @@ FUNC INT CHACHA_BLOCK(){
7878
QR(state, 0b100, 0b101, 0b1010, 0b1111)
7979
}
8080

81-
ch_buf[0b1] = BAND( ADD(state[0b1], CH_CONST<0b0>), MASK32 )
82-
ch_buf[0b10] = BAND( ADD(state[0b10], CH_CONST<0b1>), MASK32 )
83-
ch_buf[0b11] = BAND( ADD(state[0b11], CH_CONST<0b10>), MASK32 )
84-
ch_buf[0b100] = BAND( ADD(state[0b100], CH_CONST<0b11>), MASK32 )
85-
ch_buf[0b101] = BAND( ADD(state[0b101], k[0b1]), MASK32 )
86-
ch_buf[0b110] = BAND( ADD(state[0b110], k[0b10]), MASK32 )
87-
ch_buf[0b111] = BAND( ADD(state[0b111], k[0b11]), MASK32 )
88-
ch_buf[0b1000] = BAND( ADD(state[0b1000], k[0b100]), MASK32 )
89-
ch_buf[0b1001] = BAND( ADD(state[0b1001], k[0b101]), MASK32 )
90-
ch_buf[0b1010] = BAND( ADD(state[0b1010], k[0b110]), MASK32 )
91-
ch_buf[0b1011] = BAND( ADD(state[0b1011], k[0b111]), MASK32 )
92-
ch_buf[0b1100] = BAND( ADD(state[0b1100], k[0b1000]), MASK32 )
93-
ch_buf[0b1101] = BAND( ADD(state[0b1101], ch_counter), MASK32 )
94-
ch_buf[0b1110] = BAND( ADD(state[0b1110], n[0b1]), MASK32 )
95-
ch_buf[0b1111] = BAND( ADD(state[0b1111], n[0b10]), MASK32 )
96-
ch_buf[0b10000] = BAND( ADD(state[0b10000], n[0b11]), MASK32 )
81+
ch_buf[0b1] = BAND( +(state[0b1], CH_CONST<0b0>), MASK32 )
82+
ch_buf[0b10] = BAND( +(state[0b10], CH_CONST<0b1>), MASK32 )
83+
ch_buf[0b11] = BAND( +(state[0b11], CH_CONST<0b10>), MASK32 )
84+
ch_buf[0b100] = BAND( +(state[0b100], CH_CONST<0b11>), MASK32 )
85+
ch_buf[0b101] = BAND( +(state[0b101], k[0b1]), MASK32 )
86+
ch_buf[0b110] = BAND( +(state[0b110], k[0b10]), MASK32 )
87+
ch_buf[0b111] = BAND( +(state[0b111], k[0b11]), MASK32 )
88+
ch_buf[0b1000] = BAND( +(state[0b1000], k[0b100]), MASK32 )
89+
ch_buf[0b1001] = BAND( +(state[0b1001], k[0b101]), MASK32 )
90+
ch_buf[0b1010] = BAND( +(state[0b1010], k[0b110]), MASK32 )
91+
ch_buf[0b1011] = BAND( +(state[0b1011], k[0b111]), MASK32 )
92+
ch_buf[0b1100] = BAND( +(state[0b1100], k[0b1000]), MASK32 )
93+
ch_buf[0b1101] = BAND( +(state[0b1101], ch_counter), MASK32 )
94+
ch_buf[0b1110] = BAND( +(state[0b1110], n[0b1]), MASK32 )
95+
ch_buf[0b1111] = BAND( +(state[0b1111], n[0b10]), MASK32 )
96+
ch_buf[0b10000] = BAND( +(state[0b10000], n[0b11]), MASK32 )
9797

9898
RETURN(0b0)
9999
}
100100

101101
FUNC INT REFILL_BUF(){
102102
CHACHA_BLOCK()
103103
ch_buf_pos = 0b0
104-
ch_counter = BAND( ADD(ch_counter, 0b1), MASK32 )
104+
ch_counter = BAND( +(ch_counter, 0b1), MASK32 )
105105
RETURN(0b0)
106106
}
107107

108108
FUNC INT DERIVE_KEY_AND_NONCE(INT seed){
109109
INT s = BAND(seed, MASK32)
110110
FOR(i, 0b1000){ ! 8 key words (1000 == 8)
111-
s = BAND( ADD( MUL(s, ^
111+
s = BAND( +( *(s, ^
112112
0b01000001110001100100111001101101), ^
113113
0b00000000000000000011000000111001 ), ^
114114
MASK32 ^
115115
)
116116
ch_key[i] = s
117117
}
118118
FOR(j, 0b11){ ! 3 nonce words (11 == 3)
119-
s = BAND( ADD( MUL(s, ^
119+
s = BAND( +( *(s, ^
120120
0b01000001110001100100111001101101), ^
121121
0b00000000000000000011000000111001 ), ^
122122
MASK32 ^
@@ -138,8 +138,8 @@ FUNC INT NEXT(){
138138
IF( GTE(ch_buf_pos, TLEN(ch_buf, 0b1)) ){ ! buffer length
139139
REFILL_BUF()
140140
}
141-
INT v = ch_buf[ ADD(ch_buf_pos, 0b1) ]
142-
ch_buf_pos = ADD(ch_buf_pos, 0b1)
141+
INT v = ch_buf[ +(ch_buf_pos, 0b1) ]
142+
ch_buf_pos = +(ch_buf_pos, 0b1)
143143
RETURN(v)
144144
}
145145

@@ -150,9 +150,9 @@ FUNC INT RANGE(INT max){
150150

151151
FUNC INT RANGE_MIN_MAX(INT min, INT max){
152152
ASSERT( LTE(min, max) )
153-
INT range = SUB(max, min)
153+
INT range = -(max, min)
154154
IF( EQ(range, 0b0) ){ RETURN(min) }
155155
ASSERT( GT(range, 0b0) )
156156
INT offset = RANGE(range)
157-
RETURN( ADD(offset, min) )
157+
RETURN( +(offset, min) )
158158
}

lib/std/diff.pre

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FUNC STR UNIFIED(STR mod, STR src){
3131
out = _append_line(out, JOIN("+", right))
3232
}
3333
}
34-
i = ADD(i, 0d1)
34+
i = +(i, 0d1)
3535
}
3636
RETURN(out)
3737
}
@@ -61,7 +61,7 @@ FUNC STR SIDE_BY_SIDE(STR mod, STR src){
6161
IF( NEQ(left, right)){ marker = "|" }
6262
STR line = JOIN(left, " ", marker, " ", right)
6363
out = _append_line(out, line)
64-
i = ADD(i, 0d1)
64+
i = +(i, 0d1)
6565
}
6666
RETURN(out)
6767
}

lib/std/image/init.pre

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ FUNC TNS FLIP_H(TNS img){
8080
}
8181

8282
FUNC TNS INVERT(TNS img){
83-
TNS return = MSUB(TNS(SHAPE(img), 0xFF), img)
83+
TNS return = M-(TNS(SHAPE(img), 0xFF), img)
8484
return[# , # , 0d4] = img[# , # , 0d4] ! Preserve alpha
8585
POP(return)
8686
}
8787

8888
FUNC TNS RECT(TNS img, INT x, INT y, INT width, INT height, TNS color, INT fill, INT thickness){
8989
TNS pts = [ ^
9090
[x, y], ^
91-
[ADD(x, SUB(width, 0d1)), y], ^
92-
[ADD(x, SUB(width, 0d1)), ADD(y, SUB(height, 0d1))], ^
93-
[x, ADD(y, SUB(height, 0d1))], ^
91+
[+(x, -(width, 0d1)), y], ^
92+
[+(x, -(width, 0d1)), +(y, -(height, 0d1))], ^
93+
[x, +(y, -(height, 0d1))], ^
9494
[x, y] ^
9595
]
9696
RETURN(POLYGON(img, pts, color, fill, thickness))

lib/std/prime.pre

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,40 @@ FUNC BOOL IS_PRIME(INT n){
1212
RETURN(FALSE)
1313
}
1414
INT i = 0d3
15-
WHILE(LTE(MUL(i, i), n)){
15+
WHILE(LTE(*(i, i), n)){
1616
IF(EQ(MOD(n, i), 0d0)){
1717
RETURN(FALSE)
1818
}
19-
ADD(@i, 0d2)
19+
+(@i, 0d2)
2020
}
2121
RETURN(TRUE)
2222
}
2323

2424
FUNC INT NEXT_PRIME(INT start){
25-
INT n = ADD(start, 0d1)
25+
INT n = +(start, 0d1)
2626
WHILE(0d1){
2727
IF(IS_PRIME(n)){
2828
RETURN(n)
2929
}
30-
ADD(@n, 0d1)
30+
+(@n, 0d1)
3131
}
3232
}
3333

3434
FUNC INT PREV_PRIME(INT start){
35-
INT n = SUB(start, 0d1)
35+
INT n = -(start, 0d1)
3636
WHILE(GT(n, 0d1)){
3737
IF(IS_PRIME(n)){
3838
RETURN(n)
3939
}
40-
SUB(@n, 0d1)
40+
-(@n, 0d1)
4141
}
4242
RETURN(0d0)
4343
}
4444

4545
FUNC BOOL IS_MERSENNE_PRIME(INT p){
4646
IF(IS_PRIME(p)){
4747
INT exp = POW(0d2, p)
48-
INT mersenne = SUB(exp, 0d1)
48+
INT mersenne = -(exp, 0d1)
4949
IF(IS_PRIME(mersenne)){
5050
RETURN(TRUE)
5151
}
@@ -63,15 +63,15 @@ FUNC TNS FACTOR(INT n){
6363
INT p = 0d2
6464
INT coll_len = 0d0
6565
TNS coll = [0d0] ! placeholder, real shape tracked by coll_len
66-
WHILE(LTE(MUL(p, p), n)){
66+
WHILE(LTE(*(p, p), n)){
6767
IF(EQ(MOD(n, p), 0d0)){
6868
IF(EQ(coll_len, 0d0)){
6969
TNS first = [p]
7070
coll = first
7171
coll_len = 0d1
7272
} ELSE {
7373
INT old_len = TLEN(coll, 0d1)
74-
INT new_len = ADD(old_len, 0d1)
74+
INT new_len = +(old_len, 0d1)
7575
TNS new_coll = TNS([new_len], 0d0)
7676
FOR(i, old_len){
7777
new_coll[i] = coll[i]
@@ -80,9 +80,9 @@ FUNC TNS FACTOR(INT n){
8080
coll = new_coll
8181
coll_len = new_len
8282
}
83-
DIV(@n, p)
83+
/(@n, p)
8484
} ELSE {
85-
p = NEXT_PRIME( ADD(p, 0d1) )
85+
p = NEXT_PRIME( +(p, 0d1) )
8686
}
8787
}
8888
IF(GT(n, 0d1)){
@@ -92,7 +92,7 @@ FUNC TNS FACTOR(INT n){
9292
coll_len = 0d1
9393
} ELSE {
9494
INT old_len2 = TLEN(coll, 0d1)
95-
INT new_len2 = ADD(old_len2, 0d1)
95+
INT new_len2 = +(old_len2, 0d1)
9696
TNS new_coll2 = TNS([new_len2], 0d0)
9797
FOR(j, old_len2){
9898
new_coll2[j] = coll[j]

lib/std/prng.pre

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! LCG-based pseudorandom number generator
22

3-
INT MASK32 = SUB( POW(0b10, 0b100000), 0b1 ) ! 2^32 - 1
3+
INT MASK32 = -( POW(0b10, 0b100000), 0b1 ) ! 2^32 - 1
44

55
! LCG constants: state = (A * state + C) mod 2^32
66
INT LCG_A = 0b000110010110011000001101 ! 1664525
@@ -13,7 +13,7 @@ FUNC INT SEED(INT seed){
1313
}
1414

1515
FUNC INT NEXT(){
16-
lcg_state = BAND( ADD( MUL(LCG_A, lcg_state), LCG_C ), MASK32 )
16+
lcg_state = BAND( +( *(LCG_A, lcg_state), LCG_C ), MASK32 )
1717
RETURN(lcg_state)
1818
}
1919

@@ -24,9 +24,9 @@ FUNC INT RANGE(INT max){
2424

2525
FUNC INT RANGE_MIN_MAX(INT min, INT max){
2626
ASSERT( LTE(min, max) )
27-
INT range = SUB(max, min)
27+
INT range = -(max, min)
2828
IF( EQ(range, 0b0) ){ RETURN(min) }
2929
ASSERT( GT(range, 0b0) )
3030
INT offset = RANGE(range)
31-
RETURN( ADD(offset, min) )
31+
RETURN( +(offset, min) )
3232
}

0 commit comments

Comments
 (0)