mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix else do
This commit is contained in:
+21
-24
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os.odin";
|
"os.odin";
|
||||||
"fmt.odin";
|
"fmt.odin"; // TODO(bill): Remove the need for `fmt` here
|
||||||
"utf8.odin";
|
"utf8.odin";
|
||||||
"raw.odin";
|
"raw.odin";
|
||||||
"types.odin";
|
|
||||||
)
|
)
|
||||||
// Naming Conventions:
|
// Naming Conventions:
|
||||||
// In general, PascalCase for types and snake_case for values
|
// In general, PascalCase for types and snake_case for values
|
||||||
@@ -286,42 +285,40 @@ copy :: proc(dst, src: []$T) -> int #cc_contextless {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
append :: proc(array: ^[]$T, args: ..T) -> int {
|
append :: proc(array: ^[]$T, args: ..T) -> int #cc_contextless {
|
||||||
if array == nil do return 0;
|
if array == nil do return 0;
|
||||||
|
|
||||||
slice := ^raw.Slice(array);
|
|
||||||
|
|
||||||
arg_len := len(args);
|
arg_len := len(args);
|
||||||
if arg_len <= 0 do return slice.len;
|
if arg_len <= 0 do return len(array);
|
||||||
|
|
||||||
arg_len = min(slice.cap-slice.len, arg_len);
|
arg_len = min(cap(array)-len(array), arg_len);
|
||||||
if arg_len > 0 {
|
if arg_len > 0 {
|
||||||
data := ^T(slice.data);
|
s := ^raw.Slice(array);
|
||||||
|
data := ^T(s.data);
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
sz :: size_of(T);
|
sz :: size_of(T);
|
||||||
__mem_copy(data + slice.len, &args[0], sz*arg_len);
|
__mem_copy(data + s.len, &args[0], sz*arg_len);
|
||||||
slice.len += arg_len;
|
s.len += arg_len;
|
||||||
}
|
}
|
||||||
return slice.len;
|
return len(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
append :: proc(array: ^[dynamic]$T, args: ..T) -> int {
|
append :: proc(array: ^[dynamic]$T, args: ..T) -> int {
|
||||||
if array == nil do return 0;
|
if array == nil do return 0;
|
||||||
|
|
||||||
a := ^raw.DynamicArray(array);
|
|
||||||
|
|
||||||
arg_len := len(args);
|
arg_len := len(args);
|
||||||
if arg_len <= 0 do return a.len;
|
if arg_len <= 0 do return len(array);
|
||||||
|
|
||||||
|
|
||||||
ok := true;
|
ok := true;
|
||||||
if a.cap <= a.len+arg_len {
|
if cap(array) <= len(array)+arg_len {
|
||||||
cap := 2 * a.cap + max(8, arg_len);
|
cap := 2 * cap(array) + max(8, arg_len);
|
||||||
ok = __dynamic_array_reserve(a, size_of(T), align_of(T), cap);
|
ok = reserve(array, cap);
|
||||||
}
|
}
|
||||||
// TODO(bill): Better error handling for failed reservation
|
// TODO(bill): Better error handling for failed reservation
|
||||||
if !ok do return a.len;
|
if !ok do return len(array);
|
||||||
|
|
||||||
|
a := ^raw.DynamicArray(array);
|
||||||
data := ^T(a.data);
|
data := ^T(a.data);
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
__mem_copy(data + a.len, &args[0], size_of(T) * arg_len);
|
__mem_copy(data + a.len, &args[0], size_of(T) * arg_len);
|
||||||
@@ -405,8 +402,8 @@ __get_map_header :: proc(m: ^map[$K]$V) -> __MapHeader #cc_contextless {
|
|||||||
__get_map_key :: proc(key: $K) -> __MapKey #cc_contextless {
|
__get_map_key :: proc(key: $K) -> __MapKey #cc_contextless {
|
||||||
map_key: __MapKey;
|
map_key: __MapKey;
|
||||||
ti := type_info_base_without_enum(type_info(K));
|
ti := type_info_base_without_enum(type_info(K));
|
||||||
match {
|
match _ in ti {
|
||||||
case types.is_integer(ti):
|
case TypeInfo.Integer:
|
||||||
match 8*size_of(key) {
|
match 8*size_of(key) {
|
||||||
case 8: map_key.hash = u128( ^u8(&key)^);
|
case 8: map_key.hash = u128( ^u8(&key)^);
|
||||||
case 16: map_key.hash = u128( ^u16(&key)^);
|
case 16: map_key.hash = u128( ^u16(&key)^);
|
||||||
@@ -414,17 +411,17 @@ __get_map_key :: proc(key: $K) -> __MapKey #cc_contextless {
|
|||||||
case 64: map_key.hash = u128( ^u64(&key)^);
|
case 64: map_key.hash = u128( ^u64(&key)^);
|
||||||
case 128: map_key.hash = u128(^u128(&key)^);
|
case 128: map_key.hash = u128(^u128(&key)^);
|
||||||
}
|
}
|
||||||
case types.is_rune(ti):
|
case TypeInfo.Rune:
|
||||||
map_key.hash = u128(^rune(&key)^);
|
map_key.hash = u128(^rune(&key)^);
|
||||||
case types.is_pointer(ti):
|
case TypeInfo.Pointer:
|
||||||
map_key.hash = u128(uint(^rawptr(&key)^));
|
map_key.hash = u128(uint(^rawptr(&key)^));
|
||||||
case types.is_float(ti):
|
case TypeInfo.Float:
|
||||||
match 8*size_of(key) {
|
match 8*size_of(key) {
|
||||||
case 32: map_key.hash = u128(^u32(&key)^);
|
case 32: map_key.hash = u128(^u32(&key)^);
|
||||||
case 64: map_key.hash = u128(^u64(&key)^);
|
case 64: map_key.hash = u128(^u64(&key)^);
|
||||||
case: panic("Unhandled float size");
|
case: panic("Unhandled float size");
|
||||||
}
|
}
|
||||||
case types.is_string(ti):
|
case TypeInfo.String:
|
||||||
str := ^string(&key)^;
|
str := ^string(&key)^;
|
||||||
map_key.hash = __default_hash_string(str);
|
map_key.hash = __default_hash_string(str);
|
||||||
map_key.str = str;
|
map_key.str = str;
|
||||||
|
|||||||
@@ -1384,6 +1384,39 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
|
|||||||
case Type_Proc:
|
case Type_Proc:
|
||||||
if (source->kind == Type_Proc) {
|
if (source->kind == Type_Proc) {
|
||||||
// TODO(bill): Polymorphic type assignment
|
// 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;
|
return false;
|
||||||
case Type_Map:
|
case Type_Map:
|
||||||
@@ -6735,6 +6768,10 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
if (cl->elems.count == 0) {
|
||||||
|
break; // NOTE(bill): No need to init
|
||||||
|
}
|
||||||
|
|
||||||
gbString str = type_to_string(type);
|
gbString str = type_to_string(type);
|
||||||
error(node, "Invalid compound literal type `%s`", str);
|
error(node, "Invalid compound literal type `%s`", str);
|
||||||
gb_string_free(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) {
|
void show_timings(Checker *c, Timings *t) {
|
||||||
Parser *p = c->parser;
|
Parser *p = c->parser;
|
||||||
timings_print_all(t);
|
isize lines = p->total_line_count;
|
||||||
gb_printf("\n");
|
isize tokens = p->total_token_count;
|
||||||
gb_printf("Total lines: %td\n", p->total_line_count);
|
isize files = p->files.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);
|
timings_print_all(t);
|
||||||
gb_printf("\n");
|
gb_printf("\n");
|
||||||
gb_printf("Total tokens: %td\n", p->total_token_count);
|
gb_printf("Total Lines - %td\n", lines);
|
||||||
gb_printf("Tokens/s: %.3f\n", cast(f64)p->total_token_count/t->total_time_seconds);
|
gb_printf("Total Tokens - %td\n", tokens);
|
||||||
gb_printf("us/Token: %.3f\n\n", 1.0e6*t->total_time_seconds/cast(f64)p->total_token_count);
|
gb_printf("Total Files - %td\n", files);
|
||||||
gb_printf("\n");
|
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) {
|
int main(int arg_count, char **arg_ptr) {
|
||||||
|
|||||||
+25
-59
@@ -114,9 +114,8 @@ enum FieldFlag {
|
|||||||
FieldFlag_using = 1<<1,
|
FieldFlag_using = 1<<1,
|
||||||
FieldFlag_no_alias = 1<<2,
|
FieldFlag_no_alias = 1<<2,
|
||||||
FieldFlag_c_vararg = 1<<3,
|
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 {
|
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);
|
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) {
|
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 *curr_proc = f->curr_proc;
|
||||||
AstNode *body = nullptr;
|
AstNode *body = nullptr;
|
||||||
f->curr_proc = type;
|
f->curr_proc = type;
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, 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);
|
|
||||||
}
|
|
||||||
f->curr_proc = curr_proc;
|
f->curr_proc = curr_proc;
|
||||||
|
|
||||||
return ast_proc_lit(f, type, body, tags, link_name);
|
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) {
|
for_array(i, params->FieldList.list) {
|
||||||
AstNode *param = params->FieldList.list[i];
|
AstNode *param = params->FieldList.list[i];
|
||||||
ast_node(f, Field, param);
|
ast_node(f, Field, param);
|
||||||
if (f->flags&FieldFlag_dollar) {
|
|
||||||
is_generic = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (f->type != nullptr &&
|
if (f->type != nullptr &&
|
||||||
f->type->kind == AstNode_TypeType) {
|
(f->type->kind == AstNode_TypeType ||
|
||||||
|
f->type->kind == AstNode_PolyType)) {
|
||||||
is_generic = true;
|
is_generic = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3232,7 +3232,6 @@ enum FieldPrefixKind {
|
|||||||
FieldPrefix_Using,
|
FieldPrefix_Using,
|
||||||
FieldPrefix_NoAlias,
|
FieldPrefix_NoAlias,
|
||||||
FieldPrefix_CVarArg,
|
FieldPrefix_CVarArg,
|
||||||
FieldPrefix_Dollar,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
||||||
@@ -3243,9 +3242,6 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
|||||||
case Token_using:
|
case Token_using:
|
||||||
return FieldPrefix_Using;
|
return FieldPrefix_Using;
|
||||||
|
|
||||||
case Token_Dollar:
|
|
||||||
return FieldPrefix_Dollar;
|
|
||||||
|
|
||||||
case Token_Hash: {
|
case Token_Hash: {
|
||||||
next_token(f);
|
next_token(f);
|
||||||
switch (f->curr_token.kind) {
|
switch (f->curr_token.kind) {
|
||||||
@@ -3268,7 +3264,6 @@ u32 parse_field_prefixes(AstFile *f) {
|
|||||||
i32 using_count = 0;
|
i32 using_count = 0;
|
||||||
i32 no_alias_count = 0;
|
i32 no_alias_count = 0;
|
||||||
i32 c_vararg_count = 0;
|
i32 c_vararg_count = 0;
|
||||||
i32 dollar_count = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
FieldPrefixKind kind = is_token_field_prefix(f);
|
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_Using: using_count += 1; next_token(f); break;
|
||||||
case FieldPrefix_NoAlias: no_alias_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_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 (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 (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 (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;
|
u32 field_flags = 0;
|
||||||
if (using_count > 0) field_flags |= FieldFlag_using;
|
if (using_count > 0) field_flags |= FieldFlag_using;
|
||||||
if (no_alias_count > 0) field_flags |= FieldFlag_no_alias;
|
if (no_alias_count > 0) field_flags |= FieldFlag_no_alias;
|
||||||
if (c_vararg_count > 0) field_flags |= FieldFlag_c_vararg;
|
if (c_vararg_count > 0) field_flags |= FieldFlag_c_vararg;
|
||||||
if (dollar_count > 0) field_flags |= FieldFlag_dollar;
|
|
||||||
return field_flags;
|
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");
|
syntax_error(f->curr_token, "`#c_vararg` is not allowed within this field list");
|
||||||
set_flags &= ~FieldFlag_c_vararg;
|
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;
|
return set_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3806,6 +3792,7 @@ AstNode *parse_type_or_ident(AstFile *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AstNode *parse_body(AstFile *f) {
|
AstNode *parse_body(AstFile *f) {
|
||||||
Array<AstNode *> stmts = {};
|
Array<AstNode *> stmts = {};
|
||||||
Token open, close;
|
Token open, close;
|
||||||
@@ -3855,10 +3842,7 @@ AstNode *parse_if_stmt(AstFile *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (allow_token(f, Token_do)) {
|
if (allow_token(f, Token_do)) {
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
body = parse_block_stmt(f, false);
|
body = parse_block_stmt(f, false);
|
||||||
}
|
}
|
||||||
@@ -3873,10 +3857,7 @@ AstNode *parse_if_stmt(AstFile *f) {
|
|||||||
break;
|
break;
|
||||||
case Token_do: {
|
case Token_do: {
|
||||||
Token arrow = expect_token(f, Token_do);
|
Token arrow = expect_token(f, Token_do);
|
||||||
body = parse_stmt(f);
|
else_stmt = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
syntax_error(f->curr_token, "Expected if statement block statement");
|
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)) {
|
if (allow_token(f, Token_do)) {
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
body = parse_block_stmt(f, true);
|
body = parse_block_stmt(f, true);
|
||||||
}
|
}
|
||||||
@@ -3924,10 +3902,7 @@ AstNode *parse_when_stmt(AstFile *f) {
|
|||||||
break;
|
break;
|
||||||
case Token_do: {
|
case Token_do: {
|
||||||
Token arrow = expect_token(f, Token_do);
|
Token arrow = expect_token(f, Token_do);
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
syntax_error(f->curr_token, "Expected when statement block statement");
|
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)) {
|
if (allow_token(f, Token_do)) {
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
body = parse_block_stmt(f, false);
|
body = parse_block_stmt(f, false);
|
||||||
}
|
}
|
||||||
@@ -4304,10 +4276,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
f->expr_level = prev_level;
|
f->expr_level = prev_level;
|
||||||
|
|
||||||
if (allow_token(f, Token_do)) {
|
if (allow_token(f, Token_do)) {
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
body = parse_block_stmt(f, false);
|
body = parse_block_stmt(f, false);
|
||||||
}
|
}
|
||||||
@@ -4324,10 +4293,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
f->expr_level = prev_level;
|
f->expr_level = prev_level;
|
||||||
|
|
||||||
if (allow_token(f, Token_do)) {
|
if (allow_token(f, Token_do)) {
|
||||||
body = parse_stmt(f);
|
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||||
if (body->kind == AstNode_BlockStmt) {
|
|
||||||
syntax_error(body, "Expected a normal statement rather than a block statement");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
body = parse_block_stmt(f, false);
|
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));
|
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));
|
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) {
|
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);
|
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);
|
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),
|
LIT(t->total.label),
|
||||||
cast(int)(max_len-t->total.label.len), SPACES,
|
cast(int)(max_len-t->total.label.len), SPACES,
|
||||||
total_ms);
|
total_ms,
|
||||||
|
cast(f64)100.0);
|
||||||
|
|
||||||
for_array(i, t->sections) {
|
for_array(i, t->sections) {
|
||||||
TimeStamp ts = t->sections[i];
|
TimeStamp ts = t->sections[i];
|
||||||
f64 section_ms = time_stamp_as_ms(ts, t->freq);
|
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),
|
LIT(ts.label),
|
||||||
cast(int)(max_len-ts.label.len), SPACES,
|
cast(int)(max_len-ts.label.len), SPACES,
|
||||||
section_ms, 100*section_ms/total_ms);
|
section_ms, 100*section_ms/total_ms);
|
||||||
|
|||||||
Reference in New Issue
Block a user