mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Change syntax for matrices to matrix[R, C]T
This commit is contained in:
+2
-3
@@ -1954,9 +1954,8 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case runtime.Type_Info_Matrix:
|
case runtime.Type_Info_Matrix:
|
||||||
reflect.write_type(fi.writer, type_info_of(v.id))
|
io.write_string(fi.writer, "matrix[")
|
||||||
io.write_byte(fi.writer, '{')
|
defer io.write_byte(fi.writer, ']')
|
||||||
defer io.write_byte(fi.writer, '}')
|
|
||||||
|
|
||||||
fi.indent += 1; defer fi.indent -= 1
|
fi.indent += 1; defer fi.indent -= 1
|
||||||
|
|
||||||
|
|||||||
@@ -592,9 +592,9 @@ write_type_writer :: proc(w: io.Writer, ti: ^Type_Info, n_written: ^int = nil) -
|
|||||||
write_type(w, info.slice, &n) or_return
|
write_type(w, info.slice, &n) or_return
|
||||||
|
|
||||||
case Type_Info_Matrix:
|
case Type_Info_Matrix:
|
||||||
io.write_string(w, "[", &n) or_return
|
io.write_string(w, "matrix[", &n) or_return
|
||||||
io.write_i64(w, i64(info.row_count), 10, &n) or_return
|
io.write_i64(w, i64(info.row_count), 10, &n) or_return
|
||||||
io.write_string(w, "; ", &n) or_return
|
io.write_string(w, ", ", &n) or_return
|
||||||
io.write_i64(w, i64(info.column_count), 10, &n) or_return
|
io.write_i64(w, i64(info.column_count), 10, &n) or_return
|
||||||
io.write_string(w, "]", &n) or_return
|
io.write_string(w, "]", &n) or_return
|
||||||
write_type(w, info.elem, &n) or_return
|
write_type(w, info.elem, &n) or_return
|
||||||
|
|||||||
@@ -372,9 +372,9 @@ print_type :: proc "contextless" (ti: ^Type_Info) {
|
|||||||
print_type(info.slice)
|
print_type(info.slice)
|
||||||
|
|
||||||
case Type_Info_Matrix:
|
case Type_Info_Matrix:
|
||||||
print_string("[")
|
print_string("matrix[")
|
||||||
print_u64(u64(info.row_count))
|
print_u64(u64(info.row_count))
|
||||||
print_string("; ")
|
print_string(", ")
|
||||||
print_u64(u64(info.column_count))
|
print_u64(u64(info.column_count))
|
||||||
print_string("]")
|
print_string("]")
|
||||||
print_type(info.elem)
|
print_type(info.elem)
|
||||||
|
|||||||
+3
-3
@@ -9138,7 +9138,7 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) {
|
|||||||
str = write_expr_to_string(str, mie->expr, shorthand);
|
str = write_expr_to_string(str, mie->expr, shorthand);
|
||||||
str = gb_string_append_rune(str, '[');
|
str = gb_string_append_rune(str, '[');
|
||||||
str = write_expr_to_string(str, mie->row_index, shorthand);
|
str = write_expr_to_string(str, mie->row_index, shorthand);
|
||||||
str = gb_string_appendc(str, "; ");
|
str = gb_string_appendc(str, ", ");
|
||||||
str = write_expr_to_string(str, mie->column_index, shorthand);
|
str = write_expr_to_string(str, mie->column_index, shorthand);
|
||||||
str = gb_string_append_rune(str, ']');
|
str = gb_string_append_rune(str, ']');
|
||||||
case_end;
|
case_end;
|
||||||
@@ -9216,9 +9216,9 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) {
|
|||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(mt, MatrixType, node);
|
case_ast_node(mt, MatrixType, node);
|
||||||
str = gb_string_append_rune(str, '[');
|
str = gb_string_appendc(str, "matrix[");
|
||||||
str = write_expr_to_string(str, mt->row_count, shorthand);
|
str = write_expr_to_string(str, mt->row_count, shorthand);
|
||||||
str = gb_string_appendc(str, "; ");
|
str = gb_string_appendc(str, ", ");
|
||||||
str = write_expr_to_string(str, mt->column_count, shorthand);
|
str = write_expr_to_string(str, mt->column_count, shorthand);
|
||||||
str = gb_string_append_rune(str, ']');
|
str = gb_string_append_rune(str, ']');
|
||||||
str = write_expr_to_string(str, mt->elem, shorthand);
|
str = write_expr_to_string(str, mt->elem, shorthand);
|
||||||
|
|||||||
+19
-18
@@ -2241,18 +2241,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
count_expr = parse_expr(f, false);
|
count_expr = parse_expr(f, false);
|
||||||
f->expr_level--;
|
f->expr_level--;
|
||||||
}
|
}
|
||||||
if (allow_token(f, Token_Semicolon)) {
|
|
||||||
Ast *row_count = count_expr;
|
|
||||||
Ast *column_count = nullptr;
|
|
||||||
|
|
||||||
f->expr_level++;
|
|
||||||
column_count = parse_expr(f, false);
|
|
||||||
f->expr_level--;
|
|
||||||
|
|
||||||
expect_token(f, Token_CloseBracket);
|
|
||||||
|
|
||||||
return ast_matrix_type(f, token, row_count, column_count, parse_type(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
expect_token(f, Token_CloseBracket);
|
expect_token(f, Token_CloseBracket);
|
||||||
return ast_array_type(f, token, count_expr, parse_type(f));
|
return ast_array_type(f, token, count_expr, parse_type(f));
|
||||||
@@ -2271,6 +2259,23 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
|
|
||||||
return ast_map_type(f, token, key, value);
|
return ast_map_type(f, token, key, value);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Token_matrix: {
|
||||||
|
Token token = expect_token(f, Token_matrix);
|
||||||
|
Ast *row_count = nullptr;
|
||||||
|
Ast *column_count = nullptr;
|
||||||
|
Ast *type = nullptr;
|
||||||
|
Token open, close;
|
||||||
|
|
||||||
|
open = expect_token_after(f, Token_OpenBracket, "matrix");
|
||||||
|
row_count = parse_expr(f, true);
|
||||||
|
expect_token(f, Token_Comma);
|
||||||
|
column_count = parse_expr(f, true);
|
||||||
|
close = expect_token(f, Token_CloseBracket);
|
||||||
|
type = parse_type(f);
|
||||||
|
|
||||||
|
return ast_matrix_type(f, token, row_count, column_count, type);
|
||||||
|
} break;
|
||||||
|
|
||||||
case Token_struct: {
|
case Token_struct: {
|
||||||
Token token = expect_token(f, Token_struct);
|
Token token = expect_token(f, Token_struct);
|
||||||
@@ -2716,11 +2721,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
|
|||||||
case Token_RangeHalf:
|
case Token_RangeHalf:
|
||||||
syntax_error(f->curr_token, "Expected a colon, not a range");
|
syntax_error(f->curr_token, "Expected a colon, not a range");
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case Token_Semicolon: // matrix index
|
case Token_Comma: // matrix index
|
||||||
if (f->curr_token.kind == Token_Semicolon && f->curr_token.string == "\n") {
|
|
||||||
syntax_error(f->curr_token, "Expected a ';', not a newline");
|
|
||||||
}
|
|
||||||
/* fallthrough */
|
|
||||||
case Token_Colon:
|
case Token_Colon:
|
||||||
interval = advance_token(f);
|
interval = advance_token(f);
|
||||||
is_interval = true;
|
is_interval = true;
|
||||||
@@ -2736,7 +2737,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
|
|||||||
close = expect_token(f, Token_CloseBracket);
|
close = expect_token(f, Token_CloseBracket);
|
||||||
|
|
||||||
if (is_interval) {
|
if (is_interval) {
|
||||||
if (interval.kind == Token_Semicolon) {
|
if (interval.kind == Token_Comma) {
|
||||||
if (indices[0] == nullptr || indices[1] == nullptr) {
|
if (indices[0] == nullptr || indices[1] == nullptr) {
|
||||||
syntax_error(open, "Matrix index expressions require both row and column indices");
|
syntax_error(open, "Matrix index expressions require both row and column indices");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ TOKEN_KIND(Token__KeywordBegin, ""), \
|
|||||||
TOKEN_KIND(Token_or_else, "or_else"), \
|
TOKEN_KIND(Token_or_else, "or_else"), \
|
||||||
TOKEN_KIND(Token_or_return, "or_return"), \
|
TOKEN_KIND(Token_or_return, "or_return"), \
|
||||||
TOKEN_KIND(Token_asm, "asm"), \
|
TOKEN_KIND(Token_asm, "asm"), \
|
||||||
|
TOKEN_KIND(Token_matrix, "matrix"), \
|
||||||
TOKEN_KIND(Token__KeywordEnd, ""), \
|
TOKEN_KIND(Token__KeywordEnd, ""), \
|
||||||
TOKEN_KIND(Token_Count, "")
|
TOKEN_KIND(Token_Count, "")
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -3956,9 +3956,7 @@ gbString write_type_to_string(gbString str, Type *type) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_Matrix:
|
case Type_Matrix:
|
||||||
str = gb_string_appendc(str, gb_bprintf("[%d", cast(int)type->Matrix.row_count));
|
str = gb_string_appendc(str, gb_bprintf("matrix[%d, %d]", cast(int)type->Matrix.row_count, cast(int)type->Matrix.column_count));
|
||||||
str = gb_string_appendc(str, "; ");
|
|
||||||
str = gb_string_appendc(str, gb_bprintf("%d]", cast(int)type->Matrix.column_count));
|
|
||||||
str = write_type_to_string(str, type->Matrix.elem);
|
str = write_type_to_string(str, type->Matrix.elem);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user