fix interop and indexing oversights

This commit is contained in:
2026-07-01 09:08:58 +02:00
parent 7fe3552c01
commit 870f946b52
15 changed files with 593 additions and 116 deletions
+70 -2
View File
@@ -212,9 +212,15 @@ parse_type_atom :: proc(parser: ^Parser) -> ast.Type_Syntax {
if _, ok := allow(parser, .Underscore); ok {
node.inferred_count = true
} else {
count, ok := parse_type_constant(parser)
if ok {
if (current(parser).kind == .Integer || current(parser).kind == .Character) &&
(peek(parser).kind == .Right_Bracket || peek(parser).kind == .Semicolon) {
count, ok := parse_type_constant(parser)
node.count = count
_ = ok
} else {
expr := parse_expression(parser)
node.count_expr = u32(expr)
node.unresolved_count = true
}
}
if _, ok := allow(parser, .Semicolon); ok {
@@ -585,6 +591,37 @@ parse_integer_magnitude :: proc(text: string) -> (u64, bool) {
parse_primary :: proc(parser: ^Parser, nesting: int) -> ast.Expr_Id {
tok := current(parser)
#partial switch tok.kind {
case .Keyword_I8, .Keyword_I16, .Keyword_I32, .Keyword_I64,
.Keyword_U8, .Keyword_U16, .Keyword_U32, .Keyword_U64,
.Keyword_Isize, .Keyword_Usize, .Keyword_F32, .Keyword_F64,
.Keyword_C_Char, .Keyword_C_Schar, .Keyword_C_Uchar,
.Keyword_C_Short, .Keyword_C_Ushort, .Keyword_C_Int, .Keyword_C_Uint,
.Keyword_C_Long, .Keyword_C_Ulong, .Keyword_C_Longlong, .Keyword_C_Ulonglong,
.Keyword_C_Float, .Keyword_C_Double, .Keyword_C_Longdouble:
start := tok
target := parse_type_atom(parser)
if _, ok := allow(parser, .Left_Paren); !ok {
return invalid_expr(parser, current(parser).span, "expected '(' after scalar cast type")
}
parser.delimiter_depth += 1
skip_newlines(parser)
operand := parse_expression_bp(parser, 0, nesting+1)
skip_newlines(parser)
end := current(parser)
if close, ok := allow(parser, .Right_Paren); ok {
end = close
} else {
source.add(parser.diagnostics, current(parser).span, "expected ')' after scalar cast")
}
parser.delimiter_depth -= 1
return add_expr(parser, ast.Expr{
kind=.Cast,
span=span_from(start.span, end.span),
type=target,
left=operand,
right=ast.INVALID_EXPR,
diagnostic=source.INVALID_DIAGNOSTIC,
})
case .Integer:
advance(parser)
value, ok := parse_integer_magnitude(token_text(parser, tok))
@@ -1126,6 +1163,21 @@ parse_return :: proc(parser: ^Parser) -> ast.Stmt_Id {
})
return id
}
if cf, is_cf := parse_value_control_flow(parser); is_cf {
cf_span := parser.module.statements[cf].span
body := make([]ast.Stmt_Id, 1, parser.module.allocator)
body[0] = cf
id := ast.stmt_id(len(parser.module.statements))
append(&parser.module.statements, ast.Stmt{
kind=.Return,
span=span_from(start.span, cf_span),
expr=ast.INVALID_EXPR,
body=body,
value_control_flow=true,
diagnostic=source.INVALID_DIAGNOSTIC,
})
return id
}
expr := parse_expression(parser)
id := ast.stmt_id(len(parser.module.statements))
append(&parser.module.statements, ast.Stmt{
@@ -1154,6 +1206,22 @@ parse_yield :: proc(parser: ^Parser) -> ast.Stmt_Id {
source.add(parser.diagnostics, current(parser).span, "expected a loop label after ':'")
}
}
if cf, is_cf := parse_value_control_flow(parser); is_cf {
cf_span := parser.module.statements[cf].span
body := make([]ast.Stmt_Id, 1, parser.module.allocator)
body[0] = cf
id := ast.stmt_id(len(parser.module.statements))
append(&parser.module.statements, ast.Stmt{
kind=.Yield,
span=span_from(start.span, cf_span),
label=label,
expr=ast.INVALID_EXPR,
body=body,
value_control_flow=true,
diagnostic=source.INVALID_DIAGNOSTIC,
})
return id
}
expr := parse_expression(parser)
id := ast.stmt_id(len(parser.module.statements))
append(&parser.module.statements, ast.Stmt{