mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-14 15:11:25 -07:00
Fix else do
This commit is contained in:
@@ -1384,6 +1384,39 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
|
||||
case Type_Proc:
|
||||
if (source->kind == Type_Proc) {
|
||||
// TODO(bill): Polymorphic type assignment
|
||||
#if 0
|
||||
TypeProc *x = &poly->Proc;
|
||||
TypeProc *y = &source->Proc;
|
||||
if (x->calling_convention != y->calling_convention) {
|
||||
return false;
|
||||
}
|
||||
if (x->c_vararg != y->c_vararg) {
|
||||
return false;
|
||||
}
|
||||
if (x->variadic != y->variadic) {
|
||||
return false;
|
||||
}
|
||||
if (x->param_count != y->param_count) {
|
||||
return false;
|
||||
}
|
||||
if (x->result_count != y->result_count) {
|
||||
return false;
|
||||
}
|
||||
for (isize i = 0; i < x->param_count; i++) {
|
||||
Entity *a = x->params->Tuple.variables[i];
|
||||
Entity *b = y->params->Tuple.variables[i];
|
||||
bool ok = is_polymorphic_type_assignable(c, a->type, b->type, false, modify_type);
|
||||
if (!ok) return false;
|
||||
}
|
||||
for (isize i = 0; i < x->result_count; i++) {
|
||||
Entity *a = x->results->Tuple.variables[i];
|
||||
Entity *b = y->results->Tuple.variables[i];
|
||||
bool ok = is_polymorphic_type_assignable(c, a->type, b->type, false, modify_type);
|
||||
if (!ok) return false;
|
||||
}
|
||||
// TODO(bill): Polymorphic type assignment
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
case Type_Map:
|
||||
@@ -6735,6 +6768,10 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
} break;
|
||||
|
||||
default: {
|
||||
if (cl->elems.count == 0) {
|
||||
break; // NOTE(bill): No need to init
|
||||
}
|
||||
|
||||
gbString str = type_to_string(type);
|
||||
error(node, "Invalid compound literal type `%s`", str);
|
||||
gb_string_free(str);
|
||||
|
||||
+32
-12
@@ -330,18 +330,38 @@ bool parse_build_flags(Array<String> args) {
|
||||
|
||||
|
||||
void show_timings(Checker *c, Timings *t) {
|
||||
Parser *p = c->parser;
|
||||
timings_print_all(t);
|
||||
gb_printf("\n");
|
||||
gb_printf("Total lines: %td\n", p->total_line_count);
|
||||
gb_printf("Lines/s: %.3f\n", cast(f64)p->total_line_count/t->total_time_seconds);
|
||||
gb_printf("us/Line: %.3f\n", 1.0e6*t->total_time_seconds/cast(f64)p->total_line_count);
|
||||
gb_printf("\n");
|
||||
gb_printf("Total tokens: %td\n", p->total_token_count);
|
||||
gb_printf("Tokens/s: %.3f\n", cast(f64)p->total_token_count/t->total_time_seconds);
|
||||
gb_printf("us/Token: %.3f\n\n", 1.0e6*t->total_time_seconds/cast(f64)p->total_token_count);
|
||||
gb_printf("\n");
|
||||
|
||||
Parser *p = c->parser;
|
||||
isize lines = p->total_line_count;
|
||||
isize tokens = p->total_token_count;
|
||||
isize files = p->files.count;
|
||||
{
|
||||
timings_print_all(t);
|
||||
gb_printf("\n");
|
||||
gb_printf("Total Lines - %td\n", lines);
|
||||
gb_printf("Total Tokens - %td\n", tokens);
|
||||
gb_printf("Total Files - %td\n", files);
|
||||
gb_printf("\n");
|
||||
}
|
||||
{
|
||||
TimeStamp ts = t->sections[0];
|
||||
GB_ASSERT(ts.label == "parse files");
|
||||
f64 parse_time = time_stamp_as_second(ts, t->freq);
|
||||
gb_printf("Parse pass\n");
|
||||
gb_printf("LOC/s - %.3f\n", cast(f64)lines/parse_time);
|
||||
gb_printf("us/LOC - %.3f\n", 1.0e6*parse_time/cast(f64)lines);
|
||||
gb_printf("Tokens/s - %.3f\n", cast(f64)tokens/parse_time);
|
||||
gb_printf("us/Token - %.3f\n", 1.0e6*parse_time/cast(f64)tokens);
|
||||
gb_printf("\n");
|
||||
}
|
||||
{
|
||||
f64 total_time = t->total_time_seconds;
|
||||
gb_printf("Total pass\n");
|
||||
gb_printf("LOC/s - %.3f\n", cast(f64)lines/total_time);
|
||||
gb_printf("us/LOC - %.3f\n", 1.0e6*total_time/cast(f64)lines);
|
||||
gb_printf("Tokens/s - %.3f\n", cast(f64)tokens/total_time);
|
||||
gb_printf("us/Token - %.3f\n", 1.0e6*total_time/cast(f64)tokens);
|
||||
gb_printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int arg_count, char **arg_ptr) {
|
||||
|
||||
+25
-59
@@ -114,9 +114,8 @@ enum FieldFlag {
|
||||
FieldFlag_using = 1<<1,
|
||||
FieldFlag_no_alias = 1<<2,
|
||||
FieldFlag_c_vararg = 1<<3,
|
||||
FieldFlag_dollar = 1<<4,
|
||||
|
||||
FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg|FieldFlag_dollar,
|
||||
FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg,
|
||||
};
|
||||
|
||||
enum StmtAllowFlag {
|
||||
@@ -2181,6 +2180,19 @@ AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) {
|
||||
return ast_bad_expr(f, f->curr_token, end);
|
||||
}
|
||||
|
||||
AstNode *convert_stmt_to_body(AstFile *f, AstNode *stmt) {
|
||||
if (stmt->kind == AstNode_BlockStmt) {
|
||||
syntax_error(stmt, "Expected a normal statement rather than a block statement");
|
||||
return stmt;
|
||||
}
|
||||
GB_ASSERT(is_ast_node_stmt(stmt));
|
||||
Token open = ast_node_token(stmt);
|
||||
Token close = ast_node_token(stmt);
|
||||
Array<AstNode *> stmts = make_ast_node_array(f, 1);
|
||||
array_add(&stmts, stmt);
|
||||
return ast_block_stmt(f, stmts, open, close);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
@@ -2304,16 +2316,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
AstNode *curr_proc = f->curr_proc;
|
||||
AstNode *body = nullptr;
|
||||
f->curr_proc = type;
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
} else {
|
||||
Token open = ast_node_token(body);
|
||||
Token close = ast_node_token(body);
|
||||
Array<AstNode *> stmts = make_ast_node_array(f, 1);
|
||||
array_add(&stmts, body);
|
||||
body = ast_block_stmt(f, stmts, open, close);
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
f->curr_proc = curr_proc;
|
||||
|
||||
return ast_proc_lit(f, type, body, tags, link_name);
|
||||
@@ -3184,12 +3187,9 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token, String *link_name_) {
|
||||
for_array(i, params->FieldList.list) {
|
||||
AstNode *param = params->FieldList.list[i];
|
||||
ast_node(f, Field, param);
|
||||
if (f->flags&FieldFlag_dollar) {
|
||||
is_generic = true;
|
||||
break;
|
||||
}
|
||||
if (f->type != nullptr &&
|
||||
f->type->kind == AstNode_TypeType) {
|
||||
(f->type->kind == AstNode_TypeType ||
|
||||
f->type->kind == AstNode_PolyType)) {
|
||||
is_generic = true;
|
||||
break;
|
||||
}
|
||||
@@ -3232,7 +3232,6 @@ enum FieldPrefixKind {
|
||||
FieldPrefix_Using,
|
||||
FieldPrefix_NoAlias,
|
||||
FieldPrefix_CVarArg,
|
||||
FieldPrefix_Dollar,
|
||||
};
|
||||
|
||||
FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
||||
@@ -3243,9 +3242,6 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
||||
case Token_using:
|
||||
return FieldPrefix_Using;
|
||||
|
||||
case Token_Dollar:
|
||||
return FieldPrefix_Dollar;
|
||||
|
||||
case Token_Hash: {
|
||||
next_token(f);
|
||||
switch (f->curr_token.kind) {
|
||||
@@ -3268,7 +3264,6 @@ u32 parse_field_prefixes(AstFile *f) {
|
||||
i32 using_count = 0;
|
||||
i32 no_alias_count = 0;
|
||||
i32 c_vararg_count = 0;
|
||||
i32 dollar_count = 0;
|
||||
|
||||
for (;;) {
|
||||
FieldPrefixKind kind = is_token_field_prefix(f);
|
||||
@@ -3279,20 +3274,17 @@ u32 parse_field_prefixes(AstFile *f) {
|
||||
case FieldPrefix_Using: using_count += 1; next_token(f); break;
|
||||
case FieldPrefix_NoAlias: no_alias_count += 1; next_token(f); break;
|
||||
case FieldPrefix_CVarArg: c_vararg_count += 1; next_token(f); break;
|
||||
case FieldPrefix_Dollar: dollar_count += 1; next_token(f); break;
|
||||
}
|
||||
}
|
||||
if (using_count > 1) syntax_error(f->curr_token, "Multiple `using` in this field list");
|
||||
if (no_alias_count > 1) syntax_error(f->curr_token, "Multiple `#no_alias` in this field list");
|
||||
if (c_vararg_count > 1) syntax_error(f->curr_token, "Multiple `#c_vararg` in this field list");
|
||||
if (dollar_count > 1) syntax_error(f->curr_token, "Multiple `$` in this field list");
|
||||
|
||||
|
||||
u32 field_flags = 0;
|
||||
if (using_count > 0) field_flags |= FieldFlag_using;
|
||||
if (no_alias_count > 0) field_flags |= FieldFlag_no_alias;
|
||||
if (c_vararg_count > 0) field_flags |= FieldFlag_c_vararg;
|
||||
if (dollar_count > 0) field_flags |= FieldFlag_dollar;
|
||||
return field_flags;
|
||||
}
|
||||
|
||||
@@ -3314,12 +3306,6 @@ u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 se
|
||||
syntax_error(f->curr_token, "`#c_vararg` is not allowed within this field list");
|
||||
set_flags &= ~FieldFlag_c_vararg;
|
||||
}
|
||||
// if ((allowed_flags&FieldFlag_dollar) == 0 && (set_flags&FieldFlag_dollar)) {
|
||||
if ((set_flags&FieldFlag_dollar)) {
|
||||
// syntax_error(f->curr_token, "`$` is only allowed within procedures");
|
||||
syntax_error(f->curr_token, "`$` is not yet supported");
|
||||
set_flags &= ~FieldFlag_dollar;
|
||||
}
|
||||
return set_flags;
|
||||
}
|
||||
|
||||
@@ -3806,6 +3792,7 @@ AstNode *parse_type_or_ident(AstFile *f) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
AstNode *parse_body(AstFile *f) {
|
||||
Array<AstNode *> stmts = {};
|
||||
Token open, close;
|
||||
@@ -3855,10 +3842,7 @@ AstNode *parse_if_stmt(AstFile *f) {
|
||||
}
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -3873,10 +3857,7 @@ AstNode *parse_if_stmt(AstFile *f) {
|
||||
break;
|
||||
case Token_do: {
|
||||
Token arrow = expect_token(f, Token_do);
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
else_stmt = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} break;
|
||||
default:
|
||||
syntax_error(f->curr_token, "Expected if statement block statement");
|
||||
@@ -3906,10 +3887,7 @@ AstNode *parse_when_stmt(AstFile *f) {
|
||||
}
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, true);
|
||||
}
|
||||
@@ -3924,10 +3902,7 @@ AstNode *parse_when_stmt(AstFile *f) {
|
||||
break;
|
||||
case Token_do: {
|
||||
Token arrow = expect_token(f, Token_do);
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} break;
|
||||
default:
|
||||
syntax_error(f->curr_token, "Expected when statement block statement");
|
||||
@@ -4043,10 +4018,7 @@ AstNode *parse_for_stmt(AstFile *f) {
|
||||
}
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -4304,10 +4276,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
f->expr_level = prev_level;
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -4324,10 +4293,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
f->expr_level = prev_level;
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_stmt(f);
|
||||
if (body->kind == AstNode_BlockStmt) {
|
||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
||||
}
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
|
||||
+11
-6
@@ -104,9 +104,13 @@ void timings_start_section(Timings *t, String label) {
|
||||
array_add(&t->sections, make_time_stamp(label));
|
||||
}
|
||||
|
||||
f64 time_stamp_as_ms(TimeStamp ts, u64 freq) {
|
||||
f64 time_stamp_as_second(TimeStamp ts, u64 freq) {
|
||||
GB_ASSERT_MSG(ts.finish >= ts.start, "time_stamp_as_ms - %.*s", LIT(ts.label));
|
||||
return 1000.0 * cast(f64)(ts.finish - ts.start) / cast(f64)freq;
|
||||
return cast(f64)(ts.finish - ts.start) / cast(f64)freq;
|
||||
}
|
||||
|
||||
f64 time_stamp_as_ms(TimeStamp ts, u64 freq) {
|
||||
return 1000.0*time_stamp_as_second(ts, freq);
|
||||
}
|
||||
|
||||
void timings_print_all(Timings *t) {
|
||||
@@ -124,19 +128,20 @@ void timings_print_all(Timings *t) {
|
||||
|
||||
GB_ASSERT(max_len <= gb_size_of(SPACES)-1);
|
||||
|
||||
t->total_time_seconds = cast(f64)(t->total.finish - t->total.start) / cast(f64)t->freq;
|
||||
t->total_time_seconds = time_stamp_as_second(t->total, t->freq);
|
||||
|
||||
f64 total_ms = time_stamp_as_ms(t->total, t->freq);
|
||||
|
||||
gb_printf("%.*s%.*s - % 9.3f ms\n",
|
||||
gb_printf("%.*s%.*s - % 9.3f ms - %6.2f%%\n",
|
||||
LIT(t->total.label),
|
||||
cast(int)(max_len-t->total.label.len), SPACES,
|
||||
total_ms);
|
||||
total_ms,
|
||||
cast(f64)100.0);
|
||||
|
||||
for_array(i, t->sections) {
|
||||
TimeStamp ts = t->sections[i];
|
||||
f64 section_ms = time_stamp_as_ms(ts, t->freq);
|
||||
gb_printf("%.*s%.*s - % 9.3f ms - %5.2f%%\n",
|
||||
gb_printf("%.*s%.*s - % 9.3f ms - %6.2f%%\n",
|
||||
LIT(ts.label),
|
||||
cast(int)(max_len-ts.label.len), SPACES,
|
||||
section_ms, 100*section_ms/total_ms);
|
||||
|
||||
Reference in New Issue
Block a user