Skip to content

Commit 4e0bc12

Browse files
gh-184: Replace * with # in wildcard slices.
1 parent 4595ee2 commit 4e0bc12

10 files changed

Lines changed: 22 additions & 22 deletions

File tree

docs/SPECIFICATION.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
Indexed assignment to a map MUST use the same form as ordinary map access, such as `map<k1, k2> = expression`. Intermediate nested maps MUST be created on demand when assigning to deeper keys. Reassigning an existing key to a value of a different static type MUST raise a runtime error.
106106

107-
If a tensor target uses slice indices such as `lo:hi` or `*`, the right-hand side MUST evaluate to a `TNS` whose shape exactly matches the selected slice, and every written element MUST satisfy the target's static type constraints.
107+
If a tensor target uses slice indices such as `lo:hi` or `#`, the right-hand side MUST evaluate to a `TNS` whose shape exactly matches the selected slice, and every written element MUST satisfy the target's static type constraints.
108108

109109
---
110110

@@ -328,7 +328,7 @@
328328
329329
`TNS` indexing MUST use square brackets (`[` and `]`) with a comma-separated list of indices. Indexing MUST be one-based. Negative indices MUST count backwards from the end of the dimension.
330330
331-
Slice indexing MUST be supported in any index position using a range of the form `lo:hi`. The selected slice MUST be inclusive of both endpoints. The symbol `*` MAY be used in an index position to denote a full-dimension slice, selecting every element along that axis.
331+
Slice indexing MUST be supported in any index position using a range of the form `lo:hi`. The selected slice MUST be inclusive of both endpoints. The symbol `#` MAY be used in an index position to denote a full-dimension slice, selecting every element along that axis.
332332
333333
---
334334

lib/std/image/init.pre

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ FUNC INT CHANNELS(TNS img){
3636
}
3737

3838
FUNC TNS R(TNS img){
39-
RETURN(img[*, *, 0d1])
39+
RETURN(img[# , # , 0d1])
4040
}
4141

4242
FUNC TNS G(TNS img){
43-
RETURN(img[*, *, 0d2])
43+
RETURN(img[# , # , 0d2])
4444
}
4545

4646
FUNC TNS B(TNS img){
47-
RETURN(img[*, *, 0d3])
47+
RETURN(img[# , # , 0d3])
4848
}
4949

5050
FUNC TNS A(TNS img){
51-
RETURN(img[*, *, 0d4])
51+
RETURN(img[# , # , 0d4])
5252
}
5353

5454
FUNC TNS PIXEL(TNS img, INT x, INT y){
55-
RETURN(img[x, y, *])
55+
RETURN(img[x, y, #])
5656
}
5757

5858
FUNC INT PIXEL_R(TNS img, INT x, INT y){
@@ -81,7 +81,7 @@ FUNC TNS FLIP_H(TNS img){
8181

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

@@ -120,7 +120,7 @@ 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
}
123-
RETURN(img[MIN(corners[*, 0d1]):MAX(corners[*, 0d1]), MIN(corners[*, 0d2]):MAX(corners[*, 0d2]), *])
123+
RETURN(img[MIN(corners[# , 0d1]):MAX(corners[# , 0d1]), MIN(corners[# , 0d2]):MAX(corners[# , 0d2]), #])
124124
}
125125

126126
FUNC BOOL SHOW(TNS img){

src/lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Token lexer_next_token(Lexer* lexer) {
262262
if (c == ':') { advance(lexer); return make_token(lexer, TOKEN_COLON, ":", 1); }
263263
if (c == '@') { advance(lexer); return make_token(lexer, TOKEN_AT, "@", 1); }
264264
if (c == '~') { advance(lexer); return make_token(lexer, TOKEN_TILDE, "~", 1); }
265-
if (c == '*') { advance(lexer); return make_token(lexer, TOKEN_STAR, "*", 1); }
265+
if (c == '#') { advance(lexer); return make_token(lexer, TOKEN_HASH, "#", 1); }
266266
if (c == '.') { advance(lexer); return make_token(lexer, TOKEN_DOT, ".", 1); }
267267

268268
if (c == '"' || c == '\'') {

src/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static Expr* parse_call(Parser* parser) {
711711
}
712712
while (parser->current_token.type != TOKEN_RBRACKET && parser->current_token.type != TOKEN_EOF) {
713713
// wildcard
714-
if (match(parser, TOKEN_STAR)) {
714+
if (match(parser, TOKEN_HASH)) {
715715
Expr* wc = expr_wildcard(parser->previous_token.line, parser->previous_token.column);
716716
expr_list_add(&idx->as.index.indices, wc);
717717
} else {
@@ -958,7 +958,7 @@ static Stmt* parse_statement(Parser* parser) {
958958
return NULL;
959959
}
960960
while (parser->current_token.type != TOKEN_RBRACKET && parser->current_token.type != TOKEN_EOF) {
961-
if (match(parser, TOKEN_STAR)) {
961+
if (match(parser, TOKEN_HASH)) {
962962
Expr* wc = expr_wildcard(parser->previous_token.line, parser->previous_token.column);
963963
expr_list_add(&idx->as.index.indices, wc);
964964
} else {

src/token.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const char* token_type_to_string(PTokenType type) {
2222
case TOKEN_COLON: return "COLON";
2323
case TOKEN_AT: return "AT";
2424
case TOKEN_TILDE: return "TILDE";
25-
case TOKEN_STAR: return "STAR";
25+
case TOKEN_HASH: return "HASH";
2626
case TOKEN_DOT: return "DOT";
2727
case TOKEN_DASH: return "DASH";
2828
case TOKEN_TRY: return "TRY";

src/token.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef enum {
2929
TOKEN_COLON, // :
3030
TOKEN_AT, // @
3131
TOKEN_TILDE, // ~
32-
TOKEN_STAR, // *
32+
TOKEN_HASH, // #
3333
TOKEN_DOT, // .
3434
TOKEN_DASH, // - (reserved; negative numeric literals are part of NUMBER/FLOAT; standalone '-' is a syntax error)
3535

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
TNS matrix = [[0d1, 0d2], [0d3, 0d4]]
2-
ASSIGN(matrix[*, 0d2], [[0d9], [0d10]])
2+
ASSIGN(matrix[# , 0d2], [[0d9], [0d10]])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
TNS matrix = [[0d1, 0d2], [0d3, 0d4]]
2-
ASSIGN(matrix[*, *], [[0d9, 0d10, 0d11], [0d12, 0d13, 0d14]])
2+
ASSIGN(matrix[# , #], [[0d9, 0d10, 0d11], [0d12, 0d13, 0d14]])

tests/cases/passing/tns-indexing.pre

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ ASSERT(EQ(matrix[0d2], [0d3, 0d4]))
1313
ASSERT(EQ(cube[0d2, 0d1], [0d5, 0d6]))
1414
ASSERT(EQ(cube[0d2, 0d2, 0d1], 0d7))
1515
ASSERT(EQ(cube[0d1], [[0d1, 0d2], [0d3, 0d4]]))
16-
ASSERT(EQ(cube[0d1, *], [[0d1, 0d2], [0d3, 0d4]]))
16+
ASSERT(EQ(cube[0d1, #], [[0d1, 0d2], [0d3, 0d4]]))
1717

1818
ASSERT(EQ(vec[0d1:0d2], [0d1, 0d2]))
1919
ASSERT(EQ(vec[0d2:0d2], 0d2))
2020
ASSERT(EQ(vec[0d1:-0d1], [0d1, 0d2, 0d3]))
2121
ASSERT(EQ(vec[0d0:0d4], [0d1, 0d2, 0d3]))
2222

23-
ASSERT(EQ(matrix[*, *], matrix))
24-
ASSERT(EQ(matrix[*, 0d1], [0d1, 0d3]))
25-
ASSERT(EQ(matrix[0d1, *], [0d1, 0d2]))
23+
ASSERT(EQ(matrix[# , #], matrix))
24+
ASSERT(EQ(matrix[# , 0d1], [0d1, 0d3]))
25+
ASSERT(EQ(matrix[0d1, #], [0d1, 0d2]))
2626
ASSERT(EQ(matrix[0d1:0d2, 0d1:0d2], matrix))
2727
ASSERT(EQ(matrix[0d1:-0d1, 0d1], [0d1, 0d3]))
28-
ASSERT(EQ(cube[*, 0d2, 0d1], [0d3, 0d7]))
28+
ASSERT(EQ(cube[# , 0d2, 0d1], [0d3, 0d7]))
2929

3030
INT errors_caught = 0d0
3131

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
TNS matrix = [[0d1, 0d2], [0d3, 0d4]]
22

3-
ASSERT(EQ(ASSIGN(matrix[*, 0d2], [0d9, 0d10]), [0d9, 0d10]))
3+
ASSERT(EQ(ASSIGN(matrix[# , 0d2], [0d9, 0d10]), [0d9, 0d10]))
44
ASSERT(EQ(matrix, [[0d1, 0d9], [0d3, 0d10]]))

0 commit comments

Comments
 (0)