Skip to content

Commit 2ee2ac9

Browse files
Update tests for new annotation form, fix bug introduced in 24f85e8.
1 parent 24f85e8 commit 2ee2ac9

537 files changed

Lines changed: 1598 additions & 1521 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.

lib/std/csprng.pre

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

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

55
! ChaCha20 constants ("expand 32-byte k")
6-
MAP: CH_CONST = < ^
6+
MAP CH_CONST = < ^
77
0b0 = 0b01100001011100000111000001100101, ^
88
0b1 = 0b00110011001000000110010001101110, ^
99
0b10 = 0b01111001011000100010110100110010, ^
1010
0b11 = 0b01101011001000000110010101110100 ^
1111
>
1212

13-
TNS: ch_key = TNS([0b1000], 0b0) ! 8 words
14-
TNS: ch_nonce = [0b0, 0b0, 0b0] ! use literals for short TNS
15-
INT: ch_counter = 0
16-
TNS: ch_buf = TNS([0b10000], 0b0) ! 16 words
17-
INT: ch_buf_pos = TLEN(ch_buf, 0b1) ! set to buffer length to force refill
13+
TNS ch_key = TNS([0b1000], 0b0) ! 8 words
14+
TNS ch_nonce = [0b0, 0b0, 0b0] ! use literals for short TNS
15+
INT ch_counter = 0
16+
TNS ch_buf = TNS([0b10000], 0b0) ! 16 words
17+
INT ch_buf_pos = TLEN(ch_buf, 0b1) ! set to buffer length to force refill
1818

19-
FUNC INT: ROTL32(INT: x, INT: n){
20-
INT: x32 = BAND(x, MASK32)
21-
INT: left = BAND(SHL(x32, n), MASK32)
22-
INT: right = SHR(x32, SUB(0b100000, n)) ! 32 - n
19+
FUNC INT ROTL32(INT x, INT n){
20+
INT x32 = BAND(x, MASK32)
21+
INT left = BAND(SHL(x32, n), MASK32)
22+
INT right = SHR(x32, SUB(0b100000, n)) ! 32 - n
2323
RETURN( BAND(BOR(left, right), MASK32) )
2424
}
2525

26-
FUNC INT: QR(TNS: s, INT: ia, INT: ib, INT: ic, INT: id){
27-
INT: a = s[ia]
28-
INT: b = s[ib]
29-
INT: c = s[ic]
30-
INT: d = s[id]
26+
FUNC INT QR(TNS s, INT ia, INT ib, INT ic, INT id){
27+
INT a = s[ia]
28+
INT b = s[ib]
29+
INT c = s[ic]
30+
INT d = s[id]
3131

3232
a = BAND( ADD(a, b), MASK32 )
3333
d = ROTL32( BXOR(d, a), 0b10000 ) ! 16
@@ -45,10 +45,10 @@ FUNC INT: QR(TNS: s, INT: ia, INT: ib, INT: ic, INT: id){
4545
RETURN(0)
4646
}
4747

48-
FUNC INT: CHACHA_BLOCK(){
49-
TNS: k = ch_key
50-
TNS: n = ch_nonce
51-
TNS: state = [ ^
48+
FUNC INT CHACHA_BLOCK(){
49+
TNS k = ch_key
50+
TNS n = ch_nonce
51+
TNS state = [ ^
5252
CH_CONST<0b0>, ^
5353
CH_CONST<0b1>, ^
5454
CH_CONST<0b10>, ^
@@ -98,15 +98,15 @@ FUNC INT: CHACHA_BLOCK(){
9898
RETURN(0b0)
9999
}
100100

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

108-
FUNC INT: DERIVE_KEY_AND_NONCE(INT: seed){
109-
INT: s = BAND(seed, MASK32)
108+
FUNC INT DERIVE_KEY_AND_NONCE(INT seed){
109+
INT s = BAND(seed, MASK32)
110110
FOR(i, 0b1000){ ! 8 key words (1000 == 8)
111111
s = BAND( ADD( MUL(s, ^
112112
0b01000001110001100100111001101101), ^
@@ -126,33 +126,33 @@ FUNC INT: DERIVE_KEY_AND_NONCE(INT: seed){
126126
RETURN(0b0)
127127
}
128128

129-
FUNC INT: SEED(INT: seed){
129+
FUNC INT SEED(INT seed){
130130
DERIVE_KEY_AND_NONCE(seed)
131131
ch_counter = 0b0
132132
ch_buf = TNS([0b10000], 0b0)
133133
ch_buf_pos = TLEN(ch_buf, 0b1) ! set to buffer length to force refill
134134
RETURN(ch_counter)
135135
}
136136

137-
FUNC INT: NEXT(){
137+
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) ]
141+
INT v = ch_buf[ ADD(ch_buf_pos, 0b1) ]
142142
ch_buf_pos = ADD(ch_buf_pos, 0b1)
143143
RETURN(v)
144144
}
145145

146-
FUNC INT: RANGE(INT: max){
146+
FUNC INT RANGE(INT max){
147147
ASSERT( GT(max, 0b0) )
148148
RETURN( MOD(NEXT(), max) )
149149
}
150150

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

lib/std/diff.pre

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
! diff utilities for Prefix
22

3-
FUNC STR: _append_line(STR: acc, STR: line){
3+
FUNC STR _append_line(STR acc, STR line){
44
IF( EQ(acc, "") ){ RETURN(line) } ELSE { RETURN( JOIN(acc, "\n", line) ) }
55
}
66

7-
FUNC STR: UNIFIED(STR: mod, STR: src){
8-
TNS: a = SPLIT(mod, "\n")
9-
TNS: b = SPLIT(src, "\n")
10-
INT: la = TLEN(a, 0d1)
11-
INT: lb = TLEN(b, 0d1)
12-
INT: n = MAX(la, lb)
13-
STR: out = ""
14-
INT: i = 0d1
7+
FUNC STR UNIFIED(STR mod, STR src){
8+
TNS a = SPLIT(mod, "\n")
9+
TNS b = SPLIT(src, "\n")
10+
INT la = TLEN(a, 0d1)
11+
INT lb = TLEN(b, 0d1)
12+
INT n = MAX(la, lb)
13+
STR out = ""
14+
INT i = 0d1
1515
WHILE( LTE(i, n) ){
16-
STR: left = ""
16+
STR left = ""
1717
IF( LTE(i, la) ){ left = a[i] }
18-
STR: right = ""
18+
STR right = ""
1919
IF( LTE(i, lb) ){ right = b[i] }
2020

2121
IF( EQ(left, right) ){
2222
IF( NEQ(left, "")){
23-
STR: line = JOIN(" ", left)
23+
STR line = JOIN(" ", left)
2424
out = _append_line(out, line)
2525
}
2626
} ELSE {
@@ -36,30 +36,30 @@ FUNC STR: UNIFIED(STR: mod, STR: src){
3636
RETURN(out)
3737
}
3838

39-
FUNC STR: CONTEXT(STR: mod, STR: src){
39+
FUNC STR CONTEXT(STR mod, STR src){
4040
! For simplicity, use the same output as UNIFIED but with a ' ' prefix
41-
STR: u = UNIFIED(mod, src)
41+
STR u = UNIFIED(mod, src)
4242
IF( EQ(u, "") ){ RETURN("") }
4343
! Prepend a simple header to resemble context diff
4444
RETURN( JOIN("*** a", "\n", u) )
4545
}
4646

47-
FUNC STR: SIDE_BY_SIDE(STR: mod, STR: src){
48-
TNS: a = SPLIT(mod, "\n")
49-
TNS: b = SPLIT(src, "\n")
50-
INT: la = TLEN(a, 0d1)
51-
INT: lb = TLEN(b, 0d1)
52-
INT: n = MAX(la, lb)
53-
STR: out = ""
54-
INT: i = 0d1
47+
FUNC STR SIDE_BY_SIDE(STR mod, STR src){
48+
TNS a = SPLIT(mod, "\n")
49+
TNS b = SPLIT(src, "\n")
50+
INT la = TLEN(a, 0d1)
51+
INT lb = TLEN(b, 0d1)
52+
INT n = MAX(la, lb)
53+
STR out = ""
54+
INT i = 0d1
5555
WHILE( LTE(i, n) ){
56-
STR: left = ""
56+
STR left = ""
5757
IF( LTE(i, la) ){ left = a[i] }
58-
STR: right = ""
58+
STR right = ""
5959
IF( LTE(i, lb) ){ right = b[i] }
60-
STR: marker = " "
60+
STR marker = " "
6161
IF( NEQ(left, right)){ marker = "|" }
62-
STR: line = JOIN(left, " ", marker, " ", right)
62+
STR line = JOIN(left, " ", marker, " ", right)
6363
out = _append_line(out, line)
6464
i = ADD(i, 0d1)
6565
}

lib/std/gui/init.pre

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
EXTEND(EXTENSION: gui)
44

5-
FUNC INT: SCREEN_WIDTH(){
5+
FUNC INT SCREEN_WIDTH(){
66
RETURN(SCREEN()[0d1])
77
}
88

9-
FUNC INT: SCREEN_HEIGHT(){
9+
FUNC INT SCREEN_HEIGHT(){
1010
RETURN(SCREEN()[0d2])
1111
}
1212

13-
FUNC INT: WINDOW_WIDTH(INT: handle){
13+
FUNC INT WINDOW_WIDTH(INT handle){
1414
RETURN(WINDOW(handle)[0d1])
1515
}
1616

17-
FUNC INT: WINDOW_HEIGHT(INT: handle){
17+
FUNC INT WINDOW_HEIGHT(INT handle){
1818
RETURN(WINDOW(handle)[0d2])
1919
}

lib/std/image/init.pre

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ EXTEND(EXTENSION: image)
1010

1111
IMPORT(path)
1212

13-
FUNC TNS: LOAD(STR: img_path){
14-
STR: ext = path.EXTNAME(img_path)
13+
FUNC TNS LOAD(STR img_path){
14+
STR ext = path.EXTNAME(img_path)
1515
IF(EQ(ext, "png")){
1616
RETURN(LOAD_PNG(img_path))
1717
} ELSEIF (OR(EQ(ext, "jpg"),EQ(ext, "jpeg"))){
@@ -23,70 +23,70 @@ FUNC TNS: LOAD(STR: img_path){
2323
}
2424
}
2525

26-
FUNC INT: WIDTH(TNS: img){
26+
FUNC INT WIDTH(TNS img){
2727
RETURN(TLEN(img, 0d1))
2828
}
2929

30-
FUNC INT: HEIGHT(TNS: img){
30+
FUNC INT HEIGHT(TNS img){
3131
RETURN(TLEN(img, 0d2))
3232
}
3333

34-
FUNC INT: CHANNELS(TNS: img){
34+
FUNC INT CHANNELS(TNS img){
3535
RETURN(TLEN(img, 0d3))
3636
}
3737

38-
FUNC TNS: R(TNS: img){
38+
FUNC TNS R(TNS img){
3939
RETURN(img[*, *, 0d1])
4040
}
4141

42-
FUNC TNS: G(TNS: img){
42+
FUNC TNS G(TNS img){
4343
RETURN(img[*, *, 0d2])
4444
}
4545

46-
FUNC TNS: B(TNS: img){
46+
FUNC TNS B(TNS img){
4747
RETURN(img[*, *, 0d3])
4848
}
4949

50-
FUNC TNS: A(TNS: img){
50+
FUNC TNS A(TNS img){
5151
RETURN(img[*, *, 0d4])
5252
}
5353

54-
FUNC TNS: PIXEL(TNS: img, INT: x, INT: y){
54+
FUNC TNS PIXEL(TNS img, INT x, INT y){
5555
RETURN(img[x, y, *])
5656
}
5757

58-
FUNC INT: PIXEL_R(TNS: img, INT: x, INT: y){
58+
FUNC INT PIXEL_R(TNS img, INT x, INT y){
5959
RETURN(img[x, y, 0d1])
6060
}
6161

62-
FUNC INT: PIXEL_G(TNS: img, INT: x, INT: y){
62+
FUNC INT PIXEL_G(TNS img, INT x, INT y){
6363
RETURN(img[x, y, 0d2])
6464
}
6565

66-
FUNC INT: PIXEL_B(TNS: img, INT: x, INT: y){
66+
FUNC INT PIXEL_B(TNS img, INT x, INT y){
6767
RETURN(img[x, y, 0d3])
6868
}
6969

70-
FUNC INT: PIXEL_A(TNS: img, INT: x, INT: y){
70+
FUNC INT PIXEL_A(TNS img, INT x, INT y){
7171
RETURN(img[x, y, 0d4])
7272
}
7373

74-
FUNC TNS: FLIP_V(TNS: img){
74+
FUNC TNS FLIP_V(TNS img){
7575
RETURN(TFLIP(img, 0d1))
7676
}
7777

78-
FUNC TNS: FLIP_H(TNS: img){
78+
FUNC TNS FLIP_H(TNS img){
7979
RETURN(TFLIP(img, 0d2))
8080
}
8181

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

88-
FUNC TNS: RECT(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color, INT: fill, INT: thickness){
89-
TNS: pts = [ ^
88+
FUNC TNS RECT(TNS img, INT x, INT y, INT width, INT height, TNS color, INT fill, INT thickness){
89+
TNS pts = [ ^
9090
[x, y], ^
9191
[ADD(x, SUB(width, 0d1)), y], ^
9292
[ADD(x, SUB(width, 0d1)), ADD(y, SUB(height, 0d1))], ^
@@ -96,37 +96,37 @@ FUNC TNS: RECT(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color, IN
9696
RETURN(POLYGON(img, pts, color, fill, thickness))
9797
}
9898

99-
FUNC TNS: RECTANGLE(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color, INT: fill, INT: thickness){
99+
FUNC TNS RECTANGLE(TNS img, INT x, INT y, INT width, INT height, TNS color, INT fill, INT thickness){
100100
RETURN(RECT(img, x, y, width, height, color, fill, thickness))
101101
}
102102

103-
FUNC TNS: FILL_RECT(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color){
103+
FUNC TNS FILL_RECT(TNS img, INT x, INT y, INT width, INT height, TNS color){
104104
RETURN(RECT(img, x, y, width, height, color, 0d1, 0d1))
105105
}
106106

107-
FUNC TNS: FILL_ELLIPSE(TNS: img, TNS: center, INT: rx, INT: ry, TNS: color){
107+
FUNC TNS FILL_ELLIPSE(TNS img, TNS center, INT rx, INT ry, TNS color){
108108
RETURN(ELLIPSE(img, center, rx, ry, color, 0d1, 0d1))
109109
}
110110

111-
FUNC TNS: SQUARE(TNS: img, INT: x, INT: y, INT: size, TNS: color, INT: fill, INT: thickness){
111+
FUNC TNS SQUARE(TNS img, INT x, INT y, INT size, TNS color, INT fill, INT thickness){
112112
RETURN(RECT(img, x, y, size, size, color, fill, thickness))
113113
}
114114

115-
FUNC TNS: CIRCLE(TNS: img, TNS: center, INT: radius, TNS: color, INT: fill, INT: thickness){
115+
FUNC TNS CIRCLE(TNS img, TNS center, INT radius, TNS color, INT fill, INT thickness){
116116
RETURN(ELLIPSE(img, center, radius, radius, color, fill, thickness))
117117
}
118118

119-
FUNC TNS: CROP(TNS: img, TNS: corners){
119+
FUNC TNS CROP(TNS img, TNS corners){
120120
IF(NEQ(SHAPE(corners), [0d4, 0d2])){
121121
THROW("CROP corners must be a 0d4 by 0d2 tensor: [[tl_x, tl_y], [tr_x, tr_y], [bl_x, bl_y], [br_x, br_y]]")
122122
}
123123
RETURN(img[MIN(corners[*, 0d1])-MAX(corners[*, 0d1]), MIN(corners[*, 0d2])-MAX(corners[*, 0d2]), *])
124124
}
125125

126-
FUNC BOOL: SHOW(TNS: img){
126+
FUNC BOOL SHOW(TNS img){
127127
! Save the image to the provided path and open it with the system default
128128
! viewer on Windows. `img_path` is treated as the target file path.
129-
STR: img_path = "C:/Windows/Temp/tmp_img.png"
129+
STR img_path = "C:/Windows/Temp/tmp_img.png"
130130
SAVE_PNG(img, img_path, 0d0)
131131
! ShellExecuteW(hwnd, operation, file, params, dir, showcmd)
132132
! Use NULL hwnd (0), operation "open", empty params and dir, showcmd=1

0 commit comments

Comments
 (0)